GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4ReplaceException.cxx
Go to the documentation of this file.
1 // $Id$
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) {
36  GO4TRACE((13,"TGo4ReplaceException constructor -- new runnable same as old runnable",__LINE__, __FILE__));
37  fxNewRunnable = (TGo4Runnable *) runnable->Clone(); // deep copy
38  *fxNewRunnable=*runnable; // pointers to manager and thread are not streamed,
39  } else {
40  GO4TRACE((13,"TGo4ReplaceException constructor -- new runnable specified",__LINE__, __FILE__));
41  fxNewRunnable = newrunnable;
42  }
43 }
44 
45 
47 {
48  GO4TRACE((14,"TGo4ReplaceException::~TGo4ReplaceException() destructor",__LINE__, __FILE__));
49 }
50 
51 
53 {
54  GO4TRACE((14,"TGo4ReplaceException::operator=",__LINE__, __FILE__));
55  if (&right != this) {
56  TGo4ThreadException::operator=(right); // copy base class members
58  }
59  return *this;
60 }
61 
63 {
64  GO4TRACE((14,"TGo4ReplaceException::Handle()",__LINE__, __FILE__));
65  // first step: find out name of thread to be replaced
66  TString name;
67  if(!GetThreadName())
68  // no threadname specified, use name of thread associated with runnable
69  {
70  GO4TRACE((13,"TGo4ReplaceException::Handle() -- replacing thread associated with runnable",__LINE__, __FILE__));
71  name = fxRunnable->GetThread()->GetName();
72  }
73  else
74  // threadname given, use thread handler to cancel
75  {
76  GO4TRACE((13,"TGo4ReplaceException::Handle() -- replacing thread by specified name",__LINE__, __FILE__));
77  name = GetThreadName();
78  }
79 
80  // second step: remove it
81  fxThreadHandler->RemoveThread(name.Data());
82 
83  // third step: new thread
85  fxThreadHandler->Start(name);
86 
87  TThread::CancelPoint();
88  return 0;
89 
90 }
91 
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:44
TGo4ThreadException & operator=(const TGo4ThreadException &right)
Bool_t NewThread(const char *name, TGo4Runnable *runnable)
TGo4Runnable * fxRunnable
TGo4ReplaceException()=delete
Bool_t Start(const char *thname)
TGo4ReplaceException & operator=(const TGo4ReplaceException &right)
const char * GetThreadName() const
#define GO4TRACE(X)
Definition: TGo4Log.h:25
TGo4ThreadHandler * fxThreadHandler
Bool_t RemoveThread(const char *name)
TString fxDescription
Definition: TGo4Exception.h:38
TGo4Runnable * fxNewRunnable