Sirikata
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
Sirikata::ObjectHost Class Reference

#include <ObjectHost.hpp>

Inheritance diagram for Sirikata::ObjectHost:
Collaboration diagram for Sirikata::ObjectHost:

List of all members.

Classes

struct  ConnectionInfo

Public Types

typedef std::tr1::function
< void(const SpaceID &, const
ObjectReference &, ServerID)> 
SessionCallback
typedef std::tr1::function
< void(const SpaceID &, const
ObjectReference
&, ConnectionInfo)> 
ConnectedCallback
typedef std::tr1::function
< void(const SpaceID &, const
ObjectReference &, ServerID)> 
MigratedCallback
typedef std::tr1::function
< void(const
SpaceObjectReference
&, SessionManager::ConnectionEvent
after)> 
StreamCreatedCallback
typedef std::tr1::function
< void(const
SpaceObjectReference
&, Disconnect::Code)> 
DisconnectedCallback
typedef SST::Stream
< SpaceObjectReference
SSTStream
 Lookup the SST stream for a particular object.
typedef SSTStream::Ptr SSTStreamPtr

Public Member Functions

String getSimOptions (const String &)
 ObjectHost (ObjectHostContext *ctx, Network::IOService *ioServ, const String &options)
 Caller is responsible for starting a thread.
 ~ObjectHost ()
 The ObjectHost must be destroyed after all HostedObject instances.
ObjectHostContextcontext () const
virtual HostedObjectPtr createObject (const UUID &_id, const String &script_type, const String &script_opts, const String &script_contents)
 Create an object with the specified script.
virtual HostedObjectPtr createObject (const String &script_type, const String &script_opts, const String &script_contents)
 Create an object with the specified script.
virtual const String & defaultScriptType () const =0
virtual const String & defaultScriptOptions () const =0
virtual const String & defaultScriptContents () const =0
void addServerIDMap (const SpaceID &space_id, ServerIDMap *sidmap)
void setStorage (OH::Storage *storage)
OH::StoragegetStorage ()
void setPersistentSet (OH::PersistedObjectSet *persistentset)
OH::PersistedObjectSetgetPersistedObjectSet ()
void setQueryProcessor (OH::ObjectQueryProcessor *proc)
OH::ObjectQueryProcessorgetQueryProcessor ()
std::tr1::shared_ptr
< Transfer::TransferPool
getTransferPool ()
bool connect (HostedObjectPtr ho, const SpaceObjectReference &sporef, const SpaceID &space, const TimedMotionVector3f &loc, const TimedMotionQuaternion &orient, const BoundingSphere3f &bnds, const String &mesh, const String &physics, const String &query, const String &zernike, ConnectedCallback connected_cb, MigratedCallback migrated_cb, StreamCreatedCallback stream_created_cb, DisconnectedCallback disconnected_cb)
 Connect the object to the space with the given starting parameters.
void disconnectObject (const SpaceID &space, const ObjectReference &oref)
 Use this function to request the object host to send a disconnect message to space for object.
Duration serverTimeOffset (const SpaceID &space) const
 Get offset of server time from client time for the given space.
Duration clientTimeOffset (const SpaceID &space) const
 Get offset of client time from server time for the given space.
Time spaceTime (const SpaceID &space, const Time &t) const
 Convert a local time into a time for the given space.
Time currentSpaceTime (const SpaceID &space) const
 Get the current time in the given space.
Time localTime (const SpaceID &space, const Time &t) const
 Convert a time in the given space to a local time.
Time currentLocalTime () const
 Get the current local time.
bool send (SpaceObjectReference &sporefsrc, const SpaceID &space, const ObjectMessagePort src_port, const UUID &dest, const ObjectMessagePort dest_port, const std::string &payload)
 Primary ODP send function.
