Gnash  0.8.11dev
Public Member Functions | List of all members
gnash::Timer Class Reference

An interval timer. More...

#include <Timers.h>

Public Member Functions

 ~Timer ()
 
 Timer (as_function &method, unsigned long ms, as_object *this_ptr, fn_call::Args args, bool runOnce=false)
 Construct a Timer, enabling it. More...
 
 Timer (as_object *obj, ObjectURI methodName, unsigned long ms, fn_call::Args args, bool runOnce=false)
 Construct the Timer to call a late-evaluated object method, enabling it. More...
 
void clearInterval ()
 Clear the timer, ready for reuse. More...
 
bool expired (unsigned long now, unsigned long &elapsed)
 Get expiration state. More...
 
bool cleared () const
 Return true if interval has been cleared. More...
 
void executeAndReset ()
 Execute associated function and reset state. More...
 
void markReachableResources () const
 Mark all reachable resources (for GC) More...
 

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() [1/2]

Timer::Timer ( as_function method,
unsigned long  ms,
as_object this_ptr,
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() [2/2]

Timer::Timer ( as_object obj,
ObjectURI  methodName,
unsigned long  ms,
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

§ cleared()

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.

References _object, and start.

Referenced by executeAndReset(), expired(), and gnash::movie_root::processInvoke().

§ clearInterval()

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.

References gnash::VM::getTime(), and gnash::getVM().

Referenced by executeAndReset().

§ 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(), clearInterval(), gnash::as_object::get_super(), gnash::getMember(), gnash::getVM(), and gnash::invoke().

Referenced by gnash::movie_root::processInvoke().

§ expired()

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().

Referenced by gnash::movie_root::processInvoke().

§ markReachableResources()

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::GcResource::setReachable(), and gnash::FunctionArgs< T >::setReachable().

Referenced by gnash::movie_root::markReachableResources().


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