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

#include <JSContextStruct.hpp>

Inheritance diagram for Sirikata::JS::JSContextStruct:
Collaboration diagram for Sirikata::JS::JSContextStruct:

List of all members.

Public Member Functions

 JSContextStruct (JSObjectScript *parent, JSPresenceStruct *whichPresence, SpaceObjectReference home, Capabilities::CapNum capNum, v8::Handle< v8::ObjectTemplate > contGlobTempl, uint32 contextID, JSContextStruct *parentContext, JSCtx *jsctx)
 ~JSContextStruct ()
uint32 getContextID ()
virtual v8::Handle< v8::Value > suspend ()
virtual v8::Handle< v8::Value > resume ()
virtual v8::Handle< v8::Value > clear ()
void finishClear ()
v8::Handle< v8::Value > struct_suspendContext ()
v8::Handle< v8::Value > struct_resumeContext ()
v8::Handle< v8::Value > checkHeadless ()
v8::Handle< v8::Object > struct_getSystem ()
v8::Handle< v8::Value > struct_create_vis (const SpaceObjectReference &sporefWathcing, JSVisibleDataPtr addParams)
v8::Handle< v8::Value > killEntity ()
void proximateEvent (const SpaceObjectReference &goneFrom, JSVisibleStruct *jsvis, bool isGone)
v8::Handle< v8::Value > pushEvalContextScopeDirectory (const String &newDir)
v8::Handle< v8::Value > popEvalContextScopeDirectory ()
v8::Handle< v8::Value > storageBeginTransaction ()
v8::Handle< v8::Value > storageCommit (v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > storageWrite (const OH::Storage::Key &key, const String &toWrite, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > storageRead (const OH::Storage::Key &key, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > storageErase (const OH::Storage::Key &key, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > storageRangeRead (const OH::Storage::Key &start, const OH::Storage::Key &finish, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > storageRangeErase (const OH::Storage::Key &start, const OH::Storage::Key &finish, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > storageCount (const OH::Storage::Key &start, const OH::Storage::Key &finish, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > sendSandbox (const String &msgToSend, JSContextStruct *destination)
v8::Handle< v8::Value > setRestoreScript (const String &key, v8::Handle< v8::Function > cb)
v8::Handle< v8::Value > struct_evalInGlobal (const String &native_contents, ScriptOrigin *sOrigin)
v8::Handle< v8::Value > struct_createEntity (EntityCreateInfo &eci)
v8::Handle< v8::Value > struct_setReset (const std::map< SpaceObjectReference, std::vector< SpaceObjectReference > > &proxResSet)
v8::Handle< v8::Value > struct_setScript (const String &script)
v8::Handle< v8::Value > struct_getScript ()
v8::Handle< v8::Value > debug_fileWrite (String &strToWrite, String &filename)
v8::Handle< v8::Value > debug_fileRead (String &filename)
v8::Handle< v8::Value > deserialize (const String &toDeserialize)
v8::Handle< v8::Value > struct_rootReset ()
 This function is called only by JSObjectScript directly.
v8::Handle< v8::Value > restorePresence (PresStructRestoreParams &psrp)
void struct_registerSuspendable (JSSuspendable *toRegister)
void struct_deregisterSuspendable (JSSuspendable *toDeregister)
void struct_asyncDeregisterSuspendable (JSSuspendable *toDeregister, Liveness::Token contAlive, Liveness::Token suspAlive)
v8::Handle< v8::Value > struct_createVec3 (Vector3d &toCreate)
v8::Handle< v8::Value > struct_createQuaternion (Quaternion &toCreate)
bool canReceiveMessagesFor (const SpaceObjectReference &receiver)
void jsscript_print (const String &msg)
void presenceDied ()
v8::Handle< v8::Value > struct_executeScript (v8::Handle< v8::Function > funcToCall, const v8::Arguments &args)
v8::Handle< v8::Value > struct_getAssociatedPresPosition ()
v8::Handle< v8::Value > struct_sendHome (const String &toSend)
v8::Handle< v8::Value > struct_import (const String &toImportFrom, bool isJS)
v8::Handle< v8::Value > struct_require (const String &toRequireFrom, bool isJS)
void receiveSandboxMessage (v8::Local< v8::Object > msgObj, JSContextStruct *sender)
 msgObj is the JS object message that is being delivered from sender to me.
v8::Handle< v8::Value > struct_createContext (JSPresenceStruct *jspres, const SpaceObjectReference &canSendTo, Capabilities::CapNum capNum)
v8::Handle< v8::Value > struct_event (v8::Persistent< v8::Function > &cb)
v8::Handle< v8::Value > struct_createTimeout (double period, v8::Persistent< v8::Function > &cb)
v8::Handle< v8::Value > struct_createTimeout (double period, v8::Persistent< v8::Function > &cb, uint32 contID, double timeRemaining, bool isSuspended, bool isCleared)
v8::Handle< v8::Value > sendMessageNoErrorHandler (JSPresenceStruct *jspres, const String &serialized_message, JSPositionListener *jspl, bool reliable)
v8::Handle< v8::Value > struct_registerOnPresenceDisconnectedHandler (v8::Persistent< v8::Function > cb_persist)
v8::Handle< v8::Value > struct_registerOnPresenceConnectedHandler (v8::Persistent< v8::Function > cb_persist)
void checkContextConnectCallback (JSPresenceStruct *jspres)
void checkContextDisconnectCallback (JSPresenceStruct *jspres)
String getScript ()
v8::Handle< v8::Value > proxAddedHandlerCallallback (v8::Handle< v8::Function >cb)
v8::Handle< v8::Value > proxRemovedHandlerCallallback (v8::Handle< v8::Function >cb)
v8::Handle< v8::Value > getAssociatedPresence ()
JSPresenceStructgetAssociatedPresenceStruct ()
void httpFail (v8::Persistent< v8::Function > cb, const String &failureReason)
 The http request that was associated with this request failed.
void httpSuccess (v8::Persistent< v8::Function > cb, EmersonHttpManager::HttpRespPtr httpResp)
 The http request that was associated with cb passed, and its associated data are in httpResp.
v8::Handle< v8::Value > httpRequest (Sirikata::Network::Address addr, Transfer::HttpManager::HTTP_METHOD method, String request, v8::Persistent< v8::Function > cb)
v8::Handle< v8::Value > setSandboxMessageCallback (v8::Persistent< v8::Function > callback)
v8::Handle< v8::Value > setPresenceMessageCallback (v8::Persistent< v8::Function > callback)
v8::Handle< v8::Value > emersonCompileString (const String &toCompile)
Capabilities::CapNum getCapNum ()

Static Public Member Functions

static JSContextStructdecodeContextStruct (v8::Handle< v8::Value > toDecode, String &errorMsg)

Public Attributes

JSObjectScriptjsObjScript
v8::Persistent< v8::Context > mContext
JSCtxmCtx
v8::Persistent< v8::Function > proxAddedFunc
v8::Persistent< v8::Function > proxRemovedFunc
JSContextStructmParentContext
v8::Persistent< v8::Function > sandboxMessageCallback
v8::Persistent< v8::Function > presenceMessageCallback

Private Member Functions

bool hasPresence (const SpaceObjectReference &sporef)
void createContextObjects (String *scriptToEval=NULL)
void flushQueuedSuspendablesToChange ()
 Function runs through suspendablesToDelete and deregisters them.

Private Attributes

uint32 mContextID
bool hasOnConnectedCallback
v8::Persistent< v8::Function > cbOnConnected
bool hasOnDisconnectedCallback
v8::Persistent< v8::Function > cbOnDisconnected
String mScript
JSPresenceStructassociatedPresence
SpaceObjectReference mHomeObject
JSSystemStructmSystem
v8::Persistent< v8::Object > systemObj
v8::Handle< v8::ObjectTemplate > mContGlobTempl
JSUtilStructmUtil
bool inClear
SuspendableMap associatedSuspendables
bool mInSuspendableLoop
SuspendableVec suspendablesToDelete
SuspendableVec suspendablesToAdd

Constructor & Destructor Documentation

Sirikata::JS::JSContextStruct::JSContextStruct ( JSObjectScript parent,
JSPresenceStruct whichPresence,
SpaceObjectReference  home,
Capabilities::CapNum  capNum,
v8::Handle< v8::ObjectTemplate >  contGlobTempl,
uint32  contextID,
JSContextStruct parentContext,
JSCtx jsctx 
)
Sirikata::JS::JSContextStruct::~JSContextStruct ( )

Member Function Documentation

bool Sirikata::JS::JSContextStruct::canReceiveMessagesFor ( const SpaceObjectReference receiver)
void Sirikata::JS::JSContextStruct::checkContextConnectCallback ( JSPresenceStruct jspres)
void Sirikata::JS::JSContextStruct::checkContextDisconnectCallback ( JSPresenceStruct jspres)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::checkHeadless ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::clear ( ) [virtual]
void Sirikata::JS::JSContextStruct::createContextObjects ( String *  scriptToEval = NULL) [private]
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::debug_fileRead ( String &  filename)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::debug_fileWrite ( String &  strToWrite,
String &  filename 
)
JSContextStruct * Sirikata::JS::JSContextStruct::decodeContextStruct ( v8::Handle< v8::Value >  toDecode,
String &  errorMsg 
) [static]
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::deserialize ( const String &  toDeserialize)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::emersonCompileString ( const String &  toCompile)
void Sirikata::JS::JSContextStruct::finishClear ( )
void Sirikata::JS::JSContextStruct::flushQueuedSuspendablesToChange ( ) [private]

Function runs through suspendablesToDelete and deregisters them.

Also runs through suspendablesToAdd and adds them. (Makes it so that we don't mess up our iterators by adding to and removing from what they're iterating over.)

References Sirikata::Logging::error, JSLOG, mInSuspendableLoop, struct_deregisterSuspendable(), struct_registerSuspendable(), suspendablesToAdd, and suspendablesToDelete.

Referenced by finishClear(), hasPresence(), resume(), and suspend().

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::getAssociatedPresence ( )
JSPresenceStruct* Sirikata::JS::JSContextStruct::getAssociatedPresenceStruct ( ) [inline]
Capabilities::CapNum Sirikata::JS::JSContextStruct::getCapNum ( )
uint32 Sirikata::JS::JSContextStruct::getContextID ( )
String Sirikata::JS::JSContextStruct::getScript ( )

References mScript.

Referenced by struct_getScript().

bool Sirikata::JS::JSContextStruct::hasPresence ( const SpaceObjectReference sporef) [private]
void Sirikata::JS::JSContextStruct::httpFail ( v8::Persistent< v8::Function >  cb,
const String &  failureReason 
)

The http request that was associated with this request failed.

Execute callback with two arguments: false, and a string with the reason (potential reasons: UNKNOWN_ERROR, REQUEST_PARSING_ERROR, RESPONSE_PARSING_ERROR. Caller is in charge of calling dispose on cb.

References Sirikata::JS::JSObjectScript::invokeCallback(), Sirikata::JS::JSObjectScript::isStopped(), JSLOG, jsObjScript, mContext, mCtx, Sirikata::JS::JSCtx::mIsolate, Sirikata::JS::JSObjectScript::postCallbackChecks(), and Sirikata::Logging::warn.

Referenced by Sirikata::JS::EmersonHttpManager::postReceiveResp().

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::httpRequest ( Sirikata::Network::Address  addr,
Transfer::HttpManager::HTTP_METHOD  method,
String  request,
v8::Persistent< v8::Function >  cb 
)
void Sirikata::JS::JSContextStruct::httpSuccess ( v8::Persistent< v8::Function >  cb,
EmersonHttpManager::HttpRespPtr  httpResp 
)

The http request that was associated with cb passed, and its associated data are in httpResp.

Execute callback with first argument true, and second argument containing data. Caller is in charge of calling dispose on cb.

References Sirikata::JS::JSObjectScript::invokeCallback(), Sirikata::JS::JSObjectScript::isStopped(), JSLOG, jsObjScript, mContext, mCtx, Sirikata::JS::JSCtx::mIsolate, Sirikata::JS::JSObjectScript::postCallbackChecks(), Sirikata::JS::strToUint16Str(), and Sirikata::Logging::warn.

Referenced by Sirikata::JS::EmersonHttpManager::postReceiveResp().

void Sirikata::JS::JSContextStruct::jsscript_print ( const String &  msg)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::killEntity ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::popEvalContextScopeDirectory ( )
void Sirikata::JS::JSContextStruct::presenceDied ( )

References Sirikata::Logging::error, and JSLOG.

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::proxAddedHandlerCallallback ( v8::Handle< v8::Function >  cb)
void Sirikata::JS::JSContextStruct::proximateEvent ( const SpaceObjectReference goneFrom,
JSVisibleStruct jsvis,
bool  isGone 
)
Parameters:
{sporef}goneFrom The id of the local presence that the presence represented by jsvis is no longer within query set of.
{JSVisibleStruct*}The struct associated with the external presence that is no longer visible to goneFrom.
{bool}isGone True if the event is that a visible moved *out* of a presence's result set. False if the event is that a visible moved *into* a presence's result set.

Checks to see if this notification is applicable to fire. Ie, if the sandbox isn't suspended and if the notification is for its root presence (and we have capability to fire for the root presence) or if the notification is for one of the presences created in this sandbox.

If the above conditions are met, actually fires proximate event.

References associatedPresence, cbOnConnected, cbOnDisconnected, CHECK_EMERSON_SCRIPT_RETURN, Sirikata::JS::JSSuspendable::getIsCleared(), Sirikata::JS::JSSuspendable::getIsSuspended(), Sirikata::JS::JSPositionListener::getSporef(), hasPresence(), JSLOG, jsObjScript, and Sirikata::Logging::warn.

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::proxRemovedHandlerCallallback ( v8::Handle< v8::Function >  cb)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::pushEvalContextScopeDirectory ( const String &  newDir)
void Sirikata::JS::JSContextStruct::receiveSandboxMessage ( v8::Local< v8::Object >  msgObj,
JSContextStruct sender 
)

msgObj is the JS object message that is being delivered from sender to me.

Dispatches the onSandboxMessage handler that is bound to newly created contexts.

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::restorePresence ( PresStructRestoreParams psrp)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::resume ( ) [virtual]
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::sendMessageNoErrorHandler ( JSPresenceStruct jspres,
const String &  serialized_message,
JSPositionListener jspl,
bool  reliable 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::sendSandbox ( const String &  msgToSend,
JSContextStruct destination 
)
Parameters:
{string}serialized message to send
{JSContextStruct*}destination. (If null, means send to parent).

Sends a message from this sandbox to the sandbox associated with destination. If destination is null, sends to parent.

References CHECK_EMERSON_SCRIPT_ERROR, getContextID(), jsObjScript, mParentContext, sendSandbox(), and V8_EXCEPTION_CSTR.

Referenced by Sirikata::JS::JSSystemStruct::sendSandbox(), and sendSandbox().

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::setPresenceMessageCallback ( v8::Persistent< v8::Function >  callback)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::setRestoreScript ( const String &  key,
v8::Handle< v8::Function >  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::setSandboxMessageCallback ( v8::Persistent< v8::Function >  callback)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageBeginTransaction ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageCommit ( v8::Handle< v8::Function >  cb)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageCount ( const OH::Storage::Key start,
const OH::Storage::Key finish,
v8::Handle< v8::Function >  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageErase ( const OH::Storage::Key key,
v8::Handle< v8::Function >  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageRangeErase ( const OH::Storage::Key start,
const OH::Storage::Key finish,
v8::Handle< v8::Function >  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageRangeRead ( const OH::Storage::Key start,
const OH::Storage::Key finish,
v8::Handle< v8::Function >  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageRead ( const OH::Storage::Key key,
v8::Handle< v8::Function >  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::storageWrite ( const OH::Storage::Key key,
const String &  toWrite,
v8::Handle< v8::Function >  cb 
)
void Sirikata::JS::JSContextStruct::struct_asyncDeregisterSuspendable ( JSSuspendable toDeregister,
Liveness::Token  contAlive,
Liveness::Token  suspAlive 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_create_vis ( const SpaceObjectReference sporefWathcing,
JSVisibleDataPtr  addParams 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_createContext ( JSPresenceStruct jspres,
const SpaceObjectReference canSendTo,
Capabilities::CapNum  capNum 
)
Parameters:
{JSPresenceStruct}jspres Each context (other than the root) is associated with a single presence. Depending on the capabilities granted to a sandbox, code within the sandbox can act on that presence, for instance, sending messages from it, receiving its proximity callbacks, etc.
{SpaceObjectReference}canSendTo The sporef associated with the May be SpaceObjectReference::null. Used for the sendHome call.
{Capabilities::CapNum}capNum Capabilities granted to knew sandbox.

References associatedPresence, Sirikata::JS::JSObjectScript::createContext(), jsObjScript, and struct_registerSuspendable().

Referenced by Sirikata::JS::JSSystemStruct::struct_createContext().

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_createEntity ( EntityCreateInfo eci)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_createQuaternion ( Quaternion toCreate)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_createTimeout ( double  period,
v8::Persistent< v8::Function > &  cb,
uint32  contID,
double  timeRemaining,
bool  isSuspended,
bool  isCleared 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_createTimeout ( double  period,
v8::Persistent< v8::Function > &  cb 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_createVec3 ( Vector3d &  toCreate)
void Sirikata::JS::JSContextStruct::struct_deregisterSuspendable ( JSSuspendable toDeregister)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_evalInGlobal ( const String &  native_contents,
ScriptOrigin *  sOrigin 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_event ( v8::Persistent< v8::Function > &  cb)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_executeScript ( v8::Handle< v8::Function >  funcToCall,
const v8::Arguments &  args 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_getAssociatedPresPosition ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_getScript ( )
v8::Handle< Object > Sirikata::JS::JSContextStruct::struct_getSystem ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_import ( const String &  toImportFrom,
bool  isJS 
)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_registerOnPresenceConnectedHandler ( v8::Persistent< v8::Function >  cb_persist)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_registerOnPresenceDisconnectedHandler ( v8::Persistent< v8::Function >  cb_persist)
void Sirikata::JS::JSContextStruct::struct_registerSuspendable ( JSSuspendable toRegister)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_require ( const String &  toRequireFrom,
bool  isJS 
)
v8::Handle<v8::Value> Sirikata::JS::JSContextStruct::struct_resumeContext ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_rootReset ( )

This function is called only by JSObjectScript directly.

It disposes of mContext and system objects. It then runs through all suspendables associated with this context, calling clear on each (minus the presences).

References associatedSuspendables, CHECK_EMERSON_SCRIPT_ERROR, checkContextConnectCallback(), Sirikata::JS::JSPresenceStruct::clear(), createContextObjects(), inClear, jsObjScript, mContext, mContGlobTempl, mInSuspendableLoop, mScript, struct_registerSuspendable(), suspendablesToAdd, suspendablesToDelete, and systemObj.

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

v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_sendHome ( const String &  toSend)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_setReset ( const std::map< SpaceObjectReference, std::vector< SpaceObjectReference > > &  proxResSet)
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::struct_setScript ( const String &  script)
v8::Handle<v8::Value> Sirikata::JS::JSContextStruct::struct_suspendContext ( )
v8::Handle< v8::Value > Sirikata::JS::JSContextStruct::suspend ( ) [virtual]

Member Data Documentation

v8::Persistent<v8::Function> Sirikata::JS::JSContextStruct::cbOnConnected [private]
v8::Persistent<v8::Function> Sirikata::JS::JSContextStruct::cbOnDisconnected [private]

Referenced by finishClear(), and struct_rootReset().

v8::Persistent<v8::Context> Sirikata::JS::JSContextStruct::mContext

Referenced by getContextID().

v8::Handle<v8::ObjectTemplate> Sirikata::JS::JSContextStruct::mContGlobTempl [private]

Referenced by struct_rootReset().

Referenced by struct_sendHome().

v8::Persistent<v8::Function> Sirikata::JS::JSContextStruct::proxAddedFunc
v8::Persistent<v8::Function> Sirikata::JS::JSContextStruct::proxRemovedFunc
v8::Persistent<v8::Object> Sirikata::JS::JSContextStruct::systemObj [private]

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