VR-Engage  2.2
Loading...
Searching...
No Matches
extendedStateConnector.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file extendedStateConnector.h
7//! \brief Defines the DtExtendedStateConnector class for extended entity state handling
8//!
9//! This connector provides access to extended state properties of entities in the
10//! simulation, supporting various data types and value retrieval mechanisms.
11
12#pragma once
13
14#include "export.h"
15
18
19#include <string>
20#include <map>
21#include <memory>
22
23//! \brief Forward declaration of the reflected extended entity list class
24class DtReflectedExtEntityList;
25
26//! \brief Forward declaration of the reflected extended entity class
27class DtReflectedExtEntity;
28
29namespace makVre
30{
31//! \brief Connector for handling extended state properties of simulation entities
32//!
33//! DtExtendedStateConnector manages access to extended state properties of entities
34//! in the simulation. It provides mechanisms to request specific property values,
35//! monitor entity states, and convert between different data types. The connector
36//! supports bool, int, float, string, and more complex types like ammo clip maps.
38{
39public:
40 //! \brief Default constructor
41 //!
42 //! Initializes member variables with default values
44
45 //! \brief Virtual destructor
46 virtual ~DtExtendedStateConnector() override;
47
48 //! \brief Installs the extended state connector with the application and connection
49 //! \param app Pointer to the player station application
50 //! \param connection Pointer to the protocol-specific VR-Link connection
51 //!
52 //! Registers message handlers for extended state requests and initialization,
53 //! and retrieves the reflected extended entity list
54 virtual void install(
55 DtPlayerStationApp* app, makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* connection) override;
56
57 //! \brief Performs periodic processing of entity state updates
58 //!
59 //! For monitored entities, checks and sends updates for registered state properties
60 virtual void tick() override;
61
62 //! \brief Shuts down the extended state connector
63 //!
64 //! Removes message handlers for extended state requests and initialization
65 virtual void shutdown() override;
66
67protected:
68 //! \brief Handles requests for extended state properties
69 //! \param msg Pointer to the extended state request message
70 //! \return Message result indicating how the message was handled
71 //!
72 //! Processes ExtendedStateRequestMessage by finding the requested entity and
73 //! sending the requested state property or extended data
75
76 //! \brief Handles initialization of extended state monitoring
77 //! \param msg Pointer to the extended state monitor initialization message
78 //! \return Message result indicating how the message was handled
79 //!
80 //! Processes ExtendedStateMonitorInitMessage by setting up tracking for
81 //! the requested entity and state properties
83
84 //! \brief Finds an extended entity by its identifier
85 //! \param entityId The entity identifier to look up
86 //! \return Pointer to the found extended entity, or nullptr if not found
87 //!
88 //! Searches the reflected extended entity list for an entity with the given ID
89 virtual DtReflectedExtEntity* findEntity(DtEntityIdentifier entityId);
90
91 //! \brief Sends an attribute message with a specific value type
92 //! \tparam ValueType The type of the attribute value
93 //! \tparam MessageType The type of message to create and send
94 //! \param name The name of the attribute
95 //! \param value The value of the attribute
96 //! \param entityId The entity identifier to associate with the message
97 //!
98 //! Creates and queues a message containing the attribute name, value, and entity ID
99 template <typename ValueType, typename MessageType>
100 void sendAttributeMessage(const std::string& name, ValueType value, const DtEntityIdentifier& entityId);
101
102 //! \brief Sends a state property message with type conversion
103 //! \tparam RwType The reader/writer type for the property
104 //! \tparam ValueType The target value type
105 //! \tparam MessageType The type of message to create and send
106 //! \param entity Pointer to the entity containing the property
107 //! \param name The name of the state property
108 //! \return True if the property was found and sent, false otherwise
109 //!
110 //! Looks up a property of the specified reader/writer type, converts it to the
111 //! target value type, and sends it in a message of the specified message type
112 template <typename RwType, typename ValueType, typename MessageType>
113 bool sendStatePropertyMessage(DtReflectedExtEntity* entity, const std::string& name);
114
115 //! \brief Sends an extended data message for a specific entity
116 //! \param entity Pointer to the entity containing the extended data
117 //! \param name The name of the extended data property
118 //! \param type The type of the extended data property
119 //!
120 //! Creates and sends a message containing extended data from the entity
121 virtual void sendExtendedDataMessage(DtReflectedExtEntity* entity, const std::string& name, const std::string& type);
122
123 //! \brief Sends a state property message with type dispatching
124 //! \param entity Pointer to the entity containing the property
125 //! \param name The name of the state property
126 //! \param type The type of the state property ("bool", "int", "float", "string", "ammoClipMap")
127 //! \return True if the property was found and sent, false otherwise
128 //!
129 //! Dispatches to the appropriate typed sendStatePropertyMessage based on the type string
131 DtReflectedExtEntity* entity, const std::string& name, const std::string& type);
132
133 //! \brief Logs a warning about missing extended state data
134 //! \param name The name of the missing state property
135 //! \param type The type of the missing state property
136 //!
137 //! Logs a warning message the first time a specific state property is not found.
138 //! Subsequent missing properties with the same name and type won't generate
139 //! additional log messages to prevent log spam.
140 void logMissingStateProperty(const std::string& name, const std::string& type);
141
142 //! \brief Mapping of state names to their types
143 std::map<std::string, std::string> myNameTypeMap;
144
145 //! \brief Mapping of property names to their types
146 std::map<std::string, std::string> myPropertyTypeMap;
147
148 //! \brief Entity identifier for the monitored entity
149 DtEntityIdentifier myEntityId;
150
151 //! \brief Global object designator for the monitored entity
152 DtGlobalObjectDesignator myGlobalId;
153
154 //! \brief Pointer to the reflected extended entity list
155 DtReflectedExtEntityList* myRel;
156
157 //! \brief Cache for extended state data that is missing
158 //!
159 //! Used to limit the amount of warning messages put into the log by
160 //! tracking which properties have already had warnings issued
161 std::set<std::string> myMissingStateProperties;
162};
163} // namespace makVre
Base class for all simulation event connectors in VREngage.
Definition simEventConnector.h:54
virtual DtConnectorType type()
Gets the connector type.
Definition connector.h:58
virtual std::string name()
Gets the connector name.
Definition connector.h:64
DtExtendedStateConnector()
Default constructor.
void sendAttributeMessage(const std::string &name, ValueType value, const DtEntityIdentifier &entityId)
Sends an attribute message with a specific value type.
virtual void shutdown() override
Shuts down the extended state connector.
std::set< std::string > myMissingStateProperties
Cache for extended state data that is missing.
Definition extendedStateConnector.h:161
DtEntityIdentifier myEntityId
Entity identifier for the monitored entity.
Definition extendedStateConnector.h:149
std::map< std::string, std::string > myPropertyTypeMap
Mapping of property names to their types.
Definition extendedStateConnector.h:146
bool sendStatePropertyMessage(DtReflectedExtEntity *entity, const std::string &name)
Sends a state property message with type conversion.
void logMissingStateProperty(const std::string &name, const std::string &type)
Logs a warning about missing extended state data.
virtual ~DtExtendedStateConnector() override
Virtual destructor.
virtual DtVreMessageResult handleExtendedRequest(DtVreMessage *msg)
Handles requests for extended state properties.
virtual DtVreMessageResult handleExtendedInit(DtVreMessage *msg)
Handles initialization of extended state monitoring.
virtual void sendExtendedDataMessage(DtReflectedExtEntity *entity, const std::string &name, const std::string &type)
Sends an extended data message for a specific entity.
virtual bool sendStatePropertyMessage(DtReflectedExtEntity *entity, const std::string &name, const std::string &type)
Sends a state property message with type dispatching.
DtGlobalObjectDesignator myGlobalId
Global object designator for the monitored entity.
Definition extendedStateConnector.h:152
DtReflectedExtEntityList * myRel
Pointer to the reflected extended entity list.
Definition extendedStateConnector.h:155
virtual DtReflectedExtEntity * findEntity(DtEntityIdentifier entityId)
Finds an extended entity by its identifier.
std::map< std::string, std::string > myNameTypeMap
Mapping of state names to their types.
Definition extendedStateConnector.h:143
virtual void tick() override
Performs periodic processing of entity state updates.
virtual void install(DtPlayerStationApp *app, makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection *connection) override
Installs the extended state connector with the application and connection.
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:163
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
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base DtSimEventConnector class for VREngage simulation events.
Defines the base class for all VREngage messages.