orchflow_terminal/
ipc_trait.rs

1//! IPC abstraction layer for terminal communication
2//!
3//! This trait allows OrchFlow to work with any transport mechanism.
4
5use crate::protocol::{ControlMessage, TerminalInput};
6use crate::pty_manager::PtyHandle;
7use async_trait::async_trait;
8
9/// Trait for IPC communication channels
10#[async_trait]
11pub trait IpcChannel: Send + Sync {
12    /// Start streaming terminal output
13    async fn start_streaming(
14        &self,
15        terminal_id: String,
16        pty_handle: PtyHandle,
17    ) -> Result<(), Box<dyn std::error::Error>>;
18
19    /// Send input to terminal
20    async fn send_input(
21        &self,
22        terminal_id: &str,
23        input: TerminalInput,
24    ) -> Result<(), Box<dyn std::error::Error>>;
25
26    /// Send control message
27    async fn send_control(
28        &self,
29        terminal_id: &str,
30        message: ControlMessage,
31    ) -> Result<(), Box<dyn std::error::Error>>;
32
33    /// Stop streaming
34    async fn stop_streaming(&self, terminal_id: &str) -> Result<(), Box<dyn std::error::Error>>;
35}
36
37/// Direct in-process channel (no IPC overhead)
38pub struct DirectChannel;
39
40#[async_trait]
41impl IpcChannel for DirectChannel {
42    async fn start_streaming(
43        &self,
44        _terminal_id: String,
45        _pty_handle: PtyHandle,
46    ) -> Result<(), Box<dyn std::error::Error>> {
47        // In direct mode, the caller handles streaming
48        Ok(())
49    }
50
51    async fn send_input(
52        &self,
53        _terminal_id: &str,
54        _input: TerminalInput,
55    ) -> Result<(), Box<dyn std::error::Error>> {
56        // In direct mode, input is handled directly
57        Ok(())
58    }
59
60    async fn send_control(
61        &self,
62        _terminal_id: &str,
63        _message: ControlMessage,
64    ) -> Result<(), Box<dyn std::error::Error>> {
65        // In direct mode, control is handled directly
66        Ok(())
67    }
68
69    async fn stop_streaming(&self, _terminal_id: &str) -> Result<(), Box<dyn std::error::Error>> {
70        // In direct mode, nothing to stop
71        Ok(())
72    }
73}