Ignition Transport

API Reference

4.0.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.
 
virtual ~Node ()
 Destructor.
 
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).
 
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).
 
std::vector< std::stringAdvertisedTopics () const
 Get the list of topics advertised by this node.
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, std::function< void(const MessageT &_msg)> &_cb, 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.
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, std::function< void(const MessageT &_msg, const MessageInfo &_info)> &_cb, 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.
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, void(*_cb)(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.
 
template<typename MessageT >
bool Subscribe (const std::string &_topic, void(*_cb)(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.
 
template<typename ClassT , typename MessageT >
bool Subscribe (const std::string &_topic, void(ClassT::*_cb)(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.
 
template<typename ClassT , typename MessageT >
bool Subscribe (const std::string &_topic, void(ClassT::*_cb)(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.
 
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.
 
bool Unsubscribe (const std::string &_topic)
 Unsubscribe from a topic.
 

Public Attributes

class ignition::transport::Node::Publisher Advertise [in]
 

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/2]

template<typename MessageT >
Node::Publisher Advertise ( const std::string & _topic,
const AdvertiseMessageOptions & _options = AdvertiseMessageOptions() )
inline

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.

References ignition::transport::_options, and Node::Advertise.

◆ Advertise() [2/2]

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.

◆ 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.

◆ Subscribe() [1/6]

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

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]_cbLambda function with the following parameters:
[in]_msgProtobuf message containing a new topic update.
[in]_optsSubscription options.
Returns
true when successfully subscribed or false otherwise.

References ignition::transport::_cb.

◆ Subscribe() [2/6]

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

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]_cbLambda 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.

References std::endl(), TopicUtils::FullyQualifiedName(), ignition::transport::lk(), and ignition::transport::Shared().

◆ Subscribe() [3/6]

template<typename MessageT >
bool Subscribe ( const std::string & _topic,
void(*)(const MessageT &_msg) _cb,
const SubscribeOptions & _opts = SubscribeOptions() )
inline

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]_cbPointer 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.

References ignition::transport::_cb.

◆ Subscribe() [4/6]

template<typename MessageT >
bool Subscribe ( const std::string & _topic,
void(*)(const MessageT &_msg, const MessageInfo &_info) _cb,
const SubscribeOptions & _opts = SubscribeOptions() )
inline

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]_cbPointer 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.

References ignition::transport::_cb.

◆ Subscribe() [5/6]

template<typename ClassT , typename MessageT >
bool Subscribe ( const std::string & _topic,
void(ClassT::*)(const MessageT &_msg) _cb,
ClassT * _obj,
const SubscribeOptions & _opts = SubscribeOptions() )
inline

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]_cbPointer 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.

References ignition::transport::_cb, ignition::transport::_obj, and std::bind().

◆ Subscribe() [6/6]

template<typename ClassT , typename MessageT >
bool Subscribe ( const std::string & _topic,
void(ClassT::*)(const MessageT &_msg, const MessageInfo &_info) _cb,
ClassT * _obj,
const SubscribeOptions & _opts = SubscribeOptions() )
inline

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]_cbPointer 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.

References ignition::transport::_cb, ignition::transport::_obj, and std::bind().

◆ 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).

◆ 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.

Member Data Documentation

◆ Advertise


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