-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathclock.rs
More file actions
73 lines (64 loc) · 2.77 KB
/
Copy pathclock.rs
File metadata and controls
73 lines (64 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{Duration, TAI, Timestamp};
/// Interface for a controllable clock
/// This needs to be a trait as a single system can have multiple clocks
/// which need different implementation for steering and/or now.
pub trait Clock: Clone + Send + 'static {
/// Error that can occur in operations on the clock.
type Error: core::error::Error + Send + Sync;
/// Get current time
///
/// # Errors
/// Should return an error if the clock is unable to provide a timestamp.
fn now(&self) -> Result<Timestamp<TAI>, Self::Error>;
/// Change the frequency of the clock, returning the time
/// at which the change was applied.
///
/// # Errors
/// Should return an error if the clock is unable to be steered by the requested amount.
fn set_frequency(&self, freq: f64) -> Result<Timestamp<TAI>, Self::Error>;
/// Get the frequency of the clock
///
/// # Errors
/// Should return an error if the clock is unable to provide its current steering frequency.
fn get_frequency(&self) -> Result<f64, Self::Error>;
/// Maximum frequency offset the clock is capable of.
///
/// # Errors
/// Should return an error if the maximum frequency offset could not be determined.
fn max_frequency(&self) -> Result<f64, Self::Error>;
/// Change the current time of the clock by offset. Returns
/// the time at which the change was applied.
///
/// # Errors
/// Should return an error if the clock cannot be stepped by the amount requested.
fn step_clock(&self, offset: Duration) -> Result<Timestamp<TAI>, Self::Error>;
/// Provide the system with our current best estimates for
/// the statistical error of the clock (`est_error`), and
/// the maximum deviation due to frequency error and
/// distance to the root clock.
///
/// # Errors
/// Should return an error if the error estimate update cannot be applied to the clock.
fn error_estimate_update(
&self,
est_error: Duration,
max_error: Duration,
) -> Result<(), Self::Error>;
/// Change the indicators for upcoming leap seconds and
/// the clocks synchronization status. Application should happen at the end of the UTC month.
///
/// # Errors
/// Should return an error if the status update cannot be applied to the clock.
fn status_update(&self, leap_status: LeapStatus) -> Result<(), Self::Error>;
}
/// Information on what the next leap second is going to be.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LeapStatus {
/// There is no leap second at the end of the month.
#[default]
None,
/// A second needs to be removed from the last minute of the month.
Leap59,
/// A second needs to be inserted into the last minute of the month.
Leap61,
}