use crate::{
cup_ecdsa::RequestMetadata, protocol::response::Response, request_builder::RequestParams,
};
use futures::future::{BoxFuture, LocalBoxFuture};
pub mod stub;
pub trait Plan: std::marker::Sized + std::marker::Sync {
fn id(&self) -> String;
}
pub trait Installer {
type InstallPlan: Plan;
type InstallResult;
type Error: std::error::Error + std::marker::Send + std::marker::Sync + 'static;
#[allow(clippy::type_complexity)]
fn perform_install<'a>(
&'a mut self,
install_plan: &'a Self::InstallPlan,
observer: Option<&'a dyn ProgressObserver>,
) -> LocalBoxFuture<'a, (Self::InstallResult, Vec<AppInstallResult<Self::Error>>)>;
fn perform_reboot(&mut self) -> LocalBoxFuture<'_, Result<(), anyhow::Error>>;
fn try_create_install_plan<'a>(
&'a self,
request_params: &'a RequestParams,
request_metadata: Option<&'a RequestMetadata>,
response: &'a Response,
response_bytes: Vec<u8>,
ecdsa_signature: Option<Vec<u8>>,
) -> LocalBoxFuture<'a, Result<Self::InstallPlan, Self::Error>>;
}
#[derive(Debug)]
pub enum AppInstallResult<E> {
Installed,
Deferred,
Failed(E),
}
impl<E> From<Result<(), E>> for AppInstallResult<E> {
fn from(result: Result<(), E>) -> Self {
match result {
Ok(()) => Self::Installed,
Err(e) => Self::Failed(e),
}
}
}
pub trait ProgressObserver: Sync {
fn receive_progress(
&self,
operation: Option<&str>,
progress: f32,
total_size: Option<u64>,
size_so_far: Option<u64>,
) -> BoxFuture<'_, ()>;
}