ROOT logo
// @(#)root/base:$Id$
// Author: Fons Rademakers   28/11/96

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TTimer
#define ROOT_TTimer


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// 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);                                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TSysEvtHandler
#include "TSysEvtHandler.h"
#endif
#ifndef ROOT_TTime
#include "TTime.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif



class TTimer : public TSysEvtHandler {

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

private:
   TTimer(const TTimer&);            // not implemented
   TTimer& operator=(const TTimer&); // not implemented

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);
   virtual ~TTimer() { Remove(); }

   Bool_t         CheckTimer(const TTime &now);
   const char    *GetCommand() const { return fCommand.Data(); }
   TObject       *GetObject() { return fObject; }
   TTime          GetTime() const { return fTime; }
   UInt_t         GetTimerID() { return fTimeID;}
   TTime          GetAbsTime() const { return fAbsTime; }
   Bool_t         HasTimedOut() const { return fTimeout; }
   Bool_t         IsSync() const { return fSync; }
   Bool_t         IsAsync() const { return !fSync; }
   Bool_t         IsInterruptingSyscalls() const { return fIntSyscalls; }
   virtual Bool_t Notify();
   void           Add() { TurnOn(); }
   void           Remove() { TurnOff(); }
   void           Reset();
   void           SetCommand(const char *command);
   void           SetObject(TObject *object);
   void           SetInterruptSyscalls(Bool_t set = kTRUE);
   void           SetTime(Long_t milliSec) { fTime = milliSec; }
   void           SetTimerID(UInt_t id = 0) { fTimeID = id; }
   virtual void   Start(Long_t milliSec = -1, Bool_t singleShot = kFALSE);
   virtual void   Stop() { TurnOff(); }
   virtual void   TurnOn();                         //*SIGNAL*
   virtual void   TurnOff();                        //*SIGNAL*
   virtual void   Timeout() { Emit("Timeout()"); }  //*SIGNAL*

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

   ClassDef(TTimer,0)  //Handle timer event
};

#endif
 TTimer.h:1
 TTimer.h:2
 TTimer.h:3
 TTimer.h:4
 TTimer.h:5
 TTimer.h:6
 TTimer.h:7
 TTimer.h:8
 TTimer.h:9
 TTimer.h:10
 TTimer.h:11
 TTimer.h:12
 TTimer.h:13
 TTimer.h:14
 TTimer.h:15
 TTimer.h:16
 TTimer.h:17
 TTimer.h:18
 TTimer.h:19
 TTimer.h:20
 TTimer.h:21
 TTimer.h:22
 TTimer.h:23
 TTimer.h:24
 TTimer.h:25
 TTimer.h:26
 TTimer.h:27
 TTimer.h:28
 TTimer.h:29
 TTimer.h:30
 TTimer.h:31
 TTimer.h:32
 TTimer.h:33
 TTimer.h:34
 TTimer.h:35
 TTimer.h:36
 TTimer.h:37
 TTimer.h:38
 TTimer.h:39
 TTimer.h:40
 TTimer.h:41
 TTimer.h:42
 TTimer.h:43
 TTimer.h:44
 TTimer.h:45
 TTimer.h:46
 TTimer.h:47
 TTimer.h:48
 TTimer.h:49
 TTimer.h:50
 TTimer.h:51
 TTimer.h:52
 TTimer.h:53
 TTimer.h:54
 TTimer.h:55
 TTimer.h:56
 TTimer.h:57
 TTimer.h:58
 TTimer.h:59
 TTimer.h:60
 TTimer.h:61
 TTimer.h:62
 TTimer.h:63
 TTimer.h:64
 TTimer.h:65
 TTimer.h:66
 TTimer.h:67
 TTimer.h:68
 TTimer.h:69
 TTimer.h:70
 TTimer.h:71
 TTimer.h:72
 TTimer.h:73
 TTimer.h:74
 TTimer.h:75
 TTimer.h:76
 TTimer.h:77
 TTimer.h:78
 TTimer.h:79
 TTimer.h:80
 TTimer.h:81
 TTimer.h:82
 TTimer.h:83
 TTimer.h:84
 TTimer.h:85
 TTimer.h:86
 TTimer.h:87
 TTimer.h:88
 TTimer.h:89
 TTimer.h:90
 TTimer.h:91
 TTimer.h:92
 TTimer.h:93
 TTimer.h:94
 TTimer.h:95
 TTimer.h:96
 TTimer.h:97
 TTimer.h:98
 TTimer.h:99
 TTimer.h:100
 TTimer.h:101
 TTimer.h:102
 TTimer.h:103
 TTimer.h:104
 TTimer.h:105
 TTimer.h:106
 TTimer.h:107
 TTimer.h:108
 TTimer.h:109
 TTimer.h:110