summaryrefslogtreecommitdiffstats
path: root/arts/kde/kiotestslow.cc
blob: df6ed645fe3706e7c99a43f7c5cbabc155eae764 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include <kmedia2.h>
#include <tdecmdlineargs.h>
#include <connect.h>
#include <klocale.h>
#include <tdeapplication.h>
#include <tdeaboutdata.h>
#include <stdsynthmodule.h>
#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<mcopbyte>* > 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<mcopbyte> *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<DataPacket<mcopbyte>*>::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<mcopbyte> *p)
	{
		if(p->size == 0)
			p->processed();
		else
			q.push_back(p);
	}
};
REGISTER_IMPLEMENTATION(KIOTestSlow_impl);
};

static TDECmdLineOptions options[] =
{
    { "+[URL]", I18N_NOOP("URL to open"), 0 },
    TDECmdLineLastOption
};

#undef USE_FILEINPUTSTREAM

int main(int argc, char **argv)
{
	TDEAboutData aboutData( "kiotestslow", I18N_NOOP("KIOTest"), I18N_NOOP("0.1"), "", TDEAboutData::License_GPL, "");
							  
	TDECmdLineArgs::init(argc,argv,&aboutData);
	TDECmdLineArgs::addCmdLineOptions(options); 	
	TDEApplication app;
	QIOManager qiomanager;
	Dispatcher dispatcher(&qiomanager);
#ifndef USE_FILEINPUTSTREAM
	TDEIOInputStream stream;
#else
	FileInputStream stream;
#endif
	KIOTestSlow writer;

	TDECmdLineArgs *args = TDECmdLineArgs::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();
}