WSF
WsfCommNetwork.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 2018 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 WSFCOMMNETWORK_HPP
13#define WSFCOMMNETWORK_HPP
14
15#include <string>
16#include <unordered_map>
17
18class UtInput;
19#include "UtScriptClassDefine.hpp"
20#include "WsfCommAddress.hpp"
21#include "WsfObject.hpp"
22class WsfSimulation;
23#include "wsf_export.h"
24
31
32namespace wsf
33{
34namespace comm
35{
36
51{
52public:
53 struct NamedComm
54 {
57
58 NamedComm() = default;
59 NamedComm(WsfStringId aPlatformName, WsfStringId aCommName)
60 : mPlatformName(aPlatformName)
61 , mCommName(aCommName){};
62
63 bool operator==(const NamedComm& aComm) const
64 {
65 return ((mPlatformName == aComm.mPlatformName) && (mCommName == aComm.mCommName));
66 }
67
68 bool operator!=(const NamedComm& aComm) const { return !(*this == aComm); }
69 };
70
71 using AddressList = std::vector<Address>;
72 using AddressLinkList = std::vector<std::pair<Address, Address>>;
73 using NamedList = std::vector<NamedComm>;
74 using NamedLinkList = std::vector<std::pair<NamedComm, NamedComm>>;
75
79 Network() = default;
80 ~Network() override = default;
81 Network(const std::string& aNetworkName, const Address& aAddress);
82
83 Network(const Network& aSrc) = default;
84 Network& operator=(const Network& aRhs) = default;
85 Network(Network&& aSrc) = default;
86
91 bool InitializeLinkage(WsfSimulation& aSimulation);
92
93 bool ProcessInput(UtInput& aInput) override { return false; }
94 Network* Clone() const override { return nullptr; }
95 const char* GetScriptClassName() const override;
96 virtual bool Initialize(WsfSimulation& aSim) { return true; }
97
105
106 bool AddMember(const Address& aAddress, WsfSimulation& aSimulation, const Address& aOptionalAddress = Address());
107 bool RemoveMember(const Address& aAddress, WsfSimulation& aSimulation, const Address& aOptionalAddress = Address());
108 bool AddLink(const Address& aSourceAddress,
109 const Address& aDestinationAddress,
110 WsfSimulation& aSimulation,
111 const Address& aOptionalAddress = Address());
112 bool RemoveLink(const Address& aSourceAddress,
113 const Address& aDestinationAddress,
114 WsfSimulation& aSimulation,
115 const Address& aOptionalAddress = Address());
117
125
126 void SetAddress(const Address& aAddress) { mAddress = aAddress; }
127 void SetIsManaged(bool aManaged) { mManaged = aManaged; }
128
129 const Address& GetAddress() const { return mAddress; }
130 size_t GetHostsMax() const { return mAddress.GetNumHostAddresses(); }
131 bool IsManaged() const { return mManaged; }
132
138 static Address GetAddressFromNamedComm(WsfStringId aPlatformName, WsfStringId aCommName, WsfSimulation& aSimulation);
139
149 const NamedList& GetNamedMemberList() const { return mNamedList; }
150
154 bool HasMember(const Address& aAddress) const;
155
156protected:
157 virtual bool InitializeLinkageP(WsfSimulation& aSimulation) { return true; }
158
163
164 virtual bool ProcessAddressListInput(UtInput& aInput);
165 virtual bool ProcessAddressLinkListInput(UtInput& aInput);
166 virtual bool ProcessNamedListInput(UtInput& aInput);
167 virtual bool ProcessNamedLinkListInput(UtInput& aInput);
169
180
181 virtual bool AddMemberP(const Address& aAddress, WsfSimulation& aSimulation, const Address& aOptionalAddress = Address())
182 {
183 return true;
184 }
185 virtual bool RemoveMemberP(const Address& aAddress,
186 WsfSimulation& aSimulation,
187 const Address& aOptionalAddress = Address())
188 {
189 return true;
190 }
191 virtual bool AddLinkP(const Address& aSourceAddress,
192 const Address& aDestinationAddress,
193 WsfSimulation& aSimulation,
194 const Address& aOptionalAddress = Address())
195 {
196 return true;
197 }
198 virtual bool RemoveLinkP(const Address& aSourceAddress,
199 const Address& aDestinationAddress,
200 WsfSimulation& aSimulation,
201 const Address& aOptionalAddress = Address())
202 {
203 return true;
204 }
205
206
209
216
219
225
227 bool mManaged{false};
228};
229
233class WSF_EXPORT ScriptNetworkClass : public UtScriptClass
234{
235public:
236 ScriptNetworkClass(const std::string& aClassName, UtScriptTypes* aTypesPtr);
237
238 std::string ToString(void* aObjectPtr) const override;
239
244
254
259 UT_DECLARE_SCRIPT_METHOD(GetManagedNetworks);
260
261protected:
268 template<typename T>
269 static void DestroyHelper(void* aNetworkPtr)
270 {
271 static_assert(std::is_base_of<wsf::comm::Network, T>::value, "Template type must derive from wsf::comm::Network");
272 auto network = static_cast<T*>(aNetworkPtr);
273 if (!network->IsManaged())
274 {
275 delete network;
276 }
277 }
278};
279
280} // namespace comm
281} // namespace wsf
282
283UT_MAP_CLASS_TO_SCRIPT_NAME(wsf::comm::Network, "WsfNetwork")
284
285
286namespace std
287{
288template<>
289struct hash<wsf::comm::Network::NamedComm>
290{
291 size_t operator()(const wsf::comm::Network::NamedComm& aComm) const
292 {
293 return std::hash<WsfStringId>{}(aComm.mPlatformName) * 3 ^ std::hash<WsfStringId>{}(aComm.mCommName);
294 }
295};
296} // namespace std
297
298#endif
wsf::comm::Address Address
Definition WsfScriptCommRouterClass.cpp:29
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfCommAddress.hpp:57
Definition WsfCommNetwork.hpp:51
AddressLinkList mAddressLinkList
Definition WsfCommNetwork.hpp:215
virtual bool AddLinkP(const Address &aSourceAddress, const Address &aDestinationAddress, WsfSimulation &aSimulation, const Address &aOptionalAddress=Address())
Definition WsfCommNetwork.hpp:191
AddressList mInputAddressList
Definition WsfCommNetwork.hpp:214
Network(const Network &aSrc)=default
NamedLinkList mNamedLinkList
Definition WsfCommNetwork.hpp:224
void SetAddress(const Address &aAddress)
Definition WsfCommNetwork.hpp:126
AddressList mAddressList
Definition WsfCommNetwork.hpp:208
bool mManaged
True if this network is being managed by the simulation.
Definition WsfCommNetwork.hpp:227
virtual bool Initialize(WsfSimulation &aSim)
Definition WsfCommNetwork.hpp:96
std::vector< std::pair< Address, Address > > AddressLinkList
Definition WsfCommNetwork.hpp:72
std::vector< NamedComm > NamedList
Definition WsfCommNetwork.hpp:73
virtual bool RemoveLinkP(const Address &aSourceAddress, const Address &aDestinationAddress, WsfSimulation &aSimulation, const Address &aOptionalAddress=Address())
Definition WsfCommNetwork.hpp:198
Network * Clone() const override
Definition WsfCommNetwork.hpp:94
NamedList mNamedList
Definition WsfCommNetwork.hpp:223
virtual bool AddMemberP(const Address &aAddress, WsfSimulation &aSimulation, const Address &aOptionalAddress=Address())
Definition WsfCommNetwork.hpp:181
std::vector< Address > AddressList
Definition WsfCommNetwork.hpp:71
const NamedList & GetNamedMemberList() const
Definition WsfCommNetwork.hpp:149
const Address & GetAddress() const
Definition WsfCommNetwork.hpp:129
AddressLinkList mInputAddressLinkList
Same case as "mInputAddressList" above, except with link definitions.
Definition WsfCommNetwork.hpp:218
Network(Network &&aSrc)=default
const char * GetScriptClassName() const override
virtual bool InitializeLinkageP(WsfSimulation &aSimulation)
Definition WsfCommNetwork.hpp:157
bool InitializeLinkage(WsfSimulation &aSimulation)
Definition WsfCommNetwork.cpp:66
Address mAddress
Definition WsfCommNetwork.hpp:207
void SetIsManaged(bool aManaged)
Definition WsfCommNetwork.hpp:127
size_t GetHostsMax() const
Definition WsfCommNetwork.hpp:130
bool ProcessInput(UtInput &aInput) override
Definition WsfCommNetwork.hpp:93
virtual bool RemoveMemberP(const Address &aAddress, WsfSimulation &aSimulation, const Address &aOptionalAddress=Address())
Definition WsfCommNetwork.hpp:185
std::vector< std::pair< NamedComm, NamedComm > > NamedLinkList
Definition WsfCommNetwork.hpp:74
Network & operator=(const Network &aRhs)=default
bool IsManaged() const
Definition WsfCommNetwork.hpp:131
~Network() override=default
UT_DECLARE_SCRIPT_METHOD(RemoveMember_1)
static void DestroyHelper(void *aNetworkPtr)
Definition WsfCommNetwork.hpp:269
UT_DECLARE_SCRIPT_METHOD(RemoveLink_1)
UT_DECLARE_SCRIPT_METHOD(GetNetwork_1)
UT_DECLARE_SCRIPT_METHOD(GetNetwork_2)
UT_DECLARE_SCRIPT_METHOD(RemoveMember_2)
UT_DECLARE_SCRIPT_METHOD(GetManagedNetworks)
ScriptNetworkClass(const std::string &aClassName, UtScriptTypes *aTypesPtr)
Definition WsfCommNetwork.cpp:391
UT_DECLARE_SCRIPT_METHOD(RemoveLink_2)
std::string ToString(void *aObjectPtr) const override
Definition WsfCommNetwork.cpp:424
UT_DECLARE_SCRIPT_METHOD(AddMember_1)
UT_DECLARE_SCRIPT_METHOD(RemoveNetwork)
UT_DECLARE_SCRIPT_METHOD(AddMember_2)
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
size_t operator()(const wsf::comm::Network::NamedComm &aComm) const
Definition WsfCommNetwork.hpp:291
Definition WsfCommNetwork.hpp:54
WsfStringId mCommName
Definition WsfCommNetwork.hpp:56
bool operator==(const NamedComm &aComm) const
Definition WsfCommNetwork.hpp:63
bool operator!=(const NamedComm &aComm) const
Definition WsfCommNetwork.hpp:68
NamedComm(WsfStringId aPlatformName, WsfStringId aCommName)
Definition WsfCommNetwork.hpp:59
WsfStringId mPlatformName
Definition WsfCommNetwork.hpp:55
Copyrights Multiple, All Rights Reserved