use crate::dds::qos::QosPolicyId;
use mio::{Evented};
use mio_extras::channel as mio_channel;
pub trait StatusEvented<E> {
fn as_status_evented(&mut self) -> &dyn Evented;
fn try_recv_status(&self) -> Option<E>;
}
pub(crate) struct StatusReceiver<E> {
channel_receiver: mio_channel::Receiver<E>,
enabled: bool, }
impl<E> StatusReceiver<E> {
pub fn new(channel_receiver: mio_channel::Receiver<E>) -> StatusReceiver<E> {
StatusReceiver::<E> { channel_receiver, enabled: false }
}
}
impl<E> StatusEvented<E> for StatusReceiver<E> {
fn as_status_evented(&mut self) -> &dyn Evented {
self.enabled = true;
&self.channel_receiver
}
fn try_recv_status(&self) -> Option<E> {
if self.enabled {
self.channel_receiver.try_recv().ok()
} else {
None
}
}
}
#[derive(Debug, Clone)]
pub enum DomainParticipantStatus {
PublisherStatus(PublisherStatus),
SubscriberStatus(SubscriberStatus),
TopicStatus(TopicStatus),
}
#[derive(Debug, Clone)]
pub enum SubscriberStatus {
DataOnReaders,
DataReaderStatus(DataReaderStatus),
}
pub type PublisherStatus = DataWriterStatus;
#[derive(Debug, Clone)]
pub enum TopicStatus {
InconsistentTopic { count: CountWithChange },
}
#[derive(Debug, Clone)]
pub enum DataReaderStatus {
SampleRejected {
count: CountWithChange,
last_reason: SampleRejectedStatusKind,
},
LivelinessChanged {
alive_total: CountWithChange,
not_alive_total: CountWithChange,
},
RequestedDeadlineMissed {
count: CountWithChange,
},
RequestedIncompatibleQos {
count: CountWithChange,
last_policy_id: QosPolicyId,
policies: Vec<QosPolicyCount>,
},
SampleLost {
count: CountWithChange
},
SubscriptionMatched {
total: CountWithChange,
current: CountWithChange,
},
}
#[derive(Debug, Clone)]
pub enum DataWriterStatus {
LivelinessLost {
count: CountWithChange
},
OfferedDeadlineMissed {
count: CountWithChange,
},
OfferedIncompatibleQos {
count: CountWithChange,
last_policy_id: QosPolicyId,
policies: Vec<QosPolicyCount>,
},
PublicationMatched {
total: CountWithChange,
current: CountWithChange,
},
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct CountWithChange {
count: i32,
count_change: i32,
}
impl CountWithChange {
pub(crate) fn new(count: i32, count_change: i32) -> CountWithChange {
CountWithChange { count, count_change }
}
pub fn start_from(count: i32, count_change: i32) -> CountWithChange {
CountWithChange { count, count_change }
}
pub fn count(&self) -> i32 {
self.count
}
pub fn count_change(&self) -> i32 {
self.count_change
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SampleRejectedStatusKind {
NotRejected,
ByInstancesLimit,
BySamplesLimit,
BySamplesPerInstanceLimit,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct QosPolicyCount {
policy_id: QosPolicyId,
count: i32,
}