a3s_box_sdk/client/
config.rs1#[derive(Clone)]
3pub struct A3sBoxClient {
4 paths: A3sBoxPaths,
5 image_cache_size: u64,
6 execution_manager: Arc<dyn ExecutionManager>,
7 execution_session_manager: Option<Arc<dyn ExecutionSessionManager>>,
8}
9
10impl std::fmt::Debug for A3sBoxClient {
11 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 formatter
13 .debug_struct("A3sBoxClient")
14 .field("paths", &self.paths)
15 .field("image_cache_size", &self.image_cache_size)
16 .finish_non_exhaustive()
17 }
18}
19
20impl A3sBoxClient {
21 pub fn new() -> Self {
23 Self::default()
24 }
25
26 pub fn from_home(home: impl Into<PathBuf>) -> Self {
28 Self::with_paths(A3sBoxPaths::from_home(home))
29 }
30
31 pub fn with_paths(paths: A3sBoxPaths) -> Self {
33 let local_execution_manager = Arc::new(
34 a3s_box_runtime::LocalExecutionManager::with_vm_backend(
35 paths.boxes_file.clone(),
36 paths.home.clone(),
37 ),
38 );
39 Self {
40 paths,
41 image_cache_size: a3s_box_runtime::DEFAULT_IMAGE_CACHE_SIZE,
42 execution_manager: local_execution_manager.clone(),
43 execution_session_manager: Some(local_execution_manager),
44 }
45 }
46
47 pub fn with_execution_manager(
53 paths: A3sBoxPaths,
54 execution_manager: Arc<dyn ExecutionManager>,
55 ) -> Self {
56 Self {
57 paths,
58 image_cache_size: a3s_box_runtime::DEFAULT_IMAGE_CACHE_SIZE,
59 execution_manager,
60 execution_session_manager: None,
61 }
62 }
63
64 pub fn with_execution_services(
69 paths: A3sBoxPaths,
70 execution_manager: Arc<dyn ExecutionManager>,
71 execution_session_manager: Arc<dyn ExecutionSessionManager>,
72 ) -> Self {
73 Self {
74 paths,
75 image_cache_size: a3s_box_runtime::DEFAULT_IMAGE_CACHE_SIZE,
76 execution_manager,
77 execution_session_manager: Some(execution_session_manager),
78 }
79 }
80
81 pub fn with_image_cache_size(mut self, image_cache_size: u64) -> Self {
83 self.image_cache_size = image_cache_size;
84 self
85 }
86
87 pub fn paths(&self) -> &A3sBoxPaths {
89 &self.paths
90 }
91
92 pub fn runtime_diagnostics(&self) -> RuntimeDiagnostics {
94 RuntimeDiagnostics::collect(&self.paths)
95 }
96
97 pub fn runtime_disk_usage(&self) -> Result<RuntimeDiskUsage> {
99 RuntimeDiskUsage::collect(&self.paths)
100 }
101}
102
103impl Default for A3sBoxClient {
104 fn default() -> Self {
105 Self::with_paths(A3sBoxPaths::default())
106 }
107}