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