update/
monitor_updates.rs1use crate::monitor_state::monitor_state;
6use anyhow::Context as _;
7use fidl_fuchsia_update::{
8 AttemptsMonitorMarker, AttemptsMonitorRequest, AttemptsMonitorRequestStream, ManagerMarker,
9};
10use fuchsia_component::client::connect_to_protocol;
11use futures::prelude::*;
12
13pub async fn handle_monitor_updates_cmd() -> Result<(), anyhow::Error> {
14 let update_manager =
15 connect_to_protocol::<ManagerMarker>().context("Failed to connect to update manager")?;
16
17 let (client_end, request_stream) =
18 fidl::endpoints::create_request_stream::<AttemptsMonitorMarker>();
19
20 if let Err(e) = update_manager.monitor_all_update_checks(client_end) {
21 anyhow::bail!("Failed to monitor all update checks: {:?}", e);
22 }
23 monitor_all(request_stream).await?;
24 Ok(())
25}
26
27async fn monitor_all(mut stream: AttemptsMonitorRequestStream) -> Result<(), anyhow::Error> {
28 while let Some(event) = stream.try_next().await? {
29 match event {
30 AttemptsMonitorRequest::OnStart { options, monitor, responder } => {
31 responder.send()?;
32
33 match options.initiator {
34 Some(initiator) => {
35 println!("{initiator:?} started an update attempt")
36 }
37 None => println!("an update attempt was started"),
38 }
39 if let Err(e) = monitor_state(monitor.into_stream()).await {
40 eprintln!("Error: {e:?}");
41 }
42 }
43 }
44 }
45 Ok(())
46}