sl4f_lib/wpan/
commands.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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;
use crate::wpan::facade::WpanFacade;
use crate::wpan::types::WpanMethod;
use anyhow::Error;
use async_trait::async_trait;
use serde_json::{from_value, to_value, Value};

#[async_trait(?Send)]
impl Facade for WpanFacade {
    async fn handle_request(&self, method: String, _args: Value) -> Result<Value, Error> {
        Ok(match method.parse()? {
            WpanMethod::GetIsCommissioned => to_value(self.get_is_commissioned().await?),
            WpanMethod::GetMacAddressFilterSettings => {
                to_value(self.get_mac_address_filter_settings().await?)
            }
            WpanMethod::GetNcpChannel => to_value(self.get_ncp_channel().await?),
            WpanMethod::GetNcpMacAddress => to_value(self.get_ncp_mac_address().await?),
            WpanMethod::GetNcpRssi => to_value(self.get_ncp_rssi().await?),
            WpanMethod::GetNcpDeviceState => to_value(self.get_ncp_device_state().await?),
            WpanMethod::GetNcpState => to_value(self.get_ncp_state().await?),
            WpanMethod::GetNetworkName => to_value(self.get_network_name().await?),
            WpanMethod::GetNeighborTable => to_value(self.get_neighbor_table().await?),
            WpanMethod::GetPanId => to_value(self.get_panid().await?),
            WpanMethod::GetPartitionId => to_value(self.get_partition_id().await?),
            WpanMethod::GetThreadRloc16 => to_value(self.get_thread_rloc16().await?),
            WpanMethod::GetThreadRouterId => to_value(self.get_thread_router_id().await?),
            WpanMethod::GetWeaveNodeId => to_value(self.get_weave_node_id().await?),
            WpanMethod::InitializeProxies => to_value(self.initialize_proxies().await?),
            WpanMethod::ReplaceMacAddressFilterSettings => to_value(
                self.replace_mac_address_filter_settings(match from_value(_args.clone()) {
                    Ok(settings) => settings,
                    _ => bail!(
                        "Invalid json argument to ReplaceMacAddressFilterSettings! - {}",
                        _args
                    ),
                })
                .await?,
            ),
        }?)
    }
}