use super::DeviceClient;
use std::io::{Error, ErrorKind};
use std::sync::Arc;
use zbus::proxy::CacheProperties;
use zbus::{Connection, Result as ZResult, proxy};
#[proxy(
interface = "org.freedesktop.NetworkManager.Device.Modem",
default_service = "org.freedesktop.NetworkManager"
)]
pub trait Modem {
#[zbus(property)]
fn modem_capabilities(&self) -> ZResult<u32>;
#[zbus(property)]
fn current_capabilities(&self) -> ZResult<u32>;
#[zbus(property)]
fn device_id(&self) -> ZResult<String>;
#[zbus(property)]
fn operator_code(&self) -> ZResult<String>;
#[zbus(property)]
fn apn(&self) -> ZResult<String>;
}
#[derive(Debug, Clone)]
pub struct ModemClient {
device: DeviceClient,
proxy: ModemProxy<'static>,
}
impl ModemClient {
pub async fn new(connection: Arc<Connection>, service_path: String) -> Result<Self, Error> {
let device = DeviceClient::new(connection.clone(), service_path.clone()).await?;
let proxy = ModemProxy::builder(&connection)
.path(service_path)
.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
.modem_capabilities()
.await
.map_err(|e| Error::new(ErrorKind::NotFound, e.to_string()))?;
Ok(Self { device, proxy })
}
pub fn service_path(&self) -> &str {
self.device.service_path()
}
pub async fn interface(&self) -> Result<String, Error> {
self.device.interface().await
}
pub async fn disconnect(&self) -> Result<(), Error> {
self.device.disconnect().await
}
pub async fn modem_capabilities(&self) -> Result<u32, Error> {
self.proxy
.modem_capabilities()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn current_capabilities(&self) -> Result<u32, Error> {
self.proxy
.current_capabilities()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn device_id(&self) -> Result<String, Error> {
self.proxy
.device_id()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn operator_code(&self) -> Result<String, Error> {
self.proxy
.operator_code()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
pub async fn apn(&self) -> Result<String, Error> {
self.proxy
.apn()
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
}