Sirikata
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Sirikata::JS::JSTimerStruct Struct Reference

#include <JSTimerStruct.hpp>

Inheritance diagram for Sirikata::JS::JSTimerStruct:
Collaboration diagram for Sirikata::JS::JSTimerStruct:

List of all members.

Public Member Functions

 JSTimerStruct (EmersonScript *eobj, Duration dur, v8::Persistent< v8::Function > &callback, JSContextStruct *jscont, uint32 contID, double timeRemaining, bool isSuspended, bool isCleared, JSCtx *mCtx)
 ~JSTimerStruct ()
v8::Handle< v8::Value > struct_resetTimer (double timeInSecondsToRefire)
virtual v8::Handle< v8::Value > suspend ()
virtual v8::Handle< v8::Value > resume ()
virtual v8::Handle< v8::Value > clear ()
v8::Handle< v8::Value > struct_getAllData ()
virtual void fixSuspendableToContext (JSContextStruct *toAttachTo)
void noReference (const Liveness::Token &token)
 When no longer have a reference to the Emerson object holding this timer and garbage collection is occurring, this function gets called.
void setPersistentObject (v8::Persistent< v8::Object >)
 Every time a timer struct is created, the next line should set its persistent object.

Static Public Member Functions

static JSTimerStructdecodeTimerStruct (v8::Handle< v8::Value > toDecode, String &errorMessage)
static void timerWeakReferenceCleanup (v8::Persistent< v8::Value > containsTimer, void *otherArg)
 When the only reference to a timer are weak (ie, no emerson objects directly point at it, this function gets called.

Public Attributes

EmersonScriptemerScript
v8::Persistent< v8::Function > cb
JSContextStructjsContStruct
Duration timeUntil
double mTimeRemaining

Private Member Functions

void evaluateCallback (Liveness::Token isAlive)
void iEvaluateCallback (Liveness::Token token)

Private Attributes

JSCtxmCtx
Sirikata::Network::IOTimerPtr mDeadlineTimer
bool amExecuting
 Means that we're currently processing the callback of a timer.
bool killAfterFire
 Need to know when to clean up timer struct.
bool noTimerWaiting
 True if have no callback waiting to be executed.
v8::Persistent< v8::Object > mPersistentHandle
 On clear, should set mPersistentHandle's internal fields to NULL.

Constructor & Destructor Documentation

Sirikata::JS::JSTimerStruct::JSTimerStruct ( EmersonScript eobj,
Duration  dur,
v8::Persistent< v8::Function > &  callback,
JSContextStruct jscont,
uint32  contID,
double  timeRemaining,
bool  isSuspended,
bool  isCleared,
JSCtx mCtx 
)
Sirikata::JS::JSTimerStruct::~JSTimerStruct ( )

Member Function Documentation

v8::Handle< v8::Value > Sirikata::JS::JSTimerStruct::clear ( ) [virtual]
JSTimerStruct * Sirikata::JS::JSTimerStruct::decodeTimerStruct ( v8::Handle< v8::Value >  toDecode,
String &  errorMessage 
) [static]
void Sirikata::JS::JSTimerStruct::evaluateCallback ( Liveness::Token  isAlive) [private]
void Sirikata::JS::JSTimerStruct::fixSuspendableToContext ( JSContextStruct toAttachTo) [virtual]
void Sirikata::JS::JSTimerStruct::iEvaluateCallback ( Liveness::Token  token) [private]
void Sirikata::JS::JSTimerStruct::noReference ( const Liveness::Token alive)

When no longer have a reference to the Emerson object holding this timer and garbage collection is occurring, this function gets called.

Called by timerWeakReferenceCleanup and after firing timer when killAfterFire is true.

If the timer has no pending events (and won't have any pending events in the future [eg, it isn't suspended and its parent context isn't suspended]), then delete the timer right then and there. Otherwise, delete it after it fires. (Mark killAfterFire to be true.)

Parameters:
iotimeris a keepalive token to the IOTimer. If the struct is GC'd then this will no longer resolve to a shared reference and this class is dead.

Means that no Emerson objects hold references to this timer any longer and that this object should either: 1) Free itself if there's no way that its timer will re-fire. 2) Schedule itself to be freed after its timer fires.

For case 1: the timer has already fired, and (the timer isn't suspended and its context isn't suspended). For case 2: just sets killAfterFire to be true. Will re-evaluate these conditions after timer actually fires.

References clear(), Sirikata::JS::JSSuspendable::getIsSuspended(), jsContStruct, killAfterFire, mCtx, Sirikata::JS::JSCtx::mIsolate, and noTimerWaiting.

Referenced by iEvaluateCallback(), and timerWeakReferenceCleanup().

v8::Handle< v8::Value > Sirikata::JS::JSTimerStruct::resume ( ) [virtual]
void Sirikata::JS::JSTimerStruct::setPersistentObject ( v8::Persistent< v8::Object >  pers)

Every time a timer struct is created, the next line should set its persistent object.

References mPersistentHandle.

Referenced by Sirikata::JS::EmersonScript::create_timeout().

v8::Handle< v8::Value > Sirikata::JS::JSTimerStruct::struct_getAllData ( )
v8::Handle< v8::Value > Sirikata::JS::JSTimerStruct::struct_resetTimer ( double  timeInSecondsToRefire)
v8::Handle< v8::Value > Sirikata::JS::JSTimerStruct::suspend ( ) [virtual]
void Sirikata::JS::JSTimerStruct::timerWeakReferenceCleanup ( v8::Persistent< v8::Value >  containsTimer,
void *  otherArg 
) [static]

When the only reference to a timer are weak (ie, no emerson objects directly point at it, this function gets called.

The first argument contains the persistent object pointing to the timer. The second should just be null.

References CHECK_INTERNAL_FIELD_COUNT, decodeTimerStruct(), Sirikata::Logging::error, Sirikata::Logging::insane, JSLOG, Sirikata::Liveness::livenessToken(), Sirikata::JS::JSTimerLivenessHolder::lt, mCtx, noReference(), Sirikata::JS::JSCtx::objStrand, and TIMER_JSTIMER_TEMPLATE_FIELD_COUNT.

Referenced by Sirikata::JS::EmersonScript::create_timeout().


Member Data Documentation

Means that we're currently processing the callback of a timer.

Should be used to prevent invalid memory access if try to clear a timer from within its own callback. (Ie, won't delete the timer if amExecuting is true.)

Referenced by clear(), and iEvaluateCallback().

v8::Persistent<v8::Function> Sirikata::JS::JSTimerStruct::cb

Referenced by iEvaluateCallback().

Need to know when to clean up timer struct.

Have made Emerson objects that are timers weak. This means that as soon as the objects holding them go out of scope, we receive a callback. If the timer has not yet fired, we do not want to delete JSTimerStruct. Therefore, we wait until the timer has fired before freeing the memory associated with this timer struct. Setting killAfterFire to true instructs this struct to clear and free itself after it fires and executes its callback.

Referenced by iEvaluateCallback(), and noReference().

v8::Persistent<v8::Object> Sirikata::JS::JSTimerStruct::mPersistentHandle [private]

On clear, should set mPersistentHandle's internal fields to NULL.

That way. This accounts for the case where a user explicitly called clear on a timer, which deletes the JSTimerStruct pointer and then the v8 garbage collector tries to delete the internal field of mPersistentHandle.

Referenced by clear(), and setPersistentObject().

Referenced by fixSuspendableToContext().

True if have no callback waiting to be executed.

False otherwise.

Referenced by fixSuspendableToContext(), iEvaluateCallback(), JSTimerStruct(), noReference(), resume(), struct_resetTimer(), and suspend().


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