Skip to main content

DataReader

Struct DataReader 

Source
pub struct DataReader<T>
where T: DdsType,
{ /* private fields */ }
Expand description

Typed DataReader — removes samples that the RTPS reader has received for the topic.

Live mode: rx: Some delivers samples from the runtime mpsc. Offline mode: in-memory inbox for unit tests.

Implementations§

Source§

impl<T> DataReader<T>
where T: DdsType,

Source

pub fn with_filter<F>(self, filter: F) -> DataReader<T>
where F: Fn(&T) -> bool + Send + Sync + 'static,

Sets a content filter that is evaluated on every sample in the take() path. Returning false discards the sample.

Builder style: reader.with_filter(|s| s.value > 0).

.7a — SQL expression syntax via set_filter_expression follows later.

Source

pub fn topic(&self) -> &Topic<T>

The topic being read from.

Source

pub fn subscription_handle(&self) -> InstanceHandle

Spec §2.2.2.5.3.6 / §2.2.2.1.1 — InstanceHandle of this DataReader. A stable identity for DomainParticipant::contains_entity.

Source

pub fn set_listener( &self, listener: Option<Arc<dyn DataReaderListener>>, mask: u32, )

Sets the DataReaderListener + StatusMask. None clears the slot. Spec §2.2.2.5.7.x set_listener.

Source

pub fn get_listener(&self) -> Option<Arc<dyn DataReaderListener>>

Current listener clone, if any.

Source

pub fn qos(&self) -> DataReaderQos

Current QoS (cloned, .1).

Source

pub fn take(&self) -> Result<Vec<T>, DdsError>

Takes all cached samples and removes them from the inbox. Returns an empty Vec if there is nothing.

§Errors
  • WireError if a stored payload can no longer be decoded (type-eval mismatch).
Source

pub fn read(&self) -> Result<Vec<T>, DdsError>

Reads all samples without removing them. Currently identical to take minus the removal. Sample state (ReadCondition §2.2.2.5.8) follows during wire-up.

§Errors

Same as take.

Source

pub fn matched_publication_count(&self) -> usize

Number of matched remote writers. Always 0 in offline mode.

Spec: OMG DDS 1.4 §2.2.2.5.3.15 get_matched_publications.

Side effect — when the matched count changes versus the last call, on_subscription_matched is fired via the bubble-up chain (spec §2.2.4.2.6.7).

Source

pub fn wait_for_matched_publication( &self, min_count: usize, timeout: Duration, ) -> Result<(), DdsError>

Blocks until at least min_count remote writers are matched or timeout elapses. Event-driven via the runtime condvar (D.5e phase 1) — wakeup directly when SEDP propagates a match, no more 20-ms polling.

§Errors

DdsError::Timeout if min_count is not reached within the time window.

Source

pub fn requested_deadline_missed_count(&self) -> u64

Counter for requested-deadline violations (spec §2.2.4.2.11 REQUESTED_DEADLINE_MISSED_STATUS). Monotonically increasing; rises by 1 per expired deadline window without a received sample. Offline / INFINITE → 0.

May fire on_requested_deadline_missed.

Source

pub fn requested_incompatible_qos_status( &self, ) -> RequestedIncompatibleQosStatus

Current RequestedIncompatibleQosStatus. Spec §2.2.4.2.6.5. May trigger on_requested_incompatible_qos.

Source

pub fn sample_lost_count(&self) -> u64

SampleLost counter. Spec §2.2.4.2.6.2.

Source

pub fn sample_rejected_status(&self) -> SampleRejectedStatus

SampleRejected status. Spec §2.2.4.2.6.3.

Source

pub fn drive_listeners(&self)

Polls all reader statuses once and fires pending listeners. Convenience helper for tests + periodic tick callers.

Source

pub fn liveliness_changed_status(&self) -> (bool, u64, u64)

Liveliness status of the matched writer (spec §2.2.4.2.14 LIVELINESS_CHANGED_STATUS): (alive, alive_count, not_alive_count).

  • alive: current state (true = writer delivered a sample within its lease duration).
  • alive_count: counter of “not_alive → alive” transitions.
  • not_alive_count: counter of “alive → not_alive” transitions.

