Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4TaskHandlerExample/TGo4ExampleServer.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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(); // make sure threads wont work on controller instance when its deleted
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       // adding runnables to thread handler who takes over the responsibility...:
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   // stop my own threads, put dummies into queues to release semaphores
00090    threadhandler->Stop(fcControlName);
00091    if(dataq)
00092       {
00093          dataq->AddBufferFromObject(new TNamed("StopObject","dummy"));
00094          //cout << "added dummy data"<<endl;
00095       }
00096    else
00097       {
00098          //cout << "NO data queue"<<endl;
00099       }
00100    threadhandler->Stop(fcLoggingName);
00101    if(statusq)
00102       {
00103          statusq->AddBufferFromObject(new TGo4Status("StopStatus"));
00104          //cout << "added dummy status"<<endl;
00105       }
00106    else
00107       {
00108       //       cout << "NO status queue"<<endl;
00109       }
00110    rev=TGo4ServerTask::StopWorkThreads(); // this will set server task internal flag
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     // start again the  working threads on next current task
00121    TGo4ThreadHandler* threadhandler= GetWorkHandler();
00122    threadhandler->Start(fcControlName);
00123    threadhandler->Start(fcLoggingName);
00124    rev=TGo4ServerTask::StartWorkThreads(); // this will set server task internal flag
00125    return rev;
00126 
00127 }
00128 
00129 
00130 
00131 ClassImp(TGo4ExampleServer)
00132 
00133 
00134 
00135 
00136 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:07 2005 for Go4-v2.10-5 by doxygen1.2.15