Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4AppControlTimer.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "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 //cout <<"!!!!!!!!!!!!!!! Destructor of TGo4AppControlTimer" << endl;
00047      if(fxCondition)
00048          {
00049             delete fxCondition;
00050             fxCondition=0;
00051          }
00052 }
00053 
00054 Bool_t TGo4AppControlTimer::Notify ()
00055 {
00056    //TRACE((12,"TGo4AppControlTimer::Notify()",__LINE__, __FILE__));
00057 
00058 //   TurnOff();
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       // init successfull?
00067       {
00068          TRACE((11,"TGo4AppControlTimer: Successful Initialization",__LINE__, __FILE__));
00069          if(!fbApplicationRun)
00070             // root TApplication shall be blocked
00071             {
00072             TRACE((11,"TGo4AppControlTimer: Application shall be blocked!",__LINE__, __FILE__));
00073             if(TThread::Exists())
00074                // necessary to avoid gThreadImp bug in condition wait...
00075                {
00076                // normal mode:
00077                   TRACE((10,"TGo4AppControlTimer: blocking ROOT gSystem!",__LINE__, __FILE__));
00078                   TGo4Log::Debug(" Application Control Timer --  Blocking ROOT gSystem!! ");
00079                   fxCondition->Wait();  // wait for running signal
00080                   TGo4Log::Debug(" Application Control Timer --  Releasing ROOT gSystem!! ");
00081                }
00082             else
00083                {
00084                   // no thread up, cannot wait for condition
00085                   TRACE((10,"TGo4AppControlTimer: no TThread existing, not blocking !",__LINE__, __FILE__));
00086                }
00087           }
00088         else
00089           {
00090             // do not block :)
00091             TRACE((11,"TGo4AppControlTimer: Application shall not be blocked!",__LINE__, __FILE__));
00092           }
00093 
00094         if(fxManager->IsTerminating())
00095           // check if Timer was woken for program end
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                //cout << "TGo4AppControlTimer waiting for Runnables to stop..."<<t<<endl;
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;      // executes dtors
00109             fxManager=0;
00110             TurnOff(); // do not call this Notify again in Terminate
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           } // if(pleaseterminate)
00123         else
00124           {
00125             // prepare for another timer cycle
00126             TRACE((11,"TGo4AppControlTimer: Resetting for new cycle",__LINE__, __FILE__));
00127             Reset();
00128   //          TurnOn();
00129           }
00130       } //if(fxManager->Initialization()==0)
00131    else
00132       // init not successful
00133       {
00134          TRACE((11,"TGo4AppControlTimer: Initialization failed",__LINE__, __FILE__));
00135          TGo4Log::Debug(" Application Control Timer --  ThreadManager Init not successful, retrying! ");
00136          Reset();
00137 //         TurnOn();
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:31 2008 for Go4-v3.04-1 by  doxygen 1.4.2