diff --git a/sysf/src/unit.rs b/sysf/src/unit.rs index f4795f0..5f1f791 100644 --- a/sysf/src/unit.rs +++ b/sysf/src/unit.rs @@ -1,11 +1,39 @@ use crate::unit::JobMode::Replace; use crate::time::{TimeSpan, FiniteTimeSpan}; use crate::time::TimeSpan::Infinite; -use crate::unit::UnitState::Stopped; +use crate::unit::UnitState::{Stopped, Unloaded}; use crate::config::Config; use crate::unit::JobMode::{Fail, ReplaceIrreversibly, Isolate, Flush, IgnoreDependencies, IgnoreRequirements}; use crate::unit::CollectMode::{Inactive, InactiveOrFailed}; +#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Clone)] +pub struct UnitHandle { + name: String, + config: Option, +} + +impl UnitHandle { + pub fn is_loaded(&self) -> bool { + self.config.is_some() + } + + pub fn get_state(&self) -> UnitState { + if let Some(unit) = &self.config { + unit.state + } else { + Unloaded + } + } + + pub fn get_config(&self) -> Option<&Unit> { + if let Some(ref unit) = self.config { + Some(unit) + } else { + None + } + } +} + #[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Clone)] pub struct Unit { name: String, @@ -290,6 +318,7 @@ pub enum UnitState { Stopped, Failed, Running, + Unloaded, } #[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Copy, Clone)] @@ -366,6 +395,19 @@ pub enum UnitActionSeverity { Immediate, } +pub enum UnitType { + Service, + Socket, + Device, + Mount, + AutoMount, + Swap, + Target, + Path, + Slice, + Scope, +} + #[cfg(test)] mod tests { use super::*;