pub struct DataWriter<T>where
T: DdsType,{ /* private fields */ }Expand description
Typed DataWriter — sends samples to all matched readers of the topic.
Two modes:
- Live (
runtime: Some,entity_id: Some): write() delegates to the runtime → ReliableWriter → UDP. - Offline (offline fallback, runtime=None): write() queues in-memory; for unit tests without a network.
Implementations§
Source§impl<T> DataWriter<T>where
T: DdsType,
impl<T> DataWriter<T>where
T: DdsType,
Sourcepub fn rtps_guid(&self) -> Option<[u8; 16]>
pub fn rtps_guid(&self) -> Option<[u8; 16]>
This writer’s 16-byte RTPS GUID, when it is bound to a live runtime
(online participant). None in offline mode. Used by the iceoryx-cyclone
bridge to stamp the cross-vendor PSMX chunk with the writer’s real GUID
so a peer that discovered it over RTPS associates the SHM sample with it.
Sourcepub fn set_listener(
&self,
listener: Option<Arc<dyn DataWriterListener>>,
mask: u32,
)
pub fn set_listener( &self, listener: Option<Arc<dyn DataWriterListener>>, mask: u32, )
Sets the DataWriterListener + StatusMask. None clears the slot.
Spec §2.2.2.4.2.x set_listener.
Sourcepub fn get_listener(&self) -> Option<Arc<dyn DataWriterListener>>
pub fn get_listener(&self) -> Option<Arc<dyn DataWriterListener>>
Current listener clone, if present.
Sourcepub fn qos(&self) -> DataWriterQos
pub fn qos(&self) -> DataWriterQos
Current QoS (cloned, .1).
Sourcepub fn write(&self, sample: &T) -> Result<(), DdsError>
pub fn write(&self, sample: &T) -> Result<(), DdsError>
Sends a sample to all matched readers.
Spec §2.2.3.19 RESOURCE_LIMITS reliable block: If the local
writer cache has reached max_samples AND Reliability=RELIABLE AND
max_blocking_time > 0, write() blocks until a reader ACK frees
the slot or the timeout expires. In best-effort mode or with
max_blocking_time = 0, write() fails immediately with
OutOfResources.
§Errors
WireErrorifT::encodefails.OutOfResourcesif the queue is full + best-effort/no blocking time, or if the block timeout expired before a drain.PreconditionNotMeton lock poisoning.
Sourcepub fn samples_pending(&self) -> usize
pub fn samples_pending(&self) -> usize
Number of samples written so far. Test helper, replaced by real HistoryCache counters in the runtime.
Sourcepub fn matched_subscription_count(&self) -> usize
pub fn matched_subscription_count(&self) -> usize
Number of matched remote readers. Always 0 in offline mode.
Spec: OMG DDS 1.4 §2.2.2.4.2.11 get_matched_subscriptions.
That returns a list; this returns only the count, the full list
comes with listener callbacks.
Side effect — on a change of the matched count relative to the
last call, on_publication_matched is fired via the bubble-up
chain (Spec §2.2.4.2.4.4).
Sourcepub fn wait_for_matched_subscription(
&self,
min_count: usize,
timeout: Duration,
) -> Result<(), DdsError>
pub fn wait_for_matched_subscription( &self, min_count: usize, timeout: Duration, ) -> Result<(), DdsError>
Blocks until at least min_count remote readers are matched or
timeout elapses. Event-driven via a runtime condvar (D.5e
phase 1) — wakes up directly when SEDP propagates a match, no more
20-ms polling.
Related to OMG DDS 1.4 §2.2.2.4.2.22 wait_for_acknowledgments,
but focused on matching rather than ACK. Covers the typical
producer pattern “first create the writer, then wait for
subscribers, then write”.
§Errors
DdsError::Timeout if min_count is not reached within the
time window.
Sourcepub fn offered_deadline_missed_count(&self) -> u64
pub fn offered_deadline_missed_count(&self) -> u64
Counter for offered-deadline violations (Spec §2.2.4.2.9
OFFERED_DEADLINE_MISSED_STATUS). Monotonically increasing;
increments by 1 per expired deadline window without a write.
Always 0 in offline mode or with deadline=INFINITE.
Fires on_offered_deadline_missed over the bubble-up chain on a
delta relative to the last call, if applicable.
Sourcepub fn liveliness_lost_count(&self) -> u64
pub fn liveliness_lost_count(&self) -> u64
Counter for LivelinessLost detections (Spec §2.2.4.2.10).
Triggers on_liveliness_lost via bubble-up, if applicable.
Sourcepub fn offered_incompatible_qos_status(&self) -> OfferedIncompatibleQosStatus
pub fn offered_incompatible_qos_status(&self) -> OfferedIncompatibleQosStatus
Current OfferedIncompatibleQosStatus (Spec §2.2.4.2.4.2).
Triggers on_offered_incompatible_qos, if applicable.
Sourcepub fn drive_listeners(&self)
pub fn drive_listeners(&self)
Polls all statuses once and fires pending listeners. Convenience helper for tests + periodic tick callers.
Sourcepub fn assert_liveliness(&self)
pub fn assert_liveliness(&self)
Manual liveliness assert. Spec §2.2.2.4.2.20 assert_liveliness.
Sets the last_liveliness_assert timestamp; a no-op with
automatic liveliness (every write asserts anyway).
Sourcepub fn wait_for_acknowledgments(
&self,
timeout: Duration,
) -> Result<(), DdsError>
pub fn wait_for_acknowledgments( &self, timeout: Duration, ) -> Result<(), DdsError>
Blocks until all matched remote readers have acknowledged all
samples written so far, or timeout elapses.
Spec: OMG DDS 1.4 §2.2.2.4.2.22 wait_for_acknowledgments.
Returns Ok(()) immediately in offline mode and without matched
readers.
§Errors
DdsError::Timeout if not all samples are acknowledged within
the time window.
Sourcepub fn publication_handle(&self) -> InstanceHandle
pub fn publication_handle(&self) -> InstanceHandle
Local publication handle of this DataWriter (Spec §2.2.2.5.1.11).
Passed along in the publication_handle field of SampleInfo.
Note: this is NOT the same handle as the entity
InstanceHandle (Spec §2.2.2.1.1) — see Self::instance_handle.
Sourcepub fn instance_handle(&self) -> InstanceHandle
pub fn instance_handle(&self) -> InstanceHandle
Spec §2.2.2.1.1 get_instance_handle — entity identifier of this
DataWriter for comparisons via
DomainParticipant::contains_entity.
Sourcepub fn instance_tracker(&self) -> InstanceTracker
pub fn instance_tracker(&self) -> InstanceTracker
Returns the writer’s shared instance tracker (test and inspection helper, Spec §2.2.2.4.2.5+ lifecycle bookkeeping).
Sourcepub fn register_instance(
&self,
instance: &T,
) -> Result<InstanceHandle, DdsError>
pub fn register_instance( &self, instance: &T, ) -> Result<InstanceHandle, DdsError>
Registers an instance with the DataWriter and returns its stable
InstanceHandle. Spec §2.2.2.4.2.5 register_instance.
For non-keyed topics the call returns HANDLE_NIL (each sample
is its own “instance”; the spec explicitly says register/
unregister/dispose are optional here).
§Errors
Currently the call cannot fail. Later (live mode) resource limits
may return an OutOfResources error here.
Sourcepub fn register_instance_w_timestamp(
&self,
instance: &T,
timestamp: Time,
) -> Result<InstanceHandle, DdsError>
pub fn register_instance_w_timestamp( &self, instance: &T, timestamp: Time, ) -> Result<InstanceHandle, DdsError>
Like register_instance, but with an explicit timestamp.
Spec §2.2.2.4.2.6.
Sourcepub fn lookup_instance(&self, instance: &T) -> InstanceHandle
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.4.2.14 lookup_instance.
Sourcepub fn unregister_instance(
&self,
instance: &T,
handle: InstanceHandle,
) -> Result<(), DdsError>
pub fn unregister_instance( &self, instance: &T, handle: InstanceHandle, ) -> Result<(), DdsError>
Removes the instance from the writer set (Spec §2.2.2.4.2.7).
Sets the lifecycle state to NOT_ALIVE_NO_WRITERS once the last
writer has unregistered.
§Errors
BadParameter if handle does not match the instance of
instance (the spec requires this consistency check). If
handle == HANDLE_NIL, the handle is derived from instance.
Sourcepub fn unregister_instance_w_timestamp(
&self,
instance: &T,
handle: InstanceHandle,
timestamp: Time,
) -> Result<(), DdsError>
pub fn unregister_instance_w_timestamp( &self, instance: &T, handle: InstanceHandle, timestamp: Time, ) -> Result<(), DdsError>
Like unregister_instance, but with a timestamp. Spec §2.2.2.4.2.8.
Spec §2.2.3.21 WriterDataLifecycle: if
autodispose_unregistered_instances=true (default), the instance
is also disposed in addition to being unregistered — readers then
see both NOT_ALIVE_DISPOSED and NOT_ALIVE_NO_WRITERS.
Sourcepub fn dispose(
&self,
instance: &T,
handle: InstanceHandle,
) -> Result<(), DdsError>
pub fn dispose( &self, instance: &T, handle: InstanceHandle, ) -> Result<(), DdsError>
Disposes an instance (Spec §2.2.2.4.2.10). Marks it as
NOT_ALIVE_DISPOSED; readers then see a sample with
valid_data == false.
§Errors
Like unregister_instance.
Sourcepub fn dispose_w_timestamp(
&self,
instance: &T,
handle: InstanceHandle,
timestamp: Time,
) -> Result<(), DdsError>
pub fn dispose_w_timestamp( &self, instance: &T, handle: InstanceHandle, timestamp: Time, ) -> Result<(), DdsError>
Like dispose, but with a timestamp. Spec §2.2.2.4.2.11.
Sourcepub fn get_key_value(&self, handle: InstanceHandle) -> Result<T, DdsError>
pub fn get_key_value(&self, handle: InstanceHandle) -> Result<T, DdsError>
Returns the sample value with only the @key fields populated
(Spec §2.2.2.4.2.13 get_key_value). Implementation: we
reconstruct T via decode from the stored PLAIN_CDR2-BE key
holder. For this to work, T::decode must accept a key-only
stream — for simple records this is trivially the case.
§Errors
BadParameterif the handle is unknown.WireErrorif the key holder cannot be reconstructed viaT::decode.
Sourcepub fn write_w_timestamp(
&self,
sample: &T,
timestamp: Time,
) -> Result<(), DdsError>
pub fn write_w_timestamp( &self, sample: &T, timestamp: Time, ) -> Result<(), DdsError>
Writes a sample with an explicit timestamp (Spec §2.2.2.4.2.16
write_w_timestamp) and updates the instance bookkeeping.
§Errors
Like Self::write.
Trait Implementations§
Source§impl<T> Debug for DataWriter<T>where
T: DdsType,
impl<T> Debug for DataWriter<T>where
T: DdsType,
Source§impl<T> Drop for DataWriter<T>where
T: DdsType,
Available on crate feature std only.RAII teardown (Spec §2.2.2.4.1.2 — deleting a DataWriter). Dropping the
user’s handle deregisters the writer from the runtime: it removes the slot
(stopping the RTPS heartbeats), rebuilds the intra-runtime route, and sends
an SEDP dispose so remote peers drop the matched writer at once instead of
waiting for a liveliness timeout. Offline writers (no runtime) are no-ops.
impl<T> Drop for DataWriter<T>where
T: DdsType,
std only.RAII teardown (Spec §2.2.2.4.1.2 — deleting a DataWriter). Dropping the
user’s handle deregisters the writer from the runtime: it removes the slot
(stopping the RTPS heartbeats), rebuilds the intra-runtime route, and sends
an SEDP dispose so remote peers drop the matched writer at once instead of
waiting for a liveliness timeout. Offline writers (no runtime) are no-ops.
Source§impl<T> Entity for DataWriter<T>where
T: DdsType,
Available on crate feature std only.
impl<T> Entity for DataWriter<T>where
T: DdsType,
std only.Source§fn set_qos(&self, qos: <DataWriter<T> as Entity>::Qos) -> Result<(), DdsError>
fn set_qos(&self, qos: <DataWriter<T> as Entity>::Qos) -> Result<(), DdsError>
Spec §2.2.3 / §2.2.2.4.2: DURABILITY, RELIABILITY, HISTORY, RESOURCE_LIMITS, OWNERSHIP, LIVELINESS are Changeable=NO post-enable.
Source§type Qos = DataWriterQos
type Qos = DataWriterQos
DomainParticipantQos,
DataWriterQos, …).Source§fn get_qos(&self) -> <DataWriter<T> as Entity>::Qos
fn get_qos(&self) -> <DataWriter<T> as Entity>::Qos
get_qos.Source§fn enable(&self) -> Result<(), DdsError>
fn enable(&self) -> Result<(), DdsError>
enable. Read moreSource§fn entity_state(&self) -> Arc<EntityState>
fn entity_state(&self) -> Arc<EntityState>
Arc<EntityState>.Source§fn is_enabled(&self) -> bool
fn is_enabled(&self) -> bool
Source§fn get_status_condition(&self) -> StatusCondition
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
fn get_status_changes(&self) -> u32
get_status_changes.Source§fn get_instance_handle(&self) -> InstanceHandle
fn get_instance_handle(&self) -> InstanceHandle
get_instance_handle.