VR-Engage  2.3
Loading...
Searching...
No Matches
ownshipCreationConnector.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file ownshipCreationConnector.h
7//! \brief Defines the DtOwnshipCreationConnector class for ownship entity lifecycle management
8//!
9//! This connector manages the lifecycle of the local ownship entity: requesting creation
10//! of a new ownship on the VR-Forces backend, confirming creation via callback, and
11//! handling deletion when the player disengages or changes entity type. It listens for
12//! entity-added/removed events from VR-Link to track the created entity's state.
13
14#pragma once
15
19
20#include <vlpi/entityIdentifier.h>
21#include <vlpi/simulationAddress.h>
22
24
25#include <vlutil/vlString.h>
27
28#include <vrfutil/rwUUID.h>
29
30//! \brief Forward declarations
31class DtReflectedEntityList;
32class DtReflectedExtEntityList;
33class DtReflectedExtEntity;
34
35namespace makVrf
36{
37class DtVrlinkVrfRemoteController;
38} // namespace makVrf
39
40namespace makVre
41{
43
44//! \brief Connector for ownship entity creation and deletion
45//!
46//! DtOwnshipCreationConnector is responsible for the lifecycle of the single locally
47//! controlled "new ownship" entity. When the frontend requests a new ownship of a
48//! specific type, this connector submits a createEntity call to the VR-Forces backend
49//! and tracks the result via a static callback. When the desired entity type changes
50//! (or is cleared), it deletes the existing entity and optionally creates a new one.
51//!
52//! The connector registers entity-added and entity-removed callbacks on the
53//! DtReflectedExtEntityList to detect when the created entity appears in or disappears
54//! from the reflected entity list. These callbacks are filtered to the owned entity only.
55//!
56//! Backend readiness (started + loaded) and the active backend address are read from
57//! the app attribute store via DtAttributeHandleType<> handles published by
58//! DtVreBackendConnector. This avoids any direct connector-to-connector pointer dependency.
59//!
60//! \ingroup vrePlayerStationConnector
62{
63public:
64 //! \brief Default constructor. Initializes all state to default/null values.
66
67 //! \brief Virtual destructor. Frees myDesiredCreateEntityMessage.
68 virtual ~DtOwnshipCreationConnector() override;
69
70 //! \brief Installs the ownship connector with shared infrastructure
71 //!
72 //! Stores the infrastructure pointers, registers VRE message handlers for
73 //! CreateNew/DestroyNewOwnship, and registers entity-added/removed callbacks
74 //! on the reflected ext entity list. Backend readiness and the active backend
75 //! address are read from the global App attribute tree via DtAttributeHandleType<>
76 //! handles bound to \c vreBackendStatus and \c vreBackendStatus.SimAddress.
77 //!
78 //! \param connection Non-owning pointer to the protocol-specific VR-Link connection.
79 //! \param vrfRemoteController Non-owning pointer to the VRF remote controller;
80 //! used to call createEntity(), deleteObject(), and sendSetDataMsg()
81 //! \param reflectedExtEntityList Non-owning pointer to the reflected extended entity list;
82 //! used to register entity-added/removed callbacks
83 virtual void install(
84 makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* connection,
85 makVrf::DtVrlinkVrfRemoteController* vrfRemoteController,
86 DtReflectedExtEntityList* reflectedExtEntityList);
87
88 //! \brief Performs periodic processing (currently a no-op)
89 //!
90 //! \param dt The elapsed time in seconds since the last tick
91 virtual void tick(double dt) override;
92
93 //! \brief Shuts down the connector
94 //!
95 //! Removes VRE message handlers and entity-added/removed callbacks,
96 //! and frees the desired-create message.
97 virtual void shutdown() override;
98
99 //! \brief Ownship message handlers
100 //! @{
101
102 //! \brief Handles a request to create a new ownship entity of the specified type
103 //! \param message Pointer to a CreateNewOwnshipMessage
104 //! \return HANDLED
105 //!
106 //! Copies the desired entity specification to myDesiredCreateEntityMessage, then
107 //! calls verifyNewOwnship() to initiate creation if the backend is ready.
109
110 //! \brief Handles a request to destroy the current new ownship entity
111 //! \param message Pointer to a DestroyNewOwnshipMessage
112 //! \return HANDLED
113 //!
114 //! Sets the desired entity type to nullType, then calls verifyNewOwnship()
115 //! to initiate deletion of the current entity if one exists.
117
118 //! @}
119
120 //! \brief Static VR-Link callbacks
121 //! @{
122
123 //! \brief Invoked by VRF when a locally requested entity has been created
124 //! \param name Display name assigned by VRF to the new entity
125 //! \param id DIS entity identifier of the new entity
126 //! \param uuid UUID assigned to the new entity
127 //! \param usr Pointer to the owning DtOwnshipCreationConnector instance
129 const DtString& name, const DtEntityIdentifier& id, const DtUUID& uuid, void* usr);
130
131 //! \brief Invoked by VR-Link when any entity is added to the reflected list
132 //! \param obj Pointer to the added entity; filtered to owned entity only
133 //! \param usr Pointer to the owning DtOwnshipCreationConnector instance
134 static void ownedEntityAddedCallback(DtReflectedExtEntity* obj, void* usr);
135
136 //! \brief Invoked by VR-Link when any entity is removed from the reflected list
137 //! \param obj Pointer to the removed entity; filtered to owned entity only
138 //! \param usr Pointer to the owning DtOwnshipCreationConnector instance
139 static void ownedEntityRemovedCallback(DtReflectedExtEntity* obj, void* usr);
140
141 //! @}
142
143protected:
144 //! \brief Verifies whether the current entity matches the desired state and acts accordingly
145 //!
146 //! If the backend is not started/loaded, returns immediately. Otherwise compares
147 //! myDesiredCreateEntityMessage entity type against myCreatedEntityInfo.myEntityType
148 //! and issues a create or delete command as needed.
149 virtual void verifyNewOwnship();
150
151 //! \brief Sends a createEntity request to the VRF backend
152 //!
153 //! Asserts that no create or delete is already in progress and that the backend
154 //! exists. Calls myVrfRemoteController->createEntity() with the parameters from
155 //! myDesiredCreateEntityMessage. Sets myWaitingForOwnshipCreate = true.
156 virtual void sendCreateNewOwnship();
157
158 //! \brief Sends a deleteObject request to the VRF backend for the current ownship
159 //!
160 //! Asserts that no create or delete is already in progress and that an owned UUID
161 //! exists. Calls myVrfRemoteController->deleteObject(). Sets myWaitingForOwnshipDelete = true.
162 virtual void sendDeleteNewOwnship();
163
164 //! \brief Called when VRF confirms the locally requested entity was created
165 //!
166 //! Sends NewOwnshipCreatedMessage to the frontend, applies a hold-fire ROE,
167 //! records myCreatedEntityInfo, and calls verifyNewOwnship() to check the result.
168 //! If the entity type is not yet known (not yet reflected), type resolution is
169 //! deferred to handleOwnedEntityAdded().
170 //!
171 //! \param name Display name of the created entity
172 //! \param entityId DIS entity identifier
173 //! \param uuid UUID of the created entity
174 virtual void handleLocalEntityCreated(const DtString& name, const DtEntityIdentifier& entityId, const DtUUID& uuid);
175
176 //! \brief Called when the owned entity appears in the reflected entity list
177 //!
178 //! If the entity type was unknown at creation time (deferred from handleLocalEntityCreated),
179 //! fills in the type and clears myWaitingForOwnshipCreate, then calls verifyNewOwnship().
180 //!
181 //! \param entity Pointer to the reflected extended entity that was added
182 virtual void handleOwnedEntityAdded(const DtReflectedExtEntity* entity);
183
184 //! \brief Called when the owned entity is removed from the reflected entity list
185 //!
186 //! Handles expected removal (waiting for delete or backend reloading) by clearing
187 //! myCreatedEntityInfo and calling verifyNewOwnship(). Also handles unexpected
188 //! removal due to backend shutdown/unload.
189 //!
190 //! \param entity Pointer to the reflected extended entity that was removed
191 virtual void handleOwnedEntityRemoved(const DtReflectedExtEntity* entity);
192
193protected:
194 //! \brief Infrastructure pointers (NON-OWNING — owned by DtConnectorAccessory)
195 //! @{
196
197 //! \brief Shared VRF remote controller (NON-OWNING)
198 //!
199 //! Used to call createEntity(), deleteObject(), and sendSetDataMsg().
200 makVrf::DtVrlinkVrfRemoteController* myVrfRemoteController = nullptr;
201
202 //! \brief Reflected extended entity list (NON-OWNING)
203 //!
204 //! Used to register entity-added/removed callbacks.
205 DtReflectedExtEntityList* myReflectedExtEntityList = nullptr;
206
207 //! @}
208
209 //! \brief App attribute store handles for reading backend state
210 //!
211 //! Written by DtVreBackendConnector; read here without any direct connector pointer.
212 //! @{
213
214 //! \brief VRE backend simulation address
215 //!
216 //! Published by DtVreBackendConnector as a DtAttributeHandleType<DtSimulationAddress>.
217 //! Nullid when no backend is running.
218 //! \vreAttrKey{vreBackendStatus.SimAddress}
220
221 //! \brief Published backend status data
222 //! \vreAttrKey{vreBackendStatus}
224
225 //! @}
226
227 //! \brief Ownship state
228 //! @{
229
230 //! \brief The entity creation parameters that the frontend has requested
231 //!
232 //! Owned by this connector; initialized to an empty CreateNewOwnshipMessage in the constructor.
233 //! A nullType entity type signals "no ownship desired".
235
236 //! \brief Information about the entity that has been created (or is being tracked)
237 //!
238 //! myEntityId is nullId() when no entity is created.
239 //! myEntityType is nullType() if the entity exists but type is not yet known.
241
242 //! \brief True while waiting for VRF to confirm deletion of an ownship entity
244
245 //! \brief True while waiting for VRF to confirm creation of an ownship entity
247
248 //! \brief True if the newly created ownship needs to be repositioned after creation
250
251 //! @}
252};
253
254} // namespace makVre
Provides handle classes for safe access to attributes.
Send to create a new ownship entity, deleting the existing one if it's a different entity type.
Definition createNewOwnship.h:35
Base class for all simulation event connectors in VREngage.
Definition simEventConnector.h:53
Type-specific handle class for attributes.
Definition attributeHandle.h:229
virtual std::string name()
Gets the connector name.
Definition connector.h:68
DtOwnshipCreationConnector()
Default constructor. Initializes all state to default/null values.
virtual void handleOwnedEntityRemoved(const DtReflectedExtEntity *entity)
Called when the owned entity is removed from the reflected entity list.
bool myWaitingForOwnshipCreate
True while waiting for VRF to confirm creation of an ownship entity.
Definition ownshipCreationConnector.h:246
virtual DtVreMessageResult handleDestroyNewOwnship(DtVreMessage *message)
Handles a request to destroy the current new ownship entity.
virtual void handleLocalEntityCreated(const DtString &name, const DtEntityIdentifier &entityId, const DtUUID &uuid)
Called when VRF confirms the locally requested entity was created.
virtual void shutdown() override
Shuts down the connector.
DtAttributeHandleType< DtSimulationAddress > myVreBackendAttr
App attribute store handles for reading backend state.
Definition ownshipCreationConnector.h:219
virtual DtVreMessageResult handleCreateNewOwnship(DtVreMessage *message)
Ownship message handlers.
virtual void sendDeleteNewOwnship()
Sends a deleteObject request to the VRF backend for the current ownship.
DtAttributeHandleType< BackendStatusMessage::BackendStatusData > myBackendStatusAttr
Published backend status data.
Definition ownshipCreationConnector.h:223
DtReflectedExtEntityList * myReflectedExtEntityList
Reflected extended entity list (NON-OWNING)
Definition ownshipCreationConnector.h:205
virtual void install(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection *connection, makVrf::DtVrlinkVrfRemoteController *vrfRemoteController, DtReflectedExtEntityList *reflectedExtEntityList)
Installs the ownship connector with shared infrastructure.
static void ownedEntityAddedCallback(DtReflectedExtEntity *obj, void *usr)
Invoked by VR-Link when any entity is added to the reflected list.
virtual void handleOwnedEntityAdded(const DtReflectedExtEntity *entity)
Called when the owned entity appears in the reflected entity list.
CreateNewOwnshipMessage * myDesiredCreateEntityMessage
Ownship state.
Definition ownshipCreationConnector.h:234
bool myCreatedOwnshipNeedsReposition
True if the newly created ownship needs to be repositioned after creation.
Definition ownshipCreationConnector.h:249
virtual ~DtOwnshipCreationConnector() override
Virtual destructor. Frees myDesiredCreateEntityMessage.
DtReflectedExtEntityInfo myCreatedEntityInfo
Information about the entity that has been created (or is being tracked)
Definition ownshipCreationConnector.h:240
static void ownedEntityRemovedCallback(DtReflectedExtEntity *obj, void *usr)
Invoked by VR-Link when any entity is removed from the reflected list.
virtual void tick(double dt) override
Performs periodic processing (currently a no-op)
virtual void sendCreateNewOwnship()
Sends a createEntity request to the VRF backend.
virtual void verifyNewOwnship()
Verifies whether the current entity matches the desired state and acts accordingly.
static void localEntityCreatedCallback(const DtString &name, const DtEntityIdentifier &id, const DtUUID &uuid, void *usr)
Static VR-Link callbacks.
bool myWaitingForOwnshipDelete
True while waiting for VRF to confirm deletion of an ownship entity.
Definition ownshipCreationConnector.h:243
makVrf::DtVrlinkVrfRemoteController * myVrfRemoteController
Infrastructure pointers (NON-OWNING — owned by DtConnectorAccessory)
Definition ownshipCreationConnector.h:200
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.
Structure containing information about a reflected extended entity.
Definition util.h:40
Utility functions for VREngage player station connector.