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

#include <handlerthreadbase.h>

Detailed Description

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)
 

Constructor & Destructor Documentation

◆ HandlerThreadBase()

Messaging::HandlerThreadBase::HandlerThreadBase ( )

constructor

Member Function Documentation

◆ __DeclareClass()

Messaging::HandlerThreadBase::__DeclareClass ( HandlerThreadBase )
private

◆ AddMessage()

void Messaging::HandlerThreadBase::AddMessage ( const Ptr< Message > & msg)
virtual

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.

◆ AttachHandler()

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

attach a message handler

Attach a message handler to the port.

This method may be called from any thread.

◆ CancelMessage()

void Messaging::HandlerThreadBase::CancelMessage ( const Ptr< Message > & msg)
virtual

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.

◆ ClearHandlers()

void Messaging::HandlerThreadBase::ClearHandlers ( )

clear all attached message handlers

This clears all attached message handlers.

◆ RemoveHandler()

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

dynamically remove a message handler

Remove a message handler.

This method may be called form any thread.

◆ ThreadCloseHandlers()

void Messaging::HandlerThreadBase::ThreadCloseHandlers ( )
protected

close message handlers

Close attached message handlers.

This method must be called right before the handler thread shuts down.

◆ ThreadDiscardDeferredMessages()

void Messaging::HandlerThreadBase::ThreadDiscardDeferredMessages ( )
protected

clear leftover deferred messages

This clears any leftover deferred messages.

Call right before shutdown of the handler thread.

◆ ThreadHandleMessages()

bool Messaging::HandlerThreadBase::ThreadHandleMessages ( const Util::Array< Ptr< Message > > & msgArray)
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.

◆ ThreadHandleSingleMessage()

bool Messaging::HandlerThreadBase::ThreadHandleSingleMessage ( const Ptr< Message > & msg)
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.

◆ ThreadOpenHandlers()

void Messaging::HandlerThreadBase::ThreadOpenHandlers ( )
protected

open message handlers

Open attached message handlers.

This method must be called at the start of the handler thread.

◆ ThreadSignalMessageHandled()

void Messaging::HandlerThreadBase::ThreadSignalMessageHandled ( )
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!

◆ ThreadUpdateDeferredMessages()

bool Messaging::HandlerThreadBase::ThreadUpdateDeferredMessages ( )
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!

◆ ThreadUpdateHandlers()

void Messaging::HandlerThreadBase::ThreadUpdateHandlers ( )
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.

◆ WaitForHandlersOpened()

void Messaging::HandlerThreadBase::WaitForHandlersOpened ( )

wait until handlers have been opened

Wait on the handlers-opened event (will be signalled by the ThreadOpenHandlers method.

◆ WaitForMessage()

void Messaging::HandlerThreadBase::WaitForMessage ( const Ptr< Message > & msg)
virtual

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.

Member Data Documentation

◆ deferredMessages

Util::Array<Ptr<Message> > Messaging::HandlerThreadBase::deferredMessages
protected

◆ handlers

Util::Array<Ptr<Handler> > Messaging::HandlerThreadBase::handlers
protected

◆ handlersCritSect

Threading::CriticalSection Messaging::HandlerThreadBase::handlersCritSect
protected

◆ handlersOpenedEvent

Threading::Event Messaging::HandlerThreadBase::handlersOpenedEvent
protected

◆ msgHandledEvent

Threading::Event Messaging::HandlerThreadBase::msgHandledEvent
protected

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