| helics 3.6.1

Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
helics::CommsInterface Class Referenceabstract

`#include <CommsInterface.hpp>`

Inheritance diagram for helics::CommsInterface:

## Public Types
enum class | thread_generation { single , dual }

## Public Member Functions
| CommsInterface ()=default
| CommsInterface (thread_generation threads)
virtual | ~CommsInterface ()
virtual void | loadNetworkInfo (const NetworkBrokerData &netInfo)
void | loadTargetInfo (std::string_view localTarget, std::string_view brokerTarget, gmlc::networking::InterfaceNetworks targetNetwork=gmlc::networking::InterfaceNetworks::LOCAL)
void | transmit (route_id rid, const ActionMessage &cmd)
void | transmit (route_id rid, ActionMessage &&cmd)
void | addRoute (route_id rid, std::string_view routeInfo)
void | removeRoute (route_id rid)
bool | connect ()
void | disconnect ()
bool | reconnect ()
void | setName (const std::string &commName)
void | setRequireBrokerConnection (bool requireBrokerConnection)
void | setCallback (std::function< void(ActionMessage &&)> callback)
void | setLoggingCallback (std::function< void(int level, std::string_view name, std::string_view message)> callback)
void | setMessageSize (int maxMsgSize, int maxCount)
bool | isConnected () const
void | setTimeout (std::chrono::milliseconds timeOut)
virtual void | setFlag (std::string_view flag, bool val)
void | setServerMode (bool serverActive)
void | logWarning (std::string_view message) const
void | logError (std::string_view message) const
void | logMessage (std::string_view message) const

## Protected Types
enum class | ConnectionStatus : int { STARTUP = -1 , CONNECTED = 0 , RECONNECTING = 1 , TERMINATED = 2 , ERRORED = 4 }

## Protected Member Functions
void | setTxStatus (ConnectionStatus status)
void | setRxStatus (ConnectionStatus status)
ConnectionStatus | getRxStatus () const
ConnectionStatus | getTxStatus () const
bool | propertyLock ()
void | propertyUnLock ()
void | join_tx_rx_thread ()
const std::string & | getRandomID () const

## Protected Attributes
gmlc::concurrency::TriggerVariable | rxTrigger
std::string | name
| the name of the object
std::string | localTargetAddress
| the base for the receive address
std::string | brokerTargetAddress
| the base for the broker address
std::string | brokerName
std::string | brokerInitString
| the initialization string for any automatically generated broker
bool | mRequireBrokerConnection
| specify that the comms should assume we have a broker More...
bool | serverMode {true}
| some comms have a server mode and non-server mode
bool | autoBroker {false}
| the broker should be automatically generated if needed
bool | useJsonSerialization {false}
| true to make all connections use JSON serialization
bool | observer {false}
| true for connections that are for observation only
std::chrono::milliseconds | connectionTimeout {4000}
int | maxMessageSize = 16 * 1024
| the maximum message size for the queues (if needed)
int | maxMessageCount = 512
| the maximum number of message to buffer (if needed)
std::atomic< bool > | requestDisconnect {false}
| flag gets set when disconnect is called
std::function< void(ActionMessage &&)> | ActionCallback
| the callback for what to do with a received message
std::function< void(int level, std::string_view name, std::string_view message)> | loggingCallback
| callback for logging
gmlc::containers::BlockingPriorityQueue< std::pair< route_id, ActionMessage > > | txQueue
| set of messages waiting to be transmitted
std::atomic< bool > | disconnecting
| flag indicating that the comm system is in the process of disconnecting More...
gmlc::networking::InterfaceNetworks | interfaceNetwork

## Detailed Description

implementation of a generic communications interface

## Member Enumeration Documentation

## ◆ ConnectionStatus

enum helics::CommsInterface::ConnectionStatus : int
| strong protected

enumeration of the connection status flags for more immediate feedback from the processing threads

Enumerator
STARTUP | the connection is in STARTUP mode
CONNECTED | we are CONNECTED
RECONNECTING | we are trying reconnect
TERMINATED | the connection has been TERMINATED
ERRORED | some ERRORED occurred on the connection

## ◆ thread_generation

enum helics::CommsInterface::thread_generation
| strong

enumeration of whether the threading system should generate a single thread or multiple threads

