Gnash  0.8.10
Public Member Functions
gnash::Timer Class Reference

An interval timer. More...

#include <Timers.h>

List of all members.

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)

Detailed Description

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.


Constructor & Destructor Documentation

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.

Parameters:
methodThe function to call from execution operator. Will be stored in an intrusive_ptr.
msThe number of milliseconds between expires.
this_ptrThe 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).
argsThe list of arguments to pass to the function being invoked.
runOnceIf 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.

Parameters:
this_ptrThe 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).
methodNameThe method name to call from execution operator.
msThe number of milliseconds between expires.
argsThe list of arguments to pass to the function being invoked.
runOnceIf true the interval will run only once. False if omitted.

Member Function Documentation

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.

Parameters:
elapsedOutput parameter, will be set to the amount of milliseconds elapsed since actual expiration, if expired.
Returns:
true if the timer expired, false otherwise.

References cleared().

void Timer::markReachableResources ( ) const

Mark all reachable resources (for GC)

Resources reachable from Timer are:

  • Arguments list (_args)
  • Associated function (_function)
  • Target object (_object)

References gnash::FunctionArgs::setReachable(), and gnash::GcResource::setReachable().


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