2022-01-22 00:01:16 -06:00
|
|
|
use log::LevelFilter;
|
2022-01-22 01:26:25 -06:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-01-22 00:01:16 -06:00
|
|
|
|
|
|
|
#[derive(Serialize, Debug, Deserialize)]
|
|
|
|
pub enum LogLevel {
|
|
|
|
/// A level lower than all log levels.
|
|
|
|
Off,
|
|
|
|
/// Corresponds to the `Error` log level.
|
|
|
|
Error,
|
|
|
|
/// Corresponds to the `Warn` log level.
|
|
|
|
Warn,
|
|
|
|
/// Corresponds to the `Info` log level.
|
|
|
|
Info,
|
|
|
|
/// Corresponds to the `Debug` log level.
|
|
|
|
Debug,
|
|
|
|
/// Corresponds to the `Trace` log level.
|
|
|
|
Trace,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Debug, Deserialize)]
|
2022-03-11 13:51:47 -06:00
|
|
|
pub struct KernelConfig {
|
|
|
|
pub boot: BootConfig,
|
|
|
|
pub logging: LoggingConfig,
|
|
|
|
pub tests: TestsConfig,
|
2022-01-22 00:01:16 -06:00
|
|
|
}
|
|
|
|
|
2022-03-11 13:51:47 -06:00
|
|
|
impl KernelConfig {
|
2022-01-22 00:01:16 -06:00
|
|
|
pub fn new() -> Self {
|
2022-04-11 16:07:01 -05:00
|
|
|
toml::from_str(include_str!("../assets/kernel.toml")).unwrap()
|
2022-01-22 00:01:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log_level(&self) -> LevelFilter {
|
|
|
|
use LevelFilter::*;
|
2022-03-11 13:51:47 -06:00
|
|
|
match self.logging.level {
|
2022-01-22 00:01:16 -06:00
|
|
|
LogLevel::Off => Off,
|
|
|
|
LogLevel::Error => Error,
|
|
|
|
LogLevel::Warn => Warn,
|
|
|
|
LogLevel::Info => Info,
|
|
|
|
LogLevel::Debug => Debug,
|
|
|
|
LogLevel::Trace => Trace,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 13:51:47 -06:00
|
|
|
|
2022-04-11 16:07:01 -05:00
|
|
|
impl Default for KernelConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 13:51:47 -06:00
|
|
|
#[derive(Serialize, Debug, Deserialize)]
|
|
|
|
pub struct LoggingConfig {
|
|
|
|
pub enabled: bool,
|
2022-03-26 06:35:33 -05:00
|
|
|
pub log_to_serial: bool,
|
2022-03-11 13:51:47 -06:00
|
|
|
pub level: LogLevel,
|
2022-07-31 06:21:50 -05:00
|
|
|
pub filter: Vec<String>,
|
2022-03-11 13:51:47 -06:00
|
|
|
}
|
|
|
|
#[derive(Serialize, Debug, Deserialize)]
|
|
|
|
pub struct TestsConfig {
|
|
|
|
pub run_tests: bool,
|
|
|
|
pub run_demos: bool,
|
|
|
|
pub run_shader_tests: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Debug, Deserialize)]
|
|
|
|
pub struct BootConfig {
|
2022-03-11 15:14:35 -06:00
|
|
|
pub system_processes: Vec<String>,
|
|
|
|
pub user_processes: Vec<String>,
|
2022-03-11 13:51:47 -06:00
|
|
|
}
|