1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/ableos/src/scheduler/capabilities.rs
2022-01-27 01:37:12 -06:00

89 lines
1.9 KiB
Rust

use alloc::vec::Vec;
use crate::file::PathRep;
pub type SoundCardID = u8;
pub type DeviceID = u8;
pub type ControllerID = u8;
#[derive(Clone, Debug, PartialEq)]
pub enum FileAccess {
All,
Some(Vec<PathRep>),
None,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ControllerAccess {
All,
Some(Vec<ControllerID>),
None,
}
#[derive(Clone, Debug, PartialEq)]
pub enum SoundCardAccess {
All,
Some(Vec<SoundCardID>),
None,
}
#[derive(Clone, Debug, PartialEq)]
pub enum MouseAccess {
Yes,
No,
}
#[derive(Clone, Debug, PartialEq)]
pub enum KeyboardAccess {
Yes,
No,
}
#[derive(Clone, Debug, PartialEq)]
pub enum NetworkAccess {
Yes,
No,
}
/// A set of capabilities that a process has
#[derive(Clone, Debug, PartialEq)]
pub struct Capabilities {
// TODO: Add more capabilities
pub files: FileAccess,
pub mouse: MouseAccess,
pub keyboard: KeyboardAccess,
pub controllers: ControllerAccess,
pub sound_cards: SoundCardAccess,
pub network_access: NetworkAccess,
}
impl Capabilities {
/// Generate a set of empty capabilities
pub fn empty() -> Self {
Self {
files: FileAccess::None,
mouse: MouseAccess::No,
keyboard: KeyboardAccess::No,
controllers: ControllerAccess::None,
sound_cards: SoundCardAccess::None,
network_access: NetworkAccess::No,
}
}
/// Generate a set of capabilities that allows all access
/// to all devices
///
/// # Safety
/// This is a very dangerous function and should not be used
/// unless you know what you are doing
pub unsafe fn all() -> Self {
Self {
files: FileAccess::All,
mouse: MouseAccess::Yes,
keyboard: KeyboardAccess::Yes,
controllers: ControllerAccess::All,
sound_cards: SoundCardAccess::All,
network_access: NetworkAccess::Yes,
}
}
}