GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4Slave.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 "TGo4Slave.h"
15 
16 #include "TROOT.h"
17 
18 #include "TGo4Log.h"
19 #include "TGo4TaskStatus.h"
20 #include "TGo4ServerTask.h"
21 #include "TGo4ClientTask.h"
22 #include "TGo4CommandInvoker.h"
24 
25 TGo4Slave::TGo4Slave(const char *name, Bool_t isserver, const char *serverhost, UInt_t negotport) :
26  TGo4TaskOwner(isserver),
27  fbMainIsRunning(kTRUE)
28 {
29  TGo4CommandInvoker::Instance(); // make sure a command invoker exists
30  TGo4CommandInvoker::SetCommandList(new TGo4TaskHandlerCommandList("ListOfTaskHandlerCommands"));
31  TGo4CommandInvoker::Register("SlaveTask", this);
32  TGo4Task* task = nullptr;
33  if(IsServer()) {
34  task = new TGo4ServerTask(name, negotport,
35  kFALSE, //blockingmode
36  kFALSE, //standalone
37  kTRUE, //autostart
38  kTRUE, //autocreate
39  kFALSE //ismaster
40  );
41  } else {
42  task = new TGo4ClientTask(name, serverhost, negotport,
43  kFALSE, //blockingmode
44  kFALSE, //standalone
45  kFALSE, //autostart
46  kTRUE, //autocreate
47  kFALSE, //ismaster
48  kTRUE );//autoconnect
49  }
50  SetTask(task);
51 }
52 
54 {
55 }
56 
58 {
60 }
61 
62 
64 {
65  TGo4Log::Debug(" Slave ''%s'' default Start method, please override",GetName());
66  fbMainIsRunning = kTRUE;
67 }
68 
69 
71 {
72  TGo4Log::Debug(" Slave ''%s'' default Stop method, please override",GetName());
73  fbMainIsRunning = kFALSE;
74 }
75 
77 {
78 // may be overridden by concrete slave implementation
79 
80 }
82 {
83 // may be overridden by concrete slave implementation
84 }
85 
86 void TGo4Slave::Terminate (Bool_t termapp)
87 {
88  if(GetTask())
89  GetTask()->TGo4ThreadManager::Terminate(termapp);
90 }
91 
93 {
94  Terminate();
95 }
96 
98 {
100  UpdateStatus(stat); // set the internals
101  return stat;
102 }
103 
105 {
106  if(GetTask())
107  GetTask()->UpdateStatus(state);
108 }
109 
111 {
112  return GetTask() ? GetTask()->NextCommand() : nullptr;
113 }
114 
115 void TGo4Slave::SendObject(TObject *obj, const char *receiver)
116 {
117  if(GetTask())
118  GetTask()->SendObject(obj, receiver);
119 }
120 
121 void TGo4Slave::SendStatus(TGo4Status *stat, const char *receiver)
122 {
123  if(GetTask())
124  GetTask()->SendStatus(stat, receiver);
125 }
126 
128 {
129  // may be overridden by concrete slave implementation
130  return 0;
131 }
132 
134 {
135  return GetTask() ? GetTask()->GetWorkHandler() : nullptr;
136 }
137 
138 
140 {
141  if(GetTask()) GetTask()->SendStatusBuffer();
142 }
143 
144 
145 void TGo4Slave::SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
146 {
147  if(GetTask())
148  GetTask()->SendStatusMessage(level, printout, "%s", text.Data());
149 }
150 
151 
153 {
155 }
156 
157 void TGo4Slave::ExecuteString(const char *command)
158 {
159  gROOT->ProcessLineSync(command);
160 }
virtual void UpdateStatus(TGo4TaskStatus *state)
Definition: TGo4Task.cxx:393
const char * GetName() const
void SendObject(TObject *obj, const char *receiver=nullptr)
Definition: TGo4Slave.cxx:115
virtual Int_t Initialization()
Definition: TGo4Slave.cxx:127
virtual void Terminate(Bool_t termapp=kTRUE)
Definition: TGo4Slave.cxx:86
TGo4ThreadHandler * GetThreadHandler()
Definition: TGo4Slave.cxx:133
void SendStatusBuffer()
Definition: TGo4Slave.cxx:139
virtual TGo4TaskStatus * CreateStatus()
Definition: TGo4Slave.cxx:97
virtual void UpdateStatus(TGo4TaskStatus *state)
Definition: TGo4Slave.cxx:104
static void SetCommandList(TGo4CommandProtoList *list)
static void UnRegister(TGo4CommandReceiver *p)
virtual TGo4Command * NextCommand()
Definition: TGo4Task.cxx:325
virtual void TerminateFast()
Definition: TGo4Slave.cxx:92
void SendObject(TObject *obj, const char *receiver=nullptr)
Definition: TGo4Task.cxx:222
TGo4Task * GetTask() const
Definition: TGo4TaskOwner.h:42
static void Register(const char *name, TGo4CommandReceiver *p)
virtual void ExecuteString(const char *command)
Definition: TGo4Slave.cxx:157
virtual void Start()
Definition: TGo4Slave.cxx:63
virtual void Stop()
Definition: TGo4Slave.cxx:70
virtual void SendStatus(TGo4Status *stat, const char *receiver=nullptr)
Definition: TGo4Task.cxx:246
virtual void SendStatusBuffer()
Definition: TGo4Task.cxx:263
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
friend class TGo4ServerTask
Definition: TGo4TaskOwner.h:30
Bool_t IsServer() const
Definition: TGo4TaskOwner.h:40
static TGo4CommandInvoker * Instance()
Bool_t fbMainIsRunning
Definition: TGo4Slave.h:37
void SendStatus(TGo4Status *stat, const char *receiver=nullptr)
Definition: TGo4Slave.cxx:121
void SendStatusMessage(Int_t level, Bool_t printout, const char *text,...)
Definition: TGo4Task.cxx:272
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
Definition: TGo4Slave.cxx:145
TGo4ThreadHandler * GetWorkHandler() const
virtual void RestartMain()
Definition: TGo4Slave.cxx:81
void SetTask(TGo4Task *task, Bool_t delold=kTRUE)
void UpdateStatusBuffer()
Definition: TGo4Task.cxx:308
void UpdateStatusBuffer()
Definition: TGo4Slave.cxx:152
virtual void KillMain()
Definition: TGo4Slave.cxx:76
virtual ~TGo4Slave()
Definition: TGo4Slave.cxx:57
TGo4Command * NextCommand()
Definition: TGo4Slave.cxx:110