Sirikata
Public Types | Public Member Functions
Sirikata::XDP::Port< EndpointType > Class Template Reference

ODP::Port is the interface for bound ports that allows sending and receiving ODP messages. More...

#include <Port.hpp>

List of all members.

Public Types

typedef EndpointType Endpoint
typedef Endpoint::MessageHandler MessageHandler

Public Member Functions

virtual ~Port ()
virtual const Endpointendpoint () const =0
 Get the endpoint associated with this port.
virtual bool send (const Endpoint &to, MemoryReference payload)=0
 Send an ODP message from this port.
void receive (const MessageHandler &cb)
 Register a default handler for messages received on this port.
virtual void receiveFrom (const Endpoint &from, const MessageHandler &cb)=0
 Register a handler for messages from the specified endpoint.

Detailed Description

template<typename EndpointType>
class Sirikata::XDP::Port< EndpointType >

ODP::Port is the interface for bound ports that allows sending and receiving ODP messages.

By default no listeners are bound and messages will bypass the Port and be received by any more generic listeners registered with the parent ODP::Service. To receive messages via this port, register a listener with receive() or receiveFrom(). Messages can only be sent via this port to endpoints in the same Space as this Port.

It is possible for multiple registered receive callbacks to be able to handle a message since the components of an endpoint support wildcards. For example, if handlers were registered for SpaceID X, ObjectReference Y, and one with PortID 1 and one with PortID::any(), both would be capable of handling a message to (X, Y, 1). Resolution of handlers is always from more-detailed to less-detailed, *with PortID being highest priority, followed by SpaceID, with ObjectReference being lowest priority*. This order is used because generally PortID's will be associated with a particular service or protocol, which is likely to function across multiple spaces and be indifferent to the object it is communicating with (for instance, a protocol which simply responds to requests for meshes). Therefore, handler resolution proceeds as follows for a message from endpoint (S, O, P):

  1. Check for handler for (S, O, P)
  2. Check for handler for (S, any, P)
  3. Check for handler for (any, any, P)
  4. Check for handler for (S, O, any)
  5. Check for handler for (S, any, any)
  6. Check for handler for (any, any, any) Note that combinations which have an object specified but not match any space are not checked. This combination generally doesn't make sense since an object reference won't be valid across spaces.

Once allocated, a Port is owned by the allocator: if the Service it was allocated from is destroyed, the user is responsible for not using the Port any more, and is always responsible for deleting the Port.


Member Typedef Documentation

template<typename EndpointType >
typedef EndpointType Sirikata::XDP::Port< EndpointType >::Endpoint
template<typename EndpointType >
typedef Endpoint::MessageHandler Sirikata::XDP::Port< EndpointType >::MessageHandler

Constructor & Destructor Documentation

template<typename EndpointType >
virtual Sirikata::XDP::Port< EndpointType >::~Port ( ) [inline, virtual]

Member Function Documentation

template<typename EndpointType >
virtual const Endpoint& Sirikata::XDP::Port< EndpointType >::endpoint ( ) const [pure virtual]

Get the endpoint associated with this port.

Note that this will always be a full and unique endpoint, i.e. none of its components will be their corresponding ANY sentinal values.

Referenced by Sirikata::TimeSyncClient::poll().

template<typename EndpointType >
void Sirikata::XDP::Port< EndpointType >::receive ( const MessageHandler cb) [inline]

Register a default handler for messages received on this port.

This is a utility method that is a shorthand for receiveFrom(Endpoint::any(), cb).

Parameters:
cbhandler to invoke when messages are receive

References Sirikata::XDP::Port< EndpointType >::receiveFrom().

Referenced by Sirikata::JS::EmersonScript::iOnConnected(), Sirikata::SST::BaseDatagramLayer< OHDP::SpaceNodeID >::listenOn(), Sirikata::SST::BaseDatagramLayer< SpaceObjectReference >::listenOn(), Sirikata::TimeSyncClient::TimeSyncClient(), and Sirikata::TimeSyncServer::TimeSyncServer().

template<typename EndpointType >
virtual void Sirikata::XDP::Port< EndpointType >::receiveFrom ( const Endpoint from,
const MessageHandler cb 
) [pure virtual]

Register a handler for messages from the specified endpoint.

Parameters:
fromendpoint to dispatch messages from
cbhandler to invoke when messages are received

Referenced by Sirikata::XDP::Port< EndpointType >::receive().

template<typename EndpointType >
virtual bool Sirikata::XDP::Port< EndpointType >::send ( const Endpoint to,
MemoryReference  payload 
) [pure virtual]

Send an ODP message from this port.

The destination endpoint *must* be unique and have the same SpaceID as this Port's endpoint.

Parameters:
tothe endpoint to send the message to
payloadthe message payload
Returns:
true if the message was accepted, false if the underlying networking layer couldn't immediately accept the message

Referenced by Sirikata::TimeSyncServer::handleMessage(), Sirikata::TimeSyncClient::poll(), Sirikata::SST::BaseDatagramLayer< OHDP::SpaceNodeID >::send(), and Sirikata::SST::BaseDatagramLayer< SpaceObjectReference >::send().


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