Nebula
Loading...
Searching...
No Matches
Messaging::Port Class Reference

#include <port.h>

Detailed Description

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::StringGetClassName () 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!)
 

Member Function Documentation

◆ __DeclareClass()

Messaging::Port::__DeclareClass ( Port )
private

◆ AcceptsMessage()

bool Messaging::Port::AcceptsMessage ( const Id & msgId) const
inline

return true if port accepts this msg

◆ AttachHandler()

void Messaging::Port::AttachHandler ( const Ptr< Handler > & h)

attach a message handler to the port

Attach a message handler to the port.

◆ GetAcceptedMessages()

const Util::Array< const Id * > & Messaging::Port::GetAcceptedMessages ( ) const
inline

get the array of accepted messages (sorted)

◆ GetHandlerAtIndex()

const Ptr< Handler > & Messaging::Port::GetHandlerAtIndex ( IndexT i) const
inline

get a message handler by index

◆ GetNumHandlers()

SizeT Messaging::Port::GetNumHandlers ( ) const
inline

return number of handlers attached to the port

◆ HandleMessage()

void Messaging::Port::HandleMessage ( const Ptr< Messaging::Message > & msg)
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.

◆ RegisterMessage()

void Messaging::Port::RegisterMessage ( const Id & msgId)
inlineprotected

register a single accepted message

◆ RemoveAllHandlers()

void Messaging::Port::RemoveAllHandlers ( )

remove all message handler from the port

◆ RemoveHandler()

void Messaging::Port::RemoveHandler ( const Ptr< Handler > & h)

remove a message handler from the port

Remove a message handler from the port.

◆ Send()

void Messaging::Port::Send ( const Ptr< Message > & msg)
virtual

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.

Todo
should we stop here, once the message had been handled...?

◆ SetupAcceptedMessages()

void Messaging::Port::SetupAcceptedMessages ( )
virtual

override to register accepted messages

Member Data Documentation

◆ acceptedMessageIds

Util::Array<const Id*> Messaging::Port::acceptedMessageIds
private

◆ handlers

Util::Array<Ptr<Handler> > Messaging::Port::handlers
private

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