Class CPublisher#
Defined in File ecal_publisher.h
Inheritance Relationships#
Derived Type#
public eCAL::CMsgPublisher< T >
(Template Class CMsgPublisher)
Class Documentation#
-
class CPublisher#
eCAL publisher class.
The CPublisher
class is used to send topics to matching eCAL subscribers. The topic is created automatically by the constructor or by the Create member function.
For sending the topic payload the publisher class provides an overloaded Send method. The first one is sending the payload as a std::string. The second needs a preallocated buffer described by a buffer address and a buffer length. The publisher is not taking the ownership for the allocated memory buffer.
An optional time stamp can be attached to the topic payload.// create publisher, topic name "A" eCAL::CPublisher pub("A"); // send string std::string send_s = "Hello World "; // send content size_t snd_len = pub.Send(send_s);
Subclassed by eCAL::CMsgPublisher< T >
Public Functions
-
ECAL_API CPublisher()#
Constructor.
-
ECAL_API CPublisher(const std::string &topic_name_, const SDataTypeInformation &topic_info_)#
Constructor.
- Parameters:
topic_name_ – Unique topic name.
topic_info_ – Topic information (encoding, type, descriptor)
-
ECAL_API explicit CPublisher(const std::string &topic_name_)#
Constructor.
- Parameters:
topic_name_ – Unique topic name.
-
ECAL_API virtual ~CPublisher()#
Destructor.
-
CPublisher(const CPublisher&) = delete#
CPublishers are non-copyable.
-
CPublisher &operator=(const CPublisher&) = delete#
CPublishers are non-copyable.
-
ECAL_API CPublisher(CPublisher &&rhs) noexcept#
CPublishers are move-enabled.
-
ECAL_API CPublisher &operator=(CPublisher &&rhs) noexcept#
CPublishers are move-enabled.
-
ECAL_API bool Create(const std::string &topic_name_, const SDataTypeInformation &topic_info_)#
Creates this object.
- Parameters:
topic_name_ – Unique topic name.
topic_info_ – Topic information (encoding, type, descriptor)
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API bool Create(const std::string &topic_name_)#
Creates this object.
- Parameters:
topic_name_ – Unique topic name.
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API bool Destroy()#
Destroys this object.
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API bool SetDataTypeInformation(const SDataTypeInformation &topic_info_)#
Setup topic information.
- Parameters:
topic_info_ – Topic information attributes.
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API bool SetAttribute(const std::string &attr_name_, const std::string &attr_value_)#
Sets publisher attribute.
- Parameters:
attr_name_ – Attribute name.
attr_value_ – Attribute value.
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API bool ClearAttribute(const std::string &attr_name_)#
Removes publisher attribute.
- Parameters:
attr_name_ – Attribute name.
- Returns:
True if it succeeds, false if it fails.
Share topic type.
- Parameters:
state_ – Set type share mode (true == share type).
- Returns:
True if it succeeds, false if it fails.
Share topic description.
- Parameters:
state_ – Set description share mode (true == share description).
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API bool SetID(long long id_)#
Set the specific topic id.
- Parameters:
id_ – The topic id for subscriber side filtering (0 == no id).
- Returns:
True if it succeeds, false if it fails.
-
ECAL_API size_t Send(const void *buf_, size_t len_, long long time_ = DEFAULT_TIME_ARGUMENT) const#
Send a message to all subscribers.
- Parameters:
buf_ – Pointer to content buffer.
len_ – Length of buffer.
time_ – Send time (-1 = use eCAL system time in us, default = -1).
- Returns:
Number of bytes sent.
-
ECAL_API size_t Send(CPayloadWriter &payload_, long long time_ = DEFAULT_TIME_ARGUMENT) const#
Send a message to all subscribers.
- Parameters:
payload_ – Payload.
time_ – Send time (-1 = use eCAL system time in us, default = -1).
- Returns:
Number of bytes sent.
-
ECAL_API size_t Send(const std::string &s_, long long time_ = DEFAULT_TIME_ARGUMENT) const#
Send a message to all subscribers.
- Parameters:
s_ – String that contains content to send.
time_ – Send time (-1 = use eCAL system time in us, default = -1).
- Returns:
Number of bytes sent.
-
ECAL_API bool AddEventCallback(eCAL_Publisher_Event type_, PubEventCallbackT callback_)#
Add callback function for publisher events.
- Parameters:
type_ – The event type to react on.
callback_ – The callback function to add.
- Returns:
True if succeeded, false if not.
-
ECAL_API bool RemEventCallback(eCAL_Publisher_Event type_)#
Remove callback function for publisher events.
- Parameters:
type_ – The event type to remove.
- Returns:
True if succeeded, false if not.
-
ECAL_API inline bool IsCreated() const#
Query if the publisher is created.
- Returns:
True if created, false if not.
-
ECAL_API bool IsSubscribed() const#
Query if the publisher is subscribed.
- Returns:
true if subscribed, false if not.
-
ECAL_API size_t GetSubscriberCount() const#
Query the number of subscribers.
- Returns:
Number of subscribers.
-
ECAL_API std::string GetTopicName() const#
Gets name of the connected topic.
- Returns:
The topic name.
-
ECAL_API SDataTypeInformation GetDataTypeInformation() const#
Gets description of the connected topic.
- Returns:
The topic information.
-
ECAL_API std::string Dump(const std::string &indent_ = "") const#
Dump the whole class state into a string.
- Parameters:
indent_ – Indentation used for dump.
- Returns:
The dump string.
-
ECAL_API CPublisher()#