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