GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TaskOwner.cxx
Go to the documentation of this file.
1 // $Id: TGo4TaskOwner.cxx 2757 2020-04-16 11:45:21Z 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 fuer 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 <iostream>
17 
18 #include "TGo4Log.h"
19 #include "TGo4ServerTask.h"
20 #include "TGo4TaskManager.h"
21 #include "TGo4ClientTask.h"
22 
23 
26  fxTask(0),
27  fbServerMode(kTRUE)
28 {
29 }
30 
31 TGo4TaskOwner::TGo4TaskOwner(Bool_t isserver) :
33  fxTask(0),
34  fbServerMode(isserver)
35 {
36 }
37 
39 {
40  if(fxTask!=0)
41  fxTask->SetOwner(0); // avoid the task to delete us again in dtor
42  delete fxTask;
43  fxTask = 0;
44 }
45 
46 const char* TGo4TaskOwner::GetName() const
47 {
48  return (fxTask!=0) ? fxTask->GetName() : 0;
49 }
50 
51 void TGo4TaskOwner::SetTask(TGo4Task* task, Bool_t delold)
52 {
53  if(delold) delete fxTask;
54  fxTask=task;
55  if(fxTask) fxTask->SetOwner(this);
56 }
57 
59 {
60  fxTask->Quit();
61 }
62 
64 {
65  TGo4Log::Debug(" Task Owner: default StartWorkThreads() ");
66  fxTask->SetWorkIsStopped(kFALSE);
67  return 0;
68 }
69 
71 {
72  TGo4Log::Debug(" Task Owner: default StopWorkThreads() ");
73  fxTask->SetWorkIsStopped(kTRUE);
74  return 0;
75 }
76 
78 {
79  if(IsServer()) {
80  TGo4ServerTask* server = dynamic_cast<TGo4ServerTask*>(GetTask());
81  if(server==0) {
82  std::cerr <<"NEVER COME HERE: servermode without servertask in taskowner "<< GetName() << std::endl;
83  return kFALSE;
84  }
85  return (server->GetCurrentTaskHandler()!=0);
86  }
87 
88  TGo4ClientTask* client = dynamic_cast<TGo4ClientTask*>(GetTask());
89  if(client==0) {
90  std::cerr <<"NEVER COME HERE: clientmode without clienttask in taskowner "<< GetName() << std::endl;
91  return kFALSE;
92  }
93  return client->IsConnected();
94 }
95 
96 
98 {
99  return fxTask ? fxTask->IsBeingQuit() : kFALSE;
100 }
101 
102 
104 {
105  if(IsServer()) {
106  TGo4ServerTask* serv = dynamic_cast<TGo4ServerTask*>(GetTask());
107  if(serv) return serv->GetTaskManager()->GetMutex();
108  }
109  return 0;
110 }
111 
TGo4Task * fxTask
Definition: TGo4TaskOwner.h:78
Bool_t IsConnected()
void SetWorkIsStopped(Bool_t on)
Definition: TGo4Task.h:292
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:99
const char * GetName() const
TMutex * GetTaskManagerMutex()
void SetTask(TGo4Task *task, Bool_t delold=kTRUE)
virtual void Quit()
Definition: TGo4Task.cxx:116
TGo4TaskHandler * GetCurrentTaskHandler()
Bool_t IsBeingQuit()
TGo4TaskManager * GetTaskManager()
virtual Int_t StartWorkThreads()
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284