ROOT  6.06/09
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 #ifndef ROOT_TSysEvtHandler
46 #include "TSysEvtHandler.h"
47 #endif
48 #ifndef ROOT_TTime
49 #include "TTime.h"
50 #endif
51 #ifndef ROOT_TString
52 #include "TString.h"
53 #endif
54 
55 
56 
57 class TTimer : public TSysEvtHandler {
58 
59 protected:
60  TTime fTime; // time out time in ms
61  TTime fAbsTime; // absolute time out time in ms
62  Bool_t fTimeout; // true if timer has timed out
63  Bool_t fSync; // true if synchrounous timer
64  Bool_t fIntSyscalls; // true is a-synchronous timer is to interrupt system calls
65  UInt_t fTimeID; // the system ID of this timer (for WIN32)
66  TObject *fObject; // object to be notified (if any)
67  TString fCommand; // interpreter command to be executed
68 
69 private:
70  TTimer(const TTimer&); // not implemented
71  TTimer& operator=(const TTimer&); // not implemented
72 
73 public:
74  TTimer(Long_t milliSec = 0, Bool_t mode = kTRUE);
75  TTimer(TObject *obj, Long_t milliSec, Bool_t mode = kTRUE);
76  TTimer(const char *command, Long_t milliSec, Bool_t mode = kTRUE);
77  virtual ~TTimer() { Remove(); }
78 
79  Bool_t CheckTimer(const TTime &now);
80  const char *GetCommand() const { return fCommand.Data(); }
81  TObject *GetObject() { return fObject; }
82  TTime GetTime() const { return fTime; }
83  UInt_t GetTimerID() { return fTimeID;}
84  TTime GetAbsTime() const { return fAbsTime; }
85  Bool_t HasTimedOut() const { return fTimeout; }
86  Bool_t IsSync() const { return fSync; }
87  Bool_t IsAsync() const { return !fSync; }
89  virtual Bool_t Notify();
90  void Add() { TurnOn(); }
91  void Remove() { TurnOff(); }
92  void Reset();
93  void SetCommand(const char *command);
94  void SetObject(TObject *object);
95  void SetInterruptSyscalls(Bool_t set = kTRUE);
96  void SetTime(Long_t milliSec) { fTime = milliSec; }
97  void SetTimerID(UInt_t id = 0) { fTimeID = id; }
98  virtual void Start(Long_t milliSec = -1, Bool_t singleShot = kFALSE);
99  virtual void Stop() { TurnOff(); }
100  virtual void TurnOn(); //*SIGNAL*
101  virtual void TurnOff(); //*SIGNAL*
102  virtual void Timeout() { Emit("Timeout()"); } //*SIGNAL*
103 
104  static void SingleShot(Int_t milliSec, const char *receiver_class,
105  void *receiver, const char *method);
106 
107  ClassDef(TTimer,0) //Handle timer event
108 };
109 
110 #endif
void Reset()
Reset the timer.
Definition: TTimer.cxx:155
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:195
UInt_t fTimeID
Definition: TTimer.h:65
Basic string class.
Definition: TString.h:137
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:254
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Basic time type with millisecond precision.
Definition: TTime.h:29
void SetTimerID(UInt_t id=0)
Definition: TTimer.h:97
TTimer & operator=(const TTimer &)
const char * Data() const
Definition: TString.h:349
TString fCommand
Definition: TTimer.h:67
#define ClassDef(name, id)
Definition: Rtypes.h:254
TTime GetAbsTime() const
Definition: TTimer.h:84
Bool_t IsInterruptingSyscalls() const
Definition: TTimer.h:88
Bool_t fTimeout
Definition: TTimer.h:62
virtual void Start(Long_t milliSec=-1, Bool_t singleShot=kFALSE)
Starts the timer with a milliSec timeout.
Definition: TTimer.cxx:209
XFontStruct * id
Definition: TGX11.cxx:108
Bool_t fIntSyscalls
Definition: TTimer.h:64
TObject * GetObject()
Definition: TTimer.h:81
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:559
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:141
UInt_t GetTimerID()
Definition: TTimer.h:83
void Remove()
Definition: TTimer.h:91
Abstract base class for handling system events.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void TurnOff()
Remove timer from system timer list.
Definition: TTimer.cxx:227
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
Definition: TTimer.cxx:126
void Add()
Definition: TTimer.h:90
Bool_t fSync
Definition: TTimer.h:63
void SetCommand(const char *command)
Set the interpreter command to be executed at time out.
Definition: TTimer.cxx:172
long Long_t
Definition: RtypesCore.h:50
const char * GetCommand() const
Definition: TTimer.h:80
TTimer(const TTimer &)
Bool_t IsSync() const
Definition: TTimer.h:86
virtual ~TTimer()
Definition: TTimer.h:77
Mother of all ROOT objects.
Definition: TObject.h:58
Bool_t HasTimedOut() const
Definition: TTimer.h:85
TTime fTime
Definition: TTimer.h:60
void SetObject(TObject *object)
Set the object to be notified at time out.
Definition: TTimer.cxx:182
virtual void Timeout()
Definition: TTimer.h:102
virtual void Stop()
Definition: TTimer.h:99
TObject * fObject
Definition: TTimer.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:239
TTime fAbsTime
Definition: TTimer.h:61
TTime GetTime() const
Definition: TTimer.h:82
Bool_t IsAsync() const
Definition: TTimer.h:87
void SetTime(Long_t milliSec)
Definition: TTimer.h:96