Enumerator
single | indicate that a single thread is used for transmitting and receiving
dual | indicate that separate threads are used, 1 for transmission and 1 for reception

## Constructor & Destructor Documentation

## ◆ CommsInterface()

helics::CommsInterface::CommsInterface | ( |  | ) |
| default

default constructor

## ◆ ~CommsInterface()

helics::CommsInterface::~CommsInterface | ( |  | ) |
| virtual

destructor

## Member Function Documentation

## ◆ addRoute()

void helics::CommsInterface::addRoute | ( | route_id | rid,
|  | std::string_view | routeInfo
| ) |  |

add a new route assigned to the appropriate id

References helics::route_id::baseValue(), helics::ActionMessage::messageID, helics::ActionMessage::payload, and helics::ActionMessage::setExtraData().

## ◆ connect()

bool helics::CommsInterface::connect | ( |  | ) |

connect the commsInterface

Returns
  true if the connection was successful false otherwise

## ◆ disconnect()

void helics::CommsInterface::disconnect | ( |  | ) |

disconnected the comms interface

Referenced by helics::inproc::InprocComms::~InprocComms(), helics::ipc::IpcComms::~IpcComms(), helics::mpi::MpiComms::~MpiComms(), helics::tcp::TcpComms::~TcpComms(), helics::tcp::TcpCommsSS::~TcpCommsSS(), helics::udp::UdpComms::~UdpComms(), helics::zeromq::ZmqComms::~ZmqComms(), and helics::zeromq::ZmqCommsSS::~ZmqCommsSS().

## ◆ getRandomID()

const std::string& helics::CommsInterface::getRandomID | ( |  | ) | const
| inline protected

get the generated randomID for this comm interface

## ◆ isConnected()

bool helics::CommsInterface::isConnected | ( |  | ) | const

check if the commInterface is connected

## ◆ join_tx_rx_thread()

void helics::CommsInterface::join_tx_rx_thread | ( |  | ) |
| protected

function to join the processing threads

## ◆ loadNetworkInfo()

void helics::CommsInterface::loadNetworkInfo | ( | const NetworkBrokerData & | netInfo | ) |
| virtual

load network information into the comms object

Reimplemented in helics::zeromq::ZmqCommsSS, helics::zeromq::ZmqComms, helics::udp::UdpComms, helics::tcp::TcpCommsSS, helics::tcp::TcpComms, helics::NetworkCommsInterface, helics::ipc::IpcComms, and helics::inproc::InprocComms.

References helics::NetworkBrokerData::autobroker, helics::NetworkBrokerData::brokerAddress, helics::NetworkBrokerData::brokerInitString, helics::NetworkBrokerData::brokerName, helics::NetworkBrokerData::connectionAddress, helics::NetworkBrokerData::localInterface, helics::NetworkBrokerData::maxMessageCount, helics::NetworkBrokerData::maxMessageSize, helics::NetworkBrokerData::observer, and helics::NetworkBrokerData::server_mode.

Referenced by helics::inproc::InprocComms::loadNetworkInfo(), helics::ipc::IpcComms::loadNetworkInfo(), and helics::NetworkCommsInterface::loadNetworkInfo().

## ◆ logError()

void helics::CommsInterface::logError | ( | std::string_view | message | ) | const

generate a log message as an error

References HELICS_LOG_LEVEL_ERROR.

## ◆ logMessage()

void helics::CommsInterface::logMessage | ( | std::string_view | message | ) | const

generate a log message as a level above warning or error

References HELICS_LOG_LEVEL_INTERFACES.

Referenced by helics::mpi::MpiComms::MpiComms().

## ◆ logWarning()

void helics::CommsInterface::logWarning | ( | std::string_view | message | ) | const

generate a log message as a warning

References HELICS_LOG_LEVEL_WARNING.

## ◆ propertyLock()

bool helics::CommsInterface::propertyLock | ( |  | ) |
| protected

function to protect certain properties in a threaded environment these functions should be called in a pair

