openthread/ot/
link_metrics.rs

1// Copyright 2024 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.
4
5use crate::prelude_internal::*;
6
7/// Methods from the "Link Metrics " group [1]
8///
9/// [1] https://openthread.io/reference/group/api-link-metrics
10pub trait LinkMetrics {
11    /// Get Link Metrics Manager enabled/disabled state.
12    fn link_metrics_manager_is_enabled(&self) -> bool;
13
14    /// Enable or disable Link Metrics Manager.
15    fn link_metrics_manager_set_enabled(&self, enabled: bool);
16
17    /// Get Link Metrics data of a neighbor by its extended address.
18    fn link_metrics_manager_get_metrics_value_by_ext_addr(
19        &self,
20        ext_addr: &ExtAddress,
21    ) -> Result<LinkMetricsValues>;
22}
23
24impl<T: LinkMetrics + ot::Boxable> LinkMetrics for ot::Box<T> {
25    fn link_metrics_manager_is_enabled(&self) -> bool {
26        self.as_ref().link_metrics_manager_is_enabled()
27    }
28
29    fn link_metrics_manager_set_enabled(&self, enabled: bool) {
30        self.as_ref().link_metrics_manager_set_enabled(enabled)
31    }
32
33    fn link_metrics_manager_get_metrics_value_by_ext_addr(
34        &self,
35        ext_addr: &ExtAddress,
36    ) -> Result<LinkMetricsValues> {
37        self.as_ref().link_metrics_manager_get_metrics_value_by_ext_addr(ext_addr)
38    }
39}
40
41impl LinkMetrics for Instance {
42    fn link_metrics_manager_is_enabled(&self) -> bool {
43        unsafe { otLinkMetricsManagerIsEnabled(self.as_ot_ptr()) }
44    }
45
46    fn link_metrics_manager_set_enabled(&self, enabled: bool) {
47        unsafe { otLinkMetricsManagerSetEnabled(self.as_ot_ptr(), enabled) }
48    }
49
50    fn link_metrics_manager_get_metrics_value_by_ext_addr(
51        &self,
52        ext_addr: &ExtAddress,
53    ) -> Result<LinkMetricsValues> {
54        let mut values = LinkMetricsValues::default();
55        Error::from(unsafe {
56            otLinkMetricsManagerGetMetricsValueByExtAddr(
57                self.as_ot_ptr(),
58                ext_addr.as_ot_ptr(),
59                values.as_ot_mut_ptr(),
60            )
61        })
62        .into_result()?;
63        Ok(values)
64    }
65}