settings/input/
input_device_configuration.rs

1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::config::default_settings::DefaultSetting;
6use crate::input::types::{DeviceStateSource, InputDeviceType};
7use crate::inspect::config_logger::InspectConfigLogger;
8use serde::Deserialize;
9use std::rc::Rc;
10use std::sync::Mutex;
11
12#[derive(PartialEq, Debug, Default, Clone, Deserialize)]
13pub struct InputConfiguration {
14    /// List of input devices that are present on this product.
15    pub devices: Vec<InputDeviceConfiguration>,
16}
17
18#[derive(PartialEq, Debug, Clone, Deserialize)]
19pub struct InputDeviceConfiguration {
20    /// Name of the device.
21    ///
22    /// Must be unique per device type. Can be empty if there is only one
23    /// input device of this type.
24    pub device_name: String,
25
26    /// The type of input device, e.g. MICROPHONE.
27    pub device_type: InputDeviceType,
28
29    /// The sources (e.g. HARDWARE) with their corresponding states.
30    pub source_states: Vec<SourceState>,
31
32    /// The number representing the states that are toggleable by a client.
33    /// This is the sum of the bitflags that are set.
34    pub mutable_toggle_state: u64,
35}
36
37#[derive(PartialEq, Debug, Clone, Deserialize)]
38pub struct SourceState {
39    /// The source, e.g. HARDWARE.
40    pub source: DeviceStateSource,
41
42    /// The number representing the state for the source. This is the sum of
43    /// the bitflags that are set.
44    pub state: u64,
45}
46pub fn build_input_default_settings(
47    config_logger: Rc<Mutex<InspectConfigLogger>>,
48) -> DefaultSetting<InputConfiguration, &'static str> {
49    DefaultSetting::new(
50        Some(InputConfiguration::default()),
51        "/config/data/input_device_config.json",
52        config_logger,
53    )
54}