library: libCore #include "TTimer.h"

# TTimer

class description - source file - inheritance tree (.pdf)

## class TTimer : public TSysEvtHandler

| Inheritance Chart:

`TObject`

`TQObject`

<-

`TSysEvtHandler`

<-

`TTimer`

<-

`TProcessEventTimer` |

        public:

                          TTimer(Long_t milliSec = 0, Bool_t mode = kTRUE)
                          TTimer(TObject* obj, Long_t milliSec, Bool_t mode = kTRUE)
                          TTimer(const char* command, Long_t milliSec, Bool_t mode = kTRUE)
                          TTimer(const TTimer&)
                  virtual ~TTimer()
             virtual void Add()
                   Bool_t CheckTimer(const TTime& now)
           static TClass* Class()
                    TTime GetAbsTime() const
              const char* GetCommand() const
                 TObject* GetObject()
                    TTime GetTime() const
                   UInt_t GetTimerID()
                   Bool_t HasTimedOut() const
          virtual TClass* IsA() const
                   Bool_t IsAsync() const
                   Bool_t IsInterruptingSyscalls() const
                   Bool_t IsSync() const
           virtual Bool_t Notify()
                  TTimer& operator=(const TTimer&)
             virtual void Remove()
                     void Reset()
                     void SetCommand(const char* command)
                     void SetInterruptSyscalls(Bool_t set = kTRUE)
                     void SetObject(TObject* object)
                     void SetTime(Long_t milliSec)
                     void SetTimerID(UInt_t id = 0)
             virtual void ShowMembers(TMemberInspector& insp, char* parent)
              static void SingleShot(Int_t milliSec, const char* receiver_class, void* receiver, const char* method)
             virtual void Start(Int_t milliSec = -1, Bool_t singleShot = kFALSE)
             virtual void Stop()
             virtual void Streamer(TBuffer& b)
                     void StreamerNVirtual(TBuffer& b)
             virtual void Timeout()
             virtual void TurnOff()
             virtual void TurnOn()

### Data Members

        protected:

             TTime fTime         time out time in ms
             TTime fAbsTime      absolute time out time in ms
            Bool_t fTimeout      true if timer has timed out
            Bool_t fSync         true if synchrounous timer
            Bool_t fIntSyscalls  true is a-synchronous timer is to interrupt system calls
            UInt_t fTimeID       the system ID of this timer (for WIN32)
          TObject* fObject       object to be notified (if any)
           TString fCommand      interpreter command to be executed

## Class Description

     TTimer

     Handles synchronous and a-synchronous timer events. You can use
     this class in one of the following ways:
        - Sub-class TTimer and override the Notify() method.
        - Re-implement the TObject::HandleTimer() method in your class
          and pass a pointer to this object to timer, see the SetObject()
          method.
        - Pass an interpreter command to timer, see SetCommand() method.
        - Create a TTimer, connect its Timeout() signal to the
          appropriate methods. Then when the time is up it will emit a
          Timeout() signal and call connected slots.

      Minimum timeout interval is defined in TSystem::ESysConstants as
      kItimerResolution (currently 10 ms).

      Signal/slots example:
           TTimer *timer = new TTimer();
           timer->Connect("Timeout()", "myObjectClassName",
                          myObject, "TimerDone()");
           timer->Start(2000, kTRUE);   // 2 seconds single-shot

        // Timeout signal is emitted repeadetly with minimum timeout
        // timer->Start(0, kFALSE);

TTimer(Long_t ms, Bool_t mode) : fTime(ms)

     Create timer that times out in ms milliseconds. If milliSec is 0
     then the timeout will be the minimum timeout (see TSystem::ESysConstants,
     i.e. 10 ms). If mode == kTRUE then the timer is synchronous else
     a-synchronous. The default is synchronous. Add a timer to the system
     eventloop by calling TurnOn(). Set command to be executed from Notify()
     or set the object whose HandleTimer() method will be called via Notify(),
     derive from TTimer and override Notify() or connect slots to the
     signals Timeout(), TurnOn() and TurnOff().

TTimer(TObject *obj, Long_t ms, Bool_t mode) : fTime(ms)

     Create timer that times out in ms milliseconds. If mode == kTRUE then
     the timer is synchronous else a-synchronous. The default is synchronous.
     Add a timer to the system eventloop by calling TurnOn().
     The object's HandleTimer() will be called by Notify().

TTimer(const char *command, Long_t ms, Bool_t mode) : fTime(ms)

     Create timer that times out in ms milliseconds. If mode == kTRUE then
     the timer is synchronous else a-synchronous. The default is synchronous.
     Add a timer to the system eventloop by calling TurnOn().
     The interpreter will execute command from Notify().

Bool_t CheckTimer(const TTime &now)

     Check if timer timed out.

Bool_t Notify()

     Notify when timer times out. The timer is always reset. To stop
     the timer call TurnOff().

void Reset()

     Reset the timer.

void SetCommand(const char *command)

     Set the interpreter command to be executed at time out. Removes the
     object to be notified (if it was set).

void SetObject(TObject *object)

     Set the object to be notified  at time out. Removes the command to
     be executed (if it was set).

void SetInterruptSyscalls(Bool_t set)

     When the argument is true the a-synchronous timer (SIGALRM) signal
     handler is set so that interrupted syscalls will not be restarted
     by the kernel. This is typically used in case one wants to put a
     timeout on an I/O operation. By default interrupted syscalls will
     be restarted.

void Start(Int_t milliSec, Bool_t singleShot)

     Starts the timer with a milliSec timeout. If milliSec is 0
     then the timeout will be the minimum timeout (see TSystem::ESysConstants,
     i.e. 10 ms), if milliSec is -1 then the time interval as previously
     specified (in ctor or SetTime()) will be used.
     If singleShot is kTRUE, the timer will be activated only once,
     otherwise it will continue until it is stopped.
     See also TurnOn(), Stop(), TurnOff().

void TurnOff()

     Remove timer from system timer list. This requires that a timer
     has been placed in the system timer list (using TurnOn()).
     If a TTimer subclass is placed on another list, override TurnOff() to
     remove the timer from the correct list.

void TurnOn()

     Add the timer to the system timer list. If a TTimer subclass has to be
     placed on another list, override TurnOn() to add the timer to the correct
     list.

void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)

     This static function calls a slot after a given time interval.
     Created internal timer will be deleted after that.

### Inline Functions

                   void ~TTimer()
            const char* GetCommand() const
               TObject* GetObject()
                  TTime GetTime() const
                 UInt_t GetTimerID()
                  TTime GetAbsTime() const
                 Bool_t HasTimedOut() const
                 Bool_t IsSync() const
                 Bool_t IsAsync() const
                 Bool_t IsInterruptingSyscalls() const
                   void Add()
                   void Remove()
                   void SetTime(Long_t milliSec)
                   void SetTimerID(UInt_t id = 0)
                   void Stop()
                   void Timeout()
                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)
                 TTimer TTimer(const TTimer&)
                TTimer& operator=(const TTimer&)

Author: Fons Rademakers 28/11/96
Last update: root/base:$Name: $:$Id: TTimer.cxx,v 1.11 2004/05/26 10:38:55 rdm Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *