Skip to main content

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    0x59, 0x1f, 0x9a, 0x4e, 0xc6, 0xf3, 0xaf, 0x21, 0xd5, 0x7d, 0x97, 0xc8, 0x2b, 0xc1, 0x71, 0x4c,
8    0xe8, 0x66, 0x11, 0xdf, 0x72, 0xe9, 0xd0, 0xdf, 0xc5, 0xac, 0x05, 0xdb, 0x37, 0xce, 0x07, 0xef,
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_merge_touch_events: bool,
17    pub enable_mouse_baton_passing: bool,
18    pub enable_touch_baton_passing: bool,
19    pub idle_threshold_ms: u64,
20    pub supported_input_devices: Vec<String>,
21    pub suspend_enabled: bool,
22    pub viewing_distance: String,
23}
24impl Config {
25    #[doc = r" Take the config startup handle and parse its contents."]
26    #[doc = r""]
27    #[doc = r" # Panics"]
28    #[doc = r""]
29    #[doc = r" If the config startup handle was already taken or if it is not valid."]
30    pub fn take_from_startup_handle() -> Self {
31        <Self as ComponentConfig>::take_from_startup_handle()
32    }
33    #[doc = r" Parse `Self` from `vmo`."]
34    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
35        <Self as ComponentConfig>::from_vmo(vmo)
36    }
37    #[doc = r" Parse `Self` from `bytes`."]
38    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
39        <Self as ComponentConfig>::from_bytes(bytes)
40    }
41    pub fn record_inspect(&self, inspector_node: &Node) {
42        <Self as ComponentConfig>::record_inspect(self, inspector_node)
43    }
44}
45impl ComponentConfig for Config {
46    #[doc = r" Parse `Self` from `bytes`."]
47    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
48        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
49        let checksum_len_bytes: [u8; 2] =
50            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
51        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
52        let (observed_checksum, bytes) =
53            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
54        if observed_checksum != EXPECTED_CHECKSUM {
55            return Err(Error::ChecksumMismatch {
56                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
57                observed_checksum: observed_checksum.to_vec(),
58            });
59        }
60        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
61        Ok(Self {
62            attach_a11y_view: fidl_config.attach_a11y_view,
63            display_pixel_density: fidl_config.display_pixel_density,
64            display_rotation: fidl_config.display_rotation,
65            enable_button_baton_passing: fidl_config.enable_button_baton_passing,
66            enable_merge_touch_events: fidl_config.enable_merge_touch_events,
67            enable_mouse_baton_passing: fidl_config.enable_mouse_baton_passing,
68            enable_touch_baton_passing: fidl_config.enable_touch_baton_passing,
69            idle_threshold_ms: fidl_config.idle_threshold_ms,
70            supported_input_devices: fidl_config.supported_input_devices,
71            suspend_enabled: fidl_config.suspend_enabled,
72            viewing_distance: fidl_config.viewing_distance,
73        })
74    }
75    fn record_inspect(&self, inspector_node: &Node) {
76        inspector_node.record_bool("attach_a11y_view", self.attach_a11y_view);
77        inspector_node.record_string("display_pixel_density", &self.display_pixel_density);
78        inspector_node.record_uint("display_rotation", self.display_rotation);
79        inspector_node.record_bool("enable_button_baton_passing", self.enable_button_baton_passing);
80        inspector_node.record_bool("enable_merge_touch_events", self.enable_merge_touch_events);
81        inspector_node.record_bool("enable_mouse_baton_passing", self.enable_mouse_baton_passing);
82        inspector_node.record_bool("enable_touch_baton_passing", self.enable_touch_baton_passing);
83        inspector_node.record_uint("idle_threshold_ms", self.idle_threshold_ms);
84        let arr = inspector_node
85            .create_string_array("supported_input_devices", self.supported_input_devices.len());
86        for i in 0..self.supported_input_devices.len() {
87            arr.set(i, &self.supported_input_devices[i]);
88        }
89        inspector_node.record(arr);
90        inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
91        inspector_node.record_string("viewing_distance", &self.viewing_distance);
92    }
93}