Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

MultiThreadedConnector.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : MultiThreadedConnector.h
00008    Version  : $Revision: 1.5 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/MultiThreadedConnector.h,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 /* ============================================================ include files */
00038 
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042 
00043 // check for __NetBSD__ because it won't be found by AC_CHECK_HEADER on NetBSD
00044 // as pthread.h is in /usr/pkg/include, not /usr/include
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 /* ================================================================ constants */
00060 
00061 
00062 /* =================================================================== macros */
00063 
00064 
00065 /* =============================================================== data types */
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 /* ================================================= external data structures */
00336 
00337 
00338 /* ====================================================== function prototypes */
00339 
00340 
00341 
00342 #endif  /* MULTI_THREADED_CONNECTOR_H */
00343 
00344 
00345 /*------------------------------------------------------------------------------
00346  
00347   $Source: /cvsroot/darkice/darkice/src/MultiThreadedConnector.h,v $
00348 
00349   $Log: MultiThreadedConnector.h,v $
00350   Revision 1.5  2005/04/11 19:27:43  darkeye
00351   added option to turn off automatic reconnect feature
00352 
00353   Revision 1.4  2004/02/23 19:12:52  darkeye
00354   ported to NetBSD
00355 
00356   Revision 1.3  2002/11/26 21:41:20  darkeye
00357   bugfix: MultiThreadedConnector::sinkThread() was private, now public
00358 
00359   Revision 1.2  2002/10/19 13:35:21  darkeye
00360   when a connection is dropped, DarkIce tries to reconnect, indefinitely
00361   removed extreme event reporting for thread-related events
00362 
00363   Revision 1.1  2002/10/19 12:25:47  darkeye
00364   changed internals so that now each encoding/server connection is
00365   a separate thread
00366 
00367 
00368   
00369 ------------------------------------------------------------------------------*/
00370 

Generated on Thu Apr 14 13:59:12 2005 for DarkIce by  doxygen 1.4.1