Sirikata
|
An implementation of OHDP::Service which manages most bookkeeping for you, delegating only for Port creation. More...
#include <DelegateService.hpp>
Classes | |
struct | SpaceIDNodeID |
Public Types | |
typedef std::tr1::function < DelegatePort *(DelegateService *, const Endpoint &) | PortCreateFunction ) |
Public Member Functions | |
DelegateService (PortCreateFunction create_func) | |
Create a DelegateService that uses create_func to generate new ports. | |
virtual | ~DelegateService () |
virtual Port * | bindOHDPPort (const SpaceID &space, const NodeID &node, PortID port) |
Bind an OHDP port for use. | |
virtual Port * | bindOHDPPort (const SpaceID &space, const NodeID &node) |
Bind a random, unused OHDP port for use. | |
virtual PortID | unusedOHDPPort (const SpaceID &space, const NodeID &node) |
Get a random, unused OHDP port. | |
virtual void | registerDefaultOHDPHandler (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 < SpaceIDNodeID, PortMap *, SpaceIDNodeID::Hasher > | SpacePortMap |
Private Member Functions | |
PortMap * | getPortMap (const SpaceIDNodeID &snid) const |
PortMap * | getOrCreatePortMap (const SpaceIDNodeID &snid) |
Private Attributes | |
PortCreateFunction | mCreator |
SpacePortMap | mSpacePortMap |
MessageHandler | mDefaultHandler |
An implementation of OHDP::Service which manages most bookkeeping for you, delegating only for Port creation.
See ODP::Service for more details as these are essentially the same.
typedef std::tr1::function<DelegatePort*(DelegateService*, const Endpoint&) Sirikata::OHDP::DelegateService::PortCreateFunction) |
typedef std::tr1::unordered_map<PortID, DelegatePort*, PortID::Hasher> Sirikata::OHDP::DelegateService::PortMap [private] |
typedef std::tr1::unordered_map<SpaceIDNodeID, PortMap*, SpaceIDNodeID::Hasher> Sirikata::OHDP::DelegateService::SpacePortMap [private] |
Sirikata::OHDP::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::OHDP::DelegateService::~DelegateService | ( | ) | [virtual] |
Port * Sirikata::OHDP::DelegateService::bindOHDPPort | ( | const SpaceID & | space, |
const NodeID & | node, | ||
PortID | port | ||
) | [virtual] |
Bind an OHDP port for use.
space | the Space to communicate via |
node | the node 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::OHDP::Service.
References getOrCreatePortMap(), and mCreator.
Referenced by bindOHDPPort().
Port * Sirikata::OHDP::DelegateService::bindOHDPPort | ( | const SpaceID & | space, |
const NodeID & | node | ||
) | [virtual] |
Bind a random, unused OHDP 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::OHDP::Service.
References bindOHDPPort(), Sirikata::XDP::PortID::null(), and unusedOHDPPort().
void Sirikata::OHDP::DelegateService::deallocatePort | ( | DelegatePort * | port | ) |
bool Sirikata::OHDP::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::OHDP::Endpoint::node(), Sirikata::XDP::Endpoint< IdentifierType >::port(), and Sirikata::XDP::Endpoint< IdentifierType >::space().
Referenced by Sirikata::SessionManager::handleServerMessage().
DelegateService::PortMap * Sirikata::OHDP::DelegateService::getOrCreatePortMap | ( | const SpaceIDNodeID & | snid | ) | [private] |
References getPortMap(), and mSpacePortMap.
Referenced by bindOHDPPort().
DelegateService::PortMap * Sirikata::OHDP::DelegateService::getPortMap | ( | const SpaceIDNodeID & | snid | ) | const [private] |
References mSpacePortMap.
Referenced by deallocatePort(), deliver(), getOrCreatePortMap(), and unusedOHDPPort().
void Sirikata::OHDP::DelegateService::registerDefaultOHDPHandler | ( | 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::OHDP::Service.
References mDefaultHandler.
Referenced by Sirikata::ObjectHost::addServerIDMap().
PortID Sirikata::OHDP::DelegateService::unusedOHDPPort | ( | const SpaceID & | space, |
const NodeID & | node | ||
) | [virtual] |
Get a random, unused OHDP port.
Implements Sirikata::OHDP::Service.
References Sirikata::Logging::error, getPortMap(), Sirikata::XDP::PortID::null(), OBJECT_PORT_SYSTEM_MAX, OBJECT_PORT_SYSTEM_RESERVED_MAX, and SILOG.
Referenced by bindOHDPPort().
Referenced by bindOHDPPort().
Referenced by deliver(), and registerDefaultOHDPHandler().
Referenced by getOrCreatePortMap(), getPortMap(), and ~DelegateService().