bool send (SpaceObjectReference &sporefsrc, const SpaceID &space, const ObjectMessagePort src_port, const UUID &dest, const ObjectMessagePort dest_port, MemoryReference payload)
void registerHostedObject (const SpaceObjectReference &sporef_uuid, const HostedObjectPtr &obj)
 Register object by private UUID, so that it is possible to talk to objects/services which are not part of any space.
void unregisterHostedObject (const SpaceObjectReference &sporef_uuid, HostedObject *obj)
 Unregister a private UUID. Done automatically by ~HostedObject.
void hostedObjectDestroyed (const UUID &objid)
HostedObjectPtr getHostedObject (const SpaceObjectReference &id) const
 Lookup HostedObject by one of it's presence IDs.
HostedObjectPtr getHostedObject (const UUID &id) const
 Lookup HostedObject by its internal ID.
SSTStreamPtr getSpaceStream (const SpaceID &space, const ObjectReference &internalID)
virtual void start ()
virtual void stop ()
virtual OHDP::PortbindOHDPPort (const SpaceID &space, const OHDP::NodeID &node, OHDP::PortID port)
 Bind an OHDP port for use.
virtual OHDP::PortbindOHDPPort (const SpaceID &space, const OHDP::NodeID &node)
 Bind a random, unused OHDP port for use.
virtual OHDP::PortID unusedOHDPPort (const SpaceID &space, const OHDP::NodeID &node)
 Get a random, unused OHDP port.
virtual void registerDefaultOHDPHandler (const MessageHandler &cb)
ObjectScriptManagergetScriptManager (const String &id)

Private Types

typedef
std::tr1::unordered_map
< SpaceID, SessionManager
*, SpaceID::Hasher
SpaceSessionManagerMap
typedef
std::tr1::unordered_map
< SpaceObjectReference,
HostedObjectPtr,
SpaceObjectReference::Hasher
HostedObjectMap
typedef
std::tr1::unordered_map< UUID,
HostedObjectWPtr, UUID::Hasher
InternalIDHostedObjectMap
typedef
std::tr1::unordered_map
< String, ObjectScriptManager * > 
ScriptManagerMap
typedef std::tr1::function
< void(const SpaceID &, const
ObjectReference &, ServerID,
const TimedMotionVector3f
&, const TimedMotionQuaternion
&, const BoundingSphere3f
&, const String &, const
String &)> 
SessionConnectedCallback

Private Member Functions

virtual void onSpaceNodeSession (const OHDP::SpaceNodeID &id, OHDPSST::Stream::Ptr sn_stream)
virtual void onSpaceNodeSessionEnded (const OHDP::SpaceNodeID &id)
void handleObjectConnected (const SpaceObjectReference &sporef_internalID, ServerID server)
void handleObjectMigrated (const SpaceObjectReference &sporef_internalID, ServerID from, ServerID to)
void handleObjectMessage (const SpaceObjectReference &sporef_internalID, const SpaceID &space, Sirikata::Protocol::Object::ObjectMessage *msg)
void handleObjectDisconnected (const SpaceObjectReference &sporef_internalID, Disconnect::Code)
void wrappedConnectedCallback (HostedObjectWPtr ho_weak, const SpaceID &space, const ObjectReference &obj, const SessionManager::ConnectionInfo &ci, ConnectedCallback cb)
void wrappedStreamCreatedCallback (HostedObjectWPtr ho_weak, const SpaceObjectReference &sporef, SessionManager::ConnectionEvent after, StreamCreatedCallback cb)
void wrappedDisconnectedCallback (HostedObjectWPtr ho_weak, const SpaceObjectReference &sporef, Disconnect::Code cause, DisconnectedCallback)
void commandListObjects (const Command::Command &cmd, Command::Commander *cmdr, Command::CommandID cmdid)
void commandCreateObject (const Command::Command &cmd, Command::Commander *cmdr, Command::CommandID cmdid)
void commandDestroyObject (const Command::Command &cmd, Command::Commander *cmdr, Command::CommandID cmdid)
void commandObjectPresences (const Command::Command &cmd, Command::Commander *cmdr, Command::CommandID cmdid)
HostedObjectPtr getCommandObject (const Command::Command &cmd, Command::Commander *cmdr, Command::CommandID cmdid)
void handleDefaultOHDPMessageHandler (const OHDP::Endpoint &src, const OHDP::Endpoint &dst, MemoryReference payload)

