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 <gz/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 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 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 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, 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 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 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::string > | AdvertisedServices () const |
Get the list of services advertised by this node. More... | |
std::vector< std::string > | AdvertisedTopics () 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 NodeOptions & | Options () const |
Get the reference to the current node options. More... | |
template<typename RequestT > | |
bool | Request (const std::string &_topic, const RequestT &_request) |
Request a new service without waiting for response. 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 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 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 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 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 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 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 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... | |
bool | RequestRaw (const std::string &_topic, const std::string &_request, const std::string &_requestType, const std::string &_responseType, unsigned int _timeout, std::string &_response, bool &_result) |
Request a new service using a blocking call. This request function expects a serialized protobuf message as the request and returns a serialized protobuf message as the 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, 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 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 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, 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 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 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::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. 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< 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. 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()
|
explicit |
Constructor.
- Parameters
-
[in] _options Node options.
◆ ~Node()
|
virtual |
Destructor.
Member Function Documentation
◆ Advertise() [1/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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _request Protobuf message containing the request.
- _reply Protobuf message containing the response.
- Returns Service call result.
[in] _options Advertise options.
- Returns
- true when the topic has been successfully advertised or false otherwise.
- See also
- AdvertiseOptions.
◆ Advertise() [2/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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _reply Protobuf message containing the response.
- Returns Service call result.
[in] _options Advertise options.
- Returns
- true when the topic has been successfully advertised or false otherwise.
- See also
- AdvertiseOptions.
◆ Advertise() [3/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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _request Protobuf message containing the request.
- _reply Protobuf message containing the response.
- Returns Service call result.
[in] _obj Instance containing the member function. [in] _options Advertise 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(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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _reply Protobuf message containing the response.
- Returns Service call result.
[in] _obj Instance containing the member function. [in] _options Advertise options.
- Returns
- true when the topic has been successfully advertised or false otherwise.
- See also
- AdvertiseOptions.
◆ Advertise() [5/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] _topic Topic name to be advertised. [in] _options Advertise 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() [6/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] _topic Topic name to be advertised. [in] _msgTypeName Name 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] _options Advertise 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() [7/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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _request Protobuf message containing the request.
- _reply Protobuf message containing the response.
- Returns Service call result.
[in] _options Advertise 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< 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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _reply Protobuf message containing the response.
- Returns Service call result.
[in] _options Advertise 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, |
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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _request Protobuf message containing the request.
[in] _options Advertise 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, |
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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _request Protobuf message containing the request.
[in] _options Advertise 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] _topic Topic name associated to the service. [in] _callback Callback to handle the service request with the following parameters: - _request Protobuf message containing the request.
[in] _obj Instance containing the member function. [in] _options Advertise 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] _topic The name of the topic on which to enable or disable statistics. [in] _enable True to enable statistics, false to disable. [in] _publicationTopic Topic on which to publish statistics. [in] _publicationRate Rate 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 | ||
) |
Request a new service without waiting for response.
- Parameters
-
[in] _topic Topic requested. [in] _request Protobuf message containing the request's parameters.
- Returns
- true when the service call was succesfully requested.
◆ Request() [2/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] _topic Service name requested. [in] _request Protobuf message containing the request's parameters. [in] _timeout The request will timeout after '_timeout' ms. [out] _reply Protobuf message containing the response. [out] _result Result of the service call.
- Returns
- true when the request was executed or false if the timeout expired.
◆ 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] _topic Service name requested. [in] _request Protobuf message containing the request's parameters. [in] _callback Lambda function executed when the response arrives. The callback has the following parameters: - _reply Protobuf message containing the response.
- _result Result 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, |
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] _topic Service name requested. [in] _request Protobuf message containing the request's parameters. [in] _callback Pointer to the callback function executed when the response arrives. The callback has the following parameters: - _reply Protobuf message containing the response.
- _result Result 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] _topic Service name requested. [in] _request Protobuf message containing the request's parameters. [in] _callback Pointer to the callback function executed when the response arrives. The callback has the following parameters: - _reply Protobuf message containing the response.
- _result Result of the service call. If false, there was a problem executing your request.
[in] _obj Instance containing the member function.
- Returns
- true when the service call was succesfully requested.
◆ Request() [6/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] _topic Service name requested. [in] _timeout The request will timeout after '_timeout' ms. [out] _reply Protobuf message containing the response. [out] _result Result of the service call.
- Returns
- true when the request was executed or false if the timeout expired.
◆ Request() [7/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] _topic Service name requested. [in] _callback Lambda function executed when the response arrives. The callback has the following parameters: - _reply Protobuf message containing the response.
- _result Result of the service call. If false, there was a problem executing your request.
- Returns
- true when the service call was succesfully requested.
◆ Request() [8/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] _topic Service name requested. [in] _callback Pointer to the callback function executed when the response arrives. The callback has the following parameters: - _reply Protobuf message containing the response.
- _result Result of the service call. If false, there was a problem executing your request.
- Returns
- true when the service call was succesfully requested.
◆ Request() [9/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] _topic Service name requested. [in] _callback Pointer to the callback function executed when the response arrives. The callback has the following parameters: - _reply Protobuf message containing the response.
- _result Result of the service call. If false, there was a problem executing your request.
[in] _obj Instance containing the member function.
- Returns
- true when the service call was succesfully requested.
◆ RequestRaw()
bool RequestRaw | ( | const std::string & | _topic, |
const std::string & | _request, | ||
const std::string & | _requestType, | ||
const std::string & | _responseType, | ||
unsigned int | _timeout, | ||
std::string & | _response, | ||
bool & | _result | ||
) |
Request a new service using a blocking call. This request function expects a serialized protobuf message as the request and returns a serialized protobuf message as the response.
- Parameters
-
[in] _topic Service name requested. [in] _request Protobuf message serialized into a string containing the request's parameters. [in] _requestType Message type of the request. [in] _responseType Message type of the response. [in] _timeout The request will timeout after '_timeout' ms. [out] _response Serialized protobuf message containing the response. [out] _result Result of the service call.
- Returns
- true when the request was executed or false if the timeout expired.
◆ ServiceInfo()
bool ServiceInfo | ( | const std::string & | _service, |
std::vector< ServicePublisher > & | _publishers | ||
) | const |
Get the information about a service.
- Parameters
-
[in] _service Name of the service. [out] _publishers List 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] _services List of advertised services.
◆ Subscribe() [1/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] _topic Topic to be subscribed. [in] _callback Lambda function with the following parameters: - _msg Protobuf message containing a new topic update.
[in] _opts Subscription options.
- Returns
- true when successfully subscribed or false otherwise.
◆ Subscribe() [2/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] _topic Topic to be subscribed. [in] _callback Lambda function with the following parameters: - _msg Protobuf message containing a new topic update.
- _info Message information (e.g.: topic name).
[in] _opts Subscription options.
- Returns
- true when successfully subscribed or false otherwise.
◆ Subscribe() [3/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] _topic Topic to be subscribed. [in] _callback Pointer to the callback function with the following parameters: - _msg Protobuf message containing a new topic update.
[in] _opts Subscription 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] _topic Topic to be subscribed. [in] _callback Pointer to the callback function with the following parameters: - _msg Protobuf message containing a new topic update.
- _info Message information (e.g.: topic name).
[in] _opts Subscription options.
- Returns
- true when successfully subscribed or false otherwise.
◆ Subscribe() [5/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] _topic Topic to be subscribed. [in] _callback Pointer to the callback function with the following parameters: - _msg Protobuf message containing a new topic update.
[in] _obj Instance containing the member function. [in] _opts Subscription 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] _topic Topic to be subscribed. [in] _callback Pointer to the callback function with the following parameters: - _msg Protobuf message containing a new topic update.
- _info Message information (e.g.: topic name).
[in] _obj Instance containing the member function. [in] _opts Subscription 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] _topic Name of the topic to subscribe to [in] _callback A function pointer or std::function object that has a void return value and accepts two arguments: (const std::string &_msgData, const MessageInfo &_info). [in] _msgType The 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] _opts Options 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] _topic Name of the topic. [out] _publishers List 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] _topics List 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] _topic The 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] _topic Service 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] _topic Topic name to be unsubscribed.
- Returns
- true when successfully unsubscribed or false otherwise.
The documentation for this class was generated from the following file: