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 0x34, 0x45, 0x36, 0x87, 0x7e, 0x12, 0xd7, 0xe4, 0x8f, 0xb4, 0xec, 0x51, 0xd1, 0xbe, 0xc9, 0xe2,
8 0x02, 0xe7, 0x21, 0xae, 0x97, 0xe3, 0xbf, 0x17, 0xe4, 0x48, 0x55, 0xf6, 0x68, 0x9a, 0xc5, 0x71,
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 min_utc_reference_to_backstop_diff_minutes: u64,
21 pub monitor_time_source_url: String,
22 pub monitor_uses_pull: bool,
23 pub oscillator_error_std_dev_ppm: u32,
24 pub power_topology_integration_enabled: bool,
25 pub primary_time_source_url: String,
26 pub primary_uses_pull: bool,
27 pub serve_fuchsia_time_alarms: bool,
28 pub serve_fuchsia_time_external_adjust: bool,
29 pub serve_test_protocols: bool,
30 pub use_connectivity: bool,
31 pub utc_max_allowed_delta_future_sec: i64,
32 pub utc_max_allowed_delta_past_sec: i64,
33 pub utc_start_at_startup: bool,
34 pub utc_start_at_startup_when_invalid_rtc: bool,
35}
36impl Config {
37 #[doc = r" Take the config startup handle and parse its contents."]
38 #[doc = r""]
39 #[doc = r" # Panics"]
40 #[doc = r""]
41 #[doc = r" If the config startup handle was already taken or if it is not valid."]
42 pub fn take_from_startup_handle() -> Self {
43 <Self as ComponentConfig>::take_from_startup_handle()
44 }
45 #[doc = r" Parse `Self` from `vmo`."]
46 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
47 <Self as ComponentConfig>::from_vmo(vmo)
48 }
49 #[doc = r" Parse `Self` from `bytes`."]
50 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
51 <Self as ComponentConfig>::from_bytes(bytes)
52 }
53 pub fn record_inspect(&self, inspector_node: &Node) {
54 <Self as ComponentConfig>::record_inspect(self, inspector_node)
55 }
56}
57impl ComponentConfig for Config {
58 #[doc = r" Parse `Self` from `bytes`."]
59 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
60 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
61 let checksum_len_bytes: [u8; 2] =
62 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
63 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
64 let (observed_checksum, bytes) =
65 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
66 if observed_checksum != EXPECTED_CHECKSUM {
67 return Err(Error::ChecksumMismatch {
68 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
69 observed_checksum: observed_checksum.to_vec(),
70 });
71 }
72 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
73 Ok(Self {
74 back_off_time_between_pull_samples_sec: fidl_config
75 .back_off_time_between_pull_samples_sec,
76 disable_delays: fidl_config.disable_delays,
77 early_exit: fidl_config.early_exit,
78 first_sampling_delay_sec: fidl_config.first_sampling_delay_sec,
79 has_always_on_counter: fidl_config.has_always_on_counter,
80 has_real_time_clock: fidl_config.has_real_time_clock,
81 initial_frequency_ppm: fidl_config.initial_frequency_ppm,
82 max_frequency_error_ppm: fidl_config.max_frequency_error_ppm,
83 min_utc_reference_to_backstop_diff_minutes: fidl_config
84 .min_utc_reference_to_backstop_diff_minutes,
85 monitor_time_source_url: fidl_config.monitor_time_source_url,
86 monitor_uses_pull: fidl_config.monitor_uses_pull,
87 oscillator_error_std_dev_ppm: fidl_config.oscillator_error_std_dev_ppm,
88 power_topology_integration_enabled: fidl_config.power_topology_integration_enabled,
89 primary_time_source_url: fidl_config.primary_time_source_url,
90 primary_uses_pull: fidl_config.primary_uses_pull,
91 serve_fuchsia_time_alarms: fidl_config.serve_fuchsia_time_alarms,
92 serve_fuchsia_time_external_adjust: fidl_config.serve_fuchsia_time_external_adjust,
93 serve_test_protocols: fidl_config.serve_test_protocols,
94 use_connectivity: fidl_config.use_connectivity,
95 utc_max_allowed_delta_future_sec: fidl_config.utc_max_allowed_delta_future_sec,
96 utc_max_allowed_delta_past_sec: fidl_config.utc_max_allowed_delta_past_sec,
97 utc_start_at_startup: fidl_config.utc_start_at_startup,
98 utc_start_at_startup_when_invalid_rtc: fidl_config
99 .utc_start_at_startup_when_invalid_rtc,
100 })
101 }
102 fn record_inspect(&self, inspector_node: &Node) {
103 inspector_node.record_int(
104 "back_off_time_between_pull_samples_sec",
105 self.back_off_time_between_pull_samples_sec,
106 );
107 inspector_node.record_bool("disable_delays", self.disable_delays);
108 inspector_node.record_bool("early_exit", self.early_exit);
109 inspector_node.record_int("first_sampling_delay_sec", self.first_sampling_delay_sec);
110 inspector_node.record_bool("has_always_on_counter", self.has_always_on_counter);
111 inspector_node.record_bool("has_real_time_clock", self.has_real_time_clock);
112 inspector_node.record_uint("initial_frequency_ppm", self.initial_frequency_ppm as u64);
113 inspector_node.record_uint("max_frequency_error_ppm", self.max_frequency_error_ppm as u64);
114 inspector_node.record_uint(
115 "min_utc_reference_to_backstop_diff_minutes",
116 self.min_utc_reference_to_backstop_diff_minutes,
117 );
118 inspector_node.record_string("monitor_time_source_url", &self.monitor_time_source_url);
119 inspector_node.record_bool("monitor_uses_pull", self.monitor_uses_pull);
120 inspector_node
121 .record_uint("oscillator_error_std_dev_ppm", self.oscillator_error_std_dev_ppm as u64);
122 inspector_node.record_bool(
123 "power_topology_integration_enabled",
124 self.power_topology_integration_enabled,
125 );
126 inspector_node.record_string("primary_time_source_url", &self.primary_time_source_url);
127 inspector_node.record_bool("primary_uses_pull", self.primary_uses_pull);
128 inspector_node.record_bool("serve_fuchsia_time_alarms", self.serve_fuchsia_time_alarms);
129 inspector_node.record_bool(
130 "serve_fuchsia_time_external_adjust",
131 self.serve_fuchsia_time_external_adjust,
132 );
133 inspector_node.record_bool("serve_test_protocols", self.serve_test_protocols);
134 inspector_node.record_bool("use_connectivity", self.use_connectivity);
135 inspector_node
136 .record_int("utc_max_allowed_delta_future_sec", self.utc_max_allowed_delta_future_sec);
137 inspector_node
138 .record_int("utc_max_allowed_delta_past_sec", self.utc_max_allowed_delta_past_sec);
139 inspector_node.record_bool("utc_start_at_startup", self.utc_start_at_startup);
140 inspector_node.record_bool(
141 "utc_start_at_startup_when_invalid_rtc",
142 self.utc_start_at_startup_when_invalid_rtc,
143 );
144 }
145}