Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/dds/no_key/datareader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
qos::{HasQoSPolicy, QosPolicies},
readcondition::ReadCondition,
result::ReadResult,
statusevents::DataReaderStatus,
statusevents::{DataReaderStatus, SubscriptionMatchedStatus},
with_key::{
datareader as datareader_with_key,
datasample::{DataSample as WithKeyDataSample, Sample},
Expand Down Expand Up @@ -422,6 +422,43 @@ where
}
*/

/// Reads the SUBSCRIPTION_MATCHED status of this DataReader: how many
/// DataWriters it is matched with now, and how many matches there have been
/// since it was created.
///
/// The counts are those of the RTPS Reader itself. They do not come from the
/// status event stream, so they are right also when nothing reads that
/// stream and it has dropped events. Each `count_change()` is the change
/// since the previous call on this DataReader.
///
/// See DDS Spec 1.4 Section 2.2.4.1 Communication Status.
///
/// # Examples
///
/// ```
/// # use serde::{Serialize, Deserialize};
/// # use rustdds::*;
/// # use rustdds::no_key::DataReader;
/// # use rustdds::serialization::CDRDeserializerAdapter;
/// #
/// let domain_participant = DomainParticipant::new(0).unwrap();
/// let qos = QosPolicyBuilder::new().build();
/// let subscriber = domain_participant.create_subscriber(&qos).unwrap();
///
/// #[derive(Serialize, Deserialize)]
/// struct SomeType {}
///
/// // NoKey is important
/// let topic = domain_participant.create_topic("some_topic".to_string(), "SomeType".to_string(), &qos, TopicKind::NoKey).unwrap();
/// let data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
///
/// let matched = data_reader.get_subscription_matched_status();
/// println!("{} writers now, {} ever", matched.current.count(), matched.total.count());
/// ```
pub fn get_subscription_matched_status(&self) -> SubscriptionMatchedStatus {
self.keyed_datareader.get_subscription_matched_status()
}

/// An async stream for reading the (bare) data samples
pub fn async_bare_sample_stream(self) -> BareDataReaderStream<D, DA> {
BareDataReaderStream {
Expand Down
39 changes: 27 additions & 12 deletions src/dds/no_key/datawriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
pubsub::Publisher,
qos::{HasQoSPolicy, QosPolicies},
result::{unwrap_no_key_write_error, WriteResult},
statusevents::{DataWriterStatus, StatusReceiverStream},
statusevents::{DataWriterStatus, PublicationMatchedStatus, StatusReceiverStream},
topic::Topic,
with_key::datawriter as datawriter_with_key,
},
Expand Down Expand Up @@ -221,12 +221,27 @@ where
self.keyed_datawriter.get_offered_incompatible_qos_status()
}

/// Unimplemented. <b>Do not use</b>.
*/

/// Reads the PUBLICATION_MATCHED status of this DataWriter: how many
/// DataReaders it is matched with now, and how many matches there have been
/// since it was created.
///
/// The counts are those of the RTPS Writer itself. They do not come from the
/// status event stream, so they are right also when nothing reads that
/// stream and it has dropped events. Each `count_change()` is the change
/// since the previous call on this DataWriter.
///
/// The call is cheap enough to make before every write, for example to skip
/// producing a sample that nobody would receive. Skipping is right only for
/// a DataWriter with volatile durability, which keeps nothing for readers
/// that match later, and automatic liveliness, which no write has to assert.
///
/// See DDS Spec 1.4 Section 2.2.4.1 Communication Status.
///
/// # Examples
///
// TODO: enable run when implemented
/// ```no_run
/// ```
/// # use serde::{Serialize, Deserialize};
/// # use rustdds::*;
/// # use rustdds::no_key::DataWriter;
Expand All @@ -236,21 +251,21 @@ where
/// let qos = QosPolicyBuilder::new().build();
/// let publisher = domain_participant.create_publisher(&qos).unwrap();
///
/// # #[derive(Serialize, Deserialize)]
/// # struct SomeType {}
/// #
/// #[derive(Serialize, Deserialize, Debug)]
/// struct SomeType { a: i32 }
///
/// // NoKey is important
/// let topic = domain_participant.create_topic("some_topic".to_string(), "SomeType".to_string(), &qos, TopicKind::NoKey).unwrap();
/// let data_writer = publisher.create_datawriter_no_key::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
/// let data_writer = publisher.create_datawriter_no_key::<SomeType, CDRSerializerAdapter<_>>(&topic, None).unwrap();
///
/// if let Ok(status) = data_writer.get_publication_matched_status() {
/// // Do something
/// if data_writer.get_publication_matched_status().current.count() > 0 {
/// data_writer.write(SomeType { a: 1 }, None).unwrap();
/// }
/// ```
pub fn get_publication_matched_status(&self) -> Result<PublicationMatchedStatus> {
pub fn get_publication_matched_status(&self) -> PublicationMatchedStatus {
self.keyed_datawriter.get_publication_matched_status()
}
*/

/// Topic this DataWriter is connected to.
///
/// # Examples
Expand Down
16 changes: 16 additions & 0 deletions src/dds/no_key/simpledatareader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ where
self.keyed_simpledatareader.guid()
}

