14.1.4.1. DataReader

class eprosima::fastdds::dds::DataReader : public eprosima::fastdds::dds::DomainEntity

Class DataReader, contains the actual implementation of the behaviour of the Subscriber.

Read or take data methods.

Methods to read or take data from the History.

ReturnCode_t read_next_sample(void *data, SampleInfo *info)

This operation copies the next, non-previously accessed Data value from the DataReader; the operation also copies the corresponding SampleInfo. The implied order among the samples stored in the DataReader is the same as for the read operation.

The read_next_sample operation is semantically equivalent to the read operation where the input Data sequence has max_length=1, the sample_states=NOT_READ, the view_states=ANY_VIEW_STATE, and the instance_states=ANY_INSTANCE_STATE.

The read_next_sample operation provides a simplified API to ‘read’ samples avoiding the need for the application to manage sequences and specify states.

If there is no unread data in the DataReader, the operation will return NO_DATA and nothing is copied

Return

RETCODE_NO_DATA if the history is empty, RETCODE_OK if the next sample is returned and RETCODE_ERROR otherwise

Parameters
  • data: Data pointer to store the sample

  • info: SampleInfo pointer to store the sample information

ReturnCode_t take_next_sample(void *data, SampleInfo *info)

This operation copies the next, non-previously accessed Data value from the DataReader and ‘removes’ it from the DataReader so it is no longer accessible. The operation also copies the corresponding SampleInfo. This operation is analogous to the read_next_sample except for the fact that the sample is ‘removed’ from the DataReader.

The take_next_sample operation is semantically equivalent to the take operation where the input sequence has max_length=1, the sample_states=NOT_READ, the view_states=ANY_VIEW_STATE, and the instance_states=ANY_INSTANCE_STATE.

This operation provides a simplified API to ’take’ samples avoiding the need for the application to manage sequences and specify states.

If there is no unread data in the DataReader, the operation will return NO_DATA and nothing is copied.

Return

RETCODE_NO_DATA if the history is empty, RETCODE_OK if the next sample is returned and RETCODE_ERROR otherwise

Parameters
  • data: Data pointer to store the sample

  • info: SampleInfo pointer to store the sample information

Public Functions

~DataReader()

Destructor.

ReturnCode_t enable() override

This operation enables the DataReader.

Return

RETCODE_OK is successfully enabled. RETCODE_PRECONDITION_NOT_MET if the Subscriber creating this DataReader is not enabled.

bool wait_for_unread_message(const fastrtps::Duration_t &timeout)

Method to block the current thread until an unread message is available

Return

true if there is new unread message, false if timeout

Parameters
  • timeout: Max blocking time for this operation

ReturnCode_t get_first_untaken_info(SampleInfo *info)

Returns information about the first untaken sample.

Return

RETCODE_OK if sample info was returned. RETCODE_NO_DATA if there is no sample to take.

Parameters
  • [out] info: Pointer to a SampleInfo_t structure to store first untaken sample information.

const fastrtps::rtps::GUID_t &guid()

Get associated GUID

Return

Associated GUID

fastrtps::rtps::InstanceHandle_t get_instance_handle() const

Getter for the associated InstanceHandle.

Return

Copy of the InstanceHandle

TypeSupport type()

Getter for the data type

Return

TypeSupport associated to the DataReader

const TopicDescription *get_topicdescription() const

Get TopicDescription

Return

TopicDescription pointer

ReturnCode_t get_requested_deadline_missed_status(fastrtps::RequestedDeadlineMissedStatus &status)

Get the requested deadline missed status.

Return

The deadline missed status

ReturnCode_t get_requested_incompatible_qos_status(RequestedIncompatibleQosStatus &status)

Get the requested incompatible qos status.

Return

RETCODE_OK

Parameters
  • [out] status: Requested incompatible qos status

ReturnCode_t set_qos(const DataReaderQos &qos)

Setter for the DataReaderQos.

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 DataReaderQos &get_qos() const

Getter for the DataReaderQos.

Return

Pointer to the DataReaderQos

ReturnCode_t get_qos(DataReaderQos &qos) const

Getter for the DataReaderQos.

Return

RETCODE_OK

Parameters

ReturnCode_t set_listener(DataReaderListener *listener)

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

Return

RETCODE_OK

Parameters

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

Modifies the DataReaderListener.

Return

RETCODE_OK

Parameters

const DataReaderListener *get_listener() const

Getter for the DataReaderListener.

Return

Pointer to the DataReaderListener

ReturnCode_t get_liveliness_changed_status(LivelinessChangedStatus &status) const

Get the liveliness changed status.

Return

RETCODE_OK

Parameters

const Subscriber *get_subscriber() const

Getter for the Subscriber.

Return

Subscriber pointer