Very basic NetworkManager bindings
This commit is contained in:
parent
cff3029833
commit
91a7fc6da1
7 changed files with 97 additions and 1 deletions
24
networkmanager/src/device.rs
Normal file
24
networkmanager/src/device.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
pub mod bluetooth;
|
||||
pub mod wired;
|
||||
pub mod wireless;
|
||||
|
||||
use crate::interface::device::DeviceProxy;
|
||||
use std::ops::Deref;
|
||||
|
||||
pub struct Device<'a>(DeviceProxy<'a>);
|
||||
|
||||
impl<'a> Deref for Device<'a> {
|
||||
type Target = DeviceProxy<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<DeviceProxy<'a>> for Device<'a> {
|
||||
fn from(device: DeviceProxy<'a>) -> Self {
|
||||
Device(device)
|
||||
}
|
||||
}
|
||||
14
networkmanager/src/device/bluetooth.rs
Normal file
14
networkmanager/src/device/bluetooth.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::interface::device::bluetooth::BluetoothDeviceProxy;
|
||||
use std::ops::Deref;
|
||||
|
||||
pub struct BluetoothDevice<'a>(BluetoothDeviceProxy<'a>);
|
||||
|
||||
impl<'a> Deref for BluetoothDevice<'a> {
|
||||
type Target = BluetoothDeviceProxy<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
14
networkmanager/src/device/wired.rs
Normal file
14
networkmanager/src/device/wired.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::interface::device::wired::WiredDeviceProxy;
|
||||
use std::ops::Deref;
|
||||
|
||||
pub struct WiredDevice<'a>(WiredDeviceProxy<'a>);
|
||||
|
||||
impl<'a> Deref for WiredDevice<'a> {
|
||||
type Target = WiredDeviceProxy<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
14
networkmanager/src/device/wireless.rs
Normal file
14
networkmanager/src/device/wireless.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::interface::device::wireless::WirelessDeviceProxy;
|
||||
use std::ops::Deref;
|
||||
|
||||
pub struct WirelessDevice<'a>(WirelessDeviceProxy<'a>);
|
||||
|
||||
impl<'a> Deref for WirelessDevice<'a> {
|
||||
type Target = WirelessDeviceProxy<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ use zbus::dbus_proxy;
|
|||
interface = "org.freedesktop.NetworkManager.Device.Bluetooth",
|
||||
default_service = "org.freedesktop.NetworkManager"
|
||||
)]
|
||||
pub trait Bluetooth {
|
||||
pub trait BluetoothDevice {
|
||||
/// BtCapabilities property
|
||||
#[dbus_proxy(property)]
|
||||
fn bt_capabilities(&self) -> zbus::Result<u32>;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
pub mod device;
|
||||
pub mod interface;
|
||||
pub mod nm;
|
||||
|
|
|
|||
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