2022-07-28 03:39:20 -05:00
|
|
|
use core::fmt::Display;
|
|
|
|
|
|
|
|
use alloc::collections::VecDeque;
|
|
|
|
use kernel::proccess::PID;
|
|
|
|
|
|
|
|
use crate::{arch::generate_process_pass, handle::Handle};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
|
|
pub struct ChannelPermission {
|
|
|
|
pub owner: bool,
|
|
|
|
pub producer: bool,
|
|
|
|
|
|
|
|
pub consumer: bool,
|
|
|
|
/// Whether or not the process can be destructive about reading
|
|
|
|
pub distructive_consumer: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Channel {
|
|
|
|
inner: VecDeque<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Channel {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
let deq = VecDeque::from([]);
|
|
|
|
|
2022-07-28 10:57:28 -05:00
|
|
|
Self { inner: deq }
|
2022-07-28 03:39:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read(&mut self) -> Result<u8, ChannelError> {
|
|
|
|
if let Some(abc) = self.inner.pop_front() {
|
|
|
|
return Ok(abc);
|
|
|
|
}
|
|
|
|
return Err(ChannelError::EmptyBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn send(&mut self, data: u8) {
|
|
|
|
self.inner.push_back(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum ChannelError {
|
|
|
|
EmptyBuffer,
|
|
|
|
InvalidPermissions,
|
|
|
|
}
|