timekeeper_config/
timekeeper-config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_timekeeperconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0x44, 0x44, 0x26, 0xa2, 0x6d, 0xf1, 0x47, 0xf4, 0x3e, 0x48, 0xdb, 0x89, 0xf9, 0x6f, 0x39, 0xff,
8    0x73, 0x07, 0xae, 0x5f, 0xac, 0x84, 0x26, 0xba, 0x77, 0xc0, 0x7f, 0xfc, 0x14, 0xc7, 0xd2, 0xa7,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub back_off_time_between_pull_samples_sec: i64,
13    pub disable_delays: bool,
14    pub early_exit: bool,
15    pub first_sampling_delay_sec: i64,
16    pub has_always_on_counter: bool,
17    pub has_real_time_clock: bool,
18    pub initial_frequency_ppm: u32,
19    pub max_frequency_error_ppm: u32,
20    pub monitor_time_source_url: String,
21    pub monitor_uses_pull: bool,
22    pub oscillator_error_std_dev_ppm: u32,
23    pub power_topology_integration_enabled: bool,
24    pub primary_time_source_url: String,
25    pub primary_uses_pull: bool,
26    pub serve_fuchsia_time_alarms: bool,
27    pub serve_fuchsia_time_external_adjust: bool,
28    pub serve_test_protocols: bool,
29    pub use_connectivity: bool,
30    pub utc_max_allowed_delta_future_sec: i64,
31    pub utc_max_allowed_delta_past_sec: i64,
32    pub utc_start_at_startup: bool,
33    pub utc_start_at_startup_when_invalid_rtc: bool,
34}
35impl Config {
36    #[doc = r" Take the config startup handle and parse its contents."]
37    #[doc = r""]
38    #[doc = r" # Panics"]
39    #[doc = r""]
40    #[doc = r" If the config startup handle was already taken or if it is not valid."]
41    pub fn take_from_startup_handle() -> Self {
42        <Self as ComponentConfig>::take_from_startup_handle()
43    }
44    #[doc = r" Parse `Self` from `vmo`."]
45    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
46        <Self as ComponentConfig>::from_vmo(vmo)
47    }
48    #[doc = r" Parse `Self` from `bytes`."]
49    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
50        <Self as ComponentConfig>::from_bytes(bytes)
51    }
52    pub fn record_inspect(&self, inspector_node: &Node) {
53        <Self as ComponentConfig>::record_inspect(self, inspector_node)
54    }
55}
56impl ComponentConfig for Config {
57    #[doc = r" Parse `Self` from `bytes`."]
58    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
59        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
60        let checksum_len_bytes: [u8; 2] =
61            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
62        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
63        let (observed_checksum, bytes) =
64            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
65        if observed_checksum != EXPECTED_CHECKSUM {
66            return Err(Error::ChecksumMismatch {
67                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
68                observed_checksum: observed_checksum.to_vec(),
69            });
70        }
71        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
72        Ok(Self {
73            back_off_time_between_pull_samples_sec: fidl_config
74                .back_off_time_between_pull_samples_sec,
75            disable_delays: fidl_config.disable_delays,
76            early_exit: fidl_config.early_exit,
77            first_sampling_delay_sec: fidl_config.first_sampling_delay_sec,
78            has_always_on_counter: fidl_config.has_always_on_counter,
79            has_real_time_clock: fidl_config.has_real_time_clock,
80            initial_frequency_ppm: fidl_config.initial_frequency_ppm,
81            max_frequency_error_ppm: fidl_config.max_frequency_error_ppm,
82            monitor_time_source_url: fidl_config.monitor_time_source_url,
83            monitor_uses_pull: fidl_config.monitor_uses_pull,
84            oscillator_error_std_dev_ppm: fidl_config.oscillator_error_std_dev_ppm,
85            power_topology_integration_enabled: fidl_config.power_topology_integration_enabled,
86            primary_time_source_url: fidl_config.primary_time_source_url,
87            primary_uses_pull: fidl_config.primary_uses_pull,
88            serve_fuchsia_time_alarms: fidl_config.serve_fuchsia_time_alarms,
89            serve_fuchsia_time_external_adjust: fidl_config.serve_fuchsia_time_external_adjust,
90            serve_test_protocols: fidl_config.serve_test_protocols,
91            use_connectivity: fidl_config.use_connectivity,
92            utc_max_allowed_delta_future_sec: fidl_config.utc_max_allowed_delta_future_sec,
93            utc_max_allowed_delta_past_sec: fidl_config.utc_max_allowed_delta_past_sec,
94            utc_start_at_startup: fidl_config.utc_start_at_startup,
95            utc_start_at_startup_when_invalid_rtc: fidl_config
96                .utc_start_at_startup_when_invalid_rtc,
97        })
98    }
99    fn record_inspect(&self, inspector_node: &Node) {
100        inspector_node.record_int(
101            "back_off_time_between_pull_samples_sec",
102            self.back_off_time_between_pull_samples_sec,
103        );
104        inspector_node.record_bool("disable_delays", self.disable_delays);
105        inspector_node.record_bool("early_exit", self.early_exit);
106        inspector_node.record_int("first_sampling_delay_sec", self.first_sampling_delay_sec);
107        inspector_node.record_bool("has_always_on_counter", self.has_always_on_counter);
108        inspector_node.record_bool("has_real_time_clock", self.has_real_time_clock);
109        inspector_node.record_uint("initial_frequency_ppm", self.initial_frequency_ppm as u64);
110        inspector_node.record_uint("max_frequency_error_ppm", self.max_frequency_error_ppm as u64);
111        inspector_node.record_string("monitor_time_source_url", &self.monitor_time_source_url);
112        inspector_node.record_bool("monitor_uses_pull", self.monitor_uses_pull);
113        inspector_node
114            .record_uint("oscillator_error_std_dev_ppm", self.oscillator_error_std_dev_ppm as u64);
115        inspector_node.record_bool(
116            "power_topology_integration_enabled",
117            self.power_topology_integration_enabled,
118        );
119        inspector_node.record_string("primary_time_source_url", &self.primary_time_source_url);
120        inspector_node.record_bool("primary_uses_pull", self.primary_uses_pull);
121        inspector_node.record_bool("serve_fuchsia_time_alarms", self.serve_fuchsia_time_alarms);
122        inspector_node.record_bool(
123            "serve_fuchsia_time_external_adjust",
124            self.serve_fuchsia_time_external_adjust,
125        );
126        inspector_node.record_bool("serve_test_protocols", self.serve_test_protocols);
127        inspector_node.record_bool("use_connectivity", self.use_connectivity);
128        inspector_node
129            .record_int("utc_max_allowed_delta_future_sec", self.utc_max_allowed_delta_future_sec);
130        inspector_node
131            .record_int("utc_max_allowed_delta_past_sec", self.utc_max_allowed_delta_past_sec);
132        inspector_node.record_bool("utc_start_at_startup", self.utc_start_at_startup);
133        inspector_node.record_bool(
134            "utc_start_at_startup_when_invalid_rtc",
135            self.utc_start_at_startup_when_invalid_rtc,
136        );
137    }
138}