Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 9, 2023
1 parent 4881a14 commit e646fec
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions rust/agama-dbus-server/src/dbus/interfaces/progress.rs
Original file line number Diff line number Diff line change
@@ -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<Progress>, 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<Progress>, 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(())
}
Expand All @@ -47,7 +39,7 @@ pub async fn add_interface(
connection: &Connection,
rx: Receiver<u8>,
) -> Result<(), Box<dyn std::error::Error>> {
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?;
Expand All @@ -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();
}
});

Expand Down

0 comments on commit e646fec

Please sign in to comment.