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

60 lines
1.1 KiB
Rust
Raw Normal View History

2023-04-12 13:08:07 -05:00
use crate::arch::hardware_random_u64;
use alloc::vec::Vec;
2023-04-07 16:44:33 -05:00
use core::fmt::{self, Formatter};
2023-04-12 13:08:07 -05:00
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub struct OSHandle {
pub id: u64,
}
2023-04-07 16:44:33 -05:00
2023-04-12 13:08:07 -05:00
impl OSHandle {
pub fn new_from_u64(id: u64) -> Self {
Self { id }
}
pub fn random_new() -> Self {
Self {
id: hardware_random_u64(),
}
}
}
2023-04-07 16:44:33 -05:00
2023-04-12 13:08:07 -05:00
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
2023-04-07 16:44:33 -05:00
pub struct Handle {
2023-04-12 13:08:07 -05:00
id: OSHandle,
2023-04-07 16:44:33 -05:00
perms: Permissions,
}
impl Handle {
pub fn new() -> Handle {
Handle {
2023-04-12 13:08:07 -05:00
id: OSHandle::random_new(),
2023-04-07 16:44:33 -05:00
perms: Permissions::new(),
}
}
2023-04-12 13:08:07 -05:00
pub fn as_u64(&self) -> u64 {
self.id.id
}
2023-04-07 16:44:33 -05:00
}
impl fmt::Display for Handle {
fn fmt(&self, w: &mut Formatter<'_>) -> Result<(), core::fmt::Error> {
2023-04-12 13:08:07 -05:00
write!(w, "{:?}", self.id);
2023-04-07 16:44:33 -05:00
Ok(())
}
}
2023-04-12 13:08:07 -05:00
#[derive(PartialEq, Hash, Eq, Debug, Clone, Copy)]
2023-04-07 16:44:33 -05:00
pub struct Permissions {
edit_children: bool,
edit_attributes: bool,
}
impl Permissions {
pub fn new() -> Self {
Self {
edit_children: true,
edit_attributes: true,
}
}
}