Nebula
|
#include <handlerthreadbase.h>
Base class for AsyncPort message handler thread classes.
Inherits Thread.
Inherited by Messaging::BlockingHandlerThread, and Messaging::RunThroughHandlerThread.
Public Member Functions | |
HandlerThreadBase () | |
constructor | |
void | AttachHandler (const Ptr< Handler > &h) |
attach a message handler | |
void | RemoveHandler (const Ptr< Handler > &h) |
dynamically remove a message handler | |
void | ClearHandlers () |
clear all attached message handlers | |
void | WaitForHandlersOpened () |
wait until handlers have been opened | |
virtual void | AddMessage (const Ptr< Message > &msg) |
add a message to be handled (override in subclass!) | |
virtual void | CancelMessage (const Ptr< Message > &msg) |
cancel a pending message (override in subclass!) | |
virtual void | WaitForMessage (const Ptr< Message > &msg) |
wait for message to be handled (optionally override in subclass!) | |
Protected Member Functions | |
void | ThreadOpenHandlers () |
open message handlers | |
void | ThreadCloseHandlers () |
close message handlers | |
void | ThreadUpdateHandlers () |
open dynamically added handlers, and call DoWork() on all attached handlers | |
bool | ThreadUpdateDeferredMessages () |
update deferred messages, return true if at least one message has been handled | |
void | ThreadDiscardDeferredMessages () |
clear leftover deferred messages | |
bool | ThreadHandleMessages (const Util::Array< Ptr< Message > > &msgArray) |
handle messages in array, return true if at least one message has been handled | |
bool | ThreadHandleSingleMessage (const Ptr< Message > &msg) |
handle a single message without deferred support, return if message has been handled | |
void | ThreadSignalMessageHandled () |
signal message handled event (only call if at least one message has been handled) | |
Protected Attributes | |
Threading::Event | msgHandledEvent |
Threading::Event | handlersOpenedEvent |
Threading::CriticalSection | handlersCritSect |
Util::Array< Ptr< Handler > > | handlers |
Util::Array< Ptr< Message > > | deferredMessages |
Private Member Functions | |
__DeclareClass (HandlerThreadBase) | |
Messaging::HandlerThreadBase::HandlerThreadBase | ( | ) |
constructor
|
private |
add a message to be handled (override in subclass!)
This adds a new message to the thread's message queue.
In the base class this message is empty and must be implemented in a subclass.
Reimplemented in Messaging::BlockingHandlerThread, and Messaging::RunThroughHandlerThread.
attach a message handler
Attach a message handler to the port.
This method may be called from any thread.
cancel a pending message (override in subclass!)
This removes a message from the thread's message queue, regardless of its state.
Override this method in a subclass.
Reimplemented in Messaging::BlockingHandlerThread, and Messaging::RunThroughHandlerThread.
void Messaging::HandlerThreadBase::ClearHandlers | ( | ) |
clear all attached message handlers
This clears all attached message handlers.
dynamically remove a message handler
Remove a message handler.
This method may be called form any thread.
|
protected |
close message handlers
Close attached message handlers.
This method must be called right before the handler thread shuts down.
|
protected |
clear leftover deferred messages
This clears any leftover deferred messages.
Call right before shutdown of the handler thread.
|
protected |
handle messages in array, return true if at least one message has been handled
Handle all message in the provided message array.
Supports batched and deferred messages. Calls ThreadHandleSingleMessage(). If at least one message has been handled, the method returns true.
|
protected |
handle a single message without deferred support, return if message has been handled
Handle a single message, called by ThreadHandleMessages().
Return true if message has been handled. This method MUST be called from ThreadHandleMessages(), since this method will not explicitely take the handlers array critical section.
|
protected |
open message handlers
Open attached message handlers.
This method must be called at the start of the handler thread.
|
protected |
signal message handled event (only call if at least one message has been handled)
Signal the message-handled flag.
Call this method once per handler-loop if either ThreadUpdateDeferredMessages or ThreadHandleMessages returns true!
|
protected |
update deferred messages, return true if at least one message has been handled
This checks every message in the deferred message array whether it has been handled yet, if yes, the message's actual handled flag will be set, and the message will be removed from the deferred handled array.
If at least one message has been handled, the method will return true, if no message has been handled, the method returns false. If message have been handled, don't forget to call ThreadSignalMessageHandled() later!
|
protected |
open dynamically added handlers, and call DoWork() on all attached handlers
Do per-frame update of attached handlers.
This will open handlers which have been added late, and call the DoWork() method on handlers from within the thread context.
void Messaging::HandlerThreadBase::WaitForHandlersOpened | ( | ) |
wait until handlers have been opened
Wait on the handlers-opened event (will be signalled by the ThreadOpenHandlers method.
wait for message to be handled (optionally override in subclass!)
This waits until the message given as argument has been handled.
In order for this message to work, the ThreadSignalMessageHandled() must be called from within the handler thread context. Note that subclasses may override this method if they need to.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |