1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/ableos/src/handle.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2022-07-28 03:39:20 -05:00
//! A handle is a u128 with a set of permissions
//! and a resource connected to it
use crate::Path;
use crate::{arch::generate_process_pass, channels::Channel};
use core::fmt::Display;
#[derive(Debug)]
pub struct BinaryData {
name: String,
data: Vec<u8>,
}
2022-07-28 20:15:02 -05:00
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
2022-07-28 03:39:20 -05:00
pub enum HandleResource {
2022-07-28 20:15:02 -05:00
Channel,
Socket,
BinaryData,
2022-07-28 03:39:20 -05:00
}
2022-07-28 20:15:02 -05:00
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
2022-07-28 03:39:20 -05:00
pub struct Handle {
inner: u128,
res: HandleResource,
}
impl Display for Handle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Handle-{:032x}", self.inner)?;
match &self.res {
2022-07-28 20:15:02 -05:00
HandleResource::Channel => write!(f, "-Channel")?,
HandleResource::BinaryData => write!(f, "-Binary")?,
Socket => write!(f, "-Socket")?,
2022-07-28 03:39:20 -05:00
}
Ok(())
}
}
use crate::handle::HandleResource::*;
impl Handle {
2022-07-28 20:15:02 -05:00
pub fn new(htype: HandleResource) -> Self {
2022-07-28 03:39:20 -05:00
Self {
inner: generate_process_pass(),
2022-07-28 20:15:02 -05:00
res: htype,
2022-07-28 03:39:20 -05:00
}
}
}