helics  2.8.1
TcpCommsSS.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 #pragma once
8 
9 #include "../NetworkCommsInterface.hpp"
10 
11 #include <atomic>
12 #include <set>
13 #include <string>
14 #include <vector>
15 
16 class AsioContextManager;
17 namespace asio {
18 class io_context;
19 } // namespace asio
20 
21 namespace helics {
22 namespace tcp {
23  class TcpConnection;
24 
26  class TcpCommsSS final: public NetworkCommsInterface {
27  public:
29  TcpCommsSS() noexcept;
31  ~TcpCommsSS();
32 
34  void addConnection(const std::string& newConn);
36  void addConnections(const std::vector<std::string>& newConnections);
38  virtual void setFlag(const std::string& flag, bool val) override;
39 
40  private:
41  bool outgoingConnectionsAllowed{
42  true};
43  bool reuse_address{false};
44  std::vector<std::string> connections;
45  virtual int getDefaultBrokerPort() const override;
46  virtual void queue_rx_function() override;
47  virtual void queue_tx_function() override;
48 
51  int processIncomingMessage(ActionMessage&& cmd);
52 
59  size_t dataReceive(TcpConnection* connection, const char* data, size_t bytes_received);
60  // bool errorHandle()
61  };
62 
63 } // namespace tcp
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
data
@ data
print timing+data transmissions
Definition: loggingHelper.hpp:30
helics::message_process_result::processed
@ processed
the message was used to update the current state
helics::extractInterfaceandPortString
std::pair< std::string, std::string > extractInterfaceandPortString(const std::string &address)
Definition: NetworkBrokerData.cpp:250
AsioContextManager::getContextPointer
static std::shared_ptr< AsioContextManager > getContextPointer(const std::string &contextName=std::string())
Definition: AsioContextManager.cpp:38
helics::CommsInterface::logWarning
void logWarning(const std::string &message) const
Definition: CommsInterface.cpp:570
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::tcp::TcpCommsSS::addConnection
void addConnection(const std::string &newConn)
Definition: TcpCommsSS.cpp:34
helics::NetworkCommsInterface::PortNumber
std::atomic< int > PortNumber
port to use for the local connection
Definition: NetworkCommsInterface.hpp:57
helics::CommsInterface::connectionTimeout
std::chrono::milliseconds connectionTimeout
Definition: CommsInterface.hpp:144
helics::tcp::TcpCommsSS::TcpCommsSS
TcpCommsSS() noexcept
Definition: TcpCommsSS.cpp:24
helics::NetworkCommsInterface::getAddress
std::string getAddress() const
Definition: NetworkCommsInterface.cpp:228
helics::ActionMessage
Definition: ActionMessage.hpp:29
TcpHelperClasses.h
helics::tcp::TcpCommsSS
Definition: TcpCommsSS.h:26
helics::tcp::TcpCommsSS::addConnections
void addConnections(const std::vector< std::string > &newConnections)
Definition: TcpCommsSS.cpp:42
helics::CommsInterface::txQueue
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > txQueue
set of messages waiting to be transmitted
Definition: CommsInterface.hpp:153
helics::CommsInterface::CommsInterface
CommsInterface()=default
AsioContextManager::getBaseContext
asio::io_context & getBaseContext() const
Definition: AsioContextManager.h:126
AsioContextManager
Definition: AsioContextManager.h:42
TcpCommsCommon.h
helics::tcp::TcpCommsSS::~TcpCommsSS
~TcpCommsSS()
Definition: TcpCommsSS.cpp:30
helics::CommsInterface::ActionCallback
std::function< void(ActionMessage &&)> ActionCallback
the callback for what to do with a received message
Definition: CommsInterface.hpp:149
helics::tcp::TcpCommsSS::setFlag
virtual void setFlag(const std::string &flag, bool val) override
Definition: TcpCommsSS.cpp:55
helics::CommsInterface::disconnect
void disconnect()
Definition: CommsInterface.cpp:384
helics::tcp::TcpConnection
Definition: TcpHelperClasses.h:26
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::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
error
@ error
only print errors
Definition: loggingHelper.hpp:22
helics::actionMessageType
const char * actionMessageType(action_message_def::action_t action)
Definition: ActionMessage.cpp:808
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::setFlag
virtual void setFlag(const std::string &flag, bool val) override
Definition: NetworkCommsInterface.cpp:177
helics::NetworkCommsInterface
Definition: NetworkCommsInterface.hpp:18
helics::CommsInterface::maxMessageSize
int maxMessageSize
the maximum message size for the queues (if needed)
Definition: CommsInterface.hpp:145
AsioContextManager::startContextLoop
LoopHandle startContextLoop()
Definition: AsioContextManager.cpp:151