use crate::api::models::{
AccessTechnology, Bearer, BearerConfig, ConnectionStatus, Modem, Result, Sim,
};
use crate::api::modem_manager::ModemManager;
#[derive(Debug)]
pub struct ModemScope<'a> {
pub(crate) mm: &'a ModemManager,
pub(crate) path: String,
}
impl<'a> ModemScope<'a> {
pub(crate) fn new(mm: &'a ModemManager, path: &str) -> Self {
Self {
mm,
path: path.to_string(),
}
}
#[must_use]
pub fn path(&self) -> &str {
&self.path
}
pub async fn info(&self) -> Result<Modem> {
self.mm.modem_info_for_path(&self.path).await
}
pub async fn enable(&self) -> Result<()> {
self.mm.enable_for_path(&self.path).await
}
pub async fn disable(&self) -> Result<()> {
self.mm.disable_for_path(&self.path).await
}
pub async fn connect_simple(&self, apn: &str) -> Result<Bearer> {
self.connect(&BearerConfig::new(apn)).await
}
pub async fn connect(&self, config: &BearerConfig) -> Result<Bearer> {
self.mm.connect_for_path(&self.path, config).await
}
pub async fn disconnect(&self) -> Result<()> {
self.mm.disconnect_for_path(&self.path).await
}
pub async fn status(&self) -> Result<ConnectionStatus> {
self.mm.status_for_path(&self.path).await
}
pub async fn sim(&self) -> Result<Option<Sim>> {
self.mm.sim_for_path(&self.path).await
}
pub async fn unlock_pin(&self, pin: &str) -> Result<()> {
self.mm.unlock_pin_for_path(&self.path, pin).await
}
pub async fn unlock_puk(&self, puk: &str, new_pin: &str) -> Result<()> {
self.mm.unlock_puk_for_path(&self.path, puk, new_pin).await
}
pub async fn set_pin_enabled(&self, pin: &str, enabled: bool) -> Result<()> {
self.mm
.set_pin_enabled_for_path(&self.path, pin, enabled)
.await
}
pub async fn change_pin(&self, old: &str, new: &str) -> Result<()> {
self.mm.change_pin_for_path(&self.path, old, new).await
}
pub async fn signal_quality(&self) -> Result<u32> {
self.mm.signal_quality_for_path(&self.path).await
}
pub async fn access_technology(&self) -> Result<AccessTechnology> {
self.mm.access_technology_for_path(&self.path).await
}
}