GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TaskOwner.cxx
Go to the documentation of this file.
1 // $Id: TGo4TaskOwner.cxx 1031 2013-11-05 10:27:23Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4TaskOwner.h"
15 
16 #include "Riostream.h"
17 
18 #include "TGo4Log.h"
19 #include "TGo4Task.h"
20 #include "TGo4ServerTask.h"
21 #include "TGo4TaskManager.h"
22 #include "TGo4ClientTask.h"
23 
24 
27  fxTask(0),
28  fbServerMode(kTRUE)
29 {
30 }
31 
32 TGo4TaskOwner::TGo4TaskOwner(Bool_t isserver) :
34  fxTask(0),
35  fbServerMode(isserver)
36 {
37 }
38 
40 {
41  if(fxTask!=0)
42  fxTask->SetOwner(0); // avoid the task to delete us again in dtor
43  delete fxTask;
44  fxTask = 0;
45 }
46 
47 const char* TGo4TaskOwner::GetName() const
48 {
49  return (fxTask!=0) ? fxTask->GetName() : 0;
50 }
51 
52 void TGo4TaskOwner::SetTask(TGo4Task* task, Bool_t delold)
53 {
54  if(delold) delete fxTask;
55  fxTask=task;
56  if(fxTask) fxTask->SetOwner(this);
57 }
58 
60 {
61  fxTask->Quit();
62 }
63 
65 {
66  TGo4Log::Debug(" Task Owner: default StartWorkThreads() ");
67  fxTask->SetWorkIsStopped(kFALSE);
68  return 0;
69 }
70 
72 {
73  TGo4Log::Debug(" Task Owner: default StopWorkThreads() ");
74  fxTask->SetWorkIsStopped(kTRUE);
75  return 0;
76 }
77 
79 {
80  if(IsServer()) {
81  TGo4ServerTask* server = dynamic_cast<TGo4ServerTask*>(GetTask());
82  if(server==0) {
83  std::cerr <<"NEVER COME HERE: servermode without servertask in taskowner "<< GetName() << std::endl;
84  return kFALSE;
85  }
86  return (server->GetCurrentTaskHandler()!=0);
87  }
88 
89  TGo4ClientTask* client = dynamic_cast<TGo4ClientTask*>(GetTask());
90  if(client==0) {
91  std::cerr <<"NEVER COME HERE: clientmode without clienttask in taskowner "<< GetName() << std::endl;
92  return kFALSE;
93  }
94  return client->IsConnected();
95 }
96 
97 
99 {
100  return fxTask ? fxTask->IsBeingQuit() : kFALSE;
101 }
102 
103 
105 {
106  if(IsServer()) {
107  TGo4ServerTask* serv = dynamic_cast<TGo4ServerTask*>(GetTask());
108  if(serv) return serv->GetTaskManager()->GetMutex();
109  }
110  return 0;
111 }
112 
TGo4Task * fxTask
Definition: TGo4TaskOwner.h:78
Bool_t IsConnected()
void SetWorkIsStopped(Bool_t on)
Definition: TGo4Task.h:293
Bool_t IsBeingQuit() const
virtual ~TGo4TaskOwner()
virtual void Quit()
virtual Int_t StopWorkThreads()
Bool_t IsServer()
Definition: TGo4TaskOwner.h:39
TGo4Task * GetTask()
Definition: TGo4TaskOwner.h:41
TMutex * GetMutex()
Bool_t IsConnected() const
void SetOwner(TGo4TaskOwner *owner)
Definition: TGo4Task.cxx:98
const char * GetName() const
TMutex * GetTaskManagerMutex()
void SetTask(TGo4Task *task, Bool_t delold=kTRUE)
virtual void Quit()
Definition: TGo4Task.cxx:115
TGo4TaskHandler * GetCurrentTaskHandler()
Bool_t IsBeingQuit()
TGo4TaskManager * GetTaskManager()
virtual Int_t StartWorkThreads()
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270