Offline / INFINITE lease → (false, 0, 0) / (true, 0, 0) depending on init. For v1.3 only LivelinessKind::Automatic is monitored.

Source

pub fn wait_for_data(&self, timeout: Duration) -> Result<(), DdsError>

Blocks until at least one sample is available or the timeout has elapsed. The sample is not removed in the process — it is placed in a staging buffer that the next take() reads. This keeps wait_for_data + take() the canonical subscriber loop instead of busy-polling in application code.

Spec analog: OMG DDS 1.4 §2.2.2.5.8 ReadCondition + WaitSet. This API provides the most important semantics (wake-on-data) without the full WaitSet/Condition infrastructure.

§Errors

DdsError::Timeout if nothing arrives within the time window.

Source

pub fn instance_tracker(&self) -> InstanceTracker

Returns the current InstanceTracker (shared with the internal bookkeeping). Mainly for tests / inspection.

Source

pub fn instance_handle(&self) -> InstanceHandle

This reader’s instance handle (GUID-derived). Lets the application ignore the reader’s own subscription — e.g. a durability service ignoring its ingest reader on the replay-writer side to avoid an echo loop. Mirrors crate::DataWriter::instance_handle.

Source

pub fn notify_writer_liveliness_lost(&self, writer_guid: [u8; 16]) -> usize

Spec §2.2.3.23 — hook for “writer X lost liveliness”. Does two things:

  1. clears the OWNERSHIP=EXCLUSIVE owner for all instances whose owner was this writer (so the next sample from another writer can win again via should_accept_sample_under_exclusive_ownership);
  2. returns the number of affected instances.

Called from the WLP path once a writer lease has expired (see wlp::WlpEndpoint::lost_peers).

Source

pub fn notify_participant_liveliness_lost(&self, prefix: [u8; 12]) -> usize

Like Self::notify_writer_liveliness_lost, but matches only on the first 12 bytes (GuidPrefix). Allows failover when only the participant identity is known (e.g. on SPDP lease expiry).

Source

pub fn lookup_instance(&self, instance: &T) -> InstanceHandle

Turns a sample value into its corresponding local InstanceHandle, or HANDLE_NIL if unknown / non-keyed. Spec §2.2.2.5.3.26 lookup_instance (reader variant).

Source

pub fn get_key_value(&self, handle: InstanceHandle) -> Result<T, DdsError>

Spec §2.2.2.5.3.25 get_key_value. Returns the sample value with only the @key fields filled in (reconstructed from the stored key holder via T::decode).

§Errors

BadParameter if handle is unknown; WireError if T::decode cannot reconstruct the key stream.

Source

pub fn take_with_info(&self) -> Result<Vec<Sample<T>>, DdsError>

take with full SampleInfo. Spec §2.2.2.5.3.5 take. Consumes the samples from the cache (the NOT_READ → READ transition is moot since they are gone).

§Errors

Same as Self::take.

Source

pub fn read_with_info(&self) -> Result<Vec<Sample<T>>, DdsError>

read with full SampleInfo. Does not consume — only marks the samples as READ (spec §2.2.2.5.3.4).

§Errors

Same as Self::read.

Source

pub fn take_filtered( &self, sample_mask: u32, view_mask: u32, instance_mask: u32, ) -> Result<Vec<Sample<T>>, DdsError>

take with state masks (spec §2.2.2.5.3.6 take_w_condition).

§Errors

Same as Self::take.

Source

pub fn read_filtered( &self, sample_mask: u32, view_mask: u32, instance_mask: u32, ) -> Result<Vec<Sample<T>>, DdsError>

read with state masks (spec §2.2.2.5.3.3 read_w_condition).

§Errors

Same as Self::read.

Source

pub fn read_w_condition( &self, condition: &Arc<QueryCondition>, ) -> Result<Vec<Sample<T>>, DdsError>

