use std::io::{Error, ErrorKind};
use zbus::proxy::CacheProperties;
use zbus::{Connection, Result as ZResult, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.WifiP2PPeer",
default_service = "org.freedesktop.NetworkManager"
)]
pub trait WifiP2PPeer {
#[zbus(property)]
fn name(&self) -> ZResult<String>;
#[zbus(property)]
fn flags(&self) -> ZResult<u32>;
#[zbus(property)]
fn manufacturer(&self) -> ZResult<String>;
#[zbus(property)]
fn model(&self) -> ZResult<String>;
#[zbus(property)]
fn model_number(&self) -> ZResult<String>;
#[zbus(property)]
fn serial(&self) -> ZResult<String>;
#[zbus(property)]
fn wfd_ies(&self) -> ZResult<Vec<u8>>;
#[zbus(property)]
fn hw_address(&self) -> ZResult<String>;
#[zbus(property)]
fn strength(&self) -> ZResult<u8>;
#[zbus(property)]
fn last_seen(&self) -> ZResult<i32>;
}
pub struct WifiP2PPeerClient {
service_path: String,
proxy: WifiP2PPeerProxy<'static>,
}
impl WifiP2PPeerClient {
pub async fn new(connection: &Connection, service_path: String) -> Result<Self, Error> {
let proxy = WifiP2PPeerProxy::builder(connection)
.path(service_path.clone())
.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 {
service_path,
proxy,
})
}
pub fn service_path(&self) -> &str {
&self.service_path
}
pub async fn name(&self) -> Result<String, Error> {
self.proxy
.name()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn flags(&self) -> Result<u32, Error> {
self.proxy
.flags()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn manufacturer(&self) -> Result<String, Error> {
self.proxy
.manufacturer()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn model(&self) -> Result<String, Error> {
self.proxy
.model()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn model_number(&self) -> Result<String, Error> {
self.proxy
.model_number()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn serial(&self) -> Result<String, Error> {
self.proxy
.serial()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn wfd_ies(&self) -> Result<Vec<u8>, Error> {
self.proxy
.wfd_ies()
.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 strength(&self) -> Result<u8, Error> {
self.proxy
.strength()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn last_seen(&self) -> Result<i32, Error> {
self.proxy
.last_seen()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
}