diff --git a/ableos/src/channels.rs b/ableos/src/channels.rs index 540a0d6f..7db1f60e 100644 --- a/ableos/src/channels.rs +++ b/ableos/src/channels.rs @@ -19,18 +19,13 @@ pub struct ChannelPermission { #[derive(Debug)] pub struct Channel { inner: VecDeque, - // TODO(able): change this to a hashmap i think - permission_list: Vec<(PID, ChannelPermission)>, } impl Channel { pub fn new() -> Self { let deq = VecDeque::from([]); - Self { - inner: deq, - permission_list: vec![], - } + Self { inner: deq } } pub fn read(&mut self) -> Result { diff --git a/ableos/src/ipc/channel.rs b/ableos/src/ipc/channel.rs new file mode 100644 index 00000000..33daa452 --- /dev/null +++ b/ableos/src/ipc/channel.rs @@ -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, +} + +impl Channel { + pub fn new() -> Self { + let deq = VecDeque::from([]); + + Self { inner: deq } + } + + pub fn read(&mut self) -> Result { + 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() {} +} diff --git a/ableos/src/ipc/mod.rs b/ableos/src/ipc/mod.rs new file mode 100644 index 00000000..519f906f --- /dev/null +++ b/ableos/src/ipc/mod.rs @@ -0,0 +1,16 @@ +use self::{channel::Channel, socket::Socket}; + +pub mod channel; +pub mod socket; + +pub static IPC: spin::Mutex = spin::Mutex::new(IPCService { + sockets: vec![], + channels: vec![], +}); + +pub struct IPCService { + pub sockets: Vec, + pub channels: Vec, + // TODO: Add a public board of each down below which use some method of pointing to the above +} +impl IPCService {} diff --git a/ableos/src/ipc/socket.rs b/ableos/src/ipc/socket.rs new file mode 100644 index 00000000..5cd7d4aa --- /dev/null +++ b/ableos/src/ipc/socket.rs @@ -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, +} + +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, SocketError> { + if self.stream.len() != 0 { + let skt = self.stream.clone(); + self.stream = vec![]; + + return Ok(skt); + } + return Err(SocketError::EmptySocket); + } +} diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index af1a9cb5..5a6fab0a 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -69,6 +69,7 @@ pub mod allocator; // pub use allocator as aalloc; pub mod channels; pub mod handle; +pub mod ipc; mod unicode_utils; pub mod vga_e;