use std::sync::Arc;
use zbus::{Connection, Error, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.Device.Statistics",
default_service = "org.freedesktop.NetworkManager"
)]
pub trait Statistics {
#[zbus(property)]
fn refresh_rate_ms(&self) -> Result<u32, Error>;
#[zbus(property)]
fn set_refresh_rate_ms(&self, value: u32) -> Result<(), Error>;
#[zbus(property)]
fn tx_bytes(&self) -> Result<u64, Error>;
#[zbus(property)]
fn rx_bytes(&self) -> Result<u64, Error>;
}
pub struct DeviceStatistics {
path: String,
connection: Arc<Connection>,
}
impl DeviceStatistics {
pub async fn new(connection: Arc<Connection>, path: String) -> Result<Self, Error> {
let stats = DeviceStatistics { path, connection };
let proxy = StatisticsProxy::builder(&stats.connection)
.path(stats.path.clone())?
.build()
.await?;
let _ = proxy.refresh_rate_ms().await?;
Ok(stats)
}
pub async fn refresh_rate_ms(&self) -> Result<u32, Error> {
let proxy = StatisticsProxy::builder(&self.connection)
.path(self.path.clone())?
.build()
.await?;
proxy.refresh_rate_ms().await
}
pub async fn set_refresh_rate_ms(&self, value: u32) -> Result<(), Error> {
let proxy = StatisticsProxy::builder(&self.connection)
.path(self.path.clone())?
.build()
.await?;
proxy.set_refresh_rate_ms(value).await
}
pub async fn tx_bytes(&self) -> Result<u64, Error> {
let proxy = StatisticsProxy::builder(&self.connection)
.path(self.path.clone())?
.build()
.await?;
proxy.tx_bytes().await
}
pub async fn rx_bytes(&self) -> Result<u64, Error> {
let proxy = StatisticsProxy::builder(&self.connection)
.path(self.path.clone())?
.build()
.await?;
proxy.rx_bytes().await
}
}