Very basic NetworkManager bindings
This commit is contained in:
parent
cff3029833
commit
91a7fc6da1
7 changed files with 97 additions and 1 deletions
28
networkmanager/src/nm.rs
Normal file
28
networkmanager/src/nm.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{
|
||||
device::Device,
|
||||
interface::{device::DeviceProxy, NetworkManagerProxy},
|
||||
};
|
||||
use zbus::{Connection, Result};
|
||||
|
||||
pub struct NetworkManager<'a>(NetworkManagerProxy<'a>);
|
||||
|
||||
impl<'a> NetworkManager<'a> {
|
||||
pub async fn new(connection: &'a Connection) -> Result<NetworkManager<'a>> {
|
||||
NetworkManagerProxy::new(connection).await.map(Self)
|
||||
}
|
||||
|
||||
pub async fn devices(&self) -> Result<Vec<Device<'a>>> {
|
||||
let devices = self.0.get_all_devices().await?;
|
||||
let mut out = Vec::with_capacity(devices.len());
|
||||
for device in devices {
|
||||
let device = DeviceProxy::builder(self.0.connection())
|
||||
.path(device)?
|
||||
.build()
|
||||
.await?;
|
||||
out.push(device.into());
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue