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

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

Parameters
  • topic_name_ – Unique topic name.

  • topic_type_ – Type name (optional).

  • topic_desc_ – Type description (optional).

Returns

True if it succeeds, false if it fails.

bool Destroy()

Destroys this object.

Returns

True if it succeeds, false if it fails.

bool SetDescription(const std::string &topic_desc_)

Setup topic description.

Parameters

topic_desc_ – Description string.

Returns

True if it succeeds, false if it fails.

bool ShareType(bool state_ = true)

Share topic type.

Parameters

state_ – Set type share mode (true == share type).

Returns

True if it succeeds, false if it fails.

bool ShareDescription(bool state_ = true)

Share topic description.

Parameters

state_ – Set description share mode (true == share description).

Returns

True if it succeeds, false if it fails.

bool SetQOS(const QOS::SWriterQOS &qos_)

Set publisher quality of service attributes.

Parameters

qos_ – Quality of service policies.

Returns

True if it succeeds, false if it fails.

QOS::SWriterQOS GetQOS()

Get current publisher quality of service attributes.

Returns

Quality of service attributes.

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

Set publisher send mode for specific transport layer.

Parameters
  • layer_ – Transport layer.

  • mode_ – Send mode.

Returns

True if it succeeds, false if it fails.

bool SetMaxBandwidthUDP(long bandwidth_)

Set publisher maximum transmit bandwidth for the udp layer.

Parameters

bandwidth_ – Maximum bandwidth in bytes/s (-1 == unlimited).

Returns

True if it succeeds, false if it fails.

bool SetID(long long id_)

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

size_t Send(const void *const buf_, size_t len_, long long time_ = -1) 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.

size_t Send(const std::string &s_, long long time_ = -1) 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.

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.

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.

inline bool IsCreated() const

Query if the publisher is created.

Returns

True if created, false if not.

bool IsSubscribed() const

Query if the publisher is subscribed.

Returns

true if subscribed, false if not.

std::string GetTopicName() const

Gets name of the connected topic.

Returns

The topic name.

std::string GetTypeName() const

Gets type of the connected topic.

Returns

The type name.

std::string GetDescription() const

Gets description of the connected topic.

Returns

The description.

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.