11.1 C++ abstract base class TimerHandler

The abstract base class TimerHandler contains the following public member functions:

[double delay]void sched schedule a timer to expire delay seconds in the future
[double delay]void resched reschedule a timer (similar to []sched, but timer may be pending)
[]void cancel cancel a pending timer
[]int status returns timer status (either TIMER_IDLE, TIMER_PENDING, or TIMER_HANDLING)

The abstract base class TimerHandler contains the following protected members:

[Event* e]virtual void expire =0 this method must be filled in by the timer client
[Event* e]virtual void handle consumes an event; invokes expire() and sets status_ of the timer appropriately
int status
_
  keeps track of the current timer status
Event event
_
  event to be consumed upon timer expiration

The pure virtual function expire() must be defined by the timer classes deriving from this abstract base class.

Finally, two private inline functions are defined:

        inline void _sched(double delay) {
            (void)Scheduler::instance().schedule(this, &event_, delay);
        }
        inline void _cancel() {
            (void)Scheduler::instance().cancel(&event_);
        }

From this code we can see that timers make use of methods of the Scheduler class.



Subsections
Tom Henderson 2011-11-05