|
VR-Engage
2.3
|
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 |
|
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::setVreControlled(), makVre::startMapZoomIn(), makVre::startMapZoomOut(), makVre::stopMapZoomIn(), makVre::stopMapZoomOut(), makVre::subscribeToBoss(), makVre::takeControlOf(), makVre::unsubscribeFromBoss(), and makVre::DtVreGlstudioUpdater< UpdaterBase >::~DtVreGlstudioUpdater().
|
pure virtual |
Initialize the current thread as a tickable dispatch thread.
| isMainThread | Indicates 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.
|
pure virtual |
|
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.".
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().
|
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::setVreControlled(), makVre::startMapZoomIn(), makVre::startMapZoomOut(), makVre::stopMapZoomIn(), makVre::stopMapZoomOut(), makVre::subscribeToBoss(), makVre::takeControlOf(), and makVre::unsubscribeFromBoss().
|
pure virtual |
Like queueMessage, but immediately dispatches message to handlers on the current thread, if possible.
| msg | Pointer 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.
|
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.