class Communication
Declaration
class Communication { /* full declaration omitted */ };Declared at: robot_comm/include/robot_comm/Communication.h:24
Member Variables
- protected std::string name_
- protected std::shared_ptr<ISerializer> serializer_
- protected std::shared_ptr<TransportInterface> transport_
- protected int subscribers_
- protected std::mutex mutex_
- protected std::atomic<bool> running_
- private std::string tx_topic_
- private std::string rx_topic_
- private int latest_rx_
- private std::chrono::steady_clock::time_point latest_rx_time_
- private std::mutex rx_mutex_
- private std::shared_ptr<SubscriberBase> rx_subscriber_
- private std::atomic<bool> peer_seen_
- private std::atomic<bool> peer_lost_
Method Overview
- public Communication(std::string name, const mc_rtc::Configuration & config, robot_comm::SerializationBackend backend = SerializationBackend::Flatbuffer)
- protected robot_comm::SerializationBackend backendFromString(const std::string & backend)
- public void dispatch(const std::string & topic, const robot_comm::ByteBuffer & payload)
- public template <typename T>robot_comm::ByteBuffer encode(const T & msg)
- public void handleQuery(const std::string & topic, robot_comm::QueryHandler handler)
- protected mc_rtc::Configuration parseConfig(const mc_rtc::Configuration & config)
- public bool peerAlive() const
- protected robot_comm::Protocol protocolFromString(const std::string & protocol)
- public template <typename T>bool publish(const std::string & topic, const T & msg)
- public template <typename T>int query(const std::string & topic, std::chrono::milliseconds timeout = <null expr>)
- public int query(const std::string & topic, const robot_comm::ByteBuffer & payload, std::chrono::milliseconds timeout = <null expr>)
- public int receive(std::chrono::steady_clock::time_point * arrival = nullptr)
- public template <typename T, typename Handler>void registerQueryable(const std::string & topic, Handler && handler)
- public int rxAge()
- public bool send(const robot_comm::ByteBuffer & buffer)
- public inline std::shared_ptr<ISerializer> serializer() const
- public void setupClient()
- private void setupLiveliness(const std::string & role, const std::string & peer_role)
- public void setupServer()
- public void start()
- public void stop()
- public template <typename T, typename Callback>std::shared_ptr<Subscriber<T>> subscribe(const std::string & topic, Callback && cb)
- public virtual ~Communication()
Methods
¶Communication(
std::string name,
const mc_rtc::Configuration& config,
robot_comm::SerializationBackend backend =
SerializationBackend::Flatbuffer)
Communication(
std::string name,
const mc_rtc::Configuration& config,
robot_comm::SerializationBackend backend =
SerializationBackend::Flatbuffer)Declared at: robot_comm/include/robot_comm/Communication.h:30
Parameters
- std::string name
- Robot name, used as the prefix of the role-based topics.
- const mc_rtc::Configuration& config
- The `network_interface` configuration.
- robot_comm::SerializationBackend backend = SerializationBackend::Flatbuffer
- Serializer used for typed messages.
¶robot_comm::SerializationBackend
backendFromString(const std::string& backend)
robot_comm::SerializationBackend
backendFromString(const std::string& backend)Declared at: robot_comm/include/robot_comm/Communication.h:123
Parameters
- const std::string& backend
¶void dispatch(
const std::string& topic,
const robot_comm::ByteBuffer& payload)
void dispatch(
const std::string& topic,
const robot_comm::ByteBuffer& payload)Declared at: robot_comm/include/robot_comm/Communication.h:60
Parameters
- const std::string& topic
- const robot_comm::ByteBuffer& payload
¶template <typename T>
robot_comm::ByteBuffer encode(const T& msg)
template <typename T>
robot_comm::ByteBuffer encode(const T& msg)Description
Serialize `msg` for send().
Declared at: robot_comm/include/robot_comm/Communication.h:88
Templates
- T
Parameters
- const T& msg
¶void handleQuery(const std::string& topic,
robot_comm::QueryHandler handler)
void handleQuery(const std::string& topic,
robot_comm::QueryHandler handler)Description
Answer queries on `topic` with `handler`.
Declared at: robot_comm/include/robot_comm/Communication.h:67
Parameters
- const std::string& topic
- robot_comm::QueryHandler handler
¶mc_rtc::Configuration parseConfig(
const mc_rtc::Configuration& config)
mc_rtc::Configuration parseConfig(
const mc_rtc::Configuration& config)Declared at: robot_comm/include/robot_comm/Communication.h:121
Parameters
- const mc_rtc::Configuration& config
¶bool peerAlive() const
bool peerAlive() constDescription
False once the peer endpoint (interface for the server, manager for the client) was seen and then lost, as reported by the transport's liveliness. True again when it comes back.
Declared at: robot_comm/include/robot_comm/Communication.h:105
¶robot_comm::Protocol protocolFromString(
const std::string& protocol)
robot_comm::Protocol protocolFromString(
const std::string& protocol)Declared at: robot_comm/include/robot_comm/Communication.h:125
Parameters
- const std::string& protocol
¶template <typename T>
bool publish(const std::string& topic,
const T& msg)
template <typename T>
bool publish(const std::string& topic,
const T& msg)Description
Serialize and publish `msg` on `topic`.
Declared at: robot_comm/include/robot_comm/Communication.h:47
Templates
- T
Parameters
- const std::string& topic
- const T& msg
¶template <typename T>
int query(const std::string& topic,
std::chrono::milliseconds timeout =
<null expr>)
template <typename T>
int query(const std::string& topic,
std::chrono::milliseconds timeout =
<null expr>)Declared at: robot_comm/include/robot_comm/Communication.h:58
Templates
- T
Parameters
- const std::string& topic
- std::chrono::milliseconds timeout = <null expr>
¶int query(const std::string& topic,
const robot_comm::ByteBuffer& payload,
std::chrono::milliseconds timeout =
<null expr>)
int query(const std::string& topic,
const robot_comm::ByteBuffer& payload,
std::chrono::milliseconds timeout =
<null expr>)Declared at: robot_comm/include/robot_comm/Communication.h:71
Parameters
- const std::string& topic
- const robot_comm::ByteBuffer& payload
- std::chrono::milliseconds timeout = <null expr>
¶int receive(std::chrono::steady_clock::time_point*
arrival = nullptr)
int receive(std::chrono::steady_clock::time_point*
arrival = nullptr)Declared at: robot_comm/include/robot_comm/Communication.h:96
Parameters
- std::chrono::steady_clock::time_point* arrival = nullptr
¶template <typename T, typename Handler>
void registerQueryable(const std::string& topic,
Handler&& handler)
template <typename T, typename Handler>
void registerQueryable(const std::string& topic,
Handler&& handler)Declared at: robot_comm/include/robot_comm/Communication.h:55
Templates
- T
- Handler
Parameters
- const std::string& topic
- Handler&& handler
¶int rxAge()
int rxAge()Declared at: robot_comm/include/robot_comm/Communication.h:100
¶bool send(const robot_comm::ByteBuffer& buffer)
bool send(const robot_comm::ByteBuffer& buffer)Description
Publish `buffer` on the role's send topic.
Declared at: robot_comm/include/robot_comm/Communication.h:91
Parameters
- const robot_comm::ByteBuffer& buffer
¶inline std::shared_ptr<ISerializer> serializer()
const
inline std::shared_ptr<ISerializer> serializer()
constDescription
Serializer used by this endpoint.
Declared at: robot_comm/include/robot_comm/Communication.h:115
¶void setupClient()
void setupClient()Description
Robot role: send on {name}/state, receive on {name}/command.
Declared at: robot_comm/include/robot_comm/Communication.h:84
¶void setupLiveliness(const std::string& role,
const std::string& peer_role)
void setupLiveliness(const std::string& role,
const std::string& peer_role)Description
Declare this endpoint's liveliness token and watch the peer's, under uri/alive/{name}/{role}.
Declared at: robot_comm/include/robot_comm/Communication.h:143
Parameters
- const std::string& role
- const std::string& peer_role
¶void setupServer()
void setupServer()Description
Manager role: send on {name}/command, receive on {name}/state.
Declared at: robot_comm/include/robot_comm/Communication.h:82
¶void start()
void start()Description
Start the transport.
Declared at: robot_comm/include/robot_comm/Communication.h:37
¶void stop()
void stop()Description
Stop the transport.
Declared at: robot_comm/include/robot_comm/Communication.h:39
¶template <typename T, typename Callback>
std::shared_ptr<Subscriber<T>> subscribe(
const std::string& topic,
Callback&& cb)
template <typename T, typename Callback>
std::shared_ptr<Subscriber<T>> subscribe(
const std::string& topic,
Callback&& cb)Description
Call `cb(const T & )` for every message received on `topic`. Keep the returned subscriber alive for as long as you need the callback.
Declared at: robot_comm/include/robot_comm/Communication.h:52
Templates
- T
- Callback
Parameters
- const std::string& topic
- Callback&& cb
¶virtual ~Communication()
virtual ~Communication()Declared at: robot_comm/include/robot_comm/Communication.h:34