duende_platform/
adapter.rs1use async_trait::async_trait;
7
8use duende_core::{Daemon, DaemonStatus, Signal};
9
10use crate::detect::Platform;
11use crate::error::Result;
12
13#[derive(Debug, Clone)]
15pub struct DaemonHandle {
16 pub platform: Platform,
18 pub id: String,
20 pub pid: Option<u32>,
22}
23
24impl DaemonHandle {
25 #[must_use]
27 pub fn native(pid: u32) -> Self {
28 Self {
29 platform: Platform::Native,
30 id: pid.to_string(),
31 pid: Some(pid),
32 }
33 }
34
35 #[must_use]
37 pub fn systemd(unit_name: impl Into<String>) -> Self {
38 Self {
39 platform: Platform::Linux,
40 id: unit_name.into(),
41 pid: None,
42 }
43 }
44
45 #[must_use]
47 pub fn launchd(label: impl Into<String>) -> Self {
48 Self {
49 platform: Platform::MacOS,
50 id: label.into(),
51 pid: None,
52 }
53 }
54
55 #[must_use]
57 pub fn container(container_id: impl Into<String>) -> Self {
58 Self {
59 platform: Platform::Container,
60 id: container_id.into(),
61 pid: None,
62 }
63 }
64
65 #[must_use]
67 pub fn pepita(vm_id: impl Into<String>) -> Self {
68 Self {
69 platform: Platform::PepitaMicroVM,
70 id: vm_id.into(),
71 pid: None,
72 }
73 }
74
75 #[must_use]
77 pub fn wos(process_id: u32) -> Self {
78 Self {
79 platform: Platform::Wos,
80 id: process_id.to_string(),
81 pid: Some(process_id),
82 }
83 }
84}
85
86#[derive(Debug)]
88pub struct TracerHandle {
89 pub platform: Platform,
91 pub id: String,
93}
94
95#[async_trait]
100pub trait PlatformAdapter: Send + Sync {
101 fn platform(&self) -> Platform;
103
104 async fn spawn(&self, daemon: Box<dyn Daemon>) -> Result<DaemonHandle>;
109
110 async fn signal(&self, handle: &DaemonHandle, sig: Signal) -> Result<()>;
115
116 async fn status(&self, handle: &DaemonHandle) -> Result<DaemonStatus>;
121
122 async fn attach_tracer(&self, handle: &DaemonHandle) -> Result<TracerHandle>;
127}