Class CPublisher

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

Public Functions

ECAL_API_EXPORTED_MEMBER CPublisher(const std::string &topic_name_, const SDataTypeInformation &data_type_info_ = SDataTypeInformation(), const Publisher::Configuration &config_ = GetPublisherConfiguration())

Constructor.

Parameters:
  • topic_name_ – Unique topic name.

  • data_type_info_ – Topic data type information (encoding, type, descriptor).

  • config_ – Optional configuration parameters.

ECAL_API_EXPORTED_MEMBER CPublisher(const std::string &topic_name_, const SDataTypeInformation &data_type_info_, const PubEventCallbackT &event_callback_, const Publisher::Configuration &config_ = GetPublisherConfiguration())

Constructor.

Parameters:
  • topic_name_ – Unique topic name.

  • data_type_info_ – Topic data type information (encoding, type, descriptor).

  • event_callback_ – The publisher event callback funtion.

  • config_ – Optional configuration parameters.

virtual ECAL_API_EXPORTED_MEMBER ~CPublisher()

Destructor.

CPublisher(const CPublisher&) = delete

CPublishers are non-copyable.

CPublisher &operator=(const CPublisher&) = delete

CPublishers are non-copyable.

ECAL_API_EXPORTED_MEMBER CPublisher(CPublisher &&rhs) noexcept

CPublishers are move-enabled.

ECAL_API_EXPORTED_MEMBER CPublisher & operator= (CPublisher &&rhs) noexcept

CPublishers are move-enabled.

ECAL_API_EXPORTED_MEMBER bool Send (const void *buf_, size_t len_, long long time_=DEFAULT_TIME_ARGUMENT)

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:

True if succeeded, false if not.

ECAL_API_EXPORTED_MEMBER bool Send (CPayloadWriter &payload_, long long time_=DEFAULT_TIME_ARGUMENT)

Send a message to all subscribers.

Parameters:
  • payload_ – Payload writer.

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

Returns:

True if succeeded, false if not.

ECAL_API_EXPORTED_MEMBER bool Send (const std::string &payload_, long long time_=DEFAULT_TIME_ARGUMENT)

Send a message to all subscribers.

Parameters:
  • payload_ – Payload string.

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

Returns:

True if succeeded, false if not.

ECAL_API_EXPORTED_MEMBER size_t GetSubscriberCount () const

Query the number of subscribers.

Returns:

Number of subscribers.

ECAL_API_EXPORTED_MEMBER const std::string & GetTopicName () const

Retrieve the topic name.

Returns:

The topic name.

ECAL_API_EXPORTED_MEMBER const STopicId & GetTopicId () const

Retrieve the topic id.

Returns:

The topic id.

ECAL_API_EXPORTED_MEMBER const SDataTypeInformation & GetDataTypeInformation () const

Gets description of the connected topic.

Returns:

The topic information.

ECAL_API_EXPORTED_MEMBER CPublisher()

Constructor.

ECAL_API_EXPORTED_MEMBER CPublisher(const std::string &topic_name_, const SDataTypeInformation &data_type_info_, const Publisher::Configuration &config_ = GetPublisherConfiguration())

Constructor.

Parameters:
  • topic_name_ – Unique topic name.

  • data_type_info_ – Topic data type information (encoding, type, descriptor).

  • config_ – Optional configuration parameters.

explicit ECAL_API_EXPORTED_MEMBER CPublisher(const std::string &topic_name_, const Publisher::Configuration &config_ = GetPublisherConfiguration())

Constructor.

Parameters:
  • topic_name_ – Unique topic name.

  • config_ – Optional configuration parameters.

virtual ECAL_API_EXPORTED_MEMBER ~CPublisher()

Destructor.

CPublisher(const CPublisher&) = delete

CPublishers are non-copyable.

CPublisher &operator=(const CPublisher&) = delete

CPublishers are non-copyable.

ECAL_API_EXPORTED_MEMBER CPublisher(CPublisher &&rhs) noexcept

CPublishers are move-enabled.

ECAL_API_EXPORTED_MEMBER CPublisher & operator= (CPublisher &&rhs) noexcept

CPublishers are move-enabled.

ECAL_API_EXPORTED_MEMBER bool Create (const std::string &topic_name_, const SDataTypeInformation &data_type_info_, const Publisher::Configuration &config_=GetPublisherConfiguration())

Creates this object.

Parameters:
  • topic_name_ – Unique topic name.

  • data_type_info_ – Topic data type information (encoding, type, descriptor).

  • config_ – Optional configuration parameters.

Returns:

True if it succeeds, false if it fails.

ECAL_API_EXPORTED_MEMBER 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_EXPORTED_MEMBER bool Destroy ()

Destroys this object.

Returns:

True if it succeeds, false if it fails.

ECAL_API_EXPORTED_MEMBER bool SetDataTypeInformation (const SDataTypeInformation &data_type_info_)

Setup topic information.

Parameters:

data_type_info_ – Topic data type information attributes.

Returns:

True if it succeeds, false if it fails.

ECAL_API_EXPORTED_MEMBER 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_EXPORTED_MEMBER bool ClearAttribute (const std::string &attr_name_)

Removes publisher attribute.

Parameters:

attr_name_ – Attribute name.

Returns:

True if it succeeds, false if it fails. @experimental

ECAL_API_EXPORTED_MEMBER bool SetID (long long filter_id_)

Set the specific topic filter id.

Parameters:

filter_id_ – The topic id for subscriber side filtering (0 == no id).

Returns:

True if it succeeds, false if it fails.

ECAL_API_EXPORTED_MEMBER size_t Send (const void *buf_, size_t len_, long long time_=DEFAULT_TIME_ARGUMENT)

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_EXPORTED_MEMBER size_t Send (CPayloadWriter &payload_, long long time_=DEFAULT_TIME_ARGUMENT)

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

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_EXPORTED_MEMBER bool AddEventCallback (ePublisherEvent 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_EXPORTED_MEMBER bool RemEventCallback (ePublisherEvent type_)

Remove callback function for publisher events.

Parameters:

type_ – The event type to remove.

Returns:

True if succeeded, false if not.

inline ECAL_API_EXPORTED_MEMBER bool IsCreated () const

Query if the publisher is created.

Returns:

True if created, false if not.

ECAL_API_EXPORTED_MEMBER bool IsSubscribed () const

Query if the publisher is subscribed.

Returns:

true if subscribed, false if not.

ECAL_API_EXPORTED_MEMBER size_t GetSubscriberCount () const

Query the number of subscribers.

Returns:

Number of subscribers.

ECAL_API_EXPORTED_MEMBER std::string GetTopicName () const

Gets name of the connected topic.

Returns:

The topic name.

ECAL_API_EXPORTED_MEMBER STopicId GetId () const

Gets a unique ID of this Publisher.

Returns:

The topic id.

ECAL_API_EXPORTED_MEMBER SDataTypeInformation GetDataTypeInformation () const

Gets description of the connected topic.

Returns:

The topic information.

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

Public Static Attributes

static ECAL_API_EXPORTED_MEMBER constexpr long long DEFAULT_TIME_ARGUMENT   = -1

Use DEFAULT_TIME_ARGUMENT in the Send() function to let eCAL determine the send timestamp