GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
TGo4Task.h
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#ifndef TGO4TASK_H
15#define TGO4TASK_H
16
17#include "TGo4ThreadManager.h"
18#include "TGo4CommandReceiver.h"
20#include "TString.h"
21
22class TMutex;
23class TGo4TaskOwner;
24class TGo4Slave;
25class TGo4Master;
26class TGo4BufferQueue;
27class TGo4ObjectQueue;
28class TGo4TaskHandler;
31class TGo4Command;
32class TGo4Status;
33class TGo4TaskStatus;
34
38
39class TGo4Task : public TGo4ThreadManager, public TGo4CommandReceiver {
40
41public:
42 friend class TGo4LocalCommandRunnable; // access to command queue
43 friend class TGo4Slave; // access to UpdateStatus
44 friend class TGo4TaskOwner; // set workisstopped flag
45
46 TGo4Task(const char *name, Bool_t blockingmode,
47 Bool_t autostart = kFALSE,
48 Bool_t autocreate = kTRUE,
49 Bool_t ismaster = kFALSE);
50
51 virtual ~TGo4Task();
52
57 virtual void Start();
58
63 virtual void Stop();
64
70 virtual void Quit();
71
77 virtual void KillMain();
78
84 virtual void RestartMain();
85
86 void Terminate (Bool_t termapp=kTRUE) override;
87
89 void TerminateFast() override;
90
95 virtual void ExecuteString(const char *command);
96
97 Bool_t IsMaster() const { return fbCommandMaster; }
98
102
103 virtual TGo4TaskHandler *GetTaskHandler() { return nullptr; }
104
105 virtual TGo4BufferQueue *GetCommandQueue(const char *task = nullptr) { return nullptr; }
106
107 virtual TGo4BufferQueue *GetStatusQueue(const char *task = nullptr) { return nullptr; }
108
109 virtual TGo4BufferQueue *GetDataQueue(const char *task = nullptr) { return nullptr; }
110
117
123
130 TGo4Status *NextStatus(Bool_t wait = kTRUE);
131
138 TObject *NextObject(Bool_t wait = kTRUE);
139
142
146 void SendObject(TObject *obj, const char *receiver = nullptr);
147
151 virtual void SendStatus(TGo4Status *stat, const char *receiver = nullptr);
152
154 virtual void SendStatusBuffer();
155
159
166 void SendStatusMessage(Int_t level, Bool_t printout, const char *text, ...)
167 #if defined(__GNUC__) && !defined(__CLING__)
168 __attribute__((format(printf, 4, 5)))
169 #endif
170 ;
171
179
184 Int_t Initialization() override;
185
193
197 Bool_t SubmitCommand(const char *name);
198
203
208 Bool_t SubmitEmergencyData(Go4EmergencyCommand_t val, const char *receiver = nullptr);
209
210
214
218
223 TGo4Command *MakeCommand(const char *name);
224
233 void WakeCommandQueue(Int_t id = 0);
234
241 virtual Int_t StartWorkThreads();
242
248 virtual Int_t StopWorkThreads();
249
250 Bool_t IsWorkStopped() const { return fbWorkIsStopped; }
251
257 virtual void GetStatus();
258
259 const char *GetCommanderName() const { return fxCommanderName.Data(); }
260
261 TGo4Master *GetMaster() const { return fxMaster; }
262
263 TGo4Slave *GetSlave() const { return fxSlave; }
264
272 void SendStopBuffers(const char *taskname = nullptr);
273
276 TBuffer *GetAbortBuffer(){return fxAbortBuffer;}
277
278 static Int_t Get_fgiTERMID();
279
280 protected:
281
284
287
294 virtual void UpdateStatus(TGo4TaskStatus *state);
295
297
298 void SetMaster(Bool_t on = kTRUE) { fbCommandMaster = on; }
299
300 void SetWorkIsStopped(Bool_t on) { fbWorkIsStopped = on; }
301
303 TMutex *fxStatusMutex{nullptr};
304
306 TBuffer *fxStatusBuffer{nullptr};
307
308 private:
309
311
313
316
319
323 Bool_t fbCommandMaster{kFALSE};
324
326 TString fxCommanderName;
327
329 TGo4Master *fxMaster{nullptr};
330
332 TGo4Slave *fxSlave{nullptr};
333
335 TGo4TaskOwner *fxOwner{nullptr};
336
338 Bool_t fbWorkIsStopped{kFALSE};
339
341 TBuffer *fxStopBuffer{nullptr};
342
344 TBuffer *fxQuitBuffer{nullptr};
345
347 TBuffer *fxAbortBuffer{nullptr};
348
350 static const Int_t fgiTERMID;
351
352 ClassDefOverride(TGo4Task,1)
353};
354
355#endif //TGO4TASK_H
Go4EmergencyCommand_t
Class containing a pointer queue for TBuffers.
This is the Go4 Abstract Command Class; part of the Base command pattern.
Definition TGo4Command.h:35
Master.
Definition TGo4Master.h:27
Class containing a pointer queue for objects.
Baseclass for all slave process entities.
Definition TGo4Slave.h:33
Class containing all command prototypes of the TaskHandler system commands (and the basic test comman...
This class is responsible for the interconnection of two tasks: provided are three communication chan...
Baseclass for all instances that can own a TGo4Task.
Task status.
Go4 Task.
Definition TGo4Task.h:39
Int_t Initialization() override
Overrides the ThreadManager Initialization; is used to setup the client connections on demand; checks...
virtual void UpdateStatus(TGo4TaskStatus *state)
method needed by method CreateStatus of any status subclasses to set the values of the clienttask spe...
TBuffer * GetAbortBuffer()
Use preallocated abort buffer to stop remote socket wait from taskhandler itself.
Definition TGo4Task.h:276
TBuffer * fxStopBuffer
this buffer is used for stop message for threads
Definition TGo4Task.h:341
TString fxCommanderName
remember name of localcommand thread
Definition TGo4Task.h:326
TGo4Master * fxMaster
0..1
Definition TGo4Task.h:329
TGo4Task(const char *name, Bool_t blockingmode, Bool_t autostart=kFALSE, Bool_t autocreate=kTRUE, Bool_t ismaster=kFALSE)
TMutex * fxStatusMutex
Mutex protecting status buffer between main and watch thread.
Definition TGo4Task.h:303
Bool_t SubmitEmergencyCommand(Go4EmergencyCommand_t val)
send emergency quit command to the current client task
void SetMaster(Bool_t on=kTRUE)
Definition TGo4Task.h:298
static Int_t Get_fgiTERMID()
virtual void GetStatus()
Send current status information of the task to the master; may be re-implemented by application subcl...
virtual TGo4TaskHandlerCommandList * CreateCommandList()
factory method for command list; overridden by implementation
TGo4ObjectQueue * GetLocalCommandQueue()
Definition TGo4Task.h:296
void SendStopBuffers(const char *taskname=nullptr)
Send message buffers with stop values into queues and via socket connections.
void Terminate(Bool_t termapp=kTRUE) override
deletes the Manager instance via Control timer.
friend class TGo4TaskOwner
Definition TGo4Task.h:44
void AddUserCommandList(TGo4CommandProtoList *comlist)
Add a user command list to the existing command list.
virtual void Stop()
General stop method of client application to be called from remote command; should be re-implemented ...
Bool_t SubmitCommand(const char *name)
send command specified by name to the current client task
void SetOwner(TGo4TaskOwner *owner)
Set owner object and switch automatically in master or slave mode, depending on owner type.
virtual void RestartMain()
Restart the main thread; method to be called from command, should be overridden in user implementatio...
virtual TGo4BufferQueue * GetDataQueue(const char *task=nullptr)
Definition TGo4Task.h:109
TGo4Slave * fxSlave
0..1
Definition TGo4Task.h:332
const char * GetCommanderName() const
Definition TGo4Task.h:259
virtual void KillMain()
Kill the main thread; method to be called from command, should be overridden in user implementation.
TGo4Command * MakeCommand(const char *name)
Method using internal command prototype list to produce a clone of the specified command.
void SetSlave(TGo4Slave *s)
virtual Int_t StartWorkThreads()
start the working threads of the task implementation; this method is used after the current connectio...
friend class TGo4LocalCommandRunnable
Definition TGo4Task.h:42
TGo4TaskOwner * fxOwner
0..1
Definition TGo4Task.h:335
Bool_t SubmitLocalCommand(TGo4Command *com)
Send given command to the current client task.
void SetMaster(TGo4Master *m)
void SendStatusMessage(Int_t level, Bool_t printout, const char *text,...)
Send message string in a status object to the gui.
void SetWorkIsStopped(Bool_t on)
Definition TGo4Task.h:300
TBuffer * fxAbortBuffer
this buffer is used for emergency socket aborting
Definition TGo4Task.h:347
virtual TGo4BufferQueue * GetStatusQueue(const char *task=nullptr)
Definition TGo4Task.h:107
TGo4Status * NextStatus(Bool_t wait=kTRUE)
Delivers next status object from status queue.
void AddUserCommand(TGo4Command *com)
Add a user command object to the existing command list.
static const Int_t fgiTERMID
Id number of dummy command that wakes the command queue on termination.
Definition TGo4Task.h:350
virtual TGo4TaskStatus * CreateStatus()
create a status object with information on the current (slave) task.
void SendObject(TObject *obj, const char *receiver=nullptr)
Send object via data channel to the master.
Bool_t SubmitEmergencyData(Go4EmergencyCommand_t val, const char *receiver=nullptr)
Send emergency command via data channel.
TGo4Slave * GetSlave() const
Definition TGo4Task.h:263
virtual void Quit()
Quit the client; method to be called from command object, may be overridden in user implementation.
Bool_t fbWorkIsStopped
True if user work threads are stopped for connection change.
Definition TGo4Task.h:338
Bool_t IsMaster() const
Definition TGo4Task.h:97
TGo4ObjectQueue * fxLocalCommandQueue
queue for the server side local commands, submitted by the gui or cli
Definition TGo4Task.h:318
TBuffer * fxQuitBuffer
this buffer is used for quit command
Definition TGo4Task.h:344
Bool_t fbCommandMaster
This flag indicates the main state of the task: either master (sends commands, receives data and stat...
Definition TGo4Task.h:323
TGo4TaskHandlerCommandList * GetPrototype()
get pointer to currently valid command list
virtual TGo4TaskHandler * GetTaskHandler()
Definition TGo4Task.h:103
virtual ~TGo4Task()
virtual void SendStatus(TGo4Status *stat, const char *receiver=nullptr)
Send status object via status channel to the master.
void TerminateFast() override
Overwrites the Threadmanager TerminateFast to shutdown the objectserver properly.
virtual void Start()
General start method of client application to be called from remote command; should be re-implemented...
void UpdateStatusBuffer()
Create status object and stream it into the status send buffer.
friend class TGo4Slave
Definition TGo4Task.h:43
TBuffer * fxStatusBuffer
Buffer containing the analysis status which is updated by the main thread.
Definition TGo4Task.h:306
virtual void ExecuteString(const char *command)
Execute string command.
virtual TGo4Command * NextCommand()
Delivers next command from command queue.
TMutex * GetStatusBufferMutex()
Access to the mutex of status buffer.
Definition TGo4Task.h:158
TGo4Master * GetMaster() const
Definition TGo4Task.h:261
Bool_t IsWorkStopped() const
Definition TGo4Task.h:250
TObject * NextObject(Bool_t wait=kTRUE)
Delivers next object from data queue.
virtual void SendStatusBuffer()
Send internal status buffer to the master(s).
Bool_t SubmitCommand(TGo4Command *com)
send given command to the current client task.
TGo4TaskHandlerCommandList * fxCommandPrototype
the command list which holds all command prototypes
Definition TGo4Task.h:315
virtual TGo4BufferQueue * GetCommandQueue(const char *task=nullptr)
Definition TGo4Task.h:105
virtual Int_t StopWorkThreads()
stop the working threads of the task implementation; this method is used before the current connectio...
void WakeCommandQueue(Int_t id=0)
Put dummy object into command queue to wake up user threads which might wait for a command.
Go4 thread manager.