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