13.1.3.4. Publisher

class eprosima::fastdds::dds::Publisher : public eprosima::fastdds::dds::DomainEntity

Class Publisher, used to send data to associated subscribers.

Public Functions

~Publisher()

Destructor.

ReturnCode_t enable() override

This operation enables the Publisher.

Return

RETCODE_OK is successfully enabled. RETCODE_PRECONDITION_NOT_MET if the participant creating this Publisher is not enabled.

const PublisherQos &get_qos() const

Allows accessing the Publisher Qos.

Return

PublisherQos reference

ReturnCode_t get_qos(PublisherQos &qos) const

Retrieves the Publisher Qos.

Return

RETCODE_OK

ReturnCode_t set_qos(const PublisherQos &qos)

Allows modifying the Publisher Qos. The given Qos must be supported by the PublisherQos.

Return

RETCODE_IMMUTABLE_POLICY if any of the Qos cannot be changed, RETCODE_INCONSISTENT_POLICY if the Qos is not self consistent and RETCODE_OK if the qos is changed correctly.

Parameters

const PublisherListener *get_listener() const

Retrieves the attached PublisherListener.

Return

PublisherListener pointer

ReturnCode_t set_listener(PublisherListener *listener)

Modifies the PublisherListener, sets the mask to StatusMask::all()

Return

RETCODE_OK

Parameters

ReturnCode_t set_listener(PublisherListener *listener, const StatusMask &mask)

Modifies the PublisherListener.

Return

RETCODE_OK

Parameters

DataWriter *create_datawriter(Topic *topic, const DataWriterQos &qos, DataWriterListener *listener = nullptr, const StatusMask &mask = StatusMask::all())

This operation creates a DataWriter. The returned DataWriter will be attached and belongs to the Publisher.

Return

Pointer to the created DataWriter. nullptr if failed.

Parameters
  • topic: Topic the DataWriter will be listening

  • qos: QoS of the DataWriter.

  • listener: Pointer to the listener (default: nullptr).

  • mask: StatusMask that holds statuses the listener responds to (default: all).

DataWriter *create_datawriter_with_profile(Topic *topic, const std::string &profile_name, DataWriterListener *listener = nullptr, const StatusMask &mask = StatusMask::all())

This operation creates a DataWriter. The returned DataWriter will be attached and belongs to the Publisher.

Return

Pointer to the created DataWriter. nullptr if failed.

Parameters
  • topic: Topic the DataWriter will be listening

  • profile_name: DataWriter profile name.

  • listener: Pointer to the listener (default: nullptr).

  • mask: StatusMask that holds statuses the listener responds to (default: all).

ReturnCode_t delete_datawriter(DataWriter *writer)

This operation deletes a DataWriter that belongs to the Publisher.

The delete_datawriter operation must be called on the same Publisher object used to create the DataWriter. If delete_datawriter is called on a different Publisher, the operation will have no effect and it will return false.

The deletion of the DataWriter will automatically unregister all instances. Depending on the settings of the WRITER_DATA_LIFECYCLE QosPolicy, the deletion of the DataWriter may also dispose all instances.

Return

RETCODE_PRECONDITION_NOT_MET if it does not belong to this Publisher, RETCODE_OK if it is correctly deleted and RETCODE_ERROR otherwise.

Parameters

DataWriter *lookup_datawriter(const std::string &topic_name) const

This operation retrieves a previously created DataWriter belonging to the Publisher that is attached to a Topic with a matching topic_name. If no such DataWriter exists, the operation will return nullptr.

If multiple DataWriter attached to the Publisher satisfy this condition, then the operation will return one of them. It is not specified which one.

Return

Pointer to a previously created DataWriter associated to a Topic with the requested topic_name

Parameters
  • topic_name: Name of the Topic

bool get_datawriters(std::vector<DataWriter*> &writers) const

Fills the given vector with all the datawriters of this publisher.

Return

true

Parameters
  • writers: Vector where the DataWriters are returned

bool has_datawriters() const

This operation checks if the publisher has DataWriters

Return

true if the publisher has one or several DataWriters, false otherwise

ReturnCode_t wait_for_acknowledgments(const fastrtps::Duration_t &max_wait)

This operation blocks the calling thread until either all data written by the reliable DataWriter entities is acknowledged by all matched reliable DataReader entities, or else the duration specified by the max_wait parameter elapses, whichever happens first. A return value of true indicates that all the samples written have been acknowledged by all reliable matched data readers; a return value of false indicates that max_wait elapsed before all the data was acknowledged.

Return

RETCODE_TIMEOUT if the function takes more than the maximum blocking time established, RETCODE_OK if the Publisher receives the acknowledgments and RETCODE_ERROR otherwise.

Parameters
  • max_wait: Maximum blocking time for this operation

const DomainParticipant *get_participant() const

This operation returns the DomainParticipant to which the Publisher belongs.

Return

Pointer to the DomainParticipant

ReturnCode_t set_default_datawriter_qos(const DataWriterQos &qos)

This operation sets a default value of the DataWriter QoS policies which will be used for newly created DataWriter entities in the case where the QoS policies are defaulted in the create_datawriter operation.

This operation will check that the resulting policies are self consistent; if they are not, the operation will have no effect and return false.

The special value DATAWRITER_QOS_DEFAULT may be passed to this operation to indicate that the default QoS should be reset back to the initial values the factory would use, that is the values that would be used if the set_default_datawriter_qos operation had never been called.

Return

RETCODE_INCONSISTENT_POLICY if the Qos is not self consistent and RETCODE_OK if the qos is changed correctly.

Parameters

const DataWriterQos &get_default_datawriter_qos() const

This operation returns the default value of the DataWriter QoS, that is, the QoS policies which will be used for newly created DataWriter entities in the case where the QoS policies are defaulted in the create_datawriter operation.

The values retrieved by get_default_datawriter_qos will match the set of values specified on the last successful call to set_default_datawriter_qos, or else, if the call was never made, the default values.

Return

Current default WriterQos

ReturnCode_t get_default_datawriter_qos(DataWriterQos &qos) const

This operation retrieves the default value of the DataWriter QoS, that is, the QoS policies which will be used for newly created DataWriter entities in the case where the QoS policies are defaulted in the create_datawriter operation.

The values retrieved by get_default_datawriter_qos will match the set of values specified on the last successful call to set_default_datawriter_qos, or else, if the call was never made, the default values.

Return

RETCODE_OK

Parameters
  • qos: Reference to the current default WriterQos.

const fastrtps::rtps::InstanceHandle_t &get_instance_handle() const

Returns the Publisher’s handle.

Return

InstanceHandle of this Publisher.