use std::result;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
BadParameter,
Unsupported,
OutOfResources,
NotEnabled,
ImmutablePolicy, InconsistentPolicy,
PreconditionNotMet,
IllegalOperation,
LockPoisoned,
}
impl<T> From<std::sync::PoisonError<T>> for Error {
fn from(_e:std::sync::PoisonError<T>) -> Error {
Error::LockPoisoned
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub(crate) struct CountWithChange {
count: i32,
count_change: i32,
}
impl CountWithChange {
pub(crate) fn new() -> CountWithChange {
CountWithChange {
count: 0,
count_change: 0,
}
}
#[cfg(test)]
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
}
pub fn increase(&mut self) {
self.count += 1;
self.count_change += 1;
}
pub fn reset_count(&mut self) {
self.count_change = 0;
}
}
pub struct InconsistentTopicStatus {
total: CountWithChange,
}
impl InconsistentTopicStatus {
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
}
pub struct SampleLostStatus {
total: CountWithChange,
}
impl SampleLostStatus {
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
}
#[derive(Clone, Copy)]
pub enum SampleRejectedReason {
InstancesLimit,
SamplesLimit,
SamplesPerInstanceLimit,
}
pub struct SampleRejectedStatus {
total: CountWithChange,
last_reason: Option<SampleRejectedReason>, }
impl SampleRejectedStatus {
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
pub fn sample_rejected_reason(&self) -> Option<SampleRejectedReason> {
self.last_reason
}
}
#[derive(Debug, Clone)]
pub enum StatusChange {
LivelinessLostStatus(LivelinessLostStatus),
OfferedDeadlineMissedStatus(OfferedDeadlineMissedStatus),
OfferedIncompatibleQosStatus(OfferedIncompatibleQosStatus),
RequestedDeadlineMissedStatus(RequestedDeadlineMissedStatus),
RequestedIncompatibleQosStatus(RequestedIncompatibleQosStatus),
PublicationMatchedStatus(PublicationMatchedStatus),
SubscriptionMatchedStatus(SubscriptionMatchedStatus),
}
#[derive(Debug, Copy, Clone)]
pub struct LivelinessLostStatus {
total: CountWithChange,
}
impl LivelinessLostStatus {
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
}
#[derive(Debug, Copy, Clone)]
pub struct OfferedDeadlineMissedStatus {
total: CountWithChange,
}
impl OfferedDeadlineMissedStatus {
pub(crate) fn new() -> OfferedDeadlineMissedStatus {
OfferedDeadlineMissedStatus {
total: CountWithChange {
count: 0,
count_change: 0,
},
}
}
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
pub(crate) fn increase(&mut self) {
self.total.increase();
}
pub(crate) fn reset_change(&mut self) {
self.total.reset_count();
}
}
#[derive(Debug, Clone)]
pub struct OfferedIncompatibleQosStatus {
total: CountWithChange,
}
impl OfferedIncompatibleQosStatus {
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct RequestedDeadlineMissedStatus {
total: CountWithChange,
}
impl RequestedDeadlineMissedStatus {
pub(crate) fn new() -> RequestedDeadlineMissedStatus {
RequestedDeadlineMissedStatus {
total: CountWithChange {
count: 0,
count_change: 0,
},
}
}
#[cfg(test)]
pub(crate) fn from_count(total: CountWithChange) -> RequestedDeadlineMissedStatus {
RequestedDeadlineMissedStatus { total }
}
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
pub(crate) fn increase(&mut self) {
self.total.increase();
}
pub(crate) fn reset_change(&mut self) {
self.total.reset_count();
}
}
#[derive(Debug, Clone)]
pub struct RequestedIncompatibleQosStatus {
total: CountWithChange,
}
impl RequestedIncompatibleQosStatus {
pub fn count(&self) -> i32 {
self.total.count()
}
pub fn count_change(&self) -> i32 {
self.total.count_change()
}
}
#[derive(Debug, Copy, Clone)]
pub struct PublicationMatchedStatus {
total: CountWithChange,
current: CountWithChange,
}
impl PublicationMatchedStatus {
pub fn total_count(&self) -> i32 {
self.total.count()
}
pub fn total_count_change(&self) -> i32 {
self.total.count_change()
}
pub fn current_count(&self) -> i32 {
self.current.count()
}
pub fn current_count_change(&self) -> i32 {
self.current.count_change()
}
}
#[derive(Debug, Copy, Clone)]
pub struct SubscriptionMatchedStatus {
total: CountWithChange,
current: CountWithChange,
}
impl SubscriptionMatchedStatus {
pub fn total_count(&self) -> i32 {
self.total.count()
}
pub fn total_count_change(&self) -> i32 {
self.total.count_change()
}
pub fn current_count(&self) -> i32 {
self.current.count()
}
pub fn current_count_change(&self) -> i32 {
self.current.count_change()
}
}