Ignition Transport

API Reference

8.1.0

A class that allows a client to communicate with other peers. There are two main communication modes: pub/sub messages and service calls. More...

#include <ignition/transport/Node.hh>

Classes

class  Publisher
 A class that is used to store information about an advertised publisher. An instance of this class is returned from Node::Advertise, and should be used in subsequent Node::Publisher::Publish calls. More...
 

Public Member Functions

 Node (const NodeOptions &_options=NodeOptions())
 Constructor. More...
 
virtual ~Node ()
 Destructor. More...
 
template<typename MessageT >
Node::Publisher Advertise (const std::string &_topic, const AdvertiseMessageOptions &_options=AdvertiseMessageOptions())
 Advertise a new topic. If a topic is currently advertised, you cannot advertise it a second time (regardless of its type). More...
 
Node::Publisher Advertise (const std::string &_topic, const std::string &_msgTypeName, const AdvertiseMessageOptions &_options=AdvertiseMessageOptions())
 Advertise a new topic. If a topic is currently advertised, you cannot advertise it a second time (regardless of its type). More...
 
template<typename RequestT , typename ReplyT >
bool Advertise (const std::string &_topic, bool(*_callback)(const RequestT &_request, ReplyT &_reply), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service. In this version the callback is a plain function pointer. More...
 
template<typename ReplyT >
bool Advertise (const std::string &_topic, bool(*_callback)(ReplyT &_reply), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service without input parameter. In this version the callback is a free function. More...
 
template<typename RequestT >
bool Advertise (const std::string &_topic, void(*_callback)(const RequestT &_request), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service without any output parameter. In this version the callback is a free function. More...
 
template<typename RequestT , typename ReplyT >
bool Advertise (const std::string &_topic, std::function< bool(const RequestT &_request, ReplyT &_reply)> _callback, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service. In this version the callback is a lambda function. More...
 
template<typename ReplyT >
bool Advertise (const std::string &_topic, std::function< bool(ReplyT &_reply)> &_callback, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service without input parameter. In this version the callback is a lambda function. More...
 
template<typename RequestT >
bool Advertise (const std::string &_topic, std::function< void(const RequestT &_request)> &_callback, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service without any output parameter. In this version the callback is a lambda function. More...
 
template<typename ClassT , typename RequestT , typename ReplyT >
bool Advertise (const std::string &_topic, bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply), ClassT *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service. In this version the callback is a member function. More...
 
template<typename ClassT , typename ReplyT >
bool Advertise (const std::string &_topic, bool(ClassT::*_callback)(ReplyT &_reply), ClassT *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service without input parameter. In this version the callback is a member function. More...
 
template<typename ClassT , typename RequestT >
bool Advertise (const std::string &_topic, void(ClassT::*_callback)(const RequestT &_request), ClassT *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 Advertise a new service without any output parameter. In this version the callback is a member function. More...
 
std::vector< std::stringAdvertisedServices () const
 Get the list of services advertised by this node. More...
 
std::vector< std::stringAdvertisedTopics () const
 Get the list of topics advertised by this node. More...
 
bool EnableStats (const std::string &_topic, bool _enable, const std::string &_publicationTopic="/statistics", uint64_t _publicationRate=1)
 Turn topic statistics on or off. More...
 
const NodeOptionsOptions () const
 Get the reference to the current node options. More...
 
template<typename RequestT , typename ReplyT >
bool Request (const std::string &_topic, const RequestT &_request, void(*_callback)(const ReplyT &_reply, const bool _result))
 Request a new service using a non-blocking call. In this version the callback is a free function. More...
 
template<typename ReplyT >
bool Request (const std::string &_topic, void(*_callback)(const ReplyT &_reply, const bool _result))
 Request a new service without input parameter using a non-blocking call. In this version the callback is a free function. More...
 
template<typename RequestT , typename ReplyT >
bool Request (const std::string &_topic, const RequestT &_request, std::function< void(const ReplyT &_reply, const bool _result)> &_callback)
 Request a new service using a non-blocking call. In this version the callback is a lambda function. More...
 
template<typename ReplyT >
bool Request (const std::string &_topic, std::function< void(const ReplyT &_reply, const bool _result)> &_callback)
 Request a new service without input parameter using a non-blocking call. In this version the callback is a lambda function. More...
 
template<typename ClassT , typename RequestT , typename ReplyT >
bool Request (const std::string &_topic, const RequestT &_request, void(ClassT::*_callback)(const ReplyT &_reply, const bool _result), ClassT *_obj)
 Request a new service using a non-blocking call. In this version the callback is a member function. More...
 
template<typename ClassT , typename ReplyT >
bool Request (const std::string &_topic, void(ClassT::*_callback)(const ReplyT &_reply, const bool _result), ClassT *_obj)
 Request a new service without input parameter using a non-blocking call. In this version the callback is a member function. More...
 
template<typename RequestT , typename ReplyT >
bool Request (const std::string &_topic, const RequestT &_request, const unsigned int &_timeout, ReplyT &_reply, bool &_result)
 Request a new service using a blocking call. More...
 
template<typename ReplyT >
bool Request (const std::string &_topic, const unsigned int &_timeout, ReplyT &_reply, bool &_result)
 Request a new service without input parameter using a blocking call. More...
 
template<typename RequestT >
bool Request (const std::string &_topic, const RequestT &_request)
 Request a new service without waiting for response. More...
 
bool ServiceInfo (const std::string &_service, std::vector< ServicePublisher > &_publishers) const
 Get the information about a service. More...
 
void ServiceList (std::vector< std::string > &_services) const
 Get the list of topics currently advertised in the network. Note that this function can block for some time if the discovery is in its initialization phase. The value of the "heartbeatInterval" constant, with a default value of 1000ms, sets the maximum blocking time period. More...
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, void(*_callback)(const MessageT &_msg), const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. Note that this callback does not include any message information. In this version the callback is a free function. More...
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, std::function< void(const MessageT &_msg)> &_callback, const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. Note that this callback does not include any message information. In this version the callback is a lamda function. More...
 
template<typename ClassT , typename MessageT >
bool Subscribe (const std::string &_topic, void(ClassT::*_callback)(const MessageT &_msg), ClassT *_obj, const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. Note that this callback does not include any message information. In this version the callback is a member function. More...
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, void(*_callback)(const MessageT &_msg, const MessageInfo &_info), const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. Note that this callback includes message information. In this version the callback is a free function. More...
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, std::function< void(const MessageT &_msg, const MessageInfo &_info)> &_callback, const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. Note that this callback includes message information. In this version the callback is a lamda function. More...
 
template<typename ClassT , typename MessageT >
bool Subscribe (const std::string &_topic, void(ClassT::*_callback)(const MessageT &_msg, const MessageInfo &_info), ClassT *_obj, const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. Note that this callback includes message information. In this version the callback is a member function. More...
 
std::vector< std::stringSubscribedTopics () const
 Get the list of topics subscribed by this node. Note that we might be interested in one topic but we still don't know the address of a publisher. More...
 
bool SubscribeRaw (const std::string &_topic, const RawCallback &_callback, const std::string &_msgType=kGenericMessageType, const SubscribeOptions &_opts=SubscribeOptions())
 Subscribe to a topic registering a callback. The callback must accept a std::string to represent the message data, and a MessageInfo which provides metadata about the message. More...
 
bool TopicInfo (const std::string &_topic, std::vector< MessagePublisher > &_publishers) const
 Get the information about a topic. More...
 
void TopicList (std::vector< std::string > &_topics) const
 Get the list of topics currently advertised in the network. Note that this function can block for some time if the discovery is in its initialization phase. The value of the "heartbeatInterval" constant, with a default value of 1000 ms, sets the maximum blocking time period. More...
 
std::optional< TopicStatisticsTopicStats (const std::string &_topic) const
 Get the current statistics for a topic. Statistics must have been enabled using the EnableStatistics function, otherwise the return value will be std::nullopt. More...
 
bool UnadvertiseSrv (const std::string &_topic)
 Unadvertise a service. More...
 
bool Unsubscribe (const std::string &_topic)
 Unsubscribe from a topic. More...
 

Detailed Description

A class that allows a client to communicate with other peers. There are two main communication modes: pub/sub messages and service calls.

Constructor & Destructor Documentation

◆ Node()

Node ( const NodeOptions _options = NodeOptions())
explicit

Constructor.

Parameters
[in]_optionsNode options.

◆ ~Node()

virtual ~Node ( )
virtual

Destructor.

Member Function Documentation

◆ Advertise() [1/11]

Node::Publisher Advertise ( const std::string _topic,
const AdvertiseMessageOptions _options = AdvertiseMessageOptions() 
)

Advertise a new topic. If a topic is currently advertised, you cannot advertise it a second time (regardless of its type).

Parameters
[in]_topicTopic name to be advertised.
[in]_optionsAdvertise options.
Returns
A PublisherId, which can be used in Node::Publish calls. The PublisherId also acts as boolean, where true occurs if the topic was succesfully advertised.
See also
AdvertiseOptions.

◆ Advertise() [2/11]

Node::Publisher Advertise ( const std::string _topic,
const std::string _msgTypeName,
const AdvertiseMessageOptions _options = AdvertiseMessageOptions() 
)

Advertise a new topic. If a topic is currently advertised, you cannot advertise it a second time (regardless of its type).

Parameters
[in]_topicTopic name to be advertised.
[in]_msgTypeNameName of the message type that will be published on the topic. The message type name can be retrieved from a protobuf message using the GetTypeName() function.
[in]_optionsAdvertise options.
Returns
A PublisherId, which can be used in Node::Publish calls. The PublisherId also acts as boolean, where true occurs if the topic was succesfully advertised.
See also
AdvertiseOptions.

◆ Advertise() [3/11]

bool Advertise ( const std::string _topic,
bool(*)(const RequestT &_request, ReplyT &_reply)  _callback,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service. In this version the callback is a plain function pointer.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[in]_requestProtobuf message containing the request.
[out]_replyProtobuf message containing the response.
Returns
Service call result.
Parameters
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [4/11]

bool Advertise ( const std::string _topic,
bool(*)(ReplyT &_reply)  _callback,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service without input parameter. In this version the callback is a free function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[out]_replyProtobuf message containing the response.
Returns
Service call result.
Parameters
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [5/11]

bool Advertise ( const std::string _topic,
void(*)(const RequestT &_request)  _callback,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service without any output parameter. In this version the callback is a free function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[in]_requestProtobuf message containing the request.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [6/11]

bool Advertise ( const std::string _topic,
std::function< bool(const RequestT &_request, ReplyT &_reply)>  _callback,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service. In this version the callback is a lambda function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[in]_requestProtobuf message containing the request.
[out]_replyProtobuf message containing the response.
Returns
Service call result.
Parameters
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [7/11]

bool Advertise ( const std::string _topic,
std::function< bool(ReplyT &_reply)> &  _callback,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service without input parameter. In this version the callback is a lambda function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[out]_replyProtobuf message containing the response.
Returns
Service call result.
Parameters
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [8/11]

bool Advertise ( const std::string _topic,
std::function< void(const RequestT &_request)> &  _callback,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service without any output parameter. In this version the callback is a lambda function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[in]_requestProtobuf message containing the request.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [9/11]

bool Advertise ( const std::string _topic,
bool(ClassT::*)(const RequestT &_request, ReplyT &_reply)  _callback,
ClassT *  _obj,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service. In this version the callback is a member function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[in]_requestProtobuf message containing the request.
[out]_replyProtobuf message containing the response.
Returns
Service call result.
Parameters
[in]_objInstance containing the member function.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [10/11]

bool Advertise ( const std::string _topic,
bool(ClassT::*)(ReplyT &_reply)  _callback,
ClassT *  _obj,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service without input parameter. In this version the callback is a member function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[out]_replyProtobuf message containing the response.
Returns
Service call result.
Parameters
[in]_objInstance containing the member function.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.

◆ Advertise() [11/11]

bool Advertise ( const std::string _topic,
void(ClassT::*)(const RequestT &_request)  _callback,
ClassT *  _obj,
const AdvertiseServiceOptions _options = AdvertiseServiceOptions() 
)

Advertise a new service without any output parameter. In this version the callback is a member function.

Parameters
[in]_topicTopic name associated to the service.
[in]_callbackCallback to handle the service request with the following parameters:
[in]_requestProtobuf message containing the request.
[in]_objInstance containing the member function.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions

◆ AdvertisedServices()

std::vector<std::string> AdvertisedServices ( ) const

Get the list of services advertised by this node.

Returns
A vector containing all services advertised by this node.

◆ AdvertisedTopics()

std::vector<std::string> AdvertisedTopics ( ) const

Get the list of topics advertised by this node.

Returns
A vector containing all the topics advertised by this node.

◆ EnableStats()

bool EnableStats ( const std::string _topic,
bool  _enable,
const std::string _publicationTopic = "/statistics",
uint64_t  _publicationRate = 1 
)

Turn topic statistics on or off.

Parameters
[in]_topicThe name of the topic on which to enable or disable statistics.
[in]_enableTrue to enable statistics, false to disable.
[in]_publicationTopicTopic on which to publish statistics.
[in]_publicationRateRate at which to publish statistics.

◆ Options()

const NodeOptions& Options ( ) const

Get the reference to the current node options.

Returns
Reference to the current node options.

◆ Request() [1/9]

bool Request ( const std::string _topic,
const RequestT &  _request,
void(*)(const ReplyT &_reply, const bool _result)  _callback 
)

Request a new service using a non-blocking call. In this version the callback is a free function.

Parameters
[in]_topicService name requested.
[in]_requestProtobuf message containing the request's parameters.
[in]_callbackPointer to the callback function executed when the response arrives. The callback has the following parameters:
[in]_replyProtobuf message containing the response.
[in]_resultResult of the service call. If false, there was a problem executing your request.
Returns
true when the service call was succesfully requested.

◆ Request() [2/9]

bool Request ( const std::string _topic,
void(*)(const ReplyT &_reply, const bool _result)  _callback 
)

Request a new service without input parameter using a non-blocking call. In this version the callback is a free function.

Parameters
[in]_topicService name requested.
[in]_callbackPointer to the callback function executed when the response arrives. The callback has the following parameters:
[in]_replyProtobuf message containing the response.
[in]_resultResult of the service call. If false, there was a problem executing your request.
Returns
true when the service call was succesfully requested.

◆ Request() [3/9]

bool Request ( const std::string _topic,
const RequestT &  _request,
std::function< void(const ReplyT &_reply, const bool _result)> &  _callback 
)

Request a new service using a non-blocking call. In this version the callback is a lambda function.

Parameters
[in]_topicService name requested.
[in]_requestProtobuf message containing the request's parameters.
[in]_callbackLambda function executed when the response arrives. The callback has the following parameters:
[in]_replyProtobuf message containing the response.
[in]_resultResult of the service call. If false, there was a problem executing your request.
Returns
true when the service call was succesfully requested.

◆ Request() [4/9]

bool Request ( const std::string _topic,
std::function< void(const ReplyT &_reply, const bool _result)> &  _callback 
)

Request a new service without input parameter using a non-blocking call. In this version the callback is a lambda function.

Parameters
[in]_topicService name requested.
[in]_callbackLambda function executed when the response arrives. The callback has the following parameters:
[in]_replyProtobuf message containing the response.
[in]_resultResult of the service call. If false, there was a problem executing your request.
Returns
true when the service call was succesfully requested.

◆ Request() [5/9]

bool Request ( const std::string _topic,
const RequestT &  _request,
void(ClassT::*)(const ReplyT &_reply, const bool _result)  _callback,
ClassT *  _obj 
)

Request a new service using a non-blocking call. In this version the callback is a member function.

Parameters
[in]_topicService name requested.
[in]_requestProtobuf message containing the request's parameters.
[in]_callbackPointer to the callback function executed when the response arrives. The callback has the following parameters:
[in]_replyProtobuf message containing the response.
[in]_resultResult of the service call. If false, there was a problem executing your request.
[in]_objInstance containing the member function.
Returns
true when the service call was succesfully requested.

◆ Request() [6/9]

bool Request ( const std::string _topic,
void(ClassT::*)(const ReplyT &_reply, const bool _result)  _callback,
ClassT *  _obj 
)

Request a new service without input parameter using a non-blocking call. In this version the callback is a member function.

Parameters
[in]_topicService name requested.
[in]_callbackPointer to the callback function executed when the response arrives. The callback has the following parameters:
[in]_replyProtobuf message containing the response.
[in]_resultResult of the service call. If false, there was a problem executing your request.
[in]_objInstance containing the member function.
Returns
true when the service call was succesfully requested.

◆ Request() [7/9]

bool Request ( const std::string _topic,
const RequestT &  _request,
const unsigned int &  _timeout,
ReplyT &  _reply,
bool &  _result 
)

Request a new service using a blocking call.

Parameters
[in]_topicService name requested.
[in]_requestProtobuf message containing the request's parameters.
[in]_timeoutThe request will timeout after '_timeout' ms.
[out]_replyProtobuf message containing the response.
[out]_resultResult of the service call.
Returns
true when the request was executed or false if the timeout expired.

◆ Request() [8/9]

bool Request ( const std::string _topic,
const unsigned int &  _timeout,
ReplyT &  _reply,
bool &  _result 
)

Request a new service without input parameter using a blocking call.

Parameters
[in]_topicService name requested.
[in]_timeoutThe request will timeout after '_timeout' ms.
[out]_replyProtobuf message containing the response.
[out]_resultResult of the service call.
Returns
true when the request was executed or false if the timeout expired.

◆ Request() [9/9]

bool Request ( const std::string _topic,
const RequestT &  _request 
)

Request a new service without waiting for response.

Parameters
[in]_topicTopic requested.
[in]_requestProtobuf message containing the request's parameters.
Returns
true when the service call was succesfully requested.

◆ ServiceInfo()

bool ServiceInfo ( const std::string _service,
std::vector< ServicePublisher > &  _publishers 
) const

Get the information about a service.

Parameters
[in]_serviceName of the service.
[out]_publishersList of publishers on the service.
Returns
False if unable to get service info.

◆ ServiceList()

void ServiceList ( std::vector< std::string > &  _services) const

Get the list of topics currently advertised in the network. Note that this function can block for some time if the discovery is in its initialization phase. The value of the "heartbeatInterval" constant, with a default value of 1000ms, sets the maximum blocking time period.

Parameters
[out]_servicesList of advertised services.

◆ Subscribe() [1/6]

bool Subscribe ( const std::string _topic,
void(*)(const MessageT &_msg)  _callback,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. Note that this callback does not include any message information. In this version the callback is a free function.

Parameters
[in]_topicTopic to be subscribed.
[in]_callbackPointer to the callback function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

◆ Subscribe() [2/6]

bool Subscribe ( const std::string _topic,
std::function< void(const MessageT &_msg)> &  _callback,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. Note that this callback does not include any message information. In this version the callback is a lamda function.

Parameters
[in]_topicTopic to be subscribed.
[in]_callbackLambda function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

◆ Subscribe() [3/6]

bool Subscribe ( const std::string _topic,
void(ClassT::*)(const MessageT &_msg)  _callback,
ClassT *  _obj,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. Note that this callback does not include any message information. In this version the callback is a member function.

Parameters
[in]_topicTopic to be subscribed.
[in]_callbackPointer to the callback function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_objInstance containing the member function.
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

◆ Subscribe() [4/6]

bool Subscribe ( const std::string _topic,
void(*)(const MessageT &_msg, const MessageInfo &_info)  _callback,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. Note that this callback includes message information. In this version the callback is a free function.

Parameters
[in]_topicTopic to be subscribed.
[in]_callbackPointer to the callback function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_infoMessage information (e.g.: topic name).
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

◆ Subscribe() [5/6]

bool Subscribe ( const std::string _topic,
std::function< void(const MessageT &_msg, const MessageInfo &_info)> &  _callback,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. Note that this callback includes message information. In this version the callback is a lamda function.

Parameters
[in]_topicTopic to be subscribed.
[in]_callbackLambda function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_infoMessage information (e.g.: topic name).
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

◆ Subscribe() [6/6]

bool Subscribe ( const std::string _topic,
void(ClassT::*)(const MessageT &_msg, const MessageInfo &_info)  _callback,
ClassT *  _obj,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. Note that this callback includes message information. In this version the callback is a member function.

Parameters
[in]_topicTopic to be subscribed.
[in]_callbackPointer to the callback function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_infoMessage information (e.g.: topic name).
[in]_objInstance containing the member function.
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

◆ SubscribedTopics()

std::vector<std::string> SubscribedTopics ( ) const

Get the list of topics subscribed by this node. Note that we might be interested in one topic but we still don't know the address of a publisher.

Returns
A vector containing the subscribed topics (even if we do not have an address for a particular topic yet).

◆ SubscribeRaw()

bool SubscribeRaw ( const std::string _topic,
const RawCallback _callback,
const std::string _msgType = kGenericMessageType,
const SubscribeOptions _opts = SubscribeOptions() 
)

Subscribe to a topic registering a callback. The callback must accept a std::string to represent the message data, and a MessageInfo which provides metadata about the message.

Parameters
[in]_topicName of the topic to subscribe to
[in]_callbackA function pointer or std::function object that has a void return value and accepts two arguments: (const std::string &_msgData, const MessageInfo &_info).
[in]_msgTypeThe type of message to subscribe to. Using kGenericMessageType (the default) will allow this subscriber to listen to all message types. The callback function can identify the type for each message by inspecting its const MessageInfo& input argument.
[in]_optsOptions for subscribing.
Returns
True if subscribing was successful.

◆ TopicInfo()

bool TopicInfo ( const std::string _topic,
std::vector< MessagePublisher > &  _publishers 
) const

Get the information about a topic.

Parameters
[in]_topicName of the topic.
[out]_publishersList of publishers on the topic
Returns
False if unable to get topic info

◆ TopicList()

void TopicList ( std::vector< std::string > &  _topics) const

Get the list of topics currently advertised in the network. Note that this function can block for some time if the discovery is in its initialization phase. The value of the "heartbeatInterval" constant, with a default value of 1000 ms, sets the maximum blocking time period.

Parameters
[out]_topicsList of advertised topics.

◆ TopicStats()

std::optional<TopicStatistics> TopicStats ( const std::string _topic) const

Get the current statistics for a topic. Statistics must have been enabled using the EnableStatistics function, otherwise the return value will be std::nullopt.

Parameters
[in]_topicThe name of the topic to get statistics for. return A TopicStatistics class, or std::nullopt if statistics were not enabled.

◆ UnadvertiseSrv()

bool UnadvertiseSrv ( const std::string _topic)

Unadvertise a service.

Parameters
[in]_topicService name to be unadvertised.
Returns
true if the service was successfully unadvertised.

◆ Unsubscribe()

bool Unsubscribe ( const std::string _topic)

Unsubscribe from a topic.

Parameters
[in]_topicTopic name to be unsubscribed.
Returns
true when successfully unsubscribed or false otherwise.

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