GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4TaskHandler.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 TGO4TASKHANDLER_H
15#define TGO4TASKHANDLER_H
16
17#include "TNamed.h"
18#include "TGo4Command.h"
19
22class TGo4Socket;
23class TGo4Queue;
29
30
43class TGo4TaskHandler : public TNamed {
44
45 public:
46
47 friend class TGo4TaskManager;
48
49 TGo4TaskHandler(const char *name, TGo4ThreadManager *threadmanager, Bool_t clientmode = kFALSE, Bool_t mastermode = kTRUE, UInt_t negotiationport = 0);
50
51 virtual ~TGo4TaskHandler();
52
58 Bool_t ConnectServerChannel(const char *name, TGo4Socket *negotiator, TGo4Socket *channel, const char *host);
59
65 Bool_t ConnectClientChannel(const char *name, TGo4Socket *negotiator, TGo4Socket *channel, const char *host);
66
70 TGo4Socket *ServerRequest(const char *host = "localhost");
71
73 Bool_t ServerLogin(TGo4Socket *connector, Go4CommandMode_t account);
74
78 Bool_t Connect(const char *host="localhost", TGo4Socket *negotiator = nullptr);
79
86 Bool_t DisConnect(Bool_t waitforclient = kTRUE);
87
89
97 Int_t WaitGetPort(TGo4Socket *sock);
98
102 void SetNegotiationPort(UInt_t port){ fuNegPort=port;}
103
105
107
109
111
113
114 TGo4Queue *GetDataQueue() const { return fxDataQueue; }
115
116 const char *GetHostName() const { return fxHostName.Data(); }
117
118 const char *GetComName() const { return fxComName.Data(); }
119
120 const char *GetDatName() const { return fxDatName.Data(); }
121
122 const char *GetStatName() const { return fxStatName.Data(); }
123
124 Int_t GetComPort() const { return fiComPort; }
125
126 Int_t GetDatPort() const { return fiDatPort; }
127
128 Int_t GetStatPort() const { return fiStatPort; }
129
132
138
140 Bool_t IsClientMode() const { return fbClientMode; }
141
143 Bool_t IsMasterMode() const { return fbMasterMode; }
144
149 void SetAborting(Bool_t isaborting=kTRUE) { fbIsAborting=isaborting; }
150
152 Bool_t IsAborting() const { return fbIsAborting; }
153
159
167
174 Bool_t StopTransportThreads(Bool_t wait=kTRUE);
175
181
185 Bool_t WaitThreadStop(const char *name);
186
190 void CloseChannels(Option_t *opt = "");
191
193 void ClearQueues();
194
195
201 static void SetAdminAccount(const char *name, const char *passwd);
202
208 static void SetCtrlAccount(const char *name, const char *passwd);
209
215 static void SetObservAccount(const char *name, const char *passwd);
216
217 static const char *Get_fgcOK();
218
219 static const char *Get_fgcERROR();
220
221 static UInt_t Get_fguPORTWAITTIME();
222
223 static Int_t Get_fgiPORTWAITCYCLES();
224
225 protected:
226
228 static const UInt_t fguCONNECTORPORT;
229
231 static const Int_t fgiTHREADSTOPCYCLES;
232
234 static const UInt_t fguTHREADSTOPTIME;
235
237 static const UInt_t fguTRANSPORTCHECKDELAY;
238
240 static const UInt_t fguSTATUSQUEUESIZE;
241
243 static const UInt_t fguDATAQUEUESIZE;
244
246 static const UInt_t fguCOMMANDQUEUESIZE;
247
249 static const char *fgcCONNECT;
250
252 static const char *fgcDISCONNECT;
253
255 static const char *fgcMASTER;
256
258 static const char *fgcSLAVE;
259
261 static const char *fgcCOMMANDTHREAD;
262
264 static const char *fgcSTATUSTHREAD;
265
267 static const char *fgcDATATHREAD;
268
269
270 private:
272
278
283 static TNamed fgxOBSERVERACCOUNT;
284
289 static TNamed fgxCONTROLLERACCOUNT;
290
292 static const char *fgcERROR;
293
295 static const char *fgcOK;
296
298 static const UInt_t fguPORTWAITTIME;
299
301 static const Int_t fgiPORTWAITCYCLES;
302
304 Bool_t fbClientMode{kFALSE};
305
307 Bool_t fbMasterMode{kFALSE};
308
310 Bool_t fbIsAborting{kFALSE};
311
314
322
325
330
335
337 TString fxComName;
338
340 TString fxStatName;
341
343 TString fxDatName;
344
346 TString fxHostName;
347
349 UInt_t fuNegPort{0};
350
352 Int_t fiComPort{0};
353
355 Int_t fiStatPort{0};
356
358 Int_t fiDatPort{0};
359
365
370
375
380
381};
382
383#endif //TGO4TASKHANDLER_H
Go4CommandMode_t
These values define command execution rights.
Definition TGo4Command.h:27
Class that knows Command Object; When Client gets the Command it is passed to the Invoker who sets th...
Runnable responsible for command exchange between transport (socket) and buffer (queue) In receiver m...
Runnable responsible for data object exchange between transport (socket) and buffer (queue) In receiv...
Base class for all threadsafe pointer queues.
Definition TGo4Queue.h:31
Runnable responsible for status object exchange between transport (socket) and buffer (queue) In rece...
Int_t GetDatPort() const
friend class TGo4TaskManager
void SetAborting(Bool_t isaborting=kTRUE)
sets the internal aborting state of this taskhandler instance; will be checked before an exception tr...
TGo4TaskHandler(const char *name, TGo4ThreadManager *threadmanager, Bool_t clientmode=kFALSE, Bool_t mastermode=kTRUE, UInt_t negotiationport=0)
TGo4Socket * GetStatusTransport() const
Bool_t IsClientMode() const
Check whether this instance is client or server taskhandler.
Int_t fiComPort
Command connection port number.
TGo4ThreadHandler * fxThreadHandler
link to external threadhandler which is used for the transport service threads (runnables); these run...
TGo4CommandInvoker * GetInvoker() const
returns pointer to copy of client invoker which may be used by server to check the valid command clie...
TGo4Socket * fxStatusTransport
static const char * fgcSTATUSTHREAD
Suffix for status thread name.
static TNamed fgxADMINISTRATORACCOUNT
This keeps account for admin connection.
Bool_t fbMasterMode
True if taskhandler runs in master mode (sends commands, receives data and status).
static UInt_t Get_fguPORTWAITTIME()
static const char * fgcCOMMANDTHREAD
Suffix for command thread name.
TGo4Socket * fxCommandTransport
Transport channels (e.g.
static void SetCtrlAccount(const char *name, const char *passwd)
Specify login name and password for controller account.
static const char * fgcCONNECT
Initial string for connect request (raw transport)
static const UInt_t fguCONNECTORPORT
Default port number of negotiation connection (raw transport)
Bool_t StopTransportThreads(Bool_t wait=kTRUE)
Stop all transport threads of this taskhandler (command, data, status).
UInt_t fuNegPort
Actual port number of negotiation connection (raw transport)
static const char * Get_fgcERROR()
Go4CommandMode_t fiRole
For server connection to client: This indicates role of connected client, if client is master.
TString fxComName
Remember name of command thread.
void SetNegotiationPort(UInt_t port)
Set port for the negotiation channel (client mode).
TGo4DataRunnable * fxDataRun
link to data runnable which is managed by thread handler 1 1
static void SetAdminAccount(const char *name, const char *passwd)
Specify login name and password for administrator account.
void CloseChannels(Option_t *opt="")
Close transport channels and clear queues.
virtual TGo4TaskHandlerStatus * CreateStatus()
create a status object with information on the current taskhandler state.
TString fxStatName
Remember name of status thread.
Bool_t IsAborting() const
Check whether this instance is currently being aborted.
Bool_t ConnectClientChannel(const char *name, TGo4Socket *negotiator, TGo4Socket *channel, const char *host)
method defining the connection protocol of one data transport channel (data, status,...
Int_t GetStatPort() const
Bool_t ConnectServerChannel(const char *name, TGo4Socket *negotiator, TGo4Socket *channel, const char *host)
Method defining the connection protocol of one data transport channel (data, status,...
void SetInvoker(TGo4CommandInvoker *inv)
sets pointer to client invoker which may be used by server to check the valid command clients
Bool_t DisConnect(Bool_t waitforclient=kTRUE)
Closes the connections of all three transport channels.
static const char * fgcERROR
Error string for client connect negotiations (raw transport)
static TNamed fgxOBSERVERACCOUNT
This keeps account for observer connection.
static const UInt_t fguSTATUSQUEUESIZE
Maximum entries allowed for status queue.
TGo4Socket * GetCommandTransport() const
static const char * fgcMASTER
Task identifier for client connect negotiations (raw transport)
void ClearQueues()
Clear all entries of queues.
Bool_t IsMasterMode() const
Check whether this instance is client or server taskhandler.
TGo4CommandInvoker * fxInvoker
Link to external command invoker instance used for direct command in client mode:
TGo4Queue * fxCommandQueue
Buffers (queues) for the three transport channels:
Bool_t fbIsAborting
True if taskhandler is being aborted e.g.
TGo4Queue * GetStatusQueue() const
TGo4Queue * fxStatusQueue
TGo4Socket * fxDataTransport
TGo4Queue * GetDataQueue() const
static const char * fgcDISCONNECT
Initial string for disconnect request (raw transport)
static const char * fgcOK
Ok string for client connect negotiations (raw transport)
void SetRole(Go4CommandMode_t role)
static const char * Get_fgcOK()
static const UInt_t fguCOMMANDQUEUESIZE
Maximum entries allowed for command queue.
static const UInt_t fguTHREADSTOPTIME
time for each threadstop wait cycle
static const Int_t fgiPORTWAITCYCLES
Cycles to wait for a nonzero portnumber.
static void SetObservAccount(const char *name, const char *passwd)
Specify login name and password for observer account.
Bool_t WaitThreadStop(const char *name)
Wait for the thread of name to be stopped.
TGo4Socket * GetDataTransport() const
void StartTransportThreads()
Start all transport threads of this taskhandler (command, data, status).
const char * GetHostName() const
TGo4ThreadManager * fxThreadManager
Link to threadmanager that owns the task handler, used for runnable ctors.
Int_t fiDatPort
Data connection port number.
Int_t WaitGetPort(TGo4Socket *sock)
Get actual local port number of specified Go4 socket.
TGo4Socket * ServerRequest(const char *host="localhost")
request to server at host to connect or disconnect us, returns negotiation channel
const char * GetComName() const
Bool_t fbClientMode
True if taskhandler runs in client mode.
TString fxHostName
Remember name of remote task handler.
Go4CommandMode_t GetRole()
static const UInt_t fguTRANSPORTCHECKDELAY
Delay time (ms) to wait between two checks of transport connection.
const char * GetDatName() const
TGo4StatusRunnable * fxStatusRun
link to status runnable which is managed by thread handler 1 1
Bool_t Connect(const char *host="localhost", TGo4Socket *negotiator=nullptr)
establishes the connections of all three transport channels and starts the service threads
static const UInt_t fguDATAQUEUESIZE
Maximum entries allowed for data queue.
TGo4ThreadManager * GetThreadManager() const
static const char * fgcSLAVE
Task identifier for client connect negotiations (raw transport)
static TNamed fgxCONTROLLERACCOUNT
This keeps account for controller connection.
Int_t GetComPort() const
TGo4Queue * fxDataQueue
static const char * fgcDATATHREAD
Suffix for data thread name.
TGo4Queue * GetCommandQueue() const
static const UInt_t fguPORTWAITTIME
Time for each waitgetport cycle.
TGo4CommandRunnable * fxCommandRun
link to command runnable which is managed by thread handler 1 1
static Int_t Get_fgiPORTWAITCYCLES()
Bool_t ServerLogin(TGo4Socket *connector, Go4CommandMode_t account)
Negotiate login to requested server channel with account type.
const char * GetStatName() const
TString fxDatName
Remember name of data thread.
Int_t fiStatPort
Status connection port number.
static const Int_t fgiTHREADSTOPCYCLES
cycles to wait for taskhandler thread stop on disconnection
Go4 thread handler.
Go4 thread manager.