sl4f_lib/wpan/
commands.rs1use crate::server::Facade;
6use crate::wpan::facade::WpanFacade;
7use crate::wpan::types::WpanMethod;
8use anyhow::Error;
9use async_trait::async_trait;
10use serde_json::{from_value, to_value, Value};
11
12#[async_trait(?Send)]
13impl Facade for WpanFacade {
14 async fn handle_request(&self, method: String, _args: Value) -> Result<Value, Error> {
15 Ok(match method.parse()? {
16 WpanMethod::GetIsCommissioned => to_value(self.get_is_commissioned().await?),
17 WpanMethod::GetMacAddressFilterSettings => {
18 to_value(self.get_mac_address_filter_settings().await?)
19 }
20 WpanMethod::GetNcpChannel => to_value(self.get_ncp_channel().await?),
21 WpanMethod::GetNcpMacAddress => to_value(self.get_ncp_mac_address().await?),
22 WpanMethod::GetNcpRssi => to_value(self.get_ncp_rssi().await?),
23 WpanMethod::GetNcpDeviceState => to_value(self.get_ncp_device_state().await?),
24 WpanMethod::GetNcpState => to_value(self.get_ncp_state().await?),
25 WpanMethod::GetNetworkName => to_value(self.get_network_name().await?),
26 WpanMethod::GetNeighborTable => to_value(self.get_neighbor_table().await?),
27 WpanMethod::GetPanId => to_value(self.get_panid().await?),
28 WpanMethod::GetPartitionId => to_value(self.get_partition_id().await?),
29 WpanMethod::GetThreadRloc16 => to_value(self.get_thread_rloc16().await?),
30 WpanMethod::GetThreadRouterId => to_value(self.get_thread_router_id().await?),
31 WpanMethod::GetWeaveNodeId => to_value(self.get_weave_node_id().await?),
32 WpanMethod::InitializeProxies => to_value(self.initialize_proxies().await?),
33 WpanMethod::ReplaceMacAddressFilterSettings => to_value(
34 self.replace_mac_address_filter_settings(match from_value(_args.clone()) {
35 Ok(settings) => settings,
36 _ => bail!(
37 "Invalid json argument to ReplaceMacAddressFilterSettings! - {}",
38 _args
39 ),
40 })
41 .await?,
42 ),
43 }?)
44 }
45}