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