forked from AbleOS/ableos
CAPS: Changing the printing of caps
This commit is contained in:
parent
b7da4f17c2
commit
340d76fd13
|
@ -1,8 +1,8 @@
|
|||
//! AbleOS capability tree implementation
|
||||
|
||||
use {
|
||||
crate::{tab, utils::TAB},
|
||||
alloc::{
|
||||
format,
|
||||
string::{String, ToString},
|
||||
vec,
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ struct Argument {
|
|||
struct Function {
|
||||
name: String,
|
||||
args: Vec<Argument>,
|
||||
ret: Option<String>,
|
||||
ret: String,
|
||||
}
|
||||
|
||||
struct Capability {
|
||||
|
@ -41,49 +41,57 @@ impl Capability {
|
|||
|
||||
impl fmt::Display for Capability {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Capability: {}\n", self.name)?;
|
||||
write!(f, "Capability: {}\r\n", self.name)?;
|
||||
for function in &self.functions {
|
||||
write!(f, " Function: {}\n", function.name)?;
|
||||
write!(f, "{}Function: {}\r\n", tab!(1), function.name)?;
|
||||
for arg in &function.args {
|
||||
write!(f, " Argument: {} (Type: {})\n", arg.name, arg.type_)?;
|
||||
}
|
||||
if let Some(ret_type) = &function.ret {
|
||||
write!(f, " Return Type: {}\n", ret_type)?;
|
||||
} else {
|
||||
write!(f, " Return Type: None\n")?;
|
||||
write!(
|
||||
f,
|
||||
"{}Argument: {} (Type: {})\r\n",
|
||||
tab!(2),
|
||||
arg.name,
|
||||
arg.type_
|
||||
)?;
|
||||
}
|
||||
write!(f, "{}Return Type: {}\r\n", tab!(2), &function.ret)?;
|
||||
}
|
||||
for sub_capability in &self.sub_capabilities {
|
||||
write!(f, "{}", sub_capability.to_string_with_indentation(2))?;
|
||||
write!(f, "{}{}\r\n", tab!(1), sub_capability)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Capability {
|
||||
fn to_string_with_indentation(&self, level: usize) -> String {
|
||||
let indent = " ".repeat(level);
|
||||
let mut result = format!("{}Capability: {}\n", indent, self.name);
|
||||
for function in &self.functions {
|
||||
result.push_str(&format!("{} Function: {}\n", indent, function.name));
|
||||
for arg in &function.args {
|
||||
result.push_str(&format!(
|
||||
"{} Argument: {} (Type: {})\n",
|
||||
indent, arg.name, arg.type_
|
||||
));
|
||||
}
|
||||
if let Some(ret_type) = &function.ret {
|
||||
result.push_str(&format!("{} Return Type: {}\n", indent, ret_type));
|
||||
} else {
|
||||
result.push_str(&format!("{} Return Type: None\n", indent));
|
||||
}
|
||||
}
|
||||
for sub_capability in &self.sub_capabilities {
|
||||
result.push_str(&sub_capability.to_string_with_indentation(level + 1));
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
// impl Capability {
|
||||
// fn to_string_with_indentation(&self, level: usize) -> String {
|
||||
// let indent = tab!(level);
|
||||
// let mut result = format!("{}Capability: {}\n", indent, self.name);
|
||||
// for function in &self.functions {
|
||||
// result.push_str(&format!(
|
||||
// "{}Function: {}\n",
|
||||
// tab!(indent + 1),
|
||||
// function.name
|
||||
// ));
|
||||
// for arg in &function.args {
|
||||
// result.push_str(&format!(
|
||||
// "{}Argument: {} (Type: {})\n",
|
||||
// tab!(indent + 2),
|
||||
// arg.name,
|
||||
// arg.type_
|
||||
// ));
|
||||
// }
|
||||
// result.push_str(&format!(
|
||||
// "{}Return Type: {}\n",
|
||||
// tab!(indent + 2),
|
||||
// &function.ret
|
||||
// ));
|
||||
// }
|
||||
// for sub_capability in &self.sub_capabilities {
|
||||
// result.push_str(&sub_capability.to_string_with_indentation(level + 1));
|
||||
// }
|
||||
// result
|
||||
// }
|
||||
// }
|
||||
|
||||
struct CapabilityTree {
|
||||
capabilities: Vec<Capability>,
|
||||
|
@ -97,7 +105,8 @@ impl CapabilityTree {
|
|||
}
|
||||
}
|
||||
|
||||
fn example() {
|
||||
/// A super simple capabilities example
|
||||
pub fn example() {
|
||||
let mut capability_tree = Capability::new("VFS".to_string());
|
||||
|
||||
let mut file_management_capability = Capability::new("File Management".to_string());
|
||||
|
@ -113,7 +122,7 @@ fn example() {
|
|||
type_: "String".to_string(),
|
||||
},
|
||||
],
|
||||
ret: Some("FileHandle".to_string()),
|
||||
ret: "FileHandle".to_string(),
|
||||
});
|
||||
file_management_capability.functions.push(Function {
|
||||
name: "ReadFile".to_string(),
|
||||
|
@ -131,7 +140,7 @@ fn example() {
|
|||
type_: "usize".to_string(),
|
||||
},
|
||||
],
|
||||
ret: Some("usize".to_string()),
|
||||
ret: "usize".to_string(),
|
||||
});
|
||||
file_management_capability.functions.push(Function {
|
||||
name: "WriteFile".to_string(),
|
||||
|
@ -145,7 +154,7 @@ fn example() {
|
|||
type_: "&[u8]".to_string(),
|
||||
},
|
||||
],
|
||||
ret: None,
|
||||
ret: "None".to_string(),
|
||||
});
|
||||
|
||||
let mut directory_management_capability = Capability::new("Directory Management".to_string());
|
||||
|
@ -155,7 +164,7 @@ fn example() {
|
|||
name: "path".to_string(),
|
||||
type_: "String".to_string(),
|
||||
}],
|
||||
ret: Some("bool".to_string()),
|
||||
ret: "bool".to_string(),
|
||||
});
|
||||
directory_management_capability.functions.push(Function {
|
||||
name: "ListDirectory".to_string(),
|
||||
|
@ -163,7 +172,7 @@ fn example() {
|
|||
name: "path".to_string(),
|
||||
type_: "String".to_string(),
|
||||
}],
|
||||
ret: Some("Vec<String>".to_string()),
|
||||
ret: "Vec<String>".to_string(),
|
||||
});
|
||||
|
||||
capability_tree
|
||||
|
@ -173,5 +182,5 @@ fn example() {
|
|||
.sub_capabilities
|
||||
.push(directory_management_capability);
|
||||
|
||||
log::debug!("{}", capability_tree);
|
||||
log::debug!("CapTree\r\n{}", capability_tree);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! AbleOS Kernel Entrypoint
|
||||
|
||||
use crate::capabilities;
|
||||
|
||||
// use crate::arch::sloop;
|
||||
use {
|
||||
crate::{
|
||||
|
@ -37,6 +39,8 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
|
|||
// TODO: schedule the filesystem driver from the initramfs
|
||||
// TODO: schedule the init system from the initramfs
|
||||
|
||||
capabilities::example();
|
||||
|
||||
// TODO: change this to a driver
|
||||
{
|
||||
let mut prog = alloc::vec![];
|
||||
|
|
Loading…
Reference in a new issue