00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4ExampleServer.h"
00015
00016 #include "Riostream.h"
00017
00018 #include "TGo4Log.h"
00019 #include "TGo4Status.h"
00020 #include "TGo4BufferQueue.h"
00021 #include "TGo4ThreadHandler.h"
00022
00023 #include "TGo4LoggingRunnable.h"
00024 #include "TGo4ControllerRunnable.h"
00025 #include "TGo4ExampleCommandList.h"
00026
00027 const char* TGo4ExampleServer::fgcLOGGINGTHREAD="LOGGER-";
00028 const char* TGo4ExampleServer::fgcCONTROLTHREAD="CONTROL-";
00029
00030 TGo4ExampleController* TGo4ExampleServer::GetController()
00031 {
00032 TRACE((12,"TGo4ExampleServer::GetController()",__LINE__, __FILE__));
00033
00034 return fxController;
00035 }
00036 TGo4ExampleServer::~TGo4ExampleServer()
00037 {
00038 TRACE((15,"TGo4ExampleServer::~TGo4ExampleServer() destructor",__LINE__, __FILE__));
00039
00040 fxWorkHandler->CancelAll();
00041 delete fxController;
00042
00043 }
00044 TGo4ExampleServer::TGo4ExampleServer(const char* name,
00045 UInt_t negotiationport,
00046 Bool_t blockingmode)
00047 : TGo4ServerTask(name, negotiationport, blockingmode,kFALSE)
00048 {
00049 TRACE((15,"TGo4ExampleServer::TGo4ExampleServer(const char*, Bool_t) constructor",__LINE__, __FILE__));
00050
00051 TGo4Log::Debug(" ExampleServer ''%s'' started ",GetName());
00052
00053 fxController = new TGo4ExampleController();
00054
00055 TGo4ControllerRunnable* controlrun= new TGo4ControllerRunnable(Form("ControllerRunnable of %s",GetName()), this);
00056
00057 TGo4LoggingRunnable* logrun = new TGo4LoggingRunnable(Form("LoggerRunnable of %s",GetName()), this);
00058
00059
00060
00061 fcControlName.Form("%s%s",fgcCONTROLTHREAD,GetName());
00062 fxWorkHandler->NewThread(fcControlName.Data(), controlrun);
00063
00064 fcLoggingName.Form("%s%s",fgcLOGGINGTHREAD,GetName());
00065 fxWorkHandler->NewThread(fcLoggingName.Data(),logrun);
00066
00067 Launch();
00068 }
00069
00070 TGo4TaskHandlerCommandList* TGo4ExampleServer::CreateCommandList()
00071 {
00072 return (new TGo4ExampleCommandList);
00073 }
00074
00075 Int_t TGo4ExampleServer::StopWorkThreads()
00076 {
00077
00078 TGo4Log::Debug(" Example Server is stopping work threads ");
00079 Int_t rev=0;
00080 TGo4ThreadHandler* threadhandler= GetWorkHandler();
00081 TGo4BufferQueue* dataq=GetDataQueue();
00082 TGo4BufferQueue* statusq=GetStatusQueue();
00083
00084 threadhandler->Stop(fcControlName.Data());
00085 if(dataq)
00086 {
00087 dataq->AddBufferFromObject(new TNamed("StopObject","dummy"));
00088
00089 }
00090 else
00091 {
00092
00093 }
00094 threadhandler->Stop(fcLoggingName.Data());
00095 if(statusq)
00096 {
00097 statusq->AddBufferFromObject(new TGo4Status("StopStatus"));
00098
00099 }
00100 else
00101 {
00102
00103 }
00104 rev=TGo4ServerTask::StopWorkThreads();
00105 return rev;
00106 }
00107
00108
00109 Int_t TGo4ExampleServer::StartWorkThreads()
00110 {
00111
00112 TGo4Log::Debug(" Example Server is starting work threads ");
00113 Int_t rev=0;
00114
00115 TGo4ThreadHandler* threadhandler= GetWorkHandler();
00116 threadhandler->Start(fcControlName.Data());
00117 threadhandler->Start(fcLoggingName.Data());
00118 rev=TGo4ServerTask::StartWorkThreads();
00119 return rev;
00120
00121 }