sl4f_lib/wlan_deprecated/
facade.rsuse anyhow::{format_err, Error};
use fidl_fuchsia_wlan_product_deprecatedconfiguration as fidl_deprecated;
use fuchsia_component::client::connect_to_protocol;
use fuchsia_sync::RwLock;
use std::fmt::Debug;
#[derive(Debug)]
struct InnerWlanDeprecatedConfigurationFacade {
controller: fidl_deprecated::DeprecatedConfiguratorProxy,
}
#[derive(Debug)]
pub struct WlanDeprecatedConfigurationFacade {
inner: RwLock<InnerWlanDeprecatedConfigurationFacade>,
}
impl WlanDeprecatedConfigurationFacade {
pub fn new() -> Result<WlanDeprecatedConfigurationFacade, Error> {
let controller = connect_to_protocol::<fidl_deprecated::DeprecatedConfiguratorMarker>()?;
Ok(Self {
inner: RwLock::new(InnerWlanDeprecatedConfigurationFacade { controller: controller }),
})
}
pub async fn suggest_access_point_mac_address(
&self,
mac: eui48::MacAddress,
) -> Result<(), Error> {
let inner_guard = self.inner.read();
let controller = &inner_guard.controller;
let mac = fidl_fuchsia_net::MacAddress { octets: mac.to_array() };
let result = controller.suggest_access_point_mac_address(&mac).await?;
result.map_err(|e| format_err!("could not set preferred MAC: {:?}", e))
}
pub fn parse_mac_argument(&self, args: serde_json::Value) -> Result<eui48::MacAddress, Error> {
let mac = match args.get("mac") {
Some(mac) => match mac.as_str() {
Some(mac) => eui48::MacAddress::parse_str(mac)?,
None => {
return Err(format_err!(
"MAC address could not be interpreted as a string: {:?}",
mac
))
}
},
None => return Err(format_err!("Please provide a preferred MAC")),
};
Ok(mac)
}
}