22#include "TGo4LockGuard.h"
35 UInt_t negotiationport,
36 Bool_t createconnector)
37: TNamed(name,
"This is a Go4TaskManager"),
42 if(negotiationport == 0)
60 TGo4Log::Debug(
"TaskManager: Created negotiation channel in ctor");
62 fxTransport->Open(
"Server mode does not need hostname", negotiationport, kTRUE);
83 char *recvchar =
nullptr;
84 TString cliname, hostname;
92 Int_t waitresult =
fxServer->WaitForOpen();
97 std::cerr <<
" TaskManager TIMEOUT ERROR opening socket connection !!! Terminating..." << std::endl;
107 std::cerr <<
" TaskManager TIMEOUT ERROR retrieving port number !!! Terminating..." << std::endl;
121 std::cout <<
" Waiting for client connection on PORT: "<<
fuNegotiationPort << std::endl;
122 TGo4Log::Debug(
" TaskManager is waiting to serve client request on port %d ... ",
124 Int_t connectwaitseconds =
fxServer->WaitForConnection();
126 if(connectwaitseconds < 0)
130 return connectwaitseconds;
175 TGo4Log::Debug(
" TaskManager: client %s received invalid login, closing negotiation port ", cliname.Data());
182 TGo4Log::Debug(
" TaskManager: Finished negotiations with client %s ", cliname.Data());
192 TGo4Log::Debug(
" TaskManager: Waiting for timer Close() of negotiation to client %s ... ", cliname.Data());
194 TGo4Log::Debug(
" TaskManager: Finished negotiations with client %s ", cliname.Data());
198 TGo4Log::Debug(
" TaskManager: ERROR on closing down negotiation channel, client %s ", cliname.Data());
236 Bool_t matching = kFALSE;
245 TGo4Log::Debug(
" TaskManager: Client does not match Server, Login failed!!!");
258 TGo4Log::Debug(
" TaskManager: Client logged in as 2nd controller, will be observer");
268 TGo4Log::Warn(
" TaskManager: Client logged in as 2nd controller, will be observer");
271 TGo4Log::Debug(
" TaskManager: Client logged in as administrator");
288 TString cliname = client;
289 if (!
AddClient(cliname.Data(),host,role)) rev = 1;
296 TGo4Log::Info(
"TaskManager is disconnecting client %s %s ...", name, clientwait ?
"with waiting" :
"with no wait!" );
313 TString tname = taskhandler->GetName();
320 TGo4Log::Debug(
" TaskManager %s; negotiation ERROR after client disconnect!", GetName());
332 if (iscontrollertask)
335 TGo4Log::Debug(
" TaskManager: client %s has been disconnected. ", tname.Data());
338 TGo4Log::Debug(
" TaskManager: client %s disconnect ERROR %d occured !! ", tname.Data(), rev);
342 TGo4Log::Debug(
" TaskManager: FAILED to disonnect client -- no such client! ");
352 TGo4Log::Warn(
" !!! TaskManager::AddClient ERROR: client of name %s is already existing !!! ",client);
359 TGo4Log::Info(
" TaskManager: Succesfully added new client %s (host %s, ports %d,%d,%d) ",
365 fxServer->SendStatusMessage(1,kTRUE,
"%s::Client %s is logged in at %s as %s",
370 TGo4Log::Error(
" TaskManager: ERROR on connecting new client %s (host %s)", client, host);
420 if (taskhandler == currenttaskhandler) {
468 }
else if (
fxServer->IsTerminating()) {
Go4CommandMode_t
These values define command execution rights.
@ kGo4ComModeAdministrator
static const char * GetModeDescription(Go4CommandMode_t mode)
text description of current execution mode
static void Warn(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 2.
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
This class is responsible for the interconnection of two tasks: provided are three communication chan...
static TNamed fgxADMINISTRATORACCOUNT
This keeps account for admin connection.
static UInt_t Get_fguPORTWAITTIME()
static const char * fgcCONNECT
Initial string for connect request (raw transport)
static const UInt_t fguCONNECTORPORT
Default port number of negotiation connection (raw transport)
static const char * Get_fgcERROR()
Int_t GetStatPort() const
Bool_t DisConnect(Bool_t waitforclient=kTRUE)
Closes the connections of all three transport channels.
static TNamed fgxOBSERVERACCOUNT
This keeps account for observer connection.
static const char * fgcMASTER
Task identifier for client connect negotiations (raw transport)
static const char * fgcDISCONNECT
Initial string for disconnect request (raw transport)
void SetRole(Go4CommandMode_t role)
static const char * Get_fgcOK()
Go4CommandMode_t GetRole()
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 char * fgcSLAVE
Task identifier for client connect negotiations (raw transport)
static TNamed fgxCONTROLLERACCOUNT
This keeps account for controller connection.
static Int_t Get_fgiPORTWAITCYCLES()
TGo4TaskHandler * NextTaskHandler(Bool_t reset=kFALSE)
For iteration over all connected task handlers.
TGo4TaskHandler * NewTaskHandler(const char *name)
creates new task handler with given name and adds it into array
TIterator * fxTaskIter
Iterator over list of tasks.
Go4CommandMode_t ClientLogin()
Check account and password of the client that requests a connection to this server.
TGo4TaskHandler * GetLastTaskHandler()
returns last task handler in list
UInt_t fuNegotiationPort
port number for the server client negotiation connections
Bool_t AddClient(const char *client, const char *host, Go4CommandMode_t role)
adds client task of name to manager: create server task handler and try to connect to client Command ...
Bool_t RemoveTaskHandler(const char *name)
removes task handler from array by name
UInt_t GetNegotiationPort()
returns the portnumber for client server negotiation port which is actually used by the running taskm...
Bool_t AddTaskHandler(TGo4TaskHandler *han)
adds external task handler to array
Int_t ServeClient()
used by connector runnable to wait for a client connect/disonnect request
TGo4TaskHandler * GetTaskHandler(const char *name)
returns certain task handler by name
TGo4ServerTask * fxServer
Bool_t fbHasControllerConnection
True if this server already has one connection to a master client that has the controller role.
static const Int_t fgiDISCONCYCLES
cycles to wait for client disconnection
Int_t WaitForClientRemoved()
static const UInt_t fguDISCONTIME
time for each disonnection wait cycle
Bool_t fbClientIsRemoved
True if the last specified client is removed from server.
virtual ~TGo4TaskManager()
Int_t ConnectClient(const char *client, const char *host, Go4CommandMode_t role=kGo4ComModeController)
used by connector runnable to wait for a client request to connect to this server task.
Int_t DisConnectClient(const char *name, Bool_t clientwait=kTRUE)
disonnect an existing client by name, wait for negotiation OK if clientwait is true
Exception which terminates the threadmanager and the application.
static void Sleep(UInt_t millisecs)
wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termi...