VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
webLVCClientSession.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <set>
9 #include <map>
10 #include <vector>
11 #include <tbb/mutex.h>
12 #include <vrfutil/tracyLocks.h>
13 #include <string>
14 #include <chrono>
15 #include <json/json.h>
16 #include "webLVCTypes.h"
17 #include "webLVCMessage.h"
18 #include <iomanip>
19 #include <sstream>
20 
21 extern const char DtClientSessionMutexName[];
22 
29 {
30  // Per-client mutex - protects all data in this client session
31  mutable tbb::mutex mutex;
32 
33  // Connection state
34  bool connected = false; // True after successful Connect handshake
35  std::string clientName; // From Connect message
36  std::string wsUserName; // From Connect message (optional) - WebSocket-level identity only
37  std::string hostname; // From Connect message (optional)
38  std::string sessionKey; // Bearer session key associated with this connection
39  double webLVCVersion = 1.0; // Negotiated protocol version
40  std::chrono::system_clock::time_point connectedAt; // Wall-clock time of successful Connect handshake
41 
42  // Subscription state — initialised to all known categories so every client
43  // receives all message types by default (backward compatible).
44  // Modified at any time via the SubscribeMessageTypes message.
45  static std::set<DtWeblvc::DtMessageCategory> allCategories()
46  {
47  return {
55  };
56  }
57 
58  // Configuration per Section 5.3.3
60 
61  // Update frequency configuration (per connection)
62  double updateFrequencyHz = 1.0; // Updates per second (0 = on-change-only)
63  bool onChangeOnly = false; // If true, only send on changes (ignore frequency)
64 
65  // Track which entities this client has received
66  std::set<std::string> knownObjects;
67 
68  // Track which tactical graphics this client has received
69  std::set<std::string> knownTacticalGraphics;
70 
71  // Cache of last sent attributes per entity (for delta updates)
72  // Key is ObjectName, value is the last sent attributes Json::Value
73  std::map<std::string, Json::Value> lastSentAttributes;
74 
75  // Cache of last sent tactical graphic attributes per object (for delta updates)
76  std::map<std::string, Json::Value> lastSentTGAttributes;
77 
78  // Track which aggregates this client has received
79  std::set<std::string> knownAggregates;
80 
81  // Cache of last sent aggregate attributes per object (for delta updates)
82  std::map<std::string, Json::Value> lastSentAggregateAttributes;
83 
84  // Track which contact reports this client has received
85  std::set<std::string> knownContactReports;
86 
87  // Cache of last sent contact report attributes per report (for delta updates)
88  std::map<std::string, Json::Value> lastSentContactReportAttributes;
89 
90  // Per-client message category subscriptions.
91  // Contains all categories by default (opt-out model).
92  // Set by the SubscribeMessageTypes message.
93  std::set<DtWeblvc::DtMessageCategory> subscribedCategories = allCategories();
94 
96  bool suppressSpatial = false;
97 
102  {
103  return subscribedCategories.count(cat) > 0;
104  }
105 
110  void resetObjects(const std::vector<std::string>& uuids)
111  {
112  for (const auto& uuid : uuids)
113  {
114  knownObjects.erase(uuid);
115  lastSentAttributes.erase(uuid);
116  knownTacticalGraphics.erase(uuid);
117  lastSentTGAttributes.erase(uuid);
118  knownAggregates.erase(uuid);
119  lastSentAggregateAttributes.erase(uuid);
120  knownContactReports.erase(uuid);
122  }
123  }
124 
130  {
131  knownObjects.clear();
132  lastSentAttributes.clear();
133  knownTacticalGraphics.clear();
134  lastSentTGAttributes.clear();
135  knownAggregates.clear();
137  knownContactReports.clear();
139  }
140 
147  void setSubscriptions(const std::set<DtWeblvc::DtMessageCategory>& newCategories,
148  bool newSuppressSpatial)
149  {
150  const bool hadEntities = isSubscribed(DtWeblvc::DtMessageCategory::Entities);
153  const bool hadContactReports = isSubscribed(DtWeblvc::DtMessageCategory::ContactReports);
154 
155  subscribedCategories = newCategories;
156 
158  {
159  knownObjects.clear();
160  lastSentAttributes.clear();
161  }
163  {
164  knownTacticalGraphics.clear();
165  lastSentTGAttributes.clear();
166  }
168  {
169  knownAggregates.clear();
171  }
173  {
174  knownContactReports.clear();
176  }
177  if (newSuppressSpatial != suppressSpatial)
178  {
179  knownObjects.clear();
180  lastSentAttributes.clear();
181  knownTacticalGraphics.clear();
182  lastSentTGAttributes.clear();
183  knownAggregates.clear();
185  knownContactReports.clear();
187  }
188  suppressSpatial = newSuppressSpatial;
189  }
190 
191  // Per-client error log per Section 5.7
192  std::vector<DtWeblvc::DtLogEntry> logEntries;
193 
194  // Message statistics
195  uint64_t messagesSent = 0;
196  uint64_t messagesReceived = 0;
197  uint64_t bytesSent = 0;
198  uint64_t bytesReceived = 0;
199  std::chrono::steady_clock::time_point statsStartTime{std::chrono::steady_clock::now()};
200 
201  // Last statistics reading (for interval calculation)
202  uint64_t lastStatsSent = 0;
203  uint64_t lastStatsReceived = 0;
204  uint64_t lastBytesSent = 0;
205  uint64_t lastBytesReceived = 0;
206  std::chrono::steady_clock::time_point lastStatsTime{std::chrono::steady_clock::now()};
207 
208  // Helper to add log entry
209  void addLog(const std::string& message)
210  {
211  DtWeblvc::DtLogEntry entry;
213  entry.message = message;
214  logEntries.push_back(entry);
215  }
216 
217  // Return connectedAt as an ISO 8601 string (assumes connectedAt has been set)
218  std::string connectedAtISO8601() const
219  {
220  auto tt = std::chrono::system_clock::to_time_t(connectedAt);
221  std::tm tm{};
222 #ifdef _WIN32
223  gmtime_s(&tm, &tt);
224 #else
225  gmtime_r(&tt, &tm);
226 #endif
227  std::ostringstream oss;
228  oss << std::put_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
229  return oss.str();
230  }
231 };
uint64_t messagesSent
Definition: webLVCClientSession.h:195
bool isSubscribed(DtWeblvc::DtMessageCategory cat) const
Return true if the client wants to receive messages of the given category. Always true when subscribe...
Definition: webLVCClientSession.h:101
uint64_t lastStatsReceived
Definition: webLVCClientSession.h:203
tbb::mutex mutex
Definition: webLVCClientSession.h:31
std::string getISO8601Timestamp()
Get ISO 8601 formatted timestamp for logging.
Definition: webLVCTypes.h:67
ContactReportAttributeUpdate / ContactReportAttributeUpdateMultiple / ObjectDeleted for contact repor...
DtTimestampFormat
Definition: webLVCTypes.h:26
DtWeblvc::DtTimestampFormat timestampFormat
Definition: webLVCClientSession.h:59
std::set< std::string > knownAggregates
Definition: webLVCClientSession.h:79
std::set< std::string > knownContactReports
Definition: webLVCClientSession.h:85
std::chrono::system_clock::time_point connectedAt
Definition: webLVCClientSession.h:40
std::map< std::string, Json::Value > lastSentAggregateAttributes
Definition: webLVCClientSession.h:82
const char DtClientSessionMutexName[]
std::set< std::string > knownTacticalGraphics
Definition: webLVCClientSession.h:69
std::string message
Definition: webLVCMessage.h:380
AggregateAttributeUpdate / AggregateAttributeUpdateMultiple / ObjectDeleted for aggregates.
void setSubscriptions(const std::set< DtWeblvc::DtMessageCategory > &newCategories, bool newSuppressSpatial)
Replace the subscription set. Categories that are removed have their corresponding known-object sets ...
Definition: webLVCClientSession.h:147
uint64_t messagesReceived
Definition: webLVCClientSession.h:196
DtMessageCategory
Logical categories of server-to-client push messages a client may subscribe to. A client that does no...
Definition: webLVCMessage.h:78
std::chrono::steady_clock::time_point statsStartTime
Definition: webLVCClientSession.h:199
bool onChangeOnly
Definition: webLVCClientSession.h:63
void addLog(const std::string &message)
Definition: webLVCClientSession.h:209
uint64_t bytesReceived
Definition: webLVCClientSession.h:198
std::string connectedAtISO8601() const
Definition: webLVCClientSession.h:218
std::chrono::steady_clock::time_point lastStatsTime
Definition: webLVCClientSession.h:206
std::map< std::string, Json::Value > lastSentTGAttributes
Definition: webLVCClientSession.h:76
uint64_t lastStatsSent
Definition: webLVCClientSession.h:202
std::set< DtWeblvc::DtMessageCategory > subscribedCategories
Definition: webLVCClientSession.h:93
EntityAttributeUpdate / EntityAttributeUpdateMultiple / ObjectDeleted for entities.
void resetAllObjects()
Erase the diff cache for every tracked object across all object families. On the next update tick the...
Definition: webLVCClientSession.h:129
std::string timestamp
Definition: webLVCMessage.h:379
Log entry per Section 5.7.2.
Definition: webLVCMessage.h:377
std::set< std::string > knownObjects
Definition: webLVCClientSession.h:66
void resetObjects(const std::vector< std::string > &uuids)
Erase the diff cache for the specified UUIDs across all object families (entities, tactical graphics, aggregates). On the next update tick the server will re-send full attribute state for each UUID as if it were new. Caller must hold this session&#39;s mutex.
Definition: webLVCClientSession.h:110
uint64_t bytesSent
Definition: webLVCClientSession.h:197
ScenarioRolesStatus / PlayerRolesStatus.
double updateFrequencyHz
Definition: webLVCClientSession.h:62
std::map< std::string, Json::Value > lastSentAttributes
Definition: webLVCClientSession.h:73
bool connected
Definition: webLVCClientSession.h:34
std::vector< DtWeblvc::DtLogEntry > logEntries
Definition: webLVCClientSession.h:192
std::string clientName
Definition: webLVCClientSession.h:35
uint64_t lastBytesSent
Definition: webLVCClientSession.h:204
static std::set< DtWeblvc::DtMessageCategory > allCategories()
Definition: webLVCClientSession.h:45
std::string hostname
Definition: webLVCClientSession.h:37
uint64_t lastBytesReceived
Definition: webLVCClientSession.h:205
TacticalGraphicAttributeUpdate / TacticalGraphicAttributeUpdateMultiple / ObjectDeleted for TGs...
std::map< std::string, Json::Value > lastSentContactReportAttributes
Definition: webLVCClientSession.h:88
std::string wsUserName
Definition: webLVCClientSession.h:36
WebLVC Client Session - Tracks state for each connected client per SISO-STD-017-2022 Section 5...
Definition: webLVCClientSession.h:28
Interaction / InteractionMultiple.
std::string sessionKey
Definition: webLVCClientSession.h:38
bool suppressSpatial
Suppress spatial/dynamic attributes across all object updates when true (set via SubscribeMessageType...
Definition: webLVCClientSession.h:96
double webLVCVersion
Definition: webLVCClientSession.h:39

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)