FLTK 1.4.0
|
The internal class Fl_Timeout handles all timeout related functions. More...
#include <Fl_Timeout.h>
Static Public Member Functions | |
static void | add_timeout (double time, Fl_Timeout_Handler cb, void *data) |
Adds a one-shot timeout callback. | |
static void | do_timeouts () |
Elapse timers and call their callbacks if any timers are expired. | |
static void | elapse_timeouts () |
Elapse all timers w/o calling their callbacks. | |
static int | has_timeout (Fl_Timeout_Handler cb, void *data) |
Returns true if the timeout exists and has not been called yet. | |
static void | remove_timeout (Fl_Timeout_Handler cb, void *data) |
Remove a timeout callback. | |
static void | repeat_timeout (double time, Fl_Timeout_Handler cb, void *data) |
Repeats a timeout callback from the expiration of the previous timeout, allowing for more accurate timing. | |
static double | time_to_wait (double ttw) |
Returns the delay in seconds until the next timer expires, limited by ttw . | |
Protected Member Functions | |
double | delay () |
Get the timer's delay in seconds. | |
void | delay (double t) |
Set the timer's delay in seconds. | |
void | insert () |
Insert this timer entry into the active timer queue. | |
void | make_current () |
Remove the timeout from the active timer queue and push it onto the stack of currently running callbacks. | |
void | release () |
Remove the top-most timeout from the stack of currently running timeout callbacks and insert it into the list of free timers. | |
Static Protected Member Functions | |
static Fl_Timeout * | current () |
Returns the first (top-most) timeout from the current timeout stack. | |
static Fl_Timeout * | get (double time, Fl_Timeout_Handler cb, void *data) |
Get an Fl_Timeout instance for further handling. | |
Protected Attributes | |
Fl_Timeout_Handler | callback |
void * | data |
Fl_Timeout * | next |
int | skip |
double | time |
Static Protected Attributes | |
static Fl_Timeout * | current_timeout = 0 |
The list of current timeouts is used to store the timeout whose callback is called while the callback is executed. | |
static Fl_Timeout * | first_timeout = 0 |
List of active timeouts. | |
static Fl_Timeout * | free_timeout = 0 |
List of free timeouts after use. | |
The internal class Fl_Timeout handles all timeout related functions.
All code is platform independent except retrieving a timestamp which requires calling a system driver function and potentially results in different timer resolutions (from milliseconds to microseconds).
Related user documentation:
|
static |
Adds a one-shot timeout callback.
The callback function cb
will be called by Fl::wait() at time
seconds after this function is called.
[in] | time | delta time in seconds until the timer expires |
[in] | cb | callback function |
[in] | data | optional user data (default: NULL ) |
Implements Fl::add_timeout(double time, Fl_Timeout_Handler cb, void *data)
|
staticprotected |
Returns the first (top-most) timeout from the current timeout stack.
This returns a pointer to the timeout but does not remove it from the list of current timeouts. This should be the timeout that is currently executing its callback.
NULL | if no callback is currently running. |
|
static |
Elapse all timers w/o calling their callbacks.
All timer values are adjusted by the delta time since the last call. This method does NOT call timer callbacks if timers are expired.
This must be called before new timers are added to the timer queue to make sure that the next timer decrement does not count down too much time.
|
staticprotected |
Get an Fl_Timeout instance for further handling.
The timer object will be initialized with the input parameters as given by Fl::add_timeout() or Fl::repeat_timeout().
Fl_Timeout objects are maintained in three queues:
When the FLTK program is launched all queues are empty. Whenever a new timer object is required the get() method is called and a timer object is either found in the queue of free timer entries or a new timer object is created (operator new).
Active timer entries are inserted into the "active timer queue" until they expire and their callback is called.
Before the callback is called the timer entry is inserted into the list of current timers, i.e. it becomes the Fl_Timeout::current() timeout. This can be used in Fl::repeat_timeout() to find out if and how long the current timeout has been delayed.
When a timer is no longer used it is popped from the current
list and inserted into the "free timer" list so it can be reused later.
Timer queue entries are never returned to the system, there's no garbage collection. The total number of timer objects is determined by the largest number of concurrently active timers.
[in] | time | requested delta time |
[in] | cb | timer callback |
[in] | data | userdata for timer callback |
|
static |
Returns true if the timeout exists and has not been called yet.
[in] | cb | Timer callback (must match) |
[in] | data | Callback user data (must match) |
0 | not found |
1 | found |
Implements Fl::has_timeout(Fl_Timeout_Handler cb, void *data)
|
protected |
Insert this timer entry into the active timer queue.
The timer is inserted at the required position so the timer queue is always ordered by due time.
|
protected |
Remove the timeout from the active timer queue and push it onto the stack of currently running callbacks.
This becomes the current() timeout which can be used in Fl::repeat_timeout().
|
protected |
Remove the top-most timeout from the stack of currently running timeout callbacks and insert it into the list of free timers.
Typical code in the library would look like:
|
static |
Remove a timeout callback.
This method removes all matching timeouts, not just the first one. This may change in the future.
[in] | cb | Timer callback to be removed (must match) |
[in] | data | Wildcard if NULL, must match otherwise |
Implements Fl::remove_timeout(Fl_Timeout_Handler cb, void *data)
|
static |
Repeats a timeout callback from the expiration of the previous timeout, allowing for more accurate timing.
[in] | time | delta time in seconds until the timer expires |
[in] | cb | callback function |
[in] | data | optional user data (default: NULL ) |
Implements Fl::repeat_timeout(double time, Fl_Timeout_Handler cb, void *data)
|
static |
Returns the delay in seconds until the next timer expires, limited by ttw
.
This function calculates the time to wait for the FLTK event queue processing, depending on the given value ttw
.
If at least one timer is active and its timeout value is smaller than ttw
then this value is returned. Fl::wait() will wait no longer than until the next timer expires.
If no timer is active this returns the input value ttw
unchanged.
If at least one timer is expired this returns 0.0 so the event processing does not wait.
[in] | ttw | time to wait from Fl::wait() etc. (upper limit) |
|
staticprotected |
The list of current timeouts is used to store the timeout whose callback is called while the callback is executed.
This is used like a stack, the current timeout is pushed to the front of the list and once the callback is finished, that timeout is removed and entered into the free list.
Background: Fl::repeat_timeout() needs to know which timeout triggered it and the exact schedule time and/or the delay of that timeout, i.e. how long the scheduled time was missed before the callback was called. A static, global variable is not sufficient since the user code can call other functions, e.g. dialogs, that run a nested event loop which can run another timeout callback. Hence this list of "current" timeouts is used like a stack (last in, first out).
|
staticprotected |
List of active timeouts.
These timeouts can be triggered when due, which calls their callbacks. The lifetime of a timeout:
current_timeout
|
staticprotected |
List of free timeouts after use.
Timeouts can be reused many times.