omaha_client/state_machine/
observer.rs
1use crate::{
10 common::{ProtocolState, UpdateCheckSchedule},
11 installer::ProgressObserver,
12 protocol::response::Response,
13 state_machine::{update_check, State, UpdateCheckError},
14};
15use futures::{channel::mpsc, future::BoxFuture, prelude::*};
16
17#[derive(Debug)]
19pub enum StateMachineEvent {
20 StateChange(State),
21 ScheduleChange(UpdateCheckSchedule),
22 ProtocolStateChange(ProtocolState),
23 UpdateCheckResult(Result<update_check::Response, UpdateCheckError>),
24 InstallProgressChange(InstallProgress),
25 OmahaServerResponse(Response),
26 InstallerError(Option<Box<dyn std::error::Error + Send + 'static>>),
27}
28
29#[derive(Debug)]
30pub struct InstallProgress {
31 pub progress: f32,
32}
33
34pub(super) struct StateMachineProgressObserver(pub(super) mpsc::Sender<InstallProgress>);
35
36impl ProgressObserver for StateMachineProgressObserver {
37 fn receive_progress(
38 &self,
39 _operation: Option<&str>,
40 progress: f32,
41 _total_size: Option<u64>,
42 _size_so_far: Option<u64>,
43 ) -> BoxFuture<'_, ()> {
44 async move {
45 let _ = self.0.clone().send(InstallProgress { progress }).await;
46 }
47 .boxed()
48 }
49}