helics  3.3.0
TcpCommsSS.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 #pragma once
8 
9 #include "../NetworkCommsInterface.hpp"
10 
11 #include <atomic>
12 #include <set>
13 #include <string>
14 #include <vector>
15 
16 namespace gmlc::networking {
17 class TcpConnection;
18 }
19 
20 namespace helics {
21 namespace tcp {
22 
24  class TcpCommsSS final: public NetworkCommsInterface {
25  public:
27  TcpCommsSS() noexcept;
29  ~TcpCommsSS();
30 
32  void addConnection(std::string_view newConn);
34  void addConnections(const std::vector<std::string>& newConnections);
36  virtual void setFlag(std::string_view flag, bool val) override;
37 
39  virtual void loadNetworkInfo(const NetworkBrokerData& netInfo) override;
40 
41  private:
43  bool outgoingConnectionsAllowed{true};
44  bool reuse_address{false};
45  std::string encryption_config;
46  std::vector<std::string> connections;
47  virtual int getDefaultBrokerPort() const override;
48  virtual void queue_rx_function() override;
49  virtual void queue_tx_function() override;
50 
53  int processIncomingMessage(ActionMessage&& cmd);
54 
61  size_t dataReceive(gmlc::networking::TcpConnection* connection,
62  const char* data,
63  size_t bytes_received);
64  // bool errorHandle()
65  };
66 
67 } // namespace tcp
68 } // 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::NetworkCommsInterface::setFlag
virtual void setFlag(std::string_view flag, bool val) override
Definition: NetworkCommsInterface.cpp:209
helics::message_process_result::processed
@ processed
the message was used to update the current state
helics::tcp::TcpCommsSS::setFlag
virtual void setFlag(std::string_view flag, bool val) override
Definition: TcpCommsSS.cpp:76
helics::tcp::TcpCommsSS::addConnection
void addConnection(std::string_view newConn)
Definition: TcpCommsSS.cpp:55
helics::CommsInterface::thread_generation
thread_generation
Definition: CommsInterface.hpp:29
helics::NetworkCommsInterface::PortNumber
std::atomic< int > PortNumber
port to use for the local connection
Definition: NetworkCommsInterface.hpp:60
helics::tcp::TcpCommsSS::loadNetworkInfo
virtual void loadNetworkInfo(const NetworkBrokerData &netInfo) override
Definition: TcpCommsSS.cpp:39
helics::NetworkBrokerData
Definition: NetworkBrokerData.hpp:23
helics::CommsInterface::connectionTimeout
std::chrono::milliseconds connectionTimeout
Definition: CommsInterface.hpp:146
helics::tcp::TcpCommsSS::TcpCommsSS
TcpCommsSS() noexcept
Definition: TcpCommsSS.cpp:26
helics::NetworkCommsInterface::getAddress
std::string getAddress() const
Definition: NetworkCommsInterface.cpp:260
helics::ActionMessage
Definition: ActionMessage.hpp:30
helics::CommsInterface::logError
void logError(std::string_view message) const
Definition: CommsInterface.cpp:581
helics::tcp::TcpCommsSS
Definition: TcpCommsSS.h:24
helics::tcp::TcpCommsSS::addConnections
void addConnections(const std::vector< std::string > &newConnections)
Definition: TcpCommsSS.cpp:63
helics::CommsInterface::txQueue
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:155
helics::CommsInterface::CommsInterface
CommsInterface()=default
TcpCommsCommon.h
helics::tcp::TcpCommsSS::~TcpCommsSS
~TcpCommsSS()
Definition: TcpCommsSS.cpp:33
helics::CommsInterface::ActionCallback
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:151
helics::CommsInterface::disconnect
void disconnect()
Definition: CommsInterface.cpp:385
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::NetworkBrokerData::reuse_address
bool reuse_address
Definition: NetworkBrokerData.hpp:48
helics::CommsInterface::brokerName
std::string brokerName
Definition: CommsInterface.hpp:126
HELICS_CORE_TYPE_TCP_SS
@ HELICS_CORE_TYPE_TCP_SS
Definition: helics_enums.h:47
helics::prettyPrintString
std::string prettyPrintString(const ActionMessage &command)
Definition: ActionMessage.cpp:846
helics::isDisconnectCommand
bool isDisconnectCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:277
helics::CommsInterface
Definition: CommsInterface.hpp:25
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::actionMessageType
const char * actionMessageType(action_message_def::action_t action)
Definition: ActionMessage.cpp:811
helics::CommsInterface::serverMode
bool serverMode
some comms have a server mode and non-server mode
Definition: CommsInterface.hpp:141
helics::NetworkCommsInterface::encrypted
bool encrypted
Definition: NetworkCommsInterface.hpp:65
helics::NetworkCommsInterface
Definition: NetworkCommsInterface.hpp:18
helics::CommsInterface::maxMessageSize
int maxMessageSize
the maximum message size for the queues (if needed)
Definition: CommsInterface.hpp:147