helics  2.8.1
ZmqCommsSS.h
1 /*
2 Copyright (c) 2017-2021,
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 <map>
14 #include <set>
15 #include <string>
16 
17 namespace zmq {
18 class message_t;
19 class socket_t;
20 } // namespace zmq
21 
22 namespace helics {
23 namespace zeromq {
26  class ZmqCommsSS final: public NetworkCommsInterface {
27  public:
29  ZmqCommsSS() noexcept;
31  ~ZmqCommsSS() final;
33  virtual void loadNetworkInfo(const NetworkBrokerData& netInfo) override;
36  private:
37  virtual int getDefaultBrokerPort() const override;
38  virtual void queue_rx_function() override;
39  virtual void queue_tx_function() override;
40 
42  int processIncomingMessage(zmq::message_t& msg,
43  std::map<std::string, std::string>& connection_info);
46  bool processTxControlCmd(const ActionMessage& cmd,
47  std::map<route_id, std::string>& routes,
48  std::map<std::string, std::string>& connection_info);
49 
51  int processRxMessage(zmq::socket_t& socket,
52  std::map<std::string, std::string>& connection_info);
55  int replyToIncomingMessage(zmq::message_t& msg, zmq::socket_t& sock);
56 
57  int initializeConnectionToBroker(zmq::socket_t& brokerConnection);
58 
59  int initializeBrokerConnections(zmq::socket_t& brokerSocket,
60  zmq::socket_t& brokerConnection);
61  };
62 
63 } // namespace zeromq
64 } // 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:152
helics::insertProtocol
void insertProtocol(std::string &networkAddress, interface_type interfaceT)
Definition: NetworkBrokerData.cpp:291
helics::message_process_result::processed
@ processed
the message was used to update the current state
helics::CommsInterface::name
std::string name
the name of the object
Definition: CommsInterface.hpp:123
helics::zeromq::ZmqCommsSS::ZmqCommsSS
ZmqCommsSS() noexcept
Definition: ZmqCommsSS.cpp:53
helics::CommsInterface::connection_status::terminated
@ terminated
the connection has been terminated
helics::CommsInterface::logWarning
void logWarning(const std::string &message) const
Definition: CommsInterface.cpp:570
helics::extractInterfaceandPort
std::pair< std::string, int > extractInterfaceandPort(const std::string &address)
Definition: NetworkBrokerData.cpp:226
helics::CommsInterface::disconnecting
std::atomic< bool > disconnecting
flag indicating that the comm system is in the process of disconnecting
Definition: CommsInterface.hpp:156
helics::zeromq::ZmqCommsSS::~ZmqCommsSS
~ZmqCommsSS() final
Definition: ZmqCommsSS.cpp:60
helics::CommsInterface::logError
void logError(const std::string &message) const
Definition: CommsInterface.cpp:579
helics::CommsInterface::thread_generation
thread_generation
Definition: CommsInterface.hpp:30
helics::NetworkCommsInterface::PortNumber
std::atomic< int > PortNumber
port to use for the local connection
Definition: NetworkCommsInterface.hpp:57
helics::CommsInterface::brokerInitString
std::string brokerInitString
the initialization string for any automatically generated broker
Definition: CommsInterface.hpp:128
helics::NetworkBrokerData
Definition: NetworkBrokerData.hpp:36
helics::CommsInterface::connectionTimeout
std::chrono::milliseconds connectionTimeout
Definition: CommsInterface.hpp:144
helics::NetworkCommsInterface::getAddress
std::string getAddress() const
Definition: NetworkCommsInterface.cpp:228
helics::ActionMessage
Definition: ActionMessage.hpp:29
helics::NetworkCommsInterface::generateReplyToIncomingMessage
ActionMessage generateReplyToIncomingMessage(ActionMessage &cmd)
Definition: NetworkCommsInterface.cpp:194
ZmqContextManager::getContextPointer
static std::shared_ptr< ZmqContextManager > getContextPointer(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:37
helics::zeromq::ZmqCommsSS
Definition: ZmqCommsSS.h:26
helics::CommsInterface::txQueue
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:153
helics::isValidCommand
bool isValidCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:317
helics::CommsInterface::ActionCallback
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:149
helics::CommsInterface::connection_status::error
@ error
some error occurred on the connection
helics::CommsInterface::disconnect
void disconnect()
Definition: CommsInterface.cpp:384
ZmqCommsCommon.h
helics::NetworkCommsInterface::brokerPort
int brokerPort
standardized broker port to use for connection to the brokers
Definition: NetworkCommsInterface.hpp:56
helics::CommsInterface::localTargetAddress
std::string localTargetAddress
the base for the receive address
Definition: CommsInterface.hpp:124
helics::CommsInterface::brokerName
std::string brokerName
the identifier for the broker
Definition: CommsInterface.hpp:126
helics::prettyPrintString
std::string prettyPrintString(const ActionMessage &command)
Definition: ActionMessage.cpp:861
helics::isDisconnectCommand
bool isDisconnectCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:276
helics::CommsInterface
Definition: CommsInterface.hpp:26
helics::CommsInterface::requestDisconnect
std::atomic< bool > requestDisconnect
flag gets set when disconnect is called
Definition: CommsInterface.hpp:147
helics::NetworkCommsInterface::loadNetworkInfo
virtual void loadNetworkInfo(const NetworkBrokerData &netInfo) override
Definition: NetworkCommsInterface.cpp:77
helics::interface_type::tcp
@ tcp
using tcp ports for communication
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::interface_type
interface_type
Definition: NetworkBrokerData.hpp:24
helics::CommsInterface::serverMode
bool serverMode
some comms have a server mode and non-server mode
Definition: CommsInterface.hpp:140
helics::makePortAddress
std::string makePortAddress(const std::string &networkInterface, int portNumber)
Definition: NetworkBrokerData.cpp:216
helics::NetworkCommsInterface
Definition: NetworkCommsInterface.hpp:18
helics::NetworkCommsInterface::appendNameToAddress
bool appendNameToAddress
flag to append the name to the network address
Definition: NetworkCommsInterface.hpp:60
helics::CommsInterface::connection_status::connected
@ connected
we are connected
helics::zeromq::ZmqCommsSS::loadNetworkInfo
virtual void loadNetworkInfo(const NetworkBrokerData &netInfo) override
Definition: ZmqCommsSS.cpp:28
helics::CommsInterface::logMessage
void logMessage(const std::string &message) const
Definition: CommsInterface.cpp:561