Skip to main content

driver_manager_config/
driver_manager_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_drivermanagerconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0x43, 0x72, 0x3a, 0xe4, 0xb7, 0x68, 0xac, 0xb9, 0xc7, 0xd1, 0x5c, 0xba, 0x35, 0xe4, 0x05, 0x0b,
8    0xaa, 0x1f, 0x63, 0x10, 0x8f, 0xa2, 0x5e, 0xe3, 0x75, 0xbe, 0x52, 0x93, 0x07, 0xc3, 0xe5, 0x84,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub delay_fallback_until_base_drivers_indexed: bool,
13    pub enable_test_shutdown_delays: bool,
14    pub power_inject_offer: bool,
15    pub power_suspend_enabled: bool,
16    pub root_driver: String,
17    pub set_root_driver_host_critical: bool,
18    pub suspend_timeout_fallback: bool,
19    pub wait_for_suspending_token: bool,
20}
21impl Config {
22    #[doc = r" Take the config startup handle and parse its contents."]
23    #[doc = r""]
24    #[doc = r" # Panics"]
25    #[doc = r""]
26    #[doc = r" If the config startup handle was already taken or if it is not valid."]
27    pub fn take_from_startup_handle() -> Self {
28        <Self as ComponentConfig>::take_from_startup_handle()
29    }
30    #[doc = r" Parse `Self` from `vmo`."]
31    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
32        <Self as ComponentConfig>::from_vmo(vmo)
33    }
34    #[doc = r" Parse `Self` from `bytes`."]
35    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
36        <Self as ComponentConfig>::from_bytes(bytes)
37    }
38    pub fn record_inspect(&self, inspector_node: &Node) {
39        <Self as ComponentConfig>::record_inspect(self, inspector_node)
40    }
41}
42impl ComponentConfig for Config {
43    #[doc = r" Parse `Self` from `bytes`."]
44    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
45        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
46        let checksum_len_bytes: [u8; 2] =
47            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
48        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
49        let (observed_checksum, bytes) =
50            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
51        if observed_checksum != EXPECTED_CHECKSUM {
52            return Err(Error::ChecksumMismatch {
53                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
54                observed_checksum: observed_checksum.to_vec(),
55            });
56        }
57        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
58        Ok(Self {
59            delay_fallback_until_base_drivers_indexed: fidl_config
60                .delay_fallback_until_base_drivers_indexed,
61            enable_test_shutdown_delays: fidl_config.enable_test_shutdown_delays,
62            power_inject_offer: fidl_config.power_inject_offer,
63            power_suspend_enabled: fidl_config.power_suspend_enabled,
64            root_driver: fidl_config.root_driver,
65            set_root_driver_host_critical: fidl_config.set_root_driver_host_critical,
66            suspend_timeout_fallback: fidl_config.suspend_timeout_fallback,
67            wait_for_suspending_token: fidl_config.wait_for_suspending_token,
68        })
69    }
70    fn record_inspect(&self, inspector_node: &Node) {
71        inspector_node.record_bool(
72            "delay_fallback_until_base_drivers_indexed",
73            self.delay_fallback_until_base_drivers_indexed,
74        );
75        inspector_node.record_bool("enable_test_shutdown_delays", self.enable_test_shutdown_delays);
76        inspector_node.record_bool("power_inject_offer", self.power_inject_offer);
77        inspector_node.record_bool("power_suspend_enabled", self.power_suspend_enabled);
78        inspector_node.record_string("root_driver", &self.root_driver);
79        inspector_node
80            .record_bool("set_root_driver_host_critical", self.set_root_driver_host_critical);
81        inspector_node.record_bool("suspend_timeout_fallback", self.suspend_timeout_fallback);
82        inspector_node.record_bool("wait_for_suspending_token", self.wait_for_suspending_token);
83    }
84}