43 lines
1.0 KiB
Rust
43 lines
1.0 KiB
Rust
use crate::process::{ProcessKind, ProcessState};
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct ProcessId(pub u32);
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Process {
|
|
pub id: ProcessId,
|
|
pub app_id: u32,
|
|
pub title: String,
|
|
pub kind: ProcessKind,
|
|
pub state: ProcessState,
|
|
}
|
|
|
|
impl Process {
|
|
pub fn new(id: ProcessId, app_id: u32, title: impl Into<String>, kind: ProcessKind) -> Self {
|
|
Self { id, app_id, title: title.into(), kind, state: ProcessState::Created }
|
|
}
|
|
|
|
pub fn mark_running(&mut self) {
|
|
self.state = ProcessState::Running;
|
|
}
|
|
|
|
pub fn mark_suspended(&mut self) {
|
|
self.state = ProcessState::Suspended;
|
|
}
|
|
|
|
pub fn mark_stopped(&mut self) {
|
|
self.state = ProcessState::Stopped;
|
|
}
|
|
|
|
pub fn mark_crashed(&mut self) {
|
|
self.state = ProcessState::Crashed;
|
|
}
|
|
|
|
pub fn is_alive(&self) -> bool {
|
|
matches!(
|
|
self.state,
|
|
ProcessState::Created | ProcessState::Running | ProcessState::Suspended
|
|
)
|
|
}
|
|
}
|