VR-Engage  2.3
Loading...
Searching...
No Matches
sessionStatusConnector.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file sessionStatusConnector.h
7//! \brief Defines the DtSessionStatusConnector class for VRF session management
8//!
9//! This connector handles VRF session status queries, simulation model set (SMS)
10//! management, session play state, simulation control (run/pause/rewind), and
11//! station identity/role assignment messaging between the VR-Engage frontend and
12//! the VR-Forces backend.
13//!
14//! It receives shared infrastructure from DtConnectorAccessory and does not own
15//! any infrastructure components.
16
17#pragma once
18
21
23
26
27#include <vlutil/vlTime.h>
28
29#include <set>
30#include <string>
31
32//! \brief Forward declaration of the simulation message class
33class DtSimMessage;
34
35namespace makVrf
36{
37//! \brief Forward declaration of the VRF remote controller class
38class DtVrlinkVrfRemoteController;
39} // namespace makVrf
40
41namespace makVre
42{
43
44//! \brief Connector for VRF session status and simulation control
45//!
46//! DtSessionStatusConnector manages VRF session status queries, simulation model
47//! set (SMS) lists, session play state, simulation control commands (run/pause/rewind),
48//! station identity publication to the VRF backend, and role assignment messages
49//! received from the VRF backend.
50//!
51//! This connector receives shared infrastructure from DtConnectorAccessory via
52//! \c install() and does not own any infrastructure components. It communicates
53//! with the VRF backend through the shared \c DtVrlinkVrfRemoteController and
54//! its associated VRF message interface.
55//!
56//! \ingroup vrePlayerStationConnector
58{
59public:
60 //! \brief Default constructor
61 //!
62 //! Computes a stable unique station identifier (myId) from the station name
63 //! (or hostname) and process ID, matching the identity used in VRE status
64 //! messages sent to the VRF backend.
66
67 //! \brief Virtual destructor
68 virtual ~DtSessionStatusConnector() override = default;
69
70 //! \brief Installs the session status connector with shared infrastructure
71 //!
72 //! \param connection Non-owning pointer to the protocol-specific VR-Link connection.
73 //! \param vrfRemoteController Non-owning pointer to the shared VRF remote controller
74 //! owned by DtConnectorAccessory.
75 //!
76 //! Stores the non-owning infrastructure pointer and registers:
77 //! - VRE message handlers for session status, SMS list, play state, and simulation control
78 //! - VRF message factory creators for VRE status, role assignment, and role unassignment types
79 //! - VRF message callbacks for the same types (inbound from the VRF backend)
80 //!
81 //! Also binds handles from the global App attribute tree and locks write-protected handles
82 //! (mySessionStatusAttr, mySessionPlayStateAttr) to prevent unintended writes from
83 //! other connectors. These handles are read-only for this connector.
84 virtual void install(
85 makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* connection,
86 makVrf::DtVrlinkVrfRemoteController* vrfRemoteController);
87
88 //! \brief Performs periodic session status evaluation
89 //!
90 //! Calls updateSessionStatus() each tick to detect backend/session changes
91 //! and broadcast updates to the frontend.
92 //!
93 //! \param dt The elapsed time in seconds since the last tick
94 virtual void tick(double dt) override;
95
96 //! \brief Shuts down the connector
97 //!
98 //! Sends a final DtIfVreStatus message (setFinalStatusMessage = true) to inform
99 //! the VRF backend that this station is disconnecting, then unregisters all VRE
100 //! message handlers and VRF message callbacks.
101 virtual void shutdown() override;
102
103 //! \brief Session status and SMS list message handlers
104 //! @{
105
106 //! \brief Handles a request for the current VRF session status
107 //! \param message Pointer to the session status request message
108 //! \return HANDLED
109 //!
110 //! Calls sendSessionStatusMessage() to send the current cached session status
111 //! to the frontend immediately.
113
114 //! \brief Handles a request for the current simulation model set (SMS) list
115 //! \param message Pointer to the SMS list request message
116 //! \return HANDLED
117 //!
118 //! Calls sendSessionSmsUpdate() to send the current SMS list to the frontend.
120
121 //! \brief Handles a request for the current session play state
122 //! \param message Pointer to the play state request message
123 //! \return HANDLED
124 //!
125 //! Calls sendSessionPlayState() to send the current playing/paused state
126 //! to the frontend.
128
129 //! \brief Handles a request or response for the cached role assignment.
130 //! \param message Pointer to the pending-role-assignment message.
131 //! \return HANDLED
133
134 //! \brief Handles a request to set the default simulation model set (SMS) list
135 //! \param message Pointer to the set default SMS list message
136 //! \return HANDLED
137 //!
138 //! Updates the cached SMS list and propagates changes to the VRF communication
139 //! manager. If the list is unchanged, sends an SmsLoadCompleteMessage with
140 //! changed = false. If changed, calls sendSessionSmsUpdate().
142
143 //! @}
144
145 //! \brief Simulation control message handlers
146 //! @{
147
148 //! \brief Handles a request to start or resume the simulation
149 //! \param message Pointer to the VRF run message
150 //! \return HANDLED
152
153 //! \brief Handles a request to pause the simulation
154 //! \param message Pointer to the VRF pause message
155 //! \return HANDLED
157
158 //! \brief Handles a request to rewind the simulation initiated by this station
159 //! \param message Pointer to the VRF rewind message
160 //! \return HANDLED
161 //!
162 //! Pauses the simulation then rewinds it. Snapshot-based rollback is a
163 //! Phase 3 feature (DtVreBackendConnector) and is not yet supported here.
165
166 //! @}
167
168 //! \brief Builds and sends a VRE status heartbeat from the local attribute subtree
169 //!
170 //! Reads the \c vreStatus.local subtree in the global App attribute tree and
171 //! delivers a DtIfVreStatus message to the VRF backend at a fixed heartbeat interval.
173
174 //! \brief Static callbacks for VRF backend messages
175 //! @{
176
177 //! \brief Static callback for inbound VRE status messages (VRF backend → frontend)
178 //! \param msg Pointer to the simulation message
179 //! \param usr Pointer to the connector instance
180 static void vreStatusMessageCallback(DtSimMessage* msg, void* usr);
181
182 //! \brief Static callback for role assignment messages from the VRF backend
183 //! \param msg Pointer to the simulation message
184 //! \param usr Pointer to the connector instance
185 static void assignRolePlayerMessageCallback(DtSimMessage* msg, void* usr);
186
187 //! \brief Static callback for role unassignment messages from the VRF backend
188 //! \param msg Pointer to the simulation message
189 //! \param usr Pointer to the connector instance
190 static void unassignRolePlayerMessageCallback(DtSimMessage* msg, void* usr);
191
192 //! \brief Static callback invoked when a backend simulation address is removed
193 //! \param addr Simulation address of the removed backend
194 //! \param usr Pointer to the connector instance
195 static void backendRemovedCallback(const DtSimulationAddress& addr, void* usr);
196
197 //! @}
198
199protected:
200 //! \brief Instance methods for processing inbound VRF callbacks
201 //! @{
202
203 //! \brief Processes inbound VRE status messages received from the VRF backend
204 //! \param msg Pointer to the simulation message
205 //!
206 //! Filters out this station's own identity and forwards all other stations'
207 //! status to the frontend as VreStatusMessage objects.
208 virtual void processVreStatusMessage(DtSimMessage* msg);
209
210 //! \brief Processes role assignment messages received from the VRF backend
211 //! \param msg Pointer to the simulation message
212 //!
213 //! Forwards VreAssignRolePlayerMessage to the frontend if the message is
214 //! addressed to this station's identity. Policy-blocked rewind assignments are
215 //! forwarded for frontend cleanup but are not cached for subsequent replay.
216 virtual void processAssignRolePlayerMessage(DtSimMessage* msg);
217
218 //! \brief Processes role unassignment messages received from the VRF backend
219 //! \param msg Pointer to the simulation message
220 //!
221 //! Forwards VreUnassignRolePlayerMessage to the frontend if the message is
222 //! addressed to this station's identity.
223 virtual void processUnassignRolePlayerMessage(DtSimMessage* msg);
224
225 //! \brief Processes a backend removal notification for this connector.
226 //!
227 //! Removes the attribute entry for the departing backend address from
228 //! the backends attribute subtree.
229 //!
230 //! \param addr Simulation address of the removed backend
231 virtual void processBackendRemoved(const DtSimulationAddress& addr);
232
233 //! @}
234
235 //! \brief Internal status evaluation and broadcast methods
236 //! @{
237
238 //! \brief Evaluates current session status from connected backends and broadcasts changes
239 //!
240 //! Iterates the backend list from the VRF remote controller, extracts scenario and
241 //! terrain names, SMS sets, and control state. Publishes session status, play state,
242 //! and SMS list updates to the frontend when changes are detected.
243 //!
244 //! \note mySessionStatusAttr.myWeAreHost is always false in Phase 2. The backend-is-host
245 //! flag is managed by DtVreBackendConnector (Phase 3).
246 virtual void updateSessionStatus();
247
248 //! \brief Clears any cached role assignment awaiting acknowledgement
250
251 //! \brief Caches the latest role assignment until it is acknowledged.
252 //!
253 //! A checkpoint restore can replay an assignment before all VRF simulations
254 //! report the restored session. The cache must therefore outlive session
255 //! status changes. A matching acceptance or decline, unassignment, or a local
256 //! rewind request clears it. Policy-blocked rewind assignments are not cached.
259
260 //! \brief Sends the current session status to the frontend
261 //!
262 //! Creates and queues a VrfSessionStatusMessage from the cached mySessionStatusAttr data.
264
265 //! \brief Sends the current session play state to the frontend
266 //!
267 //! Creates and queues a SessionPlayStateMessage indicating whether the simulation
268 //! is currently running or paused.
269 virtual void sendSessionPlayState();
270
271 //! \brief Sends the current SMS list to the frontend and updates the communication manager
272 //!
273 //! Queues a SessionSmsListMessage with the current SMS filenames and calls
274 //! setSimulationModelSets() on the VRE communication manager. Also queues an
275 //! SmsLoadCompleteMessage for the communication manager component.
276 virtual void sendSessionSmsUpdate();
277
278 //! @}
279
280protected:
281 //! \brief Infrastructure pointer (NON-OWNING - owned by DtConnectorAccessory)
282 //! @{
283
284 //! \brief Shared VRF remote controller (NON-OWNING)
285 //!
286 //! Provides access to the VRF message interface, backend listener, and remote
287 //! control APIs. Lifetime managed by DtConnectorAccessory, guaranteed to
288 //! outlive this connector.
289 makVrf::DtVrlinkVrfRemoteController* myVrfRemoteController = nullptr;
290
291 //! @}
292
293 //! \brief Connector state
294 //! @{
295
296 //! \brief Unique identifier for this station
297 //!
298 //! Computed from the station name (or hostname) and process ID. Used to filter
299 //! inbound VRE status and role assignment messages to this station only.
300 //! Stored as a string to match the string IDs in DtIfVreStatus,
301 //! DtIfAssignRolePlayer, and DtIfUnassignRolePlayer.
302 std::string myStationId;
303
304 //! \brief Simulation address of this station's VRE backend process
305 //!
306 //! Stored as an attribute store handle so other connectors (e.g. DtOwnshipCreationConnector)
307 //! can read the current backend address via DtAttributeHandleType without a connector pointer.
308 //! Value is DtSimulationAddress::nullId() when no backend is running.
309 //! \vreAttrKey{vreBackendStatus.SimAddress}
311
312 //! \brief Current cached session status data
313 //! \vreAttrKey{sessionStatus}
315
316 //! \brief True if the session is currently playing (not paused)
317 //! \vreAttrKey{sessionPlayState}
319
320 //! \brief Read-only policy controlling automatic reengagement after rewind.
321 //! \vreAttrKey{reengageOnRewind}
323
324 //! \brief Current set of simulation model set filenames for this session
325 //! \vreAttrKey{sessionSmsList}
327
328 //! \brief Indicates whether this station is the backend host
329 //! \vreAttrKey{vreBackendIsHost}
331
332 //! \brief Read handle for the local station status attribute subtree
333 //!
334 //! Bound during install() to the global App attribute tree's \c vreStatus.local
335 //! subtree.
336 //! Read by the network thread in sendLocalStatusHeartbeat() for outbound heartbeats.
337 //! \vreAttrKey{vreStatus.local}
339
341
342 //! \brief Remote station status attribute subtree
343 //!
344 //! Bound during install() to the global App attribute tree's \c vreStatus.stations
345 //! subtree.
346 //! Stores a vector of station-ID strings as the root value; each named child holds
347 //! that station's fields (appName, playerName, entityId, entityUuid, stationName,
348 //! spectatorMode, lastSeen, id). Written by the network thread on inbound DtIfVreStatus
349 //! traffic; read by the main thread for UI and ownership-transfer logic.
350 //! \vreAttrKey{vreStatus.stations}
352
353 //! \brief True when there is a cached assignment awaiting acknowledgement
355
356 //! \brief Latest role assignment for this station awaiting acknowledgement
358
359 //! \brief Wall-clock timer tracking when the last outbound heartbeat was sent
361
362 //! \brief Heartbeat interval in Seconds for outbound DtIfVreStatus messages
363 static constexpr double theHeartbeatIntervalS = 1.f;
364
365 //! @}
366};
367
368} // namespace makVre
Provides handle classes for safe access to attributes.
Base class for all simulation event connectors in VREngage.
Definition simEventConnector.h:53
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Type-specific handle class for attributes.
Definition attributeHandle.h:229
virtual void shutdown() override
Shuts down the connector.
void clearPendingRoleAssignment()
Clears any cached role assignment awaiting acknowledgement.
virtual DtVreMessageResult handleSetDefaultSmsList(DtVreMessage *message)
Handles a request to set the default simulation model set (SMS) list.
virtual void processAssignRolePlayerMessage(DtSimMessage *msg)
Processes role assignment messages received from the VRF backend.
DtAttributeHandleType< bool > myBackendIsHostAttr
Indicates whether this station is the backend host.
Definition sessionStatusConnector.h:330
virtual DtVreMessageResult handleVrfRewind(DtVreMessage *message)
Handles a request to rewind the simulation initiated by this station.
static void vreStatusMessageCallback(DtSimMessage *msg, void *usr)
Static callbacks for VRF backend messages.
virtual void install(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection *connection, makVrf::DtVrlinkVrfRemoteController *vrfRemoteController)
Installs the session status connector with shared infrastructure.
DtAttributeHandleType< bool > mySessionPlayStateAttr
True if the session is currently playing (not paused)
Definition sessionStatusConnector.h:318
DtAttributeHandleType< std::vector< std::string > > myVreStatusStationsAttr
Remote station status attribute subtree.
Definition sessionStatusConnector.h:351
virtual void sendLocalStatusHeartbeat()
Builds and sends a VRE status heartbeat from the local attribute subtree.
std::string myStationId
Connector state.
Definition sessionStatusConnector.h:302
static constexpr double theHeartbeatIntervalS
Heartbeat interval in Seconds for outbound DtIfVreStatus messages.
Definition sessionStatusConnector.h:363
virtual DtVreMessageResult handleSessionPlayStateRequest(DtVreMessage *message)
Handles a request for the current session play state.
static void assignRolePlayerMessageCallback(DtSimMessage *msg, void *usr)
Static callback for role assignment messages from the VRF backend.
virtual ~DtSessionStatusConnector() override=default
Virtual destructor.
DtAttributeHandle myBackendsListAttr
Connector state.
Definition sessionStatusConnector.h:340
virtual void processVreStatusMessage(DtSimMessage *msg)
Instance methods for processing inbound VRF callbacks.
DtAttributeHandleType< VrfSessionStatusMessage::VrfSessionStatusData > mySessionStatusAttr
Current cached session status data.
Definition sessionStatusConnector.h:314
virtual void updateSessionStatus()
Internal status evaluation and broadcast methods.
DtAttributeHandleType< std::set< std::string > > mySessionSmsListAttr
Current set of simulation model set filenames for this session.
Definition sessionStatusConnector.h:326
VreAssignRolePlayerMessage::VreAssignRolePlayerData myPendingRoleAssignment
Latest role assignment for this station awaiting acknowledgement.
Definition sessionStatusConnector.h:357
virtual void processBackendRemoved(const DtSimulationAddress &addr)
Processes a backend removal notification for this connector.
virtual void sendSessionStatusMessage()
Sends the current session status to the frontend.
static void backendRemovedCallback(const DtSimulationAddress &addr, void *usr)
Static callback invoked when a backend simulation address is removed.
virtual DtVreMessageResult handleVrfRun(DtVreMessage *message)
Simulation control message handlers.
static void unassignRolePlayerMessageCallback(DtSimMessage *msg, void *usr)
Static callback for role unassignment messages from the VRF backend.
makVrf::DtVrlinkVrfRemoteController * myVrfRemoteController
Infrastructure pointer (NON-OWNING - owned by DtConnectorAccessory)
Definition sessionStatusConnector.h:289
DtAttributeHandle myVreStatusLocalAttr
Read handle for the local station status attribute subtree.
Definition sessionStatusConnector.h:338
virtual void sendSessionPlayState()
Sends the current session play state to the frontend.
virtual void sendSessionSmsUpdate()
Sends the current SMS list to the frontend and updates the communication manager.
virtual void processUnassignRolePlayerMessage(DtSimMessage *msg)
Processes role unassignment messages received from the VRF backend.
bool myHasPendingRoleAssignment
True when there is a cached assignment awaiting acknowledgement.
Definition sessionStatusConnector.h:354
virtual void tick(double dt) override
Performs periodic session status evaluation.
virtual DtVreMessageResult handleSessionSmsListRequest(DtVreMessage *message)
Handles a request for the current simulation model set (SMS) list.
DtAttributeHandleType< bool > myReengageOnRewindAttr
Read-only policy controlling automatic reengagement after rewind.
Definition sessionStatusConnector.h:322
virtual DtVreMessageResult handlePendingRoleAssignment(DtVreMessage *message)
Handles a request or response for the cached role assignment.
DtAttributeHandleType< DtSimulationAddress > myVreBackendAddrAttr
Simulation address of this station's VRE backend process.
Definition sessionStatusConnector.h:310
double myLastHeartbeatTime
Wall-clock timer tracking when the last outbound heartbeat was sent.
Definition sessionStatusConnector.h:360
virtual DtVreMessageResult handleVrfSessionStatusRequest(DtVreMessage *message)
Session status and SMS list message handlers.
virtual DtVreMessageResult handleVrfPause(DtVreMessage *message)
Handles a request to pause the simulation.
void cachePendingRoleAssignment(const VreAssignRolePlayerMessage::VreAssignRolePlayerData &assignmentData)
Caches the latest role assignment until it is acknowledged.
DtSessionStatusConnector()=default
Default constructor.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines export macros and protocol namespace for vrePlayerStationConnector.
#define VRL_DLL
Empty definition for non-Windows platforms.
Definition export.h:52
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition connectorAccessory.h:38
Defines the base DtSimEventConnector class for VREngage simulation events.
Data payload for VreAssignRolePlayerMessage.
Definition vreAssignRolePlayer.h:40