VR-Engage  2.3
Loading...
Searching...
No Matches
reflectedEntityConnector.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file reflectedEntityConnector.h
7//! \brief Defines the DtReflectedEntityConnector class for entity discovery and tracking
8//!
9//! This connector handles entity and control object discovery callbacks from VR-Link,
10//! broadcasting discovery messages to VR-Engage components. It also handles queries
11//! for entities filtered by type and provides a caching layer for reflected entity
12//! information including UUID lookups.
13//!
14//! Responsibilities:
15//! - Broadcast EntityDiscoveredMessage / EntityRemovedMessage when entities appear or disappear
16//! - Broadcast VrfDiscoverEventMessage / VrfRemoveEventMessage for scenario event objects
17//! - Broadcast EntityDiscoveredMessage / EntityRemovedMessage for action menu control objects
18//! - Evaluate environment process discovery conditions
19//! - Handle RequestEntitiesByTypeMessage queries
20//! - Provide UUID ↔ entity ID lookup helpers with a single-entry cache
21
22#pragma once
23
27
28#include "vreUtil/attribute.h"
29#include "vreUtil/factory.h"
30
31#include <vrfMsgTransport/event.h>
32
33#include <vrfutil/rwUUID.h>
34
35#include <vlpi/entityIdentifier.h>
36
37
38//! \brief Forward declarations
39class DtReflectedExtEntityList;
40class DtReflectedExtEntity;
41class DtReflectedControlObject;
42class DtReflectedControlObjectList;
43class DtReflectedEnvironmentProcess;
44class DtReflectedObject;
45class DtSimResource;
46class DtIfSensorData;
47class DtSensorDataEntry;
48class DtSimMessage;
49
50namespace makVrf
51{
52class DtVrlinkVrfRemoteController;
53} // namespace makVrf
54
55namespace makVre
56{
57
58//! \brief Connector for entity and control object discovery, tracking, and type queries
59//!
60//! DtReflectedEntityConnector registers callbacks with DtReflectedExtEntityList and
61//! DtReflectedControlObjectList to receive notifications when entities and control objects
62//! are added or removed from the simulation. It translates these VR-Link events into
63//! VR-Engage messages (EntityDiscoveredMessage, EntityRemovedMessage, VrfDiscoverEventMessage,
64//! VrfRemoveEventMessage) and queues them for frontend consumption.
65//!
66//! It also handles RequestEntitiesByTypeMessage, querying both the entity list and the
67//! control object list for matches and responding with RequestEntitiesByTypeResponseMessage.
68//!
69//! A single-entry cache (myCachedReflectedEntityInfo) accelerates repeated lookups of
70//! UUID and entity type for the most recently accessed entity. The deprecated lookupUUID()
71//! and findEntityIdFromUUID() methods wrap DtUUID::objectIdentificationResolver() for
72//! backward compatibility; prefer calling the resolver directly in new code.
73//!
74//! This connector is fully independent — it does not depend on any other connector
75//! and does not publish shared state to the app attribute store.
76//!
77//! \ingroup vrePlayerStationConnector
79{
80public:
81 //! \brief Default constructor. Initializes all pointers to nullptr.
83
84 //! \brief Virtual destructor. Frees myCachedReflectedEntityInfo.
85 virtual ~DtReflectedEntityConnector() override;
86
87 //! \brief Installs the entity tracking connector with shared infrastructure
88 //!
89 //! Stores the infrastructure pointers, registers entity-added/removed callbacks on
90 //! the reflected extended entity list, control-object-added/removed callbacks on the
91 //! reflected control object list, and sets the environment process discovery condition.
92 //! Also registers a handler for RequestEntitiesByTypeMessage.
93 //!
94 //! \param connection Non-owning pointer to the protocol-specific VR-Link connection.
95 //! \param vrfRemoteController Non-owning pointer to the VRF remote controller;
96 //! retained for potential controller-level queries
97 //! \param reflectedExtEntityList Non-owning pointer to the reflected extended entity list;
98 //! used to register entity-added/removed callbacks and answer type queries
99 //! \param reflectedControlObjectList Non-owning pointer to the reflected control object list;
100 //! used to register control-object-added/removed callbacks, set the discovery condition,
101 //! and answer type queries
102 virtual void install(
103 makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* connection,
104 makVrf::DtVrlinkVrfRemoteController* vrfRemoteController,
105 DtReflectedExtEntityList* reflectedExtEntityList,
106 DtReflectedControlObjectList* reflectedControlObjectList);
107
108 //! \brief Performs periodic processing (currently a no-op)
109 //!
110 //! \param dt The elapsed time in seconds since the last tick
111 virtual void tick(double dt) override;
112
113 //! \brief Shuts down the connector
114 //!
115 //! Removes the RequestEntitiesByType message handler, removes entity-added/removed
116 //! callbacks from the reflected entity list, and removes control-object-added/removed
117 //! callbacks from the reflected control object list.
118 virtual void shutdown() override;
119
120 //! \brief Message handlers
121 //! @{
122
123 //! \brief Handles a request to find entities matching a specific type pattern
124 //! \param msg Pointer to a RequestEntitiesByTypeMessage
125 //! \return HANDLED
126 //!
127 //! Iterates over the reflected entity list and the reflected control object list,
128 //! collecting entities whose type matches the requested pattern. Queues a
129 //! RequestEntitiesByTypeResponseMessage with all matches.
131
132 //! @}
133
134 //! \brief Static VR-Link entity callbacks
135 //! @{
136
137 //! \brief Invoked by VR-Link when an entity is added to the reflected list
138 //! \param obj Pointer to the added entity
139 //! \param usr Pointer to the owning DtReflectedEntityConnector instance
140 //!
141 //! Constructs and queues an EntityDiscoveredMessage carrying the entity's id,
142 //! type, force, marking text, and VRF object label.
143 static void entityAddedCallback(DtReflectedExtEntity* obj, void* usr);
144
145 //! \brief Invoked by VR-Link when an entity is removed from the reflected list
146 //! \param obj Pointer to the removed entity
147 //! \param usr Pointer to the owning DtReflectedEntityConnector instance
148 //!
149 //! Queues an EntityRemovedMessage and clears myCachedReflectedEntityInfo if it
150 //! held data for the removed entity.
151 static void entityRemovedCallback(DtReflectedExtEntity* obj, void* usr);
152
153 //! @}
154
155 //! \brief Static VR-Link control object callbacks
156 //! @{
157
158 //! \brief Invoked by VR-Link when a control object is added to the reflected list
159 //! \param obj Pointer to the added control object
160 //! \param usr Pointer to the owning DtReflectedEntityConnector instance
161 //!
162 //! For scenario event objects (DtScenarioEventsType): extracts the scenario event
163 //! caption and UUID and queues a VrfDiscoverEventMessage.
164 //! For action menu objects (entity types 16.0.0.1, bullseye, 17.0.0.2): delegates
165 //! to handleActionMenuControlObjectDiscovered().
166 static void controlObjectAddedCallback(DtReflectedControlObject* obj, void* usr);
167
168 //! \brief Invoked by VR-Link when a control object is removed from the reflected list
169 //! \param obj Pointer to the removed control object
170 //! \param usr Pointer to the owning DtReflectedEntityConnector instance
171 //!
172 //! For scenario event objects: queues a VrfRemoveEventMessage.
173 //! For action menu objects: delegates to handleActionMenuControlObjectRemoved().
174 static void controlObjectRemovedCallback(DtReflectedControlObject* obj, void* usr);
175
176 //! \brief Discovery condition callback for environment processes
177 //! \param envProcess Pointer to the reflected object being evaluated as an environment process
178 //! \param userData Pointer to the owning DtReflectedEntityConnector instance
179 //! \return true if the environment process meets the discovery criteria
180 //!
181 //! Delegates to processEnvProcessDiscoveryCriteria() on the connector instance.
182 static bool envProcessDiscoveryConditionCallback(DtReflectedObject* envProcess, void* userData);
183
184 //! @}
185
186 //! \brief Entity caching and UUID lookup
187 //! @{
188
189 //! \brief Looks up and caches reflected entity info for the given entity ID
190 //! \param entityId The entity identifier to look up
191 //! \return Pointer to DtReflectedExtEntityInfo if the entity exists, nullptr otherwise
192 //!
193 //! Checks myCachedReflectedEntityInfo first. On a cache miss, looks the entity
194 //! up in myReflectedExtEntityList, updates the cache, and returns the new entry.
195 virtual DtReflectedExtEntityInfo* lookupReflectedEntityInfo(const DtEntityIdentifier& entityId);
196
197 //! \brief Returns the UUID for an entity using the single-entry cache
198 //! \param entityId The entity identifier to resolve
199 //! \return The DtUUID for the entity, or DtUUID::nullUUID() if not found
200 //!
201 //! \deprecated Prefer DtUUID::objectIdentificationResolver() for direct lookups
202 virtual DtUUID lookupUUID(const DtEntityIdentifier& entityId);
203
204 //! \brief Resolves a UUID to an entity identifier via the object identification resolver
205 //! \param uuid The UUID to resolve
206 //! \return The DtEntityIdentifier for the entity
207 //!
208 //! \deprecated Prefer DtUUID::objectIdentificationResolver() for direct lookups
209 virtual DtEntityIdentifier findEntityIdFromUUID(const DtUUID& uuid);
210
211 //! \brief Extracts the UUID from a reflected entity via the object identification resolver
212 //! \param reflectedEntity The reflected entity to get the UUID for
213 //! \return The DtUUID for the entity
214 virtual DtUUID findUUID(DtReflectedExtEntity* reflectedEntity);
215
216 //! @}
217
218protected:
219 //! \brief Constructs and queues an EntityDiscoveredMessage for an action menu control object
220 //! \param obj Pointer to the action menu control object
221 virtual void handleActionMenuControlObjectDiscovered(DtReflectedControlObject* obj);
222
223 //! \brief Constructs and queues an EntityRemovedMessage for an action menu control object
224 //! \param obj Pointer to the action menu control object
225 virtual void handleActionMenuControlObjectRemoved(DtReflectedControlObject* obj);
226
227 //! \brief Evaluates whether an environment process meets the discovery criteria
228 //! \param envProcess Pointer to the environment process to evaluate
229 //! \return true if the process has a valid entity type and at least one environmental record
230 virtual bool processEnvProcessDiscoveryCriteria(DtReflectedEnvironmentProcess* envProcess);
231
232protected:
233 //! \brief Non-owning pointer to the VRF remote controller
234 //! \note Retained for potential controller-level queries; does not create or destroy it
235 makVrf::DtVrlinkVrfRemoteController* myVrfRemoteController;
236
237 //! \brief Non-owning pointer to the reflected extended entity list
238 //! \note Used to register entity-added/removed callbacks and to answer type queries
239 DtReflectedExtEntityList* myReflectedExtEntityList;
240
241 //! \brief Non-owning pointer to the reflected control object list
242 //! \note Used to register control-object callbacks, set the discovery condition,
243 //! and answer control object type queries
244 DtReflectedControlObjectList* myReflectedControlObjectList;
245
246 //! \brief Single-entry cache for the most recently accessed entity's reflected info
247 //! \note Owned by this connector; freed in the destructor. Invalidated when the
248 //! cached entity is removed via entityRemovedCallback().
250
251protected:
252
254
255 //! \brief Reflected Entity Attribute system
256 //!
257 //! Provides a mechanism for accessing (nearly) all reflected entity information using
258 //! DtAttributes. This includes most ESR data members, as well as Resources and Sensor data.
259 //!
260 //! Entity data is stored in DtAttribute::Root()["Entities"][entityId][propertyName]
261 //! @{
262
263 //! \brief Attribute store for reflected entity state
265
267
268 virtual void updateAttributesForEntity(DtReflectedExtEntity* ree, DtAttributeHandle& entityAttr);
269
270 //! @brief Function pointer for setting a Reflected Entity Attribute from reflected ESR data
271 using SetAttrFunc = std::function<void(const DtReflectedExtEntity&, DtAttributeHandle&)>;
272
273 //! @brief Map of individual Reflected Entity Attribute names with corresponding set
274 //! functions to read ESR data
275 //!
276 //! Most getter methods in ESR are mirrored by an Attribute of the same name.
277 //! e.g. DtReflectedEntity::damageState is found as DtAttribute::Root()["Entities"][entityId]["damageState"]
278 std::map<std::string, SetAttrFunc> mySetAttrMap;
279
280 //! @brief Register SetAttrFunc functions in mySetAttrMap for reading Entity Attributes from reflected ESR data.
281 //! \note Override and extend to add custom set functions for reading additional ESR data.
283
284 //! Appearance readers
285 //! @{
286
287 using ReadAppearanceFunc = std::function<void(const DtAppearance&, DtAttributeHandle&)>;
288 std::map<std::string, ReadAppearanceFunc> myReadAppearanceMap;
289
290 //! @}
291
292 //! Extended Data convenience conversions
293 //! @{
294
295 //! @brief Function pointer for setting a type-converted Reflected Entity Attribute from an Extended Data string
296 using ConvertExtDataFunc = std::function<void(const DtString&, DtAttributeHandle&)>;
297 //! @brief Map of State Property names with corresponding functions to read the property and set an Attribute
298 std::map<DtString, ConvertExtDataFunc> myExtDataConversionMap;
299
300 //! @}
301
302 //! State Property readers
303 //! @{
304
305 //! @brief Function pointer for setting a Reflected Entity Attribute from a State Property Interface
306 using ReadStatePropFunc = std::function<void(const DtPropertyInterface&, DtAttributeHandle&)>;
307 //! @brief Map of State Property names with corresponding functions to read the property and set an Attribute
308 std::map<DtString, ReadStatePropFunc> myRwToAttrMap;
309
310 //! @}
311
312 //! @brief Articulated part readers
313 //! @{
314
315 using SetPartParamAttrFunc = std::function<void(const DtArticulatedPart&, DtAttributeHandle&)>;
316 std::map<std::string, SetPartParamAttrFunc> mySetPartParamAttrMap;
317
318 //! @}
319
320 //! @brief Resource readers
321 //! @{
322
323 using ReadResourceParamFunc = std::function<void(const DtSimResource&, DtAttributeHandle&)>;
324 std::map<std::string, ReadResourceParamFunc> myReadResourceParamMap;
325
326 virtual void fillResourceAttribute(const DtSimResource& resource, DtAttributeHandle resourceAttr) const;
327
328 //! \brief Connection for resource response events from the VR-Forces backend.
329 //!
330 //! Connected during initialization and disconnected during shutdown.
331 boost::signals2::connection myResourceResponseConnection;
332
333 virtual void processResourceResponse(const makVrfEvents::DtEvent& evt);
334
335 std::unordered_set<std::string> myResourceMonitoringSet;
336
337 //! @}
338
339 //! \brief Sensor readers
340 //! @{
341
342 using ReadSensorParamFunc = std::function<void(const DtIfSensorData&, DtAttributeHandle&)>;
343 std::map<std::string, ReadSensorParamFunc> myReadSensorParamMap;
344
345 //! \brief Static callback wrapper for sensor update
346 //!
347 //! Calls user->handleSensorUpdate() with the sensor data extracted from the message.
348 //! \param msg The DtSimMessage containing the sensor update information.
349 //! \param usr Pointer to the DtReflectedEntityConnector instance to call the member handler.
350 static void sensorUpdateCallback(DtSimMessage* msg, void* usr);
351
352 //! @brief Member handler for sensor data from update callback
353 //! \param sensorData The sensor data extracted from the message.
354 virtual void processSensorUpdate(const DtIfSensorData& sensorData);
355
356 std::map<std::string, std::unordered_set<std::string>> mySensorMonitoringMap;
357
358 //! @}
359
360 virtual void debugFillAllEntities();
361 //! @}
362};
363
364} // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
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 installSetAttrFunctions()
Register SetAttrFunc functions in mySetAttrMap for reading Entity Attributes from reflected ESR data.
std::unordered_set< std::string > myResourceMonitoringSet
Resource readers.
Definition reflectedEntityConnector.h:335
static void controlObjectRemovedCallback(DtReflectedControlObject *obj, void *usr)
Invoked by VR-Link when a control object is removed from the reflected list.
virtual DtEntityIdentifier findEntityIdFromUUID(const DtUUID &uuid)
Resolves a UUID to an entity identifier via the object identification resolver.
virtual void updateReflectedEntityAttributes()
Function pointer for setting a Reflected Entity Attribute from reflected ESR data.
virtual void handleActionMenuControlObjectDiscovered(DtReflectedControlObject *obj)
Constructs and queues an EntityDiscoveredMessage for an action menu control object.
virtual bool processEnvProcessDiscoveryCriteria(DtReflectedEnvironmentProcess *envProcess)
Evaluates whether an environment process meets the discovery criteria.
std::function< void(const DtArticulatedPart &, DtAttributeHandle &)> SetPartParamAttrFunc
Articulated part readers.
Definition reflectedEntityConnector.h:315
std::map< DtString, ReadStatePropFunc > myRwToAttrMap
Map of State Property names with corresponding functions to read the property and set an Attribute.
Definition reflectedEntityConnector.h:308
std::map< std::string, ReadSensorParamFunc > myReadSensorParamMap
Sensor readers.
Definition reflectedEntityConnector.h:343
makVrf::DtVrlinkVrfRemoteController * myVrfRemoteController
Non-owning pointer to the VRF remote controller.
Definition reflectedEntityConnector.h:235
DtReflectedExtEntityInfo * myCachedReflectedEntityInfo
Single-entry cache for the most recently accessed entity's reflected info.
Definition reflectedEntityConnector.h:249
std::function< void(const DtReflectedExtEntity &, DtAttributeHandle &)> SetAttrFunc
Function pointer for setting a Reflected Entity Attribute from reflected ESR data.
Definition reflectedEntityConnector.h:271
DtReflectedControlObjectList * myReflectedControlObjectList
Non-owning pointer to the reflected control object list.
Definition reflectedEntityConnector.h:244
std::function< void(const DtString &, DtAttributeHandle &)> ConvertExtDataFunc
Extended Data convenience conversions.
Definition reflectedEntityConnector.h:296
DtReflectedEntityConnector()
Default constructor. Initializes all pointers to nullptr.
virtual void processSensorUpdate(const DtIfSensorData &sensorData)
Member handler for sensor data from update callback.
virtual void updateAttributesForEntity(DtReflectedExtEntity *ree, DtAttributeHandle &entityAttr)
Function pointer for setting a Reflected Entity Attribute from reflected ESR data.
std::map< std::string, SetAttrFunc > mySetAttrMap
Map of individual Reflected Entity Attribute names with corresponding set functions to read ESR data.
Definition reflectedEntityConnector.h:278
std::map< std::string, SetPartParamAttrFunc > mySetPartParamAttrMap
Articulated part readers.
Definition reflectedEntityConnector.h:316
static void entityRemovedCallback(DtReflectedExtEntity *obj, void *usr)
Invoked by VR-Link when an entity is removed from the reflected list.
virtual DtReflectedExtEntityInfo * lookupReflectedEntityInfo(const DtEntityIdentifier &entityId)
Entity caching and UUID lookup.
std::map< DtString, ConvertExtDataFunc > myExtDataConversionMap
Map of State Property names with corresponding functions to read the property and set an Attribute.
Definition reflectedEntityConnector.h:298
std::map< std::string, std::unordered_set< std::string > > mySensorMonitoringMap
Sensor readers.
Definition reflectedEntityConnector.h:356
boost::signals2::connection myResourceResponseConnection
Connection for resource response events from the VR-Forces backend.
Definition reflectedEntityConnector.h:331
virtual void install(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection *connection, makVrf::DtVrlinkVrfRemoteController *vrfRemoteController, DtReflectedExtEntityList *reflectedExtEntityList, DtReflectedControlObjectList *reflectedControlObjectList)
Installs the entity tracking connector with shared infrastructure.
static void controlObjectAddedCallback(DtReflectedControlObject *obj, void *usr)
Static VR-Link control object callbacks.
virtual void shutdown() override
Shuts down the connector.
DtReflectedExtEntityList * myReflectedExtEntityList
Non-owning pointer to the reflected extended entity list.
Definition reflectedEntityConnector.h:239
static void sensorUpdateCallback(DtSimMessage *msg, void *usr)
Static callback wrapper for sensor update.
std::function< void(const DtIfSensorData &, DtAttributeHandle &)> ReadSensorParamFunc
Sensor readers.
Definition reflectedEntityConnector.h:342
DtAttributeHandleType< std::set< std::string > > myEntityStateStore
Reflected Entity Attribute system.
Definition reflectedEntityConnector.h:264
virtual DtVreMessageResult handleRequestEntitiesByType(DtVreMessage *msg)
Message handlers.
virtual DtUUID findUUID(DtReflectedExtEntity *reflectedEntity)
Extracts the UUID from a reflected entity via the object identification resolver.
DtAttributeHandle myLocalStatusAttr
Definition reflectedEntityConnector.h:253
static void entityAddedCallback(DtReflectedExtEntity *obj, void *usr)
Static VR-Link entity callbacks.
std::map< std::string, ReadResourceParamFunc > myReadResourceParamMap
Resource readers.
Definition reflectedEntityConnector.h:324
std::function< void(const DtPropertyInterface &, DtAttributeHandle &)> ReadStatePropFunc
State Property readers.
Definition reflectedEntityConnector.h:306
virtual void fillResourceAttribute(const DtSimResource &resource, DtAttributeHandle resourceAttr) const
Resource readers.
std::function< void(const DtSimResource &, DtAttributeHandle &)> ReadResourceParamFunc
Resource readers.
Definition reflectedEntityConnector.h:323
virtual ~DtReflectedEntityConnector() override
Virtual destructor. Frees myCachedReflectedEntityInfo.
std::map< std::string, ReadAppearanceFunc > myReadAppearanceMap
Function pointer for setting a Reflected Entity Attribute from reflected ESR data.
Definition reflectedEntityConnector.h:288
virtual DtUUID lookupUUID(const DtEntityIdentifier &entityId)
Returns the UUID for an entity using the single-entry cache.
virtual void tick(double dt) override
Performs periodic processing (currently a no-op)
virtual void handleActionMenuControlObjectRemoved(DtReflectedControlObject *obj)
Constructs and queues an EntityRemovedMessage for an action menu control object.
static bool envProcessDiscoveryConditionCallback(DtReflectedObject *envProcess, void *userData)
Discovery condition callback for environment processes.
virtual void processResourceResponse(const makVrfEvents::DtEvent &evt)
Resource readers.
std::function< void(const DtAppearance &, DtAttributeHandle &)> ReadAppearanceFunc
Appearance readers.
Definition reflectedEntityConnector.h:287
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Provides a template-based factory system for object creation.
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.
Structure containing information about a reflected extended entity.
Definition util.h:40
Utility functions for VREngage player station connector.