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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum HandleResource {
|
|
|
|
Channel(Channel),
|
|
|
|
// Device
|
2022-07-28 05:02:43 -05:00
|
|
|
/// Used for things like files or images or the like
|
2022-07-28 03:39:20 -05:00
|
|
|
BinaryData(BinaryData),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
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 {
|
|
|
|
HandleResource::Channel(_) => write!(f, "-Channel")?,
|
|
|
|
HandleResource::BinaryData(data) => write!(f, "-Binary-{}", &data.name)?,
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use crate::handle::HandleResource::*;
|
|
|
|
impl Handle {
|
|
|
|
pub fn from_channel(channel: Channel) -> Self {
|
|
|
|
Self {
|
|
|
|
inner: generate_process_pass(),
|
|
|
|
res: Channel(channel),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|