Logo ROOT  
Reference Guide
TTimer.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 28/11/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TTimer
13 #define ROOT_TTimer
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TTimer //
19 // //
20 // Handles synchronous and a-synchronous timer events. You can use //
21 // this class in one of the following ways: //
22 // - Sub-class TTimer and override the Notify() method. //
23 // - Re-implement the TObject::HandleTimer() method in your class //
24 // and pass a pointer to this object to timer, see the SetObject() //
25 // method. //
26 // - Pass an interpreter command to timer, see SetCommand() method. //
27 // - Create a TTimer, connect its Timeout() signal to the //
28 // appropriate methods. Then when the time is up it will emit a //
29 // Timeout() signal and call connected slots. //
30 // //
31 // Minimum timeout interval is defined in TSystem::ESysConstants as //
32 // kItimerResolution (currently 10 ms). //
33 // //
34 // Signal/slots example: //
35 // TTimer *timer = new TTimer(); //
36 // timer->Connect("Timeout()", "myObjectClassName", //
37 // myObject, "TimerDone()"); //
38 // timer->Start(2000, kTRUE); // 2 seconds single-shot //
39 // //
40 // // Timeout signal is emitted repeadetly with minimum timeout //
41 // // timer->Start(0, kFALSE); //
42 // //
43 //////////////////////////////////////////////////////////////////////////
44 
45 #include "TSysEvtHandler.h"
46 #include "TTime.h"
47 #include "TString.h"
48 
49 
50 
51 class TTimer : public TSysEvtHandler {
52 
53 protected:
54  TTime fTime; // time out time in ms
55  TTime fAbsTime; // absolute time out time in ms
56  Bool_t fTimeout; // true if timer has timed out
57  Bool_t fSync; // true if synchrounous timer
58  Bool_t fIntSyscalls; // true is a-synchronous timer is to interrupt system calls
59  UInt_t fTimeID; // the system ID of this timer (for WIN32)
60  TObject *fObject; // object to be notified (if any)
61  TString fCommand; // interpreter command to be executed
62 
63 private:
64  TTimer(const TTimer&); // not implemented
65  TTimer& operator=(const TTimer&); // not implemented
66 
67 public:
68  TTimer(Long_t milliSec = 0, Bool_t mode = kTRUE);
69  TTimer(TObject *obj, Long_t milliSec, Bool_t mode = kTRUE);
70  TTimer(const char *command, Long_t milliSec, Bool_t mode = kTRUE);
71  virtual ~TTimer() { Remove(); }
72 
73  Bool_t CheckTimer(const TTime &now);
74  const char *GetCommand() const { return fCommand.Data(); }
75  TObject *GetObject() { return fObject; }
76  TTime GetTime() const { return fTime; }
77  UInt_t GetTimerID() { return fTimeID;}
78  TTime GetAbsTime() const { return fAbsTime; }
79  Bool_t HasTimedOut() const { return fTimeout; }
80  Bool_t IsSync() const { return fSync; }
81  Bool_t IsAsync() const { return !fSync; }
83  virtual Bool_t Notify();
84  void Add() { TurnOn(); }
85  void Remove() { TurnOff(); }
86  void Reset();
87  void SetCommand(const char *command);
88  void SetObject(TObject *object);
89  void SetInterruptSyscalls(Bool_t set = kTRUE);
90  void SetTime(Long_t milliSec) { fTime = milliSec; }
91  void SetTimerID(UInt_t id = 0) { fTimeID = id; }
92  virtual void Start(Long_t milliSec = -1, Bool_t singleShot = kFALSE);
93  virtual void Stop() { TurnOff(); }
94  virtual void TurnOn(); //*SIGNAL*
95  virtual void TurnOff(); //*SIGNAL*
96  virtual void Timeout() { Emit("Timeout()"); } //*SIGNAL*
97 
98  static void SingleShot(Int_t milliSec, const char *receiver_class,
99  void *receiver, const char *method);
100 
101  ClassDef(TTimer,0) //Handle timer event
102 };
103 
104 #endif
TSysEvtHandler
Definition: TSysEvtHandler.h:28
TTimer::SetObject
void SetObject(TObject *object)
Set the object to be notified at time out.
Definition: TTimer.cxx:184
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TTimer::GetAbsTime
TTime GetAbsTime() const
Definition: TTimer.h:84
TString::Data
const char * Data() const
Definition: TString.h:369
TTimer::GetObject
TObject * GetObject()
Definition: TTimer.h:81
TTimer::Start
virtual void Start(Long_t milliSec=-1, Bool_t singleShot=kFALSE)
Starts the timer with a milliSec timeout.
Definition: TTimer.cxx:211
TTime.h
TTimer::GetTime
TTime GetTime() const
Definition: TTimer.h:82
TTimer::IsInterruptingSyscalls
Bool_t IsInterruptingSyscalls() const
Definition: TTimer.h:88
TTimer::CheckTimer
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
Definition: TTimer.cxx:128
TTimer::TurnOff
virtual void TurnOff()
Remove timer from system timer list.
Definition: TTimer.cxx:229
TString
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TString.h
bool
id
XFontStruct * id
Definition: TGX11.cxx:109
TTimer::HasTimedOut
Bool_t HasTimedOut() const
Definition: TTimer.h:85
TTimer::fTime
TTime fTime
Definition: TTimer.h:60
TTimer::fSync
Bool_t fSync
Definition: TTimer.h:63
TTimer::fAbsTime
TTime fAbsTime
Definition: TTimer.h:61
TTimer
Definition: TTimer.h:51
TTimer::SetCommand
void SetCommand(const char *command)
Set the interpreter command to be executed at time out.
Definition: TTimer.cxx:174
TTimer::IsAsync
Bool_t IsAsync() const
Definition: TTimer.h:87
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
Long_t
long Long_t
Definition: RtypesCore.h:54
TTimer::fTimeID
UInt_t fTimeID
Definition: TTimer.h:65
TTime
Definition: TTime.h:27
TTimer::operator=
TTimer & operator=(const TTimer &)
TTimer::Remove
void Remove()
Definition: TTimer.h:91
TTimer::SingleShot
static 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.
Definition: TTimer.cxx:256
TTimer::SetTime
void SetTime(Long_t milliSec)
Definition: TTimer.h:96
TTimer::fIntSyscalls
Bool_t fIntSyscalls
Definition: TTimer.h:64
TTimer::IsSync
Bool_t IsSync() const
Definition: TTimer.h:86
unsigned int
TTimer::fObject
TObject * fObject
Definition: TTimer.h:66
TTimer::Add
void Add()
Definition: TTimer.h:90
TTimer::Stop
virtual void Stop()
Definition: TTimer.h:99
TTimer::fTimeout
Bool_t fTimeout
Definition: TTimer.h:62
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TTimer::Notify
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:143
TTimer::SetTimerID
void SetTimerID(UInt_t id=0)
Definition: TTimer.h:97
TTimer::TurnOn
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:241
TTimer::Reset
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
TTimer::TTimer
TTimer(const TTimer &)
TTimer::SetInterruptSyscalls
void SetInterruptSyscalls(Bool_t set=kTRUE)
When the argument is true the a-synchronous timer (SIGALRM) signal handler is set so that interrupted...
Definition: TTimer.cxx:197
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TTimer::fCommand
TString fCommand
Definition: TTimer.h:67
TTimer::Timeout
virtual void Timeout()
Definition: TTimer.h:102
TTimer::~TTimer
virtual ~TTimer()
Definition: TTimer.h:77
int
TTimer::GetTimerID
UInt_t GetTimerID()
Definition: TTimer.h:83
TTimer::GetCommand
const char * GetCommand() const
Definition: TTimer.h:80
TSysEvtHandler.h