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