kernel/ipc/
mod.rs

1//! Inter-Process Communication (IPC) module
2//!
3//! This module provides various IPC mechanisms for Scarlet OS:
4//! - Stream IPC: Pipes and data streams (StreamIpcOps-based)
5//! - Event IPC: Event distribution with 4 delivery modes (EventOps-based)
6//!   - Immediate: Force delivery (Signal-like)
7//!   - Notification: Best-effort delivery
8//!   - Subscription: Channel-based pub/sub
9//!   - Group: Broadcast delivery
10//! - Message Queues: Structured message passing (future)
11//! - Shared Memory: Memory-based communication
12//! - Sockets: Network and local communication endpoints (future)
13
14use crate::object::capability::{StreamError, StreamOps};
15use alloc::string::String;
16
17pub mod counter;
18pub mod event;
19pub mod pipe;
20pub mod shared_memory;
21pub mod syscall;
22
23/// Represents errors specific to IPC operations
24#[derive(Debug, Clone)]
25pub enum IpcError {
26    /// The other end of the communication channel has been closed
27    PeerClosed,
28    /// The IPC channel is full (for bounded channels)
29    ChannelFull,
30    /// The IPC channel is empty (for non-blocking reads)
31    ChannelEmpty,
32    /// Invalid IPC object state
33    InvalidState,
34    /// Operation not supported by this IPC type
35    NotSupported,
36    /// General stream error
37    StreamError(StreamError),
38    /// Custom error message
39    Other(String),
40}
41
42impl From<StreamError> for IpcError {
43    fn from(stream_err: StreamError) -> Self {
44        IpcError::StreamError(stream_err)
45    }
46}
47
48/// Common trait for stream-based IPC objects
49///
50/// This trait provides common functionality for stream-based IPC mechanisms
51/// that operate as continuous data flows, such as pipes and sockets.
52/// It extends StreamOps with stream-specific IPC state management.
53pub trait StreamIpcOps: StreamOps {
54    /// Check if the stream IPC object is still connected/valid
55    fn is_connected(&self) -> bool;
56
57    /// Get the number of active peers (readers/writers/endpoints)
58    fn peer_count(&self) -> usize;
59
60    /// Get a human-readable description of this IPC object
61    fn description(&self) -> String;
62}
63
64// Future IPC trait definitions:
65
66/// Event channel operations (implements EventSender + EventReceiver capabilities)
67///
68/// This trait defines objects that provide event-based communication
69/// channels with pub/sub semantics, different from stream-based pipes.
70pub trait EventIpcChannelObject: Send + Sync {
71    /// Get channel identifier/name
72    fn channel_id(&self) -> String;
73
74    /// Check if channel is active
75    fn is_active(&self) -> bool;
76
77    /// Get number of subscribers
78    fn subscriber_count(&self) -> usize;
79}
80
81/// Message queue operations (future implementation)
82pub trait MessageQueueObject: StreamIpcOps {
83    // Message-based communication methods will be defined here
84}
85
86/// Socket operations (future implementation)
87pub trait SocketObject: StreamIpcOps {
88    // Socket-specific methods will be defined here
89}
90
91// Re-export commonly used types
92pub use event::{
93    Event, EventContent, EventDelivery, EventError, EventManager, EventPayload, GroupTarget,
94};
95pub use pipe::{PipeEndpoint, PipeError, PipeObject, UnidirectionalPipe};
96pub use shared_memory::{SharedMemory, SharedMemoryObject};