blob: ca93e39287cae648397d7907def0a3c1083b721c [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::{server::Facade, wlan_phy::facade::WlanPhyFacade};
use anyhow::{format_err, Error};
use async_trait::async_trait;
use serde_json::{to_value, Value};
#[async_trait(?Send)]
impl Facade for WlanPhyFacade {
async fn handle_request(&self, method: String, args: Value) -> Result<Value, Error> {
match method.as_ref() {
"get_country" => {
let phy_id =
args.get("phy_id").ok_or_else(|| format_err!("Must provide a `phy_id`"))?;
let phy_id: u16 = phy_id
.as_u64()
.ok_or_else(|| format_err!("`phy_id` must be a number, but was {:?}", phy_id))?
.try_into()
.or_else(|_err| {
Err(format_err!("`phy_id` must fit u16, but was {:?}", phy_id))
})?;
Ok(to_value(self.get_country(phy_id).await?)?)
}
"get_dev_path" => {
let phy_id =
args.get("phy_id").ok_or_else(|| format_err!("Must provide a `phy_id`"))?;
let phy_id: u16 = phy_id
.as_u64()
.ok_or_else(|| format_err!("`phy_id` must be a number, but was {:?}", phy_id))?
.try_into()
.or_else(|_err| {
Err(format_err!("`phy_id` must fit u16, but was {:?}", phy_id))
})?;
Ok(to_value(self.get_dev_path(phy_id).await?)?)
}
_ => return Err(format_err!("unsupported command {} for wlan-phy-facade!", method)),
}
}
}