Gnash
0.8.10
|
An interval timer. More...
#include <Timers.h>
Public Member Functions | |
~Timer () | |
Timer (as_function &method, unsigned long ms, as_object *this_ptr, const fn_call::Args &args, bool runOnce=false) | |
Construct a Timer, enabling it. | |
Timer (as_object *obj, const ObjectURI &methodName, unsigned long ms, const fn_call::Args &args, bool runOnce=false) | |
Construct the Timer to call a late-evaluated object method, enabling it. | |
void | clearInterval () |
Clear the timer, ready for reuse. | |
bool | expired (unsigned long now, unsigned long &elapsed) |
Get expiration state. | |
bool | cleared () const |
Return true if interval has been cleared. | |
void | executeAndReset () |
Execute associated function and reset state. | |
void | markReachableResources () const |
Mark all reachable resources (for GC) |
An interval timer.
This is constructed when _global.setInterval() is called.
A timer has a function to call, a context in which to call it, a list of arguments and an interval specifying how often the function must be called.
It is *not* a "smart" timer, which is it will *not* automatically execute at given intervals. Rather, it will be movie_root responsibility to execute the timer-associated function at regular intervals. As a facility, the Timer class provides an execution operator, proxying the execution to the associated function with properly set-up context.
Timer::~Timer | ( | ) |
Timer::Timer | ( | as_function & | method, |
unsigned long | ms, | ||
as_object * | this_ptr, | ||
const fn_call::Args & | args, | ||
bool | runOnce = false |
||
) |
Construct a Timer, enabling it.
method | The function to call from execution operator. Will be stored in an intrusive_ptr. |
ms | The number of milliseconds between expires. |
this_ptr | The object to be used as 'this' pointer when calling the associated function. Will be stored in an intrusive_ptr. It is allowed to be NULL as long as fn_call is allowed a NULL as 'this_ptr' (we might want to change this). |
args | The list of arguments to pass to the function being invoked. |
runOnce | If true the interval will run only once. False if omitted. |
Timer::Timer | ( | as_object * | obj, |
const ObjectURI & | methodName, | ||
unsigned long | ms, | ||
const fn_call::Args & | args, | ||
bool | runOnce = false |
||
) |
Construct the Timer to call a late-evaluated object method, enabling it.
this_ptr | The object to be used as 'this' pointer when calling the associated function. Will be stored in an intrusive_ptr. It is allowed to be NULL as long as fn_call is allowed a NULL as 'this_ptr' (we might want to change this). |
methodName | The method name to call from execution operator. |
ms | The number of milliseconds between expires. |
args | The list of arguments to pass to the function being invoked. |
runOnce | If true the interval will run only once. False if omitted. |
bool gnash::Timer::cleared | ( | ) | const [inline] |
Return true if interval has been cleared.
Note that the timer is constructed as cleared and you need to call setInterval() to make it not-cleared.
Referenced by expired(), and executeAndReset().
void Timer::clearInterval | ( | ) |
Clear the timer, ready for reuse.
When a Timer is cleared, the expired() function will always return false.
Use setInterval() to reset it.
Referenced by executeAndReset().
void Timer::executeAndReset | ( | ) |
Execute associated function and reset state.
After execution either the timer is cleared (if runOnce) or start time is incremented by the interval.
NOTE: if the timer is cleared this call results in a no-op.
References cleared(), and clearInterval().
bool Timer::expired | ( | unsigned long | now, |
unsigned long & | elapsed | ||
) |
Get expiration state.
Current time, in milliseconds.
elapsed | Output parameter, will be set to the amount of milliseconds elapsed since actual expiration, if expired. |
References cleared().
void Timer::markReachableResources | ( | ) | const |
Mark all reachable resources (for GC)
Resources reachable from Timer are:
References gnash::FunctionArgs::setReachable(), and gnash::GcResource::setReachable().