use std::io::{Error, ErrorKind};
use zbus::proxy::CacheProperties;
use zbus::{Connection, Result as ZResult, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.AgentManager",
default_service = "org.freedesktop.NetworkManager",
default_path = "/org/freedesktop/NetworkManager/AgentManager"
)]
pub trait AgentManager {
fn register(&self, identifier: &str) -> ZResult<()>;
fn register_with_capabilities(&self, identifier: &str, capabilities: u32) -> ZResult<()>;
fn unregister(&self) -> ZResult<()>;
}
pub struct AgentManagerClient {
proxy: AgentManagerProxy<'static>,
}
impl AgentManagerClient {
pub async fn new(connection: &Connection) -> Result<Self, Error> {
let proxy = AgentManagerProxy::builder(connection)
.cache_properties(CacheProperties::Yes)
.build()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;
Ok(Self { proxy })
}
pub async fn register(&self, identifier: &str) -> Result<(), Error> {
self.proxy
.register(identifier)
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn register_with_capabilities(
&self,
identifier: &str,
capabilities: u32,
) -> Result<(), Error> {
self.proxy
.register_with_capabilities(identifier, capabilities)
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn unregister(&self) -> Result<(), Error> {
self.proxy
.unregister()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
}