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

An implementation of OHDP::Service which manages most bookkeeping for you, delegating only for Port creation. More...

#include <DelegateService.hpp>

Inheritance diagram for Sirikata::OHDP::DelegateService:
Collaboration diagram for Sirikata::OHDP::DelegateService:

List of all members.

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 PortbindOHDPPort (const SpaceID &space, const NodeID &node, PortID port)
 Bind an OHDP port for use.
virtual PortbindOHDPPort (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

PortMapgetPortMap (const SpaceIDNodeID &snid) const
PortMapgetOrCreatePortMap (const SpaceIDNodeID &snid)

Private Attributes

PortCreateFunction mCreator
SpacePortMap mSpacePortMap
MessageHandler mDefaultHandler

Detailed Description

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.


Member Typedef Documentation

typedef std::tr1::unordered_map<PortID, DelegatePort*, PortID::Hasher> Sirikata::OHDP::DelegateService::PortMap [private]

Constructor & Destructor Documentation

Sirikata::OHDP::DelegateService::DelegateService ( PortCreateFunction  create_func)

Create a DelegateService that uses create_func to generate new ports.

Parameters:
create_funca 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]

Member Function Documentation

Port * Sirikata::OHDP::DelegateService::bindOHDPPort ( const SpaceID space,
const NodeID node,
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 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.

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 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.

Parameters:
srcsource endpoint
dstdestination endpoint
datathe payload of the message
Returns:
true if the message was handled, false otherwise.

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]
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.

Parameters:
cbthe 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]

Member Data Documentation

Referenced by bindOHDPPort().


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