Public Member Functions | Protected Attributes | List of all members
ignition::transport::Node Class Reference

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::NodePrivatedataPtr
 

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

ignition::transport::Node::Node ( const NodeOptions _options = NodeOptions())

Constructor.

Parameters
[in]_optionsNode options.
virtual ignition::transport::Node::~Node ( )
virtual

Destructor.

Member Function Documentation

template<typename T >
bool ignition::transport::Node::Advertise ( const std::string &  _topic,
const AdvertiseOptions _options = AdvertiseOptions() 
)
inline

Advertise a new topic.

Parameters
[in]_topicTopic name to be advertised.
[in]_optionsAdvertise options.
Returns
true if the topic was succesfully advertised.
See also
AdvertiseOptions.

References ignition::transport::TopicUtils::FullyQualifiedName().

template<typename T1 , typename T2 >
bool ignition::transport::Node::Advertise ( const std::string &  _topic,
void(*)(const T1 &_req, T2 &_rep, bool &_result)  _cb,
const AdvertiseOptions _options = AdvertiseOptions() 
)
inline

Advertise a new service.

In this version the callback is a free function.

Parameters
[in]_topicTopic name associated to the service.
[in]_cbCallback to handle the service request with the following parameters:
[in]_reqProtobuf message containing the request.
[out]_repProtobuf message containing the response.
[out]_resultService call result.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.
template<typename T1 , typename T2 >
bool ignition::transport::Node::Advertise ( const std::string &  _topic,
std::function< void(const T1 &_req, T2 &_rep, bool &_result)> &  _cb,
const AdvertiseOptions _options = AdvertiseOptions() 
)
inline

Advertise a new service.

In this version the callback is a lambda function.

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

References ignition::transport::TopicUtils::FullyQualifiedName().

template<typename C , typename T1 , typename T2 >
bool ignition::transport::Node::Advertise ( const std::string &  _topic,
void(C::*)(const T1 &_req, T2 &_rep, bool &_result)  _cb,
C *  _obj,
const AdvertiseOptions _options = AdvertiseOptions() 
)
inline

Advertise a new service.

In this version the callback is a member function.

Parameters
[in]_topicTopic name associated to the service.
[in]_cbCallback to handle the service request with the following parameters:
[in]_reqProtobuf message containing the request.
[out]_repProtobuf message containing the response.
[out]_resultService call result.
[in]_objInstance containing the member function.
[in]_optionsAdvertise options.
Returns
true when the topic has been successfully advertised or false otherwise.
See also
AdvertiseOptions.
std::vector<std::string> ignition::transport::Node::AdvertisedServices ( ) const

Get the list of services advertised by this node.

Returns
A vector containing all services advertised by this node.
std::vector<std::string> ignition::transport::Node::AdvertisedTopics ( ) const

Get the list of topics advertised by this node.

Returns
A vector containing all the topics advertised by this node.
bool ignition::transport::Node::Publish ( const std::string &  _topic,
const ProtoMsg _msg 
)

Publish a message.

Parameters
[in]_topicTopic to be published.
[in]_msgprotobuf message.
Returns
true when success.
template<typename T1 , typename T2 >
bool ignition::transport::Node::Request ( const std::string &  _topic,
const T1 &  _req,
void(*)(const T2 &_rep, const bool _result)  _cb 
)
inline

Request a new service using a non-blocking call.

In this version the callback is a free function.

Parameters
[in]_topicTopic requested.
[in]_reqProtobuf message containing the request's parameters.
[in]_cbPointer to the callback function executed when the response arrives. The callback has the following parameters:
[in]_repProtobuf 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.
template<typename T1 , typename T2 >
bool ignition::transport::Node::Request ( const std::string &  _topic,
const T1 &  _req,
std::function< void(const T2 &_rep, const bool _result)> &  _cb 
)
inline

Request a new service using a non-blocking call.

In this version the callback is a lambda function.

Parameters
[in]_topicTopic requested.
[in]_reqProtobuf message containing the request's parameters.
[in]_cbLambda function executed when the response arrives. The callback has the following parameters:
[in]_repProtobuf 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.

References ignition::transport::TopicUtils::FullyQualifiedName().

template<typename C , typename T1 , typename T2 >
bool ignition::transport::Node::Request ( const std::string &  _topic,
const T1 &  _req,
void(C::*)(const T2 &_rep, const bool _result)  _cb,
C *  _obj 
)
inline

Request a new service using a non-blocking call.

In this version the callback is a member function.

Parameters
[in]_topicService name requested.
[in]_reqProtobuf message containing the request's parameters.
[in]_cbPointer to the callback function executed when the response arrives. The callback has the following parameters:
[in]_repProtobuf 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.
template<typename T1 , typename T2 >
bool ignition::transport::Node::Request ( const std::string &  _topic,
const T1 &  _req,
const unsigned int &  _timeout,
T2 &  _rep,
bool &  _result 
)
inline

Request a new service using a blocking call.

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

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.

Parameters
[in]_serviceName of the service.
[out]_publishersList of publishers on the service.
Returns
False if unable to get service info.
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.

Parameters
[out]_topicsList of advertised topics.
template<typename T >
bool ignition::transport::Node::Subscribe ( const std::string &  _topic,
void(*)(const T &_msg)  _cb 
)
inline

Subscribe to a topic registering a callback.

In this version the callback is a free function.

Parameters
[in]_topicTopic to be subscribed.
[in]_cbPointer to the callback function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
Returns
true when successfully subscribed or false otherwise.
template<typename T >
bool ignition::transport::Node::Subscribe ( const std::string &  _topic,
std::function< void(const T &_msg)> &  _cb 
)
inline

Subscribe to a topic registering a callback.

In this version the callback is a lamda function.

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

References ignition::transport::TopicUtils::FullyQualifiedName().

template<typename C , typename T >
bool ignition::transport::Node::Subscribe ( const std::string &  _topic,
void(C::*)(const T &_msg)  _cb,
C *  _obj 
)
inline

Subscribe to a topic registering a callback.

In this version the callback is a member function.

Parameters
[in]_topicTopic to be subscribed.
[in]_cbPointer to the callback function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_objInstance containing the member function.
Returns
true when successfully subscribed or false otherwise.
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.

Returns
A vector containing the subscribed topics (even if we do not have an address for a particular topic yet).
bool ignition::transport::Node::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
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.

Parameters
[out]_topicsList of advertised topics.
bool ignition::transport::Node::Unadvertise ( const std::string &  _topic)

Unadvertise a topic.

Parameters
[in]_topicTopic name to be unadvertised.
Returns
true if the topic was unadvertised.
bool ignition::transport::Node::UnadvertiseSrv ( const std::string &  _topic)

Unadvertise a service.

Parameters
[in]_topicTopic name to be unadvertised.
Returns
true if the service was successfully unadvertised.
bool ignition::transport::Node::Unsubscribe ( const std::string &  _topic)

Unsubscribe from a topic.

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

Member Data Documentation

std::unique_ptr<transport::NodePrivate> ignition::transport::Node::dataPtr
protected

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