00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TGO4TASKHANDLER_H
00017 #define TGO4TASKHANDLER_H
00018
00019 #include "TNamed.h"
00020 #include "TGo4Command.h"
00021
00022 class TGo4ThreadManager;
00023 class TGo4ThreadHandler;
00024 class TGo4Socket;
00025 class TGo4Queue;
00026 class TGo4CommandInvoker;
00027 class TGo4TaskHandlerStatus;
00028 class TGo4DataRunnable;
00029 class TGo4StatusRunnable;
00030 class TGo4CommandRunnable;
00031
00032
00044 class TGo4TaskHandler : public TNamed {
00045
00046 public:
00047
00048 friend class TGo4TaskManager;
00049
00050 TGo4TaskHandler(const char* name, TGo4ThreadManager* threadmanager, Bool_t clientmode=kFALSE, Bool_t mastermode=kTRUE,UInt_t negotiationport=0);
00051
00052 virtual ~TGo4TaskHandler();
00053
00059 Bool_t ConnectServerChannel(const char* name, TGo4Socket* negotiator, TGo4Socket* channel, const char* host);
00060
00066 Bool_t ConnectClientChannel(const char* name, TGo4Socket * negotiator, TGo4Socket * channel, const char* host);
00067
00071 TGo4Socket* ServerRequest(const char* host="localhost");
00072
00074 Bool_t ServerLogin(TGo4Socket* connector, Go4CommandMode_t account);
00075
00079 Bool_t Connect(const char* host="localhost", TGo4Socket* negotiator=0);
00080
00081
00088 Bool_t DisConnect(Bool_t waitforclient=kTRUE);
00089
00090 TGo4ThreadManager* GetThreadManager() const { return fxThreadManager; }
00091
00099 Int_t WaitGetPort(TGo4Socket* sock);
00100
00104 void SetNegotiationPort(UInt_t port){ fuNegPort=port;}
00105
00106 TGo4Socket* GetCommandTransport() const { return fxCommandTransport; }
00107
00108 TGo4Socket* GetStatusTransport() const { return fxStatusTransport; }
00109
00110 TGo4Socket* GetDataTransport() const { return fxDataTransport; }
00111
00112 TGo4Queue* GetCommandQueue() const { return fxCommandQueue; }
00113
00114 TGo4Queue* GetStatusQueue() const { return fxStatusQueue; }
00115
00116 TGo4Queue * GetDataQueue() const { return fxDataQueue; }
00117
00118 const char* GetHostName() const { return fxHostName.Data(); }
00119
00120 const char* GetComName() const { return fxComName.Data(); }
00121
00122 const char* GetDatName() const { return fxDatName.Data(); }
00123
00124 const char* GetStatName() const { return fxStatName.Data(); }
00125
00126 Int_t GetComPort() const { return fiComPort; }
00127
00128 Int_t GetDatPort() const { return fiDatPort; }
00129
00130 Int_t GetStatPort() const { return fiStatPort; }
00131
00132 Go4CommandMode_t GetRole(){return fiRole;}
00133 void SetRole(Go4CommandMode_t role){fiRole=role;}
00134
00139 TGo4CommandInvoker* GetInvoker() const { return fxInvoker; }
00140
00142 Bool_t IsClientMode() const { return fbClientMode; }
00143
00145 Bool_t IsMasterMode() const { return fbMasterMode; }
00146
00151 void SetAborting(Bool_t isaborting=kTRUE) { fbIsAborting=isaborting; }
00152
00154 Bool_t IsAborting() const { return fbIsAborting; }
00155
00160 void SetInvoker(TGo4CommandInvoker* inv) { fxInvoker=inv; }
00161
00168 virtual TGo4TaskHandlerStatus * CreateStatus();
00169
00176 Bool_t StopTransportThreads(Bool_t wait=kTRUE);
00177
00182 void StartTransportThreads();
00183
00187 Bool_t WaitThreadStop(const char* name);
00188
00192 void CloseChannels(Option_t *opt="");
00193
00195 void ClearQueues();
00196
00197
00203 static void SetAdminAccount(const char* name, const char* passwd);
00204
00210 static void SetCtrlAccount(const char* name, const char* passwd);
00211
00217 static void SetObservAccount(const char* name, const char* passwd);
00218
00219 static const char* Get_fgcOK();
00220
00221 static const char* Get_fgcERROR();
00222
00223 static UInt_t Get_fguPORTWAITTIME();
00224
00225 static Int_t Get_fgiPORTWAITCYCLES();
00226
00227 protected:
00228
00230 static const UInt_t fguCONNECTORPORT;
00231
00233 static const Int_t fgiTHREADSTOPCYCLES;
00234
00236 static const UInt_t fguTHREADSTOPTIME;
00237
00239 static const UInt_t fguTRANSPORTCHECKDELAY;
00240
00242 static const UInt_t fguSTATUSQUEUESIZE;
00243
00245 static const UInt_t fguDATAQUEUESIZE;
00246
00248 static const UInt_t fguCOMMANDQUEUESIZE;
00249
00251 static const Text_t fgcCONNECT[];
00252
00254 static const Text_t fgcDISCONNECT[];
00255
00257 static const Text_t fgcMASTER[];
00258
00260 static const Text_t fgcSLAVE[];
00261
00262
00264 static const Text_t fgcCOMMANDTHREAD[];
00265
00267 static const Text_t fgcSTATUSTHREAD[];
00268
00270 static const Text_t fgcDATATHREAD[];
00271
00272
00273 private:
00274 TGo4TaskHandler();
00275
00276
00281 static TNamed fgxADMINISTRATORACCOUNT;
00282
00283
00288 static TNamed fgxOBSERVERACCOUNT;
00289
00294 static TNamed fgxCONTROLLERACCOUNT;
00295
00297 static const char* fgcERROR;
00298
00300 static const char* fgcOK;
00301
00303 static const UInt_t fguPORTWAITTIME;
00304
00306 static const Int_t fgiPORTWAITCYCLES;
00307
00309 Bool_t fbClientMode;
00310
00312 Bool_t fbMasterMode;
00313
00315 Bool_t fbIsAborting;
00316
00318 TGo4ThreadManager* fxThreadManager;
00319
00326 TGo4ThreadHandler* fxThreadHandler;
00327
00329 TGo4CommandInvoker* fxInvoker;
00330
00332 TGo4Queue* fxCommandQueue;
00333 TGo4Queue* fxStatusQueue;
00334 TGo4Queue* fxDataQueue;
00335
00337 TGo4Socket* fxCommandTransport;
00338 TGo4Socket* fxStatusTransport;
00339 TGo4Socket* fxDataTransport;
00340
00342 TString fxComName;
00343
00345 TString fxStatName;
00346
00348 TString fxDatName;
00349
00351 TString fxHostName;
00352
00354 UInt_t fuNegPort;
00355
00357 Int_t fiComPort;
00358
00360 Int_t fiStatPort;
00361
00363 Int_t fiDatPort;
00364
00365
00370 Go4CommandMode_t fiRole;
00371
00375 TGo4StatusRunnable* fxStatusRun;
00376
00380 TGo4DataRunnable* fxDataRun;
00381
00385 TGo4CommandRunnable* fxCommandRun;
00386
00387
00388 };
00389
00390 #endif //TGO4TASKHANDLER_H
00391
00392