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 0xe8, 0x9f, 0x33, 0xb1, 0xa2, 0x64, 0x79, 0x4f, 0xe3, 0x55, 0xa7, 0x59, 0xb0, 0xd5, 0x2d, 0xf1,
8 0x26, 0x1b, 0x8b, 0xfa, 0x68, 0x2b, 0x6a, 0x4c, 0x13, 0x24, 0xf0, 0xf9, 0x04, 0x85, 0x58, 0x13,
9];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13 pub back_off_time_between_pull_samples_sec: i64,
14 pub disable_delays: bool,
15 pub early_exit: bool,
16 pub first_sampling_delay_sec: i64,
17 pub has_always_on_counter: bool,
18 pub has_real_time_clock: bool,
19 pub initial_frequency_ppm: u32,
20 pub max_frequency_error_ppm: u32,
21 pub min_acceptable_boot_time_for_utc_update_minutes: u64,
22 pub min_utc_reference_to_backstop_diff_minutes: u64,
23 pub monitor_time_source_url: String,
24 pub monitor_uses_pull: bool,
25 pub oscillator_error_std_dev_ppm: u32,
26 pub periodic_rtc_update_interval_minutes: u32,
27 pub power_topology_integration_enabled: bool,
28 pub primary_time_source_url: String,
29 pub primary_uses_pull: bool,
30 pub rtc_allow_setting_past_utc: String,
31 pub serve_fuchsia_time_alarms: bool,
32 pub serve_fuchsia_time_external_adjust: bool,
33 pub serve_test_protocols: bool,
34 pub use_connectivity: bool,
35 pub utc_max_allowed_delta_future_sec: i64,
36 pub utc_max_allowed_delta_past_sec: i64,
37 pub utc_start_at_startup: bool,
38 pub utc_start_at_startup_when_invalid_rtc: bool,
39}
40impl Config {
41 #[doc = r" Take the config startup handle and parse its contents."]
42 #[doc = r""]
43 #[doc = r" # Panics"]
44 #[doc = r""]
45 #[doc = r" If the config startup handle was already taken or if it is not valid."]
46 pub fn take_from_startup_handle() -> Self {
47 <Self as ComponentConfig>::take_from_startup_handle()
48 }
49 #[doc = r" Parse `Self` from `vmo`."]
50 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
51 <Self as ComponentConfig>::from_vmo(vmo)
52 }
53 #[doc = r" Parse `Self` from `bytes`."]
54 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
55 <Self as ComponentConfig>::from_bytes(bytes)
56 }
57 pub fn record_inspect(&self, inspector_node: &Node) {
58 <Self as ComponentConfig>::record_inspect(self, inspector_node)
59 }
60}
61impl ComponentConfig for Config {
62 #[doc = r" Parse `Self` from `bytes`."]
63 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
64 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
65 let checksum_len_bytes: [u8; 2] =
66 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
67 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
68 let (observed_checksum, bytes) =
69 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
70 if observed_checksum != EXPECTED_CHECKSUM {
71 return Err(Error::ChecksumMismatch {
72 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
73 observed_checksum: observed_checksum.to_vec(),
74 });
75 }
76 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
77 Ok(Self {
78 back_off_time_between_pull_samples_sec: fidl_config
79 .back_off_time_between_pull_samples_sec,
80 disable_delays: fidl_config.disable_delays,
81 early_exit: fidl_config.early_exit,
82 first_sampling_delay_sec: fidl_config.first_sampling_delay_sec,
83 has_always_on_counter: fidl_config.has_always_on_counter,
84 has_real_time_clock: fidl_config.has_real_time_clock,
85 initial_frequency_ppm: fidl_config.initial_frequency_ppm,
86 max_frequency_error_ppm: fidl_config.max_frequency_error_ppm,
87 min_acceptable_boot_time_for_utc_update_minutes: fidl_config
88 .min_acceptable_boot_time_for_utc_update_minutes,
89 min_utc_reference_to_backstop_diff_minutes: fidl_config
90 .min_utc_reference_to_backstop_diff_minutes,
91 monitor_time_source_url: fidl_config.monitor_time_source_url,
92 monitor_uses_pull: fidl_config.monitor_uses_pull,
93 oscillator_error_std_dev_ppm: fidl_config.oscillator_error_std_dev_ppm,
94 periodic_rtc_update_interval_minutes: fidl_config.periodic_rtc_update_interval_minutes,
95 power_topology_integration_enabled: fidl_config.power_topology_integration_enabled,
96 primary_time_source_url: fidl_config.primary_time_source_url,
97 primary_uses_pull: fidl_config.primary_uses_pull,
98 rtc_allow_setting_past_utc: fidl_config.rtc_allow_setting_past_utc,
99 serve_fuchsia_time_alarms: fidl_config.serve_fuchsia_time_alarms,
100 serve_fuchsia_time_external_adjust: fidl_config.serve_fuchsia_time_external_adjust,
101 serve_test_protocols: fidl_config.serve_test_protocols,
102 use_connectivity: fidl_config.use_connectivity,
103 utc_max_allowed_delta_future_sec: fidl_config.utc_max_allowed_delta_future_sec,
104 utc_max_allowed_delta_past_sec: fidl_config.utc_max_allowed_delta_past_sec,
105 utc_start_at_startup: fidl_config.utc_start_at_startup,
106 utc_start_at_startup_when_invalid_rtc: fidl_config
107 .utc_start_at_startup_when_invalid_rtc,
108 })
109 }
110 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
111 let fidl_config = FidlConfig {
112 back_off_time_between_pull_samples_sec: self
113 .back_off_time_between_pull_samples_sec
114 .clone(),
115 disable_delays: self.disable_delays.clone(),
116 early_exit: self.early_exit.clone(),
117 first_sampling_delay_sec: self.first_sampling_delay_sec.clone(),
118 has_always_on_counter: self.has_always_on_counter.clone(),
119 has_real_time_clock: self.has_real_time_clock.clone(),
120 initial_frequency_ppm: self.initial_frequency_ppm.clone(),
121 max_frequency_error_ppm: self.max_frequency_error_ppm.clone(),
122 min_acceptable_boot_time_for_utc_update_minutes: self
123 .min_acceptable_boot_time_for_utc_update_minutes
124 .clone(),
125 min_utc_reference_to_backstop_diff_minutes: self
126 .min_utc_reference_to_backstop_diff_minutes
127 .clone(),
128 monitor_time_source_url: self.monitor_time_source_url.clone(),
129 monitor_uses_pull: self.monitor_uses_pull.clone(),
130 oscillator_error_std_dev_ppm: self.oscillator_error_std_dev_ppm.clone(),
131 periodic_rtc_update_interval_minutes: self.periodic_rtc_update_interval_minutes.clone(),
132 power_topology_integration_enabled: self.power_topology_integration_enabled.clone(),
133 primary_time_source_url: self.primary_time_source_url.clone(),
134 primary_uses_pull: self.primary_uses_pull.clone(),
135 rtc_allow_setting_past_utc: self.rtc_allow_setting_past_utc.clone(),
136 serve_fuchsia_time_alarms: self.serve_fuchsia_time_alarms.clone(),
137 serve_fuchsia_time_external_adjust: self.serve_fuchsia_time_external_adjust.clone(),
138 serve_test_protocols: self.serve_test_protocols.clone(),
139 use_connectivity: self.use_connectivity.clone(),
140 utc_max_allowed_delta_future_sec: self.utc_max_allowed_delta_future_sec.clone(),
141 utc_max_allowed_delta_past_sec: self.utc_max_allowed_delta_past_sec.clone(),
142 utc_start_at_startup: self.utc_start_at_startup.clone(),
143 utc_start_at_startup_when_invalid_rtc: self
144 .utc_start_at_startup_when_invalid_rtc
145 .clone(),
146 };
147 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
148 let mut bytes = Vec::with_capacity(
149 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
150 );
151 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
152 bytes.extend_from_slice(EXPECTED_CHECKSUM);
153 bytes.append(&mut fidl_bytes);
154 Ok(bytes)
155 }
156 fn record_inspect(&self, inspector_node: &Node) {
157 inspector_node.record_int(
158 "back_off_time_between_pull_samples_sec",
159 self.back_off_time_between_pull_samples_sec,
160 );
161 inspector_node.record_bool("disable_delays", self.disable_delays);
162 inspector_node.record_bool("early_exit", self.early_exit);
163 inspector_node.record_int("first_sampling_delay_sec", self.first_sampling_delay_sec);
164 inspector_node.record_bool("has_always_on_counter", self.has_always_on_counter);
165 inspector_node.record_bool("has_real_time_clock", self.has_real_time_clock);
166 inspector_node.record_uint("initial_frequency_ppm", self.initial_frequency_ppm as u64);
167 inspector_node.record_uint("max_frequency_error_ppm", self.max_frequency_error_ppm as u64);
168 inspector_node.record_uint(
169 "min_acceptable_boot_time_for_utc_update_minutes",
170 self.min_acceptable_boot_time_for_utc_update_minutes,
171 );
172 inspector_node.record_uint(
173 "min_utc_reference_to_backstop_diff_minutes",
174 self.min_utc_reference_to_backstop_diff_minutes,
175 );
176 inspector_node.record_string("monitor_time_source_url", &self.monitor_time_source_url);
177 inspector_node.record_bool("monitor_uses_pull", self.monitor_uses_pull);
178 inspector_node
179 .record_uint("oscillator_error_std_dev_ppm", self.oscillator_error_std_dev_ppm as u64);
180 inspector_node.record_uint(
181 "periodic_rtc_update_interval_minutes",
182 self.periodic_rtc_update_interval_minutes as u64,
183 );
184 inspector_node.record_bool(
185 "power_topology_integration_enabled",
186 self.power_topology_integration_enabled,
187 );
188 inspector_node.record_string("primary_time_source_url", &self.primary_time_source_url);
189 inspector_node.record_bool("primary_uses_pull", self.primary_uses_pull);
190 inspector_node
191 .record_string("rtc_allow_setting_past_utc", &self.rtc_allow_setting_past_utc);
192 inspector_node.record_bool("serve_fuchsia_time_alarms", self.serve_fuchsia_time_alarms);
193 inspector_node.record_bool(
194 "serve_fuchsia_time_external_adjust",
195 self.serve_fuchsia_time_external_adjust,
196 );
197 inspector_node.record_bool("serve_test_protocols", self.serve_test_protocols);
198 inspector_node.record_bool("use_connectivity", self.use_connectivity);
199 inspector_node
200 .record_int("utc_max_allowed_delta_future_sec", self.utc_max_allowed_delta_future_sec);
201 inspector_node
202 .record_int("utc_max_allowed_delta_past_sec", self.utc_max_allowed_delta_past_sec);
203 inspector_node.record_bool("utc_start_at_startup", self.utc_start_at_startup);
204 inspector_node.record_bool(
205 "utc_start_at_startup_when_invalid_rtc",
206 self.utc_start_at_startup_when_invalid_rtc,
207 );
208 }
209}