00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4AppControlTimer.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TGo4ThreadManager.h"
00021 #include "TCondition.h"
00022 #include "TApplication.h"
00023 #include "Go4Log/TGo4Log.h"
00024
00025 UInt_t TGo4AppControlTimer::fguTERMWAIT = 3000;
00026
00027 Int_t TGo4AppControlTimer::fgiTERMWAITCYCLES = 5;
00028
00029
00030 TGo4AppControlTimer::TGo4AppControlTimer(const TGo4AppControlTimer &right)
00031 :TTimer(right)
00032 {
00033 TRACE((15,"TGo4AppControlTimer::TGo4AppControlTimer copy ctor",__LINE__, __FILE__));
00034 fxManager=right.fxManager;
00035 fbApplicationRun=right.fbApplicationRun;
00036 fxCondition= new TCondition();
00037 }
00038
00039 TGo4AppControlTimer::TGo4AppControlTimer (TGo4ThreadManager* manager, Long_t msperiod, Bool_t mode)
00040 :TTimer(msperiod,mode),
00041 fxManager(0),
00042 fbApplicationRun(kFALSE)
00043 {
00044 TRACE((15,"TGo4AppControlTimer::TGo4AppControlTimer(TGo4ThreadManager*, Long_t, Bool_t) ctor",__LINE__, __FILE__));
00045 fxManager=manager;
00046 fxCondition=new TCondition();
00047 }
00048
00049
00050 TGo4AppControlTimer::~TGo4AppControlTimer()
00051 {
00052 TRACE((15,"TGo4AppControlTimer::~TGo4AppControlTimer() dtor",__LINE__, __FILE__));
00053 if(fxCondition)
00054 {
00055 delete fxCondition;
00056 fxCondition=0;
00057 }
00058 }
00059
00060
00061 TGo4AppControlTimer & TGo4AppControlTimer::operator=(const TGo4AppControlTimer &right)
00062 {
00063 TRACE((15,"TGo4AppControlTimer::operator=",__LINE__, __FILE__));
00064 if (&right!=this)
00065 {
00066 delete fxCondition;
00067 TTimer::operator=(right);
00068 fxManager=right.fxManager;
00069 fbApplicationRun=right.fbApplicationRun;
00070 fxCondition= new TCondition();
00071 return *this;
00072 }
00073 else
00074 {
00075
00076 return *this;
00077 }
00078 }
00079
00080 Bool_t TGo4AppControlTimer::Notify ()
00081 {
00082
00083
00084
00085 if(fxManager->Initialization()==0)
00086
00087 {
00088 TRACE((11,"TGo4AppControlTimer: Successful Initialization",__LINE__, __FILE__));
00089 if(!fbApplicationRun)
00090
00091 {
00092 TRACE((11,"TGo4AppControlTimer: Application shall be blocked!",__LINE__, __FILE__));
00093 if(TThread::Exists())
00094
00095 {
00096
00097 TRACE((10,"TGo4AppControlTimer: blocking ROOT gSystem!",__LINE__, __FILE__));
00098 TGo4Log::Debug(" Application Control Timer -- Blocking ROOT gSystem!! ");
00099 fxCondition->Wait();
00100 TGo4Log::Debug(" Application Control Timer -- Releasing ROOT gSystem!! ");
00101 }
00102 else
00103 {
00104
00105 TRACE((10,"TGo4AppControlTimer: no TThread existing, not blocking !",__LINE__, __FILE__));
00106 }
00107 }
00108 else
00109 {
00110
00111 TRACE((11,"TGo4AppControlTimer: Application shall not be blocked!",__LINE__, __FILE__));
00112 }
00113
00114 if(fxManager->IsTerminating())
00115
00116 {
00117 TRACE((11,"TGo4AppControlTimer: Terminating mode",__LINE__, __FILE__));
00118 Int_t t=0;
00119 while(!(fxManager->GetWorkHandler()->AllWaiting()) && (t++<fgiTERMWAITCYCLES) )
00120 {
00121 TGo4Log::Debug(" Application Control Timer -- waiting for Runnables to stop... ");
00122
00123 gSystem->Sleep(fguTERMWAIT);
00124 fxManager->GetWorkHandler()->StopAll();
00125 }
00126 TGo4Log::Debug(" Application Control Timer -- deleting TGo4ThreadManager! ");
00127 delete fxManager;
00128 if(fxCondition)
00129 {
00130 delete fxCondition;
00131 fxCondition=0;
00132 }
00133 TurnOff();
00134 if(fxManager->IsTerminateApp())
00135 {
00136 TGo4Log::Debug(" Application Control Timer -- Terminating Application now! Goodbye...");
00137 gApplication->Terminate(0);
00138 }
00139 return kFALSE;
00140 }
00141 else
00142 {
00143
00144 TRACE((11,"TGo4AppControlTimer: Resetting for new cycle",__LINE__, __FILE__));
00145 Reset();
00146
00147 }
00148 }
00149 else
00150
00151 {
00152 TRACE((11,"TGo4AppControlTimer: Initialization failed",__LINE__, __FILE__));
00153 TGo4Log::Debug(" Application Control Timer -- ThreadManager Init not successful, retrying! ");
00154 Reset();
00155
00156 }
00157 return kFALSE;
00158 }
00159
00160 Bool_t TGo4AppControlTimer::GetApplicationRun ()
00161 {
00162 TRACE((12,"TGo4AppControlTimer::GetApplicationRun ()",__LINE__, __FILE__));
00163 return fbApplicationRun;
00164 }
00165
00166
00167
00168
00169
00170