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