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