Add a Settings type for all connection settings, and change bindings to use said type.
This commit is contained in:
parent
737b687bd3
commit
e660731756
3 changed files with 71 additions and 91 deletions
|
|
@ -7,7 +7,7 @@ license = "MPL-2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
derive_builder = "0.10.2"
|
derive_builder = "0.10.2"
|
||||||
serde = { version = "1.0.134", features = ["derive"] }
|
|
||||||
zbus = "2.0.1"
|
zbus = "2.0.1"
|
||||||
|
zvariant = "3.1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
//!
|
//!
|
||||||
//! …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(
|
||||||
|
|
@ -45,46 +46,24 @@ pub trait ConnectionSettings {
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// GetSettings method
|
/// GetSettings method
|
||||||
fn get_settings(
|
fn get_settings(&self) -> zbus::Result<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(
|
fn update(&self, properties: &Settings) -> zbus::Result<()>;
|
||||||
&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: std::collections::HashMap<
|
settings: &Settings,
|
||||||
&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(
|
fn update_unsaved(&self, properties: &Settings) -> zbus::Result<()>;
|
||||||
&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)]
|
||||||
|
|
|
||||||
|
|
@ -21,87 +21,88 @@ impl<'a> From<ConnectionSettingsProxy<'a>> for Connection<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! derive_value_build {
|
macro_rules! derive_value_build {
|
||||||
($name:ident, $(($arg:ident: $arg_ty:ty)),*) => {
|
($name:ident, $(($arg:ident($rename:expr): $arg_ty:ty)),*) => {
|
||||||
#[derive(Builder, serde::Deserialize, serde::Serialize)]
|
#[derive(Builder, Clone, zbus::zvariant::DeserializeDict, zbus::zvariant::SerializeDict, zbus::zvariant::Type)]
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
$(
|
$(
|
||||||
|
#[zvariant(rename = $rename)]
|
||||||
#[builder(setter(into, strip_option))]
|
#[builder(setter(into, strip_option))]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub $arg: Option<$arg_ty>,
|
||||||
$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(stringify!($arg).trim_end_matches("_").replace("_", "-"), zbus::zvariant::Value::from(val));
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
out
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
derive_value_build!(
|
||||||
|
Settings,
|
||||||
|
(connection("connection"): ConnectionSettings),
|
||||||
|
(ethernet("802-3-ethernet"): EthernetSettings),
|
||||||
|
(wifi("802-11-wireless"): WifiSettings),
|
||||||
|
(bluetooth("bluetooth"): BluetoothSettings)
|
||||||
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
ConnectionSettings,
|
ConnectionSettings,
|
||||||
(auth_retries: i32),
|
(auth_retries("auth-retries"): i32),
|
||||||
(autoconnect: bool),
|
(autoconnect("autoconnect"): bool),
|
||||||
(autoconnect_priority: i32),
|
(autoconnect_priority("autoconnect-priority"): i32),
|
||||||
(autoconnect_retries: i32),
|
(autoconnect_retries("autoconnect-retries"): i32),
|
||||||
(gateway_ping_timeout: u32),
|
(gateway_ping_timeout("gateway-ping-timeout"): u32),
|
||||||
(id: String),
|
(id("id"): String),
|
||||||
(interface_name: String),
|
(interface_name("interface-name"): String),
|
||||||
(lldp: i32),
|
(lldp("lldp"): i32),
|
||||||
(llmnr: i32),
|
(llmnr("llmnr"): i32),
|
||||||
(master: String),
|
(master("master"): String),
|
||||||
(mdns: i32),
|
(mdns("mdns"): i32),
|
||||||
(mud_url: String),
|
(mud_url("mud_url"): String),
|
||||||
(multi_connect: String),
|
(multi_connect("multi-connect"): String),
|
||||||
(permissions: Vec<String>),
|
(permissions("permissions"): Vec<String>),
|
||||||
(read_only: bool),
|
(read_only("read-only"): bool),
|
||||||
(secondaries: Vec<String>),
|
(secondaries("secondaries"): Vec<String>),
|
||||||
(stable_id: String),
|
(stable_id("stable-id"): String),
|
||||||
(type_: String),
|
(type_("type"): String),
|
||||||
(uuid: String),
|
(uuid("uuid"): String),
|
||||||
(wait_device_timeout: i32),
|
(wait_device_timeout("wait-device-timeout"): i32),
|
||||||
(zone: String)
|
(zone("zone"): String)
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
EthernetSettings,
|
EthernetSettings,
|
||||||
(assigned_mac_address: String),
|
(assigned_mac_address("assigned-mac-address"): String),
|
||||||
(auto_negotiate: bool),
|
(auto_negotiate("auto-negotiate"): bool),
|
||||||
(duplex: String),
|
(duplex("duplex"): String),
|
||||||
(generate_mac_address_mask: String),
|
(generate_mac_address_mask("generate-mac-address-mask"): String),
|
||||||
(mtu: u32),
|
(mtu("mtu"): u32),
|
||||||
(port: String),
|
(port("port"): String),
|
||||||
(speed: u32),
|
(speed("speed"): u32),
|
||||||
(wake_on_lan: u32),
|
(wake_on_lan("wake-on-lan"): u32),
|
||||||
(wake_on_lan_password: String)
|
(wake_on_lan_password("wake-on-lan-password"): String)
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(
|
derive_value_build!(
|
||||||
WifiSettings,
|
WifiSettings,
|
||||||
(assigned_mac_address: String),
|
(assigned_mac_address("assigned-mac-address"): String),
|
||||||
(band: String),
|
(band("band"): String),
|
||||||
(bssid: Vec<u8>),
|
(bssid("bssid"): Vec<u8>),
|
||||||
(channel: u32),
|
(channel("channel"): u32),
|
||||||
(cloned_mac_address: Vec<u8>),
|
(cloned_mac_address("cloned-mac-address"): Vec<u8>),
|
||||||
(generate_mac_address_mask: String),
|
(generate_mac_address_mask("generate-mac-address-mask"): String),
|
||||||
(hidden: bool),
|
(hidden("hidden"): bool),
|
||||||
(mac_address: Vec<u8>),
|
(mac_address("mac-address"): Vec<u8>),
|
||||||
(mac_address_blacklist: Vec<String>),
|
(mac_address_blacklist("mac-address-blacklist"): Vec<String>),
|
||||||
(mac_address_randomization: u32),
|
(mac_address_randomization("mac-address-randomization"): u32),
|
||||||
(mode: String),
|
(mode("mode"): String),
|
||||||
(mtu: u32),
|
(mtu("mtu"): u32),
|
||||||
(powersave: u32),
|
(powersave("powersave"): u32),
|
||||||
(rate: u32),
|
(rate("rate"): u32),
|
||||||
(seen_bssids: Vec<String>),
|
(seen_bssids("seen-bssids"): Vec<String>),
|
||||||
(ssid: Vec<u8>),
|
(ssid("ssid"): Vec<u8>),
|
||||||
(tx_power: u32),
|
(tx_power("tx-power"): u32),
|
||||||
(wake_on_wlan: u32)
|
(wake_on_wlan("wake-on-wlan"): u32)
|
||||||
);
|
);
|
||||||
|
|
||||||
derive_value_build!(BluetoothSettings, (bdaddr: Vec<u8>), (type_: String));
|
derive_value_build!(
|
||||||
|
BluetoothSettings,
|
||||||
|
(bdaddr("bdaddr"): Vec<u8>),
|
||||||
|
(type_("type"): String)
|
||||||
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue