VR-Engage  2.2
Loading...
Searching...
No Matches
vreListener.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreListener.h
7//! \ingroup vreManager
8//! \brief VREngage status listener and message handler
9//!
10//! This file defines the DtVreStatusListener class and supporting structures,
11//! which track the status of VREngage applications in the simulation and
12//! provide callbacks for status changes.
13
14#pragma once
15
16#include "vreManager/export.h"
17#include <vrfutil/rwUUID.h>
18#include <vlpi/simulationAddress.h>
19
20class DtSimMessage;
21
22namespace makVrv
23{
24class DtDe;
25}
26
27//! \brief Function pointer type for VREngage application status callbacks
28//! \param id The unique identifier of the VREngage application
29//! \param usr User-defined data pointer provided during callback registration
30using DtVreAppStatusCallbackFcn = void (*)(unsigned long id, void* usr);
31
32//! \brief Structure to track the status of a VREngage application
33//!
34//! Contains information about a VREngage application's identity, assigned entity,
35//! role, and operational status.
37{
38 //! \brief Unique identifier for the VREngage application
39 //!
40 //! Must be unique across all VREngage stations in an exercise
41 //! and must not change over the lifetime of the application.
42 DtU64 myId;
43
44 //! \brief Name of the VREngage application
45 //!
46 //! Should be unique across all VREngage stations in an exercise.
47 //! Unlike the ID, the name may be changed during an exercise.
48 DtString myName;
49
50 //! \brief Name of the player using the VREngage application
51 //!
52 //! Optional identifier for the human user of the application.
53 DtString myPlayerName;
54
55 //! \brief UUID of the entity being controlled
56 //!
57 //! Identifies the entity currently controlled by this VREngage station.
58 //! May be empty if no entity is currently controlled.
59 DtString myUUID;
60
61 //! \brief Station/role name for the player
62 //!
63 //! The station name (role) assumed by the player at the VREngage station
64 //! (defined in the .entity file, e.g., "driver", "gunner", "commander").
65 DtString myStationName;
66
67 //! \brief Flag indicating whether player is in spectator mode
68 //!
69 //! When true, the player can observe but not interact with the entity.
70 bool mySpectatorMode;
71
72 //! \brief Timestamp of the last status update
73 //!
74 //! Used for timeout tracking of heartbeat messages.
75 DtTime myLastUpdateTime;
76};
77
78//! \brief Structure to store callback function and user data
79//!
80//! Used to maintain registered callbacks for VREngage application status changes.
82{
83 //! \brief The callback function
85
86 //! \brief User-defined data to pass to the callback
87 void* myUsrData;
88};
89
90//! \brief List of VREngage application status structures
91using VreAppStatusList = std::vector<VreAppStatus>;
92
93//! \brief Map of VREngage application IDs to status structures
94using VreAppStatusMap = std::map<unsigned long, VreAppStatus>;
95
96//! \brief List of callback information structures
97using VreAppStatusCallbackList = std::vector<DtCallbackInfo>;
98
99//! \brief Tracks the status of VREngage applications
100//!
101//! This class monitors VREngage application status messages, maintains current
102//! status information for all known VREngage applications, handles heartbeat
103//! timeouts, and provides callback notifications for status changes.
105{
106public:
107 //! \brief Constructor
108 //! \param de The distributed environment reference
109 //!
110 //! Initializes a new VREngage status listener with the specified distributed environment.
111 DtVreStatusListener(makVrv::DtDe& de);
112
113 //! \brief Destructor
114 //!
115 //! Cleans up resources used by the status listener.
117
118 //! \brief Gets the map of all known VREngage applications
119 //! \return Constant reference to the status map
120 //!
121 //! Returns a map of application IDs to status structures for all known VREngage applications.
122 virtual const VreAppStatusMap& vreAppStatusMap() const;
123
124 //! \brief Looks up a VREngage application by ID
125 //! \param id The unique identifier of the VREngage application
126 //! \return The status structure for the specified application
127 //!
128 //! Retrieves the status information for a specific VREngage application.
129 virtual VreAppStatus lookupVreApp(unsigned long id);
130
131 //! \brief Sets the timeout interval for heartbeating VREngage applications
132 //! \param timeoutInterval The timeout interval in milliseconds, or -1 to disable timeouts
133 //!
134 //! Sets the time interval after which an application is considered inactive
135 //! if no status updates have been received.
137
138 //! \brief Gets the current timeout interval
139 //! \return The timeout interval in milliseconds, or -1 if timeouts are disabled
140 //!
141 //! Returns the current timeout interval for heartbeating VREngage applications.
142 virtual int timeoutInterval();
143
144 //! \brief Processes timeouts for inactive applications
145 //!
146 //! Checks all status objects and deactivates any that have not sent
147 //! an update within the timeout interval. For each timed-out application,
148 //! the removed callbacks will be invoked.
149 virtual void doTimeouts();
150
151 //! \brief Processes a status message from a VREngage application
152 //! \param msg The simulation message containing status information
153 //!
154 //! Extracts status information from the message and updates the internal
155 //! status tracking. Invokes appropriate callbacks for new, changed, or
156 //! removed applications.
157 virtual void processStatusMessage(DtSimMessage* msg);
158
159 //! \brief Registers a callback for new VREngage application discovery
160 //! \param fcn The callback function to register
161 //! \param usrData User-defined data to pass to the callback
162 //!
163 //! Adds a callback that will be invoked when a new VREngage application is discovered.
164 virtual void addVreAppAddedCallback(DtVreAppStatusCallbackFcn fcn, void* usrData);
165
166 //! \brief Unregisters a callback for new VREngage application discovery
167 //! \param fcn The callback function to unregister
168 //! \param usrData User-defined data that was registered with the callback
169 //!
170 //! Removes a previously registered callback for new application discovery.
171 virtual void removeVreAppAddedCallback(DtVreAppStatusCallbackFcn fcn, void* usrData);
172
173 //! \brief Registers a callback for VREngage application removal
174 //! \param fcn The callback function to register
175 //! \param usrData User-defined data to pass to the callback
176 //!
177 //! Adds a callback that will be invoked when a VREngage application is removed
178 //! or times out.
179 virtual void addVreAppRemovedCallback(DtVreAppStatusCallbackFcn fcn, void* usrData);
180
181 //! \brief Unregisters a callback for VREngage application removal
182 //! \param fcn The callback function to unregister
183 //! \param usrData User-defined data that was registered with the callback
184 //!
185 //! Removes a previously registered callback for application removal.
187
188 //! \brief Registers a callback for VREngage application status changes
189 //! \param fcn The callback function to register
190 //! \param usrData User-defined data to pass to the callback
191 //!
192 //! Adds a callback that will be invoked when a VREngage application's status changes
193 //! (e.g., entity assignment, role change, spectator mode toggle).
194 virtual void addVreAppChangedCallback(DtVreAppStatusCallbackFcn fcn, void* usrData);
195
196 //! \brief Unregisters a callback for VREngage application status changes
197 //! \param fcn The callback function to unregister
198 //! \param usrData User-defined data that was registered with the callback
199 //!
200 //! Removes a previously registered callback for application status changes.
202
203protected:
204 //! \brief Invokes all callbacks in a callback list
205 //! \param cbList The list of callbacks to invoke
206 //! \param id The ID of the VREngage application related to the callback
207 //!
208 //! Helper method to invoke all callbacks in a list with the specified application ID.
209 virtual void invokeCallbacks(const VreAppStatusCallbackList& cbList, unsigned long id) const;
210
211 //! \brief Removes a VREngage application from tracking
212 //! \param id The ID of the VREngage application to remove
213 //!
214 //! Removes an application from the status map and invokes removed callbacks.
215 virtual void removeVreApplication(unsigned long id);
216
217private:
218 //! \brief Copy constructor (not implemented)
219 //! \param orig The source object
221
222 //! \brief Assignment operator (not implemented)
223 //! \param orig The source object
224 //! \return Reference to this object
226
227protected:
228 //! \brief Reference to the distributed environment
229 makVrv::DtDe& myDe;
230
231 //! \brief Map of all known VREngage applications
232 //!
233 //! Maps application IDs to their status structures.
235
236 //! \brief List of callbacks for application discovery
238
239 //! \brief List of callbacks for application removal
241
242 //! \brief List of callbacks for application status changes
244
245 //! \brief Timestamp of the last timeout check
247
248 //! \brief Timeout interval in milliseconds
249 //!
250 //! Applications that haven't sent a status update within this interval
251 //! will be considered inactive and removed. Set to -1 to disable timeouts.
253};
VreAppStatusMap myVreAppStatusMap
Map of all known VREngage applications.
Definition vreListener.h:234
VreAppStatusCallbackList myVreAppChangedCbList
List of callbacks for application status changes.
Definition vreListener.h:243
virtual void invokeCallbacks(const VreAppStatusCallbackList &cbList, unsigned long id) const
Invokes all callbacks in a callback list.
virtual void removeVreAppChangedCallback(DtVreAppStatusCallbackFcn fcn, void *usrData)
Unregisters a callback for VREngage application status changes.
virtual void removeVreAppRemovedCallback(DtVreAppStatusCallbackFcn fcn, void *usrData)
Unregisters a callback for VREngage application removal.
virtual void removeVreAppAddedCallback(DtVreAppStatusCallbackFcn fcn, void *usrData)
Unregisters a callback for new VREngage application discovery.
virtual void setTimeoutInterval(int timeoutInterval)
Sets the timeout interval for heartbeating VREngage applications.
makVrv::DtDe & myDe
Reference to the distributed environment.
Definition vreListener.h:229
virtual void doTimeouts()
Processes timeouts for inactive applications.
DtTime myLastTimeoutCheck
Timestamp of the last timeout check.
Definition vreListener.h:246
VreAppStatusCallbackList myVreAppRemovedCbList
List of callbacks for application removal.
Definition vreListener.h:240
virtual void removeVreApplication(unsigned long id)
Removes a VREngage application from tracking.
virtual void addVreAppRemovedCallback(DtVreAppStatusCallbackFcn fcn, void *usrData)
Registers a callback for VREngage application removal.
virtual void addVreAppChangedCallback(DtVreAppStatusCallbackFcn fcn, void *usrData)
Registers a callback for VREngage application status changes.
int myTimeoutInterval
Timeout interval in milliseconds.
Definition vreListener.h:252
DtVreStatusListener & operator=(const DtVreStatusListener &orig)
Assignment operator (not implemented)
virtual VreAppStatus lookupVreApp(unsigned long id)
Looks up a VREngage application by ID.
virtual void processStatusMessage(DtSimMessage *msg)
Processes a status message from a VREngage application.
virtual void addVreAppAddedCallback(DtVreAppStatusCallbackFcn fcn, void *usrData)
Registers a callback for new VREngage application discovery.
virtual int timeoutInterval()
Gets the current timeout interval.
DtVreStatusListener(const DtVreStatusListener &orig)
Copy constructor (not implemented)
virtual ~DtVreStatusListener()
Destructor.
VreAppStatusCallbackList myVreAppAddedCbList
List of callbacks for application discovery.
Definition vreListener.h:237
virtual const VreAppStatusMap & vreAppStatusMap() const
Gets the map of all known VREngage applications.
DtVreStatusListener(makVrv::DtDe &de)
Constructor.
Export macros for the VREngage Manager library.
#define VREMANAGER_DLL
Platform-specific export/import macro for VREngage Manager library.
Definition export.h:28
Definition appLauncherComponent.h:28
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.
Structure to store callback function and user data.
Definition vreListener.h:82
DtVreAppStatusCallbackFcn myFcn
The callback function.
Definition vreListener.h:84
void * myUsrData
User-defined data to pass to the callback.
Definition vreListener.h:87
void(*)(unsigned long id, void *usr) DtVreAppStatusCallbackFcn
Function pointer type for VREngage application status callbacks.
Definition vreListener.h:30
struct VreAppStatus { DtU64 myId; DtString myName; DtString myPlayerName; DtString myUUID; DtString myStationName; bool mySpectatorMode; DtTime myLastUpdateTime;} VreAppStatus
Structure to track the status of a VREngage application.
Definition vreListener.h:36
std::vector< DtCallbackInfo > VreAppStatusCallbackList
List of callback information structures.
Definition vreListener.h:97
std::vector< VreAppStatus > VreAppStatusList
List of VREngage application status structures.
Definition vreListener.h:91
std::map< unsigned long, VreAppStatus > VreAppStatusMap
Map of VREngage application IDs to status structures.
Definition vreListener.h:94