Private Attributes

ObjectHostContextmContext
OH::StoragemStorage
OH::PersistedObjectSetmPersistentSet
OH::ObjectQueryProcessormQueryProcessor
SpaceSessionManagerMap mSessionManagers
uint32 mActiveHostedObjects
HostedObjectMap mHostedObjects
InternalIDHostedObjectMap mHostedObjectsByID
ScriptManagerMap mScriptManagers
std::tr1::shared_ptr
< Transfer::TransferPool
mTransferPool
Transfer::TransferMediatormTransferMediator
std::tr1::unordered_map
< String, OptionSet * > 
mSpaceConnectionProtocolOptions
std::map< std::string,
std::string > 
mSimOptions
 options passed to initialization of scripts (usually path information)
Sirikata::SerializationCheck mSessionSerialization
OHDP::MessageHandler mDefaultOHDPMessageHandler

Member Typedef Documentation

typedef std::tr1::function<void(const SpaceID&, const ObjectReference&, ConnectionInfo)> Sirikata::ObjectHost::ConnectedCallback
typedef std::tr1::function<void(const SpaceID&, const ObjectReference&, ServerID)> Sirikata::ObjectHost::MigratedCallback
typedef std::tr1::unordered_map<String, ObjectScriptManager*> Sirikata::ObjectHost::ScriptManagerMap [private]
typedef std::tr1::function<void(const SpaceID&, const ObjectReference&, ServerID)> Sirikata::ObjectHost::SessionCallback
typedef std::tr1::function<void(const SpaceID&, const ObjectReference&, ServerID, const TimedMotionVector3f&, const TimedMotionQuaternion&, const BoundingSphere3f&, const String&, const String&)> Sirikata::ObjectHost::SessionConnectedCallback [private]

Lookup the SST stream for a particular object.


Constructor & Destructor Documentation

Sirikata::ObjectHost::ObjectHost ( ObjectHostContext ctx,
Network::IOService ioServ,
const String &  options 
)
Sirikata::ObjectHost::~ObjectHost ( )

The ObjectHost must be destroyed after all HostedObject instances.

References mHostedObjects.


Member Function Documentation

void Sirikata::ObjectHost::addServerIDMap ( const SpaceID space_id,
ServerIDMap sidmap 
)
OHDP::Port * Sirikata::ObjectHost::bindOHDPPort ( const SpaceID space,
const OHDP::NodeID node,
OHDP::PortID  port 
) [virtual]

Bind an OHDP port for use.

Parameters:
spacethe Space to communicate via
nodethe node to communicate via
portthe PortID to attempt to bind
Returns:
an OHDP Port object which can be used immediately, or NULL if the port is already bound
Exceptions:
PortAllocationErrorif the Service cannot allocate the port for some reason other than it already being allocated.

Implements Sirikata::OHDP::Service.

References mSessionManagers.

OHDP::Port * Sirikata::ObjectHost::bindOHDPPort ( const SpaceID space,
const OHDP::NodeID node 
) [virtual]

Bind a random, unused OHDP port for use.

Parameters:
spacethe Space to communicate via
Returns:
an OHDP Port object which can be used immediately, or, in extremely rare cases, NULL when an unused port isn't available
Exceptions:
PortAllocationErrorif the Service cannot allocate the port for some reason other than it already being allocated.

Implements Sirikata::OHDP::Service.

References mSessionManagers.

Duration Sirikata::ObjectHost::clientTimeOffset ( const SpaceID space) const

Get offset of client time from server time for the given space.

Should only be called by objects with an active connection to that space. This is just a utility, is always -serverTimeOffset().

References mSessionManagers.

Referenced by localTime().

