Continue to work on bindings, including NetworkManager::activate_connection

This commit is contained in:
Lucy 2022-01-12 11:23:09 -05:00
parent 0168219a78
commit 6dd7eb9da4
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
8 changed files with 77 additions and 8 deletions

View file

@ -4,8 +4,8 @@ use crate::{
config::{ip4::Ipv4Config, ip6::Ipv6Config},
device::Device,
interface::{
active_connection::ActiveConnectionProxy,
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
connection::ActiveConnectionProxy,
device::DeviceProxy,
enums::{ActivationStateFlags, State},
},

View file

@ -5,11 +5,11 @@ pub mod wired;
pub mod wireless;
use crate::{
active_connection::ActiveConnection,
config::{ip4::Ipv4Config, ip6::Ipv6Config},
connection::ActiveConnection,
interface::{
active_connection::ActiveConnectionProxy,
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
connection::ActiveConnectionProxy,
device::{
bluetooth::BluetoothDeviceProxy, wired::WiredDeviceProxy,
wireless::WirelessDeviceProxy, DeviceProxy,

View file

@ -22,8 +22,8 @@
#![allow(clippy::type_complexity)]
pub mod access_point;
pub mod active_connection;
pub mod config;
pub mod connection;
pub mod device;
pub mod enums;
pub mod settings;

View file

@ -1,7 +1,8 @@
// SPDX-License-Identifier: MPL-2.0
pub mod active_connection;
pub mod config;
pub mod connection;
pub mod device;
pub mod interface;
pub mod nm;
pub mod settings;

View file

@ -1,18 +1,59 @@
// SPDX-License-Identifier: MPL-2.0
use crate::{
active_connection::ActiveConnection,
device::Device,
interface::{device::DeviceProxy, NetworkManagerProxy},
interface::{
active_connection::ActiveConnectionProxy,
device::DeviceProxy,
enums::{ConnectivityState, State},
NetworkManagerProxy,
},
settings::connection::Connection,
};
use zbus::{Connection, Result};
use zbus::{zvariant::ObjectPath, Result};
pub struct NetworkManager<'a>(NetworkManagerProxy<'a>);
impl<'a> NetworkManager<'a> {
pub async fn new(connection: &'a Connection) -> Result<NetworkManager<'a>> {
pub async fn new(connection: &'a zbus::Connection) -> Result<NetworkManager<'a>> {
NetworkManagerProxy::new(connection).await.map(Self)
}
pub async fn activate_connection(
&self,
connection: &'a Connection<'a>,
device: &'a Device<'a>,
) -> Result<ActiveConnection<'a>> {
let connection = connection.path();
let device = device.path();
let specific_object = ObjectPath::from_static_str("/").unwrap();
let active_connection_path = self
.0
.activate_connection(connection, device, &specific_object)
.await?;
ActiveConnectionProxy::builder(self.0.connection())
.path(active_connection_path)?
.build()
.await
.map(ActiveConnection::from)
}
pub async fn connectivity(&self) -> Result<ConnectivityState> {
self.0.connectivity().await.map(ConnectivityState::from)
}
pub async fn check_connectivity(&self) -> Result<ConnectivityState> {
self.0
.check_connectivity()
.await
.map(ConnectivityState::from)
}
pub async fn deactivate_connection(&self, connection: &'a ActiveConnection<'a>) -> Result<()> {
self.0.deactivate_connection(connection.path()).await
}
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());
@ -38,4 +79,8 @@ impl<'a> NetworkManager<'a> {
}
Ok(out)
}
pub async fn state(&self) -> State {
self.0.state().await.map(State::from).unwrap()
}
}

View file

@ -0,0 +1,3 @@
// SPDX-License-Identifier: MPL-2.0
pub mod connection;

View file

@ -0,0 +1,20 @@
// SPDX-License-Identifier: MPL-2.0
use crate::interface::settings::connection::ConnectionSettingsProxy;
use std::ops::Deref;
pub struct Connection<'a>(ConnectionSettingsProxy<'a>);
impl<'a> Deref for Connection<'a> {
type Target = ConnectionSettingsProxy<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> From<ConnectionSettingsProxy<'a>> for Connection<'a> {
fn from(conn: ConnectionSettingsProxy<'a>) -> Self {
Connection(conn)
}
}