TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <stdio.h>
  2. #include <kmedia2.h>
  3. #include <tdecmdlineargs.h>
  4. #include <connect.h>
  5. #include <tdelocale.h>
  6. #include <tdeapplication.h>
  7. #include <tdeaboutdata.h>
  8. #include <stdsynthmodule.h>
  9. #include "qiomanager.h"
  10. #include "artskde.h"
  11. using namespace std;
  12. using namespace Arts;
  13. namespace Arts {
  14. /* simulate slow receiver */
  15. class KIOTestSlow_impl : public KIOTestSlow_skel,
  16. public TimeNotify,
  17. public StdSynthModule
  18. {
  19. int pos;
  20. list< DataPacket<mcopbyte>* > q;
  21. InputStream _inputStream;
  22. public:
  23. InputStream inputStream() { return _inputStream; }
  24. void inputStream(InputStream i) { _inputStream = i; }
  25. KIOTestSlow_impl()
  26. {
  27. Dispatcher::the()->ioManager()->addTimer(10, this);
  28. pos = 0;
  29. }
  30. void notifyTime()
  31. {
  32. if(!_inputStream.isNull() && _inputStream.eof())
  33. {
  34. printf("\n[*EOF*] remaining = %d packets\n");
  35. _inputStream = InputStream::null();
  36. return;
  37. }
  38. int TODO = 100;
  39. do {
  40. if(q.empty())
  41. return;
  42. DataPacket<mcopbyte> *p = q.front();
  43. char ch = p->contents[pos++];
  44. if(p->size == pos)
  45. {
  46. p->processed();
  47. q.pop_front();
  48. pos = 0;
  49. }
  50. if(ch == '\n')
  51. {
  52. long size = 0;
  53. list<DataPacket<mcopbyte>*>::iterator i;
  54. for(i = q.begin(); i != q.end(); i++)
  55. size += (*i)->size;
  56. printf("\n[queued %8ld] ",size-pos);
  57. }
  58. else
  59. putchar(ch);
  60. } while(TODO-- > 0);
  61. }
  62. void process_data(DataPacket<mcopbyte> *p)
  63. {
  64. if(p->size == 0)
  65. p->processed();
  66. else
  67. q.push_back(p);
  68. }
  69. };
  70. REGISTER_IMPLEMENTATION(KIOTestSlow_impl);
  71. };
  72. static TDECmdLineOptions options[] =
  73. {
  74. { "+[URL]", I18N_NOOP("URL to open"), 0 },
  75. TDECmdLineLastOption
  76. };
  77. #undef USE_FILEINPUTSTREAM
  78. int main(int argc, char **argv)
  79. {
  80. TDEAboutData aboutData( "kiotestslow", I18N_NOOP("KIOTest"), I18N_NOOP("0.1"), "", TDEAboutData::License_GPL, "");
  81. TDECmdLineArgs::init(argc,argv,&aboutData);
  82. TDECmdLineArgs::addCmdLineOptions(options);
  83. TDEApplication app;
  84. QIOManager qiomanager;
  85. Dispatcher dispatcher(&qiomanager);
  86. #ifndef USE_FILEINPUTSTREAM
  87. TDEIOInputStream stream;
  88. #else
  89. FileInputStream stream;
  90. #endif
  91. KIOTestSlow writer;
  92. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  93. if(args->count())
  94. {
  95. #ifdef USE_FILEINPUTSTREAM
  96. if(!stream.open(args->arg(0)))
  97. #else
  98. if(!stream.openURL(args->arg(0)))
  99. #endif
  100. {
  101. printf("can't open url");
  102. exit(1);
  103. }
  104. }
  105. else
  106. exit(1);
  107. args->clear();
  108. writer.inputStream(stream);
  109. connect(stream, writer);
  110. writer.start();
  111. stream.start();
  112. app.exec();
  113. }