ctoolbox/workspace/ipc/services/process/
api.rs

1//! Process service API definitions.
2//!
3//! This service provides operations that any process can handle, such as
4//! graceful shutdown of its process tree.
5
6use anyhow::Result;
7use async_trait::async_trait;
8use serde::{Deserialize, Serialize};
9
10/// Service name for process-level operations.
11pub const SERVICE_NAME: &str = "process";
12
13/// Method name for `shutdown_tree`.
14pub const METHOD_SHUTDOWN_TREE: &str = "shutdown_tree";
15
16/// Request to shutdown a process and its children.
17#[derive(Debug, Clone, Default, Serialize, Deserialize)]
18pub struct ShutdownTreeRequest {
19    /// Optional reason for shutdown (for logging/audit).
20    pub reason: Option<String>,
21}
22
23/// Response from `shutdown_tree`.
24#[derive(Debug, Clone, Default, Serialize, Deserialize)]
25pub struct ShutdownTreeResponse {
26    /// Whether the shutdown was acknowledged.
27    pub acknowledged: bool,
28}
29
30/// Trait for process-level service operations.
31///
32/// Any process that participates in the IPC system should implement this
33/// trait to handle graceful shutdown requests.
34#[async_trait]
35pub trait ProcessService: Send + Sync + std::fmt::Debug {
36    /// Request graceful shutdown of this process and its children.
37    async fn shutdown_tree(
38        &self,
39        request: ShutdownTreeRequest,
40    ) -> Result<ShutdownTreeResponse, crate::workspace::ipc::error::Error>;
41}
42
43#[derive(Debug)]
44pub struct MockProcessService;
45
46#[async_trait]
47impl ProcessService for MockProcessService {
48    async fn shutdown_tree(
49        &self,
50        _request: ShutdownTreeRequest,
51    ) -> Result<ShutdownTreeResponse, crate::workspace::ipc::error::Error> {
52        Ok(ShutdownTreeResponse { acknowledged: true })
53    }
54}