void Sirikata::ObjectHost::commandCreateObject ( const Command::Command cmd,
Command::Commander cmdr,
Command::CommandID  cmdid 
) [private]
void Sirikata::ObjectHost::commandDestroyObject ( const Command::Command cmd,
Command::Commander cmdr,
Command::CommandID  cmdid 
) [private]
void Sirikata::ObjectHost::commandListObjects ( const Command::Command cmd,
Command::Commander cmdr,
Command::CommandID  cmdid 
) [private]
void Sirikata::ObjectHost::commandObjectPresences ( const Command::Command cmd,
Command::Commander cmdr,
Command::CommandID  cmdid 
) [private]

References getCommandObject().

Referenced by ObjectHost().

bool Sirikata::ObjectHost::connect ( HostedObjectPtr  ho,
const SpaceObjectReference sporef,
const SpaceID space,
const TimedMotionVector3f loc,
const TimedMotionQuaternion orient,
const BoundingSphere3f &  bnds,
const String &  mesh,
const String &  physics,
const String &  query,
const String &  zernike,
ConnectedCallback  connected_cb,
MigratedCallback  migrated_cb,
StreamCreatedCallback  stream_created_cb,
DisconnectedCallback  disconnected_cb 
)

Connect the object to the space with the given starting parameters.

returns true if the connection was initiated and no other objects are using this ID to connect.

References Sirikata::SessionManager::connect(), Sirikata::OH::ObjectQueryProcessor::connectRequest(), mHostedObjects, mQueryProcessor, mSessionManagers, mSessionSerialization, wrappedConnectedCallback(), wrappedDisconnectedCallback(), and wrappedStreamCreatedCallback().

Referenced by Sirikata::HostedObject::objectHostConnect().

ObjectHostContext* Sirikata::ObjectHost::context ( ) const [inline]
HostedObjectPtr Sirikata::ObjectHost::createObject ( const String &  script_type,
const String &  script_opts,
const String &  script_contents 
) [virtual]

Create an object with the specified script.

The object will be automatically assigned a unique identifier.

Parameters:
script_typetype of script to instantiate, e.g. 'js'
script_optsoptions to pass to the created script
script_contentscontents of the script, i.e. the script text to eval

References createObject(), and Sirikata::UUID::random().

HostedObjectPtr Sirikata::ObjectHost::createObject ( const UUID _id,
const String &  script_type,
const String &  script_opts,
const String &  script_contents 
) [virtual]

Create an object with the specified script.

This version allows you to specify the unique identifier manually, so it should only be used if you need an exact ID, e.g. if you are restoring an object.

Parameters:
_ida unique identifier for this object. Only use this
script_typetype of script to instantiate, e.g. 'js'
script_optsoptions to pass to the created script
script_contentscontents of the script, i.e. the script text to eval

References defaultScriptContents(), defaultScriptOptions(), defaultScriptType(), mActiveHostedObjects, mContext, and mHostedObjectsByID.

Referenced by commandCreateObject(), Sirikata::SQLiteObjectFactory::connectObjects(), Sirikata::CassandraObjectFactory::connectObjects(), createObject(), Sirikata::JS::EmersonScript::eCreateEntityFinish(), and Sirikata::CSVObjectFactory::generate().

Time Sirikata::ObjectHost::currentLocalTime ( ) const

Get the current local time.

References mContext, and Sirikata::Context::simTime().

Referenced by Sirikata::HostedObject::currentLocalTime().

Time Sirikata::ObjectHost::currentSpaceTime ( const SpaceID space) const

Get the current time in the given space.

References mContext, Sirikata::Context::simTime(), and spaceTime().

Referenced by Sirikata::HostedObject::currentSpaceTime().

virtual const String& Sirikata::ObjectHost::defaultScriptContents ( ) const [pure virtual]

Implemented in Sirikata::CppohObjectHost.

Referenced by createObject().

virtual const String& Sirikata::ObjectHost::defaultScriptOptions ( ) const [pure virtual]

