|
VR-Engage
2.2
|
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 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 |
|
strong |
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) |
|
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().
|
protectedvirtual |
Virtual destructor.
Ensures proper cleanup of derived classes.
|
static |
Gets the singleton instance of the message manager.
This static method returns a reference to the singleton instance of the message manager. If the instance doesn't exist yet, it creates a new one.
References DtVreMessageManager().
Referenced by makVre::createGimbalView(), makVre::createPlanView(), makVre::cycleGimbalView(), makVre::destroyGimbalView(), makVre::destroyPlanView(), makVre::DtVreGlstudioUpdater< UpdaterBase >::init(), 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(), makVre::unsubscribeFromBoss(), and makVre::DtVreGlstudioUpdater< UpdaterBase >::~DtVreGlstudioUpdater().
|
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.
|
pure virtual |
Registers a message handler for a specific message type.
| messageType | Type of messages to handle (can include wildcards) |
| handler | Delegate to the handler function |
| handlerPos | Position 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().
|
pure virtual |
Unregisters a message handler for a specific message type.
| messageType | Type of messages the handler was registered for |
| handler | Delegate 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().
|
pure virtual |
Processes queued messages for the current thread.
| dt | Delta 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.
|
pure virtual |
Queues a message for later dispatch.
| msg | Pointer to the message to queue |
| delay | Delay 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.
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().
|
pure virtual |
Immediately dispatches a message.
| msg | Pointer 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.
|
pure virtual |
Gets the message factory associated with this message manager.
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.
|
pure virtual |
Gets the event statistics for the current thread.
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.
|
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.
|
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.