VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtVreMessageManager Class Referenceabstract

Detailed Description

This abstract base class defines the interface for the message manager, which serves as the central hub for message routing and dispatching in the VREngage system. It provides thread-safe mechanisms for registering message handlers, queuing messages, and dispatching messages to appropriate handlers.

The message manager uses a hierarchical message listener tree to efficiently route messages to the appropriate handlers based on their message types, and supports both immediate message dispatch and delayed message queuing.

The system is implemented as a singleton, with a concrete implementation (DtTbbVreMessageManager) that uses Intel TBB concurrent containers for thread-safe message queuing across multiple threads.

#include <vreMessageManager.h>

Classes

struct  EventStats
 

Public Types

enum class  HandlerPosition { FRONT = 0 , BACK }
 

Public Member Functions

virtual void initDispatchThread (bool isMainThread=false)=0
 
virtual void shutdownDispatchThread ()=0
 
virtual void addHandler (const std::string &messageType, const DtVreMessageDelegate &handler, HandlerPosition handlerPos=HandlerPosition::BACK)=0
 
virtual void removeHandler (const std::string &messageType, const DtVreMessageDelegate &handler)=0
 
virtual void dispatchTick (double dt)=0
 
virtual void queueMessage (DtVreMessage *msg, double delay=0.0)=0
 
virtual void sendMessageAsap (DtVreMessage *msg)=0
 
virtual DtVreMessageFactory & factory ()=0
 
virtual const EventStats & stats ()=0
 

Static Public Member Functions

static DtVreMessageManager & instance ()
 

Protected Member Functions

 DtVreMessageManager ()
 
virtual ~DtVreMessageManager ()
 

Static Protected Attributes

static DtVreMessageManager * theVreMessageManager
 
static DtVreMessageFactory * theMessageFactory
 

Member Enumeration Documentation

◆ HandlerPosition

Position for adding a message handler in the handler list.

This enumeration defines the possible positions for adding a message handler in the handler list for a specific message type. The position affects the order in which handlers are called when a message is dispatched.

Enumerator
FRONT 

Add the handler at the front of the list (called first)

BACK 

Add the handler at the back of the list (called last)

Constructor & Destructor Documentation

◆ DtVreMessageManager()

makVre::DtVreMessageManager::DtVreMessageManager ( )
protected

Protected constructor.

This constructor is protected to enforce the singleton pattern. It creates a new message factory and initializes member variables.

Referenced by instance().

◆ ~DtVreMessageManager()

virtual makVre::DtVreMessageManager::~DtVreMessageManager ( )
protectedvirtual

Virtual destructor.

Ensures proper cleanup of derived classes.

Member Function Documentation

◆ instance()

◆ initDispatchThread()

virtual void makVre::DtVreMessageManager::initDispatchThread ( bool isMainThread = false)
pure virtual

Initialize the current thread as a tickable dispatch thread.

Parameters
isMainThreadIndicates if the current thread is the main thread

This method registers the current thread as a tickable dispatch thread, allowing it to process messages. All registered threads are expected to call dispatchTick() in their thread loop to process and dispatch messages for that thread.

The main app thread should init with isMainThread = true. The main thread serves as the default fallback for handlers added from unregistered threads.

Message handlers are assigned to the thread from which addHandler is called, as long as that thread is a registed dispatch thread. Any handlers added from an unregistered thread will be assigned to the main thread instead.

Dispatch threads should call shutdownDispatchThread() before exiting.

◆ shutdownDispatchThread()

virtual void makVre::DtVreMessageManager::shutdownDispatchThread ( )
pure virtual

◆ addHandler()

virtual void makVre::DtVreMessageManager::addHandler ( const std::string & messageType,
const DtVreMessageDelegate & handler,
HandlerPosition handlerPos = HandlerPosition::BACK )
pure virtual

Registers a message handler for a specific message type.

Parameters
messageTypeType of messages to handle (can include wildcards)
handlerDelegate to the handler function
handlerPosPosition to add the handler (FRONT or BACK)

This method registers a handler function for a specific message type. When a message of the specified type is dispatched, the handler function will be called with the message as its parameter. The position parameter determines whether the handler is added to the front or back of the handler list, affecting its execution order relative to other handlers for the same message type.

The message type can include wildcards ("*") to match multiple message types. For example, "entity.*" would match all message types that start with "entity.".

