00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef MULTI_THREADED_CONNECTOR_H
00030 #define MULTI_THREADED_CONNECTOR_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042
00043
00044
00045 #if defined( HAVE_PTHREAD_H ) || defined( __NetBSD__ )
00046 #include <pthread.h>
00047 #else
00048 #error need pthread.h
00049 #endif
00050
00051 #include "Referable.h"
00052 #include "Ref.h"
00053 #include "Reporter.h"
00054 #include "Source.h"
00055 #include "Sink.h"
00056 #include "Connector.h"
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00074 class MultiThreadedConnector : public virtual Connector
00075 {
00076 private:
00077
00081 class ThreadData
00082 {
00083 public:
00087 MultiThreadedConnector * connector;
00088
00092 unsigned int ixSink;
00093
00097 pthread_t thread;
00098
00102 bool accepting;
00103
00108 bool isDone;
00109
00113 inline
00114 ThreadData()
00115 {
00116 this->connector = 0;
00117 this->ixSink = 0;
00118 this->thread = 0;
00119 this->accepting = false;
00120 this->isDone = false;
00121 }
00122
00130 static void *
00131 threadFunction( void * param );
00132 };
00133
00137 pthread_mutex_t mutexProduce;
00138
00142 pthread_cond_t condProduce;
00143
00147 pthread_attr_t threadAttr;
00148
00152 ThreadData * threads;
00153
00157 bool running;
00158
00163 bool reconnect;
00164
00168 unsigned char * dataBuffer;
00169
00173 unsigned int dataSize;
00174
00183 void
00184 init ( bool reconnect ) throw ( Exception );
00185
00191 void
00192 strip ( void ) throw ( Exception );
00193
00194 protected:
00195
00201 inline
00202 MultiThreadedConnector ( void ) throw ( Exception )
00203 {
00204 throw Exception( __FILE__, __LINE__);
00205 }
00206
00207
00208 public:
00209
00219 inline
00220 MultiThreadedConnector ( Source * source,
00221 bool reconnect )
00222 throw ( Exception )
00223 : Connector( source )
00224 {
00225 init(reconnect);
00226 }
00227
00238 inline
00239 MultiThreadedConnector ( Source * source,
00240 Sink * sink,
00241 bool reconnect )
00242 throw ( Exception )
00243 : Connector( source, sink)
00244 {
00245 init(reconnect);
00246 }
00247
00254 MultiThreadedConnector ( const MultiThreadedConnector & connector )
00255 throw ( Exception );
00256
00262 inline virtual
00263 ~MultiThreadedConnector( void ) throw ( Exception )
00264 {
00265 strip();
00266 }
00267
00275 virtual MultiThreadedConnector &
00276 operator= ( const MultiThreadedConnector & connector )
00277 throw ( Exception );
00278
00285 virtual bool
00286 open ( void ) throw ( Exception );
00287
00310 virtual unsigned int
00311 transfer ( unsigned long bytes,
00312 unsigned int bufSize,
00313 unsigned int sec,
00314 unsigned int usec ) throw ( Exception );
00315
00321 virtual void
00322 close ( void ) throw ( Exception );
00323
00330 void
00331 sinkThread( int ixSink );
00332 };
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 #endif
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370