More dictionary-based stuff
This commit is contained in:
parent
ec7ac55a60
commit
337b27e4a8
4 changed files with 60 additions and 36 deletions
|
|
@ -8,6 +8,5 @@ license = "MPL-2.0"
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
derive_builder = "0.10.2"
|
derive_builder = "0.10.2"
|
||||||
zbus = "2.0.1"
|
zbus = "2.0.1"
|
||||||
zvariant = "3.1.0"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
pub mod connection;
|
pub mod connection;
|
||||||
|
|
||||||
use crate::settings::connection::Settings;
|
|
||||||
use zbus::dbus_proxy;
|
use zbus::dbus_proxy;
|
||||||
|
|
||||||
#[dbus_proxy(
|
#[dbus_proxy(
|
||||||
|
|
@ -34,13 +33,19 @@ pub trait Settings {
|
||||||
/// AddConnection method
|
/// AddConnection method
|
||||||
fn add_connection(
|
fn add_connection(
|
||||||
&self,
|
&self,
|
||||||
connection: &Settings,
|
connection: std::collections::HashMap<
|
||||||
|
&str,
|
||||||
|
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
>,
|
||||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||||
|
|
||||||
/// AddConnection2 method
|
/// AddConnection2 method
|
||||||
fn add_connection2(
|
fn add_connection2(
|
||||||
&self,
|
&self,
|
||||||
settings: &Settings,
|
settings: std::collections::HashMap<
|
||||||
|
&str,
|
||||||
|
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
>,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
) -> zbus::Result<(
|
) -> zbus::Result<(
|
||||||
|
|
@ -51,7 +56,10 @@ pub trait Settings {
|
||||||
/// AddConnectionUnsaved method
|
/// AddConnectionUnsaved method
|
||||||
fn add_connection_unsaved(
|
fn add_connection_unsaved(
|
||||||
&self,
|
&self,
|
||||||
connection: &Settings,
|
connection: std::collections::HashMap<
|
||||||
|
&str,
|
||||||
|
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
>,
|
||||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||||
|
|
||||||
/// GetConnectionByUuid method
|
/// GetConnectionByUuid method
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
//!
|
//!
|
||||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||||
|
|
||||||
use crate::settings::connection::Settings;
|
|
||||||
use zbus::dbus_proxy;
|
use zbus::dbus_proxy;
|
||||||
|
|
||||||
#[dbus_proxy(
|
#[dbus_proxy(
|
||||||
|
|
@ -46,24 +45,46 @@ pub trait ConnectionSettings {
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// GetSettings method
|
/// GetSettings method
|
||||||
fn get_settings(&self) -> zbus::Result<Settings>;
|
fn get_settings(
|
||||||
|
&self,
|
||||||
|
) -> zbus::Result<
|
||||||
|
std::collections::HashMap<
|
||||||
|
String,
|
||||||
|
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
|
||||||
|
>,
|
||||||
|
>;
|
||||||
|
|
||||||
/// Save method
|
/// Save method
|
||||||
fn save(&self) -> zbus::Result<()>;
|
fn save(&self) -> zbus::Result<()>;
|
||||||
|
|
||||||
/// Update method
|
/// Update method
|
||||||
fn update(&self, properties: &Settings) -> zbus::Result<()>;
|
fn update(
|
||||||
|
&self,
|
||||||
|
properties: std::collections::HashMap<
|
||||||
|
&str,
|
||||||
|
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
>,
|
||||||
|
) -> zbus::Result<()>;
|
||||||
|
|
||||||
/// Update2 method
|
/// Update2 method
|
||||||
fn update2(
|
fn update2(
|
||||||
&self,
|
&self,
|
||||||
settings: &Settings,
|
settings: std::collections::HashMap<
|
||||||
|
&str,
|
||||||
|
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
>,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
) -> zbus::Result<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>;
|
) -> zbus::Result<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>;
|
||||||
|
|
||||||
/// UpdateUnsaved method
|
/// UpdateUnsaved method
|
||||||
fn update_unsaved(&self, properties: &Settings) -> zbus::Result<()>;
|
fn update_unsaved(
|
||||||
|
&self,
|
||||||
|
properties: std::collections::HashMap<
|
||||||
|
&str,
|
||||||
|
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
>,
|
||||||
|
) -> zbus::Result<()>;
|
||||||
|
|
||||||
/// Removed signal
|
/// Removed signal
|
||||||
#[dbus_proxy(signal)]
|
#[dbus_proxy(signal)]
|
||||||
|
|
|
||||||
|
|
@ -22,32 +22,31 @@ impl<'a> From<ConnectionSettingsProxy<'a>> for Connection<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! derive_value_build {
|
macro_rules! derive_value_build {
|
||||||
($name:ident($signature:expr), $(($arg:ident($rename:expr): $arg_ty:ty)),*) => {
|
($name:ident, $(($arg:ident($rename:expr): $arg_ty:ty)),*) => {
|
||||||
#[derive(Debug, Builder, Clone, zbus::zvariant::DeserializeDict, zbus::zvariant::SerializeDict, zbus::zvariant::Type)]
|
#[derive(Debug, Builder, Clone)]
|
||||||
#[zvariant(signature = $signature)]
|
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
$(
|
$(
|
||||||
#[zvariant(rename = $rename)]
|
|
||||||
#[builder(setter(into, strip_option))]
|
#[builder(setter(into, strip_option))]
|
||||||
pub $arg: Option<$arg_ty>,
|
pub $arg: Option<$arg_ty>,
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl $name {
|
||||||
|
pub fn build<'a>(&'a self) -> std::collections::HashMap<String, zbus::zvariant::Value<'a>> {
|
||||||
|
let mut out = std::collections::HashMap::new();
|
||||||
|
$(
|
||||||
|
if let Some(val) = &self.$arg {
|
||||||
|
out.insert($rename.to_string(), val.to_owned().into());
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
Settings("a{sa{sv}}"),
|
ConnectionSettings,
|
||||||
(connection("connection"): ConnectionSettings),
|
|
||||||
(ethernet("802-3-ethernet"): EthernetSettings),
|
|
||||||
(wifi("802-11-wireless"): WifiSettings),
|
|
||||||
(bluetooth("bluetooth"): BluetoothSettings),
|
|
||||||
(ipv4("ipv4"): Ipv4Settings),
|
|
||||||
(ipv6("ipv6"): Ipv6Settings),
|
|
||||||
(proxy("proxy"): WwwProxySettings)
|
|
||||||
);
|
|
||||||
|
|
||||||
derive_value_build!(
|
|
||||||
ConnectionSettings("dict"),
|
|
||||||
(auth_retries("auth-retries"): i32),
|
(auth_retries("auth-retries"): i32),
|
||||||
(autoconnect("autoconnect"): bool),
|
(autoconnect("autoconnect"): bool),
|
||||||
(autoconnect_priority("autoconnect-priority"): i32),
|
(autoconnect_priority("autoconnect-priority"): i32),
|
||||||
|
|
@ -73,7 +72,7 @@ derive_value_build!(
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
EthernetSettings("dict"),
|
EthernetSettings,
|
||||||
(accept_all_mac_addresses("accept-all-mac-addresses"): i32),
|
(accept_all_mac_addresses("accept-all-mac-addresses"): i32),
|
||||||
(assigned_mac_address("assigned-mac-address"): String),
|
(assigned_mac_address("assigned-mac-address"): String),
|
||||||
(auto_negotiate("auto-negotiate"): bool),
|
(auto_negotiate("auto-negotiate"): bool),
|
||||||
|
|
@ -93,7 +92,8 @@ derive_value_build!(
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
WifiSettings("dict"),
|
WifiSettings,
|
||||||
|
(ap_isolation("ap-isolation"): i32),
|
||||||
(assigned_mac_address("assigned-mac-address"): String),
|
(assigned_mac_address("assigned-mac-address"): String),
|
||||||
(band("band"): String),
|
(band("band"): String),
|
||||||
(bssid("bssid"): Vec<u8>),
|
(bssid("bssid"): Vec<u8>),
|
||||||
|
|
@ -115,14 +115,13 @@ derive_value_build!(
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
BluetoothSettings("dict"),
|
BluetoothSettings,
|
||||||
(bdaddr("bdaddr"): Vec<u8>),
|
(bdaddr("bdaddr"): Vec<u8>),
|
||||||
(type_("type"): String)
|
(type_("type"): String)
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
Ipv4Settings("dict"),
|
Ipv4Settings,
|
||||||
(address_data("address-data"): Vec<()>),
|
|
||||||
(addresses("addresses"): Vec<Vec<u32>>),
|
(addresses("addresses"): Vec<Vec<u32>>),
|
||||||
(dad_timeout("dad-timeout"): i32),
|
(dad_timeout("dad-timeout"): i32),
|
||||||
(dhcp_client_id("dhcp-client-id"): String),
|
(dhcp_client_id("dhcp-client-id"): String),
|
||||||
|
|
@ -144,16 +143,14 @@ derive_value_build!(
|
||||||
(method("method"): String),
|
(method("method"): String),
|
||||||
(never_default("never-default"): bool),
|
(never_default("never-default"): bool),
|
||||||
(ra_timeout("ra-timeout"): i32),
|
(ra_timeout("ra-timeout"): i32),
|
||||||
(route_data("route-data"): Vec<()>),
|
|
||||||
(route_metric("route-metric"): i32),
|
(route_metric("route-metric"): i32),
|
||||||
(route_table("route-table"): u32),
|
(route_table("route-table"): u32),
|
||||||
(routes("routes"): Vec<Vec<u32>>)
|
(routes("routes"): Vec<Vec<u32>>)
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
Ipv6Settings("dict"),
|
Ipv6Settings,
|
||||||
(addr_gen_mode("addr-gen-mode"): i32),
|
(addr_gen_mode("addr-gen-mode"): i32),
|
||||||
(address_data("address-data"): Vec<()>),
|
|
||||||
(addresses("addresses"): Vec<String>),
|
(addresses("addresses"): Vec<String>),
|
||||||
(dad_timeout("dad-timeout"): i32),
|
(dad_timeout("dad-timeout"): i32),
|
||||||
(dhcp_duid("dhcp-duid"): Vec<u8>),
|
(dhcp_duid("dhcp-duid"): Vec<u8>),
|
||||||
|
|
@ -175,7 +172,6 @@ derive_value_build!(
|
||||||
(method("method"): String),
|
(method("method"): String),
|
||||||
(never_default("never-default"): bool),
|
(never_default("never-default"): bool),
|
||||||
(ra_timeout("ra-timeout"): i32),
|
(ra_timeout("ra-timeout"): i32),
|
||||||
(route_data("route-data"): Vec<()>),
|
|
||||||
(route_metric("route-metric"): i32),
|
(route_metric("route-metric"): i32),
|
||||||
(route_table("route-table"): u32),
|
(route_table("route-table"): u32),
|
||||||
(routes("routes"): Vec<String>),
|
(routes("routes"): Vec<String>),
|
||||||
|
|
@ -183,7 +179,7 @@ derive_value_build!(
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
WwwProxySettings("dict"),
|
WwwProxySettings,
|
||||||
(browser_only("browser-only"): bool),
|
(browser_only("browser-only"): bool),
|
||||||
(method("method"): i32),
|
(method("method"): i32),
|
||||||
(pac_script("pac-script"): String),
|
(pac_script("pac-script"): String),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue