diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index d3159c82aec89f2d63ea6b11a71917be3a285417..4aea4d03e2928f658de0827159de084f48b5e5dc 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -10,7 +10,7 @@ pub(crate) struct Scheduler { runtime: Arc, polling: PollingClient, scheduler_id: u32, - debug_logging: bool, + log_level: LogLevel, } pub(crate) struct SchedulerCtx<'a> { @@ -18,36 +18,48 @@ pub(crate) struct SchedulerCtx<'a> { pub polling: &'a PollingClient, pub id: u32, pub comp: u32, - pub logging_enabled: bool, + pub log_level: LogLevel, } impl<'a> SchedulerCtx<'a> { - pub fn new(runtime: &'a RuntimeInner, polling: &'a PollingClient, id: u32, logging_enabled: bool) -> Self { + pub fn new(runtime: &'a RuntimeInner, polling: &'a PollingClient, id: u32, log_level: LogLevel) -> Self { return Self { runtime, polling, id, comp: 0, - logging_enabled, + log_level, } } - pub(crate) fn log(&self, text: &str) { - if self.logging_enabled { + pub(crate) fn debug(&self, text: &str) { + // TODO: Probably not always use colour + if LogLevel::Debug >= self.log_level { + println!("[s:{:02}, c:{:03}] \x1b[0;36m{}\x1b[0m", self.id, self.comp, text); + } + } + + pub(crate) fn info(&self, text: &str) { + if LogLevel::Info >= self.log_level { println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text); } } + + pub(crate) fn error(&self, text: &str) { + // TODO: Probably not always use colour + println!("[s:{:02}, c:{:03}] \x1b[0;31m{}\x1b[0m", self.id, self.comp, text); + } } impl Scheduler { // public interface to thread - pub fn new(runtime: Arc, polling: PollingClient, scheduler_id: u32, debug_logging: bool) -> Self { - return Scheduler{ runtime, polling, scheduler_id, debug_logging } + pub fn new(runtime: Arc, polling: PollingClient, scheduler_id: u32, log_level: LogLevel) -> Self { + return Scheduler{ runtime, polling, scheduler_id, log_level } } pub fn run(&mut self) { - let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, &self.polling, self.scheduler_id, self.debug_logging); + let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, &self.polling, self.scheduler_id, self.log_level); 'run_loop: loop { // Wait until we have something to do (or need to quit) @@ -67,7 +79,7 @@ impl Scheduler { while let Some(message) = component.inbox.pop() { component.component.handle_message(&mut scheduler_ctx, &mut component.ctx, message); } - new_scheduling = component.component.run(&mut scheduler_ctx, &mut component.ctx).expect("TODO: Handle error"); + new_scheduling = component.component.run(&mut scheduler_ctx, &mut component.ctx); } // Handle the new scheduling