WSF
WsfExternalLinks.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 WSFEXTERNALLINKS_HPP
13#define WSFEXTERNALLINKS_HPP
14
15#include "wsf_export.h"
16
17#include <string>
18#include <unordered_set>
19#include <vector>
20
21class UtInput;
22#include "UtTypeTraits.hpp"
23#include "WsfCommAddress.hpp"
24class WsfMessage;
25class WsfPlatform;
26class WsfSimulation;
27#include "WsfStringId.hpp"
28
29namespace wsf
30{
31
32namespace comm
33{
34class Comm;
35}; // namespace comm
36
62{
63public:
64 enum class CommandChainRecipient : unsigned int
65 {
66 cCOMMANDER,
67 cSUBORDINATES,
68 cPEERS,
69 cNONE
70 };
71
72 class ExternalLink;
74 using LinkVec = std::vector<ExternalLink>;
75 using LinkIt = LinkVec::iterator;
76 using LinkConstIt = LinkVec::const_iterator;
77 using CommPair = std::pair<WsfStringId, WsfStringId>;
78 using AddressVec = std::vector<Address>;
79
81 {
85
86 bool operator==(const CommandChainTarget& aRhs) const
87 {
88 if ((mChainName == aRhs.mChainName) && (mReportType == aRhs.mReportType) && (mRcvrName == aRhs.mRcvrName))
89 {
90 return true;
91 }
92
93 return false;
94 }
95 };
96
98 {
99 public:
102
104 {
105 size_t operator()(const CommPair& aKey) const
106 {
107 // using multipliers to increase hash entrophy between nearby WsfStringId
108 return (std::hash<WsfStringId>()(aKey.first) * 3 + std::hash<WsfStringId>()(aKey.second) * 7);
109 }
110 };
111
113 {
114 size_t operator()(const CommandChainTarget& aKey) const
115 {
116 // using multipliers to increase hash entrophy between nearby WsfStringId
117 return ((std::hash<WsfStringId>()(aKey.mChainName)) * 3 ^
118 (static_cast<ut::underlying_type_t<CommandChainRecipient>>(aKey.mReportType)) ^
119 (std::hash<WsfStringId>()(aKey.mRcvrName))) *
120 7;
121 }
122 };
123
124
125 using AddressSet = std::unordered_set<Address>;
126 using WsfStringSet = std::unordered_set<WsfStringId>;
127 using CommandSet = std::unordered_set<CommandChainTarget, CommandHash>;
128 using CommSet = std::unordered_set<CommPair, CommPairHash>;
129
130 ExternalLink() = default;
131 virtual ~ExternalLink() = default;
132
134
135 bool AddAddressRecipient(const Address& aAddress);
136 bool AddGroupRecipient(WsfStringId aGroupName);
137 bool AddCommandRecipient(const CommandChainTarget& aCommandChainTarget);
138 bool AddCommRecipient(const CommPair& aCommPair);
139
140 bool RemoveAddressRecipient(const Address& aAddress);
141 bool RemoveGroupRecipient(WsfStringId aGroupName);
142 bool RemoveCommandRecipient(const CommandChainTarget& aCommandChainTarget);
143 bool RemoveCommRecipient(const CommPair& aCommPair);
145
146 void DeleteAllRecipients();
147
150
151 AddressVec GetRecipients(bool aNotify = false) const;
152 comm::Comm* GetXmtr() const;
153 size_t GetRecipientCount() const;
155
157 void SetXmtrName(WsfStringId aXmtrName) { mXmtrName = aXmtrName; }
158 void SetParent(ExternalLinks* aParentPtr) { mParentPtr = aParentPtr; }
159
160 protected:
167 };
168
169 ExternalLinks() = default;
170 virtual ~ExternalLinks() = default;
171
172 bool HasLinks() const { return (!mLinks.empty()); }
173
174 bool Initialize(double aSimTime, WsfPlatform* aPlatformPtr);
175
176 bool ProcessInput(UtInput& aInput);
177 bool CommandChainCommand(const std::string& aCommand, CommandChainRecipient& aReportType);
178
179#undef SendMessage // Avoid conflict with Windows macro
180 void SendMessage(double aSimTime, const WsfMessage& aMessage);
181
184 void SendMessage(double aSimTime, const WsfMessage& aMessage, WsfStringId aExcludedPlatformName);
185
186 WsfSimulation* GetSimulation() const;
188
190
191 bool AddRecipient(WsfStringId aXmtrName, const Address& aRcvrAddress);
192 bool AddRecipient(WsfStringId aXmtrName, WsfStringId aCommGroupName);
193 bool AddRecipient(WsfStringId aXmtrName, const CommandChainTarget& aCommandChainTarget);
194 bool AddRecipient(WsfStringId aXmtrName, const CommPair& aCommPair);
195 bool RemoveRecipient(WsfStringId aXmtrName, const Address& aRcvrAddress);
196 bool RemoveRecipient(WsfStringId aXmtrName, WsfStringId aCommGroupName);
197 bool RemoveRecipient(WsfStringId aXmtrName, const CommandChainTarget& aCommandChainTarget);
198 bool RemoveRecipient(WsfStringId aXmtrName, const CommPair& aCommPair);
199
200 void DeleteAllRecipients();
201
204 size_t GetRecipientCount() const;
205 size_t GetRecipientCount(WsfStringId aXmtrName) const;
207
208 size_t GetLinkCount() const { return mLinks.size(); }
209 ExternalLink& GetLink(size_t aIndex) { return mLinks.at(aIndex); }
210
211protected:
212 LinkIt FindLink(WsfStringId aXmtrName);
213 LinkConstIt FindLink(WsfStringId aXmtrName) const;
214
217 bool mDebug{false};
218};
219
220} // namespace wsf
221#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
A base class for messages sent among simulation communication objects, processors and sensors.
Definition WsfMessage.hpp:33
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfCommAddress.hpp:57
Definition WsfComm.hpp:43
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