Handlers are assigned to the dispatch thread from which this method is called, provided that thread is registered as a dispatch thread. If this method is called from an unregisted thread, the handler will be assigned to the main thread for dispatch instead.

References BACK.

Referenced by makVre::DtVreGlstudioUpdater< UpdaterBase >::init().

◆ removeHandler()

virtual void makVre::DtVreMessageManager::removeHandler ( const std::string & messageType,
const DtVreMessageDelegate & handler )
pure virtual

Unregisters a message handler for a specific message type.

Parameters
messageTypeType of messages the handler was registered for
handlerDelegate to the handler function to remove

This method removes a previously registered handler function for a specific message type. After removal, the handler will no longer be called when messages of the specified type are dispatched.

Referenced by makVre::DtVreGlstudioUpdater< UpdaterBase >::~DtVreGlstudioUpdater().

◆ dispatchTick()

virtual void makVre::DtVreMessageManager::dispatchTick ( double dt)
pure virtual

Processes queued messages for the current thread.

Parameters
dtDelta time in seconds since the last tick

This method processes all queued messages for the current thread, dispatching them to registered handlers. It also updates the timers for delayed messages, making them available for dispatch when their delay time has elapsed.

Note
Each thread that participates in the messaging system must call this method in its thread loop to process messages targeted for that thread.

◆ queueMessage()

virtual void makVre::DtVreMessageManager::queueMessage ( DtVreMessage * msg,
double delay = 0.0 )
pure virtual

Queues a message for later dispatch.

Parameters
msgPointer to the message to queue
delayDelay in seconds before the message is dispatched

This method queues a message for later dispatch. If a delay is specified, the message will not be dispatched until the delay time has elapsed. The message will be dispatched the next time tick() is called after the delay has elapsed.

Note
The message manager takes ownership of the message and will delete it when it is no longer needed.

Referenced by makVre::createGimbalView(), makVre::createPlanView(), makVre::cycleGimbalView(), makVre::destroyGimbalView(), makVre::destroyPlanView(), makVre::lowerGate(), makVre::modifyGimbalView(), makVre::playRwrSound(), makVre::raiseGate(), makVre::releaseControlOf(), makVre::requestGlsConfig(), makVre::requestSimState(), makVre::restoreOverlaySections(), makVre::sendCockpitInitialized(), makVre::sendJoystickMessage(), makVre::sendSarRequest(), makVre::sendSetRwrEnabledMessage(), makVre::setLightState(), makVre::setOverlaySections(), makVre::setRadarModeAndSubmode(), makVre::setRwrSoundsEnabled(), makVre::setVreControlled(), makVre::startMapZoomIn(), makVre::startMapZoomOut(), makVre::stopMapZoomIn(), makVre::stopMapZoomOut(), makVre::subscribeToBoss(), makVre::takeControlOf(), and makVre::unsubscribeFromBoss().

◆ sendMessageAsap()

virtual void makVre::DtVreMessageManager::sendMessageAsap ( DtVreMessage * msg)
pure virtual

Like queueMessage, but immediately dispatches message to handlers on the current thread, if possible.

Parameters
msgPointer to the message to dispatch

Message will be dispatchd immediately for handlers on the current thread, if the current thread is registered as a dispatch thread. In all other cases and for all other threads the message will be queued for dispatch on the next thread tick, as if queueMessage were called.

◆ factory()

virtual DtVreMessageFactory & makVre::DtVreMessageManager::factory ( )
pure virtual

Gets the message factory associated with this message manager.

Returns
Reference to the message factory

This method returns a reference to the message factory associated with this message manager. The factory is used to create messages from serialized data and to register message types.

◆ stats()

virtual const EventStats & makVre::DtVreMessageManager::stats ( )
pure virtual

Gets the event statistics for the current thread.

Returns
Reference to the event statistics structure

This method returns a reference to the event statistics structure for the current thread. The statistics include the number of messages dispatched in the current frame and the types of messages that were dispatched.

Member Data Documentation

◆ theVreMessageManager

DtVreMessageManager* makVre::DtVreMessageManager::theVreMessageManager
staticprotected

Singleton instance of the message manager.

This static pointer holds the singleton instance of the message manager. It is initialized by the constructor and accessed through the instance() method.

◆ theMessageFactory

DtVreMessageFactory* makVre::DtVreMessageManager::theMessageFactory
staticprotected

Message factory for creating messages.

This static pointer holds the message factory associated with the message manager. It is initialized by the constructor and accessed through the factory() method.


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