VR-Engage  2.2
Loading...
Searching...
No Matches
vrengageStatusPublisher.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vrengageStatusPublisher.h
7//! \ingroup vrfcgf
8//! \brief Defines the status publisher for VREngage applications
9//!
10//! This file contains the DtVreStatusPublisher class which is responsible for
11//! broadcasting status information about a VREngage application to other
12//! applications in the distributed simulation environment, such as VR-Forces GUI.
13//! The publisher sends periodic heartbeat messages containing application identity,
14//! player information, and entity state.
15
16#pragma once
17
19#include <vlpi/entityIdentifier.h>
20#include <vlutil/vlString.h>
21#include <vlutil/vlTime.h>
22
23namespace makVre
24{
25
26//! \brief Status publisher for VREngage applications
27//!
28//! This class is responsible for broadcasting status information about a
29//! VREngage application to other applications in the distributed simulation
30//! environment, such as VR-Forces GUI and other control applications. It sends
31//! periodic heartbeat messages containing application identity, player information,
32//! and entity state.
33//!
34//! The status publisher maintains information such as the application ID, name,
35//! player name, controlled entity ID, station name, and operational mode. This
36//! information can be updated at runtime, and the publisher will automatically
37//! track changes and send updated status messages when necessary.
39{
40public:
41 //! \brief Constructor
42 //!
43 //! Initializes a new status publisher with default values for all properties.
44 //! The heartbeat interval is initialized to a default value, and the publisher
45 //! is marked as modified to ensure a status message is sent on the next tick.
47
48 //! \brief Virtual destructor
49 //!
50 //! Ensures proper cleanup of derived classes.
52
53 //! \brief Sends a status message immediately
54 //!
55 //! This method immediately broadcasts a status message containing the current
56 //! state of the publisher. It resets the last sent time and clears the modified
57 //! flag. This method is called automatically by tick() when necessary, but can
58 //! also be called manually to force an immediate status update.
59 virtual void sendStatus();
60
61 //! \brief Sets the heartbeat interval
62 //! \param heartbeatInterval Interval in milliseconds between status messages
63 //!
64 //! This method sets the interval at which status messages are automatically
65 //! sent. The interval is specified in milliseconds. If the publisher has not
66 //! been modified since the last status message, a new status message will be
67 //! sent every heartbeatInterval milliseconds.
69
70 //! \brief Gets the current heartbeat interval
71 //! \return Current heartbeat interval in milliseconds
72 //!
73 //! This method returns the current interval at which status messages are
74 //! automatically sent.
75 virtual int heartbeatInterval();
76
77 //! \brief Updates the publisher and sends status messages when necessary
78 //!
79 //! This method is called periodically (typically by the simulation manager)
80 //! to update the publisher and send status messages when necessary. It checks
81 //! if the publisher has been modified or if the heartbeat interval has elapsed,
82 //! and sends a status message if either condition is true.
83 //!
84 //! \note This method should be called regularly to ensure timely status updates.
85 virtual void tick();
86
87 //! \brief Sets the application ID
88 //! \param id Unique identifier for this application
89 //!
90 //! This method sets the unique identifier for this VREngage application.
91 //! The ID should be unique across all participating VREngage applications
92 //! in an exercise. Setting a new ID marks the publisher as modified.
93 virtual void setId(unsigned long id);
94
95 //! \brief Gets the application ID
96 //! \return Current application ID
97 //!
98 //! This method returns the unique identifier for this VREngage application.
99 virtual unsigned long id() const;
100
101 //! \brief Sets the application name
102 //! \param name Name for this application
103 //!
104 //! This method sets the name for this VREngage application. The name should
105 //! be unique across all participating VREngage applications in an exercise,
106 //! but may be changed over the lifetime of an application. Setting a new name
107 //! marks the publisher as modified.
108 virtual void setName(const std::string& name);
109
110 //! \brief Gets the application name
111 //! \return Current application name
112 //!
113 //! This method returns the name for this VREngage application.
114 virtual std::string name() const;
115
116 //! \brief Sets the player name
117 //! \param name Name of the player using this application
118 //!
119 //! This method sets the name of the player using this VREngage application.
120 //! The player name is optional and can be used to identify the human user
121 //! controlling the application. Setting a new player name marks the publisher
122 //! as modified.
123 virtual void setPlayerName(const DtString& name);
124
125 //! \brief Gets the player name
126 //! \return Current player name
127 //!
128 //! This method returns the name of the player using this VREngage application.
129 virtual DtString playerName() const;
130
131 //! \brief Sets the controlled entity ID
132 //! \param entityId Identifier of the entity controlled by this application
133 //!
134 //! This method sets the identifier of the entity controlled by this VREngage
135 //! application. This is typically the primary entity that the player is
136 //! controlling or inhabiting. Setting a new entity ID marks the publisher as
137 //! modified and updates the static entity ID.
138 virtual void setEntityId(const DtEntityIdentifier& entityId);
139
140 //! \brief Gets the controlled entity ID
141 //! \return Current entity ID
142 //!
143 //! This method returns the identifier of the entity controlled by this
144 //! VREngage application.
145 virtual DtEntityIdentifier entityId() const;
146
147 //! \brief Gets the static controlled entity ID
148 //! \return Current static entity ID
149 //!
150 //! This static method provides access to the entity ID from anywhere in the
151 //! application without needing a reference to the status publisher instance.
152 static DtEntityIdentifier getEntityId();
153
154 //! \brief Sets the station name (player role)
155 //! \param name Name of the station/role this player is operating
156 //!
157 //! This method sets the station name, which identifies the player's role.
158 //! Available string identifiers for roles are defined in VR-Engage player
159 //! definition lua files (e.g., "Pilot", "Human", "LAV Driver", etc.).
160 //! Setting a new station name marks the publisher as modified.
161 virtual void setStationName(const std::string& name);
162
163 //! \brief Gets the station name (player role)
164 //! \return Current station name
165 //!
166 //! This method returns the station name, which identifies the player's role.
167 virtual std::string stationName() const;
168
169 //! \brief Sets the spectator mode flag
170 //! \param mode True if the player is in spectator mode, false otherwise
171 //!
172 //! This method sets the flag indicating whether the player is in spectator mode.
173 //! In spectator mode, the player is observing the simulation but not actively
174 //! controlling an entity. Setting a new spectator mode marks the publisher as
175 //! modified.
176 virtual void setSpectatorMode(bool mode);
177
178 //! \brief Gets the spectator mode flag
179 //! \return True if the player is in spectator mode, false otherwise
180 //!
181 //! This method returns the flag indicating whether the player is in spectator mode.
182 virtual bool spectatorMode() const;
183
184 //! \brief Sets the final status flag
185 //! \param status True if this is the final status message, false otherwise
186 //!
187 //! This method sets the flag indicating if this is a final status message
188 //! for the VREngage application. A final status message indicates that the
189 //! application is shutting down and will no longer be sending status updates.
190 //! Setting the final status flag to true marks the publisher as modified.
191 virtual void setFinalStatus(bool status);
192
193 //! \brief Gets the final status flag
194 //! \return True if this is the final status message, false otherwise
195 //!
196 //! This method returns the flag indicating if this is a final status message
197 //! for the VREngage application.
198 virtual bool finalStatus() const;
199
200protected:
201 //! \brief Copy constructor
202 //! \param orig Original status publisher to copy
203 //!
204 //! This copy constructor creates a new status publisher that is a copy of
205 //! the specified original. It is protected to prevent unintended copying.
207
208 //! \brief Assignment operator
209 //! \param orig Original status publisher to assign from
210 //! \return Reference to this status publisher
211 //!
212 //! This assignment operator assigns the state of the specified original
213 //! status publisher to this status publisher. It is protected to prevent
214 //! unintended assignment.
216
217protected:
218 //! \brief Interval in milliseconds between status messages
220
221 //! \brief Time when the last status message was sent
223
224 //! \brief Flag indicating if the publisher has been modified since the last message
226
227 //! \brief Unique identifier for this application
228 unsigned long long myId;
229
230 //! \brief Name of this application
231 std::string myName;
232
233 //! \brief Name of the player using this application
234 std::string myPlayerName;
235
236 //! \brief Identifier of the entity controlled by this application
237 DtEntityIdentifier myEntityId;
238
239 //! \brief Name of the station/role this player is operating
240 std::string myStationName;
241
242 //! \brief Flag indicating whether the player is in spectator mode
244
245 //! \brief Flag indicating if this is a final status message
247
248 //! \brief Static entity identifier for global access
249 //!
250 //! This static member provides access to the entity ID from anywhere in the
251 //! application without needing a reference to the status publisher instance.
252 static DtEntityIdentifier theEntityId;
253};
254
255} // namespace makVre
DtEntityIdentifier myEntityId
Identifier of the entity controlled by this application.
Definition vrengageStatusPublisher.h:237
DtVreStatusPublisher & operator=(const DtVreStatusPublisher &orig)
Assignment operator.
DtTime myTimeLastSent
Time when the last status message was sent.
Definition vrengageStatusPublisher.h:222
std::string myName
Name of this application.
Definition vrengageStatusPublisher.h:231
bool myHasBeenModified
Flag indicating if the publisher has been modified since the last message.
Definition vrengageStatusPublisher.h:225
virtual void setFinalStatus(bool status)
Sets the final status flag.
DtVreStatusPublisher()
Constructor.
virtual void setPlayerName(const DtString &name)
Sets the player name.
virtual std::string name() const
Gets the application name.
virtual ~DtVreStatusPublisher()
Virtual destructor.
int myHeartbeatInterval
Interval in milliseconds between status messages.
Definition vrengageStatusPublisher.h:219
virtual bool spectatorMode() const
Gets the spectator mode flag.
virtual DtEntityIdentifier entityId() const
Gets the controlled entity ID.
virtual int heartbeatInterval()
Gets the current heartbeat interval.
virtual void setStationName(const std::string &name)
Sets the station name (player role)
virtual DtString playerName() const
Gets the player name.
virtual std::string stationName() const
Gets the station name (player role)
virtual unsigned long id() const
Gets the application ID.
virtual bool finalStatus() const
Gets the final status flag.
static DtEntityIdentifier getEntityId()
Gets the static controlled entity ID.
std::string myStationName
Name of the station/role this player is operating.
Definition vrengageStatusPublisher.h:240
std::string myPlayerName
Name of the player using this application.
Definition vrengageStatusPublisher.h:234
virtual void setName(const std::string &name)
Sets the application name.
static DtEntityIdentifier theEntityId
Static entity identifier for global access.
Definition vrengageStatusPublisher.h:252
virtual void sendStatus()
Sends a status message immediately.
virtual void setId(unsigned long id)
Sets the application ID.
virtual void setSpectatorMode(bool mode)
Sets the spectator mode flag.
virtual void setHeartbeatInterval(int heartbeatInterval)
Sets the heartbeat interval.
virtual void tick()
Updates the publisher and sends status messages when necessary.
virtual void setEntityId(const DtEntityIdentifier &entityId)
Sets the controlled entity ID.
bool mySpectatorMode
Flag indicating whether the player is in spectator mode.
Definition vrengageStatusPublisher.h:243
bool myFinalStatus
Flag indicating if this is a final status message.
Definition vrengageStatusPublisher.h:246
DtVreStatusPublisher(const DtVreStatusPublisher &orig)
Copy constructor.
unsigned long long myId
Unique identifier for this application.
Definition vrengageStatusPublisher.h:228
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49