Class CPublisher

Inheritance Relationships

Derived Type

Class Documentation

class eCAL::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

CPublisher()

Constructor.

CPublisher(const std::string &topic_name_, const std::string &topic_type_ = "", const std::string &topic_desc_ = "")

Constructor.

Parameters
  • topic_name_: Unique topic name.

  • topic_type_: Type name (optional).

  • topic_desc_: Type description (optional).

~CPublisher()

Destructor.

CPublisher(const CPublisher&) = delete

CPublishers are non-copyable.

CPublisher &operator=(const CPublisher&) = delete

CPublishers are non-copyable.

CPublisher(CPublisher &&rhs) noexcept

CPublishers are move-enabled.

CPublisher &operator=(CPublisher &&rhs) noexcept

CPublishers are move-enabled.

bool Create(const std::string &topic_name_, const std::string &topic_type_ = "", const std::string &topic_desc_ = "")

Creates this object.

Return

True if it succeeds, false if it fails.

Parameters
  • topic_name_: Unique topic name.

  • topic_type_: Type name (optional).

  • topic_desc_: Type description (optional).

bool Destroy()

Destroys this object.

Return

True if it succeeds, false if it fails.

bool SetDescription(const std::string &topic_desc_)

Setup topic description.

Return

True if it succeeds, false if it fails.

Parameters
  • topic_desc_: Description string.

bool ShareType(bool state_ = true)

Share topic type.

Return

True if it succeeds, false if it fails.

Parameters
  • state_: Set type share mode (true == share type).

bool ShareDescription(bool state_ = true)

Share topic description.

Return

True if it succeeds, false if it fails.

Parameters
  • state_: Set description share mode (true == share description).

bool SetQOS(const QOS::SWriterQOS &qos_)

Set publisher quality of service attributes.

Return

True if it succeeds, false if it fails.

Parameters
  • qos_: Quality of service policies.

QOS::SWriterQOS GetQOS()

Get current publisher quality of service attributes.

Return

Quality of service attributes.

bool SetLayerMode(TLayer::eTransportLayer layer_, TLayer::eSendMode mode_)

Set publisher send mode for specific transport layer.

Return

True if it succeeds, false if it fails.

Parameters
  • layer_: Transport layer.

  • mode_: Send mode.

bool SetMaxBandwidthUDP(long bandwidth_)

Set publisher maximum transmit bandwidth for the udp layer.

Return

True if it succeeds, false if it fails.

Parameters
  • bandwidth_: Maximum bandwidth in bytes/s (-1 == unlimited).

bool SetID(long long id_)

Set the the specific topic id.

Return

True if it succeeds, false if it fails.

Parameters
  • id_: The topic id for subscriber side filtering (0 == no id).

size_t Send(const void *const buf_, size_t len_, long long time_ = -1) const

Send a message to all subscribers.

Return

Number of bytes sent.

Parameters
  • buf_: Pointer to content buffer.

  • len_: Length of buffer.

  • time_: Send time (-1 = use eCAL system time in us, default = -1).

size_t Send(const std::string &s_, long long time_ = -1) const

Send a message to all subscribers.

Return

Number of bytes sent.

Parameters
  • s_: String that contains content to send.

  • time_: Send time (-1 = use eCAL system time in us, default = -1).

bool AddEventCallback(eCAL_Publisher_Event type_, PubEventCallbackT callback_)

Add callback function for publisher events.

Return

True if succeeded, false if not.

Parameters
  • type_: The event type to react on.

  • callback_: The callback function to add.

bool RemEventCallback(eCAL_Publisher_Event type_)

Remove callback function for publisher events.

Return

True if succeeded, false if not.

Parameters
  • type_: The event type to remove.

bool IsCreated() const

Query if the publisher is created.

Return

True if created, false if not.

bool IsSubscribed() const

Query if the publisher is subscribed.

Return

true if subscribed, false if not.

std::string GetTopicName() const

Gets name of the connected topic.

Return

The topic name.

std::string GetTypeName() const

Gets type of the connected topic.

Return

The type name.

std::string GetDescription() const

Gets description of the connected topic.

Return

The description.

std::string Dump(const std::string &indent_ = "") const

Dump the whole class state into a string.

Return

The dump string.

Parameters
  • indent_: Indentation used for dump.