Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4ThreadManager/TGo4AppControlTimer.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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       // copy is already source object
00076       return *this;
00077     }
00078 }
00079 
00080 Bool_t TGo4AppControlTimer::Notify ()
00081 {
00082    //TRACE((12,"TGo4AppControlTimer::Notify()",__LINE__, __FILE__));
00083 
00084 //   TurnOff();
00085    if(fxManager->Initialization()==0)
00086       // init successfull?
00087       {
00088          TRACE((11,"TGo4AppControlTimer: Successful Initialization",__LINE__, __FILE__));
00089          if(!fbApplicationRun)
00090             // root TApplication shall be blocked
00091             {
00092             TRACE((11,"TGo4AppControlTimer: Application shall be blocked!",__LINE__, __FILE__));
00093             if(TThread::Exists())
00094                // necessary to avoid gThreadImp bug in condition wait...
00095                {
00096                // normal mode:
00097                   TRACE((10,"TGo4AppControlTimer: blocking ROOT gSystem!",__LINE__, __FILE__));
00098                   TGo4Log::Debug(" Application Control Timer --  Blocking ROOT gSystem!! ");
00099                   fxCondition->Wait();  // wait for running signal
00100                   TGo4Log::Debug(" Application Control Timer --  Releasing ROOT gSystem!! ");
00101                }
00102             else
00103                {
00104                   // no thread up, cannot wait for condition
00105                   TRACE((10,"TGo4AppControlTimer: no TThread existing, not blocking !",__LINE__, __FILE__));
00106                }
00107           }
00108         else
00109           {
00110             // do not block :)
00111             TRACE((11,"TGo4AppControlTimer: Application shall not be blocked!",__LINE__, __FILE__));
00112           }
00113 
00114         if(fxManager->IsTerminating())
00115           // check if Timer was woken for program end
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                //cout << "TGo4AppControlTimer waiting for Runnables to stop..."<<t<<endl;
00123                gSystem->Sleep(fguTERMWAIT);
00124                fxManager->GetWorkHandler()->StopAll();
00125             }
00126             TGo4Log::Debug(" Application Control Timer --  deleting TGo4ThreadManager! ");
00127             delete fxManager;      // executes dtors
00128             if(fxCondition)
00129                   {
00130                      delete fxCondition;
00131                      fxCondition=0;
00132                   }
00133             TurnOff(); // do not call this Notify again in Terminate
00134             if(fxManager->IsTerminateApp())
00135                { 
00136                   TGo4Log::Debug(" Application Control Timer --  Terminating Application now! Goodbye...");
00137                   gApplication->Terminate(0);
00138                }
00139             return kFALSE;
00140           } // if(fxManager->IsTerminating())
00141         else
00142           {
00143             // prepare for another timer cycle
00144             TRACE((11,"TGo4AppControlTimer: Resetting for new cycle",__LINE__, __FILE__));
00145             Reset();
00146   //          TurnOn();
00147           }
00148       } //if(fxManager->Initialization()==0)
00149    else
00150       // init not successful
00151       {
00152          TRACE((11,"TGo4AppControlTimer: Initialization failed",__LINE__, __FILE__));
00153          TGo4Log::Debug(" Application Control Timer --  ThreadManager Init not successful, retrying! ");
00154          Reset();
00155 //         TurnOn();
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:07 2005 for Go4-v2.10-5 by doxygen1.2.15