Implemented in Sirikata::CppohObjectHost.

Referenced by createObject().

virtual const String& Sirikata::ObjectHost::defaultScriptType ( ) const [pure virtual]

Implemented in Sirikata::CppohObjectHost.

Referenced by createObject().

void Sirikata::ObjectHost::disconnectObject ( const SpaceID space,
const ObjectReference oref 
)

Use this function to request the object host to send a disconnect message to space for object.

References mSessionManagers.

Referenced by Sirikata::HostedObject::destroy(), Sirikata::HostedObject::disconnectDeadPresence(), and Sirikata::HostedObject::disconnectFromSpace().

HostedObjectPtr Sirikata::ObjectHost::getCommandObject ( const Command::Command cmd,
Command::Commander cmdr,
Command::CommandID  cmdid 
) [private]
HostedObjectPtr Sirikata::ObjectHost::getHostedObject ( const SpaceObjectReference id) const

Lookup HostedObject by one of it's presence IDs.

This may return an empty pointer if no objects have tried to connect. The returned object may also still be in the process of connecting that presence.

References mHostedObjects.

Referenced by getCommandObject(), and handleObjectMessage().

HostedObjectPtr Sirikata::ObjectHost::getHostedObject ( const UUID id) const

Lookup HostedObject by its internal ID.

References mHostedObjectsByID.

OH::PersistedObjectSet* Sirikata::ObjectHost::getPersistedObjectSet ( ) [inline]
OH::ObjectQueryProcessor* Sirikata::ObjectHost::getQueryProcessor ( ) [inline]
ObjectScriptManager * Sirikata::ObjectHost::getScriptManager ( const String &  id)
String Sirikata::ObjectHost::getSimOptions ( const String &  simName)
ObjectHost::SSTStreamPtr Sirikata::ObjectHost::getSpaceStream ( const SpaceID space,
const ObjectReference internalID 
)
OH::Storage* Sirikata::ObjectHost::getStorage ( ) [inline]
std::tr1::shared_ptr<Transfer::TransferPool> Sirikata::ObjectHost::getTransferPool ( ) [inline]
void Sirikata::ObjectHost::handleDefaultOHDPMessageHandler ( const OHDP::Endpoint src,
const OHDP::Endpoint dst,
MemoryReference  payload 
) [private]

References mDefaultOHDPMessageHandler.

Referenced by addServerIDMap().

void Sirikata::ObjectHost::handleObjectConnected ( const SpaceObjectReference sporef_internalID,
ServerID  server 
) [private]
void Sirikata::ObjectHost::handleObjectDisconnected ( const SpaceObjectReference sporef_internalID,
Disconnect::Code   
) [private]
void Sirikata::ObjectHost::handleObjectMessage ( const SpaceObjectReference sporef_internalID,
const SpaceID space,
Sirikata::Protocol::Object::ObjectMessage *  msg 
) [private]
void Sirikata::ObjectHost::handleObjectMigrated ( const SpaceObjectReference sporef_internalID,
ServerID  from,
ServerID  to 
) [private]
void Sirikata::ObjectHost::hostedObjectDestroyed ( const UUID objid)
Time Sirikata::ObjectHost::localTime ( const SpaceID space,
const Time t 
) const

Convert a time in the given space to a local time.

Parameters:
spacethe space to translate from
tthe time in the space to convert to a local time

References clientTimeOffset(), Sirikata::Time::null(), and Sirikata::Time::raw().

Referenced by Sirikata::HostedObject::localTime().

virtual void Sirikata::ObjectHost::onSpaceNodeSession ( const OHDP::SpaceNodeID id,
OHDPSST::Stream::Ptr  sn_stream 
) [inline, private, virtual]
virtual void Sirikata::ObjectHost::onSpaceNodeSessionEnded ( const OHDP::SpaceNodeID id) [inline, private, virtual]
void Sirikata::ObjectHost::registerDefaultOHDPHandler ( const MessageHandler cb) [virtual]
void Sirikata::ObjectHost::registerHostedObject ( const SpaceObjectReference sporef_uuid,
const HostedObjectPtr obj 
)

