Gizmo3D

gzPipe.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // File         : gzPipe.h
00003 // Module       : gzBase
00004 // Description  : Class definition of Pipes classes
00005 // Author       : Anders Modén      
00006 // Product      : GizmoBase 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training System AB, Sweden
00009 //          
00010 // NOTE:    GizmoBase is a platform abstraction utility layer for C++. It contains 
00011 //          design patterns and C++ solutions for the advanced programmer.
00012 //
00013 //
00014 // Revision History...                          
00015 //                                  
00016 // Who  Date    Description                     
00017 //                                  
00018 // AMO  030912  Created file    
00019 //
00020 // ******************************************************************************
00021 
00022 #ifndef __GZ_PIPE_H__
00023 #define __GZ_PIPE_H__
00024 
00025 #include "gzBasicTypes.h"
00026 #include "gzMemory.h"
00027 #include "gzDynamic.h"
00028 #include "gzThread.h"
00029 #include "gzNotify.h"
00030 
00036 class gzPipe; // Forward decl
00037 
00038 class gzSocket; // Forward decl (from gzNetwork.h)
00039 
00040 
00042 enum gzPipeConnection
00043 {
00044     GZ_PIPE_LOCAL,
00045     GZ_PIPE_GLOBAL
00046 };
00047 
00048 
00049 //******************************************************************************
00050 // Class    : gzPipeData
00051 //                                  
00052 // Purpose  : A data container used by the gzPipeServer
00053 //                                  
00054 // Notes    : - 
00055 //                                  
00056 // Revision History...                          
00057 //                                  
00058 // Who  Date    Description                     
00059 //                                  
00060 // AMO  030917  Created 
00061 //                                  
00062 //******************************************************************************
00063 class gzPipeData
00064 {
00065 public:
00066 
00067     gzUByte *adress;
00068 
00069     gzULong len;
00070 };
00071 
00072 typedef gzPipeData * gzPipeDataPtr;
00073 
00074 
00075 //******************************************************************************
00076 // Class    : gzPipeRecieveDataInterface
00077 //                                  
00078 // Purpose  : Interface to receive data from a pipe through a callback
00079 //                                  
00080 // Notes    : - 
00081 //                                  
00082 // Revision History...                          
00083 //                                  
00084 // Who  Date    Description                     
00085 //                                  
00086 // AMO  030917  Created 
00087 //                                  
00088 //******************************************************************************
00090 
00094 class gzPipeRecieveDataInterface : public gzNotifySlave<gzPipe,gzPipeRecieveDataInterface,gzPipeDataPtr>
00095 {
00096 public:
00097 
00099     virtual GZ_BASE_EXPORT gzVoid onPipeRecieveData(gzPipe *pipe, gzUByte *adress , gzULong len)=0;
00100 
00102     virtual GZ_BASE_EXPORT gzVoid onPipeTerminate(gzPipe *pipe){};
00103 
00104 
00106     gzVoid GZ_BASE_EXPORT onNotify(gzPipe *notifier,gzPipeDataPtr &data,gzULong senderClass);
00107 
00108 };
00109 
00110 //******************************************************************************
00111 // Class    : gzPipeConnectionInterface
00112 //                                  
00113 // Purpose  : Controls the connection
00114 //                                  
00115 // Notes    : - 
00116 //                                  
00117 // Revision History...                          
00118 //                                  
00119 // Who  Date    Description                     
00120 //                                  
00121 // AMO  030917  Created 
00122 //                                  
00123 //******************************************************************************
00124 class gzPipeControlInterface
00125 {
00126 public:
00127         // Connection management
00128     GZ_BASE_EXPORT virtual gzBool   onPipeOpenRequest(const gzString &pipeID , const gzString &optionString)    { return TRUE; }
00129     GZ_BASE_EXPORT virtual gzBool   onPipeOpenAck(const gzString &pipeID , const gzString &optionString)        { return TRUE; }
00130 };
00131 
00132 //******************************************************************************
00133 // Class    : gzPipe
00134 //                                  
00135 // Purpose  : Actual named pipe implementation
00136 //                                  
00137 // Notes    : - 
00138 //                                  
00139 // Revision History...                          
00140 //                                  
00141 // Who  Date    Description                     
00142 //                                  
00143 // AMO  030917  Created 
00144 //                                  
00145 //******************************************************************************
00147 
00154 class gzPipe : public gzThread , public gzNotifyMaster<gzPipe,gzPipeRecieveDataInterface,gzPipeDataPtr> , public gzSerializeAdapter , public gzMutex
00155 {
00156 public:
00157 
00158     GZ_BASE_EXPORT gzPipe(gzPipeControlInterface *pipeControl=NULL);
00159 
00160     GZ_BASE_EXPORT virtual ~gzPipe();
00161 
00163 
00164     GZ_BASE_EXPORT gzBool connect( const gzString &name, gzBool create=FALSE, gzPipeConnection connection=GZ_PIPE_GLOBAL, gzULong timeOutRetry=50 , const gzString &optionString=GZ_EMPTY_STRING);
00165 
00167     GZ_BASE_EXPORT gzBool createPipe(const gzUShort port,gzULong timeOutRetry=50);
00168 
00170     GZ_BASE_EXPORT gzBool openPipe(const gzString &address,gzUShort port,gzULong timeOutRetry=50);
00171 
00173 
00174     GZ_BASE_EXPORT gzBool isConnected();
00175 
00177     GZ_BASE_EXPORT gzVoid disconnect(gzBool waitForRemoteConnection=TRUE);
00178 
00180     GZ_BASE_EXPORT gzULong writePipe(gzUByte *adress, gzULong len);
00181 
00183 
00184     GZ_BASE_EXPORT gzULong readPipe( gzUByte *adress, gzULong maxlen, gzBool blocking=TRUE);
00185 
00187     GZ_BASE_EXPORT gzULong pendingBytes();
00188 
00189     
00190     // Serialize interface
00191 
00192     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte data);
00193 
00194     GZ_BASE_EXPORT virtual gzUByte  read_imp();
00195 
00196     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte *data, gzULong count);
00197     
00198     GZ_BASE_EXPORT virtual gzULong  read_imp(gzUByte *data, gzULong maxcount);
00199     
00200     GZ_BASE_EXPORT virtual gzULong  length_imp();
00201 
00202     // properties
00203 
00204     GZ_PROPERTY_GET_EXPORT( gzString,       PipeName,       GZ_BASE_EXPORT);
00205     GZ_PROPERTY_GET_EXPORT( gzString,       PipeID,         GZ_BASE_EXPORT);
00206     GZ_PROPERTY_GET_EXPORT( gzString,       RemotePipeID,   GZ_BASE_EXPORT);
00207 
00208     GZ_PROPERTY_GET_EXPORT( gzUShort,       PipePort,       GZ_BASE_EXPORT);
00209     GZ_PROPERTY_GET_EXPORT( gzBool,         DirectConnect,  GZ_BASE_EXPORT);
00210 
00211 private:
00212 
00213     gzBool createNamedPipe(gzULong timeOutRetry);
00214     gzBool openNamedPipe(gzULong timeOutRetry);
00215 
00216     GZ_BASE_EXPORT virtual gzVoid process();
00217 
00218     gzSocket*                           m_pipeSocket;
00219 
00220     gzBool                              m_createPipe;
00221 
00222     gzPipeConnection                    m_connection:8;
00223 
00224     gzList<gzPipeRecieveDataInterface>  m_subscribers;
00225 
00226     gzString                            m_optionString;
00227 
00228     gzPipeControlInterface              *m_pipeControl;
00229     
00230     gzULong                             m_pipeRequestID;
00231 
00232     static gzMutex                      s_lastRequestIDLocker;
00233 
00234     static gzDict<gzString,gzVoid>      s_lastRequestID;
00235 
00236     static  gzMutex                     s_pipePortLocker;
00237 
00238     static gzQueue<gzUShort>            s_pipePortStack;
00239 
00240     static gzBool                       s_pipePortStackInitialised;
00241 };
00242 
00243 
00244 //******************************************************************************
00245 // Class    : gzPipeServer
00246 //                                  
00247 // Purpose  : Actual named pipe server implementation. Echoes between all pipes
00248 //                                  
00249 // Notes    : - 
00250 //                                  
00251 // Revision History...                          
00252 //                                  
00253 // Who  Date    Description                     
00254 //                                  
00255 // AMO  030917  Created 
00256 //                                  
00257 //******************************************************************************
00259 
00264 class gzPipeServer : public gzThread , public gzPipeRecieveDataInterface , public gzPipeControlInterface
00265 {
00266 public:
00267 
00268     GZ_BASE_EXPORT gzPipeServer(const gzString &pipeName);
00269 
00270     GZ_BASE_EXPORT virtual ~gzPipeServer();
00271 
00272     GZ_BASE_EXPORT gzVoid doEchoPipeData(gzBool on);
00273 
00274     GZ_BASE_EXPORT virtual gzVoid stop(gzBool waitForStop=FALSE);
00275 
00276 protected:
00277 
00278     virtual GZ_BASE_EXPORT gzVoid onPipeRecieveData(gzPipe *pipe, gzUByte *adress , gzULong len);
00279 
00280     virtual GZ_BASE_EXPORT gzVoid onPipeTerminate(gzPipe *pipe);
00281 
00282     virtual gzVoid process();
00283 
00284     gzString                m_pipeName; 
00285 
00286     gzRefList<gzPipe>       m_pipeList;
00287 
00288     gzMutex                 m_pipeListLocker;
00289 
00290     gzBool                  m_checkPipeRemoval:1;
00291 
00292     gzBool                  m_doEchoPipeData:1;
00293 
00294 };
00295 
00296 
00297 //******************************************************************************
00298 // Class    : gzPipeURLServer
00299 //                                  
00300 // Purpose  : Works like a pipe URL server on remote hosts
00301 //                                  
00302 // Notes    : - 
00303 //                                  
00304 // Revision History...                          
00305 //                                  
00306 // Who  Date    Description                     
00307 //                                  
00308 // AMO  030917  Created 
00309 //                                  
00310 //******************************************************************************
00311 class gzPipeURLServer : public gzPipeServer
00312 {
00313 public:
00314 
00315     GZ_BASE_EXPORT gzPipeURLServer(const gzString &pipeName);
00316 
00317     GZ_BASE_EXPORT virtual ~gzPipeURLServer();
00318 
00319 protected:
00320 
00321     GZ_BASE_EXPORT virtual gzBool   onPipeOpenRequest(const gzString &pipeID , const gzString &optionString);
00322     GZ_BASE_EXPORT virtual gzBool   onPipeOpenAck(const gzString &pipeID , const gzString &optionString);
00323 
00324     virtual GZ_BASE_EXPORT gzVoid onPipeRecieveData(gzPipe *pipe, gzUByte *adress , gzULong len);
00325 };
00326 
00327 #endif // __GZ_PIPE_H__

Documentation for Gizmo3D generated at Wed Feb 20 11:54:08 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond