Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TTimer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/base:$Id$
0002 // Author: Fons Rademakers   28/11/96
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TTimer
0013 #define ROOT_TTimer
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TTimer                                                               //
0019 //                                                                      //
0020 // Handles synchronous and a-synchronous timer events. You can use      //
0021 // this class in one of the following ways:                             //
0022 //    - Sub-class TTimer and override the Notify() method.              //
0023 //    - Re-implement the TObject::HandleTimer() method in your class    //
0024 //      and pass a pointer to this object to timer, see the SetObject() //
0025 //      method.                                                         //
0026 //    - Pass an interpreter command to timer, see SetCommand() method.  //
0027 //    - Create a TTimer, connect its Timeout() signal to the            //
0028 //      appropriate methods. Then when the time is up it will emit a    //
0029 //      Timeout() signal and call connected slots.                      //
0030 //                                                                      //
0031 //  Minimum timeout interval is defined in TSystem::ESysConstants as    //
0032 //  kItimerResolution (currently 10 ms).                                //
0033 //                                                                      //
0034 //  Signal/slots example:                                               //
0035 //       TTimer *timer = new TTimer();                                  //
0036 //       timer->Connect("Timeout()", "myObjectClassName",               //
0037 //                      myObject, "TimerDone()");                       //
0038 //       timer->Start(2000, kTRUE);   // 2 seconds single-shot          //
0039 //                                                                      //
0040 //    // Timeout signal is emitted repeadetly with minimum timeout      //
0041 //    // timer->Start(0, kFALSE);                                       //
0042 //                                                                      //
0043 //////////////////////////////////////////////////////////////////////////
0044 
0045 #include "TSysEvtHandler.h"
0046 #include "TTime.h"
0047 #include "TString.h"
0048 
0049 
0050 
0051 class TTimer : public TSysEvtHandler {
0052 
0053 protected:
0054    TTime     fTime;        // time out time in ms
0055    TTime     fAbsTime;     // absolute time out time in ms
0056    Bool_t    fTimeout;     // true if timer has timed out
0057    Bool_t    fSync;        // true if synchrounous timer
0058    Bool_t    fIntSyscalls; // true is a-synchronous timer is to interrupt system calls
0059    UInt_t    fTimeID;      // the system ID of this timer (for WIN32)
0060    TObject  *fObject;      // object to be notified (if any)
0061    TString   fCommand;     // interpreter command to be executed
0062 
0063 private:
0064    TTimer(const TTimer&) = delete;
0065    TTimer& operator=(const TTimer&) = delete;
0066 
0067 public:
0068    TTimer(Long_t milliSec = 0, Bool_t mode = kTRUE);
0069    TTimer(TObject *obj, Long_t milliSec, Bool_t mode = kTRUE);
0070    TTimer(const char *command, Long_t milliSec, Bool_t mode = kTRUE);
0071    virtual ~TTimer() { Remove(); }
0072 
0073    Bool_t         CheckTimer(const TTime &now);
0074    const char    *GetCommand() const { return fCommand.Data(); }
0075    TObject       *GetObject() { return fObject; }
0076    TTime          GetTime() const { return fTime; }
0077    UInt_t         GetTimerID() { return fTimeID;}
0078    TTime          GetAbsTime() const { return fAbsTime; }
0079    Bool_t         HasTimedOut() const { return fTimeout; }
0080    Bool_t         IsSync() const { return fSync; }
0081    Bool_t         IsAsync() const { return !fSync; }
0082    Bool_t         IsInterruptingSyscalls() const { return fIntSyscalls; }
0083    Bool_t         IsRunning();
0084    Bool_t         Notify() override;
0085    void           Add() override { TurnOn(); }
0086    void           Remove() override { TurnOff(); }
0087    void           Reset();
0088    void           SetCommand(const char *command);
0089    void           SetObject(TObject *object);
0090    void           SetInterruptSyscalls(Bool_t set = kTRUE);
0091    void           SetTime(Long_t milliSec) { fTime = milliSec; }
0092    void           SetTimerID(UInt_t id = 0) { fTimeID = id; }
0093    virtual void   Start(Long_t milliSec = -1, Bool_t singleShot = kFALSE);
0094    virtual void   Stop() { TurnOff(); }
0095    virtual void   TurnOn();                         //*SIGNAL*
0096    virtual void   TurnOff();                        //*SIGNAL*
0097    virtual void   Timeout() { Emit("Timeout()"); }  //*SIGNAL*
0098 
0099    static void    SingleShot(Int_t milliSec, const char *receiver_class,
0100                              void *receiver, const char *method);
0101 
0102    ClassDefOverride(TTimer,0)  //Handle timer event
0103 };
0104 
0105 #endif