Skip to main content

rustorb_dds/
lib.rs

1//! A DDS 1.4 implementation in Rust: the DCPS API (domain participants,
2//! topics, publishers, subscribers, data writers and data readers) over
3//! DDSI-RTPS 2.5 ([`rustorb_rtps`]).
4//!
5//! Sample types implement [`TopicType`] from `rustorb-typesupport`, which
6//! the IDL compiler generates (`rustorb-idl -brust -Wbdds`); a
7//! hand-written implementation works the same way. Samples of types known
8//! only at run time are [`DynamicData`].
9//!
10//! ```no_run
11//! # fn f<Greeting: rustorb_dds::TopicType + 'static>(hello: Greeting) -> rustorb_dds::Result<()> {
12//! use std::time::Duration;
13//! use rustorb_dds::DomainParticipant;
14//!
15//! let participant = DomainParticipant::new(0)?;
16//! let topic = participant.create_topic::<Greeting>("hello")?;
17//! let writer = participant.create_publisher()?.create_datawriter(&topic)?;
18//! let reader = participant.create_subscriber()?.create_datareader(&topic)?;
19//! writer.write(&hello)?;
20//! if reader.wait_for_data(Duration::from_secs(1)) {
21//!     for sample in reader.take() {
22//!         // `None` when the sample only tells of a change in the state
23//!         // of its instance (disposed, no more writers).
24//!         let _greeting: Option<Greeting> = sample.data;
25//!     }
26//! }
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! What works now (rustorb/rustorb#111, stages D1 and part of D2):
32//! discovery with SPDP and SEDP, and RELIABLE or BEST_EFFORT, VOLATILE or
33//! TRANSIENT_LOCAL writers and readers (and TRANSIENT and PERSISTENT ones,
34//! whose samples outlive the writer), in partitions (with wildcards),
35//! over UDPv4. Endpoints whose QoS do not match are counted in the
36//! incompatible QoS statuses; readers reject samples beyond their
37//! RESOURCE_LIMITS. LIVELINESS (with the Writer Liveliness Protocol) and
38//! DEADLINE are kept and reported in statuses. A thread can wait for
39//! samples or status changes on a [`WaitSet`], with a [`StatusCondition`],
40//! a [`ReadCondition`] or a [`GuardCondition`], or have them handed to a
41//! [`DataReaderListener`] or [`DataWriterListener`]; a status that the
42//! endpoint's listener does not take goes to the [`PublisherListener`] or
43//! [`SubscriberListener`] (with `on_data_on_readers` first), then to the
44//! [`DomainParticipantListener`] (DDS 1.4, 2.2.4.3). A participant that is
45//! deleted tells the others. Keyed types
46//! have instances: writers register, write, dispose and unregister them;
47//! readers keep a history per instance with its states (DDS 1.4,
48//! 2.2.2.5.1). Samples larger than a datagram go as DATA_FRAG, and lost
49//! fragments are repaired. Samples are written in XCDR1. Writers and
50//! readers in the same participant are matched with each other too.
51//!
52//! Data flows with ROS 2 nodes too (the `ros2` example).
53//!
54//! A [`ContentFilteredTopic`] (DDS 1.4, 2.2.2.3.3) gives its readers only
55//! the samples of its related topic that pass a filter expression
56//! (DDS 1.4, Annex B, see [`ContentFilter`]); readers are created for a
57//! [`TopicDescription`], a topic or a content filtered topic.
58//!
59//! DDS-XTypes (D3, in progress): a type registered with
60//! [`DomainParticipant::register_type`] (its [`DescribeType`] is written
61//! by `rustorb-idl -Wbxtypes`) is announced with its TypeInformation, and
62//! its endpoints match others by type assignability
63//! ([`DataReaderQos::type_consistency`]) instead of by type name. Writers
64//! can write XCDR2 ([`DataWriterQos::data_representation`]). Topics count
65//! the endpoints whose types are not consistent with theirs
66//! ([`Topic::inconsistent_topic_status`]). When a remote endpoint's type
67//! differs from the local one, the participant gets its TypeObjects from
68//! the remote participant with the TypeLookup service (DDS-XTypes 1.3,
69//! 7.6.3.3) before it decides, and answers such requests for its own
70//! types ([`DomainParticipant::learnt_types`], the `evolve` example).
71//!
72//! A program can also handle topics whose types it was not built with
73//! (DDS-XTypes 1.3, 7.5.2): [`DomainParticipant::discover_topic_type`]
74//! gets the type of a remote endpoint of a topic as a [`DynamicType`],
75//! by TypeLookup, and [`DomainParticipant::create_dynamic_topic`] makes a
76//! topic of it (or of a type built at run time) whose writers and readers
77//! write and read [`DynamicData`] (the `dynamic` example).
78
79mod condition;
80mod error;
81mod instance;
82mod listener;
83mod loan;
84mod participant;
85mod persistent;
86mod publisher;
87mod qos;
88pub mod rpc;
89#[cfg(feature = "security")]
90mod security;
91#[cfg(feature = "security")]
92pub mod security_log;
93mod status;
94mod subscriber;
95#[cfg(test)]
96#[path = "../examples/keyed/shape.rs"]
97mod test_shape;
98mod topic;
99mod typed;
100
101pub use condition::{Condition, GuardCondition, ReadCondition, StatusCondition, WaitSet};
102pub use error::{Error, Result};
103pub use instance::{
104    InstanceHandle, InstanceState, InstanceStateMask, SampleInfo, SampleState, SampleStateMask,
105    StateFilter, ViewState, ViewStateMask,
106};
107pub use listener::{
108    AnyDataReader, AnyDataWriter, DataReaderListener, DataWriterListener,
109    DomainParticipantListener, PublisherListener, SubscriberListener, TopicListener,
110};
111pub use loan::{PlainType, ReadLoan, WriteLoan};
112pub use participant::{DomainParticipant, ParticipantConfig, VENDOR_ID};
113pub use publisher::{DataWriter, Publisher, WriteParams};
114pub use qos::{
115    DataReaderQos, DataWriterQos, DurabilityKind, DurabilityService, History, Liveliness,
116    LivelinessKind, PublisherQos, QosPolicyId, Reliability, ResourceLimits, SubscriberQos,
117    TypeConsistency, TypeConsistencyKind, WriterDataLifecycle, data_representation,
118};
119#[cfg(feature = "security")]
120pub use rustorb_dds_security::ocsp::OcspOptions;
121#[cfg(feature = "security")]
122pub use rustorb_dds_security::{access::ProtectionKind, psk::PskConfig};
123pub use rustorb_rtps::qos::ReliabilityKind;
124pub use rustorb_rtps::sedp::DATA_REPRESENTATION_QOS_POLICY_ID;
125pub use rustorb_rtps::{Guid, GuidPrefix, SampleIdentity, SequenceNumber, Time};
126pub use rustorb_typesupport::TopicType;
127pub use rustorb_xtypes::dynamic::ContentFilter;
128pub use rustorb_xtypes::dynamic::{
129    DynamicData, DynamicDataFactory, DynamicType, DynamicTypeBuilder, DynamicTypeBuilderFactory,
130    MEMBER_ID_INVALID,
131};
132pub use rustorb_xtypes::types::DescribeType;
133#[cfg(feature = "security")]
134pub use security::SecurityConfig;
135pub use status::{
136    DeadlineMissedStatus, IncompatibleQosStatus, InconsistentTopicStatus, LivelinessChangedStatus,
137    LivelinessLostStatus, MatchedStatus, QosPolicyCount, SampleLostStatus, SampleRejectedReason,
138    SampleRejectedStatus, StatusMask,
139};
140pub use subscriber::{DataReader, MaxSamples, Sample, Subscriber};
141pub use topic::{ContentFilteredTopic, Topic, TopicDescription};