use std::io::{Error, ErrorKind};
use zbus::proxy::CacheProperties;
use zbus::zvariant::OwnedObjectPath;
use zbus::{Connection, Result as ZResult, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.Checkpoint",
default_service = "org.freedesktop.NetworkManager"
)]
pub trait Checkpoint {
#[zbus(property)]
fn devices(&self) -> ZResult<Vec<OwnedObjectPath>>;
#[zbus(property)]
fn created(&self) -> ZResult<i64>;
#[zbus(property)]
fn rollback_timeout(&self) -> ZResult<u32>;
}
pub struct CheckpointClient {
service_path: String,
proxy: CheckpointProxy<'static>,
}
impl CheckpointClient {
pub async fn new(connection: &Connection, service_path: String) -> Result<Self, Error> {
let proxy = CheckpointProxy::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
.created()
.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 devices(&self) -> Result<Vec<OwnedObjectPath>, Error> {
self.proxy
.devices()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn created(&self) -> Result<i64, Error> {
self.proxy
.created()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn rollback_timeout(&self) -> Result<u32, Error> {
self.proxy
.rollback_timeout()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
}