00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TGO4TASK_H
00017 #define TGO4TASK_H
00018
00019 #include "TGo4ThreadManager.h"
00020 #include "TGo4CommandReceiver.h"
00021 #include "Go4EmergencyCommands.h"
00022
00023 #include "TString.h"
00024
00025 class TMutex;
00026 class TGo4TaskOwner;
00027 class TGo4Slave;
00028 class TGo4Master;
00029 class TGo4BufferQueue;
00030 class TGo4ObjectQueue;
00031 class TGo4TaskHandler;
00032 class TGo4TaskHandlerCommandList;
00033 class TGo4CommandProtoList;
00034 class TGo4Command;
00035 class TGo4Status;
00036 class TGo4TaskStatus;
00037
00038 class TGo4Task : public TGo4ThreadManager, public TGo4CommandReceiver {
00039
00040 public:
00041 friend class TGo4LocalCommandRunnable;
00042 friend class TGo4Slave;
00043 friend class TGo4TaskOwner;
00044
00045 TGo4Task(const char* name, Bool_t blockingmode,
00046 Bool_t autostart=kFALSE,
00047 Bool_t autocreate=kTRUE,
00048 Bool_t ismaster=kFALSE);
00049
00050 virtual ~TGo4Task();
00051
00056 virtual void Start();
00057
00062 virtual void Stop();
00063
00069 virtual void Quit();
00070
00076 virtual void KillMain();
00077
00083 virtual void RestartMain();
00084
00085 virtual void Terminate (Bool_t termapp=kTRUE);
00086
00088 virtual void TerminateFast ();
00089
00094 virtual void ExecuteString(const Text_t* command);
00095
00096 Bool_t IsMaster() { return fbCommandMaster; }
00097
00100 void SetOwner(TGo4TaskOwner* owner);
00101
00102 virtual TGo4TaskHandler* GetTaskHandler();
00103
00104 virtual TGo4BufferQueue* GetCommandQueue(const char* task=0);
00105
00106 virtual TGo4BufferQueue* GetStatusQueue(const char* task=0);
00107
00108 virtual TGo4BufferQueue* GetDataQueue(const char* task=0);
00109
00115 void AddUserCommand(TGo4Command* com);
00116
00121 void AddUserCommandList(TGo4CommandProtoList * comlist);
00122
00129 TGo4Status* NextStatus(Bool_t wait=kTRUE);
00130
00137 TObject * NextObject(Bool_t wait=kTRUE);
00138
00140 virtual TGo4Command* NextCommand();
00141
00145 void SendObject(TObject * obj, const char* receiver=0);
00146
00150 virtual void SendStatus(TGo4Status * stat, const char* receiver=0);
00151
00153 virtual void SendStatusBuffer();
00154
00157 TMutex* GetStatusBufferMutex(){return fxStatusMutex;}
00158
00165 void SendStatusMessage(Int_t level, Bool_t printout, const char* text, ...);
00166
00173 void UpdateStatusBuffer();
00174
00179 virtual Int_t Initialization();
00180
00187 virtual TGo4TaskStatus* CreateStatus();
00188
00192 Bool_t SubmitCommand(const char* name);
00193
00197 Bool_t SubmitEmergencyCommand(Go4EmergencyCommand_t val);
00198
00203 Bool_t SubmitEmergencyData(Go4EmergencyCommand_t val, const char* receiver=0);
00204
00205
00208 Bool_t SubmitLocalCommand(TGo4Command* com);
00209
00212 Bool_t SubmitCommand(TGo4Command* com);
00213
00218 TGo4Command* MakeCommand(const char* name);
00219
00228 void WakeCommandQueue(Int_t id=0);
00229
00236 virtual Int_t StartWorkThreads();
00237
00243 virtual Int_t StopWorkThreads();
00244
00245 Bool_t IsWorkStopped(){return fbWorkIsStopped;}
00246
00249 virtual void LockAll();
00250
00253 virtual void UnLockAll();
00254
00255
00261 virtual void GetStatus();
00262
00263 const char* GetCommanderName() const { return fxCommanderName.Data(); }
00264
00265 TGo4Master* GetMaster() { return fxMaster; }
00266
00267 TGo4Slave* GetSlave() { return fxSlave; }
00268
00276 void SendStopBuffers(const char* taskname=0);
00277
00280 TBuffer* GetAbortBuffer(){return fxAbortBuffer;}
00281
00282 static Int_t Get_fgiTERMID();
00283
00284 protected:
00285
00287 virtual TGo4TaskHandlerCommandList* CreateCommandList();
00288
00290 TGo4TaskHandlerCommandList * GetPrototype();
00291
00298 virtual void UpdateStatus(TGo4TaskStatus* state);
00299
00300 TGo4ObjectQueue* GetLocalCommandQueue() { return fxLocalCommandQueue; }
00301
00302 void SetMaster(Bool_t on=kTRUE) { fbCommandMaster=on; }
00303
00304 void SetWorkIsStopped(Bool_t on) { fbWorkIsStopped=on; }
00305
00307 TMutex * fxStatusMutex;
00308
00310 TBuffer* fxStatusBuffer;
00311
00312 private:
00313
00314 void SetMaster(TGo4Master* m);
00315
00316 void SetSlave(TGo4Slave* s);
00317
00319 TGo4TaskHandlerCommandList * fxCommandPrototype;
00320
00322 TGo4ObjectQueue* fxLocalCommandQueue;
00323
00327 Bool_t fbCommandMaster;
00328
00330 TString fxCommanderName;
00331
00333 TGo4Master * fxMaster;
00334
00336 TGo4Slave * fxSlave;
00337
00339 TGo4TaskOwner * fxOwner;
00340
00342 Bool_t fbWorkIsStopped;
00343
00344
00346 TBuffer* fxStopBuffer;
00347
00349 TBuffer* fxQuitBuffer;
00350
00352 TBuffer* fxAbortBuffer;
00353
00355 static const Int_t fgiTERMID;
00356
00357
00358 ClassDef(TGo4Task,1)
00359 };
00360
00361 #endif //TGO4TASK_H
00362
00363