A node can advertise and subscribe topics, publish on advertised topics and listen to subscribed topics. More...
#include <transport/transport.hh>
Inherits enable_shared_from_this< Node >.
Public Member Functions | |
Node () | |
Constructor. More... | |
virtual | ~Node () |
Destructor. More... | |
template<typename M > | |
transport::PublisherPtr | Advertise (const std::string &_topic, unsigned int _queueLimit=1000, double _hzRate=0) |
Advertise a topic. More... | |
transport::PublisherPtr | Advertise (const std::string &_topic, const std::string &_msgTypeName, unsigned int _queueLimit=1000, double _hzRate=0) |
Advertise a topic. More... | |
std::string | DecodeTopicName (const std::string &_topic) |
Decode a topic name. More... | |
std::string | EncodeTopicName (const std::string &_topic) |
Encode a topic name. More... | |
void | Fini () |
Finalize the node. More... | |
unsigned int | GetId () const |
Get the unique ID of the node. More... | |
std::string | GetMsgType (const std::string &_topic) const |
Get the message type for a topic. More... | |
std::string | GetTopicNamespace () const |
Get the topic namespace for this node. More... | |
bool | HandleData (const std::string &_topic, const std::string &_msg) |
Handle incoming data. More... | |
bool | HandleMessage (const std::string &_topic, MessagePtr _msg) |
Handle incoming msg. More... | |
bool | HasLatchedSubscriber (const std::string &_topic) const |
Return true if a subscriber on a specific topic is latched. More... | |
void | Init (const std::string &_space="") |
Init the node. More... | |
void | InsertLatchedMsg (const std::string &_topic, const std::string &_msg) |
Add a latched message to the node for publication. More... | |
void | InsertLatchedMsg (const std::string &_topic, MessagePtr _msg) |
Add a latched message to the node for publication. More... | |
bool | IsInitialized () const |
Check if this Node has been initialized. More... | |
void | ProcessIncoming () |
Process incoming messages. More... | |
void | ProcessPublishers () |
Process all publishers, which has each publisher send it's most recent message over the wire. More... | |
template<typename M > | |
void | Publish (const std::string &_topic, const google::protobuf::Message &_message) |
A convenience function for a one-time publication of a message. More... | |
void | Publish (const std::string &_topic, const google::protobuf::Message &_message) |
A convenience function for a one-time publication of a message. More... | |
void | RemoveCallback (const std::string &_topic, unsigned int _id) |
template<typename M , typename T > | |
SubscriberPtr | Subscribe (const std::string &_topic, void(T::*_fp)(const boost::shared_ptr< M const > &), T *_obj, bool _latching=false) |
Subscribe to a topic using a class method as the callback. More... | |
template<typename M > | |
SubscriberPtr | Subscribe (const std::string &_topic, void(*_fp)(const boost::shared_ptr< M const > &), bool _latching=false) |
Subscribe to a topic using a bare function as the callback. More... | |
template<typename T > | |
SubscriberPtr | Subscribe (const std::string &_topic, void(T::*_fp)(const std::string &), T *_obj, bool _latching=false) |
Subscribe to a topic using a class method as the callback. More... | |
SubscriberPtr | Subscribe (const std::string &_topic, void(*_fp)(const std::string &), bool _latching=false) |
Subscribe to a topic using a bare function as the callback. More... | |
bool | TryInit (const common::Time &_maxWait=common::Time(1, 0)) |
Try to initialize the node to use the global namespace, and specify the maximum wait time. More... | |
A node can advertise and subscribe topics, publish on advertised topics and listen to subscribed topics.
Node | ( | ) |
Constructor.
|
virtual |
Destructor.
|
inline |
Advertise a topic.
[in] | _topic | The topic to advertise |
[in] | _queueLimit | The maximum number of outgoing messages to queue for delivery |
[in] | _hz | Update rate for the publisher. Units are 1.0/seconds. |
References SingletonT< TopicManager >::Instance().
|
inline |
Advertise a topic.
[in] | _topic | The topic to advertise |
[in] | _queueLimit | The maximum number of outgoing messages to queue for delivery |
[in] | _hz | Update rate for the publisher. Units are 1.0/seconds. |
References SingletonT< TopicManager >::Instance().
std::string DecodeTopicName | ( | const std::string & | _topic | ) |
Decode a topic name.
[in] | The | encoded name |
std::string EncodeTopicName | ( | const std::string & | _topic | ) |
Encode a topic name.
[in] | The | decoded name |
void Fini | ( | ) |
Finalize the node.
unsigned int GetId | ( | ) | const |
Get the unique ID of the node.
std::string GetMsgType | ( | const std::string & | _topic | ) | const |
Get the message type for a topic.
[in] | _topic | The topic |
std::string GetTopicNamespace | ( | ) | const |
Get the topic namespace for this node.
bool HandleData | ( | const std::string & | _topic, |
const std::string & | _msg | ||
) |
Handle incoming data.
[in] | _topic | Topic for which the data was received |
[in] | _msg | The message that was received |
bool HandleMessage | ( | const std::string & | _topic, |
MessagePtr | _msg | ||
) |
Handle incoming msg.
[in] | _topic | Topic for which the data was received |
[in] | _msg | The message that was received |
bool HasLatchedSubscriber | ( | const std::string & | _topic | ) | const |
Return true if a subscriber on a specific topic is latched.
[in] | _topic | Name of the topic to check. |
void Init | ( | const std::string & | _space = "" | ) |
Init the node.
[in] | _space | Set the namespace of this topic. If this is the first Node initialized, then this namespace will become the global namespace. If left blank, the topic will initialize to the first namespace on the Master. If the Master does not have any namespaces within 1 second of calling this function, the Node will be initialized with a namespace of "default". |
void InsertLatchedMsg | ( | const std::string & | _topic, |
const std::string & | _msg | ||
) |
Add a latched message to the node for publication.
This is called when a subscription is connected to a publication.
[in] | _topic | Name of the topic to publish data on. |
[in] | _msg | The message to publish. |
void InsertLatchedMsg | ( | const std::string & | _topic, |
MessagePtr | _msg | ||
) |
Add a latched message to the node for publication.
This is called when a subscription is connected to a publication.
[in] | _topic | Name of the topic to publish data on. |
[in] | _msg | The message to publish. |
bool IsInitialized | ( | ) | const |
void ProcessIncoming | ( | ) |
Process incoming messages.
void ProcessPublishers | ( | ) |
Process all publishers, which has each publisher send it's most recent message over the wire.
This is for internal use only
|
inline |
A convenience function for a one-time publication of a message.
This is inefficient, compared to Node::Advertise followed by Publisher::Publish. This function should only be used when sending a message very infrequently.
[in] | _topic | The topic to advertise |
[in] | _message | Message to be published |
|
inline |
A convenience function for a one-time publication of a message.
This is inefficient, compared to Node::Advertise followed by Publisher::Publish. This function should only be used when sending a message very infrequently.
[in] | _topic | The topic to advertise |
[in] | _message | Message to be published |
void RemoveCallback | ( | const std::string & | _topic, |
unsigned int | _id | ||
) |
|
inline |
Subscribe to a topic using a class method as the callback.
[in] | _topic | The topic to subscribe to |
[in] | _fp | Class method to be called on receipt of new message |
[in] | _obj | Class instance to be used on receipt of new message |
[in] | _latching | If true, latch latest incoming message; otherwise don't latch |
References SingletonT< TopicManager >::Instance().
|
inline |
Subscribe to a topic using a bare function as the callback.
[in] | _topic | The topic to subscribe to |
[in] | _fp | Function to be called on receipt of new message |
[in] | _latching | If true, latch latest incoming message; otherwise don't latch |
References SingletonT< TopicManager >::Instance().
|
inline |
Subscribe to a topic using a class method as the callback.
[in] | _topic | The topic to subscribe to |
[in] | _fp | Class method to be called on receipt of new message |
[in] | _obj | Class instance to be used on receipt of new message |
[in] | _latching | If true, latch latest incoming message; otherwise don't latch |
References SubscribeOptions::Init(), and SingletonT< TopicManager >::Instance().
|
inline |
Subscribe to a topic using a bare function as the callback.
[in] | _topic | The topic to subscribe to |
[in] | _fp | Function to be called on receipt of new message |
[in] | _latching | If true, latch latest incoming message; otherwise don't latch |
References SubscribeOptions::Init(), and SingletonT< TopicManager >::Instance().
bool TryInit | ( | const common::Time & | _maxWait = common::Time(1, 0) | ) |
Try to initialize the node to use the global namespace, and specify the maximum wait time.
If a global namespace is not available by the time a duration of _maxWait has transpired, this will return false, and the Node will not be initialized.
[in] | _maxWait | The maximum amount of time to wait for the Node to initialize. The initialization might be delayed while waiting for namespaces to be found. The default is 1 second. |