settings/
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
5use crate::agent::AgentCreator;
6use settings_common::config::AgentType;
7
8#[macro_export]
9macro_rules! create_agent {
10    ($component:ident, $create:expr) => {
11        AgentCreator {
12            debug_id: concat!(stringify!($component), "_agent"),
13            create: $crate::agent::CreationFunc::Static(|c| Box::pin($create(c))),
14        }
15    };
16}
17
18impl AgentCreator {
19    pub(crate) fn from_type(agent_type: AgentType) -> Option<AgentCreator> {
20        use crate::agent::*;
21        Some(match agent_type {
22            AgentType::CameraWatcher => {
23                create_agent!(camera_watcher, camera_watcher::CameraWatcherAgent::create)
24            }
25            AgentType::Earcons => create_agent!(earcons, earcons::agent::Agent::create),
26            AgentType::MediaButtons
27            | AgentType::InspectSettingValues
28            | AgentType::InspectExternalApis
29            | AgentType::InspectSettingProxy
30            | AgentType::InspectSettingTypeUsage => {
31                // Moved to lib.rs
32                return None;
33            }
34            AgentType::Restore => create_agent!(restore_agent, restore_agent::RestoreAgent::create),
35        })
36    }
37}