-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(update-agent): publishing update-agent progress to dbus (#349)
* feat(update-agent): publishing update-agent progress to dbus * adding detailed reporting * ryan review 1 * review vol 2 * missing signal * Working Signals * review vol 3 --------- Co-authored-by: Ryan Butler <thebutlah@gmail.com>
- Loading branch information
1 parent
d61e38e
commit 9a58dd1
Showing
10 changed files
with
297 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "orb-update-agent-dbus" | ||
version = "0.0.0" | ||
authors = ["Theodore Sfikas <theodore.sfikas@toolsforhumanity.com>"] | ||
description = "Dbus proxy and interface for orb-update-agent" | ||
publish = false | ||
|
||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
zbus.workspace = true | ||
serde.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Query the current update status: | ||
//! ```bash | ||
//! gdbus call --session -d org.worldcoin.UpdateAgentManager1 -o \ | ||
//! '/org/worldcoin/UpdateAgentManager1' -m \ | ||
//! org.freedesktop.DBus.Properties.Get org.worldcoin.UpdateAgentManager1 Progress | ||
//! ``` | ||
//! | ||
//! Monitor for signals: | ||
//! ```bash | ||
//! export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/worldcoin_bus_socket | ||
//! dbus-monitor --session type='signal',sender='org.worldcoin.UpdateAgentManager1' | ||
//! ``` | ||
use serde::{Deserialize, Serialize}; | ||
use zbus::interface; | ||
use zbus::zvariant::{OwnedValue, Type, Value}; | ||
|
||
/// A trait representing update progress behavior. | ||
/// | ||
/// This trait is implemented by types that can provide information about the current update status. | ||
/// It abstracts the behavior to allow multiple implementations, enabling dependency injection, | ||
/// mocking for tests, and sharing the same interface across both client and server code. | ||
pub trait UpdateAgentManagerT: Send + Sync + 'static { | ||
fn progress(&self) -> Vec<ComponentStatus>; | ||
} | ||
|
||
/// A wrapper struct for types implementing [`UpdateAgentManagerT`]. | ||
pub struct UpdateAgentManager<T>(pub T); | ||
|
||
#[derive( | ||
Debug, Serialize, Deserialize, Type, Clone, Copy, Eq, PartialEq, Value, OwnedValue, | ||
)] | ||
pub enum ComponentState { | ||
None = 1, | ||
Downloading = 2, | ||
Fetched = 3, | ||
Processed = 4, | ||
Installed = 5, | ||
} | ||
|
||
#[derive( | ||
Debug, Serialize, Deserialize, Type, Eq, PartialEq, Clone, Value, OwnedValue, | ||
)] | ||
pub struct ComponentStatus { | ||
/// Component Name | ||
pub name: String, | ||
/// Current state of acomponent | ||
pub state: ComponentState, | ||
/// Progress through the current state (0-100) | ||
pub progress: u8, | ||
} | ||
|
||
/// DBus interface implementation for [`UpdateProgress`]. | ||
#[interface( | ||
name = "org.worldcoin.UpdateAgentManager1", | ||
proxy( | ||
default_service = "org.worldcoin.UpdateAgentManager1", | ||
default_path = "/org/worldcoin/UpdateAgentManager1", | ||
) | ||
)] | ||
impl<T: UpdateAgentManagerT> UpdateAgentManagerT for UpdateAgentManager<T> { | ||
#[zbus(property)] | ||
fn progress(&self) -> Vec<ComponentStatus> { | ||
self.0.progress() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use eyre::WrapErr; | ||
use orb_update_agent_core::ManifestComponent; | ||
use orb_update_agent_dbus::{ | ||
ComponentState, ComponentStatus, UpdateAgentManager, UpdateAgentManagerT, | ||
}; | ||
use zbus::blocking::object_server::InterfaceRef; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct UpdateProgress { | ||
pub components: Vec<ComponentStatus>, | ||
} | ||
|
||
impl UpdateAgentManagerT for UpdateProgress { | ||
fn progress(&self) -> Vec<ComponentStatus> { | ||
self.components.clone() | ||
} | ||
} | ||
|
||
pub fn init_dbus_properties( | ||
components: &[ManifestComponent], | ||
iface: &InterfaceRef<UpdateAgentManager<UpdateProgress>>, | ||
) { | ||
iface.get_mut().0.components = components | ||
.iter() | ||
.map(|c| ComponentStatus { | ||
name: c.name.clone(), | ||
state: ComponentState::None, | ||
progress: 0, | ||
}) | ||
.collect(); | ||
} | ||
|
||
pub fn update_dbus_properties( | ||
name: &str, | ||
state: ComponentState, | ||
progress: u8, | ||
iface: &InterfaceRef<UpdateAgentManager<UpdateProgress>>, | ||
) -> eyre::Result<()> { | ||
if let Some(component) = iface | ||
.get_mut() | ||
.0 | ||
.components | ||
.iter_mut() | ||
.find(|c| c.name == name) | ||
{ | ||
component.state = state; | ||
component.progress = progress; | ||
} | ||
zbus::block_on(iface.get_mut().progress_changed(iface.signal_context())) | ||
.wrap_err("Failed to emit progress_changed signal")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod interfaces; | ||
pub mod proxies; |
File renamed without changes.
Oops, something went wrong.