use super::DeviceClient;
use std::io::{Error, ErrorKind};
use std::sync::Arc;
use zbus::proxy::CacheProperties;
use zbus::zvariant::OwnedObjectPath;
use zbus::{Connection, Result as ZResult, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.Device.WiMax",
default_service = "org.freedesktop.NetworkManager"
)]
pub trait WiMax {
fn get_nsp_list(&self) -> ZResult<Vec<OwnedObjectPath>>;
#[zbus(property)]
fn nsps(&self) -> ZResult<Vec<OwnedObjectPath>>;
#[zbus(property)]
fn hw_address(&self) -> ZResult<String>;
#[zbus(property)]
fn center_frequency(&self) -> ZResult<u32>;
#[zbus(property)]
fn rssi(&self) -> ZResult<i32>;
#[zbus(property)]
fn cinr(&self) -> ZResult<i32>;
#[zbus(property)]
fn tx_power(&self) -> ZResult<i32>;
#[zbus(property)]
fn bsid(&self) -> ZResult<String>;
#[zbus(property)]
fn active_nsp(&self) -> ZResult<OwnedObjectPath>;
}
#[derive(Debug, Clone)]
pub struct WiMaxClient {
device: DeviceClient,
proxy: WiMaxProxy<'static>,
}
impl WiMaxClient {
pub async fn new(connection: Arc<Connection>, service_path: String) -> Result<Self, Error> {
let device = DeviceClient::new(connection.clone(), service_path.clone()).await?;
let proxy = WiMaxProxy::builder(&connection)
.path(service_path)
.map_err(|e| Error::new(ErrorKind::InvalidInput, e.to_string()))?
.cache_properties(CacheProperties::Yes)
.build()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;
proxy
.hw_address()
.await
.map_err(|e| Error::new(ErrorKind::NotFound, e.to_string()))?;
Ok(Self { device, proxy })
}
pub fn service_path(&self) -> &str {
self.device.service_path()
}
pub async fn interface(&self) -> Result<String, Error> {
self.device.interface().await
}
pub async fn disconnect(&self) -> Result<(), Error> {
self.device.disconnect().await
}
pub async fn get_nsp_list(&self) -> Result<Vec<OwnedObjectPath>, Error> {
self.proxy
.get_nsp_list()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn nsps(&self) -> Result<Vec<OwnedObjectPath>, Error> {
self.proxy
.nsps()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn hw_address(&self) -> Result<String, Error> {
self.proxy
.hw_address()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn center_frequency(&self) -> Result<u32, Error> {
self.proxy
.center_frequency()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn rssi(&self) -> Result<i32, Error> {
self.proxy
.rssi()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn cinr(&self) -> Result<i32, Error> {
self.proxy
.cinr()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn tx_power(&self) -> Result<i32, Error> {
self.proxy
.tx_power()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn bsid(&self) -> Result<String, Error> {
self.proxy
.bsid()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn active_nsp(&self) -> Result<OwnedObjectPath, Error> {
self.proxy
.active_nsp()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
}