00001 // $Id: TGo4TaskOwner.cxx 615 2010-04-14 15:34:12Z adamczew $ 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 } 00045 00046 const char* TGo4TaskOwner::GetName() const 00047 { 00048 return (fxTask!=0) ? fxTask->GetName() : 0; 00049 } 00050 00051 void TGo4TaskOwner::SetTask(TGo4Task* task, Bool_t delold) 00052 { 00053 if(delold) delete fxTask; 00054 fxTask=task; 00055 if(fxTask) fxTask->SetOwner(this); 00056 } 00057 00058 void TGo4TaskOwner::Quit() 00059 { 00060 fxTask->Quit(); 00061 } 00062 00063 Int_t TGo4TaskOwner::StartWorkThreads() 00064 { 00065 TGo4Log::Debug(" Task Owner: default StartWorkThreads() "); 00066 fxTask->SetWorkIsStopped(kFALSE); 00067 return 0; 00068 } 00069 Int_t TGo4TaskOwner::StopWorkThreads() 00070 { 00071 TGo4Log::Debug(" Task Owner: default StopWorkThreads() "); 00072 fxTask->SetWorkIsStopped(kTRUE); 00073 return 0; 00074 } 00075 00076 00077 Bool_t TGo4TaskOwner::IsConnected() 00078 { 00079 if(IsServer()) 00080 { 00081 TGo4ServerTask* server=dynamic_cast<TGo4ServerTask*>(GetTask()); 00082 if(server==0) 00083 { 00084 cerr <<"NEVER COME HERE: servermode without servertask in taskowner "<< GetName() << endl; 00085 return kFALSE; 00086 } 00087 return (server->GetCurrentTaskHandler()!=0); 00088 } 00089 else 00090 { 00091 TGo4ClientTask* client=dynamic_cast<TGo4ClientTask*>(GetTask()); 00092 if(client==0) 00093 { 00094 cerr <<"NEVER COME HERE: clientmode without clienttask in taskowner "<< GetName() << endl; 00095 return kFALSE; 00096 } 00097 return (client->IsConnected()); 00098 } 00099 00100 } 00101 00102 00103 Bool_t TGo4TaskOwner::IsBeingQuit() 00104 { 00105 if(fxTask) 00106 return fxTask->IsBeingQuit(); 00107 else 00108 return kFALSE; 00109 } 00110 00111 00112 TMutex* TGo4TaskOwner::GetTaskManagerMutex() 00113 { 00114 if(IsServer()) 00115 { 00116 TGo4ServerTask* serv=dynamic_cast<TGo4ServerTask*>(GetTask()); 00117 if(serv) 00118 return (serv->GetTaskManager()->GetMutex()); 00119 else 00120 return 0; 00121 } 00122 else 00123 { 00124 return 0; 00125 } 00126 } 00127