GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4TaskHandler.cxx
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#include "TGo4TaskHandler.h"
15
16#include "TSystem.h"
17
18#include "TGo4Log.h"
19#include "TGo4Thread.h"
20#include "TGo4ThreadHandler.h"
21#include "TGo4Socket.h"
22#include "TGo4BufferQueue.h"
24#include "TGo4DataRunnable.h"
25#include "TGo4StatusRunnable.h"
26#include "TGo4CommandRunnable.h"
27#include "TGo4ServerTask.h"
29
30const UInt_t TGo4TaskHandler::fguCONNECTORPORT=5000; // port no of default connector 9229
31// 5000 is the first number of ROOT portscan
32const UInt_t TGo4TaskHandler::fguTRANSPORTCHECKDELAY=5000; // delay in ms for transport init check
33
35const UInt_t TGo4TaskHandler::fguDATAQUEUESIZE=1000;
37
38
39const Int_t TGo4TaskHandler::fgiPORTWAITCYCLES=150;//60
40
41const UInt_t TGo4TaskHandler::fguPORTWAITTIME=200;//500
42
44
46
47const char *TGo4TaskHandler::fgcCONNECT="CONNECT-VERSION-300";
48const char *TGo4TaskHandler::fgcDISCONNECT="DISCONNECT-VERSION-300";
49
50const char *TGo4TaskHandler::fgcOK = "OK-VERSION-300";
51const char *TGo4TaskHandler::fgcERROR = "ERROR-VERSION-300";
52
53const char *TGo4TaskHandler::fgcMASTER="Master-VERSION-300";
54const char *TGo4TaskHandler::fgcSLAVE="Slave-VERSION-300";
55
56const char *TGo4TaskHandler::fgcCOMMANDTHREAD="COMMAND-";
57const char *TGo4TaskHandler::fgcSTATUSTHREAD="STATUS-";
58const char *TGo4TaskHandler::fgcDATATHREAD="DATA-";
59
60TNamed TGo4TaskHandler::fgxOBSERVERACCOUNT("observer","go4view");
61TNamed TGo4TaskHandler::fgxCONTROLLERACCOUNT("controller","go4ctrl");
62TNamed TGo4TaskHandler::fgxADMINISTRATORACCOUNT("admin","go4super");
63
64TGo4TaskHandler::TGo4TaskHandler(const char *name, TGo4ThreadManager *threadmanager, Bool_t clientmode, Bool_t mastermode,UInt_t negotiationport)
65:TNamed(name,"This is a Go4 Task Handler"),
67{
68 fbClientMode = clientmode;
69 fbMasterMode = mastermode;
70 if(!threadmanager) {
71 // error
72 TGo4Log::Debug(" TaskHandler -- constructor error, unspecified ThreadManager: aborting ");
73 //throw TGo4RuntimeException();
74 }
75
76 // set port number for the client server negotiation channel:
77 if(negotiationport == 0)
78 {
79 // default: use taskhandler intrinsic port number
81 }
82 else
83 {
84 // use dynamic port number given by taskhandler owner
85 fuNegPort=negotiationport;
86 }
87
88 fxThreadManager=threadmanager;
89 fxThreadHandler=fxThreadManager->GetWorkHandler();
90 TString namebuffer;
91 fxInvoker = nullptr;
92 fxCommandQueue= new TGo4BufferQueue("Command"); // receiv commands
93 fxStatusQueue= new TGo4BufferQueue("Status"); // send status buffer
94 fxDataQueue= new TGo4BufferQueue("Data"); // send data
95
99 namebuffer.Form("CommandRunnable of %s",GetName());
100 // command runnable receivermode: receiving as slave and sending as master
101 fxCommandRun=new TGo4CommandRunnable(namebuffer.Data(), fxThreadManager, this, !IsMasterMode());
102
103 namebuffer.Form("StatusRunnable of %s",GetName());
104 // status runnable receivermode: sending as slave and receiving as master
105 fxStatusRun=new TGo4StatusRunnable(namebuffer.Data(), fxThreadManager, this, IsMasterMode());
106
107 namebuffer.Form("DataRunnable of %s",GetName());
108 // data runnable receivermode: sending as slave and receiving as master
109 fxDataRun=new TGo4DataRunnable(namebuffer.Data(), fxThreadManager, this, IsMasterMode());
110
111 // adding runnables to thread handler who takes over the responsibility...:
112 namebuffer.Form("%s%s",fgcCOMMANDTHREAD,GetName());
113 fxComName=namebuffer;
115 namebuffer.Form("%s%s",fgcSTATUSTHREAD,GetName());
116 fxStatName=namebuffer;
118 namebuffer.Form("%s%s",fgcDATATHREAD,GetName());
119 fxDatName=namebuffer;
121 if(IsClientMode())
122 TGo4Log::Debug(" New TaskHandler %s in client mode ",GetName());
123 else
124 TGo4Log::Debug(" New TaskHandler %s in server mode ",GetName());
125
126 // adjust queue size to our wishes
130}
131
133{
134 fxThreadHandler->RemoveThread(GetComName());
135 fxThreadHandler->RemoveThread(GetDatName());
136 fxThreadHandler->RemoveThread(GetStatName());
137 delete fxCommandTransport;
138 delete fxStatusTransport;
139 delete fxDataTransport;
140 delete fxCommandQueue;
141 delete fxStatusQueue;
142 delete fxDataQueue;
143}
144
146{
147 if(fbClientMode)
148 {
149 // we are client and want access to the server task (connector runnable)
150 TGo4Socket *connector=new TGo4Socket(kTRUE); // raw socket transport
151 connector->Open(host,fuNegPort); // open connection to server's connector runnable
152 if(ServerLogin(connector, GetRole()))
153 {
154 // client and server know each other- we continue
155 TString myname=fxThreadManager->GetName();
156 connector->Send(myname.Data()); // tell server the client name
157 connector->Send(gSystem->HostName()); // tell server our machine hostname
158 return connector;
159 } //if(!strcmp(localbuffer,fgcOK))
160 else
161 {
162 // error: client does not match to server-- connect failed
163 connector->Send(Get_fgcERROR()); // send dummy strings, server will come out of receive
164 connector->Send(Get_fgcERROR()); // might check the errortext at server later
165#ifdef _MSC_VER
166 gSystem->Sleep(1000);
167#endif
168 connector->Close();
169 delete connector;
170 TGo4Log::Debug(" TaskHandler %s server connection ERROR ",GetName());
171 return nullptr;
172
173 } // else if(!strcmp(localbuffer,fgcOK))
174 } //if(fbClientMode)
175
176 // we _are_ a server task handler, shall not request to our own Server task
177 return nullptr;
178}
179
180
181Bool_t TGo4TaskHandler::Connect(const char *host, TGo4Socket *connector)
182// establish connection of all three channels
183{
184 TGo4Log::Debug(" TaskHandler %s connecting to host %s ...",GetName(),host);
185 char *recvchar;
186 if(fbClientMode)
187 {
189 SetAborting(kFALSE); // reset if we reconnect after exception disconnect
190 fxHostName=host;// remember hostname for later DisConnect
191 if(!connector)
192 {
193 // normal mode for client: we establish negotiation connection first
194 connector=ServerRequest(host); // get negotiation channel from server
195 }
196 if(connector)
197 {
198 // request was successful, we keep talking:
199 connector->Send(fgcCONNECT); // tell server we want to connect
200 recvchar=connector->RecvRaw("dummy");
201 if(!recvchar)
202 {
203 TGo4Log::Debug(" TaskHandler %s; Error on server connection, abortin... ",GetName());
204 connector->Close();
205 throw TGo4RuntimeException();
206 }
207 if(!strcmp(recvchar,Get_fgcERROR()))
208 {
209 // server refuses to connect us, we abort
210 TGo4Log::Debug(" TaskHandler %s; Server refuses Connection",GetName());
211 connector->Send(fgcOK); // tell server we are through
212#ifdef _MSC_VER
213 gSystem->Sleep(1000);
214#endif
215 connector->Close();
216 throw TGo4RuntimeException();
217 }
218 if(!ConnectClientChannel("Command",connector,fxCommandTransport,host))
219 {
220 TGo4Log::Debug(" TaskHandler %s; negotiation error, FAILED to open Command Channel",GetName());
221 throw TGo4RuntimeException();
222 }
223 if(!ConnectClientChannel("Status",connector,fxStatusTransport,host))
224 {
225 TGo4Log::Debug(" TaskHandler %s; negotiation error, FAILED to open Status Channel",GetName());
226 throw TGo4RuntimeException();
227 }
228 if(!ConnectClientChannel("Data",connector,fxDataTransport,host))
229 {
230 TGo4Log::Debug(" TaskHandler %s; negotiation error, FAILED to open Data Channel",GetName());
231 throw TGo4RuntimeException();
232 }
233 connector->Send(fgcOK); // tell server we finish negotiation
234#ifdef _MSC_VER
235 gSystem->Sleep(1000);
236#endif
237 connector->Close();
238 TGo4Log::Debug(" TaskHandler %s closed negotiation connection ",GetName());
239 delete connector;
240 }
241 else
242 {
243 // something failed
244 TGo4Log::Debug(" TaskHandler %s server connection ERROR ",GetName());
245 return kFALSE;
246 } // if(connector)
247 } //if(fbClientMode)
248 else
249 {
251 const char *client = GetName();
252 if(!connector) return kFALSE;
253 connector->Send(TGo4TaskHandler::fgcOK);
254 // first ok to initialize client, fgcERROR would abort client
255 if (!ConnectServerChannel("Command",connector, fxCommandTransport, host))
256 {
257 TGo4Log::Debug(" TaskHandler: Command channel connect ERROR for client %s ",client);
258 return kFALSE;
259 }
260 if (!ConnectServerChannel("Status",connector, fxStatusTransport, host))
261 {
262 TGo4Log::Debug(" TaskManager: Status channel connect ERROR for client %s ",client);
263 return kFALSE;
264 }
265 if (!ConnectServerChannel("Data",connector, fxDataTransport, host))
266 {
267 TGo4Log::Debug(" TaskManager: Data channel connect ERROR for client %s ",client);
268 return kFALSE;
269 }
270 } //if(fbClientMode)
271
272 fiComPort = WaitGetPort(fxCommandTransport); // set port numbers for runnables
276
277 return kTRUE;
278}
279
281{
282 if(!connector) return kFALSE;
283 //std::cout <<"ServerLogin with mode "<<account << std::endl;
284 //std::cout <<"observer account is "<<TGo4TaskHandler::fgxOBSERVERACCOUNT.GetName()<<", "<<TGo4TaskHandler::fgxOBSERVERACCOUNT.GetTitle() << std::endl;
285 //std::cout <<"controller account is "<<TGo4TaskHandler::fgxCONTROLLERACCOUNT.GetName()<<", "<<TGo4TaskHandler::fgxCONTROLLERACCOUNT.GetTitle() << std::endl;
286 //std::cout <<"admin account is "<<TGo4TaskHandler::fgxADMINISTRATORACCOUNT.GetName()<<", "<<TGo4TaskHandler::fgxADMINISTRATORACCOUNT.GetTitle() << std::endl;
287
288 connector->Send(fgcOK); // tell server that we are a valid client
289
290 // tell server if we are master or slave:
291 if(fbMasterMode)
292 connector->Send(fgcMASTER);
293 else
294 connector->Send(fgcSLAVE);
295
296 // now send accountname and password:
297 switch (account)
298 {
300 connector->Send(fgxOBSERVERACCOUNT.GetName());
301 connector->Send(fgxOBSERVERACCOUNT.GetTitle());
302 break;
303
305 connector->Send(fgxCONTROLLERACCOUNT.GetName());
306 connector->Send(fgxCONTROLLERACCOUNT.GetTitle());
307 break;
308
310 connector->Send(fgxADMINISTRATORACCOUNT.GetName());
311 connector->Send(fgxADMINISTRATORACCOUNT.GetTitle());
312 break;
313
315 default:
316 connector->Send(Get_fgcERROR());
317 connector->Send(Get_fgcERROR());
318 break;
319 }
320
321 char *recvchar = connector->RecvRaw("dummy");// handshake back if it is ok
322 if(recvchar && !strcmp(recvchar,fgcOK)) return kTRUE;
323 return kFALSE;
324}
325
326Bool_t TGo4TaskHandler::DisConnect(Bool_t waitforclient)
327{
328 TGo4Log::Debug(" TaskHandler %s disconnecting ",GetName());
329 //TGo4Task* task=dynamic_cast<TGo4Task*>(fxThreadManager);
330 if(fbClientMode)
331 {
332 if(!IsAborting())
333 {
334 // normal DisConnect mode:
335 // we are client, have to tell server to let us go...
336 TGo4Socket *connector=ServerRequest(GetHostName()); // get negotiation channel from server
337 if(connector)
338 {
339 // request was successful, we keep talking:
340 // task->StopWorkThreads();
341 // if(task->IsMaster())
342 // fxCommandQueue->Clear();// only clear command queue on master side,
343 // // otherwise we lose status messages from server
344 // task->WakeCommandQueue(TGo4Task::Get_fgiTERMID()); // will stop local command thread, and remote
345 // task->SendStopBuffers(); // only stop remote threads if login was successful!
347 connector->Send(fgcDISCONNECT); // tell server we want to disconnect
348 StopTransportThreads(kTRUE);// wait until threads are really stopped
350 connector->Send(fgcOK); // tell server we finished transports
351 // server will close its transport sockets after this
352
353 connector->Send(fgcOK); // second ok to let server shutdown connector
354#ifdef _MSC_VER
355 gSystem->Sleep(1000);
356#endif
357 connector->Close();
358 delete connector;
359 }
360 else
361 {
362 // something failed
363 TGo4Log::Debug(" TaskHandler %s server disconnect login ERROR - Trying Fast DisConnect... ",GetName());
364 StopTransportThreads(kFALSE);
365 CloseChannels("force");
366 //return kFALSE;
367 }
368 }
369 else // if(!IsAborting())
370 {
371 // DisConnect after exception, fast Close without negotiations
372 TGo4Log::Debug(" TaskHandler %s Client Aborting mode: Fast DisConnect... ",GetName());
373 StopTransportThreads(kFALSE);
374 CloseChannels("force");
375 }
376 }
377 else
378 {
379 StopTransportThreads(waitforclient);// wait until threads are really stopped
381 }
382 return kTRUE;
383}
384
386{
387 //TString option=opt;
388 //if(option=="force")
389 // {
390 // std::cout <<"sSSSSSSSSSSSS CloseChannels sending abort buffer" << std::endl;
391 // TGo4Task* task=dynamic_cast<TGo4Task*>(fxThreadManager);
392 // // provoke socket exception on receiver channels:
393 // if(fbMasterMode)
394 // {
395 // fxCommandTransport->SendBuffer(task->GetAbortBuffer());
396 // }
397 // else
398 // {
399 // fxDataTransport->SendBuffer(task->GetAbortBuffer());
400 // fxStatusTransport->SendBuffer(task->GetAbortBuffer());
401 //
402 // }
403 // }
404 fxDataTransport->Close(opt);
405 fxCommandTransport->Close(opt);
406 fxStatusTransport->Close(opt);
407 ClearQueues();
408
409}
410
412{
413 fxDataQueue->Clear();
414 fxCommandQueue->Clear();
415 fxStatusQueue->Clear();
416
417}
418
420{
421 TGo4TaskHandlerStatus* state= new TGo4TaskHandlerStatus(GetName());
422 // we are friend of our status class, may use private setters:
423 state->SetFlags(fbIsAborting);
426 return state;
427}
428
429
430
431Bool_t TGo4TaskHandler::ConnectServerChannel(const char *name, TGo4Socket *negotiator, TGo4Socket *channel, const char *host)
432{
433 char *revchar = nullptr;
434 Int_t waitresult = 0;
435 TGo4ServerTask *server = dynamic_cast<TGo4ServerTask *>(fxThreadManager);
436 if(!server)
437 {
438 TGo4Log::Debug(" TaskHandler: Channel %s open ERROR: no server task ",name);
439 return kFALSE;
440 }
441 if(!negotiator || !negotiator->IsOpen())
442 {
443 TGo4Log::Debug(" TaskHandler: Channel %s open ERROR: no negotiation channel", name);
444 return kFALSE;
445 }
446 if(!channel)
447 {
448 TGo4Log::Debug(" TaskHandler: Channel %s open ERROR: no TGo4Socket instance", name);
449 return kFALSE;
450 }
451 const char *client = GetName(); // taskhandler name is client name
452 // in server mode, we connect by the connector thread:
453 // need timer mechanism for proper registration of ROOT sockets (timer is main thread)
454 // only root sockets connected in main application thread will be cleaned up
455 server->SetConnect(channel, host,0,kTRUE);
456 // tell the ServerTask timer we want to connect; portscan. we keep server socket open for windows
457 waitresult = server->WaitForOpen(); // wait for the server Open() call by timer
458 if(waitresult < 0)
459 {
460 // open timeout
461 TGo4Log::Debug(" TaskHandler: Channel %s open TIMEOUT for client %s ",name, client);
462 return kFALSE;
463 }
464 else
465 {
466 // ok, proceed
467 }
468 Int_t port = WaitGetPort(channel);
469 if (port < 0)
470 {
471 TGo4Log::Debug(" TaskHandler: Channel %s getport TIMEOUT for client %s ",name, client);
472 return kFALSE;
473 }
474 negotiator->Send(TGo4TaskHandler::fgcOK); // tell client we are ready to connect
475 TString localbuffer;
476 localbuffer.Form("%d",port);
477 negotiator->Send(localbuffer.Data()); // tell client the port number;
478 revchar=negotiator->RecvRaw("dummy"); // wait for client connection ok
479 if(revchar && !strcmp(revchar,TGo4TaskHandler::fgcOK))
480 {
481 // o.k., client tells us connection is open, continue
482 }
483 else
484 {
485 // something went wrong, no ok
486 TGo4Log::Debug(" TaskHandler: Negotiation ERROR after Channel %s open for client %s ",
487 name, client);
488 return kFALSE;
489 //throw TGo4RuntimeException();
490 }
491
492 waitresult=server->WaitForConnection(); // we also check ourselves if timer has returned from server open
493 if(waitresult < 0)
494 {
495 // connect timeout
496 TGo4Log::Debug(" TaskHandler: Channel %s connect TIMEOUT for client %s ", name, client);
497 return kFALSE;
498 }
499 else
500 {
501 // ok, proceed
502 }
503 TGo4Log::Debug(" TaskHandler: Channel %s for client %s open!",name, client);
504 return kTRUE;
505}
506
507Bool_t TGo4TaskHandler::ConnectClientChannel(const char *name, TGo4Socket *negotiator, TGo4Socket *channel, const char *host)
508{
509 //
510 char *recvchar = nullptr;
511 Int_t port = 0;
512 if(!negotiator || !negotiator->IsOpen())
513 {
514 TGo4Log::Debug(" TaskHandler: Channel %s open ERROR: no negotiation channel ",name);
515 return kFALSE;
516 }
517 if(!channel)
518 {
519 TGo4Log::Debug(" TaskHandler: Channel %s open ERROR: no TGo4Socket instance ",name);
520 return kFALSE;
521 }
522
523 recvchar = negotiator->RecvRaw("dummy");// get OK from server to connect first channel
524 if(recvchar && !strcmp(recvchar,fgcOK))
525 {
526 // get portnumber from server:
527 recvchar=negotiator->RecvRaw("dummy");
528 TString localbuffer = recvchar;
529 port=atoi(localbuffer.Data());
530 // std::cout <<"------- TaskHandler::Connect client tries port "<< port << "for Channel "<< name << std::endl;
531 channel->Open(host,port); // in client mode, we connect directly (main thread!)
532 TGo4Log::Debug(" TaskHandler %s: Channel %s open!",GetName(), name );
533 negotiator->Send(fgcOK); // tell server that open is ready
534 return kTRUE;
535 }
536 else
537 {
538 TGo4Log::Debug(" TaskHandler %s; negotiation error, FAILED to open Channel %s ",
539 GetName(), name);
540 return kFALSE;
541 //throw TGo4RuntimeException();
542 } // if(!strcmp(recvchar,fgcOK))
543}
544
546{
547 Int_t count = 0, port = 0;
548 while(port == 0)
549 {
550 port = sock->GetPort(); // get dynamically bound port number of server socket
551 // std::cout <<"------- WaitGetPort has next portnumber "<< port << std::endl;
552 if(count>fgiPORTWAITCYCLES)
553 {
554 return -1;
555 }
556 else if(fxThreadManager->IsTerminating())
557 {
558 return -2;
559 }
560 else
561 {
563 ++count;
564 }
565 }
566 return port;
567
568}
569
571{
572 fxThreadHandler->Start(GetComName()); // start runnables
574 fxThreadHandler->Start(GetDatName());
575}
576
578{
579 Bool_t rev = kTRUE;
581 if(IsMasterMode())
582 {
583 TGo4BufferQueue *comq= dynamic_cast<TGo4BufferQueue*>(GetCommandQueue());
584 if(comq)
585 comq->Wake();
586 }
589 if(wait)
590 {
594 }
595 return rev;
596}
597
598Bool_t TGo4TaskHandler::WaitThreadStop(const char *name)
599{
600 if(!name) return kFALSE;
601 TGo4Thread *thread=fxThreadHandler->GetThread(name);
602 if(!thread) return kFALSE;
603 Int_t t = 0;
604 Bool_t timeout = kFALSE;
605 while(!thread->IsWaiting())
606 {
607 TGo4Log::Debug(" TaskHandler Disconnect -- waiting for runnable %s to stop... ",name);
610 {
611 timeout = kTRUE;
612 break;
613 }
614 }
615 return !timeout;
616}
617
618void TGo4TaskHandler::SetAdminAccount(const char *name, const char *passwd)
619{
620 if(name) fgxADMINISTRATORACCOUNT.SetName(name);
621 if(passwd) fgxADMINISTRATORACCOUNT.SetTitle(passwd);
622}
623
624void TGo4TaskHandler::SetCtrlAccount(const char *name, const char *passwd)
625{
626 if(name) fgxCONTROLLERACCOUNT.SetName(name);
627 if(passwd) fgxCONTROLLERACCOUNT.SetTitle(passwd);
628}
629
630void TGo4TaskHandler::SetObservAccount(const char *name, const char *passwd)
631{
632 if(name) fgxOBSERVERACCOUNT.SetName(name);
633 if(passwd) fgxOBSERVERACCOUNT.SetTitle(passwd);
634}
635
637{
638 return fgcOK;
639}
640
642{
643 return fgcERROR;
644}
645
650
Go4CommandMode_t
These values define command execution rights.
Definition TGo4Command.h:27
@ kGo4ComModeController
Definition TGo4Command.h:30
@ kGo4ComModeRefused
Definition TGo4Command.h:28
@ kGo4ComModeObserver
Definition TGo4Command.h:29
@ kGo4ComModeAdministrator
Definition TGo4Command.h:31
Class containing a pointer queue for TBuffers.
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...
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
virtual void Wake()
Definition TGo4Queue.cxx:86
Server task.
void SetConnect(TGo4Socket *trans, const char *host, UInt_t port, Bool_t keepserv=kFALSE)
Bool_t IsOpen() const
Definition TGo4Socket.h:37
Int_t GetPort() const
Definition TGo4Socket.h:41
virtual Int_t Send(TObject *obj)
virtual Int_t Close(Option_t *opt="")
virtual Int_t Open(const char *host, Int_t port, Bool_t keepservsock=kFALSE)
virtual char * RecvRaw(const char *name=nullptr)
Runnable responsible for status object exchange between transport (socket) and buffer (queue) In rece...
void SetPorts(UInt_t neg, Int_t com, Int_t stat, Int_t dat)
void SetNames(const char *com, const char *stat, const char *dat, const char *host)
void SetFlags(Bool_t isaborting)
void SetAborting(Bool_t isaborting=kTRUE)
sets the internal aborting state of this taskhandler instance; will be checked before an exception tr...
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...
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.
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,...
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,...
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.
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 * fxStatusQueue
TGo4Socket * fxDataTransport
static const char * fgcDISCONNECT
Initial string for disconnect request (raw transport)
static const char * fgcOK
Ok string for client connect negotiations (raw transport)
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.
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.
static const char * fgcSLAVE
Task identifier for client connect negotiations (raw transport)
static TNamed fgxCONTROLLERACCOUNT
This keeps account for controller connection.
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 manager.
go4 thread class
Definition TGo4Thread.h:34
Bool_t IsWaiting() const
true if Threadfunc is suspended to condition wait
Definition TGo4Thread.h:90
static void Sleep(UInt_t millisecs)
wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termi...