Ignition Transport

API Reference

4.0.0
Node.hh File Reference
#include <algorithm>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_set>
#include <vector>
#include <ignition/msgs.hh>
#include "ignition/transport/AdvertiseOptions.hh"
#include "ignition/transport/Export.hh"
#include "ignition/transport/NodeOptions.hh"
#include "ignition/transport/NodeShared.hh"
#include "ignition/transport/Publisher.hh"
#include "ignition/transport/RepHandler.hh"
#include "ignition/transport/ReqHandler.hh"
#include "ignition/transport/SubscribeOptions.hh"
#include "ignition/transport/SubscriptionHandler.hh"
#include "ignition/transport/TopicUtils.hh"
#include "ignition/transport/TransportTypes.hh"

Go to the source code of this file.

Classes

class  Node
 A class that allows a client to communicate with other peers. There are two main communication modes: pub/sub messages and service calls. More...
 
class  Node::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...
 
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...
 

Namespaces

namespace  ignition
 
namespace  ignition::transport
 

Typedefs

using f
 

Functions

virtual ~Node ()
 Destructor.
 
*brief Old method for advertising a service This signature is *considered deprecated Please migrate to the callback signature std::function< void(ReplyT &_rep, bool &_result)> const AdvertiseServiceOptions ReplyT const std::string void(ClassT::*) _cb (const RequestT &_req, ReplyT &_rep, bool &_result)
 
