ableos/kernel/src/ipc/buffer.rs

71 lines
1.8 KiB
Rust
Raw Normal View History

2023-06-13 06:00:11 -05:00
//!
2023-05-15 02:19:34 -05:00
2023-06-13 06:00:11 -05:00
use {
super::message::Message,
crossbeam_queue::{ArrayQueue, SegQueue},
};
2023-05-15 02:19:34 -05:00
pub enum BufferTypes {
2023-05-15 02:19:34 -05:00
Unbound(SegQueue<Message>),
Bound(ArrayQueue<Message>),
}
2023-06-13 06:00:11 -05:00
/// Interproccess buffer
2023-05-15 02:19:34 -05:00
pub struct IpcBuffer {
protocol: Protocol,
buffer: BufferTypes,
}
impl IpcBuffer {
2023-09-09 02:35:16 -05:00
pub fn new(bounded: bool, length: u64) -> Self {
log::debug!(
"New IPCBuffer\r
bounded: {}\r
length: {:?}\r",
bounded,
length
);
match (bounded, length) {
(false, a) => {
let buftype = BufferTypes::Unbound(SegQueue::new());
Self {
protocol: Protocol {},
buffer: buftype,
}
}
(true, length) => {
let buftype = BufferTypes::Bound(ArrayQueue::new(length as usize));
Self {
protocol: Protocol {},
buffer: buftype,
}
}
}
}
2023-06-13 06:00:11 -05:00
/// Validate a message to match the `IPC.protocol`
pub fn validate_messages(&mut self) -> Result<(), IpcError> {
Ok(())
}
}
2023-06-13 06:00:11 -05:00
/// Interprocess Communication Errors
pub enum IpcError {
2023-06-13 06:00:11 -05:00
/// An invalid message error returned to the sender
InvalidMessage,
}
/// TODO: define this, possibly as the binary form of the IDL
/// DEPEND: This depends on an IDL
pub struct Protocol {
// TODO: add in settings
// like `invalid_message_handler` with some options similar to
// `Deny` Drops the message
// `Allow` Allows invalid messages (This disables validators IPC side and relies on programs to handle invalid messages)
// `CustomFunct` a callback
// and `report_invalid_messages_to_sender`
// `True`
// `False`
// settings: PSettings,
}