Register object by private UUID, so that it is possible to talk to objects/services which are not part of any space.

Done automatically by HostedObject::initialize* functions.

References Sirikata::Logging::error, mHostedObjects, obj, SILOG, and Sirikata::SpaceObjectReference::toString().

Referenced by Sirikata::HostedObject::objectHostConnect().

bool Sirikata::ObjectHost::send ( SpaceObjectReference sporefsrc,
const SpaceID space,
const ObjectMessagePort  src_port,
const UUID dest,
const ObjectMessagePort  dest_port,
const std::string &  payload 
)

Primary ODP send function.

References mSessionManagers, and mSessionSerialization.

Referenced by Sirikata::HostedObject::delegateODPPortSend(), and send().

bool Sirikata::ObjectHost::send ( SpaceObjectReference sporefsrc,
const SpaceID space,
const ObjectMessagePort  src_port,
const UUID dest,
const ObjectMessagePort  dest_port,
MemoryReference  payload 
)
Duration Sirikata::ObjectHost::serverTimeOffset ( const SpaceID space) const

Get offset of server time from client time for the given space.

Should only be called by objects with an active connection to that space.

References mSessionManagers.

Referenced by spaceTime().

void Sirikata::ObjectHost::setPersistentSet ( OH::PersistedObjectSet persistentset) [inline]
void Sirikata::ObjectHost::setQueryProcessor ( OH::ObjectQueryProcessor proc) [inline]
void Sirikata::ObjectHost::setStorage ( OH::Storage storage) [inline]
Time Sirikata::ObjectHost::spaceTime ( const SpaceID space,
const Time t 
) const

Convert a local time into a time for the given space.

Parameters:
spacethe space to translate to
tthe local time to convert

References Sirikata::Time::null(), Sirikata::Time::raw(), and serverTimeOffset().

Referenced by currentSpaceTime(), and Sirikata::HostedObject::spaceTime().

void Sirikata::ObjectHost::start ( ) [virtual]

Implements Sirikata::Service.

void Sirikata::ObjectHost::stop ( ) [virtual]
void Sirikata::ObjectHost::unregisterHostedObject ( const SpaceObjectReference sporef_uuid,
HostedObject obj 
)
OHDP::PortID Sirikata::ObjectHost::unusedOHDPPort ( const SpaceID space,
const OHDP::NodeID node 
) [virtual]

Get a random, unused OHDP port.

Implements Sirikata::OHDP::Service.

References mSessionManagers, and Sirikata::XDP::PortID::null().

void Sirikata::ObjectHost::wrappedConnectedCallback ( HostedObjectWPtr  ho_weak,
const SpaceID space,
const ObjectReference obj,
const SessionManager::ConnectionInfo ci,
ConnectedCallback  cb 
) [private]
void Sirikata::ObjectHost::wrappedDisconnectedCallback ( HostedObjectWPtr  ho_weak,
const SpaceObjectReference sporef,
Disconnect::Code  cause,
DisconnectedCallback  cb 
) [private]
void Sirikata::ObjectHost::wrappedStreamCreatedCallback ( HostedObjectWPtr  ho_weak,
const SpaceObjectReference sporef,
SessionManager::ConnectionEvent  after,
StreamCreatedCallback  cb 
) [private]

Member Data Documentation

Referenced by getScriptManager(), and ObjectHost().

Referenced by commandListObjects(), connect(), and send().

std::map<std::string, std::string > Sirikata::ObjectHost::mSimOptions [private]

options passed to initialization of scripts (usually path information)

Referenced by getSimOptions(), and ObjectHost().

std::tr1::unordered_map<String,OptionSet*> Sirikata::ObjectHost::mSpaceConnectionProtocolOptions [private]

Referenced by ObjectHost().

Referenced by ObjectHost().

Referenced by ObjectHost().


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