VR-Engage  2.3
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
20#include <map>
21#include <string>
22#include <vector>
23
24class DtSimMessage;
25
26namespace makVrv
27{
28class DtDe;
29}
30
31//! \brief Function pointer type for VREngage application status callbacks
32//! \param id The unique identifier of the VREngage application
33//! \param usr User-defined data pointer provided during callback registration
34using DtVreAppStatusCallbackFcn = void (*)(const std::string& id, void* usr);
35
36//! \brief Structure to track the status of a VREngage application
37//!
38//! Contains information about a VREngage application's identity, assigned entity,
39//! role, and operational status.
41{
42 //! \brief Station identity string for the VREngage application
43 //!
44 //! This is the station's name string (from --stationName or hostname) and
45 //! serves as its unique identifier. Must be unique across all VREngage
46 //! stations in an exercise and does not change over the application lifetime.
47 std::string myStationId;
48
49 //! \brief Name of the player using the VREngage application
50 //!
51 //! Optional identifier for the human user of the application.
52 std::string myPlayerName;
53
54 //! \brief UUID of the entity being controlled
55 //!
56 //! Identifies the entity currently controlled by this VREngage station.
57 //! May be a null UUID if no entity is currently controlled.
58 DtUUID myUUID;
59
60 //! \brief Engaged role name for the player
61 //!
62 //! The role the player has assumed at the VREngage station (defined in the
63 //! .entity file, e.g., "driver", "gunner", "commander"). Empty when the
64 //! station is connected but not engaged in a role.
65 std::string myRoleName;
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 = false;
71
72 //! \brief Timestamp of the last status update
73 //!
74 //! Used for timeout tracking of heartbeat messages.
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<std::string, 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(const std::string& id);
130
131 //! \brief Sets the timeout interval for heartbeating VREngage applications
132 //! \param timeoutInterval The timeout interval in seconds, 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 seconds, 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, const std::string& 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(const std::string& id);
216
217private:
218 //! \brief Copy construction is disabled.
220
221 //! \brief Copy assignment is disabled.
222 //! \return Reference to this object
224
225protected:
226 //! \brief Reference to the distributed environment
227 makVrv::DtDe& myDe;
228
229 //! \brief Map of all known VREngage applications
230 //!
231 //! Maps application IDs to their status structures.
233
234 //! \brief List of callbacks for application discovery
236
237 //! \brief List of callbacks for application removal
239
240 //! \brief List of callbacks for application status changes
242
243 //! \brief Timestamp of the last timeout check
245
246 //! \brief Timeout interval in seconds
247 //!
248 //! Applications that haven't sent a status update within this interval
249 //! will be considered inactive and removed. Set to -1 to disable timeouts.
250 //! Compared against DtAbsRealTime(), which is expressed in seconds.
252};
VreAppStatusMap myVreAppStatusMap
Map of all known VREngage applications.
Definition vreListener.h:232
VreAppStatusCallbackList myVreAppChangedCbList
List of callbacks for application status changes.
Definition vreListener.h:241
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:227
virtual void doTimeouts()
Processes timeouts for inactive applications.
DtTime myLastTimeoutCheck
Timestamp of the last timeout check.
Definition vreListener.h:244
VreAppStatusCallbackList myVreAppRemovedCbList
List of callbacks for application removal.
Definition vreListener.h:238
virtual void invokeCallbacks(const VreAppStatusCallbackList &cbList, const std::string &id) const
Invokes all callbacks in a callback list.
virtual void removeVreApplication(const std::string &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 seconds.
Definition vreListener.h:251
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)=delete
Copy construction is disabled.
virtual ~DtVreStatusListener()
Destructor.
VreAppStatusCallbackList myVreAppAddedCbList
List of callbacks for application discovery.
Definition vreListener.h:235
DtVreStatusListener & operator=(const DtVreStatusListener &orig)=delete
Copy assignment is disabled.
virtual VreAppStatus lookupVreApp(const std::string &id)
Looks up a VREngage application by ID.
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
Structure to track the status of a VREngage application.
Definition vreListener.h:41
DtTime myLastUpdateTime
Timestamp of the last status update.
Definition vreListener.h:75
std::string myRoleName
Engaged role name for the player.
Definition vreListener.h:65
DtUUID myUUID
UUID of the entity being controlled.
Definition vreListener.h:58
bool mySpectatorMode
Flag indicating whether player is in spectator mode.
Definition vreListener.h:70
std::string myStationId
Station identity string for the VREngage application.
Definition vreListener.h:47
std::string myPlayerName
Name of the player using the VREngage application.
Definition vreListener.h:52
std::map< std::string, VreAppStatus > VreAppStatusMap
Map of VREngage application IDs to status structures.
Definition vreListener.h:94
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
void(*)(const std::string &id, void *usr) DtVreAppStatusCallbackFcn
Function pointer type for VREngage application status callbacks.
Definition vreListener.h:34