Skip to content

Commit

Permalink
Move MacAddress string conversion to dbus interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Dec 5, 2023
1 parent db9a040 commit b27645f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 5 additions & 3 deletions rust/agama-dbus-server/src/network/dbus/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use super::ObjectsRegistry;
use crate::network::{
action::Action,
error::NetworkStateError,
model::{Connection as NetworkConnection, Device as NetworkDevice, WirelessConnection},
model::{
Connection as NetworkConnection, Device as NetworkDevice, MacAddress, WirelessConnection,
},
};

use agama_lib::network::types::SSID;
use std::sync::Arc;
use std::{str::FromStr, sync::Arc};
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::{MappedMutexGuard, Mutex, MutexGuard};
use zbus::{
Expand Down Expand Up @@ -248,7 +250,7 @@ impl Connection {
#[dbus_interface(property)]
pub async fn set_mac_address(&mut self, mac_address: &str) -> zbus::fdo::Result<()> {
let mut connection = self.get_connection().await;
connection.set_mac_address(mac_address)?;
connection.set_mac_address(MacAddress::from_str(mac_address)?);
self.update_connection(connection).await
}
}
Expand Down
5 changes: 2 additions & 3 deletions rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ impl Connection {
self.base().mac_address.to_string()
}

pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> {
self.base_mut().mac_address = MacAddress::from_str(mac_address)?;
Ok(())
pub fn set_mac_address(&mut self, mac_address: MacAddress) {
self.base_mut().mac_address = mac_address;
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ mod test {

let mut updated = Connection::Ethernet(EthernetConnection::default());
updated.set_interface("");
assert!(updated.set_mac_address("").is_ok());
updated.set_mac_address(MacAddress::Unset);
let updated = connection_to_dbus(&updated);

let merged = merge_dbus_connections(&original, &updated);
Expand Down

0 comments on commit b27645f

Please sign in to comment.