rillrate_system_protocol/
proclist.rs

1use rill_protocol::flow::core::{Flow, TimedEvent};
2use rill_protocol::flow::location::Location;
3use rill_protocol::io::provider::StreamType;
4use serde::{Deserialize, Serialize};
5use std::collections::BTreeMap;
6
7pub const LOCATION: Location = Location::new("system:proclist");
8
9pub type Pid = usize;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct ProcInfo {
13    pub name: String,
14    // TODO: Sparklines?
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct ProclistState {
19    #[serde(with = "vectorize")]
20    procs: BTreeMap<Pid, ProcInfo>,
21}
22
23#[allow(clippy::new_without_default)]
24impl ProclistState {
25    pub fn new() -> Self {
26        Self {
27            procs: BTreeMap::new(),
28        }
29    }
30}
31
32impl Flow for ProclistState {
33    type Action = ProclistAction;
34    type Event = ProclistEvent;
35
36    fn stream_type() -> StreamType {
37        StreamType::from("rillrate::system::proclist::v0")
38    }
39
40    fn apply(&mut self, event: TimedEvent<Self::Event>) {
41        match event.event {
42            ProclistEvent::InsertProcess { pid, proc_info } => {
43                self.procs.insert(pid, proc_info);
44            }
45            ProclistEvent::RemoveProcess { pid } => {
46                self.procs.remove(&pid);
47            }
48        }
49    }
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub enum ProclistAction {
54    Kill { pid: Pid },
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub enum ProclistEvent {
59    InsertProcess { pid: Pid, proc_info: ProcInfo },
60    RemoveProcess { pid: Pid },
61}