use super::time::{DURATION_ZERO_NSEC, DURATION_ZERO_SEC};
use crate::{
infrastructure::{
time::{Duration, DurationKind},
type_support::TypeSupport,
},
transport::types::{DurabilityKind, ReliabilityKind},
xtypes::{
binding::XTypesBinding,
dynamic_type::{DynamicDataFactory, TypeKind},
},
};
use alloc::{string::String, vec::Vec};
use core::cmp::Ordering;
pub type QosPolicyId = i32;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Length {
Unlimited,
Limited(i32),
}
impl TypeSupport for Length {
#[inline]
fn get_type_name() -> &'static str {
"Length"
}
#[inline]
fn get_type() -> crate::xtypes::dynamic_type::DynamicType {
i32::get_dynamic_type()
}
fn create_dynamic_sample(self) -> crate::xtypes::dynamic_type::DynamicData {
let value = match self {
Length::Limited(length) => length,
Length::Unlimited => LENGTH_UNLIMITED,
};
let mut data = DynamicDataFactory::create_data(Self::get_type());
data.set_int32_value(0, value).unwrap();
data
}
fn create_sample(src: crate::xtypes::dynamic_type::DynamicData) -> Self {
let value = src.get_int32_value(0).cloned().unwrap();
match value {
LENGTH_UNLIMITED => Length::Unlimited,
v => Length::Limited(v),
}
}
}
const LENGTH_UNLIMITED: i32 = i32::MAX;
impl PartialOrd for Length {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match self {
Length::Unlimited => match other {
Length::Unlimited => Some(Ordering::Equal),
Length::Limited(_) => Some(Ordering::Greater),
},
Length::Limited(value) => match other {
Length::Unlimited => Some(Ordering::Less),
Length::Limited(other) => value.partial_cmp(other),
},
}
}
}
impl PartialEq<usize> for Length {
fn eq(&self, other: &usize) -> bool {
match self {
Length::Unlimited => false,
Length::Limited(value) => (*value as usize).eq(other),
}
}
}
impl PartialOrd<usize> for Length {
fn partial_cmp(&self, other: &usize) -> Option<Ordering> {
match self {
Length::Unlimited => Some(Ordering::Greater),
Length::Limited(value) => (*value as usize).partial_cmp(other),
}
}
}
impl PartialEq<Length> for usize {
fn eq(&self, other: &Length) -> bool {
match other {
Length::Unlimited => false,
Length::Limited(value) => self.eq(&(*value as usize)),
}
}
}
impl PartialOrd<Length> for usize {
fn partial_cmp(&self, other: &Length) -> Option<Ordering> {
match other {
Length::Unlimited => Some(Ordering::Less),
Length::Limited(value) => self.partial_cmp(&(*value as usize)),
}
}
}
pub trait QosPolicy {
fn name(&self) -> &str;
}
const USERDATA_QOS_POLICY_NAME: &str = "UserData";
const DURABILITY_QOS_POLICY_NAME: &str = "Durability";
const PRESENTATION_QOS_POLICY_NAME: &str = "Presentation";
const DEADLINE_QOS_POLICY_NAME: &str = "Deadline";
const LATENCYBUDGET_QOS_POLICY_NAME: &str = "LatencyBudget";
const OWNERSHIP_QOS_POLICY_NAME: &str = "Ownership";
const OWNERSHIP_STRENGTH_QOS_POLICY_NAME: &str = "OwnershipStrength";
const LIVELINESS_QOS_POLICY_NAME: &str = "Liveliness";
const TIMEBASEDFILTER_QOS_POLICY_NAME: &str = "TimeBasedFilter";
const PARTITION_QOS_POLICY_NAME: &str = "Partition";
const RELIABILITY_QOS_POLICY_NAME: &str = "Reliability";
const DESTINATIONORDER_QOS_POLICY_NAME: &str = "DestinationOrder";
const HISTORY_QOS_POLICY_NAME: &str = "History";
const RESOURCELIMITS_QOS_POLICY_NAME: &str = "ResourceLimits";
const ENTITYFACTORY_QOS_POLICY_NAME: &str = "EntityFactory";
const WRITERDATALIFECYCLE_QOS_POLICY_NAME: &str = "WriterDataLifecycle";
const READERDATALIFECYCLE_QOS_POLICY_NAME: &str = "ReaderDataLifecycle";
const TOPICDATA_QOS_POLICY_NAME: &str = "TopicData";
const TRANSPORTPRIORITY_QOS_POLICY_NAME: &str = "TransportPriority";
const GROUPDATA_QOS_POLICY_NAME: &str = "GroupData";
const LIFESPAN_QOS_POLICY_NAME: &str = "Lifespan";
const DATA_REPRESENTATION_QOS_POLICY_NAME: &str = "DataRepresentation";
pub const INVALID_QOS_POLICY_ID: QosPolicyId = 0;
pub const USERDATA_QOS_POLICY_ID: QosPolicyId = 1;
pub const DURABILITY_QOS_POLICY_ID: QosPolicyId = 2;
pub const PRESENTATION_QOS_POLICY_ID: QosPolicyId = 3;
pub const DEADLINE_QOS_POLICY_ID: QosPolicyId = 4;
pub const LATENCYBUDGET_QOS_POLICY_ID: QosPolicyId = 5;
pub const OWNERSHIP_QOS_POLICY_ID: QosPolicyId = 6;
pub const OWNERSHIP_STRENGTH_QOS_POLICY_ID: QosPolicyId = 7;
pub const LIVELINESS_QOS_POLICY_ID: QosPolicyId = 8;
pub const TIMEBASEDFILTER_QOS_POLICY_ID: QosPolicyId = 9;
pub const PARTITION_QOS_POLICY_ID: QosPolicyId = 10;
pub const RELIABILITY_QOS_POLICY_ID: QosPolicyId = 11;
pub const DESTINATIONORDER_QOS_POLICY_ID: QosPolicyId = 12;
pub const HISTORY_QOS_POLICY_ID: QosPolicyId = 13;
pub const RESOURCELIMITS_QOS_POLICY_ID: QosPolicyId = 14;
pub const ENTITYFACTORY_QOS_POLICY_ID: QosPolicyId = 15;
pub const WRITERDATALIFECYCLE_QOS_POLICY_ID: QosPolicyId = 16;
pub const READERDATALIFECYCLE_QOS_POLICY_ID: QosPolicyId = 17;
pub const TOPICDATA_QOS_POLICY_ID: QosPolicyId = 18;
pub const GROUPDATA_QOS_POLICY_ID: QosPolicyId = 19;
pub const TRANSPORTPRIORITY_QOS_POLICY_ID: QosPolicyId = 20;
pub const LIFESPAN_QOS_POLICY_ID: QosPolicyId = 21;
pub const DURABILITYSERVICE_QOS_POLICY_ID: QosPolicyId = 22;
pub const DATA_REPRESENTATION_QOS_POLICY_ID: QosPolicyId = 23;
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct UserDataQosPolicy {
pub value: Vec<u8>,
}
impl UserDataQosPolicy {
pub const fn const_default() -> Self {
Self { value: Vec::new() }
}
}
impl QosPolicy for UserDataQosPolicy {
fn name(&self) -> &str {
USERDATA_QOS_POLICY_NAME
}
}
impl Default for UserDataQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct TopicDataQosPolicy {
pub value: Vec<u8>,
}
impl TopicDataQosPolicy {
pub const fn const_default() -> Self {
Self { value: Vec::new() }
}
}
impl Default for TopicDataQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
impl QosPolicy for TopicDataQosPolicy {
fn name(&self) -> &str {
TOPICDATA_QOS_POLICY_NAME
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct GroupDataQosPolicy {
pub value: Vec<u8>,
}
impl GroupDataQosPolicy {
pub const fn const_default() -> Self {
Self { value: Vec::new() }
}
}
impl QosPolicy for GroupDataQosPolicy {
fn name(&self) -> &str {
GROUPDATA_QOS_POLICY_NAME
}
}
impl Default for GroupDataQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct TransportPriorityQosPolicy {
pub value: i32,
}
impl TransportPriorityQosPolicy {
pub const fn const_default() -> Self {
Self { value: 0 }
}
}
impl QosPolicy for TransportPriorityQosPolicy {
fn name(&self) -> &str {
TRANSPORTPRIORITY_QOS_POLICY_NAME
}
}
impl Default for TransportPriorityQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct LifespanQosPolicy {
pub duration: DurationKind,
}
impl LifespanQosPolicy {
pub const fn const_default() -> Self {
Self {
duration: DurationKind::Infinite,
}
}
}
impl QosPolicy for LifespanQosPolicy {
fn name(&self) -> &str {
LIFESPAN_QOS_POLICY_NAME
}
}
impl Default for LifespanQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, TypeSupport)]
pub enum DurabilityQosPolicyKind {
Volatile,
TransientLocal,
Transient,
Persistent,
}
impl PartialOrd for DurabilityQosPolicyKind {
fn partial_cmp(&self, other: &DurabilityQosPolicyKind) -> Option<Ordering> {
match self {
DurabilityQosPolicyKind::Volatile => match other {
DurabilityQosPolicyKind::Volatile => Some(Ordering::Equal),
DurabilityQosPolicyKind::TransientLocal => Some(Ordering::Less),
DurabilityQosPolicyKind::Transient => Some(Ordering::Less),
DurabilityQosPolicyKind::Persistent => Some(Ordering::Less),
},
DurabilityQosPolicyKind::TransientLocal => match other {
DurabilityQosPolicyKind::Volatile => Some(Ordering::Greater),
DurabilityQosPolicyKind::TransientLocal => Some(Ordering::Equal),
DurabilityQosPolicyKind::Transient => Some(Ordering::Less),
DurabilityQosPolicyKind::Persistent => Some(Ordering::Less),
},
DurabilityQosPolicyKind::Transient => match other {
DurabilityQosPolicyKind::Volatile => Some(Ordering::Greater),
DurabilityQosPolicyKind::TransientLocal => Some(Ordering::Greater),
DurabilityQosPolicyKind::Transient => Some(Ordering::Equal),
DurabilityQosPolicyKind::Persistent => Some(Ordering::Less),
},
DurabilityQosPolicyKind::Persistent => match other {
DurabilityQosPolicyKind::Volatile => Some(Ordering::Greater),
DurabilityQosPolicyKind::TransientLocal => Some(Ordering::Greater),
DurabilityQosPolicyKind::Transient => Some(Ordering::Greater),
DurabilityQosPolicyKind::Persistent => Some(Ordering::Equal),
},
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct DurabilityQosPolicy {
pub kind: DurabilityQosPolicyKind,
}
impl DurabilityQosPolicy {
pub const fn const_default() -> Self {
Self {
kind: DurabilityQosPolicyKind::Volatile,
}
}
}
impl QosPolicy for DurabilityQosPolicy {
fn name(&self) -> &str {
DURABILITY_QOS_POLICY_NAME
}
}
impl Default for DurabilityQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, TypeSupport)]
pub enum PresentationQosPolicyAccessScopeKind {
Instance,
Topic,
}
impl PartialOrd for PresentationQosPolicyAccessScopeKind {
fn partial_cmp(&self, other: &PresentationQosPolicyAccessScopeKind) -> Option<Ordering> {
match self {
PresentationQosPolicyAccessScopeKind::Instance => match other {
PresentationQosPolicyAccessScopeKind::Instance => Some(Ordering::Equal),
PresentationQosPolicyAccessScopeKind::Topic => Some(Ordering::Less),
},
PresentationQosPolicyAccessScopeKind::Topic => match other {
PresentationQosPolicyAccessScopeKind::Instance => Some(Ordering::Greater),
PresentationQosPolicyAccessScopeKind::Topic => Some(Ordering::Equal),
},
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct PresentationQosPolicy {
pub access_scope: PresentationQosPolicyAccessScopeKind,
pub coherent_access: bool,
pub ordered_access: bool,
}
impl PresentationQosPolicy {
pub const fn const_default() -> Self {
Self {
access_scope: PresentationQosPolicyAccessScopeKind::Instance,
coherent_access: false,
ordered_access: false,
}
}
}
impl QosPolicy for PresentationQosPolicy {
fn name(&self) -> &str {
PRESENTATION_QOS_POLICY_NAME
}
}
impl Default for PresentationQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct DeadlineQosPolicy {
pub period: DurationKind,
}
impl DeadlineQosPolicy {
pub const fn const_default() -> Self {
Self {
period: DurationKind::Infinite,
}
}
}
impl QosPolicy for DeadlineQosPolicy {
fn name(&self) -> &str {
DEADLINE_QOS_POLICY_NAME
}
}
impl Default for DeadlineQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(PartialOrd, PartialEq, Eq, Debug, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct LatencyBudgetQosPolicy {
pub duration: DurationKind,
}
impl LatencyBudgetQosPolicy {
pub const fn const_default() -> Self {
Self {
duration: DurationKind::Finite(Duration::new(DURATION_ZERO_SEC, DURATION_ZERO_NSEC)),
}
}
}
impl QosPolicy for LatencyBudgetQosPolicy {
fn name(&self) -> &str {
LATENCYBUDGET_QOS_POLICY_NAME
}
}
impl Default for LatencyBudgetQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, TypeSupport)]
pub enum OwnershipQosPolicyKind {
Shared,
Exclusive,
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct OwnershipQosPolicy {
pub kind: OwnershipQosPolicyKind,
}
impl OwnershipQosPolicy {
pub const fn const_default() -> Self {
Self {
kind: OwnershipQosPolicyKind::Shared,
}
}
}
impl QosPolicy for OwnershipQosPolicy {
fn name(&self) -> &str {
OWNERSHIP_QOS_POLICY_NAME
}
}
impl Default for OwnershipQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct OwnershipStrengthQosPolicy {
pub value: i32,
}
impl OwnershipStrengthQosPolicy {
pub const fn const_default() -> Self {
Self { value: 0 }
}
}
impl QosPolicy for OwnershipStrengthQosPolicy {
fn name(&self) -> &str {
OWNERSHIP_STRENGTH_QOS_POLICY_NAME
}
}
impl Default for OwnershipStrengthQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, TypeSupport)]
pub enum LivelinessQosPolicyKind {
Automatic,
ManualByParticipant,
ManualByTopic,
}
impl PartialOrd for LivelinessQosPolicyKind {
fn partial_cmp(&self, other: &LivelinessQosPolicyKind) -> Option<Ordering> {
match self {
LivelinessQosPolicyKind::Automatic => match other {
LivelinessQosPolicyKind::Automatic => Some(Ordering::Equal),
LivelinessQosPolicyKind::ManualByParticipant => Some(Ordering::Less),
LivelinessQosPolicyKind::ManualByTopic => Some(Ordering::Less),
},
LivelinessQosPolicyKind::ManualByParticipant => match other {
LivelinessQosPolicyKind::Automatic => Some(Ordering::Greater),
LivelinessQosPolicyKind::ManualByParticipant => Some(Ordering::Equal),
LivelinessQosPolicyKind::ManualByTopic => Some(Ordering::Less),
},
LivelinessQosPolicyKind::ManualByTopic => match other {
LivelinessQosPolicyKind::Automatic => Some(Ordering::Greater),
LivelinessQosPolicyKind::ManualByParticipant => Some(Ordering::Greater),
LivelinessQosPolicyKind::ManualByTopic => Some(Ordering::Equal),
},
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct LivelinessQosPolicy {
pub kind: LivelinessQosPolicyKind,
pub lease_duration: DurationKind,
}
impl LivelinessQosPolicy {
pub const fn const_default() -> Self {
Self {
kind: LivelinessQosPolicyKind::Automatic,
lease_duration: DurationKind::Infinite,
}
}
}
impl QosPolicy for LivelinessQosPolicy {
fn name(&self) -> &str {
LIVELINESS_QOS_POLICY_NAME
}
}
impl Default for LivelinessQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct TimeBasedFilterQosPolicy {
pub minimum_separation: DurationKind,
}
impl TimeBasedFilterQosPolicy {
pub const fn const_default() -> Self {
Self {
minimum_separation: DurationKind::Finite(Duration::new(
DURATION_ZERO_SEC,
DURATION_ZERO_NSEC,
)),
}
}
}
impl QosPolicy for TimeBasedFilterQosPolicy {
fn name(&self) -> &str {
TIMEBASEDFILTER_QOS_POLICY_NAME
}
}
impl Default for TimeBasedFilterQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct PartitionQosPolicy {
pub name: Vec<String>,
}
impl PartitionQosPolicy {
pub const fn const_default() -> Self {
Self { name: Vec::new() }
}
}
impl QosPolicy for PartitionQosPolicy {
fn name(&self) -> &str {
PARTITION_QOS_POLICY_NAME
}
}
impl Default for PartitionQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, TypeSupport)]
#[repr(i32)]
pub enum ReliabilityQosPolicyKind {
BestEffort = 1,
Reliable = 2,
}
impl PartialOrd for ReliabilityQosPolicyKind {
fn partial_cmp(&self, other: &ReliabilityQosPolicyKind) -> Option<Ordering> {
match self {
ReliabilityQosPolicyKind::BestEffort => match other {
ReliabilityQosPolicyKind::BestEffort => Some(Ordering::Equal),
ReliabilityQosPolicyKind::Reliable => Some(Ordering::Less),
},
ReliabilityQosPolicyKind::Reliable => match other {
ReliabilityQosPolicyKind::BestEffort => Some(Ordering::Greater),
ReliabilityQosPolicyKind::Reliable => Some(Ordering::Equal),
},
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct ReliabilityQosPolicy {
pub kind: ReliabilityQosPolicyKind,
pub max_blocking_time: DurationKind,
}
impl QosPolicy for ReliabilityQosPolicy {
fn name(&self) -> &str {
RELIABILITY_QOS_POLICY_NAME
}
}
impl PartialOrd for ReliabilityQosPolicy {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.kind.partial_cmp(&other.kind)
}
}
const DEFAULT_MAX_BLOCKING_TIME: Duration = Duration::new(0, 100_000_000);
pub(crate) const DEFAULT_RELIABILITY_QOS_POLICY_DATA_READER_AND_TOPICS: ReliabilityQosPolicy =
ReliabilityQosPolicy {
kind: ReliabilityQosPolicyKind::BestEffort,
max_blocking_time: DurationKind::Finite(DEFAULT_MAX_BLOCKING_TIME),
};
pub(crate) const DEFAULT_RELIABILITY_QOS_POLICY_DATA_WRITER: ReliabilityQosPolicy =
ReliabilityQosPolicy {
kind: ReliabilityQosPolicyKind::Reliable,
max_blocking_time: DurationKind::Finite(DEFAULT_MAX_BLOCKING_TIME),
};
#[derive(Debug, PartialEq, Eq, Clone, Copy, TypeSupport)]
pub enum DestinationOrderQosPolicyKind {
ByReceptionTimestamp,
BySourceTimestamp,
}
impl PartialOrd for DestinationOrderQosPolicyKind {
fn partial_cmp(&self, other: &DestinationOrderQosPolicyKind) -> Option<Ordering> {
match self {
DestinationOrderQosPolicyKind::ByReceptionTimestamp => match other {
DestinationOrderQosPolicyKind::ByReceptionTimestamp => Some(Ordering::Equal),
DestinationOrderQosPolicyKind::BySourceTimestamp => Some(Ordering::Less),
},
DestinationOrderQosPolicyKind::BySourceTimestamp => match other {
DestinationOrderQosPolicyKind::ByReceptionTimestamp => Some(Ordering::Greater),
DestinationOrderQosPolicyKind::BySourceTimestamp => Some(Ordering::Equal),
},
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct DestinationOrderQosPolicy {
pub kind: DestinationOrderQosPolicyKind,
}
impl DestinationOrderQosPolicy {
pub const fn const_default() -> Self {
Self {
kind: DestinationOrderQosPolicyKind::ByReceptionTimestamp,
}
}
}
impl QosPolicy for DestinationOrderQosPolicyKind {
fn name(&self) -> &str {
DESTINATIONORDER_QOS_POLICY_NAME
}
}
impl Default for DestinationOrderQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum HistoryQosPolicyKind {
KeepLast(u32),
KeepAll,
}
impl TypeSupport for HistoryQosPolicyKind {
#[inline]
fn get_type_name() -> &'static str {
"HistoryQosPolicyKind"
}
fn get_type() -> crate::xtypes::dynamic_type::DynamicType {
extern crate alloc;
let builder = dust_dds::xtypes::dynamic_type::DynamicTypeBuilderFactory::create_type(
dust_dds::xtypes::dynamic_type::TypeDescriptor {
kind: dust_dds::xtypes::dynamic_type::TypeKind::ENUM,
name: alloc::string::String::from(Self::get_type_name()),
base_type: None,
discriminator_type: Some(
dust_dds::xtypes::dynamic_type::DynamicTypeBuilderFactory::get_primitive_type(
dust_dds::xtypes::dynamic_type::TypeKind::UINT8,
),
),
bound: alloc::vec::Vec::new(),
element_type: None,
key_element_type: None,
extensibility_kind: dust_dds::xtypes::dynamic_type::ExtensibilityKind::Final,
is_nested: false,
},
);
builder.build()
}
fn create_sample(src: crate::xtypes::dynamic_type::DynamicData) -> Self {
let discriminant = src.get_uint8_value(0).unwrap();
match discriminant {
0 => Self::KeepLast(1),
1 => Self::KeepAll,
d => panic!("Discriminant not valid {d:?}"),
}
}
fn create_dynamic_sample(self) -> crate::xtypes::dynamic_type::DynamicData {
let value = match self {
HistoryQosPolicyKind::KeepLast(_) => 0,
HistoryQosPolicyKind::KeepAll => 1,
};
let mut data = DynamicDataFactory::create_data(Self::get_type());
data.set_uint8_value(0, value).unwrap();
data
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct HistoryQosPolicy {
pub kind: HistoryQosPolicyKind,
}
impl HistoryQosPolicy {
pub const fn const_default() -> Self {
Self {
kind: HistoryQosPolicyKind::KeepLast(1),
}
}
}
impl dust_dds::infrastructure::type_support::TypeSupport for HistoryQosPolicy {
#[inline]
fn get_type_name() -> &'static str {
"HistoryQosPolicy"
}
fn get_type() -> dust_dds::xtypes::dynamic_type::DynamicType {
extern crate alloc;
let mut builder = dust_dds::xtypes::dynamic_type::DynamicTypeBuilderFactory::create_type(
dust_dds::xtypes::dynamic_type::TypeDescriptor {
kind: dust_dds::xtypes::dynamic_type::TypeKind::STRUCTURE,
name: alloc::string::String::from(Self::get_type_name()),
base_type: None,
discriminator_type: None,
bound: alloc::vec::Vec::new(),
element_type: None,
key_element_type: None,
extensibility_kind: dust_dds::xtypes::dynamic_type::ExtensibilityKind::Appendable,
is_nested: true,
},
);
builder
.add_member(dust_dds::xtypes::dynamic_type::MemberDescriptor {
name: alloc::string::String::from("kind"),
id: 0,
r#type: HistoryQosPolicyKind::get_type(),
default_value: None,
index: 0u32,
try_construct_kind: dust_dds::xtypes::dynamic_type::TryConstructKind::UseDefault,
label: alloc::vec::Vec::new(),
is_key: false,
is_optional: false,
is_must_understand: true,
is_shared: false,
is_default_label: false,
})
.unwrap();
builder
.add_member(dust_dds::xtypes::dynamic_type::MemberDescriptor {
name: alloc::string::String::from("depth"),
id: 1,
r#type:
dust_dds::xtypes::dynamic_type::DynamicTypeBuilderFactory::get_primitive_type(
TypeKind::INT32,
),
default_value: None,
index: 1u32,
try_construct_kind: dust_dds::xtypes::dynamic_type::TryConstructKind::UseDefault,
label: alloc::vec::Vec::new(),
is_key: false,
is_optional: false,
is_must_understand: true,
is_shared: false,
is_default_label: false,
})
.unwrap();
builder.build()
}
fn create_sample(src: crate::xtypes::dynamic_type::DynamicData) -> Self {
let kind = src.get_complex_value(0).cloned().unwrap();
let depth = src.get_int32_value(1).unwrap();
let qos_policy_kind = HistoryQosPolicyKind::create_sample(kind);
match qos_policy_kind {
HistoryQosPolicyKind::KeepLast(_) => HistoryQosPolicy {
kind: HistoryQosPolicyKind::KeepLast(*depth as u32),
},
HistoryQosPolicyKind::KeepAll => HistoryQosPolicy {
kind: HistoryQosPolicyKind::KeepAll,
},
}
}
fn create_dynamic_sample(self) -> crate::xtypes::dynamic_type::DynamicData {
let mut data = DynamicDataFactory::create_data(Self::get_type());
match self.kind {
HistoryQosPolicyKind::KeepLast(depth) => {
data.set_complex_value(0, self.kind.create_dynamic_sample())
.unwrap();
data.set_int32_value(1, depth as i32).unwrap();
}
HistoryQosPolicyKind::KeepAll => {
data.set_complex_value(0, self.kind.create_dynamic_sample())
.unwrap();
data.set_int32_value(1, 0).unwrap();
}
}
data
}
}
impl QosPolicy for HistoryQosPolicy {
fn name(&self) -> &str {
HISTORY_QOS_POLICY_NAME
}
}
impl Default for HistoryQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct ResourceLimitsQosPolicy {
pub max_samples: Length,
pub max_instances: Length,
pub max_samples_per_instance: Length,
}
impl ResourceLimitsQosPolicy {
pub const fn const_default() -> Self {
Self {
max_samples: Length::Unlimited,
max_instances: Length::Unlimited,
max_samples_per_instance: Length::Unlimited,
}
}
}
impl QosPolicy for ResourceLimitsQosPolicy {
fn name(&self) -> &str {
RESOURCELIMITS_QOS_POLICY_NAME
}
}
impl Default for ResourceLimitsQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct EntityFactoryQosPolicy {
pub autoenable_created_entities: bool,
}
impl EntityFactoryQosPolicy {
pub const fn const_default() -> Self {
Self {
autoenable_created_entities: true,
}
}
}
impl QosPolicy for EntityFactoryQosPolicy {
fn name(&self) -> &str {
ENTITYFACTORY_QOS_POLICY_NAME
}
}
impl Default for EntityFactoryQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct WriterDataLifecycleQosPolicy {
pub autodispose_unregistered_instances: bool,
}
impl WriterDataLifecycleQosPolicy {
pub const fn const_default() -> Self {
Self {
autodispose_unregistered_instances: true,
}
}
}
impl QosPolicy for WriterDataLifecycleQosPolicy {
fn name(&self) -> &str {
WRITERDATALIFECYCLE_QOS_POLICY_NAME
}
}
impl Default for WriterDataLifecycleQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ReaderDataLifecycleQosPolicy {
pub autopurge_nowriter_samples_delay: DurationKind,
pub autopurge_disposed_samples_delay: DurationKind,
}
impl ReaderDataLifecycleQosPolicy {
pub const fn const_default() -> Self {
Self {
autopurge_nowriter_samples_delay: DurationKind::Infinite,
autopurge_disposed_samples_delay: DurationKind::Infinite,
}
}
}
impl QosPolicy for ReaderDataLifecycleQosPolicy {
fn name(&self) -> &str {
READERDATALIFECYCLE_QOS_POLICY_NAME
}
}
impl Default for ReaderDataLifecycleQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
impl From<&ReliabilityQosPolicy> for ReliabilityKind {
fn from(value: &ReliabilityQosPolicy) -> Self {
match value.kind {
ReliabilityQosPolicyKind::BestEffort => ReliabilityKind::BestEffort,
ReliabilityQosPolicyKind::Reliable => ReliabilityKind::Reliable,
}
}
}
impl From<&DurabilityQosPolicy> for DurabilityKind {
fn from(value: &DurabilityQosPolicy) -> Self {
match value.kind {
DurabilityQosPolicyKind::Volatile => DurabilityKind::Volatile,
DurabilityQosPolicyKind::TransientLocal => DurabilityKind::TransientLocal,
DurabilityQosPolicyKind::Transient => DurabilityKind::Transient,
DurabilityQosPolicyKind::Persistent => DurabilityKind::Persistent,
}
}
}
type DataRepresentationId = u16;
pub const XCDR_DATA_REPRESENTATION: DataRepresentationId = 0;
pub const XML_DATA_REPRESENTATION: DataRepresentationId = 1;
pub const XCDR2_DATA_REPRESENTATION: DataRepresentationId = 2;
pub(crate) const BUILT_IN_DATA_REPRESENTATION: DataRepresentationId = 9999;
type DataRepresentationIdSeq = Vec<DataRepresentationId>;
#[derive(Debug, PartialEq, Eq, Clone, TypeSupport)]
#[dust_dds(extensibility = "appendable", nested)]
pub struct DataRepresentationQosPolicy {
pub value: DataRepresentationIdSeq,
}
impl DataRepresentationQosPolicy {
pub const fn const_default() -> Self {
Self {
value: DataRepresentationIdSeq::new(),
}
}
}
impl QosPolicy for DataRepresentationQosPolicy {
fn name(&self) -> &str {
DATA_REPRESENTATION_QOS_POLICY_NAME
}
}
impl Default for DataRepresentationQosPolicy {
fn default() -> Self {
Self::const_default()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn durability_qos_policy_kind_ordering() {
assert!(DurabilityQosPolicyKind::Volatile < DurabilityQosPolicyKind::TransientLocal);
assert!(DurabilityQosPolicyKind::Volatile == DurabilityQosPolicyKind::Volatile);
assert!(DurabilityQosPolicyKind::Volatile < DurabilityQosPolicyKind::TransientLocal);
assert!(DurabilityQosPolicyKind::TransientLocal > DurabilityQosPolicyKind::Volatile);
assert!(DurabilityQosPolicyKind::TransientLocal == DurabilityQosPolicyKind::TransientLocal);
}
#[test]
fn presentation_qos_policy_access_scope_kind_ordering() {
assert!(
PresentationQosPolicyAccessScopeKind::Instance
< PresentationQosPolicyAccessScopeKind::Topic
);
assert!(
PresentationQosPolicyAccessScopeKind::Instance
== PresentationQosPolicyAccessScopeKind::Instance
);
assert!(
PresentationQosPolicyAccessScopeKind::Instance
< PresentationQosPolicyAccessScopeKind::Topic
);
assert!(
PresentationQosPolicyAccessScopeKind::Topic
> PresentationQosPolicyAccessScopeKind::Instance
);
assert!(
PresentationQosPolicyAccessScopeKind::Topic
== PresentationQosPolicyAccessScopeKind::Topic
);
}
#[test]
fn liveliness_qos_policy_kind_ordering() {
assert!(LivelinessQosPolicyKind::Automatic < LivelinessQosPolicyKind::ManualByParticipant);
assert!(
LivelinessQosPolicyKind::ManualByParticipant < LivelinessQosPolicyKind::ManualByTopic
);
assert!(LivelinessQosPolicyKind::Automatic == LivelinessQosPolicyKind::Automatic);
assert!(LivelinessQosPolicyKind::Automatic < LivelinessQosPolicyKind::ManualByParticipant);
assert!(LivelinessQosPolicyKind::Automatic < LivelinessQosPolicyKind::ManualByTopic);
assert!(LivelinessQosPolicyKind::ManualByParticipant > LivelinessQosPolicyKind::Automatic);
assert!(
LivelinessQosPolicyKind::ManualByParticipant
== LivelinessQosPolicyKind::ManualByParticipant
);
assert!(
LivelinessQosPolicyKind::ManualByParticipant < LivelinessQosPolicyKind::ManualByTopic
);
assert!(LivelinessQosPolicyKind::ManualByTopic > LivelinessQosPolicyKind::Automatic);
assert!(
LivelinessQosPolicyKind::ManualByTopic > LivelinessQosPolicyKind::ManualByParticipant
);
assert!(LivelinessQosPolicyKind::ManualByTopic == LivelinessQosPolicyKind::ManualByTopic);
}
#[test]
fn reliability_qos_policy_kind_ordering() {
assert!(ReliabilityQosPolicyKind::BestEffort < ReliabilityQosPolicyKind::Reliable);
assert!(ReliabilityQosPolicyKind::BestEffort == ReliabilityQosPolicyKind::BestEffort);
assert!(ReliabilityQosPolicyKind::BestEffort < ReliabilityQosPolicyKind::Reliable);
assert!(ReliabilityQosPolicyKind::Reliable > ReliabilityQosPolicyKind::BestEffort);
assert!(ReliabilityQosPolicyKind::Reliable == ReliabilityQosPolicyKind::Reliable);
}
#[test]
fn destination_order_qos_policy_kind_ordering() {
assert!(
DestinationOrderQosPolicyKind::ByReceptionTimestamp
< DestinationOrderQosPolicyKind::BySourceTimestamp
);
assert!(
DestinationOrderQosPolicyKind::ByReceptionTimestamp
== DestinationOrderQosPolicyKind::ByReceptionTimestamp
);
assert!(
DestinationOrderQosPolicyKind::ByReceptionTimestamp
< DestinationOrderQosPolicyKind::BySourceTimestamp
);
assert!(
DestinationOrderQosPolicyKind::BySourceTimestamp
> DestinationOrderQosPolicyKind::ByReceptionTimestamp
);
assert!(
DestinationOrderQosPolicyKind::BySourceTimestamp
== DestinationOrderQosPolicyKind::BySourceTimestamp
);
}
#[test]
fn length_ordering() {
assert!(Length::Unlimited > Length::Limited(10));
assert!(Length::Unlimited == Length::Unlimited);
assert!(Length::Limited(10) < Length::Unlimited);
assert!(Length::Limited(10) < Length::Limited(20));
assert!(Length::Limited(20) > Length::Limited(10));
}
#[test]
fn length_usize_ordering() {
assert!(Length::Unlimited > 10usize);
assert!(10usize < Length::Unlimited);
assert!(Length::Limited(20) > 10usize);
assert!(10usize < Length::Limited(20));
assert!(Length::Limited(10) == 10usize);
assert!(10usize == Length::Limited(10));
}
}