settings/input/
input_device_configuration.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::config::default_settings::DefaultSetting;
use crate::input::types::{DeviceStateSource, InputDeviceType};
use crate::inspect::config_logger::InspectConfigLogger;
use serde::Deserialize;
use std::rc::Rc;
use std::sync::Mutex;

#[derive(PartialEq, Debug, Default, Clone, Deserialize)]
pub struct InputConfiguration {
    /// List of input devices that are present on this product.
    pub devices: Vec<InputDeviceConfiguration>,
}

#[derive(PartialEq, Debug, Clone, Deserialize)]
pub struct InputDeviceConfiguration {
    /// Name of the device.
    ///
    /// Must be unique per device type. Can be empty if there is only one
    /// input device of this type.
    pub device_name: String,

    /// The type of input device, e.g. MICROPHONE.
    pub device_type: InputDeviceType,

    /// The sources (e.g. HARDWARE) with their corresponding states.
    pub source_states: Vec<SourceState>,

    /// The number representing the states that are toggleable by a client.
    /// This is the sum of the bitflags that are set.
    pub mutable_toggle_state: u64,
}

#[derive(PartialEq, Debug, Clone, Deserialize)]
pub struct SourceState {
    /// The source, e.g. HARDWARE.
    pub source: DeviceStateSource,

    /// The number representing the state for the source. This is the sum of
    /// the bitflags that are set.
    pub state: u64,
}
pub fn build_input_default_settings(
    config_logger: Rc<Mutex<InspectConfigLogger>>,
) -> DefaultSetting<InputConfiguration, &'static str> {
    DefaultSetting::new(
        Some(InputConfiguration::default()),
        "/config/data/input_device_config.json",
        config_logger,
    )
}