Node Class Reference

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

Detailed Description

A node can advertise and subscribe topics, publish on advertised topics and listen to subscribed topics.

Constructor & Destructor Documentation

Node ( )

Constructor.

virtual ~Node ( )
virtual

Destructor.

Member Function Documentation

transport::PublisherPtr Advertise ( const std::string &  _topic,
unsigned int  _queueLimit = 1000,
double  _hzRate = 0 
)
inline

Adverise a topic.

Parameters
[in]_topicThe topic to advertise
[in]_queueLimitThe maximum number of outgoing messages to queue for delivery
[in]_hzUpdate rate for the publisher. Units are 1.0/seconds.
Returns
Pointer to new publisher object

References Node::DecodeTopicName(), and SingletonT< TopicManager >::Instance().

std::string DecodeTopicName ( const std::string &  _topic)

Decode a topic name.

Parameters
[in]Theencoded name
Returns
The decoded name

Referenced by Node::Advertise(), and Node::Subscribe().

std::string EncodeTopicName ( const std::string &  _topic)

Encode a topic name.

Parameters
[in]Thedecoded name
Returns
The encoded name
void Fini ( )

Finalize the node.

unsigned int GetId ( ) const

Get the unique ID of the node.

Returns
The unique ID of the node

Referenced by Node::Subscribe().

std::string GetMsgType ( const std::string &  _topic) const

Get the message type for a topic.

Parameters
[in]_topicThe topic
Returns
The message type
std::string GetTopicNamespace ( ) const

Get the topic namespace for this node.

Returns
The namespace
bool HandleData ( const std::string &  _topic,
const std::string &  _msg 
)

Handle incoming data.

Parameters
[in]_topicTopic for which the data was received
[in]_msgThe message that was received
Returns
true if the message was handled successfully, false otherwise
bool HandleMessage ( const std::string &  _topic,
MessagePtr  _msg 
)

Handle incoming msg.

Parameters
[in]_topicTopic for which the data was received
[in]_msgThe message that was received
Returns
true if the message was handled successfully, false otherwise
bool HasLatchedSubscriber ( const std::string &  _topic) const

Return true if a subscriber on a specific topic is latched.

Parameters
[in]_topicName of the topic to check.
Returns
True if a latched subscriber exists.
void Init ( const std::string &  _space = "")

Init the node.

Parameters
[in]_spaceSet the global namespace of all topics. If left blank, the topic will initialize to the first namespace on the Master
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.

Parameters
[in]_topicName of the topic to publish data on.
[in]_msgThe 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.

Parameters
[in]_topicName of the topic to publish data on.
[in]_msgThe message to publish.
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

void Publish ( const std::string &  _topic,
const google::protobuf::Message &  _message 
)
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.

Parameters
[in]_topicThe topic to advertise
[in]_messageMessage to be published
void RemoveCallback ( const std::string &  _topic,
unsigned int  _id 
)
SubscriberPtr Subscribe ( const std::string &  _topic,
void(T::*)(const boost::shared_ptr< M const > &)  _fp,
T *  _obj,
bool  _latching = false 
)
inline

Subscribe to a topic using a class method as the callback.

Parameters
[in]_topicThe topic to subscribe to
[in]_fpClass method to be called on receipt of new message
[in]_objClass instance to be used on receipt of new message
[in]_latchingIf true, latch latest incoming message; otherwise don't latch
Returns
Pointer to new Subscriber object

References Node::DecodeTopicName(), Node::GetId(), and SingletonT< TopicManager >::Instance().

SubscriberPtr Subscribe ( const std::string &  _topic,
void(*)(const boost::shared_ptr< M const > &)  _fp,
bool  _latching = false 
)
inline

Subscribe to a topic using a bare function as the callback.

Parameters
[in]_topicThe topic to subscribe to
[in]_fpFunction to be called on receipt of new message
[in]_latchingIf true, latch latest incoming message; otherwise don't latch
Returns
Pointer to new Subscriber object

References Node::DecodeTopicName(), Node::GetId(), and SingletonT< TopicManager >::Instance().

SubscriberPtr Subscribe ( const std::string &  _topic,
void(T::*)(const std::string &)  _fp,
T *  _obj,
bool  _latching = false 
)
inline

Subscribe to a topic using a class method as the callback.

Parameters
[in]_topicThe topic to subscribe to
[in]_fpClass method to be called on receipt of new message
[in]_objClass instance to be used on receipt of new message
[in]_latchingIf true, latch latest incoming message; otherwise don't latch
Returns
Pointer to new Subscriber object

References Node::DecodeTopicName(), Node::GetId(), SubscribeOptions::Init(), and SingletonT< TopicManager >::Instance().

SubscriberPtr Subscribe ( const std::string &  _topic,
void(*)(const std::string &)  _fp,
bool  _latching = false 
)
inline

Subscribe to a topic using a bare function as the callback.

Parameters
[in]_topicThe topic to subscribe to
[in]_fpFunction to be called on receipt of new message
[in]_latchingIf true, latch latest incoming message; otherwise don't latch
Returns
Pointer to new Subscriber object

References Node::DecodeTopicName(), Node::GetId(), SubscribeOptions::Init(), and SingletonT< TopicManager >::Instance().


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