ntpsec_rs_core/
ntp_refclock.rs1use crate::ntp_types::*;
9
10pub type RefClockId = u32;
12
13pub type RefClockUnit = u32;
15
16#[derive(Debug, Clone, Copy)]
18pub struct RefClockSample {
19 pub offset: f64,
20 pub delay: f64,
21 pub dispersion: f64,
22 pub time: NtpTs64,
23 pub leap: LeapIndicator,
24}
25
26pub trait RefClockDriver: std::fmt::Debug {
28 fn name(&self) -> &'static str;
29 fn type_id(&self) -> RefClockId;
30 fn poll(&mut self) -> Option<RefClockSample>;
31 fn timeout(&self) -> u32;
32}
33
34#[derive(Debug, Default)]
36pub struct RefClockRegistry {
37 drivers: Vec<Box<dyn RefClockDriver + Send>>,
38}
39
40impl RefClockRegistry {
41 pub fn new() -> Self {
42 Self {
43 drivers: Vec::new(),
44 }
45 }
46
47 pub fn register(&mut self, driver: Box<dyn RefClockDriver + Send>) {
48 self.drivers.push(driver);
49 }
50
51 pub fn drivers(&self) -> &[Box<dyn RefClockDriver + Send>] {
52 &self.drivers
53 }
54}