GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4ExampleServer.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 "TGo4ExampleServer.h"
15 
16 #include "TGo4Log.h"
17 #include "TGo4Status.h"
18 #include "TGo4BufferQueue.h"
19 #include "TGo4ThreadHandler.h"
20 
21 #include "TGo4LoggingRunnable.h"
22 #include "TGo4ControllerRunnable.h"
23 #include "TGo4ExampleCommandList.h"
24 
25 const char *TGo4ExampleServer::fgcLOGGINGTHREAD="LOGGER-";
26 const char *TGo4ExampleServer::fgcCONTROLTHREAD="CONTROL-";
27 
29 {
30  GO4TRACE((12,"TGo4ExampleServer::GetController()",__LINE__, __FILE__));
31 
32  return fxController;
33 }
35 {
36  GO4TRACE((15,"TGo4ExampleServer::~TGo4ExampleServer() destructor",__LINE__, __FILE__));
37 
38  fxWorkHandler->CancelAll(); // make sure threads wont work on controller instance when its deleted
39  delete fxController;
40 
41 }
43  UInt_t negotiationport,
44  Bool_t blockingmode)
45 : TGo4ServerTask(name, negotiationport, blockingmode,kFALSE)
46 {
47  GO4TRACE((15,"TGo4ExampleServer::TGo4ExampleServer(const char*, Bool_t) constructor",__LINE__, __FILE__));
48 
49  TGo4Log::Debug(" ExampleServer ''%s'' started ",GetName());
50 
52 
53  TGo4ControllerRunnable* controlrun= new TGo4ControllerRunnable(TString::Format("ControllerRunnable of %s",GetName()).Data(), this);
54 
55  TGo4LoggingRunnable* logrun = new TGo4LoggingRunnable(TString::Format("LoggerRunnable of %s",GetName()).Data(), this);
56 
57  // adding runnables to thread handler who takes over the responsibility...:
58 
59  fcControlName.Form("%s%s",fgcCONTROLTHREAD,GetName());
60  fxWorkHandler->NewThread(fcControlName.Data(), controlrun);
61 
62  fcLoggingName.Form("%s%s",fgcLOGGINGTHREAD,GetName());
63  fxWorkHandler->NewThread(fcLoggingName.Data(),logrun);
64 
65  Launch();
66 }
67 
69 {
70  return new TGo4ExampleCommandList;
71 }
72 
74 {
75 
76  TGo4Log::Debug(" Example Server is stopping work threads ");
77  Int_t rev = 0;
78  TGo4ThreadHandler* threadhandler = GetWorkHandler();
81  // stop my own threads, put dummies into queues to release semaphores
82  threadhandler->Stop(fcControlName.Data());
83  if(dataq)
84  dataq->AddBufferFromObject(new TNamed("StopObject","dummy"));
85  threadhandler->Stop(fcLoggingName.Data());
86  if(statusq)
87  statusq->AddBufferFromObject(new TGo4Status("StopStatus"));
88  rev = TGo4ServerTask::StopWorkThreads(); // this will set server task internal flag
89  return rev;
90 }
91 
92 
94 {
95 
96  TGo4Log::Debug(" Example Server is starting work threads ");
97  Int_t rev = 0;
98  // start again the working threads on next current task
99  TGo4ThreadHandler* threadhandler = GetWorkHandler();
100  threadhandler->Start(fcControlName.Data());
101  threadhandler->Start(fcLoggingName.Data());
102  rev = TGo4ServerTask::StartWorkThreads(); // this will set server task internal flag
103  return rev;
104 
105 }
virtual Int_t StartWorkThreads()
Definition: TGo4Task.cxx:548
TGo4TaskHandlerCommandList * CreateCommandList() override
static const char * fgcLOGGINGTHREAD
TGo4ThreadHandler * fxWorkHandler
TGo4ExampleController * fxController
Bool_t NewThread(const char *name, TGo4Runnable *runnable)
virtual Int_t StopWorkThreads()
Definition: TGo4Task.cxx:554
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
Int_t StopWorkThreads() override
Bool_t Stop(const char *thname)
Bool_t Start(const char *thname)
TGo4BufferQueue * GetDataQueue(const char *task=nullptr) override
Int_t StartWorkThreads() override
TGo4ThreadHandler * GetWorkHandler() const
#define GO4TRACE(X)
Definition: TGo4Log.h:25
TGo4ExampleController * GetController()
static const char * fgcCONTROLTHREAD
void AddBufferFromObject(TObject *object)
TGo4BufferQueue * GetStatusQueue(const char *task=nullptr) override