00001 // $Id: TGo4TaskOwner.cxx 1031 2013-11-05 10:27:23Z linev $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "TGo4TaskOwner.h" 00015 00016 #include "Riostream.h" 00017 00018 #include "TGo4Log.h" 00019 #include "TGo4Task.h" 00020 #include "TGo4ServerTask.h" 00021 #include "TGo4TaskManager.h" 00022 #include "TGo4ClientTask.h" 00023 00024 00025 TGo4TaskOwner::TGo4TaskOwner() : 00026 TGo4CommandReceiver(), 00027 fxTask(0), 00028 fbServerMode(kTRUE) 00029 { 00030 } 00031 00032 TGo4TaskOwner::TGo4TaskOwner(Bool_t isserver) : 00033 TGo4CommandReceiver(), 00034 fxTask(0), 00035 fbServerMode(isserver) 00036 { 00037 } 00038 00039 TGo4TaskOwner::~TGo4TaskOwner() 00040 { 00041 if(fxTask!=0) 00042 fxTask->SetOwner(0); // avoid the task to delete us again in dtor 00043 delete fxTask; 00044 fxTask = 0; 00045 } 00046 00047 const char* TGo4TaskOwner::GetName() const 00048 { 00049 return (fxTask!=0) ? fxTask->GetName() : 0; 00050 } 00051 00052 void TGo4TaskOwner::SetTask(TGo4Task* task, Bool_t delold) 00053 { 00054 if(delold) delete fxTask; 00055 fxTask=task; 00056 if(fxTask) fxTask->SetOwner(this); 00057 } 00058 00059 void TGo4TaskOwner::Quit() 00060 { 00061 fxTask->Quit(); 00062 } 00063 00064 Int_t TGo4TaskOwner::StartWorkThreads() 00065 { 00066 TGo4Log::Debug(" Task Owner: default StartWorkThreads() "); 00067 fxTask->SetWorkIsStopped(kFALSE); 00068 return 0; 00069 } 00070 00071 Int_t TGo4TaskOwner::StopWorkThreads() 00072 { 00073 TGo4Log::Debug(" Task Owner: default StopWorkThreads() "); 00074 fxTask->SetWorkIsStopped(kTRUE); 00075 return 0; 00076 } 00077 00078 Bool_t TGo4TaskOwner::IsConnected() 00079 { 00080 if(IsServer()) { 00081 TGo4ServerTask* server = dynamic_cast<TGo4ServerTask*>(GetTask()); 00082 if(server==0) { 00083 std::cerr <<"NEVER COME HERE: servermode without servertask in taskowner "<< GetName() << std::endl; 00084 return kFALSE; 00085 } 00086 return (server->GetCurrentTaskHandler()!=0); 00087 } 00088 00089 TGo4ClientTask* client = dynamic_cast<TGo4ClientTask*>(GetTask()); 00090 if(client==0) { 00091 std::cerr <<"NEVER COME HERE: clientmode without clienttask in taskowner "<< GetName() << std::endl; 00092 return kFALSE; 00093 } 00094 return client->IsConnected(); 00095 } 00096 00097 00098 Bool_t TGo4TaskOwner::IsBeingQuit() 00099 { 00100 return fxTask ? fxTask->IsBeingQuit() : kFALSE; 00101 } 00102 00103 00104 TMutex* TGo4TaskOwner::GetTaskManagerMutex() 00105 { 00106 if(IsServer()) { 00107 TGo4ServerTask* serv = dynamic_cast<TGo4ServerTask*>(GetTask()); 00108 if(serv) return serv->GetTaskManager()->GetMutex(); 00109 } 00110 return 0; 00111 } 00112