GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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
15
16#include "TThread.h"
17
18#include "TGo4Log.h"
19#include "TGo4Thread.h"
20#include "TGo4ThreadHandler.h"
21#include "TGo4Runnable.h"
22
25{
26 GO4TRACE((14,"TGo4ReplaceException::TGo4ReplaceException(const TGo4ReplaceException &)",__LINE__, __FILE__));
28}
29
30TGo4ReplaceException::TGo4ReplaceException(TGo4Runnable *runnable, TGo4Runnable *newrunnable, const char *oldthreadname)
31 :TGo4ThreadException(runnable, oldthreadname)
32{
33 GO4TRACE((14,"TGo4ReplaceException::TGo4ReplaceException(TGo4Runnable *,TGo4Runnable *,const char *)",__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()",__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 GO4TRACE((13, "TGo4ReplaceException::Handle() -- replacing thread associated with runnable", __LINE__, __FILE__));
70 name = fxRunnable->GetThread()->GetName();
71 } else {
72 // threadname given, use thread handler to cancel
73 GO4TRACE((13, "TGo4ReplaceException::Handle() -- replacing thread by specified name", __LINE__, __FILE__));
74 name = GetThreadName();
75 }
76
77 // second step: remove it
78 fxThreadHandler->RemoveThread(name.Data());
79
80 // third step: new thread
81 fxThreadHandler->NewThread(name, fxNewRunnable);
82 fxThreadHandler->Start(name);
83
84 TThread::CancelPoint();
85 return 0;
86}
87
#define GO4TRACE(X)
Definition TGo4Log.h:25
TString fxDescription
TGo4ReplaceException & operator=(const TGo4ReplaceException &right)
Int_t Handle() override
This is a default handler function for the respective exception type.
TGo4ReplaceException()=delete
Base class for all go4 runnables.
TGo4ThreadException()=delete
TGo4Runnable * fxRunnable
Link to the runnable connected with the thread (exception throwing runnable might simply pass its 'th...
const char * GetThreadName() const
TGo4ThreadException & operator=(const TGo4ThreadException &right)
TGo4ThreadHandler * fxThreadHandler
Link to threadhandler associated with the runnable.