use std::path::PathBuf;
use modem_device::{
Capabilities, Counter, DeviceEvent, LaneKey, Metrics, Report, SecurityProperties,
};
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct LaneView {
pub key: LaneKey,
pub path: PathBuf,
pub connected: bool,
pub backlog_bytes: Option<u64>,
}
impl LaneView {
#[must_use]
pub fn new(key: LaneKey, path: PathBuf, connected: bool) -> Self {
Self {
key,
path,
connected,
backlog_bytes: None,
}
}
#[must_use]
pub fn backlog_bytes(mut self, bytes: u64) -> Self {
self.backlog_bytes = Some(bytes);
self
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct SchedulerCounters {
pub submitted: u64,
pub sent: u64,
pub dropped: u64,
pub stale: u64,
pub peerless: u64,
pub tx_failed: u64,
pub unroutable: u64,
pub rx_oversize: u64,
pub tx_oversize: u64,
}
macro_rules! scheduler_counter_setters {
($($name:ident),* $(,)?) => {
impl SchedulerCounters {
#[must_use]
pub fn new() -> Self {
Self::default()
}
$(
#[doc = concat!("With `", stringify!($name), "`.")]
#[must_use]
pub fn $name(mut self, n: u64) -> Self {
self.$name = n;
self
}
)*
}
};
}
scheduler_counter_setters!(
submitted,
sent,
dropped,
stale,
peerless,
tx_failed,
unroutable,
rx_oversize,
tx_oversize,
);
impl SchedulerCounters {
#[must_use]
pub fn queue_depth(&self) -> u64 {
self.submitted.saturating_sub(self.sent)
}
}
#[async_trait::async_trait]
pub trait SduPlane: Send + Sync {
fn device(&self) -> &str;
fn capabilities(&self) -> Capabilities;
fn lanes(&self) -> Vec<LaneView>;
fn scheduler(&self) -> SchedulerCounters;
fn medium_metrics(&self) -> Metrics;
fn report(&self) -> Report;
fn security(&self) -> Option<SecurityProperties> {
None
}
fn counters(&self) -> Vec<Counter> {
Vec::new()
}
fn health(&self) -> tokio::sync::watch::Receiver<bool>;
fn oper(&self) -> modem_device::OperStatus;
fn identity(&self) -> modem_device::Identity;
fn configuration(&self) -> Option<&dyn modem_device::Configure>;
fn actions(&self) -> Option<&dyn modem_device::Actions>;
fn events(&self) -> tokio::sync::broadcast::Receiver<DeviceEvent>;
async fn shutdown(&self);
}