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

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>

Inheritance diagram for Sirikata::ODP::DelegateService:
Collaboration diagram for Sirikata::ODP::DelegateService:

List of all members.

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 PortbindODPPort (const SpaceID &space, const ObjectReference &objref, PortID port)
 Bind an ODP port for use.
virtual PortbindODPPort (const SpaceObjectReference &sor, PortID port)
virtual PortbindODPPort (const SpaceID &space, const ObjectReference &objref)
 Bind a random, unused ODP port for use.
virtual PortbindODPPort (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

PortMapgetPortMap (const SpaceObjectReference &sor) const
PortMapgetOrCreatePortMap (const SpaceObjectReference &sor)

Private Attributes

PortCreateFunction mCreator
SpacePortMap mSpacePortMap
MessageHandler mDefaultHandler

Detailed Description

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.


Member Typedef Documentation

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

Constructor & Destructor Documentation

Sirikata::ODP::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::ODP::DelegateService::~DelegateService ( ) [virtual]

Member Function Documentation

Port * Sirikata::ODP::DelegateService::bindODPPort ( const SpaceID space,
const ObjectReference objref,
PortID  port 
) [virtual]

Bind an ODP port for use.

Parameters:
spacethe Space to communicate via
objrefthe Object to communicate via
portthe PortID to attempt to bind
Returns:
an ODP 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::ODP::Service.

Referenced by Sirikata::HostedObject::bindODPPort(), and bindODPPort().

Port * Sirikata::ODP::DelegateService::bindODPPort ( const SpaceObjectReference sor,
PortID  port 
) [virtual]
Port * Sirikata::ODP::DelegateService::bindODPPort ( const SpaceObjectReference sor) [virtual]
Port * Sirikata::ODP::DelegateService::bindODPPort ( const SpaceID space,
const ObjectReference objref 
) [virtual]

Bind a random, unused ODP port for use.

Parameters:
spacethe Space to communicate via
Returns:
an ODP 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::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.

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

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


Member Data Documentation

Referenced by bindODPPort().


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