A class that allows a client to communicate with other peers. More...
#include <ignition/transport/Node.hh>
Public Member Functions | |
Node (const NodeOptions &_options=NodeOptions()) | |
Constructor. More... | |
virtual | ~Node () |
Destructor. More... | |
template<typename T > | |
bool | Advertise (const std::string &_topic, const AdvertiseOptions &_options=AdvertiseOptions()) |
Advertise a new topic. More... | |
template<typename T1 , typename T2 > | |
bool | Advertise (const std::string &_topic, void(*_cb)(const T1 &_req, T2 &_rep, bool &_result), const AdvertiseOptions &_options=AdvertiseOptions()) |
Advertise a new service. More... | |
template<typename T1 , typename T2 > | |
bool | Advertise (const std::string &_topic, std::function< void(const T1 &_req, T2 &_rep, bool &_result)> &_cb, const AdvertiseOptions &_options=AdvertiseOptions()) |
Advertise a new service. More... | |
template<typename C , typename T1 , typename T2 > | |
bool | Advertise (const std::string &_topic, void(C::*_cb)(const T1 &_req, T2 &_rep, bool &_result), C *_obj, const AdvertiseOptions &_options=AdvertiseOptions()) |
Advertise a new service. 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 | Publish (const std::string &_topic, const ProtoMsg &_msg) |
Publish a message. More... | |
template<typename T1 , typename T2 > | |
bool | Request (const std::string &_topic, const T1 &_req, void(*_cb)(const T2 &_rep, const bool _result)) |
Request a new service using a non-blocking call. More... | |
template<typename T1 , typename T2 > | |
bool | Request (const std::string &_topic, const T1 &_req, std::function< void(const T2 &_rep, const bool _result)> &_cb) |
Request a new service using a non-blocking call. More... | |
template<typename C , typename T1 , typename T2 > | |
bool | Request (const std::string &_topic, const T1 &_req, void(C::*_cb)(const T2 &_rep, const bool _result), C *_obj) |
Request a new service using a non-blocking call. More... | |
template<typename T1 , typename T2 > | |
bool | Request (const std::string &_topic, const T1 &_req, const unsigned int &_timeout, T2 &_rep, bool &_result) |
Request a new service using a blocking call. 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. More... | |
template<typename T > | |
bool | Subscribe (const std::string &_topic, void(*_cb)(const T &_msg)) |
Subscribe to a topic registering a callback. More... | |
template<typename T > | |
bool | Subscribe (const std::string &_topic, std::function< void(const T &_msg)> &_cb) |
Subscribe to a topic registering a callback. More... | |
template<typename C , typename T > | |
bool | Subscribe (const std::string &_topic, void(C::*_cb)(const T &_msg), C *_obj) |
Subscribe to a topic registering a callback. More... | |
std::vector< std::string > | SubscribedTopics () const |
Get the list of topics subscribed by this node. 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. More... | |
bool | Unadvertise (const std::string &_topic) |
Unadvertise a topic. More... | |
bool | UnadvertiseSrv (const std::string &_topic) |
Unadvertise a service. More... | |
bool | Unsubscribe (const std::string &_topic) |
Unsubscribe from a topic. More... | |
Protected Attributes | |
std::unique_ptr< transport::NodePrivate > | dataPtr |
A class that allows a client to communicate with other peers.
There are two main communication modes: pub/sub messages and service calls.
ignition::transport::Node::Node | ( | const NodeOptions & | _options = NodeOptions() | ) |
Constructor.
[in] | _options | Node options. |
|
virtual |
Destructor.
|
inline |
Advertise a new topic.
[in] | _topic | Topic name to be advertised. |
[in] | _options | Advertise options. |
References ignition::transport::TopicUtils::FullyQualifiedName().
|
inline |
Advertise a new service.
In this version the callback is a free function.
[in] | _topic | Topic name associated to the service. |
[in] | _cb | Callback to handle the service request with the following parameters: |
[in] | _req | Protobuf message containing the request. |
[out] | _rep | Protobuf message containing the response. |
[out] | _result | Service call result. |
[in] | _options | Advertise options. |
|
inline |
Advertise a new service.
In this version the callback is a lambda function.
[in] | _topic | Topic name associated to the service. |
[in] | _cb | Callback to handle the service request with the following parameters: |
[in] | _req | Protobuf message containing the request. |
[out] | _rep | Protobuf message containing the response. |
[out] | _result | Service call result. |
[in] | _options | Advertise options. |
References ignition::transport::TopicUtils::FullyQualifiedName().
|
inline |
Advertise a new service.
In this version the callback is a member function.
[in] | _topic | Topic name associated to the service. |
[in] | _cb | Callback to handle the service request with the following parameters: |
[in] | _req | Protobuf message containing the request. |
[out] | _rep | Protobuf message containing the response. |
[out] | _result | Service call result. |
[in] | _obj | Instance containing the member function. |
[in] | _options | Advertise options. |
std::vector<std::string> ignition::transport::Node::AdvertisedServices | ( | ) | const |
Get the list of services advertised by this node.
std::vector<std::string> ignition::transport::Node::AdvertisedTopics | ( | ) | const |
Get the list of topics advertised by this node.
bool ignition::transport::Node::Publish | ( | const std::string & | _topic, |
const ProtoMsg & | _msg | ||
) |
Publish a message.
[in] | _topic | Topic to be published. |
[in] | _msg | protobuf message. |
|
inline |
Request a new service using a non-blocking call.
In this version the callback is a free function.
[in] | _topic | Topic requested. |
[in] | _req | Protobuf message containing the request's parameters. |
[in] | _cb | Pointer to the callback function executed when the response arrives. The callback has the following parameters: |
[in] | _rep | Protobuf message containing the response. |
[in] | _result | Result of the service call. If false, there was a problem executing your request. |
|
inline |
Request a new service using a non-blocking call.
In this version the callback is a lambda function.
[in] | _topic | Topic requested. |
[in] | _req | Protobuf message containing the request's parameters. |
[in] | _cb | Lambda function executed when the response arrives. The callback has the following parameters: |
[in] | _rep | Protobuf message containing the response. |
[in] | _result | Result of the service call. If false, there was a problem executing your request. |
References ignition::transport::TopicUtils::FullyQualifiedName().
|
inline |
Request a new service using a non-blocking call.
In this version the callback is a member function.
[in] | _topic | Service name requested. |
[in] | _req | Protobuf message containing the request's parameters. |
[in] | _cb | Pointer to the callback function executed when the response arrives. The callback has the following parameters: |
[in] | _rep | Protobuf message containing the response. |
[in] | _result | Result of the service call. If false, there was a problem executing your request. |
[in] | _obj | Instance containing the member function. |
|
inline |
Request a new service using a blocking call.
[in] | _topic | Topic requested. |
[in] | _req | Protobuf message containing the request's parameters. |
[in] | _timeout | The request will timeout after '_timeout' ms. |
[out] | _res | Protobuf message containing the response. |
[out] | _result | Result of the service call. |
References ignition::transport::TopicUtils::FullyQualifiedName().
bool ignition::transport::Node::ServiceInfo | ( | const std::string & | _service, |
std::vector< ServicePublisher > & | _publishers | ||
) | const |
Get the information about a service.
[in] | _service | Name of the service. |
[out] | _publishers | List of publishers on the service. |
void ignition::transport::Node::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.
[out] | _topics | List of advertised topics. |
|
inline |
Subscribe to a topic registering a callback.
In this version the callback is a free function.
[in] | _topic | Topic to be subscribed. |
[in] | _cb | Pointer to the callback function with the following parameters: |
[in] | _msg | Protobuf message containing a new topic update. |
|
inline |
Subscribe to a topic registering a callback.
In this version the callback is a lamda function.
[in] | _topic | Topic to be subscribed. |
[in] | _cb | Lambda function with the following parameters: |
[in] | _msg | Protobuf message containing a new topic update. |
References ignition::transport::TopicUtils::FullyQualifiedName().
|
inline |
Subscribe to a topic registering a callback.
In this version the callback is a member function.
[in] | _topic | Topic to be subscribed. |
[in] | _cb | Pointer to the callback function with the following parameters: |
[in] | _msg | Protobuf message containing a new topic update. |
[in] | _obj | Instance containing the member function. |
std::vector<std::string> ignition::transport::Node::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.
bool ignition::transport::Node::TopicInfo | ( | const std::string & | _topic, |
std::vector< MessagePublisher > & | _publishers | ||
) | const |
Get the information about a topic.
[in] | _topic | Name of the topic. |
[out] | _publishers | List of publishers on the topic |
void ignition::transport::Node::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.
[out] | _topics | List of advertised topics. |
bool ignition::transport::Node::Unadvertise | ( | const std::string & | _topic | ) |
Unadvertise a topic.
[in] | _topic | Topic name to be unadvertised. |
bool ignition::transport::Node::UnadvertiseSrv | ( | const std::string & | _topic | ) |
Unadvertise a service.
[in] | _topic | Topic name to be unadvertised. |
bool ignition::transport::Node::Unsubscribe | ( | const std::string & | _topic | ) |
Unsubscribe from a topic.
[in] | _topic | Topic name to be unsubscribed. |
|
protected |