Sirikata
|
An implementation of ODP::Service which can be delegated to by providing a single function for allocating Ports when they are available. More...
#include <DelegateService.hpp>
Public Types | |
typedef std::tr1::function < DelegatePort *(DelegateService *, const SpaceObjectReference &, PortID) | PortCreateFunction ) |
Public Member Functions | |
DelegateService (PortCreateFunction create_func) | |
Create a DelegateService that uses create_func to generate new ports. | |
virtual | ~DelegateService () |
virtual Port * | bindODPPort (const SpaceID &space, const ObjectReference &objref, PortID port) |
Bind an ODP port for use. | |
virtual Port * | bindODPPort (const SpaceObjectReference &sor, PortID port) |
virtual Port * | bindODPPort (const SpaceID &space, const ObjectReference &objref) |
Bind a random, unused ODP port for use. | |
virtual Port * | bindODPPort (const SpaceObjectReference &sor) |
virtual PortID | unusedODPPort (const SpaceID &space, const ObjectReference &objref) |
Get a random, unused ODP port. | |
virtual PortID | unusedODPPort (const SpaceObjectReference &sor) |
virtual void | registerDefaultODPHandler (const MessageHandler &cb) |
Register a handler for messages that arrive on unbound ports. | |
bool | deliver (const Endpoint &src, const Endpoint &dst, MemoryReference data) const |
Deliver a message to this subsystem. | |
void | deallocatePort (DelegatePort *port) |
Private Types | |
typedef std::tr1::unordered_map < PortID, DelegatePort *, PortID::Hasher > | PortMap |
typedef std::tr1::unordered_map < SpaceObjectReference, PortMap *, SpaceObjectReference::Hasher > | SpacePortMap |
Private Member Functions | |
PortMap * | getPortMap (const SpaceObjectReference &sor) const |
PortMap * | getOrCreatePortMap (const SpaceObjectReference &sor) |
Private Attributes | |
PortCreateFunction | mCreator |
SpacePortMap | mSpacePortMap |
MessageHandler | mDefaultHandler |
An implementation of ODP::Service which can be delegated to by providing a single function for allocating Ports when they are available.
DelegateService takes care of all the other bookkeeping. Generally this will be the simplest and best way to provide the Service interface.
This class works in conjunction with the DelegatePort class. In order to function properly, your port creation function must return a DelegatePort (or subclass).
To ease memory management, the DelegateService notifies DelegatePorts when they have become invalid (e.g. the DelegateService is being deleted). As the Port is owned by the allocator, it remains valid memory (it is not deleted) but it will no longer function normally, producing warnings that it has been invalidated.
typedef std::tr1::function<DelegatePort*(DelegateService*,const SpaceObjectReference&,PortID) Sirikata::ODP::DelegateService::PortCreateFunction) |
typedef std::tr1::unordered_map<PortID, DelegatePort*, PortID::Hasher> Sirikata::ODP::DelegateService::PortMap [private] |
typedef std::tr1::unordered_map<SpaceObjectReference, PortMap*, SpaceObjectReference::Hasher> Sirikata::ODP::DelegateService::SpacePortMap [private] |
Sirikata::ODP::DelegateService::DelegateService | ( | PortCreateFunction | create_func | ) |
Create a DelegateService that uses create_func to generate new ports.
create_func | a function which accepts a SpaceID and PortID and returns a new Port object. It only needs to generate the ports; the DelegateService class will handle other bookkeeping and error checking. |
Sirikata::ODP::DelegateService::~DelegateService | ( | ) | [virtual] |
Port * Sirikata::ODP::DelegateService::bindODPPort | ( | const SpaceID & | space, |
const ObjectReference & | objref, | ||
PortID | port | ||
) | [virtual] |
Bind an ODP port for use.
space | the Space to communicate via |
objref | the Object to communicate via |
port | the PortID to attempt to bind |
PortAllocationError | if the Service cannot allocate the port for some reason other than it already being allocated. |
Implements Sirikata::ODP::Service.
Referenced by Sirikata::HostedObject::bindODPPort(), and bindODPPort().
Port * Sirikata::ODP::DelegateService::bindODPPort | ( | const SpaceObjectReference & | sor, |
PortID | port | ||
) | [virtual] |
Implements Sirikata::ODP::Service.
References getOrCreatePortMap(), and mCreator.
Port * Sirikata::ODP::DelegateService::bindODPPort | ( | const SpaceObjectReference & | sor | ) | [virtual] |
Implements Sirikata::ODP::Service.
References bindODPPort(), Sirikata::XDP::PortID::null(), and unusedODPPort().
Port * Sirikata::ODP::DelegateService::bindODPPort | ( | const SpaceID & | space, |
const ObjectReference & | objref | ||
) | [virtual] |
Bind a random, unused ODP port for use.
space | the Space to communicate via |
PortAllocationError | if the Service cannot allocate the port for some reason other than it already being allocated. |
Implements Sirikata::ODP::Service.
References bindODPPort().
void Sirikata::ODP::DelegateService::deallocatePort | ( | DelegatePort * | port | ) |
bool Sirikata::ODP::DelegateService::deliver | ( | const Endpoint & | src, |
const Endpoint & | dst, | ||
MemoryReference | data | ||
) | const |
Deliver a message to this subsystem.
src | source endpoint |
dst | destination endpoint |
data | the payload of the message |
References Sirikata::XDP::DelegatePort< EndpointType, DelegateServiceType, PortType >::deliver(), getPortMap(), mDefaultHandler, Sirikata::XDP::Endpoint< IdentifierType >::port(), and Sirikata::ODP::Endpoint::spaceObject().
Referenced by Sirikata::Forwarder::dispatchMessage(), Sirikata::Server::handleSingleObjectHostMessageRouting(), and Sirikata::HostedObject::receiveMessage().
DelegateService::PortMap * Sirikata::ODP::DelegateService::getOrCreatePortMap | ( | const SpaceObjectReference & | sor | ) | [private] |
References getPortMap(), and mSpacePortMap.
Referenced by bindODPPort().
DelegateService::PortMap * Sirikata::ODP::DelegateService::getPortMap | ( | const SpaceObjectReference & | sor | ) | const [private] |
References mSpacePortMap.
Referenced by deallocatePort(), deliver(), getOrCreatePortMap(), and unusedODPPort().
void Sirikata::ODP::DelegateService::registerDefaultODPHandler | ( | const MessageHandler & | cb | ) | [virtual] |
Register a handler for messages that arrive on unbound ports.
By default there is no handler and such messages are ignored. Note that this handler will not be invoked for messages arriving at a bound port for which no handler has been registered.
cb | the handler for messages arriving at unbound ports |
Implements Sirikata::ODP::Service.
References mDefaultHandler.
Referenced by Sirikata::HostedObject::registerDefaultODPHandler().
PortID Sirikata::ODP::DelegateService::unusedODPPort | ( | const SpaceObjectReference & | sor | ) | [virtual] |
Implements Sirikata::ODP::Service.
References Sirikata::Logging::error, getPortMap(), Sirikata::XDP::PortID::null(), OBJECT_PORT_SYSTEM_MAX, OBJECT_PORT_SYSTEM_RESERVED_MAX, and SILOG.
PortID Sirikata::ODP::DelegateService::unusedODPPort | ( | const SpaceID & | space, |
const ObjectReference & | objref | ||
) | [virtual] |
Get a random, unused ODP port.
Implements Sirikata::ODP::Service.
Referenced by bindODPPort(), and Sirikata::HostedObject::unusedODPPort().
Referenced by bindODPPort().
Referenced by deliver(), and registerDefaultODPHandler().
Referenced by getOrCreatePortMap(), getPortMap(), and ~DelegateService().