GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ReplaceException.cxx
Go to the documentation of this file.
1 // $Id: TGo4ReplaceException.cxx 2758 2020-04-16 12:28:24Z 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 "TGo4ReplaceException.h"
15 
16 #include "TThread.h"
17 
18 #include "TGo4Log.h"
19 #include "TGo4Thread.h"
20 #include "TGo4ThreadHandler.h"
21 #include "TGo4Runnable.h"
22 
24  :TGo4ThreadException(right)
25 {
26  GO4TRACE((14,"TGo4ReplaceException::TGo4ReplaceException() copy constructor",__LINE__, __FILE__));
28 }
29 
30 TGo4ReplaceException::TGo4ReplaceException (TGo4Runnable* runnable, TGo4Runnable* newrunnable, const char* oldthreadname)
31  :TGo4ThreadException(runnable, oldthreadname)
32 {
33  GO4TRACE((14,"TGo4ReplaceException::TGo4ReplaceException(TGo4Runnable*,TGo4Runnable*,const char*) constructor",__LINE__, __FILE__));
34  fxDescription= "!!!-- Go4 Replace Exception --!!!";
35  if(newrunnable==0)
36  {
37  GO4TRACE((13,"TGo4ReplaceException constructor -- new runnable same as old runnable",__LINE__, __FILE__));
38  fxNewRunnable=(TGo4Runnable*) runnable->Clone(); // deep copy
39  *fxNewRunnable=*runnable; // pointers to manager and thread are not streamed,
40  // must be handed over by operator= of base class
41  }
42  else
43  {
44  GO4TRACE((13,"TGo4ReplaceException constructor -- new runnable specified",__LINE__, __FILE__));
45  fxNewRunnable=newrunnable;
46  }
47 }
48 
49 
51 {
52  GO4TRACE((14,"TGo4ReplaceException::~TGo4ReplaceException() destructor",__LINE__, __FILE__));
53 }
54 
55 
57 {
58  GO4TRACE((14,"TGo4ReplaceException::operator=",__LINE__, __FILE__));
59  if (&right!=this)
60  {
61  GO4TRACE((13,"TGo4ReplaceException::operator= processing copy",__LINE__, __FILE__));
62  TGo4ThreadException::operator=(right); // copy base class members
63  // put additional member copies here...
65  return *this;
66  }
67  else
68  {
69  // copy is already source object
70  GO4TRACE((13,"TGo4ReplaceException::operator= source and destination objects are identical",__LINE__, __FILE__));
71  return *this;
72  }
73 }
74 
76 {
77  GO4TRACE((14,"TGo4ReplaceException::Handle()",__LINE__, __FILE__));
78  // first step: find out name of thread to be replaced
79  TString name;
80  if(GetThreadName()==0)
81  // no threadname specified, use name of thread associated with runnable
82  {
83  GO4TRACE((13,"TGo4ReplaceException::Handle() -- replacing thread associated with runnable",__LINE__, __FILE__));
84  name = fxRunnable->GetThread()->GetName();
85  }
86  else
87  // threadname given, use thread handler to cancel
88  {
89  GO4TRACE((13,"TGo4ReplaceException::Handle() -- replacing thread by specified name",__LINE__, __FILE__));
90  name = GetThreadName();
91  }
92 
93  // second step: remove it
94  fxThreadHandler->RemoveThread(name.Data());
95 
96  // third step: new thread
98  fxThreadHandler->Start(name);
99 
100  TThread::CancelPoint();
101  return 0;
102 
103 }
104 
105 
106 
107 
TGo4ThreadException & operator=(const TGo4ThreadException &right)
const char * GetThreadName()
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:45
Bool_t NewThread(const char *name, TGo4Runnable *runnable)
TGo4Runnable * fxRunnable
Bool_t Start(const char *thname)
TGo4ReplaceException & operator=(const TGo4ReplaceException &right)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
TGo4ThreadHandler * fxThreadHandler
Bool_t RemoveThread(const char *name)
TString fxDescription
Definition: TGo4Exception.h:38
TGo4Runnable * fxNewRunnable