sl4f_lib/hardware_power_statecontrol/
commands.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::server::Facade;
6use anyhow::Error;
7use async_trait::async_trait;
8use serde_json::{to_value, Value};
9
10use crate::hardware_power_statecontrol::facade::HardwarePowerStatecontrolFacade;
11
12#[async_trait(?Send)]
13impl Facade for HardwarePowerStatecontrolFacade {
14    async fn handle_request(&self, method: String, _args: Value) -> Result<Value, Error> {
15        match method.as_ref() {
16            "SuspendReboot" => {
17                let result = self.suspend_reboot().await?;
18                Ok(to_value(result)?)
19            }
20            "SuspendRebootBootloader" => {
21                let result = self.suspend_reboot_bootloader().await?;
22                Ok(to_value(result)?)
23            }
24            "SuspendRebootRecovery" => {
25                let result = self.suspend_reboot_recovery().await?;
26                Ok(to_value(result)?)
27            }
28            "SuspendPoweroff" => {
29                let result = self.suspend_poweroff().await?;
30                Ok(to_value(result)?)
31            }
32            "SuspendMexec" => {
33                let result = self.suspend_mexec().await?;
34                Ok(to_value(result)?)
35            }
36            "SuspendRam" => {
37                let result = self.suspend_ram().await?;
38                Ok(to_value(result)?)
39            }
40            _ => bail!("Invalid HardwarePowerStatecontrolFacade FIDL method: {:?}", method),
41        }
42    }
43}