kernel/ipc/mod.rs
1//! Inter-Process Communication (IPC) module
2//!
3//! This module provides various IPC mechanisms for Scarlet OS:
4//! - Pipes: Unidirectional and bidirectional data streams
5//! - Message Queues: Structured message passing
6//! - Shared Memory: Memory-based communication
7//! - Sockets: Network and local communication endpoints
8//! - Events: Synchronization and notification primitives
9//! - Semaphores: Resource counting and synchronization
10
11use crate::object::capability::{StreamOps, StreamError};
12use alloc::string::String;
13
14pub mod pipe;
15pub mod syscall;
16
17/// Represents errors specific to IPC operations
18#[derive(Debug, Clone)]
19pub enum IpcError {
20 /// The other end of the communication channel has been closed
21 PeerClosed,
22 /// The IPC channel is full (for bounded channels)
23 ChannelFull,
24 /// The IPC channel is empty (for non-blocking reads)
25 ChannelEmpty,
26 /// Invalid IPC object state
27 InvalidState,
28 /// Operation not supported by this IPC type
29 NotSupported,
30 /// General stream error
31 StreamError(StreamError),
32 /// Custom error message
33 Other(String),
34}
35
36impl From<StreamError> for IpcError {
37 fn from(stream_err: StreamError) -> Self {
38 IpcError::StreamError(stream_err)
39 }
40}
41
42/// Common trait for all IPC objects
43///
44/// This trait provides common functionality that all IPC mechanisms share,
45/// such as connection state management and peer information.
46pub trait IpcObject: StreamOps {
47 /// Check if the IPC object is still connected/valid
48 fn is_connected(&self) -> bool;
49
50 /// Get the number of active peers (readers/writers/endpoints)
51 fn peer_count(&self) -> usize;
52
53 /// Get a human-readable description of this IPC object
54 fn description(&self) -> String;
55}
56
57// Future IPC trait definitions:
58
59/// Message queue operations (future implementation)
60pub trait MessageQueueObject: IpcObject {
61 // Message-based communication methods will be defined here
62}
63
64/// Shared memory operations (future implementation)
65pub trait SharedMemoryObject: IpcObject {
66 // Shared memory methods will be defined here
67}
68
69/// Socket operations (future implementation)
70pub trait SocketObject: IpcObject {
71 // Socket-specific methods will be defined here
72}
73
74// Re-export commonly used types
75pub use pipe::{PipeEndpoint, UnidirectionalPipe, PipeError, PipeObject};