GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ExampleServer.cxx
Go to the documentation of this file.
1 // $Id: TGo4ExampleServer.cxx 999 2013-07-25 11:58:59Z 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 "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(Form("ControllerRunnable of %s",GetName()), this);
54 
55  TGo4LoggingRunnable* logrun = new TGo4LoggingRunnable(Form("LoggerRunnable of %s",GetName()), 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  {
85  dataq->AddBufferFromObject(new TNamed("StopObject","dummy"));
86  //std::cout << "added dummy data"<< std::endl;
87  }
88  else
89  {
90  //std::cout << "NO data queue"<< std::endl;
91  }
92  threadhandler->Stop(fcLoggingName.Data());
93  if(statusq)
94  {
95  statusq->AddBufferFromObject(new TGo4Status("StopStatus"));
96  //std::cout << "added dummy status"<< std::endl;
97  }
98  else
99  {
100  // std::cout << "NO status queue"<< std::endl;
101  }
102  rev=TGo4ServerTask::StopWorkThreads(); // this will set server task internal flag
103  return rev;
104 }
105 
106 
108 {
109 
110  TGo4Log::Debug(" Example Server is starting work threads ");
111  Int_t rev=0;
112  // start again the working threads on next current task
113  TGo4ThreadHandler* threadhandler= GetWorkHandler();
114  threadhandler->Start(fcControlName.Data());
115  threadhandler->Start(fcLoggingName.Data());
116  rev=TGo4ServerTask::StartWorkThreads(); // this will set server task internal flag
117  return rev;
118 
119 }
virtual Int_t StartWorkThreads()
Definition: TGo4Task.cxx:589
static const char * fgcLOGGINGTHREAD
TGo4ThreadHandler * fxWorkHandler
TGo4ExampleController * fxController
virtual Int_t StopWorkThreads()
Bool_t NewThread(const char *name, TGo4Runnable *runnable)
virtual Int_t StopWorkThreads()
Definition: TGo4Task.cxx:595
TGo4BufferQueue * GetStatusQueue(const char *task=0)
TGo4ThreadHandler * GetWorkHandler() const
Bool_t Stop(const char *thname)
Bool_t Start(const char *thname)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
virtual Int_t StartWorkThreads()
TGo4ExampleController * GetController()
TGo4BufferQueue * GetDataQueue(const char *task=0)
TGo4TaskHandlerCommandList * CreateCommandList()
static const char * fgcCONTROLTHREAD
void AddBufferFromObject(TObject *object)
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270