capsules_system/
process_policies.rsuse kernel::process;
use kernel::process::Process;
use kernel::process::ProcessFaultPolicy;
pub struct PanicFaultPolicy {}
impl ProcessFaultPolicy for PanicFaultPolicy {
fn action(&self, _: &dyn Process) -> process::FaultAction {
process::FaultAction::Panic
}
}
pub struct StopFaultPolicy {}
impl ProcessFaultPolicy for StopFaultPolicy {
fn action(&self, _: &dyn Process) -> process::FaultAction {
process::FaultAction::Stop
}
}
pub struct StopWithDebugFaultPolicy {}
impl ProcessFaultPolicy for StopWithDebugFaultPolicy {
fn action(&self, process: &dyn Process) -> process::FaultAction {
kernel::debug!(
"Process {} faulted and was stopped.",
process.get_process_name()
);
process::FaultAction::Stop
}
}
pub struct RestartFaultPolicy {}
impl ProcessFaultPolicy for RestartFaultPolicy {
fn action(&self, _: &dyn Process) -> process::FaultAction {
process::FaultAction::Restart
}
}
pub struct RestartWithDebugFaultPolicy {}
impl ProcessFaultPolicy for RestartWithDebugFaultPolicy {
fn action(&self, process: &dyn Process) -> process::FaultAction {
kernel::debug!(
"Process {} faulted and will be restarted.",
process.get_process_name()
);
process::FaultAction::Restart
}
}
pub struct ThresholdRestartFaultPolicy {
threshold: usize,
}
impl ThresholdRestartFaultPolicy {
pub const fn new(threshold: usize) -> ThresholdRestartFaultPolicy {
ThresholdRestartFaultPolicy { threshold }
}
}
impl ProcessFaultPolicy for ThresholdRestartFaultPolicy {
fn action(&self, process: &dyn Process) -> process::FaultAction {
if process.get_restart_count() <= self.threshold {
process::FaultAction::Restart
} else {
process::FaultAction::Stop
}
}
}
pub struct ThresholdRestartThenPanicFaultPolicy {
threshold: usize,
}
impl ThresholdRestartThenPanicFaultPolicy {
pub const fn new(threshold: usize) -> ThresholdRestartThenPanicFaultPolicy {
ThresholdRestartThenPanicFaultPolicy { threshold }
}
}
impl ProcessFaultPolicy for ThresholdRestartThenPanicFaultPolicy {
fn action(&self, process: &dyn Process) -> process::FaultAction {
if process.get_restart_count() <= self.threshold {
process::FaultAction::Restart
} else {
process::FaultAction::Panic
}
}
}