Referenced by helics::tcp::TcpCommsSS::addConnection(), helics::tcp::TcpCommsSS::addConnections(), helics::inproc::InprocComms::loadNetworkInfo(), helics::ipc::IpcComms::loadNetworkInfo(), helics::NetworkCommsInterface::loadNetworkInfo(), helics::tcp::TcpComms::loadNetworkInfo(), helics::tcp::TcpCommsSS::loadNetworkInfo(), helics::udp::UdpComms::loadNetworkInfo(), helics::zeromq::ZmqComms::loadNetworkInfo(), helics::zeromq::ZmqCommsSS::loadNetworkInfo(), helics::NetworkCommsInterface::setAutomaticPortStartPort(), helics::NetworkCommsInterface::setBrokerPort(), helics::NetworkCommsInterface::setFlag(), helics::tcp::TcpComms::setFlag(), helics::tcp::TcpCommsSS::setFlag(), and helics::NetworkCommsInterface::setPortNumber().

## ◆ reconnect()

bool helics::CommsInterface::reconnect | ( |  | ) |

try reconnected from a mismatched or disconnection

## ◆ removeRoute()

void helics::CommsInterface::removeRoute | ( | route_id | rid | ) |

remove a route from use

References helics::route_id::baseValue(), helics::ActionMessage::messageID, and helics::ActionMessage::setExtraData().

## ◆ setCallback()

void helics::CommsInterface::setCallback | ( | std::function< void(ActionMessage &&)> | callback | ) |

set the callback for processing the messages

## ◆ setFlag()

void helics::CommsInterface::setFlag | ( | std::string_view | flag,
|  | bool | val
| ) |  |
| virtual

set a flag for the comms system

Reimplemented in helics::tcp::TcpCommsSS, helics::tcp::TcpComms, and helics::NetworkCommsInterface.

Referenced by helics::NetworkCommsInterface::setFlag().

## ◆ setLoggingCallback()

void helics::CommsInterface::setLoggingCallback | ( | std::function< void(int level, std::string_view name, std::string_view message)> | callback | ) |

set the callback for processing the messages

## ◆ setMessageSize()

void helics::CommsInterface::setMessageSize | ( | int | maxMsgSize,
|  | int | maxCount
| ) |  |

set the max message size and max Queue size

## ◆ setName()

void helics::CommsInterface::setName | ( | const std::string & | commName | ) |

set the name of the communicator

## ◆ setRequireBrokerConnection()

void helics::CommsInterface::setRequireBrokerConnection | ( | bool | requireBrokerConnection | ) |

set a flag indicating that a broker connection is required and all Connection fields are targeted at a broker

## ◆ setServerMode()

void helics::CommsInterface::setServerMode | ( | bool | serverActive | ) |

enable or disable the server mode for the comms

## ◆ setTimeout()

void helics::CommsInterface::setTimeout | ( | std::chrono::milliseconds | timeOut | ) |

set the timeout for the initial broker connection

Parameters

  timeOut | the value is in milliseconds

## ◆ transmit() [1/2]

void helics::CommsInterface::transmit | ( | route_id | rid,
|  | ActionMessage && | cmd
| ) |  |

transmit a message along a particular route

References helics::isPriorityCommand().

## ◆ transmit() [2/2]

void helics::CommsInterface::transmit | ( | route_id | rid,
|  | const ActionMessage & | cmd
| ) |  |

transmit a message along a particular route

References helics::isPriorityCommand().

## Member Data Documentation

## ◆ brokerName

std::string helics::CommsInterface::brokerName
| protected

the identifier for the broker

## ◆ connectionTimeout

std::chrono::milliseconds helics::CommsInterface::connectionTimeout {4000}
| protected

timeout for the initial connection to a broker or to bind a broker port(in ms)

## ◆ disconnecting

std::atomic<bool> helics::CommsInterface::disconnecting
| protected

Initial value:
{
false}

flag indicating that the comm system is in the process of disconnecting

Referenced by helics::zeromq::ZmqCommsSS::~ZmqCommsSS().

## ◆ interfaceNetwork

gmlc::networking::InterfaceNetworks helics::CommsInterface::interfaceNetwork
| protected

Initial value:
{
gmlc::networking::InterfaceNetworks::LOCAL}

## ◆ mRequireBrokerConnection

bool helics::CommsInterface::mRequireBrokerConnection
| protected

Initial value:
{
false}

specify that the comms should assume we have a broker

Referenced by helics::NetworkCommsInterface::loadNetworkInfo().

The documentation for this class was generated from the following files:

- CommsInterface.hpp
- CommsInterface.cpp