home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / asyncstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  2.6 KB  |  104 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef ASYNCSTREAM_H
  24. #define ASYNCSTREAM_H
  25.  
  26. #include "arts_export.h"
  27. #include "buffer.h"
  28. #include "datapacket.h"
  29.  
  30. /*
  31.  * BC - Status (2002-03-08): GenericAsyncStream, AsyncStream,
  32.  *   FloatAsyncStream/ByteAsyncStream
  33.  *
  34.  * These classes are to be treated with extreme care, as they are used in
  35.  * all kinds of relations with the flow system and the generated code. Do
  36.  * NOT touch unless you REALLY know what you are doing. For further
  37.  * extensibility, GenericAsyncStream features a private d pointer.
  38.  */
  39.  
  40. namespace Arts {
  41.  
  42. class GenericAsyncStreamPrivate;
  43.  
  44. class ARTS_EXPORT GenericAsyncStream {
  45. private:
  46.     GenericAsyncStreamPrivate *d;    // unused
  47. public:
  48.     /**
  49.      * interface to create packets and to get rid of them
  50.      */
  51.     virtual GenericDataPacket *createPacket(int capacity) = 0;
  52.     virtual void freePacket(GenericDataPacket *packet) = 0;
  53.  
  54.     virtual GenericAsyncStream *createNewStream() = 0;
  55.  
  56.     GenericDataChannel *channel;
  57.     int _notifyID;
  58.  
  59.     inline int notifyID() { return _notifyID; }
  60. };
  61.  
  62. template<class T>
  63. class AsyncStream : public GenericAsyncStream {
  64. protected:
  65.     GenericDataPacket *createPacket(int capacity)
  66.     {
  67.         return allocPacket(capacity);
  68.     }
  69.     void freePacket(GenericDataPacket *packet)
  70.     {
  71.         delete packet;
  72.     }
  73. public:
  74.     // for outgoing streams
  75.     virtual DataPacket<T> *allocPacket(int capacity) = 0;
  76.  
  77.     inline void setPull(int packets, int capacity)
  78.     {
  79.         channel->setPull(packets,capacity);
  80.     }
  81.     inline void endPull()
  82.     {
  83.         channel->endPull();
  84.     }
  85. };
  86.  
  87. class ARTS_EXPORT FloatAsyncStream : public AsyncStream<float>
  88. {
  89. public:
  90.     DataPacket<float> *allocPacket(int capacity);
  91.     GenericAsyncStream *createNewStream();
  92. };
  93.  
  94. class ARTS_EXPORT ByteAsyncStream : public AsyncStream<mcopbyte>
  95. {
  96. public:
  97.     DataPacket<mcopbyte> *allocPacket(int capacity);
  98.     GenericAsyncStream *createNewStream();
  99. };
  100.  
  101. }
  102.  
  103. #endif /* ASYNCSTREAM_H */
  104.