WSF
WsfCommMedium.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 2019 Infoscitex, a DCS 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 WSFCOMMMEDIUM_HPP
13#define WSFCOMMMEDIUM_HPP
14
15#include "wsf_export.h"
16
17#include <string>
18#include <vector>
19
20class UtInput;
21#include "UtCloneablePtr.hpp"
22#include "UtMath.hpp"
23#include "UtScriptAccessible.hpp"
24#include "UtScriptClassDefine.hpp"
27#include "WsfCommMessage.hpp"
28#include "WsfObject.hpp"
29#include "WsfRandomVariable.hpp"
30#include "WsfScenario.hpp"
31#include "WsfSimulation.hpp"
33
34namespace wsf
35{
36namespace comm
37{
38
39class Layer;
40
41namespace medium
42{
43
56
63class WSF_EXPORT Mode : public UtScriptAccessible
64{
65public:
66 Mode() = default;
67 Mode(const std::string& aName)
68 : mName(aName)
69 {
70 }
71 virtual ~Mode() = default;
72 Mode(const Mode& aSrc) = default;
73 virtual Mode* Clone() const = 0;
74
75 const char* GetScriptClassName() const override { return "WsfCommMediumMode"; }
76
77 virtual bool ProcessInput(UtInput& aInput) { return false; };
78
79 virtual double GetTransmissionTime(double aSimTime, Comm& aXmtr, Layer* aLayerPtr, Message& aMessage) = 0;
80
81 virtual double GetPropagationTime(double aSimTime, Comm& aXmtr, Comm& aRcvr, Message& aMessage) = 0;
82
83 virtual double GetPacketLossTime(double aSimTime, Message& aMessage) = 0;
84
85 const std::string& GetName() const { return mName; }
86 void SetName(const std::string& aName) { mName = aName; }
87
88private:
89 std::string mName{};
90};
91
93class WSF_EXPORT ScriptMediumModeClass : public UtScriptClass
94{
95public:
96 ScriptMediumModeClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
97
98 ~ScriptMediumModeClass() override = default;
99
101};
102
113{
114public:
115 using ModeIt = std::vector<std::unique_ptr<Mode>>::iterator;
116 using const_ModeIt = std::vector<std::unique_ptr<Mode>>::const_iterator;
117
118 Medium(WsfScenario& aScenario);
119 ~Medium() override = default;
120 Medium(const Medium& aSrc);
121 Medium& operator=(Medium& aRhs);
122
123 const char* GetScriptClassName() const override { return "WsfCommMedium"; }
124
125 Medium* Clone() const override = 0;
126 bool ProcessInput(UtInput& aInput) override;
127 virtual bool Initialize(double aSimTime);
128
129 void SetSimulation(WsfSimulation* aSimPtr) { mSimPtr = aSimPtr; }
130 WsfSimulation* GetSimulation() const { return mSimPtr; }
131
136
137 virtual TransmissionResult TransmitMessage(double aSimTime, Layer* aLayerPtr, Message& aMessage, Comm& aXmtr) = 0;
138
139 virtual void EndTransmission(double aSimTime, const Message::Identifier& aIdentifier) = 0;
140
141 virtual void PropagateMessage(double aSimTime, const Message::Identifier& aIdentifier) = 0;
142
143 virtual void EndPropagation(double aSimTime, const Message::Identifier& aIdentifier) = 0;
145
147
148 size_t GetNumModes() const { return mModes.size(); }
149 size_t GetCurrentModeIndex() const { return mModeIndex; }
150 std::pair<size_t, bool> GetModeIndex(const std::string& aModeName) const;
151 size_t GetNumChannels() const { return mChannels; }
152 const std::string& GetActiveModeName() const;
153 bool IsMediumShared() const { return mShared; }
154 bool UserDirectedSharing() const { return mUseSharing; }
155 size_t GetCurrentTransmissions() const;
156 size_t GetNumMessageStatuses() const { return mMessages.size(); }
157
168
169 bool SetActiveMode(const std::string& aModeName);
170 bool SetActiveMode(size_t aIndex);
171 void SetActiveModeDelayed(const std::string& aModeName);
172 void SetActiveModeDelayed(size_t aIndex);
174
175 void SetIsShared(bool aIsShared) { mShared = aIsShared; }
176
179
180 MessageStatus* GetMessageStatus(const Message::Identifier& aIdentifier);
181 MessageStatus* GetMessageStatusByIndex(size_t aIndex);
183
186 virtual std::unique_ptr<Mode> CreateDefaultMode() const = 0;
187
188 Mode* GetMode(const std::string& aModeName) const;
189 Mode* GetMode(size_t aModeIndex) const;
190
193 std::string ExecuteModeOnTransmit(double aSimTime, const Message& aMessage, const Comm& aXmtr, const Comm& aRcvr);
194
195protected:
196 void RemoveMessageStatus(const Message::Identifier& aIdentifier);
197 void SetNumChannels(size_t aNumChannels) { mChannels = aNumChannels; }
198
202 Mode* GetModeForTransmission(double aSimTime, Comm& aXmtr, Comm& aRcvr, Message& aMessage);
203
210 std::unordered_map<Message::Identifier, MessageStatus> mMessages{};
211
217 std::vector<ut::CloneablePtr<Mode>> mModes{};
218
230 bool mShared{false};
231
233 bool mDebug{false};
234
237 std::shared_ptr<int> mEventPtr{nullptr};
238
239private:
240 size_t mChannels{std::numeric_limits<size_t>::max()};
241 size_t mModeIndex{0U};
242 std::string mDefaultModeName{"default"};
243 WsfScenario& mScenario;
244 WsfSimulation* mSimPtr{nullptr};
245
255 bool mUseSharing{true};
256
257 std::unique_ptr<WsfScriptContext> mContextPtr{nullptr};
258
260 UtScript* mModeOnTransmit{nullptr};
261};
262
264{
265public:
266 ScriptMediumClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
267
268 ~ScriptMediumClass() override = default;
269
271 UT_DECLARE_SCRIPT_METHOD(CurrentModeIndex);
272 UT_DECLARE_SCRIPT_METHOD(CurrentModeName);
277
278 UT_DECLARE_SCRIPT_METHOD(TransmissionCount);
279 UT_DECLARE_SCRIPT_METHOD(MessageStatusCount);
280 UT_DECLARE_SCRIPT_METHOD(GetMessageStatus);
281 UT_DECLARE_SCRIPT_METHOD(GetMessageStatusByIndex);
282 UT_DECLARE_SCRIPT_METHOD(CheckValidMessageStatus);
283
285
288};
289
290} // namespace medium
291} // namespace comm
292} // namespace wsf
293
294#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
WsfScriptObjectClass(const std::string &aClassName, UtScriptTypes *aTypesPtr)
Definition WsfScriptObjectClass.cpp:24
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfComm.hpp:43
Definition WsfCommLayer.hpp:40
Definition WsfCommMessage.hpp:95
Definition WsfCommMessage.hpp:51
virtual std::unique_ptr< Mode > CreateDefaultMode() const =0
std::vector< ut::CloneablePtr< Mode > > mModes
Definition WsfCommMedium.hpp:217
virtual bool Initialize(double aSimTime)
Definition WsfCommMedium.cpp:179
size_t GetCurrentModeIndex() const
Definition WsfCommMedium.hpp:149
size_t GetNumModes() const
Definition WsfCommMedium.hpp:148
Medium(WsfScenario &aScenario)
Definition WsfCommMedium.cpp:52
bool UserDirectedSharing() const
Definition WsfCommMedium.hpp:154
void SetSimulation(WsfSimulation *aSimPtr)
Definition WsfCommMedium.hpp:129
virtual void EndTransmission(double aSimTime, const Message::Identifier &aIdentifier)=0
std::string ExecuteModeOnTransmit(double aSimTime, const Message &aMessage, const Comm &aXmtr, const Comm &aRcvr)
Definition WsfCommMedium.cpp:346
virtual void PropagateMessage(double aSimTime, const Message::Identifier &aIdentifier)=0
void SetIsShared(bool aIsShared)
Definition WsfCommMedium.hpp:175
bool mShared
Definition WsfCommMedium.hpp:230
std::vector< std::unique_ptr< Mode > >::const_iterator const_ModeIt
Definition WsfCommMedium.hpp:116
virtual void EndPropagation(double aSimTime, const Message::Identifier &aIdentifier)=0
bool ProcessInput(UtInput &aInput) override
Definition WsfCommMedium.cpp:97
bool IsMediumShared() const
Definition WsfCommMedium.hpp:153
Mode * GetMode(const std::string &aModeName) const
Definition WsfCommMedium.cpp:319
virtual TransmissionResult TransmitMessage(double aSimTime, Layer *aLayerPtr, Message &aMessage, Comm &aXmtr)=0
std::vector< std::unique_ptr< Mode > >::iterator ModeIt
Definition WsfCommMedium.hpp:115
size_t GetNumMessageStatuses() const
Definition WsfCommMedium.hpp:156
WsfSimulation * GetSimulation() const
Definition WsfCommMedium.hpp:130
size_t GetNumChannels() const
Definition WsfCommMedium.hpp:151
Medium & operator=(Medium &aRhs)
Definition WsfCommMedium.cpp:77
std::unordered_map< Message::Identifier, MessageStatus > mMessages
Definition WsfCommMedium.hpp:210
Medium * Clone() const override=0
bool mDebug
Debug flag.
Definition WsfCommMedium.hpp:233
void SetNumChannels(size_t aNumChannels)
Definition WsfCommMedium.hpp:197
std::shared_ptr< int > mEventPtr
Definition WsfCommMedium.hpp:237
~Medium() override=default
virtual TypeIdentifier GetMediumIdentifier() const =0
void RemoveMessageStatus(const Message::Identifier &aIdentifier)
Definition WsfCommMedium.cpp:363
const char * GetScriptClassName() const override
Definition WsfCommMedium.hpp:123
Definition WsfCommMediumMessageStatus.hpp:35
Definition WsfCommMedium.hpp:64
Mode(const Mode &aSrc)=default
const char * GetScriptClassName() const override
Definition WsfCommMedium.hpp:75
virtual Mode * Clone() const =0
Mode(const std::string &aName)
Definition WsfCommMedium.hpp:67
virtual double GetPacketLossTime(double aSimTime, Message &aMessage)=0
virtual ~Mode()=default
virtual double GetTransmissionTime(double aSimTime, Comm &aXmtr, Layer *aLayerPtr, Message &aMessage)=0
virtual bool ProcessInput(UtInput &aInput)
Definition WsfCommMedium.hpp:77
const std::string & GetName() const
Definition WsfCommMedium.hpp:85
virtual double GetPropagationTime(double aSimTime, Comm &aXmtr, Comm &aRcvr, Message &aMessage)=0
void SetName(const std::string &aName)
Definition WsfCommMedium.hpp:86
UT_DECLARE_SCRIPT_METHOD(GetMessageStatusByIndex)
UT_DECLARE_SCRIPT_METHOD(TransmissionCount)
UT_DECLARE_SCRIPT_METHOD(GetMessageStatus)
UT_DECLARE_SCRIPT_METHOD(MessageStatusCount)
ScriptMediumClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfCommMedium.cpp:393
UT_DECLARE_SCRIPT_METHOD(CheckValidMessageStatus)
UT_DECLARE_SCRIPT_METHOD(CurrentModeIndex)
ScriptMediumModeClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfCommMedium.cpp:34
Definition WsfCommMedium.cpp:31
TypeIdentifier
Definition WsfCommMediumTypeIdentifier.hpp:50
TransmissionResult
Definition WsfCommMedium.hpp:48
@ cSUCCESS
Definition WsfCommMedium.hpp:50
@ cFAILURE_CHANNEL_LIMIT_REACHED
Definition WsfCommMedium.hpp:51
@ cFAILURE_UNSPECIFIED
Definition WsfCommMedium.hpp:49
@ cFAILURE_NONEXISTENT_RECEIVER
Definition WsfCommMedium.hpp:52
@ cFAILURE_EM_INTERACTION
Definition WsfCommMedium.hpp:54
@ cFAILURE_UNCONNECTED_RECEIVER
Definition WsfCommMedium.hpp:53
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved