WSF
WsfPlatformPart.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 WSFPLATFORMPART_HPP
13#define WSFPLATFORMPART_HPP
14
15#include "wsf_export.h"
16
17#include <mutex>
18#include <queue>
19
20#include "WsfAuxDataEnabled.hpp"
21#include "WsfCategoryList.hpp"
22#include "WsfComponent.hpp"
23class WsfGroup;
24#include "WsfGroupList.hpp"
25#include "WsfInternalLinks.hpp"
26#include "WsfObject.hpp"
27class WsfPlatform;
28class WsfScenario;
29class WsfSimulation;
30#include "WsfTypes.hpp"
31#include "WsfUniqueId.hpp"
32#include "WsfVariable.hpp"
33
61{
62public:
63 enum
64 {
65 cLEVEL_ONE_DEBUG = 0x00000001,
66 cLEVEL_TWO_DEBUG = 0x00000002
67 };
68
69 using InternalMessageQueue = std::queue<WsfMessage*>;
70 using RecipientMessageQueue = std::queue<std::pair<WsfPlatformPart*, WsfMessage*>>;
71
72 WsfPlatformPart(const WsfScenario& aScenario, int aPartType);
74 ~WsfPlatformPart() override;
75
76 const int* GetComponentRoles() const override;
77 void* QueryInterface(int aRole) override;
78
82
83 WsfStringId GetComponentName() const override { return GetNameId(); }
84 void ComponentParentChanged(WsfPlatform* aPlatformPtr) override
85 {
86 // Set the pointer AND call the SetPlatform. Some classes define SetPlatform so they get control
87 // when ever the attachment is made. In particular, some of the script stuff needs to be set
88 // as soon as possible so script compiles work. SetPlatform *should* set the pointer, but we do
89 // it here just in case a derived method fails to call the base class version as they should.
90 SetPlatform(aPlatformPtr);
91 mPlatformPtr = aPlatformPtr;
92 }
93
94
96
97 bool Initialize(double aSimTime) override;
98 bool Initialize2(double aSimTime) override;
99 bool ProcessInput(UtInput& aInput) override;
100 virtual void Update(double aSimTime);
102
104
105
107 WsfPlatform* GetPlatform() const { return mPlatformPtr; }
108
113 virtual void SetPlatform(WsfPlatform* aPlatformPtr) { mPlatformPtr = aPlatformPtr; }
115
118
119 virtual void PlatformAdded(double aSimTime, WsfPlatform* aPlatformPtr);
120
121 virtual void PlatformDeleted(WsfPlatform* aPlatformPtr);
123
125
126
128 double GetLastStatusChangeTime() const { return mLastStatusChangeTime; }
129
131 void SetLastStatusChangeTime(double aSimTime) { mLastStatusChangeTime = aSimTime; }
132
135 {
136 return (!mIsOperational) && (mDamageFactor < 1.0) && (!mIsExternallyControlled);
137 }
138
140 bool CanBeMadeNonOperational() const { return mIsOperational && (!mIsExternallyControlled); }
141
143 bool CanBeTurnedOn() const { return mIsOperational && (!mIsTurnedOn) && (!mIsExternallyControlled); }
144
146 bool CanBeTurnedOff() const { return mIsTurnedOn && (!mIsExternallyControlled); }
147
150 bool IsTurnedOn() const { return mIsTurnedOn; }
151
153 bool InitiallyTurnedOn() const { return mInitiallyTurnedOn; }
154
156 void SetInitiallyTurnedOn(bool aInitiallyTurnedOn) { mInitiallyTurnedOn = aInitiallyTurnedOn; }
157
158 virtual void TurnOff(double aSimTime);
159
160 virtual void TurnOn(double aSimTime);
161
162 virtual void SetOperational(double aSimTime);
163
164 virtual void SetNonOperational(double aSimTime);
165
166 virtual void PartBroken(double aSimTime);
167
168 virtual void Restore(double aSimTime);
170
175
176
178 bool IsOperational() const { return mIsOperational; }
179
180 bool SetOperational(double aSimTime, bool aMakeOperational);
181
186 double GetDamageFactor() const { return mDamageFactor; }
187
188 bool SetDamageFactor(double aSimTime, double aDamageFactor);
189
192 bool IsCritical() const { return mIsCritical; }
193
194 void SetCritical(bool aValue) { mIsCritical = aValue; }
195
197 virtual void OnPlatformBrokenEvent(double aSimTime);
198
201 bool IsBroken() const { return (mDamageFactor == 1.0) && (!mIsRestorable); }
202
204
206
207
208 WsfInternalLinks& GetInternalLinks() { return mInternalLinks; }
209
211 virtual bool HasInternalLinks() const { return mInternalLinks.HasLinks(); }
212
213 virtual bool ProcessMessage(double aSimTime, const WsfMessage& aMessage);
214
215 virtual bool ReceiveMessage(double aSimTime, const WsfMessage& aMessage);
216
217#undef SendMessage // Avoid conflict with Windows macro
218 virtual void SendMessage(double aSimTime, const WsfMessage& aMessage);
220
222
223 virtual void SendMessageTo(double aSimTime, const WsfMessage& aMessage, WsfStringId aRecipientId);
224
225 void SendMessageToProcessor(double aSimTime, const WsfMessage& aMessage, WsfStringId aRecipientId);
226
227 virtual void SendQueuedMessages(double aSimTime);
229
232
233
234 const WsfCategoryList& GetCategories() const { return mCategories; }
235
237 void AddCategory(WsfStringId aCategoryId) { mCategories.JoinCategory(aCategoryId); }
238
242 bool IsCategoryMember(WsfStringId aCategoryId) const { return mCategories.IsCategoryMember(aCategoryId); }
244
246
247
248 const WsfGroupList& GetGroups() const { return mGroups; }
249 void JoinGroup(WsfGroup* aGroupPtr);
250 void LeaveGroup(WsfGroup* aGroupPtr);
251 bool IsGroupMember(WsfStringId aGroupId);
253
255
256
258 virtual double GetUpdateInterval() const = 0;
260
264 //{@
269 virtual void SetUpdateInterval(double aUpdateInterval) = 0;
270
273 unsigned int GetUpdateEventEpoch() const { return mUpdateEventEpoch; }
274
277 void IncrementUpdateEventEpoch() { ++mUpdateEventEpoch; }
278
280 bool UpdateEventActive() const { return mUpdateEventActive; }
281
283 void SetUpdateEventActive(bool aUpdateEventActive) { mUpdateEventActive = aUpdateEventActive; }
285
287
288
289 bool DebugEnabled() const { return mDebugEnabled; }
290
291 void SetDebugEnabled(bool aDebugEnabled) { mDebugEnabled = aDebugEnabled; }
292
293 unsigned int GetDebugMask() { return mDebugMask; }
295
296 bool IsExternallyControlled() const { return mIsExternallyControlled; }
297
298 virtual void SetExternallyControlled(double aSimTime, bool aIsExternallyControlled);
299
300 int GetPartType() const { return mPartType; }
301
302 const char* GetScriptClassName() const override;
303
304 WsfSimulation* GetSimulation() const;
305
306 const WsfScenario& GetScenario() const { return mScenario; }
307
308protected:
309 WsfPlatformPart(const WsfPlatformPart& aSrc);
310
311private:
313 int mPartType;
314
316 const WsfScenario& mScenario;
317
319 WsfPlatform* mPlatformPtr;
320
322 WsfInternalLinks mInternalLinks;
323
325 WsfCategoryList mCategories;
326
328 WsfGroupList mGroups;
329
331 double mLastStatusChangeTime;
332
334 double mAutomaticRecoveryTime;
335
337 double mDamageFactor;
338
340 bool mIsCritical;
341
343 bool mIsTurnedOn;
344
346 bool mInitiallyTurnedOn;
347
349 bool mIsOperational;
350
353 bool mIsRestorable;
354
356 bool mDebugEnabled;
357
359 bool mIsExternallyControlled;
360
362 bool mUpdateEventActive;
363
365 unsigned int mDebugMask;
366
369 unsigned int mUpdateEventEpoch;
370
372 InternalMessageQueue mInternalMessageQueue;
373
375 RecipientMessageQueue mRecipientMessageQueue;
376
377 std::recursive_mutex mMutex;
378};
379
381
382#endif
#define WSF_DECLARE_COMPONENT_ROLE_TYPE(TYPE, ROLE)
Definition WsfComponentRoles.hpp:44
@ cWSF_COMPONENT_PLATFORM_PART
The component derives from WsfPlatformPart.
Definition WsfComponentRoles.hpp:98
WsfComponentT< WsfPlatform > WsfPlatformComponent
A convenient typedef for a platform component.
Definition WsfComponent.hpp:171
aObjectPtr Update(simTime)
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfAuxDataEnabled()=default
Contains the 'categories' to which an object belongs.
Definition WsfCategoryList.hpp:34
virtual const int * GetComponentRoles() const =0
virtual bool Initialize(double aSimTime)
Definition WsfComponent.cpp:45
virtual bool Initialize2(double aSimTime)
Definition WsfComponent.cpp:63
virtual void * QueryInterface(int aRole)=0
Contains the 'groups' to which platform or platform part belongs.
Definition WsfGroupList.hpp:30
A class to support the concept of 'groups' and 'group membership'.
Definition WsfGroup.hpp:30
A base class for messages sent among simulation communication objects, processors and sensors.
Definition WsfMessage.hpp:33
WsfStringId GetNameId() const
Definition WsfObject.hpp:66
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
virtual bool ProcessInput(UtInput &aInput)
Definition WsfObject.cpp:140
const char * GetScriptClassName() const override
Definition WsfObject.cpp:115
Definition WsfPlatformPart.hpp:61
bool CanBeTurnedOn() const
Returns an indication that this system can be turned on.
Definition WsfPlatformPart.hpp:143
void SetCritical(bool aValue)
Definition WsfPlatformPart.hpp:194
WsfStringId GetComponentName() const override
Definition WsfPlatformPart.hpp:83
bool InitiallyTurnedOn() const
Is the system to be turned 'on' when added to the simulation?
Definition WsfPlatformPart.hpp:153
bool IsExternallyControlled() const
Definition WsfPlatformPart.hpp:296
unsigned int GetDebugMask()
Definition WsfPlatformPart.hpp:293
bool IsBroken() const
Definition WsfPlatformPart.hpp:201
void IncrementUpdateEventEpoch()
Definition WsfPlatformPart.hpp:277
bool IsCategoryMember(WsfStringId aCategoryId) const
Definition WsfPlatformPart.hpp:242
void SetInitiallyTurnedOn(bool aInitiallyTurnedOn)
Sets if the system is turned on when added to the simulation.
Definition WsfPlatformPart.hpp:156
double GetDamageFactor() const
Definition WsfPlatformPart.hpp:186
bool CanBeMadeNonOperational() const
Returns an indication that this system can be made non-operational.
Definition WsfPlatformPart.hpp:140
bool IsOperational() const
Definition WsfPlatformPart.hpp:178
const WsfScenario & GetScenario() const
Definition WsfPlatformPart.hpp:306
double GetLastStatusChangeTime() const
Definition WsfPlatformPart.hpp:128
virtual double GetUpdateInterval() const =0
bool IsCritical() const
Definition WsfPlatformPart.hpp:192
WsfInternalLinks & GetInternalLinks()
Return the internal links for this part.
Definition WsfPlatformPart.hpp:208
std::queue< WsfMessage * > InternalMessageQueue
Definition WsfPlatformPart.hpp:69
void ComponentParentChanged(WsfPlatform *aPlatformPtr) override
Definition WsfPlatformPart.hpp:84
void SetDebugEnabled(bool aDebugEnabled)
Definition WsfPlatformPart.hpp:291
WsfPlatformPart & operator=(const WsfPlatformPart &aRhs)=delete
const WsfGroupList & GetGroups() const
Get the groups to which this platform part belongs.
Definition WsfPlatformPart.hpp:248
virtual void SetUpdateInterval(double aUpdateInterval)=0
unsigned int GetUpdateEventEpoch() const
Definition WsfPlatformPart.hpp:273
WsfPlatformPart(const WsfScenario &aScenario, int aPartType)
Definition WsfPlatformPart.cpp:62
bool IsTurnedOn() const
Definition WsfPlatformPart.hpp:150
virtual bool HasInternalLinks() const
Does this platform part have a communication link to other platform parts?
Definition WsfPlatformPart.hpp:211
int GetPartType() const
Definition WsfPlatformPart.hpp:300
void SetUpdateEventActive(bool aUpdateEventActive)
Indicate if the 'Update' event is active.
Definition WsfPlatformPart.hpp:283
bool UpdateEventActive() const
Is an 'Update' event active?
Definition WsfPlatformPart.hpp:280
std::queue< std::pair< WsfPlatformPart *, WsfMessage * > > RecipientMessageQueue
Definition WsfPlatformPart.hpp:70
bool CanBeTurnedOff() const
Returns an indication that this system can be turned off.
Definition WsfPlatformPart.hpp:146
virtual void SetPlatform(WsfPlatform *aPlatformPtr)
Definition WsfPlatformPart.hpp:113
void AddCategory(WsfStringId aCategoryId)
Adds the provided category to the platform part's category list.
Definition WsfPlatformPart.hpp:237
@ cLEVEL_ONE_DEBUG
General debug.
Definition WsfPlatformPart.hpp:65
@ cLEVEL_TWO_DEBUG
Full debug.
Definition WsfPlatformPart.hpp:66
const WsfCategoryList & GetCategories() const
Get the categories to which this part belongs.
Definition WsfPlatformPart.hpp:234
void SetLastStatusChangeTime(double aSimTime)
Allows a system to set the time at which the device was initialized.
Definition WsfPlatformPart.hpp:131
bool CanBeMadeOperational() const
Returns an indication that this system can be made operational.
Definition WsfPlatformPart.hpp:134
WsfPlatform * GetPlatform() const
Definition WsfPlatformPart.hpp:107
bool DebugEnabled() const
Returns 'true' if debugging is enabled for this instance.
Definition WsfPlatformPart.hpp:289
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
The main controller for a simulation.
Definition WsfSimulation.hpp:109
WsfUniqueId()
Construtor initializes the unique identifier to 0.
Definition WsfUniqueId.hpp:38
Copyrights Multiple, All Rights Reserved