Gazebo Transport

API Reference

11.4.1
Node::Publisher Class Reference

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

#include <Node.hh>

Public Member Functions

 Publisher ()
 Default constructor. More...
 
 Publisher (const MessagePublisher &_publisher)
 Constructor. More...
 
virtual ~Publisher ()
 Destructor. More...
 
bool HasConnections () const
 Return true if this publisher has subscribers. More...
 
 operator bool ()
 Allows this class to be evaluated as a boolean. More...
 
 operator bool () const
 Allows this class to be evaluated as a boolean (const). More...
 
bool Publish (const ProtoMsg &_msg)
 Publish a message. This function will copy the message when publishing to interprocess subscribers. This copy is necessary to facilitate asynchronous publication. More...
 
bool PublishRaw (const std::string &_msgData, const std::string &_msgType)
 Publish a raw pre-serialized message. More...
 
bool ThrottledUpdateReady () const
 Check if message publication is throttled. If so, verify whether the next message should be published or not. More...
 
bool Valid () const
 Return true if valid information, such as a non-empty topic name, is present. More...
 

Detailed Description

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.

Pseudo code example

auto pub = myNode.Advertise<MsgType>("topic_name"); if (pub) { MsgType msg;

// Note that this version of Publish will copy the message // when publishing to interprocess subscribers. pub.Publish(msg); }

Constructor & Destructor Documentation

◆ Publisher() [1/2]

Publisher ( )

Default constructor.

◆ Publisher() [2/2]

Publisher ( const MessagePublisher _publisher)
explicit

Constructor.

Parameters
[in]_publisherA message publisher.

◆ ~Publisher()

virtual ~Publisher ( )
virtual

Destructor.

Member Function Documentation

◆ HasConnections()

bool HasConnections ( ) const

Return true if this publisher has subscribers.

Returns
True if subscribers have connected to this publisher.

◆ operator bool() [1/2]

operator bool ( )

Allows this class to be evaluated as a boolean.

Returns
True if valid
See also
Valid

◆ operator bool() [2/2]

operator bool ( ) const

Allows this class to be evaluated as a boolean (const).

Returns
True if valid
See also
Valid

◆ Publish()

bool Publish ( const ProtoMsg _msg)

Publish a message. This function will copy the message when publishing to interprocess subscribers. This copy is necessary to facilitate asynchronous publication.

Parameters
[in]_msgA google::protobuf message.
Returns
true when success.

◆ PublishRaw()

bool PublishRaw ( const std::string _msgData,
const std::string _msgType 
)

Publish a raw pre-serialized message.

Warning
This function is only intended for advanced users. The standard publishing function, Publish(const ProtoMsg &_msg), will ensure that your message is correctly serialized. It is strongly recommended that you use the standard publishing function unless there is a specific reason for using this one (e.g. you are forwarding or playing back data instead of serializing/deserializing it). We currently only support the serialization scheme of protobuf.
This function will copy the message data when publishing to remote subscribers (interprocess communication).
Note
This function will deserialize the message when sending it to local (intraprocess) subscribers.
Parameters
[in]_msgDataA std::string that represents a serialized google::protobuf message.
[in]_msgTypeA std::string that contains the message type name.
Returns
true when success.

◆ ThrottledUpdateReady()

bool ThrottledUpdateReady ( ) const

Check if message publication is throttled. If so, verify whether the next message should be published or not.

This may be used to skip resource or time-intensive operations in the case that the message won't be published.

Returns
true if the message should be published or false otherwise. Additionally always returns true if the topic is not throttled.

◆ Valid()

bool Valid ( ) const

Return true if valid information, such as a non-empty topic name, is present.

Returns
True if this object can be used in Publish() calls.

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