scene_manager_structured_config/
scene_manager_structured_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_scenemanagerstructuredconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0xd6, 0x3f, 0xd9, 0xd2, 0xa2, 0xad, 0xbe, 0xae, 0x1b, 0x12, 0x7e, 0x99, 0x4e, 0x10, 0x4a, 0x4f,
8    0xcf, 0x6f, 0x18, 0x72, 0xe4, 0x65, 0x27, 0x3f, 0x65, 0x8a, 0x73, 0xb3, 0x70, 0xbf, 0x77, 0xd2,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub attach_a11y_view: bool,
13    pub display_pixel_density: String,
14    pub display_rotation: u64,
15    pub enable_button_baton_passing: bool,
16    pub enable_mouse_baton_passing: bool,
17    pub enable_touch_baton_passing: bool,
18    pub idle_threshold_ms: u64,
19    pub supported_input_devices: Vec<String>,
20    pub suspend_enabled: bool,
21    pub viewing_distance: String,
22}
23impl Config {
24    #[doc = r" Take the config startup handle and parse its contents."]
25    #[doc = r""]
26    #[doc = r" # Panics"]
27    #[doc = r""]
28    #[doc = r" If the config startup handle was already taken or if it is not valid."]
29    pub fn take_from_startup_handle() -> Self {
30        <Self as ComponentConfig>::take_from_startup_handle()
31    }
32    #[doc = r" Parse `Self` from `vmo`."]
33    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
34        <Self as ComponentConfig>::from_vmo(vmo)
35    }
36    #[doc = r" Parse `Self` from `bytes`."]
37    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
38        <Self as ComponentConfig>::from_bytes(bytes)
39    }
40    pub fn record_inspect(&self, inspector_node: &Node) {
41        <Self as ComponentConfig>::record_inspect(self, inspector_node)
42    }
43}
44impl ComponentConfig for Config {
45    #[doc = r" Parse `Self` from `bytes`."]
46    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
47        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
48        let checksum_len_bytes: [u8; 2] =
49            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
50        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
51        let (observed_checksum, bytes) =
52            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
53        if observed_checksum != EXPECTED_CHECKSUM {
54            return Err(Error::ChecksumMismatch {
55                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
56                observed_checksum: observed_checksum.to_vec(),
57            });
58        }
59        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
60        Ok(Self {
61            attach_a11y_view: fidl_config.attach_a11y_view,
62            display_pixel_density: fidl_config.display_pixel_density,
63            display_rotation: fidl_config.display_rotation,
64            enable_button_baton_passing: fidl_config.enable_button_baton_passing,
65            enable_mouse_baton_passing: fidl_config.enable_mouse_baton_passing,
66            enable_touch_baton_passing: fidl_config.enable_touch_baton_passing,
67            idle_threshold_ms: fidl_config.idle_threshold_ms,
68            supported_input_devices: fidl_config.supported_input_devices,
69            suspend_enabled: fidl_config.suspend_enabled,
70            viewing_distance: fidl_config.viewing_distance,
71        })
72    }
73    fn record_inspect(&self, inspector_node: &Node) {
74        inspector_node.record_bool("attach_a11y_view", self.attach_a11y_view);
75        inspector_node.record_string("display_pixel_density", &self.display_pixel_density);
76        inspector_node.record_uint("display_rotation", self.display_rotation);
77        inspector_node.record_bool("enable_button_baton_passing", self.enable_button_baton_passing);
78        inspector_node.record_bool("enable_mouse_baton_passing", self.enable_mouse_baton_passing);
79        inspector_node.record_bool("enable_touch_baton_passing", self.enable_touch_baton_passing);
80        inspector_node.record_uint("idle_threshold_ms", self.idle_threshold_ms);
81        let arr = inspector_node
82            .create_string_array("supported_input_devices", self.supported_input_devices.len());
83        for i in 0..self.supported_input_devices.len() {
84            arr.set(i, &self.supported_input_devices[i]);
85        }
86        inspector_node.record(arr);
87        inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
88        inspector_node.record_string("viewing_distance", &self.viewing_distance);
89    }
90}