VR-Engage  2.2
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 init ()=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 tick (double dt)=0
 
virtual void queueMessage (DtVreMessage *msg, double delay=0.0)=0
 
virtual void sendMessage (DtVreMessage *msg)=0
 
virtual DtVreMessageFactoryfactory ()=0
 
virtual const EventStatsstats ()=0
 

Static Public Member Functions

static DtVreMessageManagerinstance ()
 

Protected Member Functions

 DtVreMessageManager ()
 
virtual ~DtVreMessageManager ()
 

Static Protected Attributes

static DtVreMessageManagertheVreMessageManager
 
static DtVreMessageFactorytheMessageFactory
 

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()

◆ init()

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

Initializes the message manager.

This method must be called in the main thread to initialize the message manager. It identifies the main thread, which has special responsibilities in the messaging system, such as handling delayed messages.

Note
This function must be called from the main thread because the main thread performs some additional work in the messaging system.

◆ 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.".

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().

◆ tick()

virtual void makVre::DtVreMessageManager::tick ( 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::startMapZoomIn(), makVre::startMapZoomOut(), makVre::stopMapZoomIn(), makVre::stopMapZoomOut(), makVre::subscribeToBoss(), makVre::takeControlOf(), and makVre::unsubscribeFromBoss().

◆ sendMessage()

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

Immediately dispatches a message.

Parameters
msgPointer to the message to dispatch

This method immediately dispatches a message to all registered handlers that match its message type. The message is dispatched in the context of the calling thread.

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

◆ 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: