Skip to content

Commit

Permalink
Expose Software ServiceStatus and Progress APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Mar 13, 2024
1 parent 992acca commit 3586de9
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions rust/agama-server/src/software/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
//! * `software_service` which returns the Axum service.
//! * `software_stream` which offers an stream that emits the software events coming from D-Bus.
use crate::{error::Error, web::Event};
use crate::{
error::Error,
web::{
common::{progress_router, progress_stream, service_status_router, service_status_stream},
Event,
},
};
use agama_lib::{
error::ServiceError,
product::{Product, ProductClient},
Expand Down Expand Up @@ -61,8 +67,24 @@ impl IntoResponse for SoftwareError {
/// * `connection`: D-Bus connection to listen for events.
pub async fn software_stream(dbus: zbus::Connection) -> Result<impl Stream<Item = Event>, Error> {
Ok(StreamExt::merge(
product_changed_stream(dbus.clone()).await?,
patterns_changed_stream(dbus.clone()).await?,
StreamExt::merge(
StreamExt::merge(
product_changed_stream(dbus.clone()).await?,
patterns_changed_stream(dbus.clone()).await?,
),
service_status_stream(
dbus.clone(),
"org.opensuse.Agama.Software1",
"/org/opensuse/Agama/Software1",
)
.await?,
),
progress_stream(
dbus,
"org.opensuse.Agama.Software1",
"/org/opensuse/Agama/Software1",
)
.await,
))
}

Expand Down Expand Up @@ -122,6 +144,12 @@ fn reason_to_selected_by(

/// Sets up and returns the axum service for the software module.
pub async fn software_service(dbus: zbus::Connection) -> Result<Router, ServiceError> {
const DBUS_SERVICE: &'static str = "org.opensuse.Agama.Software1";
const DBUS_PATH: &'static str = "/org/opensuse/Agama/Software1";

let status_router = service_status_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?;
let progress_router = progress_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?;

let product = ProductClient::new(dbus.clone()).await?;
let software = SoftwareClient::new(dbus).await?;
let state = SoftwareState { product, software };
Expand All @@ -131,6 +159,8 @@ pub async fn software_service(dbus: zbus::Connection) -> Result<Router, ServiceE
.route("/proposal", get(proposal))
.route("/config", put(set_config).get(get_config))
.route("/probe", post(probe))
.merge(status_router)
.merge(progress_router)
.with_state(state);
Ok(router)
}
Expand Down

0 comments on commit 3586de9

Please sign in to comment.