Public Member Functions | Protected Member Functions

MessageListener Class Reference

MessageListener subclasses can post and receive Message objects. More...

Inherited by ActionBroadcaster::CallbackReceiver, ApplicationCommandTarget::CommandTargetMessageInvoker, and InterprocessConnection [private].

List of all members.

Public Member Functions

virtual ~MessageListener ()
 Destructor.
virtual void handleMessage (const Message &message)=0
 This is the callback method that receives incoming messages.
void postMessage (Message *message) const noexcept
 Sends a message to the message queue, for asynchronous delivery to this listener later on.
bool isValidMessageListener () const noexcept
 Checks whether this MessageListener has been deleted.

Protected Member Functions

 MessageListener () noexcept
 Creates a MessageListener.

Detailed Description

MessageListener subclasses can post and receive Message objects.

See also:
Message, MessageManager, ActionListener, ChangeListener

Constructor & Destructor Documentation

MessageListener::MessageListener (  ) [protected]

Creates a MessageListener.

virtual MessageListener::~MessageListener (  ) [virtual]

Destructor.

When a MessageListener is deleted, it removes itself from a global list of registered listeners, so that the isValidMessageListener() method will no longer return true.


Member Function Documentation

virtual void MessageListener::handleMessage ( const Message message ) [pure virtual]

This is the callback method that receives incoming messages.

This is called by the MessageManager from its dispatch loop.

See also:
postMessage
void MessageListener::postMessage ( Message message ) const

Sends a message to the message queue, for asynchronous delivery to this listener later on.

This method can be called safely by any thread.

Parameters:
messagethe message object to send - this will be deleted automatically by the message queue, so don't keep any references to it after calling this method.
See also:
handleMessage
bool MessageListener::isValidMessageListener (  ) const

Checks whether this MessageListener has been deleted.

Although not foolproof, this method is safe to call on dangling or null pointers. A list of active MessageListeners is kept internally, so this checks whether the object is on this list or not.

Note that it's possible to get a false-positive here, if an object is deleted and another is subsequently created that happens to be at the exact same memory location, but I can't think of a good way of avoiding this.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines