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.
45use crate::server::Facade;
6use crate::wlan_phy::facade::WlanPhyFacade;
7use anyhow::{format_err, Error};
8use async_trait::async_trait;
9use serde_json::{to_value, Value};
1011#[async_trait(?Send)]
12impl Facade for WlanPhyFacade {
13async fn handle_request(&self, method: String, args: Value) -> Result<Value, Error> {
14match method.as_ref() {
15"get_country" => {
16let phy_id =
17 args.get("phy_id").ok_or_else(|| format_err!("Must provide a `phy_id`"))?;
18let phy_id: u16 = phy_id
19 .as_u64()
20 .ok_or_else(|| format_err!("`phy_id` must be a number, but was {:?}", phy_id))?
21.try_into()
22 .or_else(|_err| {
23Err(format_err!("`phy_id` must fit u16, but was {:?}", phy_id))
24 })?;
25Ok(to_value(self.get_country(phy_id).await?)?)
26 }
27"get_dev_path" => {
28let phy_id =
29 args.get("phy_id").ok_or_else(|| format_err!("Must provide a `phy_id`"))?;
30let phy_id: u16 = phy_id
31 .as_u64()
32 .ok_or_else(|| format_err!("`phy_id` must be a number, but was {:?}", phy_id))?
33.try_into()
34 .or_else(|_err| {
35Err(format_err!("`phy_id` must fit u16, but was {:?}", phy_id))
36 })?;
37Ok(to_value(self.get_dev_path(phy_id).await?)?)
38 }
39_ => return Err(format_err!("unsupported command {} for wlan-phy-facade!", method)),
40 }
41 }
42}