read_w_condition (spec §2.2.2.5.3.7) — in addition to the state mask, applies the QueryCondition’s SQL filter per sample. Samples stay in the cache (sample state NOT_READ → READ).

§Errors

PreconditionNotMet on lock poisoning or SQL eval error.

Source

pub fn take_w_condition( &self, condition: &Arc<QueryCondition>, ) -> Result<Vec<Sample<T>>, DdsError>

take_w_condition (spec §2.2.2.5.3.8) — like read_w_condition, but consumes the samples (removes them from the cache).

§Errors

PreconditionNotMet on lock poisoning or SQL eval error.

Source

pub fn read_instance( &self, handle: InstanceHandle, ) -> Result<Vec<Sample<T>>, DdsError>

read_instance (spec §2.2.2.5.3.27). Returns only samples of the given instance.

§Errors

BadParameter if handle == HANDLE_NIL.

Source

pub fn take_instance( &self, handle: InstanceHandle, ) -> Result<Vec<Sample<T>>, DdsError>

take_instance (spec §2.2.2.5.3.27, take variant). Consumes.

§Errors

BadParameter if handle == HANDLE_NIL.

Source

pub fn read_next_instance( &self, previous: InstanceHandle, ) -> Result<Vec<Sample<T>>, DdsError>

read_next_instance (spec §2.2.2.5.3.28). Returns the samples of the next instance (in sort order) after previous.

previous == HANDLE_NIL starts at the first handle.

§Errors

Same as read.

Source

pub fn take_next_instance( &self, previous: InstanceHandle, ) -> Result<Vec<Sample<T>>, DdsError>

take_next_instance (spec §2.2.2.5.3.28). Take variant.

§Errors

Same as take.

Trait Implementations§

Source§

impl<T> Debug for DataReader<T>
where T: DdsType,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for DataReader<T>
where T: DdsType,

Available on crate feature std only.

RAII teardown (Spec §2.2.2.5.1.2 — deleting a DataReader). Dropping the user’s handle deregisters the reader from the runtime: it removes the slot, rebuilds the intra-runtime route, and sends an SEDP dispose so remote peers drop the matched reader at once. Offline readers (no runtime) are no-ops.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> Entity for DataReader<T>
where T: DdsType,

Available on crate feature std only.
Source§

fn set_qos(&self, qos: <DataReader<T> as Entity>::Qos) -> Result<(), DdsError>

Spec §2.2.3 / §2.2.2.5.3: DURABILITY, RELIABILITY, HISTORY, RESOURCE_LIMITS, OWNERSHIP are Changeable=NO post-enable.

Source§

type Qos = DataReaderQos

QoS type for this entity (e.g. DomainParticipantQos, DataWriterQos, …).
Source§

fn get_qos(&self) -> <DataReader<T> as Entity>::Qos

Returns the current QoS (clone). Spec §2.2.2.1.2 get_qos.
Source§

fn enable(&self) -> Result<(), DdsError>

Enables the entity (idempotent). Spec §2.2.2.1.4 enable. Read more
Source§

fn entity_state(&self) -> Arc<EntityState>

Internal accessor — each impl returns its Arc<EntityState>.
Source§

fn is_enabled(&self) -> bool

True if the entity is already enabled.
Source§

fn get_status_condition(&self) -> StatusCondition

StatusCondition of this entity. Spec §2.2.2.1.6 get_status_condition.
Source§

fn get_status_changes(&self) -> u32

Bitmask of the status kinds changed since the last read. Spec §2.2.2.1.5 get_status_changes.
Source§

fn get_instance_handle(&self) -> InstanceHandle

Local 64-bit identifier. Spec §2.2.2.1.7 get_instance_handle.

Auto Trait Implementations§

§

impl<T> !Freeze for DataReader<T>

§

impl<T> !RefUnwindSafe for DataReader<T>

§

impl<T> !UnwindSafe for DataReader<T>

§

impl<T> Send for DataReader<T>
where T: Send,

§

impl<T> Sync for DataReader<T>
where T: Sync,

§

impl<T> Unpin for DataReader<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DataReader<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.