diff --git a/rust/agama-dbus-server/src/dbus/interfaces/progress.rs b/rust/agama-dbus-server/src/dbus/interfaces/progress.rs index 931b727c67..be95aaf446 100644 --- a/rust/agama-dbus-server/src/dbus/interfaces/progress.rs +++ b/rust/agama-dbus-server/src/dbus/interfaces/progress.rs @@ -1,34 +1,26 @@ use async_std::channel::Receiver; -use zbus::{dbus_interface, Connection, InterfaceRef}; +use zbus::{dbus_interface, Connection, SignalContext}; use crate::error::Error; pub struct Progress { - path: String, - connection: Connection, total_steps: u8, } impl Progress { - pub fn new(path: &str, connection: Connection) -> Self { + pub fn new() -> Self { Self { - path: path.to_string(), - connection, total_steps: 0, } } - // pub async fn update(&self, reference: InterfaceRef, value: u8) -> Result<(), Error> { - pub async fn update(&mut self, value: u8) -> Result<(), Error> { - println!("*** updated: {}", value); - + // pub async fn update(&mut self, reference: InterfaceRef, value: u8) -> Result<(), Error> { + pub async fn set_total_steps( + &mut self, + value: u8, + signal_context: &SignalContext<'_> + ) -> Result<(), Error> { self.total_steps = value; - - // let _iface_ref = self.connection.object_server().interface::<_, Progress>(self.path.as_str()).await?; - // println!("step1"); - // let iface = reference.get_mut().await; - // println!("step2"); - // iface.total_steps_changed(reference.signal_context()).await?; - // println!("step3"); + self.total_steps_changed(signal_context).await?; Ok(()) } @@ -47,7 +39,7 @@ pub async fn add_interface( connection: &Connection, rx: Receiver, ) -> Result<(), Box> { - let progress = Progress::new(path, connection.clone()); + let progress = Progress::new(); connection.object_server().at(path, progress).await?; let iface_ref = connection.object_server().interface::<_, Progress>(path).await?; @@ -56,9 +48,7 @@ pub async fn add_interface( let mut iface = iface_ref.get_mut().await; while let Ok(value) = rx.recv().await { - println!("receive"); - iface.update(value).await.unwrap(); - iface.total_steps_changed(iface_ref.signal_context()).await.unwrap(); + iface.set_total_steps(value, iface_ref.signal_context()).await.unwrap(); } });