class ignition::transport::Node Advertise (const std::string &_topic, bool(*_cb)(ReplyT &_rep), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 
*brief Old method for advertising a service This signature is *considered deprecated Please migrate to the callback signature std::function< void(ReplyT &_rep, bool &_result)> const AdvertiseServiceOptions ReplyT const std::string void(ClassT::ClassT const AdvertiseServiceOptions ReplyT bool Advertise (const std::string &_topic, bool(ClassT::*_cb)(const RequestT &_req, ReplyT &_rep), ClassT *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 
*brief Old method for advertising a service This signature is *considered deprecated Please migrate to the callback signature void(ClassT::ClassT const AdvertiseServiceOptions ReplyT bool Advertise (const std::string &_topic, bool(ClassT::*_cb)(ReplyT &_rep), ClassT *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 
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).
 
*brief Advertise a new service without any output parameter *In this version the callback is a member function *param[in] _topic Topic name associated to the service *param[in] _cb Callback to handle the service request with the *following RequestT bool Advertise (const std::string &_topic, void(ClassT::*_cb)(const RequestT &_req), ClassT *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 
std::vector< std::stringAdvertisedServices () const
 
std::vector< std::stringAdvertisedTopics () const
 Get the list of topics advertised by this node.
 
 if (!_rep.ParseFromString(reqHandlerPtr->Response()))
 
 if (!executed) return false
 
 if (!reqHandlerPtr->Result())
 
 if (!TopicUtils::FullyQualifiedName(this->Options().Partition(), this->Options().NameSpace(), _topic, fullyQualifiedTopic))
 
 if (localResponserFound)
 
 if (this->Shared() ->repliers.FirstHandler(fullyQualifiedTopic, _req.GetTypeName(), _rep.GetTypeName(), repHandler))
 
 if (this->Shared() ->TopicPublishers(fullyQualifiedTopic, addresses))
 
std::unique_lock< std::recursive_mutexlk (this->Shared() ->mutex)
 
 Node (const NodeOptions &_options=NodeOptions())
 Constructor.
 
return this Request (_topic, req, _cb)
 
return this Request (_topic, req, _cb, _obj)
 
return this Request (_topic, req, _timeout, _rep, _result)
 
template<typename RequestT >
bool Request (const std::string &_topic, const RequestT &_req)
 
return this Request< RequestT, ReplyT > (_topic, _req, f)
 
bool ServiceInfo (const std::string &_service, std::vector< ServicePublisher > &_publishers) const
 
void ServiceList (std::vector< std::string > &_services) const
 
reqHandlerPtr SetCallback (_cb)
 
this Shared () -> requests.AddHandler(fullyQualifiedTopic, this->NodeUuid(), reqHandlerPtr)
 
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 TopicInfo (const std::string &_topic, std::vector< MessagePublisher > &_publishers) const
 
void TopicList (std::vector< std::string > &_topics) const
 
bool UnadvertiseSrv (const std::string &_topic)
 
bool Unsubscribe (const std::string &_topic)
 Unsubscribe from a topic.
 
void waitForShutdown ()
 Block the current thread until a SIGINT or SIGTERM is received. Note that this function registers a signal handler. Do not use this function if you want to manage yourself SIGINT/SIGTERM.
 

Variables

*brief Advertise a new service without any output parameter *In this version the callback is a free function *param[in] _topic Topic name associated to the service *param[in] _cb Callback to handle the service request with the *following void(* _cb )(const RequestT &_req)
 
*brief Old method for advertising a service This signature is *considered deprecated Please migrate to the callback signature std::function< void(ReplyT &_rep, bool &_result)> const AdvertiseServiceOptions ReplyT const std::string void(ClassT::ClassT _obj )
 
*brief Advertise a new service without any output parameter *In this version the callback is a free function *param[in] _topic Topic name associated to the service *param[in] _cb Callback to handle the service request with the *following void const AdvertiseServiceOptions_options
 
reqHandlerPtr SetResponse & _rep
 
reqHandlerPtr SetMessage & _req
 
 _result = true
 
*brief Advertise a new service without any output parameter *In this version the callback is a free function *param[in] _topic Topic name associated to the service *param[in] _cb Callback to handle the service request with the *following void const AdvertiseServiceOptions ReplyT const std::string_topic
 
SrvAddresses_M addresses
 
*brief Advertise a new service without any output parameter *In this version the callback is a free function *param[in] _topic Topic name associated to the service *param[in] _cb Callback to handle the service request with the *following void const AdvertiseServiceOptions ReplyT const std::string std::function< void(const RequestT &_req, ReplyT &_rep, bool &_result)> const AdvertiseServiceOptions ReplyT boo Advertise )(const std::string &_topic, std::function< bool(const RequestT &_req, ReplyT &_rep)> &_cb, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
 
*brief Subscribe to a topic registering a callback The callback must *accept a std::string to represent the message and a MessageInfo *which provides metadata about the message *param[in] _topic Name of the topic to subscribe to *param[in] _callback A function pointer or std::function object that *has a void return value and accepts two arguments
 
*brief Old method for advertising a service This signature is *considered deprecated Please migrate to the callback signature * code
 
*brief 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
 
*brief Subscribe to a topic registering a callback The callback must *accept a std::string to represent the message data
 
 else
 
bool localResponserFound
 
*brief 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 with a default *value of ms
 
*brief 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 with a default *value of
 
*brief Advertise a new service without any output parameter *In this version the callback is a free function *param[in] _topic Topic name associated to the service *param[in] _cb Callback to handle the service request with the *following parameters
 
IRepHandlerPtr repHandler
 
std::shared_ptr< ReqHandler< RequestT, ReplyT > > reqHandlerPtr (new ReqHandler< RequestT, ReplyT >(this->NodeUuid()))
 
*brief Old method for advertising a service This signature is *considered deprecated Please migrate to the callback signature std::function< void(ReplyT &_rep, bool &_result)> const AdvertiseServiceOption RequestT )
 
return true
 

Function Documentation

◆ ~Node()

virtual ~Node ( )
virtual

Destructor.

◆ Advertise() [1/2]

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

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

◆ Node()

Node ( const NodeOptions & _options = NodeOptions())
explicit

Constructor.

Parameters
[in]_optionsNode options.

◆ Subscribe() [1/6]

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.

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.

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

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.

◆ Subscribe() [3/6]

template<typename MessageT >
bool Subscribe ( const std::string & _topic,
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 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.

◆ Subscribe() [4/6]

template<typename MessageT >
bool Subscribe ( const std::string & _topic,
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 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.

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

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.

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

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.

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