GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4ExampleClient.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 "TGo4ExampleClient.h"
15 
16 #include <iostream>
17 
18 #include "TGo4Log.h"
19 #include "TGo4TaskHandler.h"
20 #include "TGo4ThreadHandler.h"
21 
23 #include "TGo4MainRunnable.h"
24 #include "TGo4WatchRunnable.h"
25 
26 const char *TGo4ExampleClient::fgcWATCHTHREAD="WATCH-";
27 const char *TGo4ExampleClient::fgcMAINTHREAD="MAIN-";
28 
29 
31  const char *host,
32  UInt_t negport,
33  Bool_t blockingmode)
34 : TGo4ClientTask(name, host, negport, blockingmode, kFALSE)
35 {
36  GO4TRACE((15,"TGo4ExampleClient::TGo4ExampleClient(const char*, const char*, Uint_t, Bool_t) constructor",__LINE__, __FILE__));
37  SetMaster(kFALSE);
38  TGo4Log::Debug(" ExampleClient ''%s'' started ",GetName());
40  TGo4MainRunnable* mainrun = new TGo4MainRunnable(TString::Format("MainRunnable of %s",GetName()).Data(), this);
41  TGo4WatchRunnable* watchrun = new TGo4WatchRunnable(TString::Format("WatchRunnable of %s",GetName()).Data(), this);
42  // adding runnables to thread handler who takes over the responsibility...:
43  fcMainName.Form("%s%s", fgcMAINTHREAD, GetName());
44  fxWorkHandler->NewThread(fcMainName.Data(), mainrun);
45  fcWatchName.Form("%s%s", fgcWATCHTHREAD, GetName());
46  fxWorkHandler->NewThread(fcWatchName.Data(), watchrun);
47  Launch();
48 }
49 
51 {
52  GO4TRACE((15,"TGo4ExampleClient::~TGo4ExampleClient() destructor",__LINE__, __FILE__));
53  fxWorkHandler->CancelAll(); // make sure threads wont work on application when its deleted
54  delete fxApplication;
55 }
56 
58 {
59  GO4TRACE((12,"TGo4ExampleClient::CreateStatus()",__LINE__, __FILE__));
61  UpdateStatus(stat); // set the internals
62  return stat;
63 
64 }
66 {
67  GO4TRACE((12,"TGo4ExampleClient::UpdateStatus(TGo4ClientStatus*)",__LINE__, __FILE__));
68  TGo4ClientTask::UpdateStatus(state); // fill superclass attributes
69  TGo4ExampleClientStatus* exstate= dynamic_cast<TGo4ExampleClientStatus*> (state);
70  if (exstate) {
72  exstate->SetNames(fcMainName.Data(), fcWatchName.Data());
73  }
74 }
75 
77 {
78  GO4TRACE((12,"TGo4ExampleClient::Stop()",__LINE__, __FILE__));
79  std::cout << "Stop of example client!" << std::endl;
80 
81  TGo4Log::Debug(" ExampleClient ''%s'' executing Stop(): stop main thread",GetName());
82  fxWorkHandler->Stop(fcMainName.Data());
83 }
84 
86 {
87  GO4TRACE((12,"TGo4ExampleClient::Start()",__LINE__, __FILE__));
88  std::cout << "Start of example client!" << std::endl;
89 
90  TGo4Log::Debug(" ExampleClient ''%s'' executing Start(): start main thread",GetName());
92 }
93 
95 {
96  GO4TRACE((12,"TGo4ExampleClient::GetApplication()",__LINE__, __FILE__));
97  return fxApplication;
98 }
void UpdateStatus(TGo4TaskStatus *state) override
static const char * fgcWATCHTHREAD
void Start() override
TGo4BufferQueue * GetDataQueue(const char *task=nullptr) override
TGo4ThreadHandler * fxWorkHandler
TGo4ExampleApplication * fxApplication
void Stop() override
TGo4TaskHandler * GetTaskHandler() override
Bool_t NewThread(const char *name, TGo4Runnable *runnable)
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
void UpdateStatus(TGo4TaskStatus *state) override
TGo4TaskStatus * CreateStatus() override
TH1D * GetHistogram(const char *HistogramName)
Definition: Example1.cxx:43
void SetHistoStatus(TH1 *histogram)
void SetNames(const char *main, const char *watch)
Bool_t Stop(const char *thname)
Bool_t Start(const char *thname)
void SetMaster(Bool_t on=kTRUE)
Definition: TGo4Task.h:294
#define GO4TRACE(X)
Definition: TGo4Log.h:25
TGo4ExampleApplication * GetApplication()
static const char * fgcMAINTHREAD