Add connectio nsettings types+builders
This commit is contained in:
parent
6dd7eb9da4
commit
29550a9658
3 changed files with 172 additions and 0 deletions
85
Cargo.lock
generated
85
Cargo.lock
generated
|
|
@ -153,9 +153,45 @@ name = "cosmic-dbus-networkmanager"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
"derive_builder",
|
||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling"
|
||||||
|
version = "0.12.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core",
|
||||||
|
"darling_macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_core"
|
||||||
|
version = "0.12.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e91455b86830a1c21799d94524df0845183fa55bafd9aa137b01c7d1065fa36"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"ident_case",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"strsim",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_macro"
|
||||||
|
version = "0.12.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derivative"
|
name = "derivative"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
|
@ -167,6 +203,37 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_builder"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d13202debe11181040ae9063d739fa32cfcaaebe2275fe387703460ae2365b30"
|
||||||
|
dependencies = [
|
||||||
|
"derive_builder_macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_builder_core"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "66e616858f6187ed828df7c64a6d71720d83767a7f19740b2d1b6fe6327b36e5"
|
||||||
|
dependencies = [
|
||||||
|
"darling",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_builder_macro"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "58a94ace95092c5acb1e97a7e846b310cfbd499652f72297da7493f618a98d73"
|
||||||
|
dependencies = [
|
||||||
|
"derive_builder_core",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "easy-parallel"
|
name = "easy-parallel"
|
||||||
version = "3.2.0"
|
version = "3.2.0"
|
||||||
|
|
@ -209,6 +276,12 @@ dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-core"
|
name = "futures-core"
|
||||||
version = "0.3.19"
|
version = "0.3.19"
|
||||||
|
|
@ -279,6 +352,12 @@ version = "0.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ident_case"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "instant"
|
name = "instant"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
|
|
@ -528,6 +607,12 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.85"
|
version = "1.0.85"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ license = "MPL-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
|
derive_builder = "0.10.2"
|
||||||
zbus = "2.0.0"
|
zbus = "2.0.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use crate::interface::settings::connection::ConnectionSettingsProxy;
|
use crate::interface::settings::connection::ConnectionSettingsProxy;
|
||||||
|
use derive_builder::Builder;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub struct Connection<'a>(ConnectionSettingsProxy<'a>);
|
pub struct Connection<'a>(ConnectionSettingsProxy<'a>);
|
||||||
|
|
@ -18,3 +19,88 @@ impl<'a> From<ConnectionSettingsProxy<'a>> for Connection<'a> {
|
||||||
Connection(conn)
|
Connection(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! derive_value_build {
|
||||||
|
($name:ident, $(($arg:ident: $arg_ty:ty)),*) => {
|
||||||
|
#[derive(Builder)]
|
||||||
|
pub struct $name {
|
||||||
|
$(
|
||||||
|
#[builder(setter(into, strip_option))]
|
||||||
|
$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!(
|
||||||
|
ConnectionSettings,
|
||||||
|
(auth_retries: i32),
|
||||||
|
(autoconnect: bool),
|
||||||
|
(autoconnect_priority: i32),
|
||||||
|
(autoconnect_retries: i32),
|
||||||
|
(gateway_ping_timeout: u32),
|
||||||
|
(id: String),
|
||||||
|
(interface_name: String),
|
||||||
|
(lldp: i32),
|
||||||
|
(llmnr: i32),
|
||||||
|
(master: String),
|
||||||
|
(mdns: i32),
|
||||||
|
(mud_url: String),
|
||||||
|
(multi_connect: String),
|
||||||
|
(permissions: Vec<String>),
|
||||||
|
(read_only: bool),
|
||||||
|
(secondaries: Vec<String>),
|
||||||
|
(stable_id: String),
|
||||||
|
(type_: String),
|
||||||
|
(uuid: String),
|
||||||
|
(wait_device_timeout: i32),
|
||||||
|
(zone: String)
|
||||||
|
);
|
||||||
|
|
||||||
|
derive_value_build!(
|
||||||
|
EthernetSettings,
|
||||||
|
(assigned_mac_address: String),
|
||||||
|
(auto_negotiate: bool),
|
||||||
|
(duplex: String),
|
||||||
|
(generate_mac_address_mask: String),
|
||||||
|
(mtu: u32),
|
||||||
|
(port: String),
|
||||||
|
(speed: u32),
|
||||||
|
(wake_on_lan: u32),
|
||||||
|
(wake_on_lan_password: String)
|
||||||
|
);
|
||||||
|
|
||||||
|
derive_value_build!(
|
||||||
|
WifiSettings,
|
||||||
|
(assigned_mac_address: String),
|
||||||
|
(band: String),
|
||||||
|
(bssid: Vec<u8>),
|
||||||
|
(channel: u32),
|
||||||
|
(cloned_mac_address: Vec<u8>),
|
||||||
|
(generate_mac_address_mask: String),
|
||||||
|
(hidden: bool),
|
||||||
|
(mac_address: Vec<u8>),
|
||||||
|
(mac_address_blacklist: Vec<String>),
|
||||||
|
(mac_address_randomization: u32),
|
||||||
|
(mode: String),
|
||||||
|
(mtu: u32),
|
||||||
|
(powersave: u32),
|
||||||
|
(rate: u32),
|
||||||
|
(seen_bssids: Vec<String>),
|
||||||
|
(ssid: Vec<u8>),
|
||||||
|
(tx_power: u32),
|
||||||
|
(wake_on_wlan: u32)
|
||||||
|
);
|
||||||
|
|
||||||
|
derive_value_build!(BluetoothSettings, (bdaddr: Vec<u8>), (type_: String));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue