settings_common/
config.rs

1// Copyright 2019 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
5pub mod default_settings;
6
7use serde::{Deserialize, Serialize};
8use std::collections::HashSet;
9
10/// The flags used to control behavior of controllers.
11#[derive(PartialEq, Debug, Eq, Hash, Copy, Clone, Serialize, Deserialize)]
12pub enum ControllerFlag {
13    /// This flag controls whether an external service is in control of the
14    /// brightness configuration.
15    ExternalBrightnessControl,
16}
17
18#[derive(Clone, Debug, PartialEq)]
19pub enum Event {
20    /// A load of a config file with the given information about the load.
21    Load(ConfigLoadInfo),
22}
23
24#[derive(Clone, Debug, PartialEq)]
25pub struct ConfigLoadInfo {
26    /// The status of the load.
27    pub status: ConfigLoadStatus,
28    /// The contents of the loaded config file.
29    pub contents: Option<String>,
30}
31
32#[derive(Clone, Debug, PartialEq)]
33pub enum ConfigLoadStatus {
34    /// Failed to parse the file.
35    ParseFailure(String),
36    /// Successfully loaded the file.
37    Success,
38    /// Falling back to default.
39    UsingDefaults(String),
40}
41
42impl From<ConfigLoadStatus> for String {
43    fn from(status: ConfigLoadStatus) -> String {
44        match status {
45            ConfigLoadStatus::ParseFailure(_) => "ParseFailure".to_string(),
46            ConfigLoadStatus::Success => "Success".to_string(),
47            ConfigLoadStatus::UsingDefaults(_) => "UsingDefaults".to_string(),
48        }
49    }
50}
51
52/// Represents each agent that can be run.
53#[derive(Eq, PartialEq, Hash, Debug, Copy, Clone, Deserialize)]
54pub enum AgentType {
55    /// Responsible for watching the camera3 mute status. If other clients
56    /// of the camera3 api modify the camera state, the agent should watch and
57    /// should coordinate that change with the internal camera state.
58    CameraWatcher,
59    /// Plays earcons in response to certain events. If MediaButtons is
60    /// enabled, then it will also handle some media buttons events.
61    Earcons,
62    /// Responsible for managing the connection to media buttons. It will
63    /// broadcast events to the controllers and agents.
64    MediaButtons,
65    /// Responsible for initializing all of the controllers.
66    Restore,
67    /// Responsible for logging external API calls to other components and
68    /// their responses to Inspect.
69    InspectExternalApis,
70    /// Responsible for logging all settings values of messages between the
71    /// proxy and setting handlers to Inspect.
72    InspectSettingProxy,
73    /// Responsible for logging the setting values in the setting proxy to Inspect.
74    InspectSettingValues,
75    /// Responsible for logging API usage counts to Inspect.
76    InspectSettingTypeUsage,
77}
78
79pub fn get_default_agent_types() -> HashSet<AgentType> {
80    [
81        AgentType::Restore,
82        AgentType::InspectExternalApis,
83        AgentType::InspectSettingProxy,
84        AgentType::InspectSettingValues,
85        AgentType::InspectSettingTypeUsage,
86    ]
87    .into_iter()
88    .collect()
89}