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