implementing rough ipc

This commit is contained in:
able 2022-07-28 10:57:28 -05:00
parent 3a93907251
commit f6d0c71a24
5 changed files with 103 additions and 6 deletions

View file

@ -19,18 +19,13 @@ pub struct ChannelPermission {
#[derive(Debug)] #[derive(Debug)]
pub struct Channel { pub struct Channel {
inner: VecDeque<u8>, inner: VecDeque<u8>,
// TODO(able): change this to a hashmap i think
permission_list: Vec<(PID, ChannelPermission)>,
} }
impl Channel { impl Channel {
pub fn new() -> Self { pub fn new() -> Self {
let deq = VecDeque::from([]); let deq = VecDeque::from([]);
Self { Self { inner: deq }
inner: deq,
permission_list: vec![],
}
} }
pub fn read(&mut self) -> Result<u8, ChannelError> { pub fn read(&mut self) -> Result<u8, ChannelError> {

54
ableos/src/ipc/channel.rs Normal file
View file

@ -0,0 +1,54 @@
use alloc::collections::VecDeque;
#[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 {
// public: bool,
inner: VecDeque<ChannelMessage>,
}
impl Channel {
pub fn new() -> Self {
let deq = VecDeque::from([]);
Self { inner: deq }
}
pub fn read(&mut self) -> Result<ChannelMessage, ChannelError> {
if let Some(msg) = self.inner.pop_front() {
return Ok(msg);
}
return Err(ChannelError::EmptyBuffer);
}
pub fn send(&mut self, data: ChannelMessage) {
self.inner.push_back(data);
}
}
pub enum ChannelError {
EmptyBuffer,
InvalidPermissions,
}
#[derive(Debug)]
pub struct ChannelMessage {
inner: [u8; 4096],
}
impl ChannelMessage {
pub fn new(data: [u8; 4096]) -> Self {
Self { inner: data }
}
pub fn from_string() {}
}

16
ableos/src/ipc/mod.rs Normal file
View file

@ -0,0 +1,16 @@
use self::{channel::Channel, socket::Socket};
pub mod channel;
pub mod socket;
pub static IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
sockets: vec![],
channels: vec![],
});
pub struct IPCService {
pub sockets: Vec<Socket>,
pub channels: Vec<Channel>,
// TODO: Add a public board of each down below which use some method of pointing to the above
}
impl IPCService {}

31
ableos/src/ipc/socket.rs Normal file
View file

@ -0,0 +1,31 @@
// SEEALSO: https://git.ablecorp.us/able/ableos/src/branch/master/ableos/src/relib/network/socket.rs
pub enum SocketError {
EmptySocket,
}
pub struct Socket {
stream: Vec<u8>,
}
impl Socket {
pub fn new() -> Self {
Self { stream: vec![] }
}
pub fn write(&mut self, data: String) -> Result<(), SocketError> {
for c in data.chars() {
self.stream.push(c as u8);
}
Ok(())
}
pub fn read(&mut self) -> Result<Vec<u8>, SocketError> {
if self.stream.len() != 0 {
let skt = self.stream.clone();
self.stream = vec![];
return Ok(skt);
}
return Err(SocketError::EmptySocket);
}
}

View file

@ -69,6 +69,7 @@ pub mod allocator;
// pub use allocator as aalloc; // pub use allocator as aalloc;
pub mod channels; pub mod channels;
pub mod handle; pub mod handle;
pub mod ipc;
mod unicode_utils; mod unicode_utils;
pub mod vga_e; pub mod vga_e;