# arts Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kiotestslow.cc

    00001 #include <stdio.h>
    00002 #include <kmedia2.h>
    00003 #include <kcmdlineargs.h>
    00004 #include <connect.h>
    00005 #include <klocale.h>
    00006 #include <kapplication.h>
    00007 #include <kaboutdata.h>
    00008 #include <stdsynthmodule.h>
    00009 #include "qiomanager.h"
    00010 #include "artskde.h"
    00011
    00012 using namespace std;
    00013 using namespace Arts;
    00014
    00015 namespace Arts {
    00016 /* simulate slow receiver */
    00017 class KIOTestSlow_impl : public KIOTestSlow_skel,
    00018                          public TimeNotify,
    00019                          public StdSynthModule
    00020 {
    00021     int pos;
    00022     list< DataPacket<mcopbyte>* > q;
    00023     InputStream _inputStream;
    00024
    00025 public:
    00026     InputStream inputStream() { return _inputStream; }
    00027     void inputStream(InputStream i) { _inputStream = i; }
    00028
    00029     KIOTestSlow_impl()
    00030     {
    00031         Dispatcher::the()->ioManager()->addTimer(10, this);
    00032         pos = 0;
    00033     }
    00034     void notifyTime()
    00035     {
    00036         if(!_inputStream.isNull() && _inputStream.eof())
    00037         {
    00038             printf("\n[*EOF*] remaining = %d packets\n");
    00039             _inputStream = InputStream::null();
    00040             return;
    00041         }
    00042
    00043         int TODO = 100;
    00044         do {
    00045             if(q.empty())
    00046                 return;
    00047
    00048             DataPacket<mcopbyte> *p = q.front();
    00049             char ch = p->contents[pos++];
    00050             if(p->size == pos)
    00051             {
    00052                 p->processed();
    00053                 q.pop_front();
    00054                 pos = 0;
    00055             }
    00056
    00057             if(ch == '\n')
    00058             {
    00059                 long size = 0;
    00060                 list<DataPacket<mcopbyte>*>::iterator i;
    00061                 for(i = q.begin(); i != q.end(); i++)
    00062                     size += (*i)->size;
    00063                 printf("\n[queued %8ld] ",size-pos);
    00064             }
    00065             else
    00066                 putchar(ch);
    00067
    00068         } while(TODO-- > 0);
    00069     }
    00070     void process_data(DataPacket<mcopbyte> *p)
    00071     {
    00072         if(p->size == 0)
    00073             p->processed();
    00074         else
    00075             q.push_back(p);
    00076     }
    00077 };
    00078 REGISTER_IMPLEMENTATION(KIOTestSlow_impl);
    00079 };
    00080
    00081 static KCmdLineOptions options[] =
    00082 {
    00083     { "+[URL]", I18N_NOOP("URL to open"), 0 },
    00084     KCmdLineLastOption
    00085 };
    00086
    00087 #undef USE_FILEINPUTSTREAM
    00088
    00089 int main(int argc, char **argv)
    00090 {
    00091     KAboutData aboutData( "kiotestslow", I18N_NOOP("KIOTest"), I18N_NOOP("0.1"), "", KAboutData::License_GPL, "");
    00092
    00093     KCmdLineArgs::init(argc,argv,&aboutData);
    00094     KCmdLineArgs::addCmdLineOptions(options);
    00095     KApplication app;
    00096     QIOManager qiomanager;
    00097     Dispatcher dispatcher(&qiomanager);
    00098 #ifndef USE_FILEINPUTSTREAM
    00099     KIOInputStream stream;
    00100 #else
    00101     FileInputStream stream;
    00102 #endif
    00103     KIOTestSlow writer;
    00104
    00105     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    00106
    00107     if(args->count())
    00108     {
    00109 #ifdef USE_FILEINPUTSTREAM
    00110         if(!stream.open(args->arg(0)))
    00111 #else
    00112         if(!stream.openURL(args->arg(0)))
    00113 #endif
    00114         {
    00115         printf("can't open url");
    00116         exit(1);
    00117         }
    00118     }
    00119     else
    00120         exit(1);
    00121
    00122     args->clear();
    00123
    00124     writer.inputStream(stream);
    00125     connect(stream, writer);
    00126
    00127     writer.start();
    00128     stream.start();
    00129
    00130     app.exec();
    00131 }

This file is part of the documentation for arts Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:27:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003