GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Slave.cxx
Go to the documentation of this file.
1 // $Id: TGo4Slave.cxx 2627 2019-10-01 08:02:45Z linev $
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=0;
33  if(IsServer())
34  {
35  task=new TGo4ServerTask(name, negotport,
36  kFALSE, //blockingmode
37  kFALSE, //standalone
38  kTRUE, //autostart
39  kTRUE, //autocreate
40  kFALSE //ismaster
41  );
42  }
43  else
44  {
45  task=new TGo4ClientTask(name, serverhost, negotport,
46  kFALSE, //blockingmode
47  kFALSE, //standalone
48  kFALSE, //autostart
49  kTRUE, //autocreate
50  kFALSE, //ismaster
51  kTRUE );//autoconnect
52  }
53  SetTask(task);
54 }
55 
56 TGo4Slave::TGo4Slave() : fbMainIsRunning(kTRUE)
57 {
58 }
59 
61 {
63 }
64 
65 
67 {
68  TGo4Log::Debug(" Slave ''%s'' default Start method, please override",GetName());
69  fbMainIsRunning = kTRUE;
70 }
71 
72 
74 {
75  TGo4Log::Debug(" Slave ''%s'' default Stop method, please override",GetName());
76  fbMainIsRunning = kFALSE;
77 }
78 
80 {
81 // may be overridden by concrete slave implementation
82 
83 }
85 {
86 // may be overridden by concrete slave implementation
87 }
88 
89 void TGo4Slave::Terminate (Bool_t termapp)
90 {
91  if(GetTask())
92  GetTask()->TGo4ThreadManager::Terminate(termapp);
93 }
94 
96 {
97  Terminate();
98 }
99 
100 
102 {
103  TGo4TaskStatus* stat= new TGo4TaskStatus(GetName());
104  UpdateStatus(stat); // set the internals
105  return stat;
106 }
107 
109 {
110  if(GetTask())
111  GetTask()->UpdateStatus(state);
112 }
113 
115 {
116  return GetTask() ? GetTask()->NextCommand() : 0;
117 }
118 
119 void TGo4Slave::SendObject(TObject * obj, const char* receiver)
120 {
121  if(GetTask())
122  GetTask()->SendObject(obj, receiver);
123 }
124 
125 void TGo4Slave::SendStatus(TGo4Status * stat, const char* receiver)
126 {
127  if(GetTask())
128  GetTask()->SendStatus(stat, receiver);
129 }
130 
132 {
133 // may be overridden by concrete slave implementation
134  return 0;
135 }
136 
138 {
139  return GetTask() ? GetTask()->GetWorkHandler() : 0;
140 }
141 
142 
144 {
145  if(GetTask()) GetTask()->SendStatusBuffer();
146 }
147 
148 
149 void TGo4Slave::SendStatusMessage(Int_t level, Bool_t printout, const TString& text)
150 {
151  if(GetTask())
152  GetTask()->SendStatusMessage(level, printout, text.Data());
153 }
154 
155 
157 {
159 }
160 
161 void TGo4Slave::ExecuteString(const char* command)
162 {
163  gROOT->ProcessLineSync(command);
164 }
165 
virtual void UpdateStatus(TGo4TaskStatus *state)
Definition: TGo4Task.cxx:407
virtual Int_t Initialization()
Definition: TGo4Slave.cxx:131
virtual void Terminate(Bool_t termapp=kTRUE)
Definition: TGo4Slave.cxx:89
TGo4ThreadHandler * GetThreadHandler()
Definition: TGo4Slave.cxx:137
void SendStatusBuffer()
Definition: TGo4Slave.cxx:143
virtual TGo4TaskStatus * CreateStatus()
Definition: TGo4Slave.cxx:101
virtual void UpdateStatus(TGo4TaskStatus *state)
Definition: TGo4Slave.cxx:108
static void SetCommandList(TGo4CommandProtoList *list)
static void UnRegister(TGo4CommandReceiver *p)
virtual TGo4Command * NextCommand()
Definition: TGo4Task.cxx:339
virtual void TerminateFast()
Definition: TGo4Slave.cxx:95
static void Register(const char *name, TGo4CommandReceiver *p)
virtual void ExecuteString(const char *command)
Definition: TGo4Slave.cxx:161
virtual void Start()
Definition: TGo4Slave.cxx:66
virtual void Stop()
Definition: TGo4Slave.cxx:73
Bool_t IsServer()
Definition: TGo4TaskOwner.h:39
virtual void SendStatusBuffer()
Definition: TGo4Task.cxx:276
friend class TGo4ServerTask
Definition: TGo4TaskOwner.h:29
void SendObject(TObject *obj, const char *receiver=0)
Definition: TGo4Task.cxx:235
virtual void SendStatus(TGo4Status *stat, const char *receiver=0)
Definition: TGo4Task.cxx:259
static TGo4CommandInvoker * Instance()
TGo4Task * GetTask()
Definition: TGo4TaskOwner.h:41
Bool_t fbMainIsRunning
Definition: TGo4Slave.h:34
TGo4ThreadHandler * GetWorkHandler() const
void SendObject(TObject *obj, const char *receiver=0)
Definition: TGo4Slave.cxx:119
const char * GetName() const
void SendStatusMessage(Int_t level, Bool_t printout, const char *text,...)
Definition: TGo4Task.cxx:285
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
Definition: TGo4Slave.cxx:149
virtual void RestartMain()
Definition: TGo4Slave.cxx:84
void SetTask(TGo4Task *task, Bool_t delold=kTRUE)
void UpdateStatusBuffer()
Definition: TGo4Task.cxx:322
void SendStatus(TGo4Status *stat, const char *receiver=0)
Definition: TGo4Slave.cxx:125
void UpdateStatusBuffer()
Definition: TGo4Slave.cxx:156
virtual void KillMain()
Definition: TGo4Slave.cxx:79
virtual ~TGo4Slave()
Definition: TGo4Slave.cxx:60
TGo4Command * NextCommand()
Definition: TGo4Slave.cxx:114
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284