VR-Engage  2.3
Loading...
Searching...
No Matches
ownershipTransferManager.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file ownershipTransferManager.h
7//! \ingroup vrePlayerStation
8//! \brief Runtime manager for the Ownership Transfer feature
9//!
10//! This file defines \c DtOwnershipTransferManager, the app-owned runtime
11//! manager for ownership-transfer policy, request IDs, and divest-before-exit
12//! or voluntary network disconnect. The manager reads its policy values from
13//! the Lua configuration file and is exposed by
14//! DtPlayerStationApp::ownershipTransferManager().
15
16#pragma once
17
19
20#include "vreUtil/baseClass.h"
21#include "vreUtil/initializer.h"
22
24
26
27#include <string>
28#include <set>
29
30namespace makVre
31{
32
36class DtOwnershipTransferExitEventFilter;
37
38//! \brief App-level runtime manager for the Ownership Transfer feature
39//!
40//! Holds the parsed configuration for the Ownership Transfer feature,
41//! provides typed policy accessors, allocates request IDs, and coordinates
42//! divest-before-exit and voluntary-disconnect behavior. All policy fields
43//! are default-initialised so a default-constructed instance is always safe
44//! to query before the Lua file is loaded.
45//!
46//! Override parseConfiguration() in a subclass to customise how settings are
47//! read from the Lua table, or use the setters directly to populate the
48//! configuration programmatically. Call
49//! \c DtOwnershipTransferManager::registerCreator<CustomType>() before
50//! \c DtPlayerStationApp::initialize() to substitute a custom derived type.
51class PLAYERSTATION_DLL DtOwnershipTransferManager : public DtVreUniqueBase<DtOwnershipTransferManager>
52{
53public:
57 virtual ~DtOwnershipTransferManager() override;
58
59 //! \brief Stores the back-pointer to the owning application.
60 //!
61 //! Called by DtPlayerStationApp after construction. Must be invoked before
62 //! isOwnershipTransferAvailable() or roleTriggersOwnershipTransfer() are
63 //! called, since those methods access app state.
64 //!
65 //! Installs a main-window filter that defers application exit until divest completes.
66 //!
67 //! \param app Pointer to the owning DtPlayerStationApp instance.
68 virtual void initialize(DtPlayerStationApp* app);
69
70 //! \brief Initiates application exit after divesting all entities owned by this station.
71 //!
72 //! If ownership transfer is unavailable or no entity is owned, immediately
73 //! requests application close. Otherwise displays a persistent divest
74 //! notification and submits release requests. The close proceeds after all
75 //! releases succeed, or after a release fails; the connector's ownership
76 //! transfer timeout bounds the no-response case.
77 virtual void requestExit();
78
79 //! \name Accessors
80 //! \{
81
82 //! Returns true when the Ownership Transfer feature is active.
83 bool enabled() const;
84
85 //! Returns the maximum seconds to wait for an acquire response.
86 double acquireTimeoutSeconds() const;
87
88 //! Returns the number of seconds an owned entity may sit idle in the
89 //! choose-role panel before ownership is automatically released.
90 //! A value of 0.0 disables the idle-release timer entirely.
92
93 //! \brief Returns true when the system-level conditions for ownership
94 //! transfer are met.
95 //!
96 //! Checks that the feature is enabled, the ownship backend is running,
97 //! and the station is in an externally VR-Forces-hosted joined session by
98 //! reading the relevant attributes from the application attribute store.
99 //! Returns false for unhosted and self-hosted sessions.
101
102 //! \brief Returns true when a role engagement should trigger ownership transfer.
103 //!
104 //! Resolves the entity type from the attribute store's entity resolver,
105 //! then evaluates all policy conditions: the feature must be enabled, the
106 //! station must not be in spectator mode, and the role's Lua configuration
107 //! must set \c takeOwnership to \c true (via the player creation palette).
108 //!
109 //! \param entityId The entity being engaged.
110 //! \param roleName The name of the role being engaged.
111 //! \param displayLayout The display layout name for the station.
112 //! \param spectatorMode True when the station is in spectator mode.
113 bool roleTriggersOwnershipTransfer(const DtEntityIdentifier& entityId,
114 const std::string& roleName,
115 const std::string& displayLayout,
116 bool spectatorMode) const;
117
118 //! \}
119
120 //! \name Mutators
121 //! \{
122
123 //! Sets the master feature toggle.
124 void setEnabled(bool enabled);
125
126 //! Sets the acquire timeout in seconds. Values <= 0 are ignored with a warning.
127 void setAcquireTimeoutSeconds(double seconds);
128
129 //! Sets the idle-release timeout in seconds.
130 //! A value of 0.0 disables the timer. Negative values are clamped to 0.0.
131 void setIdleReleaseTimeoutSeconds(double seconds);
132
133 //! \}
134
135 //! \name Request ID allocation
136 //! \{
137
138 //! \brief Allocates and returns the next ownership transfer request identifier.
139 //!
140 //! Returns a monotonically increasing \c uint64_t used to correlate request,
141 //! status, and terminal response messages across timeouts and retries.
142 uint64_t nextRequestId();
143
144 //! \}
145
146 //! \name Parsing
147 //! \{
148
149 //! \brief Populate this instance from a DtInitTable.
150 //!
151 //! Reads the \c OwnershipTransfer Lua table fields: \c enabled,
152 //! \c acquireTimeoutSeconds, and \c idleReleaseTimeoutSeconds.
153 //! Override in a subclass to extend or replace the default parsing logic.
154 //!
155 //! \param table The DtInitTable wrapping the \c OwnershipTransfer Lua table.
156 virtual void parseConfiguration(DtInitTable table);
157 //! \}
158
159protected:
161
162 //! \brief Handles a close event before VR-Vantage begins shutdown.
164
165 //! \brief Starts releases for all owned entities.
166 //!
167 //! \return True when at least one release was queued; false when no entity
168 //! is owned.
169 virtual bool beginDivest();
170
171 //! \brief Completes a pending exit or voluntary disconnect after every release succeeds or is skipped.
172 virtual void completeDivest();
173
174 //! \brief Resumes application exit after successful divest or a failed exit-time release.
175 virtual void completeExit();
176
177 //! \brief Cancels a pending voluntary disconnect after a release failure.
178 virtual void cancelDivest(const std::string& reason);
179
180 //! \brief Processes terminal responses for release requests created by beginDivest().
181 //!
182 //! A skipped release permits the deferred action to proceed. A failed release
183 //! permits a pending application exit to proceed, but cancels a pending
184 //! voluntary network disconnect.
186
187 //! \brief Defers a voluntary disconnect until owned entities are divested.
189
190 //! \brief Back-pointer to the owning DtPlayerStationApp.
191 //!
192 //! Set by initialize(). Used by isOwnershipTransferAvailable() and
193 //! roleTriggersOwnershipTransfer() to access the app attribute store,
194 //! entity resolver, and player creation palette.
196
197 bool myEnabled = true;
199
200 //! \brief Seconds an owned entity may sit idle in the choose-role panel
201 //! before ownership is automatically released.
202 //!
203 //! Set to 0.0 to disable the idle-release timer entirely.
204 //! Negative values supplied via setIdleReleaseTimeoutSeconds() or the
205 //! Lua config are clamped to 0.0.
206 //!
207 //! \note Default value is 10.0 seconds.
209
210 //! \brief Monotonic counter used to assign unique request identifiers.
211 //!
212 //! Incremented by nextRequestId() on each call.
213 uint64_t myNextRequestId = 1;
214
215 //! \brief Main-window filter that defers close events until divest succeeds.
217
218 //! \brief Member-scope instance of message handler group
219 //!
220 //! Used to manage message handler connections for this component. Handlers connected
221 //! through this group will be automatically disconnected when this component is destroyed.
223
224 //! \brief True while an exit or voluntary disconnect waits for owned entities to be divested.
225 bool myDivestInProgress = false;
226
227 //! \brief Allows the close event posted after a successful divest to reach VR-Vantage.
229
230 //! \brief Suppresses the VR-Vantage confirmation after this manager already confirmed a close.
232
233 //! \brief Release request IDs that must succeed before the deferred action may resume.
234 std::set<unsigned long long> myDivestRequestIds;
235
236 //! \brief True when a voluntary network disconnect is waiting for divest completion.
238
239 //! \brief Driver Data retained while the voluntary disconnect is deferred.
241};
242
243} // namespace makVre
Provides base classes for shared pointer managed objects with factory creation support.
Entity resolution and mapping system.
Definition entityResolver.h:52
Table-based access to Lua state for configuration data.
Definition initializer.h:38
bool myDisconnectPending
True when a voluntary network disconnect is waiting for divest completion.
Definition ownershipTransferManager.h:237
DtOwnershipTransferManager & operator=(const DtOwnershipTransferManager &)=delete
double acquireTimeoutSeconds() const
Returns the maximum seconds to wait for an acquire response.
virtual DtVreMessageResult handleStopConnectionRequest(DtVreMessage *message)
Defers a voluntary disconnect until owned entities are divested.
friend class DtOwnershipTransferExitEventFilter
Definition ownershipTransferManager.h:160
void setAcquireTimeoutSeconds(double seconds)
Sets the acquire timeout in seconds. Values <= 0 are ignored with a warning.
virtual void handleMainWindowCloseRequested()
Handles a close event before VR-Vantage begins shutdown.
virtual void cancelDivest(const std::string &reason)
Cancels a pending voluntary disconnect after a release failure.
bool roleTriggersOwnershipTransfer(const DtEntityIdentifier &entityId, const std::string &roleName, const std::string &displayLayout, bool spectatorMode) const
Returns true when a role engagement should trigger ownership transfer.
virtual ~DtOwnershipTransferManager() override
virtual void completeDivest()
Completes a pending exit or voluntary disconnect after every release succeeds or is skipped.
DtOwnershipTransferManager(const DtOwnershipTransferManager &)=delete
double myIdleReleaseTimeoutSeconds
Seconds an owned entity may sit idle in the choose-role panel before ownership is automatically relea...
Definition ownershipTransferManager.h:208
uint64_t myNextRequestId
Monotonic counter used to assign unique request identifiers.
Definition ownershipTransferManager.h:213
virtual bool beginDivest()
Starts releases for all owned entities.
std::set< unsigned long long > myDivestRequestIds
Release request IDs that must succeed before the deferred action may resume.
Definition ownershipTransferManager.h:234
bool isOwnershipTransferAvailable() const
Returns true when the system-level conditions for ownership transfer are met.
virtual void requestExit()
Initiates application exit after divesting all entities owned by this station.
bool myExitCloseApproved
Allows the close event posted after a successful divest to reach VR-Vantage.
Definition ownershipTransferManager.h:228
bool myDivestInProgress
True while an exit or voluntary disconnect waits for owned entities to be divested.
Definition ownershipTransferManager.h:225
virtual void initialize(DtPlayerStationApp *app)
Stores the back-pointer to the owning application.
DtPlayerStationApp * myApp
Back-pointer to the owning DtPlayerStationApp.
Definition ownershipTransferManager.h:195
bool enabled() const
Returns true when the Ownership Transfer feature is active.
bool myEnabled
Definition ownershipTransferManager.h:197
void setIdleReleaseTimeoutSeconds(double seconds)
Sets the idle-release timeout in seconds. A value of 0.0 disables the timer. Negative values are clam...
bool myExitSkipCloseDialog
Suppresses the VR-Vantage confirmation after this manager already confirmed a close.
Definition ownershipTransferManager.h:231
DtVreMessageHandlerGroup myMessageHandlers
Member-scope instance of message handler group.
Definition ownershipTransferManager.h:222
virtual DtVreMessageResult handleDivestResponse(DtVreMessage *message)
Processes terminal responses for release requests created by beginDivest().
double idleReleaseTimeoutSeconds() const
Returns the number of seconds an owned entity may sit idle in the choose-role panel before ownership ...
DtOwnershipTransferExitEventFilter * myExitEventFilter
Main-window filter that defers close events until divest succeeds.
Definition ownershipTransferManager.h:216
virtual void completeExit()
Resumes application exit after successful divest or a failed exit-time release.
void setEnabled(bool enabled)
Sets the master feature toggle.
virtual void parseConfiguration(DtInitTable table)
Populate this instance from a DtInitTable.
uint64_t nextRequestId()
Allocates and returns the next ownership transfer request identifier.
StopConnectionDriverMessage::StopConnectionDriverData myDisconnectDriverData
Driver Data retained while the voluntary disconnect is deferred.
Definition ownershipTransferManager.h:240
double myAcquireTimeoutSeconds
Definition ownershipTransferManager.h:198
Class for managing available entities and roles for engagement.
Definition playerCreationPalette.h:59
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:155
Manager class for connecting message handlers to message types.
Definition vreMessageManager.h:292
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Provides configuration initialization for VREngage components.
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Data payload for StopConnectionDriverMessage.
Definition stopConnectionDriver.h:45
Defines the central message manager for the VREngage messaging system.