use core::fmt;
use std::sync::Arc;
use crate::constructed::{BACnetBDTEntry, BACnetFDTEntry, BACnetHostNPort};
use crate::enums::IPMode;
pub trait BbmdTables: Send + Sync {
fn broadcast_distribution_table(&self) -> Vec<BACnetBDTEntry>;
fn accepts_foreign_device_registrations(&self) -> bool;
fn foreign_device_table(&self) -> Vec<BACnetFDTEntry>;
}
#[derive(Clone)]
pub enum BipPortMode {
Normal,
Foreign {
bbmd: BACnetHostNPort,
subscription_lifetime: u16,
},
Bbmd {
tables: Option<Arc<dyn BbmdTables>>,
},
}
impl BipPortMode {
pub fn ip_mode(&self) -> IPMode {
match self {
Self::Normal => IPMode::NORMAL,
Self::Foreign { .. } => IPMode::FOREIGN,
Self::Bbmd { .. } => IPMode::BBMD,
}
}
}
impl fmt::Debug for BipPortMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Normal => f.write_str("Normal"),
Self::Foreign {
bbmd,
subscription_lifetime,
} => f
.debug_struct("Foreign")
.field("bbmd", bbmd)
.field("subscription_lifetime", subscription_lifetime)
.finish(),
Self::Bbmd { tables } => f
.debug_struct("Bbmd")
.field("started", &tables.is_some())
.finish(),
}
}
}