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

TGo4Slave.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 "TGo4Slave.h"
00017 
00018 #include "TROOT.h"
00019 #include "snprintf.h"
00020 
00021 #include "TGo4Log.h"
00022 #include "TGo4TaskStatus.h"
00023 #include "TGo4ServerTask.h"
00024 #include "TGo4ClientTask.h"
00025 #include "TGo4CommandInvoker.h"
00026 #include "TGo4TaskHandlerCommandList.h"
00027 
00028 TGo4Slave::TGo4Slave(const char* name, Bool_t isserver, const char* serverhost, UInt_t negotport)
00029 :TGo4TaskOwner(isserver),
00030  fbMainIsRunning(kTRUE)
00031 {
00032    TGo4CommandInvoker::Instance(); // make sure a command invoker exists
00033    TGo4CommandInvoker::SetCommandList(new TGo4TaskHandlerCommandList("ListOfTaskHandlerCommands"));
00034    TGo4CommandInvoker::Register("SlaveTask", this);
00035    TGo4Task* task=0;
00036    if(IsServer())
00037       {
00038          task=new TGo4ServerTask(name, negotport,
00039                kFALSE, //blockingmode
00040                kFALSE, //standalone
00041                kTRUE,  //autostart
00042                kTRUE,  //autocreate
00043                kFALSE   //ismaster
00044                );
00045       }
00046    else
00047       {
00048          task=new TGo4ClientTask(name, serverhost, negotport,
00049                      kFALSE, //blockingmode
00050                      kFALSE, //standalone
00051                      kFALSE, //autostart
00052                      kTRUE,  //autocreate
00053                      kFALSE, //ismaster
00054                      kTRUE );//autoconnect
00055       }
00056    SetTask(task);
00057 }
00058 
00059 TGo4Slave::TGo4Slave():fbMainIsRunning(kTRUE)
00060 {
00061 
00062 }
00063 
00064 TGo4Slave::~TGo4Slave()
00065 {
00066     TGo4CommandInvoker::UnRegister(this);
00067 }
00068 
00069 
00070 void TGo4Slave::Start()
00071 {
00072    TGo4Log::Debug(" Slave ''%s'' default Start method, please override",GetName());
00073    fbMainIsRunning=kTRUE;
00074 }
00075 void TGo4Slave::Stop()
00076 {
00077    TGo4Log::Debug(" Slave ''%s'' default Stop method, please override",GetName());
00078    fbMainIsRunning=kFALSE;
00079 }
00080 
00081 void TGo4Slave::KillMain()
00082 {
00083 // may be overridden by concrete slave implementation
00084 
00085 }
00086 void TGo4Slave::RestartMain()
00087 {
00088 // may be overridden by concrete slave implementation
00089 }
00090 
00091 void TGo4Slave::Terminate (Bool_t termapp)
00092 {
00093    if(GetTask())
00094       GetTask()->TGo4ThreadManager::Terminate(termapp);
00095 }
00096 
00097 void TGo4Slave::TerminateFast ()
00098 {
00099    Terminate();
00100 }
00101 
00102 
00103 TGo4TaskStatus* TGo4Slave::CreateStatus()
00104 {
00105    TGo4TaskStatus* stat= new TGo4TaskStatus(GetName());
00106    UpdateStatus(stat); // set the internals
00107    return stat;
00108 }
00109 
00110 void TGo4Slave::UpdateStatus(TGo4TaskStatus* state)
00111 {
00112    if(GetTask())
00113       GetTask()->UpdateStatus(state);
00114 }
00115 
00116 TGo4Command* TGo4Slave::NextCommand()
00117 {
00118    if(GetTask())
00119       return (GetTask()->NextCommand());
00120    else
00121       return 0;
00122 }
00123 
00124 
00125 
00126 void TGo4Slave::SendObject(TObject * obj, const char* receiver)
00127 {
00128    if(GetTask())
00129       GetTask()->SendObject(obj, receiver);
00130 }
00131 
00132 void TGo4Slave::SendStatus(TGo4Status * stat, const char* receiver)
00133 {
00134    if(GetTask())
00135       GetTask()->SendStatus(stat, receiver);
00136 }
00137 
00138 Int_t TGo4Slave::Initialization()
00139 {
00140 // may be overridden by concrete slave implementation
00141     return 0;
00142 }
00143 
00144 TGo4ThreadHandler* TGo4Slave::GetThreadHandler()
00145 {
00146    if(GetTask())
00147       return(GetTask()->GetWorkHandler());
00148    else
00149       return 0;
00150 }
00151 
00152 
00153 void TGo4Slave::SendStatusBuffer()
00154 {
00155    if(GetTask()) GetTask()->SendStatusBuffer();
00156 }
00157 
00158 void TGo4Slave::SendStatusMessage(Int_t level, Bool_t printout, const char* text,...)
00159 {
00160    if(GetTask()==0) return;
00161    Int_t lbuflen=256;
00162    // put potential printf arguments in text:
00163    Text_t txtbuf[256];
00164    va_list args;
00165    va_start(args, text);
00166    vsnprintf(txtbuf, lbuflen, text, args);
00167    va_end(args);
00168    GetTask()->SendStatusMessage(level, printout, txtbuf);
00169 }
00170 
00171 void TGo4Slave::UpdateStatusBuffer()
00172 {
00173    if(GetTask()) GetTask()->UpdateStatusBuffer();
00174 }
00175 void TGo4Slave::ExecuteString(const Text_t* command)
00176 {
00177    gROOT->ProcessLine(command);
00178 }
00179 
00180 
00181 //----------------------------END OF GO4 SOURCE FILE ---------------------

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