forked from AbleOS/ableos
47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use hashbrown::HashMap;
|
|
|
|
use crate::handle::Handle;
|
|
|
|
use self::{
|
|
channel::Channel,
|
|
socket::{Socket, SocketError},
|
|
};
|
|
|
|
pub mod channel;
|
|
pub mod socket;
|
|
|
|
lazy_static::lazy_static! {
|
|
pub static ref IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
|
|
sockets: HashMap::new(),
|
|
channels: HashMap::new(),
|
|
});
|
|
}
|
|
pub struct IPCService {
|
|
pub sockets: HashMap<Handle, Socket>,
|
|
pub channels: HashMap<Handle, Socket>,
|
|
// TODO: Add a public board of each down below which use some method of pointing to the above
|
|
}
|
|
|
|
// Socket Related Impl
|
|
impl IPCService {
|
|
pub fn create_socket(&mut self) -> Handle {
|
|
let handle = Handle::new(crate::handle::HandleResource::Socket);
|
|
|
|
let sock = Socket::new();
|
|
self.sockets.insert(handle.clone(), sock);
|
|
|
|
handle
|
|
}
|
|
|
|
pub fn send_socket(&mut self, handle: Handle, data: String) -> Result<(), SocketError> {
|
|
let sock = self.sockets.get_mut(&handle);
|
|
|
|
match sock {
|
|
Some(socket) => {
|
|
return socket.write(data);
|
|
}
|
|
None => return Err(SocketError::NonexistantSocket),
|
|
}
|
|
}
|
|
}
|