/// Reads the SUBSCRIPTION_MATCHED status of this DataReader: how many
/// DataWriters it is matched with now, and how many matches there have been
/// since it was created.
///
/// The counts are those of the RTPS Reader itself. They do not come from the
/// status event stream, so they are right also when nothing reads that
/// stream and it has dropped events. Each `count_change()` is the change
/// since the previous call on this DataReader.
///
/// See DDS Spec 1.4 Section 2.2.4.1 Communication Status.
pub fn get_subscription_matched_status(&self) -> SubscriptionMatchedStatus {
self
.keyed_simpledatareader
.get_subscription_matched_status()
}

pub fn as_async_stream(
&self,
) -> impl FusedStream<Item = ReadResult<DeserializedCacheChange<D>>> + '_
Expand Down
10 changes: 9 additions & 1 deletion src/dds/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
participant::*,
qos::*,
result::{CreateError, CreateResult, WaitResult},
statusevents::{sync_status_channel, DataReaderStatus},
statusevents::{sync_status_channel, DataReaderStatus, MatchedCounts},
topic::*,
with_key,
with_key::{
Expand Down Expand Up @@ -481,6 +481,8 @@ impl InnerPublisher {
{
// Status reports back from Writer to DataWriter.
let (status_sender, status_receiver) = sync_status_channel(4)?;
// The Writer's matched-reader counts, for `get_publication_matched_status`.
let matched_counts = Arc::new(MatchedCounts::default());

// DDS Spec 2.2.2.4.1.5 create_datawriter:
// If no QoS is specified, we should take the Publisher default
Expand Down Expand Up @@ -618,6 +620,7 @@ impl InnerPublisher {
doorbell.clone(),
self.discovery_command.clone(),
status_receiver,
Arc::clone(&matched_counts),
)?;

// Construct security info if needed
Expand Down Expand Up @@ -700,6 +703,7 @@ impl InnerPublisher {
like_stateless: writer_like_stateless,
qos_policies: writer_qos,
status_sender,
matched_counts,
security_plugins: self.security_plugins_handle.clone(),
};

Expand Down Expand Up @@ -1129,6 +1133,8 @@ impl InnerSubscriber {
let (send, rec) = crate::mio_source::notification_channel(4);
// status change channel from Reader to DataReader
let (status_sender, status_receiver) = sync_status_channel::<DataReaderStatus>(4)?;
// The Reader's matched-writer counts, for `get_subscription_matched_status`.
let matched_counts = Arc::new(MatchedCounts::default());

// reader command channel from Datareader to Reader.
// Capacity 0 is a rendezvous, matching the previous mio-extras channel: the
Expand Down Expand Up @@ -1232,6 +1238,7 @@ impl InnerSubscriber {
guid: reader_guid,
notification_sender: send,
status_sender,
matched_counts: Arc::clone(&matched_counts),
topic_name: topic.name(),
topic_cache_handle: topic_cache_handle.clone(),
like_stateless: reader_like_stateless,
Expand Down Expand Up @@ -1314,6 +1321,7 @@ impl InnerSubscriber {
topic_cache_handle,
self.discovery_command.clone(),
status_receiver,
matched_counts,
reader_command_sender,
data_reader_waker,
poll_event_source,
Expand Down
Loading
Loading