#[derive(Clone)]
pub struct A3sBoxClient {
paths: A3sBoxPaths,
image_cache_size: u64,
execution_manager: Arc<dyn ExecutionManager>,
execution_session_manager: Option<Arc<dyn ExecutionSessionManager>>,
}
impl std::fmt::Debug for A3sBoxClient {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("A3sBoxClient")
.field("paths", &self.paths)
.field("image_cache_size", &self.image_cache_size)
.finish_non_exhaustive()
}
}
impl A3sBoxClient {
pub fn new() -> Self {
Self::default()
}
pub fn from_home(home: impl Into<PathBuf>) -> Self {
Self::with_paths(A3sBoxPaths::from_home(home))
}
pub fn with_paths(paths: A3sBoxPaths) -> Self {
let local_execution_manager = Arc::new(
a3s_box_runtime::LocalExecutionManager::with_vm_backend(
paths.boxes_file.clone(),
paths.home.clone(),
),
);
Self {
paths,
image_cache_size: a3s_box_runtime::DEFAULT_IMAGE_CACHE_SIZE,
execution_manager: local_execution_manager.clone(),
execution_session_manager: Some(local_execution_manager),
}
}
pub fn with_execution_manager(
paths: A3sBoxPaths,
execution_manager: Arc<dyn ExecutionManager>,
) -> Self {
Self {
paths,
image_cache_size: a3s_box_runtime::DEFAULT_IMAGE_CACHE_SIZE,
execution_manager,
execution_session_manager: None,
}
}
pub fn with_execution_services(
paths: A3sBoxPaths,
execution_manager: Arc<dyn ExecutionManager>,
execution_session_manager: Arc<dyn ExecutionSessionManager>,
) -> Self {
Self {
paths,
image_cache_size: a3s_box_runtime::DEFAULT_IMAGE_CACHE_SIZE,
execution_manager,
execution_session_manager: Some(execution_session_manager),
}
}
pub fn with_image_cache_size(mut self, image_cache_size: u64) -> Self {
self.image_cache_size = image_cache_size;
self
}
pub fn paths(&self) -> &A3sBoxPaths {
&self.paths
}
pub fn runtime_diagnostics(&self) -> RuntimeDiagnostics {
RuntimeDiagnostics::collect(&self.paths)
}
pub fn runtime_disk_usage(&self) -> Result<RuntimeDiskUsage> {
RuntimeDiskUsage::collect(&self.paths)
}
}
impl Default for A3sBoxClient {
fn default() -> Self {
Self::with_paths(A3sBoxPaths::default())
}
}