Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4ExampleServer.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "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(); // make sure threads wont work on controller instance when its deleted
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       // adding runnables to thread handler who takes over the responsibility...:
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   // stop my own threads, put dummies into queues to release semaphores
00095    threadhandler->Stop(fcControlName);
00096    if(dataq)
00097       {
00098          dataq->AddBufferFromObject(new TNamed("StopObject","dummy"));
00099          //cout << "added dummy data"<<endl;
00100       }
00101    else
00102       {
00103          //cout << "NO data queue"<<endl;
00104       }
00105    threadhandler->Stop(fcLoggingName);
00106    if(statusq)
00107       {
00108          statusq->AddBufferFromObject(new TGo4Status("StopStatus"));
00109          //cout << "added dummy status"<<endl;
00110       }
00111    else
00112       {
00113       //       cout << "NO status queue"<<endl;
00114       }
00115    rev=TGo4ServerTask::StopWorkThreads(); // this will set server task internal flag
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     // start again the  working threads on next current task
00126    TGo4ThreadHandler* threadhandler= GetWorkHandler();
00127    threadhandler->Start(fcControlName);
00128    threadhandler->Start(fcLoggingName);
00129    rev=TGo4ServerTask::StartWorkThreads(); // this will set server task internal flag
00130    return rev;
00131 
00132 }
00133 
00134 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:31 2008 for Go4-v3.04-1 by  doxygen 1.4.2