1use crate::agent::AgentCreator;
6use serde::{Deserialize, Serialize};
7use std::collections::HashSet;
8
9#[derive(PartialEq, Debug, Eq, Hash, Copy, Clone, Serialize, Deserialize)]
11pub enum ControllerFlag {
12 ExternalBrightnessControl,
15}
16
17#[derive(Clone, Debug, PartialEq)]
18pub enum Event {
19 Load(ConfigLoadInfo),
21}
22
23#[derive(Clone, Debug, PartialEq)]
24pub struct ConfigLoadInfo {
25 pub status: ConfigLoadStatus,
27 pub contents: Option<String>,
29}
30
31#[derive(Clone, Debug, PartialEq)]
32pub enum ConfigLoadStatus {
33 ParseFailure(String),
35 Success,
37 UsingDefaults(String),
39}
40
41impl From<ConfigLoadStatus> for String {
42 fn from(status: ConfigLoadStatus) -> String {
43 match status {
44 ConfigLoadStatus::ParseFailure(_) => "ParseFailure".to_string(),
45 ConfigLoadStatus::Success => "Success".to_string(),
46 ConfigLoadStatus::UsingDefaults(_) => "UsingDefaults".to_string(),
47 }
48 }
49}
50
51#[derive(Eq, PartialEq, Hash, Debug, Copy, Clone, Deserialize)]
53pub enum AgentType {
54 CameraWatcher,
58 Earcons,
61 MediaButtons,
64 Restore,
66 InspectExternalApis,
69 InspectSettingProxy,
72 InspectSettingValues,
74 InspectSettingTypeUsage,
76}
77
78pub fn get_default_agent_types() -> HashSet<AgentType> {
79 [
80 AgentType::Restore,
81 AgentType::InspectExternalApis,
82 AgentType::InspectSettingProxy,
83 AgentType::InspectSettingValues,
84 AgentType::InspectSettingTypeUsage,
85 ]
86 .into_iter()
87 .collect()
88}
89
90#[macro_export]
91macro_rules! create_agent {
92 ($component:ident, $create:expr) => {
93 AgentCreator {
94 debug_id: concat!(stringify!($component), "_agent"),
95 create: $crate::agent::CreationFunc::Static(|c| Box::pin($create(c))),
96 }
97 };
98}
99
100impl From<AgentType> for AgentCreator {
101 fn from(agent_type: AgentType) -> AgentCreator {
102 use crate::agent::*;
103 match agent_type {
104 AgentType::CameraWatcher => {
105 create_agent!(camera_watcher, camera_watcher::CameraWatcherAgent::create)
106 }
107 AgentType::Earcons => create_agent!(earcons, earcons::agent::Agent::create),
108 AgentType::MediaButtons => {
109 create_agent!(media_buttons, media_buttons::MediaButtonsAgent::create)
110 }
111 AgentType::Restore => create_agent!(restore_agent, restore_agent::RestoreAgent::create),
112 AgentType::InspectExternalApis => create_agent!(
113 external_apis,
114 inspect::external_apis::ExternalApiInspectAgent::create
115 ),
116 AgentType::InspectSettingProxy => create_agent!(
117 setting_proxy,
118 inspect::setting_proxy::SettingProxyInspectAgent::create
119 ),
120 AgentType::InspectSettingTypeUsage => create_agent!(
121 usage_counts,
122 inspect::usage_counts::SettingTypeUsageInspectAgent::create
123 ),
124 AgentType::InspectSettingValues => create_agent!(
125 setting_values,
126 inspect::setting_values::SettingValuesInspectAgent::create
127 ),
128 }
129 }
130}