Sirikata
|
ODP::Port is the interface for bound ports that allows sending and receiving ODP messages. More...
#include <Port.hpp>
Public Types | |
typedef EndpointType | Endpoint |
typedef Endpoint::MessageHandler | MessageHandler |
Public Member Functions | |
virtual | ~Port () |
virtual const Endpoint & | endpoint () 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. |
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):
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.
typedef EndpointType Sirikata::XDP::Port< EndpointType >::Endpoint |
typedef Endpoint::MessageHandler Sirikata::XDP::Port< EndpointType >::MessageHandler |
virtual Sirikata::XDP::Port< EndpointType >::~Port | ( | ) | [inline, virtual] |
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().
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).
cb | handler 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().
virtual void Sirikata::XDP::Port< EndpointType >::receiveFrom | ( | const Endpoint & | from, |
const MessageHandler & | cb | ||
) | [pure virtual] |
Register a handler for messages from the specified endpoint.
from | endpoint to dispatch messages from |
cb | handler to invoke when messages are received |
Referenced by Sirikata::XDP::Port< EndpointType >::receive().
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.
to | the endpoint to send the message to |
payload | the message payload |
Referenced by Sirikata::TimeSyncServer::handleMessage(), Sirikata::TimeSyncClient::poll(), Sirikata::SST::BaseDatagramLayer< OHDP::SpaceNodeID >::send(), and Sirikata::SST::BaseDatagramLayer< SpaceObjectReference >::send().