GSI Object Oriented Online Offline (Go4) GO4-6.4.0
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
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
101 void SetOwner(TGo4TaskOwner* owner);
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
116 void AddUserCommand(TGo4Command *com);
117
123
130 TGo4Status *NextStatus(Bool_t wait = kTRUE);
131
138 TObject *NextObject(Bool_t wait = kTRUE);
139
141 virtual TGo4Command *NextCommand();
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
178 void UpdateStatusBuffer();
179
184 Int_t Initialization() override;
185
192 virtual TGo4TaskStatus *CreateStatus();
193
197 Bool_t SubmitCommand(const char *name);
198
203
208 Bool_t SubmitEmergencyData(Go4EmergencyCommand_t val, const char *receiver = nullptr);
209
210
213 Bool_t SubmitLocalCommand(TGo4Command *com);
214
217 Bool_t SubmitCommand(TGo4Command *com);
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
310 void SetMaster(TGo4Master *m);
311
312 void SetSlave(TGo4Slave *s);
313
316
319
323 Bool_t fbCommandMaster{kFALSE};
324
327
330
332 TGo4Slave *fxSlave{nullptr};
333
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.
Int_t Initialization() override
Overrides the ThreadManager Initialization; is used to setup the client connections on demand; checks...
Definition TGo4Task.cxx:362
virtual Int_t StopWorkThreads()
stop the working threads of the task implementation; this method is used before the current connectio...
Definition TGo4Task.cxx:554
TGo4TaskHandlerCommandList * fxCommandPrototype
the command list which holds all command prototypes
Definition TGo4Task.h:315
TBuffer * GetAbortBuffer()
Use preallocated abort buffer to stop remote socket wait from taskhandler itself.
Definition TGo4Task.h:276
TBuffer * fxQuitBuffer
this buffer is used for quit command
Definition TGo4Task.h:344
TString fxCommanderName
remember name of localcommand thread
Definition TGo4Task.h:326
static Int_t Get_fgiTERMID()
Definition TGo4Task.cxx:588
virtual TGo4Command * NextCommand()
Delivers next command from command queue.
Definition TGo4Task.cxx:325
TGo4Task(const char *name, Bool_t blockingmode, Bool_t autostart=kFALSE, Bool_t autocreate=kTRUE, Bool_t ismaster=kFALSE)
Definition TGo4Task.cxx:39
virtual void GetStatus()
Send current status information of the task to the master; may be re-implemented by application subcl...
Definition TGo4Task.cxx:536
Bool_t SubmitEmergencyCommand(Go4EmergencyCommand_t val)
send emergency quit command to the current client task
Definition TGo4Task.cxx:433
void SetMaster(Bool_t on=kTRUE)
Definition TGo4Task.h:298
static const Int_t fgiTERMID
Id number of dummy command that wakes the command queue on termination.
Definition TGo4Task.h:350
TGo4ObjectQueue * GetLocalCommandQueue()
Definition TGo4Task.h:296
void SendStopBuffers(const char *taskname=nullptr)
Send message buffers with stop values into queues and via socket connections.
Definition TGo4Task.cxx:560
void Terminate(Bool_t termapp=kTRUE) override
deletes the Manager instance via Control timer.
Definition TGo4Task.cxx:130
void AddUserCommandList(TGo4CommandProtoList *comlist)
Add a user command list to the existing command list.
Definition TGo4Task.cxx:211
Bool_t SubmitCommand(const char *name)
send command specified by name to the current client task
Definition TGo4Task.cxx:409
void SetOwner(TGo4TaskOwner *owner)
Set owner object and switch automatically in master or slave mode, depending on owner type.
Definition TGo4Task.cxx:98
virtual void SendStatus(TGo4Status *stat, const char *receiver=nullptr)
Send status object via status channel to the master.
Definition TGo4Task.cxx:246
virtual TGo4BufferQueue * GetDataQueue(const char *task=nullptr)
Definition TGo4Task.h:109
TBuffer * fxStopBuffer
this buffer is used for stop message for threads
Definition TGo4Task.h:341
const char * GetCommanderName() const
Definition TGo4Task.h:259
virtual void Stop()
General stop method of client application to be called from remote command; should be re-implemented ...
Definition TGo4Task.cxx:110
virtual TGo4TaskHandlerCommandList * CreateCommandList()
factory method for command list; overridden by implementation
Definition TGo4Task.cxx:497
virtual void SendStatusBuffer()
Send internal status buffer to the master(s).
Definition TGo4Task.cxx:263
virtual void Quit()
Quit the client; method to be called from command object, may be overridden in user implementation.
Definition TGo4Task.cxx:115
TGo4Command * MakeCommand(const char *name)
Method using internal command prototype list to produce a clone of the specified command.
Definition TGo4Task.cxx:502
friend class TGo4TaskOwner
Definition TGo4Task.h:44
void SetSlave(TGo4Slave *s)
Definition TGo4Task.cxx:92
Bool_t SubmitLocalCommand(TGo4Command *com)
Send given command to the current client task.
Definition TGo4Task.cxx:508
void SendStatusMessage(Int_t level, Bool_t printout, const char *text,...)
Send message string in a status object to the gui.
Definition TGo4Task.cxx:272
void SetWorkIsStopped(Bool_t on)
Definition TGo4Task.h:300
virtual TGo4BufferQueue * GetStatusQueue(const char *task=nullptr)
Definition TGo4Task.h:107
TBuffer * fxStatusBuffer
Buffer containing the analysis status which is updated by the main thread.
Definition TGo4Task.h:306
TBuffer * fxAbortBuffer
this buffer is used for emergency socket aborting
Definition TGo4Task.h:347
TGo4Status * NextStatus(Bool_t wait=kTRUE)
Delivers next status object from status queue.
Definition TGo4Task.cxx:160
virtual void Start()
General start method of client application to be called from remote command; should be re-implemented...
Definition TGo4Task.cxx:105
void AddUserCommand(TGo4Command *com)
Add a user command object to the existing command list.
Definition TGo4Task.cxx:206
virtual void UpdateStatus(TGo4TaskStatus *state)
method needed by method CreateStatus of any status subclasses to set the values of the clienttask spe...
Definition TGo4Task.cxx:393
friend class TGo4LocalCommandRunnable
Definition TGo4Task.h:42
virtual void RestartMain()
Restart the main thread; method to be called from command, should be overridden in user implementatio...
Definition TGo4Task.cxx:125
TGo4TaskOwner * fxOwner
0..1
Definition TGo4Task.h:335
void SendObject(TObject *obj, const char *receiver=nullptr)
Send object via data channel to the master.
Definition TGo4Task.cxx:222
Bool_t SubmitEmergencyData(Go4EmergencyCommand_t val, const char *receiver=nullptr)
Send emergency command via data channel.
Definition TGo4Task.cxx:455
TGo4Slave * GetSlave() const
Definition TGo4Task.h:263
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
virtual void ExecuteString(const char *command)
Execute string command.
Definition TGo4Task.cxx:146
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
Definition TGo4Task.cxx:154
virtual TGo4TaskHandler * GetTaskHandler()
Definition TGo4Task.h:103
void TerminateFast() override
Overwrites the Threadmanager TerminateFast to shutdown the objectserver properly.
Definition TGo4Task.cxx:138
virtual void KillMain()
Kill the main thread; method to be called from command, should be overridden in user implementation.
Definition TGo4Task.cxx:120
void UpdateStatusBuffer()
Create status object and stream it into the status send buffer.
Definition TGo4Task.cxx:308
virtual Int_t StartWorkThreads()
start the working threads of the task implementation; this method is used after the current connectio...
Definition TGo4Task.cxx:548
TGo4Slave * fxSlave
0..1
Definition TGo4Task.h:332
TMutex * fxStatusMutex
Mutex protecting status buffer between main and watch thread.
Definition TGo4Task.h:303
TMutex * GetStatusBufferMutex()
Access to the mutex of status buffer.
Definition TGo4Task.h:158
TGo4Master * GetMaster() const
Definition TGo4Task.h:261
friend class TGo4Slave
Definition TGo4Task.h:43
Bool_t IsWorkStopped() const
Definition TGo4Task.h:250
TGo4Master * fxMaster
0..1
Definition TGo4Task.h:329
TObject * NextObject(Bool_t wait=kTRUE)
Delivers next object from data queue.
Definition TGo4Task.cxx:189
virtual TGo4TaskStatus * CreateStatus()
create a status object with information on the current (slave) task.
Definition TGo4Task.cxx:402
virtual TGo4BufferQueue * GetCommandQueue(const char *task=nullptr)
Definition TGo4Task.h:105
void WakeCommandQueue(Int_t id=0)
Put dummy object into command queue to wake up user threads which might wait for a command.
Definition TGo4Task.cxx:522
virtual ~TGo4Task()
Definition TGo4Task.cxx:71
TGo4ObjectQueue * fxLocalCommandQueue
queue for the server side local commands, submitted by the gui or cli
Definition TGo4Task.h:318
TGo4ThreadManager(const TGo4ThreadManager &right)