VR-Engage  2.2
Loading...
Searching...
No Matches
vreCommunicationManager.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
6//! \file vreCommunicationManager.h
7//! \ingroup vrePlayerStation.dll
8//! \brief Contains the DtVreCommunicationManager class for connecting and managing communication with VR-Link.
9
10#pragma once
11
12#include "export.h"
13
15
16#include <vrfMsgTransport/communicationManager.h>
17#include <vrvUtil/DtVirtualBaseClass.h>
18#include <boost/signals2.hpp>
19
20#include <set>
21
22namespace makVrv
23{
24class DtBaseConnection;
25} // namespace makVrv
26
27class DtMtlParameterDb;
28class DtSimulationModelSet;
29
30namespace makVre
31{
32//! \brief This class manages communication between player stations and VR-Link connections
33//!
34//! DtVreCommunicationManager provides functionality for managing simulation model sets,
35//! parameter databases, and frame updates. It serves as a bridge between the player station
36//! and the underlying VR-Link connection, handling pre and post thread ticks for frame advancement.
37class MESSAGEMANAGER_DLL DtVreCommunicationManager : public DtCommunicationManager, public makVrv::DtVirtualBaseClass
38{
39public:
40 //! \brief Constructor for the communication manager
41 //! \param addr The simulation address to be used
42 //! \param sm Pointer to the state data manager (optional)
43 //! \param threadPoolSize Size of the thread pool; -1 uses default size
45 const DtSimulationAddress& addr, makVrf::DtStateDataManager* sm = 0, int threadPoolSize = -1);
46
47 //! \brief Virtual destructor
48 virtual ~DtVreCommunicationManager() override;
49
50 //! \brief Gets or creates a singleton instance of DtVreCommunicationManager for the given connection
51 //! \param conn Reference to the VR-Link connection to associate with the instance
52 //! \return Reference to the singleton instance
53 //!
54 //! If an instance doesn't exist, one will be created and registered with the connection
55 static DtVreCommunicationManager& instance(makVrv::DtBaseConnection& conn);
56
57 //! \brief Registers an instance with the connection and connects it for updates
58 //! \param sim Reference to the VR-Link connection
59 //! \param instance Pointer to the instance to register
60 static void registerInstance(
61 makVrv::DtBaseConnection& sim, DtVreCommunicationManager* instance);
62
63 //! \brief Factory method to create a new communication manager
64 //! \param addr The simulation address to use
65 //! \param sm Pointer to the state data manager (optional)
66 //! \param threadPoolSize Size of the thread pool; -1 uses default size
67 //! \return Pointer to a newly created DtCommunicationManager
68 static DtCommunicationManager* creator(
69 const DtSimulationAddress& addr, makVrf::DtStateDataManager* sm = 0, int threadPoolSize = -1);
70
71 //! \brief Connects for pre/post tick to be able to advance frame
72 //! \param vrlConn Reference to the VR-Link connection to connect to
73 //!
74 //! This function connects the manager to the pre and post tick signals of the VR-Link connection,
75 //! allowing automatic frame advancement. Call disconnectForUpdate to disable this
76 //! and handle the updates yourself.
77 virtual void connectForUpdate(makVrv::DtBaseConnection& vrlConn);
78
79 //! \brief Disconnects from pre/post tick signals
80 //!
81 //! Disconnects the manager from the pre and post tick signals,
82 //! disabling automatic frame advancement.
83 virtual void disconnectForUpdate();
84
85 //! \brief Sets the simulation model sets from a vector of DtFilename objects
86 //! \param smss Vector of DtFilename objects representing simulation model sets
87 //! \return True if the model sets were changed, false otherwise
88 virtual bool setSimulationModelSets(const std::vector<DtFilename>& smss);
89
90 //! \brief Sets the simulation model sets from a vector of strings
91 //! \param smss Vector of strings representing simulation model sets
92 //! \return True if the model sets were changed, false otherwise
93 virtual bool setSimulationModelSets(const std::vector<std::string>& smss);
94
95 //! \brief Sets the simulation model sets from a set of strings
96 //! \param smss Set of strings representing simulation model sets
97 //! \return True if the model sets were changed, false otherwise
98 virtual bool setSimulationModelSets(const std::set<std::string>& smss);
99
100 //! \brief Sets the simulation model sets from a vector of DtString objects
101 //! \param smss Vector of DtString objects representing simulation model sets
102 //! \return True if the model sets were changed, false otherwise
103 virtual bool setSimulationModelSets(const std::vector<DtString>& smss);
104
105 //! \brief Adds a single simulation model set
106 //! \param sms String representing the simulation model set to add
107 virtual void addSimulationModelSet(const std::string& sms);
108
109 //! \brief Clears all simulation model sets
110 virtual void clearSimModelSets();
111
112 //! \brief Gets the current simulation model sets
113 //! \return Constant reference to the vector of simulation model sets
114 virtual const std::vector<DtFilename>& simulationModelSets() { return mySimulationModelSets; };
115
116 //! \brief Sets the parameter database for the communication manager
117 //! \param parameterDb Pointer to the parameter database to use
118 //! \note The parameter database is cast to DtMtlParameterDb internally
119 virtual void setParameterDatabase(DtVrfParameterDb* parameterDb) override;
120
121protected:
122 //! \brief Slot called before each thread tick
123 //!
124 //! Calls beginFrame to prepare for the next simulation frame
125 virtual void slot_preThreadTick();
126
127 //! \brief Slot called after each thread tick
128 //!
129 //! Calls advanceFrame to complete the current simulation frame and
130 //! handles parameter database updates if simulation model sets have changed
131 virtual void slot_postThreadTick();
132
133 //! \brief Sets up the parameter database with the current simulation model sets
134 //! \return True if the parameter database was set up successfully, false otherwise
135 //!
136 //! Creates a new parameter database if one doesn't exist, then loads all OPD files
137 //! from the simulation model sets into the database
139
140 //! \brief Parses OPD files from a simulation model set
141 //! \param smsToLoad The simulation model set to load
142 //! \param opdFiles Vector to store the found OPD files
143 //! \param searchPaths Vector to store the search paths
144 //!
145 //! Recursively processes included simulation model sets and collects
146 //! all OPD files and search paths
147 virtual void parseOPDFiles(
148 const DtFilename& smsToLoad, std::vector<DtFilename>& opdFiles, std::vector<DtFilename>& searchPaths);
149
150protected:
151 //! \brief Connection to the pre-tick signal
152 boost::signals2::scoped_connection myPreTickConnection;
153
154 //! \brief Connection to the post-tick signal
155 boost::signals2::scoped_connection myPostTickConnection;
156
157 //! \brief Pointer to the parameter database
158 DtMtlParameterDb* myParamDB;
159
160 //! \brief Last used search paths for the parameter database
161 std::vector<DtFilename> myLastSearchPaths;
162
163 //! \brief Current simulation model sets
164 std::vector<DtFilename> mySimulationModelSets;
165
166 //! \brief Flag indicating whether simulation model sets have changed
168
169 //! \brief Timer for parameter database updates
171};
172} // namespace makVre
static DtVreCommunicationManager & instance(makVrv::DtBaseConnection &conn)
Gets or creates a singleton instance of DtVreCommunicationManager for the given connection.
bool mySmsChanged
Flag indicating whether simulation model sets have changed.
Definition vreCommunicationManager.h:167
virtual void slot_postThreadTick()
Slot called after each thread tick.
static DtCommunicationManager * creator(const DtSimulationAddress &addr, makVrf::DtStateDataManager *sm=0, int threadPoolSize=-1)
Factory method to create a new communication manager.
std::vector< DtFilename > mySimulationModelSets
Current simulation model sets.
Definition vreCommunicationManager.h:164
virtual bool setSimulationModelSets(const std::set< std::string > &smss)
Sets the simulation model sets from a set of strings.
virtual void parseOPDFiles(const DtFilename &smsToLoad, std::vector< DtFilename > &opdFiles, std::vector< DtFilename > &searchPaths)
Parses OPD files from a simulation model set.
double myParamDBTimerStart
Timer for parameter database updates.
Definition vreCommunicationManager.h:170
std::vector< DtFilename > myLastSearchPaths
Last used search paths for the parameter database.
Definition vreCommunicationManager.h:161
DtVreCommunicationManager(const DtSimulationAddress &addr, makVrf::DtStateDataManager *sm=0, int threadPoolSize=-1)
Constructor for the communication manager.
virtual void addSimulationModelSet(const std::string &sms)
Adds a single simulation model set.
virtual void disconnectForUpdate()
Disconnects from pre/post tick signals.
virtual bool setSimulationModelSets(const std::vector< DtString > &smss)
Sets the simulation model sets from a vector of DtString objects.
DtMtlParameterDb * myParamDB
Pointer to the parameter database.
Definition vreCommunicationManager.h:158
virtual void connectForUpdate(makVrv::DtBaseConnection &vrlConn)
Connects for pre/post tick to be able to advance frame.
virtual bool setSimulationModelSets(const std::vector< DtFilename > &smss)
Sets the simulation model sets from a vector of DtFilename objects.
virtual bool setupParameterDatabase()
Sets up the parameter database with the current simulation model sets.
virtual const std::vector< DtFilename > & simulationModelSets()
Gets the current simulation model sets.
Definition vreCommunicationManager.h:114
virtual bool setSimulationModelSets(const std::vector< std::string > &smss)
Sets the simulation model sets from a vector of strings.
static void registerInstance(makVrv::DtBaseConnection &sim, DtVreCommunicationManager *instance)
Registers an instance with the connection and connects it for updates.
virtual void clearSimModelSets()
Clears all simulation model sets.
virtual ~DtVreCommunicationManager() override
Virtual destructor.
boost::signals2::scoped_connection myPreTickConnection
Connection to the pre-tick signal.
Definition vreCommunicationManager.h:152
boost::signals2::scoped_connection myPostTickConnection
Connection to the post-tick signal.
Definition vreCommunicationManager.h:155
virtual void setParameterDatabase(DtVrfParameterDb *parameterDb) override
Sets the parameter database for the communication manager.
virtual void slot_preThreadTick()
Slot called before each thread tick.
Defines export macros for the VREngage Message Manager library.
#define MESSAGEMANAGER_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Definition appLauncherComponent.h:28
Defines the base class for all VREngage messages.