From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- arts/kde/kiotestslow.cc | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 arts/kde/kiotestslow.cc (limited to 'arts/kde/kiotestslow.cc') diff --git a/arts/kde/kiotestslow.cc b/arts/kde/kiotestslow.cc new file mode 100644 index 000000000..fd5f1e129 --- /dev/null +++ b/arts/kde/kiotestslow.cc @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "qiomanager.h" +#include "artskde.h" + +using namespace std; +using namespace Arts; + +namespace Arts { +/* simulate slow receiver */ +class KIOTestSlow_impl : public KIOTestSlow_skel, + public TimeNotify, + public StdSynthModule +{ + int pos; + list< DataPacket* > q; + InputStream _inputStream; + +public: + InputStream inputStream() { return _inputStream; } + void inputStream(InputStream i) { _inputStream = i; } + + KIOTestSlow_impl() + { + Dispatcher::the()->ioManager()->addTimer(10, this); + pos = 0; + } + void notifyTime() + { + if(!_inputStream.isNull() && _inputStream.eof()) + { + printf("\n[*EOF*] remaining = %d packets\n"); + _inputStream = InputStream::null(); + return; + } + + int TODO = 100; + do { + if(q.empty()) + return; + + DataPacket *p = q.front(); + char ch = p->contents[pos++]; + if(p->size == pos) + { + p->processed(); + q.pop_front(); + pos = 0; + } + + if(ch == '\n') + { + long size = 0; + list*>::iterator i; + for(i = q.begin(); i != q.end(); i++) + size += (*i)->size; + printf("\n[queued %8ld] ",size-pos); + } + else + putchar(ch); + + } while(TODO-- > 0); + } + void process_data(DataPacket *p) + { + if(p->size == 0) + p->processed(); + else + q.push_back(p); + } +}; +REGISTER_IMPLEMENTATION(KIOTestSlow_impl); +}; + +static KCmdLineOptions options[] = +{ + { "+[URL]", I18N_NOOP("URL to open"), 0 }, + KCmdLineLastOption +}; + +#undef USE_FILEINPUTSTREAM + +int main(int argc, char **argv) +{ + KAboutData aboutData( "kiotestslow", I18N_NOOP("KIOTest"), I18N_NOOP("0.1"), "", KAboutData::License_GPL, ""); + + KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions(options); + KApplication app; + QIOManager qiomanager; + Dispatcher dispatcher(&qiomanager); +#ifndef USE_FILEINPUTSTREAM + KIOInputStream stream; +#else + FileInputStream stream; +#endif + KIOTestSlow writer; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + if(args->count()) + { +#ifdef USE_FILEINPUTSTREAM + if(!stream.open(args->arg(0))) +#else + if(!stream.openURL(args->arg(0))) +#endif + { + printf("can't open url"); + exit(1); + } + } + else + exit(1); + + args->clear(); + + writer.inputStream(stream); + connect(stream, writer); + + writer.start(); + stream.start(); + + app.exec(); +} -- cgit v1.2.3