 |
helics
3.3.0
|
9 #include "NetworkBrokerData.hpp"
10 #include "gmlc/concurrency/TriggerVariable.hpp"
11 #include "gmlc/concurrency/TripWire.hpp"
12 #include "gmlc/containers/BlockingPriorityQueue.hpp"
13 #include "helics/core/ActionMessage.hpp"
41 void loadTargetInfo(std::string_view localTarget,
42 std::string_view brokerTarget,
43 gmlc::networking::InterfaceNetworks targetNetwork =
44 gmlc::networking::InterfaceNetworks::LOCAL);
68 void setName(
const std::string& commName);
80 std::function<
void(
int level, std::string_view
name, std::string_view message)> callback);
91 void setTimeout(std::chrono::milliseconds timeOut);
93 virtual void setFlag(std::string_view flag,
bool val);
98 void logWarning(std::string_view message)
const;
100 void logError(std::string_view message)
const;
102 void logMessage(std::string_view message)
const;
121 gmlc::concurrency::TriggerVariable rxTrigger;
131 std::string randomID;
134 gmlc::concurrency::TriggerVariable txTrigger;
135 std::atomic<bool> operating{
false};
136 const bool singleThread{
false};
152 std::function<void(
int level, std::string_view
name, std::string_view message)>
154 gmlc::containers::BlockingPriorityQueue<std::pair<route_id, ActionMessage>>
160 gmlc::networking::InterfaceNetworks interfaceNetwork{
161 gmlc::networking::InterfaceNetworks::LOCAL};
164 std::thread queue_transmitter;
165 std::thread queue_watcher;
166 std::mutex threadSyncLock;
167 virtual void queue_rx_function() = 0;
168 virtual void queue_tx_function() = 0;
169 virtual void closeTransmitter();
170 virtual void closeReceiver();
171 virtual void reconnectTransmitter();
172 virtual void reconnectReceiver();
181 void propertyUnLock();
188 gmlc::concurrency::TripWireDetector
192 namespace CommFactory {
196 virtual std::unique_ptr<CommsInterface> build() = 0;
200 template<
class CommTYPE>
203 static_assert(std::is_base_of<CommsInterface, CommTYPE>::value,
204 "Type does not inherit from helics::CommsInterface");
206 using comm_build_type = CommTYPE;
207 virtual std::unique_ptr<CommsInterface> build()
override
209 return std::make_unique<CommTYPE>();
215 defineCommBuilder(std::shared_ptr<CommBuilder> cb, std::string_view commTypeName,
int code);
218 template<
class CommTYPE>
219 std::shared_ptr<CommBuilder> addCommType(std::string_view commTypeName,
int code)
221 auto bld = std::make_shared<CommTypeBuilder<CommTYPE>>();
222 std::shared_ptr<CommBuilder> cbld = std::static_pointer_cast<CommBuilder>(bld);
223 defineCommBuilder(cbld, commTypeName, code);
227 std::unique_ptr<CommsInterface> create(
CoreType type);
228 std::unique_ptr<CommsInterface> create(std::string_view type);
235 std::atomic<X>& aref;
241 aref(var), fval(std::move(finalValue)), expectedValue(std::move(expValue))
std::string brokerTargetAddress
the base for the broker address
Definition: CommsInterface.hpp:125
bool propertyLock()
Definition: CommsInterface.cpp:153
bool observer
true for connections that are for observation only
Definition: CommsInterface.hpp:144
std::function< void(int level, std::string_view name, std::string_view message)> loggingCallback
callback for logging
Definition: CommsInterface.hpp:153
std::string name
the name of the object
Definition: CommsInterface.hpp:123
int maxMessageSize
maximum message size
Definition: NetworkBrokerData.hpp:43
virtual ~CommsInterface()
Definition: CommsInterface.cpp:99
std::atomic< bool > disconnecting
flag indicating that the comm system is in the process of disconnecting
Definition: CommsInterface.hpp:158
CoreType
Definition: CoreTypes.hpp:36
std::string localInterface
the interface to use for the local connection
Definition: NetworkBrokerData.hpp:35
thread_generation
Definition: CommsInterface.hpp:29
int maxMessageCount
maximum message count
Definition: NetworkBrokerData.hpp:44
@ HELICS_LOG_LEVEL_WARNING
Definition: helics_enums.h:192
void setCallback(std::function< void(ActionMessage &&)> callback)
Definition: CommsInterface.cpp:501
bool autobroker
Definition: NetworkBrokerData.hpp:51
std::string brokerInitString
the initialization string for any automatically generated broker
Definition: CommsInterface.hpp:128
Definition: NetworkBrokerData.hpp:23
std::chrono::milliseconds connectionTimeout
Definition: CommsInterface.hpp:146
Definition: ActionMessage.hpp:30
bool observer
specify that the network connection is used for observation only
Definition: NetworkBrokerData.hpp:57
void logError(std::string_view message) const
Definition: CommsInterface.cpp:581
@ single
indicate that a single thread is used for transmitting and receiving
std::shared_ptr< Broker > create(CoreType type, std::string_view configureString)
Definition: BrokerFactory.cpp:99
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:155
void setMessageSize(int maxMsgSize, int maxCount)
Definition: CommsInterface.cpp:518
@ dual
indicate that separate threads are used, 1 for transmission and 1 for reception
void setServerMode(bool serverActive)
Definition: CommsInterface.cpp:550
void logMessage(std::string_view message) const
Definition: CommsInterface.cpp:563
Definition: CommsInterface.hpp:201
Definition: GlobalFederateId.hpp:184
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:151
void join_tx_rx_thread()
Definition: CommsInterface.cpp:458
int32_t messageID
8 – message ID for a variety of purposes
Definition: ActionMessage.hpp:36
@ ERRORED
some ERRORED occurred on the connection
void setExtraData(int32_t data)
Definition: ActionMessage.hpp:157
void disconnect()
Definition: CommsInterface.cpp:385
std::string brokerInitString
a string containing arguments for the broker initialization
Definition: NetworkBrokerData.hpp:36
void transmit(route_id rid, const ActionMessage &cmd)
Definition: CommsInterface.cpp:170
Definition: CommsInterface.hpp:194
@ TERMINATED
the connection has been TERMINATED
bool useJsonSerialization
true to make all connections use JSON serialization
Definition: CommsInterface.hpp:143
void logWarning(std::string_view message) const
Definition: CommsInterface.cpp:572
std::string brokerAddress
the address or domain name of the broker
Definition: NetworkBrokerData.hpp:34
SmallBuffer payload
buffer to contain the data payload
Definition: ActionMessage.hpp:48
std::string localTargetAddress
the base for the receive address
Definition: CommsInterface.hpp:124
std::string brokerName
Definition: CommsInterface.hpp:126
void setLoggingCallback(std::function< void(int level, std::string_view name, std::string_view message)> callback)
Definition: CommsInterface.cpp:509
Definition: CommsInterface.hpp:25
std::atomic< bool > requestDisconnect
flag gets set when disconnect is called
Definition: CommsInterface.hpp:149
@ STARTUP
the connection is in STARTUP mode
void addRoute(route_id rid, std::string_view routeInfo)
Definition: CommsInterface.cpp:188
constexpr BaseType baseValue() const
Definition: GlobalFederateId.hpp:192
ConnectionStatus
Definition: CommsInterface.hpp:107
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
virtual void loadNetworkInfo(const NetworkBrokerData &netInfo)
Definition: CommsInterface.cpp:104
@ RECONNECTING
we are trying reconnect
Definition: CommsInterface.hpp:233
bool serverMode
some comms have a server mode and non-server mode
Definition: CommsInterface.hpp:141
@ HELICS_LOG_LEVEL_ERROR
Definition: helics_enums.h:188
ServerModeOptions server_mode
setup a server mode
Definition: NetworkBrokerData.hpp:58
void setName(const std::string &commName)
Definition: CommsInterface.cpp:377
void setTimeout(std::chrono::milliseconds timeOut)
Definition: CommsInterface.cpp:542
void setRequireBrokerConnection(bool requireBrokerConnection)
Definition: CommsInterface.cpp:369
bool mRequireBrokerConnection
specify that the comms should assume we have a broker
Definition: CommsInterface.hpp:139
std::string connectionAddress
the address for connecting
Definition: NetworkBrokerData.hpp:37
bool autoBroker
the broker should be automatically generated if needed
Definition: CommsInterface.hpp:142
std::string brokerName
the identifier for the broker
Definition: NetworkBrokerData.hpp:33
int maxMessageSize
the maximum message size for the queues (if needed)
Definition: CommsInterface.hpp:147
virtual void setFlag(std::string_view flag, bool val)
Definition: CommsInterface.cpp:531
bool reconnect()
Definition: CommsInterface.cpp:471
@ HELICS_LOG_LEVEL_INTERFACES
Definition: helics_enums.h:199
bool isPriorityCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:232
@ CONNECTED
we are CONNECTED
bool connect()
Definition: CommsInterface.cpp:262
bool isConnected() const
Definition: CommsInterface.cpp:558
int maxMessageCount
the maximum number of message to buffer (if needed)
Definition: CommsInterface.hpp:148
const std::string & getRandomID() const
Definition: CommsInterface.hpp:185
void removeRoute(route_id rid)
Definition: CommsInterface.cpp:197