|
luna-sysmgr-common
|
#include <SingletonTimer.h>
Public Member Functions | |
| SingletonTimer (GMainLoop *loop) | |
| ~SingletonTimer () | |
| TimerHandle * | create (TimerCallback callback, void *userArg) |
| void | fire (TimerHandle *timer, uint64_t timeInMs) |
| void | ref (TimerHandle *timer) |
| void | deref (TimerHandle *timer) |
Static Public Member Functions | |
| static uint64_t | currentTime () |
| static gboolean | timerPrepare (GSource *source, gint *timeout) |
| static gboolean | timerCheck (GSource *source) |
| static gboolean | timerDispatch (GSource *source, GSourceFunc callback, gpointer userData) |
Timer management utility class
Allows for creation and management of timers which call a callback after a specified time. Also allows for querying of the system clock.
Despite the name, this class is not designed as a true singleton. It's designed to be instantiated once per GLib main loop object to generate timers associated with it.
| SingletonTimer::SingletonTimer | ( | GMainLoop * | loop | ) |
Constructs a new timer generator
SingletonTimer is largely implemented using GLib functionality. As such, it needs a GLib main loop structure to tie GLib's timer functions to. That's where this constructor comes in. This ties the SingletonTimer object to GLib so other timer users don't need to worry about GLib.
| loop | The GLib main loop structure to tie the timers to |
| SingletonTimer::~SingletonTimer | ( | ) |
Clean up resources allocated for timers
Currently unused, but declared nonetheless.
| TimerHandle * SingletonTimer::create | ( | TimerCallback | callback, |
| void * | userArg | ||
| ) |
Sets up a new timer callback
Timers are set up in a two-stage process. Firstm you set up the function to call, then you set up the timing. This method sets up the callback, which can then be passed into SingletonTimer::fire() to activate that callback to run at a given time.
| callback | Pointer to the function to call. |
| userArg | Pointer to data to pass to the callback function. |
|
static |
Gets the number of milliseconds since some system-wide unknown time
Returns the number of milliseconds since some unspecified point in time as given by the system clock. While the "zero" point of this value is arbitrary, it's consistent between every call to it while the program is running. Because of this, it can be used as a very accurate clock for calculating time differences but not absolute time/date values.
Implemented as static since it uses the system-wide clock rather than using GLib.
| void SingletonTimer::deref | ( | TimerHandle * | timer | ) |
Indicates the a timer callback that a previous pointer to it has been destroyed
Primitive form of reference counting. Keeps track of how many things are using a TimerHandle and automatically deletes it when nothing needs it any longer.
| timer | The timer callback that has had a pointer to it destroyed. |
| void SingletonTimer::fire | ( | TimerHandle * | timer, |
| uint64_t | timeInMs | ||
| ) |
Activate a timer callback to be called at after a given time period elapses
This method is what actually sets up the timer to run. It takes a callback set up by SingletonTimer::create() and runs it after the given number of milliseconds have passed.
| timer | A TimerHandle pointer from SingletonTimer::create() containing information about the code to run. |
| timeInMs | How many milliseconds to wait before calling the function from the "timer" parameter. |
| void SingletonTimer::ref | ( | TimerHandle * | timer | ) |
Indicates to a timer callback that there is a new pointer to it
TimerHandle objects are reference counted like in the sptr system. SingletonTimer::ref() and SingletonTimer::deref() are the correct way to indicate how many pointers there are to a timer calkback so they an be automatically cleaned up from memory when everything is done using them.
| timer | The timer callback that has a new pointer to it. |
|
static |
Event source function for GLib timers
DO NOT USE. This function should only be called by the GLib functionality within this class.
Clean this up - having non-callable public methods is a messy way to do things.
Figure out how/why this works - GLib documentation on the subject seems to be pretty sparse.
|
static |
Event source function for GLib timers
DO NOT USE. This function should only be called by the GLib functionality within this class.
Clean this up - having non-callable public methods is a messy way to do things.
Figure out how/why this works - GLib documentation on the subject seems to be pretty sparse.
|
static |
Event source function for GLib timers
DO NOT USE. This function should only be called by the GLib functionality within this class.
Clean this up - having non-callable public methods is a messy way to do things.
Figure out how/why this works - GLib documentation on the subject seems to be pretty sparse.