TTimer.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TTimer.h 20877 2007-11-19 11:17:07Z rdm $
00002 // Author: Fons Rademakers   28/11/96
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TTimer
00013 #define ROOT_TTimer
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TTimer                                                               //
00019 //                                                                      //
00020 // Handles synchronous and a-synchronous timer events. You can use      //
00021 // this class in one of the following ways:                             //
00022 //    - Sub-class TTimer and override the Notify() method.              //
00023 //    - Re-implement the TObject::HandleTimer() method in your class    //
00024 //      and pass a pointer to this object to timer, see the SetObject() //
00025 //      method.                                                         //
00026 //    - Pass an interpreter command to timer, see SetCommand() method.  //
00027 //    - Create a TTimer, connect its Timeout() signal to the            //
00028 //      appropriate methods. Then when the time is up it will emit a    //
00029 //      Timeout() signal and call connected slots.                      //
00030 //                                                                      //
00031 //  Minimum timeout interval is defined in TSystem::ESysConstants as    //
00032 //  kItimerResolution (currently 10 ms).                                //
00033 //                                                                      //
00034 //  Signal/slots example:                                               //
00035 //       TTimer *timer = new TTimer();                                  //
00036 //       timer->Connect("Timeout()", "myObjectClassName",               //
00037 //                      myObject, "TimerDone()");                       //
00038 //       timer->Start(2000, kTRUE);   // 2 seconds single-shot          //
00039 //                                                                      //
00040 //    // Timeout signal is emitted repeadetly with minimum timeout      //
00041 //    // timer->Start(0, kFALSE);                                       //
00042 //                                                                      //
00043 //////////////////////////////////////////////////////////////////////////
00044 
00045 #ifndef ROOT_TSysEvtHandler
00046 #include "TSysEvtHandler.h"
00047 #endif
00048 #ifndef ROOT_TTime
00049 #include "TTime.h"
00050 #endif
00051 #ifndef ROOT_TString
00052 #include "TString.h"
00053 #endif
00054 
00055 
00056 
00057 class TTimer : public TSysEvtHandler {
00058 
00059 protected:
00060    TTime     fTime;        // time out time in ms
00061    TTime     fAbsTime;     // absolute time out time in ms
00062    Bool_t    fTimeout;     // true if timer has timed out
00063    Bool_t    fSync;        // true if synchrounous timer
00064    Bool_t    fIntSyscalls; // true is a-synchronous timer is to interrupt system calls
00065    UInt_t    fTimeID;      // the system ID of this timer (for WIN32)
00066    TObject  *fObject;      // object to be notified (if any)
00067    TString   fCommand;     // interpreter command to be executed
00068 
00069 private:
00070    TTimer(const TTimer&);            // not implemented
00071    TTimer& operator=(const TTimer&); // not implemented
00072 
00073 public:
00074    TTimer(Long_t milliSec = 0, Bool_t mode = kTRUE);
00075    TTimer(TObject *obj, Long_t milliSec, Bool_t mode = kTRUE);
00076    TTimer(const char *command, Long_t milliSec, Bool_t mode = kTRUE);
00077    virtual ~TTimer() { Remove(); }
00078 
00079    Bool_t         CheckTimer(const TTime &now);
00080    const char    *GetCommand() const { return fCommand.Data(); }
00081    TObject       *GetObject() { return fObject; }
00082    TTime          GetTime() const { return fTime; }
00083    UInt_t         GetTimerID() { return fTimeID;}
00084    TTime          GetAbsTime() const { return fAbsTime; }
00085    Bool_t         HasTimedOut() const { return fTimeout; }
00086    Bool_t         IsSync() const { return fSync; }
00087    Bool_t         IsAsync() const { return !fSync; }
00088    Bool_t         IsInterruptingSyscalls() const { return fIntSyscalls; }
00089    virtual Bool_t Notify();
00090    void           Add() { TurnOn(); }
00091    void           Remove() { TurnOff(); }
00092    void           Reset();
00093    void           SetCommand(const char *command);
00094    void           SetObject(TObject *object);
00095    void           SetInterruptSyscalls(Bool_t set = kTRUE);
00096    void           SetTime(Long_t milliSec) { fTime = milliSec; }
00097    void           SetTimerID(UInt_t id = 0) { fTimeID = id; }
00098    virtual void   Start(Long_t milliSec = -1, Bool_t singleShot = kFALSE);
00099    virtual void   Stop() { TurnOff(); }
00100    virtual void   TurnOn();                         //*SIGNAL*
00101    virtual void   TurnOff();                        //*SIGNAL*
00102    virtual void   Timeout() { Emit("Timeout()"); }  //*SIGNAL*
00103 
00104    static void    SingleShot(Int_t milliSec, const char *receiver_class,
00105                              void *receiver, const char *method);
00106 
00107    ClassDef(TTimer,0)  //Handle timer event
00108 };
00109 
00110 #endif

Generated on Tue Jul 5 14:10:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1