WSF
WsfExtInterface.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFEXTINTERFACE_HPP
13#define WSFEXTINTERFACE_HPP
14
15#include "wsf_export.h"
16
17#include <bitset>
18#include <cstdint>
19#include <iosfwd>
20#include <map>
21#include <set>
22#include <string>
23
24#include "UtCallback.hpp"
25#include "UtCallbackHolder.hpp"
26#include "UtRandom.hpp"
27#include "WsfComm.hpp"
28#include "WsfComponent.hpp"
31#include "WsfStringId.hpp"
36
37class UtInput;
38class WsfExtEmission;
39class WsfObject;
40class WsfPlatform;
41class WsfScenario;
42
43class WsfExtData;
44
46{
47public:
48 virtual bool CompleteLoad(WsfScenario& aScenario) { return true; }
49 virtual void PrintEmitterTypes(WsfScenario& aScenario, std::ostream& aStream) {}
50};
51
55{
56public:
59
60 WsfExtData(WsfScenario& aScenario);
61 virtual ~WsfExtData();
62
63 void AddComponent(Component* aComponentPtr) { mComponents.AddComponent(aComponentPtr); }
64 const ComponentList& GetComponents() const { return mComponents; }
65
66 virtual bool ProcessInput(WsfScenario& aScenario, UtInput& aInput);
67
69
70 bool ProcessDeadReckonInput(UtInput& aInput);
71 void ProcessEntityType(UtInput& aInput);
72
73 void ProcessRadioEntityType(UtInput& aInput);
74 void ProcessExternalEntity(UtInput& aInput);
75 void ProcessExternalType(UtInput& aInput);
76 // Allow other modules to set a specific entity id value during run-time if a new
77 // entity is created after start time = 0 seconds.
78 bool ProcessEntityId(std::string aName, int aEntityId);
79
80 void ProcessEntityId(UtInput& aInput);
81
82 void WriteEntityTypes(WsfScenario& aScenario, std::ostream& aStream);
83 void WriteEmitterTypes(WsfScenario& aScenario, std::ostream& aStream);
84
85 bool GetEntityType(WsfStringId aObjectTypeId, WsfExtEntityType& aEntityType) const;
86 bool GetRadioEntityType(WsfStringId aCommTypeId, WsfExtRadioEntityType& aEntityType) const;
87
88 bool GetEntityType(const WsfObject* aObjectPtr, WsfExtEntityType& aEntityType) const;
89 int GetForceId(WsfStringId aSideId) const;
90
91 WsfStringId GetSideId(int aForceId) const;
92
93 static void ReadEntityType(UtInput& aInput, WsfExtEntityType& aEntityType);
94 static void ReadEntityId(UtInput& aInput, WsfExtEntityId& aEntityId);
95
96 static void ReadRadioEntityType(UtInput& aInput, WsfExtRadioEntityType& aEntityType);
97
98 static void ConvertInputToEntityId(std::string& aInput, WsfExtEntityId& aEntityId);
99
100
101 static void ConvertInputToEntityType(std::string& aInput, WsfExtEntityType& aEntityType);
102
103 static void ConvertInputToRadioEntityType(std::string& aInput, WsfExtRadioEntityType& aEntityType);
104
105 void SelectEntityType(WsfPlatform* aPlatformPtr, WsfExtEntityType& aEntityType) const;
106
107 WsfStringId GetStringId(const WsfExtEntityType& aEntityType) const;
108
109 WsfStringId GetStringId(const WsfExtRadioEntityType& aEntityType) const;
110
111 bool GetRadioEntityType(const wsf::comm::Comm* aCommPtr, WsfExtRadioEntityType& aEntityType) const;
112
113
114 bool CompleteLoad(WsfScenario& aScenario);
115
117 std::set<WsfStringId> mPrivateTypeId;
118 std::set<WsfStringId> mPrivateNameId;
120 uint16_t mStartEntity;
121 unsigned short mSiteId;
122 unsigned short mApplicationId;
127
128 std::map<WsfStringId, double> mTargetPriority;
129
131 // The following are maps between WSF side and force ID
132 std::map<WsfStringId, int> mSideIdToForceId;
133
134 // The following maps a WSF platform type id to entity type.
135 std::map<WsfStringId, WsfExtEntityType> mObjectTypeToEntityType;
136 std::map<WsfExtEntityType, WsfStringId> mEntityTypeToObjectType;
137
138 // The following maps a WSF Comm type id to entity type.
139 std::map<WsfStringId, WsfExtRadioEntityType> mCommTypeToRadioEntityType;
140 std::map<WsfExtRadioEntityType, WsfStringId> mRadioEntityTypeToCommType;
141
143
144 // A bit vector of entity IDs (number) that have been preassigned by the from entity_id.
145 std::bitset<65536U> mPreassignedEntityIds;
146 // Explicit mappings of a specific platform name to an entity Id (from the entity_id command).
147 std::map<WsfStringId, uint16_t> mPlatformNameToEntityId;
148 // Set of platforms which are externally moved
149 std::set<WsfExtEntityId> mExternalEntityIds;
150 std::set<WsfExtEntityType> mExternalEntityTypes;
151
153
154protected:
156};
157
159{
160public:
161 static WsfExtInput* Find(const WsfScenario& aScenario);
162
163 WsfExtInput(WsfScenario& aScenario);
164 ~WsfExtInput() override;
165
166 void SimulationCreated(WsfSimulation& aSimulation) override;
167 bool Complete() override;
168
173 virtual bool ProcessExtInput(UtInput& aInput) { return mData.ProcessInput(GetScenario(), aInput); }
174 WsfExtEmission* GetEmission() { return mData.GetEmission(); }
175
176 void AddedToScenario() override;
177
179};
180
183{
184public:
185 enum
186 {
187 cALL_SITES = 0xFFFF,
188 cALL_APPLIC = 0xFFFF,
194 };
195
196 static WsfExtInterface* Find(const WsfSimulation& aSimulation);
197
199 ~WsfExtInterface() override;
200
201 void SimulationComplete(double aSimTime);
202
203 bool PrepareExtension() override;
204
206
207 static void StripExternalPlatform(WsfPlatform* aPlatformPtr);
208
209 WsfPlatform* CreateExternalPlatform(const std::string& aPlatformType);
210
212 WsfStringId GetDefaultPlatformTypeId() { return mDefaultPlatformTypeId; }
215
216 void SelectEntityId(WsfPlatform* aPlatformPtr, uint16_t& aEntityId);
217 void FreeEntityId(uint16_t aEntityId);
218
219 bool IsPrivate(const WsfPlatform* aPlatformPtr) const;
220
221 std::set<WsfStringId>& GetPrivateNameId() { return mPrivateNameId; }
222 std::set<WsfStringId>& GetPrivateTypeId() { return mPrivateTypeId; }
224
225 void AddPrivateType(WsfStringId aTypeId);
226
227 unsigned short GetSiteId() { return mSiteId; }
228 unsigned short GetApplicationId() { return mApplicationId; }
229
230 std::map<WsfStringId, WsfExtEntityType>& GetObjectToEntityTypeMap() { return mObjectTypeToEntityType; }
231 std::map<WsfExtEntityType, WsfStringId>& GetEntityTypeToObjectMap() { return mEntityTypeToObjectType; }
232
233
234 bool IsEntityExternallyMoved(const WsfExtEntityId& aEntityId, const WsfExtEntityType& aEntityType);
235
236 uint16_t GetNewEventId();
237
239 ut::Random& GetRandom() { return mRandom; }
240
243
246
247 WsfExtEntityDeadReckon* GetEntityDeadReckon() const { return mDeadReckonPtr; }
248
249 // Called at the point when external interfaces should be connected.
250 // Either at the start of the simulation, or after the deferred connection time.
251 UtCallbackListN<void(double)> ConnectionComplete;
252
253 // Allow other modules to access the current entity number.
254 uint16_t AssignNewEntity();
255 std::bitset<65536U>* PreassignedEntityIds() { return &mPreassignedEntityIds; }
256 std::bitset<65536U>* ActiveEntityIds() { return &mActiveEntityIds; }
257 std::map<WsfStringId, uint16_t>* PlatformNameToEntityId() { return &mPlatformNameToEntityId; }
258
259private:
260 double Connected(double aSimTime);
261
262
266 ut::Random mRandom;
267
268 UtCallbackHolder mCallbacks;
269
270 bool mIsInitialized;
271
272 bool mShadowAll;
273
274 WsfStringId mDefaultPlatformTypeId;
275
276 WsfExtEntityDeadReckon* mDeadReckonPtr;
277
278 uint16_t mNextEntity;
279
280 uint16_t mNextEventId;
281
282 // A bitset of entity IDs (number) that are currently in-use.
283 std::bitset<65536U> mActiveEntityIds;
284};
285
286#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Contains the 'categories' to which an object belongs.
Definition WsfCategoryList.hpp:34
A component list that stores only components of a specified type.
Definition WsfComponentList.hpp:343
WsfComponentT()
Definition WsfComponent.hpp:124
virtual bool ProcessInput(UtInput &aInput)
Definition WsfComponent.cpp:100
Definition WsfExtInterface.hpp:55
std::map< WsfStringId, WsfExtRadioEntityType > mCommTypeToRadioEntityType
Definition WsfExtInterface.hpp:139
std::map< WsfExtEntityType, WsfStringId > mEntityTypeToObjectType
Definition WsfExtInterface.hpp:136
double mDeferredConnectionTime
Definition WsfExtInterface.hpp:123
WsfExtInterfaceComponent Component
Definition WsfExtInterface.hpp:57
std::map< WsfStringId, uint16_t > mPlatformNameToEntityId
Definition WsfExtInterface.hpp:147
uint16_t mStartEntity
Definition WsfExtInterface.hpp:120
std::map< WsfStringId, double > mTargetPriority
Definition WsfExtInterface.hpp:128
std::set< WsfExtEntityId > mExternalEntityIds
Definition WsfExtInterface.hpp:149
unsigned short mApplicationId
Definition WsfExtInterface.hpp:122
std::map< WsfExtRadioEntityType, WsfStringId > mRadioEntityTypeToCommType
Definition WsfExtInterface.hpp:140
std::set< WsfExtEntityType > mExternalEntityTypes
Definition WsfExtInterface.hpp:150
ComponentList mComponents
Definition WsfExtInterface.hpp:155
bool mAllPrivate
Definition WsfExtInterface.hpp:116
void AddComponent(Component *aComponentPtr)
Definition WsfExtInterface.hpp:63
std::set< WsfStringId > mPrivateTypeId
Definition WsfExtInterface.hpp:117
bool mDebugDetonationEnabled
Definition WsfExtInterface.hpp:126
WsfExtEmission * GetEmission() const
Definition WsfExtInterface.hpp:68
unsigned short mSiteId
Definition WsfExtInterface.hpp:121
WsfExtData(WsfScenario &aScenario)
Definition WsfExtInterface.cpp:91
std::map< WsfStringId, int > mSideIdToForceId
Definition WsfExtInterface.hpp:132
WsfExtEntityDeadReckonSetup mDR_Setup
Definition WsfExtInterface.hpp:142
WsfComponentListT< WsfExtInterfaceComponent > ComponentList
Definition WsfExtInterface.hpp:58
WsfCategoryList mPrivateCategoryId
Definition WsfExtInterface.hpp:119
WsfStringId mUnknownPlatformTypeId
Definition WsfExtInterface.hpp:130
const ComponentList & GetComponents() const
Definition WsfExtInterface.hpp:64
WsfExtEmission * mEmissionPtr
Definition WsfExtInterface.hpp:152
std::set< WsfStringId > mPrivateNameId
Definition WsfExtInterface.hpp:118
std::map< WsfStringId, WsfExtEntityType > mObjectTypeToEntityType
Definition WsfExtInterface.hpp:135
std::bitset< 65536U > mPreassignedEntityIds
Definition WsfExtInterface.hpp:145
double mDeferredPDUSendTime
Deferred time before any DIS PDUs can be sent.
Definition WsfExtInterface.hpp:125
Definition WsfExtEmission.hpp:32
Definition WsfExtEntityDeadReckon.hpp:46
Definition WsfExtEntityId.hpp:22
Definition WsfExtEntityType.hpp:28
Definition WsfExtInterface.hpp:159
void SimulationCreated(WsfSimulation &aSimulation) override
Definition WsfExtInterface.cpp:735
WsfExtInput(WsfScenario &aScenario)
Definition WsfExtInterface.cpp:728
WsfExtEmission * GetEmission()
Definition WsfExtInterface.hpp:174
WsfExtData mData
Definition WsfExtInterface.hpp:178
bool Complete() override
Definition WsfExtInterface.cpp:740
static WsfExtInput * Find(const WsfScenario &aScenario)
Definition WsfExtInterface.cpp:747
virtual bool ProcessExtInput(UtInput &aInput)
Definition WsfExtInterface.hpp:173
Definition WsfExtInterface.hpp:46
virtual bool CompleteLoad(WsfScenario &aScenario)
Definition WsfExtInterface.hpp:48
virtual void PrintEmitterTypes(WsfScenario &aScenario, std::ostream &aStream)
Definition WsfExtInterface.hpp:49
The WSF Ext is code which is shared between common external interfaces like DIS and HLA.
Definition WsfExtInterface.hpp:183
@ cALL_ENTITIES
Definition WsfExtInterface.hpp:189
@ cALL_APPLIC
Definition WsfExtInterface.hpp:188
@ cNO_SITES
Definition WsfExtInterface.hpp:190
@ cALL_SITES
Definition WsfExtInterface.hpp:187
@ cNO_ENTITY
Definition WsfExtInterface.hpp:192
@ cNO_APPLIC
Definition WsfExtInterface.hpp:191
@ cRQST_ASSIGN_ID
Definition WsfExtInterface.hpp:193
WsfCategoryList & GetPrivateCategoryId()
Definition WsfExtInterface.hpp:223
std::set< WsfStringId > & GetPrivateNameId()
Definition WsfExtInterface.hpp:221
std::map< WsfExtEntityType, WsfStringId > & GetEntityTypeToObjectMap()
Definition WsfExtInterface.hpp:231
WsfStringId SelectPlatformType(const WsfExtEntityType &aEntityType)
Given an entity type, select the object type to be used.
Definition WsfExtInterface.cpp:860
std::bitset< 65536U > * PreassignedEntityIds()
Definition WsfExtInterface.hpp:255
bool PrepareExtension() override
Definition WsfExtInterface.cpp:774
std::map< WsfStringId, uint16_t > * PlatformNameToEntityId()
Definition WsfExtInterface.hpp:257
UtCallbackListN< void(double)> ConnectionComplete
Definition WsfExtInterface.hpp:251
WsfExtInterface(WsfExtInput &aInput)
Definition WsfExtInterface.cpp:752
std::set< WsfStringId > & GetPrivateTypeId()
Definition WsfExtInterface.hpp:222
static void StripExternalPlatform(WsfPlatform *aPlatformPtr)
Definition WsfExtInterface.cpp:808
WsfExtEntityDeadReckon * GetEntityDeadReckon() const
Definition WsfExtInterface.hpp:247
uint16_t AssignNewEntity()
Definition WsfExtInterface.cpp:928
unsigned short GetSiteId()
Definition WsfExtInterface.hpp:227
WsfStringId GetDefaultPlatformTypeId()
Return the type ID of the default platform.
Definition WsfExtInterface.hpp:212
ut::Random & GetRandom()
Get the local random number generator.
Definition WsfExtInterface.hpp:239
WsfPlatform * CreateExternalPlatform(const std::string &aPlatformType)
Definition WsfExtInterface.cpp:835
void SimulationComplete(double aSimTime)
std::map< WsfStringId, WsfExtEntityType > & GetObjectToEntityTypeMap()
Definition WsfExtInterface.hpp:230
std::bitset< 65536U > * ActiveEntityIds()
Definition WsfExtInterface.hpp:256
unsigned short GetApplicationId()
Definition WsfExtInterface.hpp:228
double GetDeferredConnectionTime() const
Return the time from the start of the simulation run that external interfaces will open connections.
Definition WsfExtInterface.hpp:242
WsfStringId GetUnknownPlatformTypeId()
Return the type ID of the platform mapped to unknown types.
Definition WsfExtInterface.hpp:214
double GetDeferredPDUSendTime() const
Return the time from the start of the simulation run that DIS PDUs can be sent across external interf...
Definition WsfExtInterface.hpp:245
Definition WsfExtRadioEntityType.hpp:22
Definition WsfObject.hpp:40
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
WsfScenarioExtension()
Definition WsfScenarioExtension.cpp:21
WsfScenario & GetScenario() const
Definition WsfScenarioExtension.hpp:46
friend class WsfScenario
Definition WsfScenarioExtension.hpp:39
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
WsfSimulationExtension()
Definition WsfSimulationExtension.cpp:23
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfComm.hpp:43
Definition WsfExtEntityDeadReckon.hpp:31
Copyrights Multiple, All Rights Reserved