use crate::dbus_api::Options;
use std::collections::HashMap;
use std::io::{Error, ErrorKind};
use zbus::proxy::CacheProperties;
use zbus::zvariant::OwnedValue;
use zbus::{Connection, Result as ZResult, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.DHCP6Config",
default_service = "org.freedesktop.NetworkManager"
)]
pub trait Dhcp6 {
#[zbus(property)]
fn options(&self) -> ZResult<HashMap<String, OwnedValue>>;
}
pub struct Dhcp6Client {
service_path: String,
proxy: Dhcp6Proxy<'static>,
}
impl Dhcp6Client {
pub async fn new(connection: &Connection, service_path: String) -> Result<Self, Error> {
let proxy = Dhcp6Proxy::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
.options()
.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 options(&self) -> Result<Options, Error> {
self.proxy
.options()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
}