Continue to work on bindings, including NetworkManager::activate_connection
This commit is contained in:
parent
0168219a78
commit
6dd7eb9da4
8 changed files with 77 additions and 8 deletions
|
|
@ -4,8 +4,8 @@ use crate::{
|
||||||
config::{ip4::Ipv4Config, ip6::Ipv6Config},
|
config::{ip4::Ipv4Config, ip6::Ipv6Config},
|
||||||
device::Device,
|
device::Device,
|
||||||
interface::{
|
interface::{
|
||||||
|
active_connection::ActiveConnectionProxy,
|
||||||
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
|
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
|
||||||
connection::ActiveConnectionProxy,
|
|
||||||
device::DeviceProxy,
|
device::DeviceProxy,
|
||||||
enums::{ActivationStateFlags, State},
|
enums::{ActivationStateFlags, State},
|
||||||
},
|
},
|
||||||
|
|
@ -5,11 +5,11 @@ pub mod wired;
|
||||||
pub mod wireless;
|
pub mod wireless;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
active_connection::ActiveConnection,
|
||||||
config::{ip4::Ipv4Config, ip6::Ipv6Config},
|
config::{ip4::Ipv4Config, ip6::Ipv6Config},
|
||||||
connection::ActiveConnection,
|
|
||||||
interface::{
|
interface::{
|
||||||
|
active_connection::ActiveConnectionProxy,
|
||||||
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
|
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
|
||||||
connection::ActiveConnectionProxy,
|
|
||||||
device::{
|
device::{
|
||||||
bluetooth::BluetoothDeviceProxy, wired::WiredDeviceProxy,
|
bluetooth::BluetoothDeviceProxy, wired::WiredDeviceProxy,
|
||||||
wireless::WirelessDeviceProxy, DeviceProxy,
|
wireless::WirelessDeviceProxy, DeviceProxy,
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
pub mod access_point;
|
pub mod access_point;
|
||||||
|
pub mod active_connection;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod connection;
|
|
||||||
pub mod device;
|
pub mod device;
|
||||||
pub mod enums;
|
pub mod enums;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
pub mod active_connection;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod connection;
|
|
||||||
pub mod device;
|
pub mod device;
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
pub mod nm;
|
pub mod nm;
|
||||||
|
pub mod settings;
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,59 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
active_connection::ActiveConnection,
|
||||||
device::Device,
|
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>);
|
pub struct NetworkManager<'a>(NetworkManagerProxy<'a>);
|
||||||
|
|
||||||
impl<'a> NetworkManager<'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)
|
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>>> {
|
pub async fn devices(&self) -> Result<Vec<Device<'a>>> {
|
||||||
let devices = self.0.get_all_devices().await?;
|
let devices = self.0.get_all_devices().await?;
|
||||||
let mut out = Vec::with_capacity(devices.len());
|
let mut out = Vec::with_capacity(devices.len());
|
||||||
|
|
@ -38,4 +79,8 @@ impl<'a> NetworkManager<'a> {
|
||||||
}
|
}
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn state(&self) -> State {
|
||||||
|
self.0.state().await.map(State::from).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
networkmanager/src/settings.rs
Normal file
3
networkmanager/src/settings.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
pub mod connection;
|
||||||
20
networkmanager/src/settings/connection.rs
Normal file
20
networkmanager/src/settings/connection.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue