VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::TimerList Class Reference

A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their behalf. More...

#include <gtimerlist.h>

Classes

class  NoThrow
 Overload discriminator class for TimerList. More...
 

Public Member Functions

 TimerList ()
 Default constructor.
 
 ~TimerList ()
 Destructor. Any expired timers have their timeouts called.
 
void add (TimerBase &)
 Adds a timer.
 
void remove (TimerBase &)
 Removes a timer from the list.
 
void update (TimerBase &)
 Called when a timer changes its value.
 
G::EpochTime interval (bool &infinite) const
 Returns the interval to the first timer expiry. More...
 
void doTimeouts ()
 Triggers the timeout callbacks of any expired timers. More...
 
std::string report () const
 Returns a line of text reporting the status of the timer list. More...
 

Static Public Member Functions

static TimerListinstance (const NoThrow &)
 Singleton access. Returns nullptr if none.
 
static TimerListinstance ()
 Singleton access. Throws an exception if none.
 

Detailed Description

A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their behalf.

Event loops that can do a timed-wait should call TimerList::interval() to determine how long to wait before the first G::Timer goes off. If the timed-wait times-out or if the interval was zero then they must call TimerList::doTimeouts().

Event loops that cannot do timed waits efficiently (ie. the traditional Windows message queue) have their setTimeout() method called by this class and they are expected to call doTimeouts() when the event-loop timer expires.

In both models there can be a race where this class sees no expired timers in doTimeouts(), perhaps because the system clock is being stretched. However, the next interval() or setTimer() time will be very small and the race will resolve itself naturally.

Definition at line 56 of file gtimerlist.h.

Member Function Documentation

void GNet::TimerList::doTimeouts ( )

Triggers the timeout callbacks of any expired timers.

Called by the event loop (GNet::EventLoop).

Definition at line 148 of file gtimerlist.cpp.

G::EpochTime GNet::TimerList::interval ( bool &  infinite) const

Returns the interval to the first timer expiry.

The 'infinite' value is set to true if there are no timers running.

Definition at line 114 of file gtimerlist.cpp.

std::string GNet::TimerList::report ( ) const

Returns a line of text reporting the status of the timer list.

Used in debugging and diagnostics.

Definition at line 180 of file gtimerlist.cpp.


The documentation for this class was generated from the following files: