VR-Engage  2.2
Loading...
Searching...
No Matches
cigiSession.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5#pragma once
6
7//! @file cigiSession.h
8//!
9//! @brief DtCigiSession instances manage a connection to a single CIGI IG, and
10//! all associated Publishers.
11
12#include "vreCigiHost/export.h"
16
17#include "vreUtil/initializer.h"
18#include "vreUtil/baseClass.h"
19
20#include <vlutil/vlInetSocket.h>
21#include <vlutil/vlInetEndpoint.h>
22
23#include <CigiTypes.h>
24
25#include <memory>
26#include <map>
27
28class CigiHostSession;
29class CigiOutgoingMsg;
30
31namespace makVre
32{
33class DtCigiHost;
35
36
37class CIGIHOST_DLL DtCigiSession : public DtSpSubClass<DtCigiSession>
38{
39public:
40 using ConfigPtr = std::shared_ptr<DtInitializer>;
41
43 virtual ~DtCigiSession() override;
44
45 //! @brief CIGI Major Version for this Session
46 //! @return int representing CIGI Major Version
47 virtual unsigned int version() const;
48
50 virtual DtCigiHost& host();
51
53 virtual ConfigPtr config();
54
55 virtual Sptr setIgAddress(std::string address);
56 virtual std::string igAddress();
57
58 virtual void init();
59
60 //! @brief Called once per Sim tick. Processes all incoming CIGI packets and may send outgoing CIGI packets.
61 //!
62 //! DtCigiSession::tick is called from DtCigiHost::tick which is connected to
63 //! DtSimObjectManager::signal_advanceFrame.
64 //!
65 //! DtCigiSession::ticks process all CIGI packets received from the IG and dispatches them to
66 //! the correct Listeners.
67 //!
68 //! If a Start Of Frame is received from the IG indicating that the IG has advanced a frame, then
69 //! advanceFrame() will be called and the Publishers will be ticked and called upon to update and write
70 //! CIGI packet data. If no Start Of Frame has been received for the configured updTimeout time, the IG
71 //! will be marked as offline.
72 //!
73 //! If the IG is offline, Publishers will not be ticked, nor called to update and write CIGI data; except
74 //! for the root DtCigiIgControlPublisher publisher, which will continue to heartbeat IGCtrl CIGI packets
75 //! once per second.
76 //!
77 //! @param dt Elapsed time in seconds since the last tick.
78 virtual void tick(double dt);
79
80 //! @brief Returns the Session frame number.
81 //!
82 //! The Session frame number is published by DtCigiIgControlPublisher. The Session frame number does not
83 //! correspond to the IG frame number, but the Session frame number does advances when the IG frame
84 //! number advances.
85 virtual unsigned int frame() const;
86
87 //! @brief Advances the Session frame number, updates Publishers and sends CIGI data.
88 //!
89 //! advanceFrame ticks the root Publisher (which in turn ticks all child Publishers), then calls
90 //! packAndSendFrame(), which will call upon Publishers to update and write CIGI data.
91 virtual void advanceFrame();
92
93 //! @brief Returns online status of IG.
94 //!
95 //! The IG is considered online if a Start Of Frame packet has been received within the configured
96 //! udpTimeout window, and the Start Of Frame packet does not indicate that the IG is in Offline
97 //! Maintenance mode.
98 virtual bool igOnline();
99
100 //! @brief Returns true if the IG is online and has indicated that it is in Operate mode.
101 virtual bool igRunning();
102
103 //! @brief Begins the process of shutting down the Session.
104 //!
105 //! IG Control Mode is set to Standby and all published CIGI entity states are set to Remove/Destroyed.
106 //! The Session will continue to tick until receipt of entity removal is confirmed or the IG times out,
107 //! at which point the IP socket is closed and sessionEnded() will return true.
108 virtual void endSession();
109
110 //! @brief Returns true if endSession() has been called.
111 virtual bool endingSession();
112
113 //! @brief Returns true if the process started by endSession() is complete.
114 virtual bool sessionEnded();
115
116 //! @brief Returns a smart pointer to the root Publisher, a DtCigiIgControlPublisher class.
118
119 //! @brief Marks all publishers as dirty and clears list of publishers waiting for receipt confirmation.
120 virtual void resetPublishers();
121
122 virtual void addListener(DtCigiListenerBase::Sptr listener);
123
125 virtual void frameConfirmedReceived(unsigned int receivedFrame);
126
127 virtual Cigi_int8 terrainDatabaseId();
128
129 //! @brief Gets the next available CIGI EntityID.
130 //! @param forWho Publisher this ID will be assigned to. ID is freed when Publisher is deleted.
131 //! @return A CIGI EntityID
133
134 virtual bool useExtendedEntityType();
135 virtual bool findShortEntityType(const DtEntityType& entityType, Cigi_uint16& found_id);
136 virtual bool findCigiPartId(const DtEntityType& entityType, unsigned int partType, Cigi_uint8& found_id);
137 virtual bool findMuzzleFlashType(const DtEntityType& munitionType, Cigi_uint16& found_id);
138 virtual bool findDetonationType(const DtEntityType& munitionType, Cigi_uint16& found_id);
139
140 //! @brief In Publish Ownship Only mode, only the entity(s) with a ViewControl attached are published.
141 //! @return Bool indicating whether Publish Ownship Only mode is enabled.
142 virtual bool publishOwnshipOnly();
143
144 virtual bool findCigiViewType(const std::string& sensor, Cigi_uint8& found_type);
145 virtual int firstViewId();
146
147 using EntityPubPtr = std::shared_ptr<DtCigiSimEntityPublisher>;
148
149 //! @brief Find the SimEntityPublisher associted with the given DtEntityIdentifier.
150 //! @param entityId DtEntityIdentifier of the Sim Entity to find.
151 //! @return Shared Pointer to SimEntityPublisher associated with entityId, if there is one.
152 EntityPubPtr findEntity(const DtEntityIdentifier& entityId);
153
154 //! @brief Find the SimEntityPublisher associated with the given entityId, or create one if not found.
155 //! @param entityId DtEntityIdenifier of the Sim Entity to find, or to create a Publisher for.
156 //! @return Shared Pointer to the SimEntityPublisher associated with the given entityId.
157 EntityPubPtr findOrCreateEntity(const DtEntityIdentifier& entityId);
158
159 virtual DtInitTable findConfigTableByType(const std::string& mapName, const DtEntityType& entityType);
160
161 template <typename FIND_T, typename RETURN_T = FIND_T>
162 bool findConfigParam(DtInitTable table, const std::string paramName, RETURN_T& ret)
163 {
164 if (table.isValid())
165 {
166 if (table.hasField(paramName))
167 {
168 ret = table.findData<FIND_T>(paramName);
169 return true;
170 }
171 }
172 return false;
173 }
174
175 //! @brief Creates a new Publisher of the type registered for the given CREATE_T and Session version.
176 //! @tparam CREATE_T Type of Publisher to create. This is usually an abstract base type, and the
177 //! actual instance will be a derived concete "V#" class.
178 //! @return Shared Pointer to the new Publisher.
179 template <class CREATE_T>
180 std::shared_ptr<CREATE_T> createVersioned()
181 {
182 return CREATE_T::createVersion(version());
183 }
184
185protected:
186 virtual void openSocket();
187 virtual void initRootPublisher();
188 virtual void initListeners();
189 virtual void startSession();
190
192
194
195 virtual void packAndSendFrame();
196
198 virtual bool findCigiDatabaseId(const std::string& terrain, Cigi_int8& found_id);
199
200protected:
202
204 unsigned int myVersion;
205
207
208 std::shared_ptr<DtInetSocket> mySocket;
209 DtInetEndpoint myIgEndpoint;
210
211 std::shared_ptr<CigiHostSession> mySession;
212
214
215 unsigned int myFrame;
218
220
221 using SortedTypeSet = std::set<DtEntityType>;
222 using SortedTypeSetMap = std::map<std::string, SortedTypeSet>;
224
225 using BestTypeMatchMap = std::map<DtEntityType, DtInitTable>;
226 using BestTypeMatchMapMap = std::map<std::string, BestTypeMatchMap>;
228
229 using CigiIdMap = std::map<Cigi_uint16, DtCigiPublisherBase::Wptr>;
231 Cigi_uint16 myLastUsedId;
232
233 using FrameReceiptRequest = std::pair<DtCigiPublisherBase::Wptr, unsigned int>;
234 using FrameReceiptMap = std::map<void*, FrameReceiptRequest>;
236
237 using ListenerMap = std::map<Cigi_uint16, DtCigiListenerBase::Sptr>;
239
241
243};
244
245} // namespace makVre
Provides base classes for shared pointer managed objects with factory creation support.
Singleton foundation for the vreCigiHost system.
Publishes CIGI IG Control packets.
Definition cigiHost.h:39
virtual unsigned int frame() const
Returns the Session frame number.
virtual bool findCigiDatabaseId(const std::string &terrain, Cigi_int8 &found_id)
Cigi_int8 myTerrainDatabaseId
Definition cigiSession.h:219
virtual DtCigiHost & host()
Cigi_uint16 myLastUsedId
Definition cigiSession.h:231
virtual ConfigPtr config()
DtInetEndpoint myIgEndpoint
Definition cigiSession.h:209
double myShutdownStarted
Definition cigiSession.h:217
virtual DtInitTable findConfigTableByType(const std::string &mapName, const DtEntityType &entityType)
DtCigiHost * myHost
Definition cigiSession.h:201
std::map< void *, FrameReceiptRequest > FrameReceiptMap
Definition cigiSession.h:234
virtual bool findCigiPartId(const DtEntityType &entityType, unsigned int partType, Cigi_uint8 &found_id)
virtual bool findDetonationType(const DtEntityType &munitionType, Cigi_uint16 &found_id)
unsigned int myFrame
Definition cigiSession.h:215
std::map< std::string, SortedTypeSet > SortedTypeSetMap
Definition cigiSession.h:222
std::pair< DtCigiPublisherBase::Wptr, unsigned int > FrameReceiptRequest
Definition cigiSession.h:233
virtual bool useExtendedEntityType()
virtual void updateTerrainDatabaseId()
virtual void initRootPublisher()
EntityPubPtr findEntity(const DtEntityIdentifier &entityId)
Find the SimEntityPublisher associted with the given DtEntityIdentifier.
virtual void advanceFrame()
Advances the Session frame number, updates Publishers and sends CIGI data.
ListenerMap myListenerMap
Definition cigiSession.h:238
virtual bool findShortEntityType(const DtEntityType &entityType, Cigi_uint16 &found_id)
std::map< Cigi_uint16, DtCigiPublisherBase::Wptr > CigiIdMap
Definition cigiSession.h:229
virtual DtCigiStartOfFrameListener::Sptr igStatus()
virtual bool findCigiViewType(const std::string &sensor, Cigi_uint8 &found_type)
virtual void packAndSendFrame()
DtCigiIgControlPublisher::Sptr myIgControl
Definition cigiSession.h:213
virtual void init()
virtual Cigi_uint16 claimNextEntitytId(DtCigiPublisherBase::Sptr forWho)
Gets the next available CIGI EntityID.
virtual Sptr setHost(DtCigiHost &host)
virtual bool findMuzzleFlashType(const DtEntityType &munitionType, Cigi_uint16 &found_id)
virtual void endSession()
Begins the process of shutting down the Session.
FrameReceiptMap myFrameReceiptMap
Definition cigiSession.h:235
std::string myOverrideIgAddress
Definition cigiSession.h:206
virtual void startSession()
virtual DtCigiIgControlPublisher::Sptr rootPublisher()
Returns a smart pointer to the root Publisher, a DtCigiIgControlPublisher class.
virtual Cigi_int8 terrainDatabaseId()
virtual std::string igAddress()
virtual unsigned int version() const
CIGI Major Version for this Session.
virtual Sptr setConfig(ConfigPtr config)
CigiIdMap myCigiIdMap
Definition cigiSession.h:230
bool findConfigParam(DtInitTable table, const std::string paramName, RETURN_T &ret)
Definition cigiSession.h:162
virtual Sptr setIgAddress(std::string address)
virtual bool endingSession()
Returns true if endSession() has been called.
EntityPubPtr findOrCreateEntity(const DtEntityIdentifier &entityId)
Find the SimEntityPublisher associated with the given entityId, or create one if not found.
virtual ~DtCigiSession() override
virtual bool igRunning()
Returns true if the IG is online and has indicated that it is in Operate mode.
std::map< std::string, BestTypeMatchMap > BestTypeMatchMapMap
Definition cigiSession.h:226
std::map< Cigi_uint16, DtCigiListenerBase::Sptr > ListenerMap
Definition cigiSession.h:237
virtual int firstViewId()
virtual bool publishOwnshipOnly()
In Publish Ownship Only mode, only the entity(s) with a ViewControl attached are published.
std::shared_ptr< CigiHostSession > mySession
Definition cigiSession.h:211
std::shared_ptr< DtInetSocket > mySocket
Definition cigiSession.h:208
std::shared_ptr< DtInitializer > ConfigPtr
Definition cigiSession.h:40
bool myFakeIgHeartbeat
Definition cigiSession.h:240
virtual void openSocket()
BestTypeMatchMapMap myBestTypeMatchMapMap
Definition cigiSession.h:227
std::shared_ptr< DtCigiSimEntityPublisher > EntityPubPtr
Definition cigiSession.h:147
virtual bool sessionEnded()
Returns true if the process started by endSession() is complete.
SortedTypeSetMap mySortedTypeSetMap
Definition cigiSession.h:223
unsigned int myVersion
Definition cigiSession.h:204
std::set< DtEntityType > SortedTypeSet
Definition cigiSession.h:221
virtual void resetPublishers()
Marks all publishers as dirty and clears list of publishers waiting for receipt confirmation.
std::map< DtEntityType, DtInitTable > BestTypeMatchMap
Definition cigiSession.h:225
virtual void initListeners()
virtual void frameConfirmedReceived(unsigned int receivedFrame)
bool myShuttingDown
Definition cigiSession.h:242
double myLastFrameTime
Definition cigiSession.h:216
virtual bool igOnline()
Returns online status of IG.
ConfigPtr myConfig
Definition cigiSession.h:203
virtual void addListener(DtCigiListenerBase::Sptr listener)
virtual void tick(double dt)
Called once per Sim tick. Processes all incoming CIGI packets and may send outgoing CIGI packets.
virtual void requestFrameReceipt(DtCigiPublisherBase::Wptr publisher)
virtual void checkForIncomingPackets()
std::shared_ptr< CREATE_T > createVersioned()
Creates a new Publisher of the type registered for the given CREATE_T and Session version.
Definition cigiSession.h:180
Definition cigiSimEntityPublisher.h:15
Table-based access to Lua state for configuration data.
Definition initializer.h:38
RT findData(const std::string &name, bool resolveDots=true)
Definition initializer.h:175
virtual bool isValid() const
Checks if this object is valid.
virtual bool hasField(const std::string &name, bool resolveDots=true)
Checks if the table has a field with the given name.
std::shared_ptr< DtSpObject > Sptr
Shared pointer type alias.
Definition baseClass.h:99
std::weak_ptr< DtSpObject > Wptr
Weak pointer type alias.
Definition baseClass.h:102
DtSpSubClass()
Definition baseClass.h:190
std::shared_ptr< DtCigiSession > Sptr
Definition baseClass.h:184
Contains the DLL export macro.
#define CIGIHOST_DLL
Definition export.h:20
Provides configuration initialization for VREngage components.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49