Nebula
|
#include <port.h>
A message port is a receiving point for messages.
Messages processed immediately and the port will be blocked until the message has been processed.
Messages are processed by message handlers which are attached to the port. More then one message handler can be attached to a port. When a message should be attached, each message handler is called in their attachment order until one of the handlers returns true, which means that the message has been handled.
For an asynchronous port implementation, which runs the message handlers in a separate thread, please check Message::AsyncPort.
Inherits Core::RefCounted.
Inherited by Messaging::Dispatcher.
Public Member Functions | |
virtual void | SetupAcceptedMessages () |
override to register accepted messages | |
void | AttachHandler (const Ptr< Handler > &h) |
attach a message handler to the port | |
void | RemoveHandler (const Ptr< Handler > &h) |
remove a message handler from the port | |
void | RemoveAllHandlers () |
remove all message handler from the port | |
SizeT | GetNumHandlers () const |
return number of handlers attached to the port | |
const Ptr< Handler > & | GetHandlerAtIndex (IndexT i) const |
get a message handler by index | |
virtual void | Send (const Ptr< Message > &msg) |
send a message to the port | |
const Util::Array< const Id * > & | GetAcceptedMessages () const |
get the array of accepted messages (sorted) | |
bool | AcceptsMessage (const Id &msgId) const |
return true if port accepts this msg | |
virtual void | HandleMessage (const Ptr< Messaging::Message > &msg) |
handle a single accepted message | |
Public Member Functions inherited from Core::RefCounted | |
RefCounted () | |
constructor | |
int | GetRefCount () const |
get the current refcount | |
void | AddRef () |
increment refcount by one | |
void | Release () |
decrement refcount and destroy object if refcount is zero | |
bool | IsInstanceOf (const Rtti &rtti) const |
return true if this object is instance of given class | |
bool | IsInstanceOf (const Util::String &className) const |
return true if this object is instance of given class by string | |
bool | IsInstanceOf (const Util::FourCC &classFourCC) const |
return true if this object is instance of given class by fourcc | |
bool | IsA (const Rtti &rtti) const |
return true if this object is instance of given class, or a derived class | |
bool | IsA (const Util::String &rttiName) const |
return true if this object is instance of given class, or a derived class, by string | |
bool | IsA (const Util::FourCC &rttiFourCC) const |
return true if this object is instance of given class, or a derived class, by fourcc | |
const Util::String & | GetClassName () const |
get the class name | |
Util::FourCC | GetClassFourCC () const |
get the class FourCC code | |
Protected Member Functions | |
void | RegisterMessage (const Id &msgId) |
register a single accepted message | |
Protected Member Functions inherited from Core::RefCounted | |
virtual | ~RefCounted () |
destructor (called when refcount reaches zero) | |
Private Member Functions | |
__DeclareClass (Port) | |
Private Attributes | |
Util::Array< Ptr< Handler > > | handlers |
Util::Array< const Id * > | acceptedMessageIds |
Additional Inherited Members | |
Static Public Member Functions inherited from Core::RefCounted | |
static void | DumpRefCountingLeaks () |
dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!) | |
|
private |
|
inline |
return true if port accepts this msg
attach a message handler to the port
Attach a message handler to the port.
|
inline |
get the array of accepted messages (sorted)
get a message handler by index
|
inline |
return number of handlers attached to the port
|
virtual |
handle a single accepted message
Handle a specific message.
Overwrite this method in a subclass. It is guaranteed that this method will only be called for messages which are accepted by AcceptMessage().
Reimplemented in Messaging::Dispatcher.
|
inlineprotected |
register a single accepted message
void Messaging::Port::RemoveAllHandlers | ( | ) |
remove all message handler from the port
remove a message handler from the port
Remove a message handler from the port.
send a message to the port
Send a message to the port.
This will immediately call the HandleMessage() method of all attached handlers. If the message has been handled by at least one of the handlers, the Handled() flag of the message will be set to true.
|
virtual |
override to register accepted messages
|
private |
|
private |