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. | |
Publisher (const MessagePublisher &_publisher) | |
Constructor. | |
virtual | ~Publisher () |
Destructor. | |
bool | HasConnections () const |
Return true if this publisher has subscribers. | |
operator bool () | |
Allows this class to be evaluated as a boolean. | |
operator bool () const | |
Allows this class to be evaluated as a boolean (const). | |
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. | |
bool | PublishRaw (const std::string &_msgData, const std::string &_msgType) |
Publish a raw pre-serialized message. | |
bool | ThrottledUpdateReady () const |
Check if message publication is throttled. If so, verify whether the next message should be published or not. | |
bool | Valid () const |
Return true if valid information, such as a non-empty topic name, is present. | |
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]
|
explicit |
Constructor.
- Parameters
-
[in] _publisher A message publisher.
◆ ~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 | ( | ) |
◆ operator bool() [2/2]
operator bool | ( | ) | const |
◆ 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] _msg A 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] _msgData A std::string that represents a serialized google::protobuf message. [in] _msgType A 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: