helics  3.3.0
ZmqComms.h
1 /*
2 Copyright (c) 2017-2022,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 #pragma once
9 
10 #include "../NetworkCommsInterface.hpp"
11 
12 #include <atomic>
13 #include <set>
14 #include <string>
15 
16 namespace zmq {
17 class message_t;
18 class socket_t;
19 } // namespace zmq
20 namespace helics {
21 namespace zeromq {
23  class ZmqComms final: public NetworkCommsInterface {
24  public:
26  ZmqComms() noexcept;
28  ~ZmqComms();
30  virtual void loadNetworkInfo(const NetworkBrokerData& netInfo) override;
33  private:
34  virtual int getDefaultBrokerPort() const override;
35  virtual void queue_rx_function() override;
36  virtual void queue_tx_function() override;
37  virtual void closeReceiver() override;
38 
41  int processIncomingMessage(zmq::message_t& msg);
44  int replyToIncomingMessage(zmq::message_t& msg, zmq::socket_t& sock);
45 
46  int initializeBrokerConnections(zmq::socket_t& controlSocket);
47 
48  public:
49  std::string getPushAddress() const;
50  };
51 
52 } // namespace zeromq
53 } // namespace helics
helics::CommsInterface::brokerTargetAddress
std::string brokerTargetAddress
the base for the broker address
Definition: CommsInterface.hpp:125
helics::CommsInterface::propertyLock
bool propertyLock()
Definition: CommsInterface.cpp:153
helics::message_process_result::processed
@ processed
the message was used to update the current state
helics::zeromq::ZmqComms::loadNetworkInfo
virtual void loadNetworkInfo(const NetworkBrokerData &netInfo) override
Definition: ZmqComms.cpp:31
helics::CommsInterface::name
std::string name
the name of the object
Definition: CommsInterface.hpp:123
helics::zeromq::ZmqComms::ZmqComms
ZmqComms() noexcept
Definition: ZmqComms.cpp:57
HELICS_CORE_TYPE_ZMQ
@ HELICS_CORE_TYPE_ZMQ
Definition: helics_enums.h:26
helics::zeromq::ZmqComms
Definition: ZmqComms.h:23
helics::CommsInterface::disconnecting
std::atomic< bool > disconnecting
flag indicating that the comm system is in the process of disconnecting
Definition: CommsInterface.hpp:158
helics::NetworkCommsInterface::PortNumber
std::atomic< int > PortNumber
port to use for the local connection
Definition: NetworkCommsInterface.hpp:60
helics::NetworkCommsInterface::forceConnection
bool forceConnection
Definition: NetworkCommsInterface.hpp:68
helics::NetworkBrokerData
Definition: NetworkBrokerData.hpp:23
helics::CommsInterface::connectionTimeout
std::chrono::milliseconds connectionTimeout
Definition: CommsInterface.hpp:146
helics::zeromq::ZmqComms::~ZmqComms
~ZmqComms()
Definition: ZmqComms.cpp:60
helics::NetworkCommsInterface::generateReplyToIncomingMessage
ActionMessage generateReplyToIncomingMessage(ActionMessage &cmd)
Definition: NetworkCommsInterface.cpp:226
helics::CommsInterface::logError
void logError(std::string_view message) const
Definition: CommsInterface.cpp:581
ZmqContextManager::getContextPointer
static std::shared_ptr< ZmqContextManager > getContextPointer(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:37
helics::CommsInterface::txQueue
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:155
helics::isValidCommand
bool isValidCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:338
helics::isIgnoreableCommand
bool isIgnoreableCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:317
helics::CommsInterface::logMessage
void logMessage(std::string_view message) const
Definition: CommsInterface.cpp:563
helics::CommsInterface::ActionCallback
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:151
helics::CommsInterface::ConnectionStatus::ERRORED
@ ERRORED
some ERRORED occurred on the connection
helics::setActionFlag
void setActionFlag(FlagContainer &M, FlagIndex flag)
Definition: flagOperations.hpp:130
helics::CommsInterface::disconnect
void disconnect()
Definition: CommsInterface.cpp:385
helics::CommsInterface::transmit
void transmit(route_id rid, const ActionMessage &cmd)
Definition: CommsInterface.cpp:170
helics::CommsInterface::ConnectionStatus::TERMINATED
@ TERMINATED
the connection has been TERMINATED
ZmqCommsCommon.h
helics::CommsInterface::useJsonSerialization
bool useJsonSerialization
true to make all connections use JSON serialization
Definition: CommsInterface.hpp:143
helics::CommsInterface::logWarning
void logWarning(std::string_view message) const
Definition: CommsInterface.cpp:572
helics::NetworkCommsInterface::brokerPort
int brokerPort
standardized broker port to use for connection to the brokers
Definition: NetworkCommsInterface.hpp:59
helics::CommsInterface::localTargetAddress
std::string localTargetAddress
the base for the receive address
Definition: CommsInterface.hpp:124
helics::CommsInterface::brokerName
std::string brokerName
Definition: CommsInterface.hpp:126
helics::prettyPrintString
std::string prettyPrintString(const ActionMessage &command)
Definition: ActionMessage.cpp:846
helics::CommsInterface::requestDisconnect
std::atomic< bool > requestDisconnect
flag gets set when disconnect is called
Definition: CommsInterface.hpp:149
helics::CommsInterface::ConnectionStatus::STARTUP
@ STARTUP
the connection is in STARTUP mode
helics::NetworkCommsInterface::loadNetworkInfo
virtual void loadNetworkInfo(const NetworkBrokerData &netInfo) override
Definition: NetworkCommsInterface.cpp:97
helics::isProtocolCommand
bool isProtocolCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:226
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
HELICS_ERROR_TERMINATED
@ HELICS_ERROR_TERMINATED
Definition: helics_enums.h:248
helics::CommsInterface::serverMode
bool serverMode
some comms have a server mode and non-server mode
Definition: CommsInterface.hpp:141
helics::checkActionFlag
bool checkActionFlag(uint16_t flags, FlagIndex flag)
Definition: flagOperations.hpp:138
helics::use_json_serialization_flag
@ use_json_serialization_flag
flag to indicate it should use the json packetization
Definition: flagOperations.hpp:79
helics::NetworkCommsInterface
Definition: NetworkCommsInterface.hpp:18
helics::CommsInterface::ConnectionStatus::CONNECTED
@ CONNECTED
we are CONNECTED
helics::CommsInterface::getRandomID
const std::string & getRandomID() const
Definition: CommsInterface.hpp:185