GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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"
24
25const char *TGo4ExampleServer::fgcLOGGINGTHREAD="LOGGER-";
26const char *TGo4ExampleServer::fgcCONTROLTHREAD="CONTROL-";
27
29{
30 GO4TRACE((12,"TGo4ExampleServer::GetController()",__LINE__, __FILE__));
31
32 return fxController;
33}
35{
36 GO4TRACE((15,"TGo4ExampleServer::~TGo4ExampleServer()",__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)",__LINE__, __FILE__));
48
49 TGo4Log::Debug(" ExampleServer ''%s'' started ",GetName());
50
52
53 auto controlrun = new TGo4ControllerRunnable(TString::Format("ControllerRunnable of %s",GetName()).Data(), this);
54
55 auto 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
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}
#define GO4TRACE(X)
Definition TGo4Log.h:25
Class containing a pointer queue for TBuffers.
void AddBufferFromObject(TObject *object)
Reconstruct a TObject queue entry from a given TBuffer pointer.
runnable performing the main action of example client task: getting commands out of command queue,...
example class for a user control interface (might be a kind of GUI later on); methods of this class a...
Int_t StartWorkThreads() override
start the working threads of the task implementation; this method is used after the current connectio...
Int_t StopWorkThreads() override
stop the working threads of the task implementation; this method is used before the current connectio...
TString fcControlName
remember name of controller thread
TGo4TaskHandlerCommandList * CreateCommandList() override
factory method for command list; overridden by implementation
static const char * fgcCONTROLTHREAD
suffix for controller thread name
TString fcLoggingName
remember name of logging thread
static const char * fgcLOGGINGTHREAD
suffix for logging thread name
TGo4ExampleController * fxController
aggregationByValue 1 0..1
TGo4ExampleController * GetController()
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
runnable performing control watcher functions of example client task: status of application is send t...
TGo4ServerTask(const char *name, UInt_t negotiationport=0, Bool_t blockingmode=kFALSE, Bool_t standalone=kFALSE, Bool_t autostart=kTRUE, Bool_t autocreate=kTRUE, Bool_t ismaster=kTRUE)
TGo4BufferQueue * GetStatusQueue(const char *task=nullptr) override
TGo4BufferQueue * GetDataQueue(const char *task=nullptr) override
Class containing all command prototypes of the TaskHandler system commands (and the basic test comman...
virtual Int_t StopWorkThreads()
stop the working threads of the task implementation; this method is used before the current connectio...
Definition TGo4Task.cxx:554
virtual Int_t StartWorkThreads()
start the working threads of the task implementation; this method is used after the current connectio...
Definition TGo4Task.cxx:548
Go4 thread handler.
Bool_t Start(const char *thname)
Starts work function of the Go4 Thread of name 'name'.
Bool_t Stop(const char *thname)
Stops work function of the Go4 Thread of name 'name'.
TGo4ThreadHandler * fxWorkHandler
Thread handler aggregate (threadsafe list of go4 threads) aggregationByValue 1 1.
TGo4ThreadHandler * GetWorkHandler() const
Access to ThreadHandler for working threads.
void Launch()
This Method has to be called to create the startup threads and to turn on the application control tim...