Meta::MMessageHandler Class Reference

Message handler that responds to messages received from a message buffer. More...

#include <MMessageHandler.h>

List of all members.

Public Types

enum  Action { ReleaseContinue, SaveContinue, SaveStop, ReleaseStop }

Public Member Functions

 MMessageHandler ()
virtual ~MMessageHandler ()
void addBuffer (MMessageBuffer *buf)
void removeBuffer (MMessageBuffer *buf, bool all=true)
void clearBuffers ()
void setStartIndex (const mnum &index)
void setEndIndex (const mnum &index)
const mnumstartIndex () const
const mnumendIndex () const
bool await (MMessageBuffer *buf)
bool await (MMessageBuffer *buf, const mtime &timeout)
void interrupt ()
void setAllowInterrupt (bool flag)
bool allowInterrupt ()
void handleMessages ()
virtual Action handleMessage (const MMessage *msg)=0

Friends

class MMessageHandler_

Detailed Description

Message handler that responds to messages received from a message buffer.

Message handlers process messages queued for them at a message buffer. This class provides a way to specify the the means by which a handler responds to a message. Of course the actions a message handler takes given a message is application specific, but as far as the buffer is concerned, the message is either released or saved for later presentation to the handler. Message handlers may block, optionally with a timeout, until a message arrives at the designated buffer. If it is allowed by the handler, the handler may be interrupted from awaiting a message, however the default behavior is not to allow interruptions. MMessageHandler is fully thread-safe.


Member Enumeration Documentation

Actions returned by handleMessage().


Constructor & Destructor Documentation

Meta::MMessageHandler::MMessageHandler (  ) 

Constructor.

virtual Meta::MMessageHandler::~MMessageHandler (  )  [virtual]

Destructor.


Member Function Documentation

void Meta::MMessageHandler::addBuffer ( MMessageBuffer buf  ) 

Subscribe to a message buffer.

bool Meta::MMessageHandler::allowInterrupt (  ) 

Get whether to allow interrupts.

bool Meta::MMessageHandler::await ( MMessageBuffer buf,
const mtime timeout 
)

Block with timeout until a message is delivered to the designated message buffer. Note: handleMessages() must then be called to respond to the newly received message(s).

Returns:
true on success, fails if interrupted or timed out.
bool Meta::MMessageHandler::await ( MMessageBuffer buf  ) 

Wait for a message to be delivered to message buffer for this handler's response. Note: handleMessages() must then be called.

Returns:
true on success, fails if interrupted.
void Meta::MMessageHandler::clearBuffers (  ) 

Unsubscribe from all buffers.

const mnum& Meta::MMessageHandler::endIndex (  )  const

Get the ending index of messages presented to the handler in handleMessages().

virtual Action Meta::MMessageHandler::handleMessage ( const MMessage msg  )  [pure virtual]

Reimplement to provide application-specific responses to a messages.

Returns:
An action: ReleaseContinue, SaveContinue, SaveStop, or ReleaseStop. Releasing a message will instruct the buffer not present this message again, while saving it, saves it for a subsequent call to handleMessages(). Stop halts the presentation of messages in this handleMessages() session.
void Meta::MMessageHandler::handleMessages (  ) 

Begin handling messages if any. Messages are successively presented to the handler by calling handleMessage().

void Meta::MMessageHandler::interrupt (  ) 

Interrupt this handler. A no-op if interrupts are not allowed.

void Meta::MMessageHandler::removeBuffer ( MMessageBuffer buf,
bool  all = true 
)

Unsubscribe from a message buffer. A count keep tracks of the number of times the buffer was added, if 'all' is true the buffer is removed regardless of the number of times it was added, else the count is decremented and removed when 0 is reached.

void Meta::MMessageHandler::setAllowInterrupt ( bool  flag  ) 

Set whether to allow interrupts.

void Meta::MMessageHandler::setEndIndex ( const mnum index  ) 

Set the ending index of messages presented to the handler in handleMessages().

void Meta::MMessageHandler::setStartIndex ( const mnum index  ) 

Set the starting index of messages presented to the handler in handleMessages().

const mnum& Meta::MMessageHandler::startIndex (  )  const

Get the starting index of messages presented to the handler in handleMessages().


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

Generated on Wed Mar 24 16:22:42 2010 for AndroMeta by  doxygen 1.6.1