up Matpack


class MpTimerQueue - interval timer class

Class: class MpTimerQueue, class MpTimerInterface
Include: #include "mptimerqueue.h"
Examples: MpTimerQueue-demo.cpp
Description: supply versatile interval timer queue

Class MpTimerQueue is the base class for general purpose interval timers. It manages the timer queue and supplies functions for adding and removing timers, starting timer event processing and getting the time until the next timer expires.

Class MpTimerInterface supplies an abstract interface for the callback that is called when a timer is exhausted. You have to overload it's method virtual void MpTimerInterface::TimerEvent(MpTimerInfo *info).

The structure "struct timeval" as defined in "sys/time.h" is used for time arguments. Use the convenience inline functions for calculations with time values defined in mptimeval.h. The description can be found here.

The graphical user interface of Matpack contains a class MpTimer which is implemented using this base class.

Member functions:


   timeval MpTimerQueue::GetTime(void);

returns the current time as a timeval.

   MpTimerInfo* MpTimerQueue::StartTimer (MpTimerInterface *receiver, int sec, int usec);

Install and start a new interval timer. The interval is given in seconds plus microseconds. A pointer to an object that will reveive timer events if a timer has expired is given as the first argument. Class MpTimerInterface supplies an abstract interface for the callback that is called when a timer is exhausted. You have to inherit MpTimerInterface in your application class and to overload the method

virtual void MpTimerInterface::TimerEvent(MpTimerInfo *info);

to receive the timer events. A pointer to a timer info structure is returned to identify the timer, e.g. for destroying it (via StopTimer, see below).

    void MpTimerQueue::StopTimer (MpTimerInfo* info);

Stop and deinstall the given timer.

    void MpTimerQueue::StopAllTimers (void);

Stop and deinstall all timers. The timer queue is empty afterwards.

    int  MpTimerQueue::EvaluateTimers (void);

Activate all expired timers of the queue and return the number of generated timer events. The number of events is maximally the number of installed timers.

    timeval* MpTimerQueue::NextTimer (void);

Return time to wait for the next timer or 0-pointer if there is no timer waiting. The wait time is returned by a pointer to a static timeval structure.

    void MpTimerQueue::SleepTime(const timeval& sleep);

Current process will sleep for the given time interval.

    MpTimerQueue::~MpTimerQueue();

Destroy all timers and this class instance.



up © B.M.Gammel, last change 13 Jan 2001