GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
TGo4ClientTask.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 "TGo4ClientTask.h"
15
16#include "TGo4Log.h"
17
18#include "TGo4BufferQueue.h"
19#include "TGo4ClientStatus.h"
20#include "TGo4ThreadHandler.h"
21#include "TGo4TaskHandler.h"
22
24 const char *serverhost,
25 UInt_t negotiationport,
26 Bool_t blockingmode,
27 Bool_t standalone,
28 Bool_t autostart,
29 Bool_t autocreate,
30 Bool_t ismaster,
31 Bool_t autoconnect) :
32 TGo4Task(name,blockingmode,autostart,autocreate,ismaster),
33 fxTaskHandler(nullptr),
34 fbAutoConnect(autoconnect),
35 fbServerConnected(kFALSE)
36{
37 fxServerHostname = serverhost;
38 TString nomen("TaskHandler of ");
39 nomen += name;
40 fxTaskHandler = new TGo4TaskHandler(nomen.Data(), this, kTRUE, IsMaster(), negotiationport);
43 fxDataQ = dynamic_cast<TGo4BufferQueue *>(GetTaskHandler()->GetDataQueue());
44 if (standalone) {
45 Launch(); // create threads, start application control timer
46 } else {
47 // subclass must call Launch at end of its ctor
48 }
49}
50
56
61
63{
64 // already initialized, return ok value
65 if (fbInitDone)
66 return 0;
67
68 Int_t rev = TGo4Task::Initialization(); // this will launch threads, etc.
69 if (rev == 0) {
70 // success: then try to connect (all threads are up now)
71 if (fbAutoConnect) {
73 Terminate();
74 }
75 }
76 return rev;
77}
78
79Bool_t TGo4ClientTask::ConnectServer(const char *node, UInt_t negport,
81 const char *passwd)
82{
84 TGo4Log::Warn(" ClientTask::ConnectServer ''%s'': ServerTask already connected", GetName());
85 return kTRUE;
86 }
87
88 if (negport)
89 fxTaskHandler->SetNegotiationPort(negport); // null negport will use the default port
90 if (IsMaster())
91 fxTaskHandler->ClearQueues(); // do not clear queues on slave side,
92 // because analysis status might be already in it!
93
94 TGo4Log::Info("TGo4ClientTask::ConnectServer with role %d and passwd %s", role, passwd);
95 if (passwd) {
96 fxTaskHandler->SetRole(role);
97 if (role == kGo4ComModeObserver) {
98 TGo4TaskHandler::SetObservAccount(nullptr, passwd);
99 } else if (role == kGo4ComModeController) {
100 TGo4TaskHandler::SetCtrlAccount(nullptr, passwd);
101 } else if (role == kGo4ComModeAdministrator) {
102 TGo4TaskHandler::SetAdminAccount(nullptr, passwd);
103 }
104 }
105 if (fxTaskHandler->Connect(node, nullptr)) {
106 // TGo4Log::Info(" ClientTask ''%s'': connected successfully to ServerTask at node %s (port %d) ",
107 // GetName(),node, negport);
108 fbServerConnected = kTRUE;
109 fxWorkHandler->StartAll(); // all transports are there, then start waiting threads
110 SendStatusMessage(1, kTRUE, "Client %s connected successfully to Server task at node %s", GetName(),
111 node); // note that negport does not contain actual portnumber here
112 return kTRUE;
113 } else {
114 TGo4Log::Error(" ClientTask ''%s'': FAILED connection to ServerTask at node %s", GetName(), node);
115 return kFALSE;
116 }
117}
118
119Bool_t TGo4ClientTask::DisconnectServer(Bool_t isterminating)
120{
121 Bool_t rev = kTRUE;
122 if (fbServerConnected) {
124 if (IsMaster()) {
125 // fxTaskHandler->ClearQueues(); // prevent monitor commands to interfere with disconnect
127 if (cq)
128 cq->Clear(); // only clear command queue on master side,
129 // otherwise we lose status messages from server
130 }
132 WakeCommandQueue(TGo4Task::Get_fgiTERMID()); // will stop local command thread, and remote
133 SendStopBuffers(); // note: this should only be done after disconnect login was successful JA
134 rev = fxTaskHandler->DisConnect();
136 if (rev)
137 fbServerConnected = kFALSE;
138 if (!isterminating)
140 }
141 return rev;
142}
143
145{
146 TGo4Log::Debug(" ClientTask''%s'' is quitting... ",GetName());
147 SendStatusMessage(2,kTRUE,"ClientTask %s is terminating...",GetName());
149 DisconnectServer(kTRUE);
150
151 Terminate(!IsMaster()); // never terminate master process
152}
153
155{
156 TGo4ClientStatus* stat= new TGo4ClientStatus(GetName());
157 UpdateStatus(stat); // set the internals
158 return stat;
159}
160
162{
164 TGo4ClientStatus* clstate=dynamic_cast<TGo4ClientStatus*>(state);
165 if(clstate)
166 clstate->SetNames(GetServerHostName());
167}
168
170{
171 if (!com)
172 return;
173 if (fxCommandQ) {
174 fxCommandQ->AddBufferFromObject(com);
175 } else {
176 TGo4Log::Debug(" !!! ClientTask - ERROR adding local command - no command queue !!! ");
177 }
178}
179
181{
182 return fxCommandQ;
183}
184
186{
187 return fxStatusQ;
188}
190{
191 return fxDataQ;
192}
Go4CommandMode_t
These values define command execution rights.
Definition TGo4Command.h:27
@ kGo4ComModeController
Definition TGo4Command.h:30
@ kGo4ComModeObserver
Definition TGo4Command.h:29
@ kGo4ComModeAdministrator
Definition TGo4Command.h:31
Class containing a pointer queue for TBuffers.
Client status.
void SetNames(const char *serverhost)
virtual ~TGo4ClientTask()
TGo4ClientTask(const char *name, const char *serverhost="localhost", UInt_t negotiationport=0, Bool_t blockingmode=kTRUE, Bool_t standalone=kFALSE, Bool_t autostart=kFALSE, Bool_t autocreate=kTRUE, Bool_t ismaster=kFALSE, Bool_t autoconnect=kTRUE)
TGo4TaskHandler * fxTaskHandler
aggregationByValue
void UpdateStatus(TGo4TaskStatus *state) override
method needed by method CreateStatus of any status subclasses to set the values of the clienttask spe...
TGo4BufferQueue * fxDataQ
TGo4BufferQueue * GetStatusQueue(const char *task=nullptr) override
Int_t Initialization() override
override the ThreadManager Initialization used by AppControlTimer to let this thing initialize the cl...
TGo4BufferQueue * GetDataQueue(const char *task=nullptr) override
const char * GetServerHostName() const
Bool_t fbAutoConnect
!True if client task shall try to connect automatically at Initialization.
Bool_t ConnectServer(const char *node, UInt_t negport, Go4CommandMode_t role=kGo4ComModeRefused, const char *passwd=nullptr)
Connect this client to a waiting server task on node with negotiation channel negport.
void AddLocalCommand(TGo4Command *com)
Put command into the command queue for local execution in main thread.
Bool_t fbServerConnected
true if connection to server is established, otherwise false
TGo4TaskStatus * CreateStatus() override
create a status object with information on the current client state.
TGo4BufferQueue * fxCommandQ
Bool_t DisconnectServer(Bool_t isterminating=kFALSE)
Disconnect the current server task, but do not terminate the client.
TGo4BufferQueue * fxStatusQ
TGo4BufferQueue * GetCommandQueue(const char *task=nullptr) override
TGo4TaskHandler * GetTaskHandler() override
void Quit() override
Quit the client; method to be called from command object, may be overridden in user implementation.
TString fxServerHostname
hostname of server machine
This is the Go4 Abstract Command Class; part of the Base command pattern.
Definition TGo4Command.h:35
static void Warn(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 2.
Definition TGo4Log.cxx:315
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
Definition TGo4Log.cxx:302
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:289
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:328
Base class for all threadsafe pointer queues.
Definition TGo4Queue.h:31
void Clear(Option_t *opt="") override
Definition TGo4Queue.cxx:43
This class is responsible for the interconnection of two tasks: provided are three communication chan...
static void SetCtrlAccount(const char *name, const char *passwd)
Specify login name and password for controller account.
static void SetAdminAccount(const char *name, const char *passwd)
Specify login name and password for administrator account.
TGo4Queue * GetStatusQueue() const
TGo4Queue * GetDataQueue() const
static void SetObservAccount(const char *name, const char *passwd)
Specify login name and password for observer account.
TGo4Queue * GetCommandQueue() const
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
static Int_t Get_fgiTERMID()
Definition TGo4Task.cxx:588
TGo4Task(const char *name, Bool_t blockingmode, Bool_t autostart=kFALSE, Bool_t autocreate=kTRUE, Bool_t ismaster=kFALSE)
Definition TGo4Task.cxx:39
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
virtual void Quit()
Quit the client; method to be called from command object, may be overridden in user implementation.
Definition TGo4Task.cxx:115
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
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
Bool_t IsMaster() const
Definition TGo4Task.h:97
virtual Int_t StartWorkThreads()
start the working threads of the task implementation; this method is used after the current connectio...
Definition TGo4Task.cxx:548
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
Bool_t fbInitDone
is set kTRUE after first Initialize is done
TGo4ThreadHandler * fxWorkHandler
Thread handler aggregate (threadsafe list of go4 threads) aggregationByValue 1 1.
void Launch()
This Method has to be called to create the startup threads and to turn on the application control tim...