sysd_manager_comcontroler/
journal_data.rs1pub const BOOT_IDX: u8 = 200;
2
3#[derive(Clone, Copy, Debug)]
4pub enum JournalEventChunkInfo {
5 NoMore,
6 ChunkMaxReached,
7 Tail,
10 Error,
11}
12
13#[derive(Debug)]
14pub struct JournalEventChunk {
15 events: Vec<JournalEvent>,
16 pub info: JournalEventChunkInfo,
17 pub what_grab: WhatGrab,
18}
19
20impl JournalEventChunk {
21 pub fn new(capacity: usize, what_grab: WhatGrab) -> Self {
22 Self::new_info(capacity, JournalEventChunkInfo::NoMore, what_grab)
23 }
24
25 pub fn new_info(capacity: usize, info: JournalEventChunkInfo, what_grab: WhatGrab) -> Self {
26 let events = Vec::with_capacity(capacity);
27
28 JournalEventChunk {
29 events,
30 info,
31 what_grab,
32 }
33 }
34
35 pub fn error(what_grab: WhatGrab) -> Self {
36 let events = Vec::with_capacity(0);
37
38 let info = JournalEventChunkInfo::Error;
39 JournalEventChunk {
40 events,
41 info,
42 what_grab,
43 }
44 }
45
46 pub fn push(&mut self, event: JournalEvent) {
47 self.events.push(event);
48 }
49
50 pub fn len(&self) -> usize {
51 self.events.len()
52 }
53
54 pub fn is_empty(&self) -> bool {
55 self.events.is_empty()
56 }
57
58 pub fn iter(&self) -> core::slice::Iter<'_, JournalEvent> {
59 self.events.iter()
60 }
61
62 pub fn last(&self) -> Option<&JournalEvent> {
63 self.events.last()
64 }
65
66 pub fn set_info(&mut self, info: JournalEventChunkInfo) {
67 self.info = info;
68 }
69
70 pub fn info(&self) -> JournalEventChunkInfo {
71 self.info
72 }
73
74 pub fn first(&self) -> Option<&JournalEvent> {
75 self.events.first()
76 }
77
78 pub fn times(&self) -> Option<(u64, u64)> {
79 if self.events.is_empty() {
80 return None;
81 }
82
83 let first = self.events.first().expect("must have a first");
84 let last = self.events.last().expect("must have a last");
85
86 match self.what_grab {
87 WhatGrab::Newer => Some((first.timestamp, last.timestamp)),
88 WhatGrab::Older => Some((last.timestamp, first.timestamp)),
89 }
90 }
91
92 }
96
97#[derive(Debug, Copy, Clone, PartialEq)]
98pub enum WhatGrab {
99 Newer,
101 Older,
103}
104
105#[derive(Debug)]
106pub struct EventRange {
107 pub oldest_events_time: Option<u64>,
108 pub newest_events_time: Option<u64>,
109 pub batch_size: usize,
110 pub what_grab: WhatGrab,
111}
112
113impl EventRange {
114 pub fn new(
115 what_grab: WhatGrab,
116 batch_size: usize,
117 oldest_events_time: Option<u64>,
118 newest_events_time: Option<u64>,
119 ) -> Self {
120 EventRange {
121 oldest_events_time,
122 newest_events_time,
123 batch_size,
124 what_grab,
125 }
126 }
127
128 }
140
141#[derive(Debug)]
142pub struct JournalEvent {
143 pub prefix: String,
144 pub message: String,
145 pub timestamp: u64,
146 pub priority: u8,
147}
148
149impl JournalEvent {
150 pub fn new_param(priority: u8, timestamp: u64, prefix: String, message: String) -> Self {
151 JournalEvent {
152 prefix,
153 message,
154 timestamp,
155 priority,
156 }
157 }
158}
159pub struct Boot {
160 pub index: i32,
161 pub boot_id: String,
162 pub first: u64,
163 pub last: u64,
164 pub total: i32,
165}
166
167impl Boot {
168 pub fn neg_offset(&self) -> i32 {
169 -(self.total - self.index)
170 }
171
172 pub fn index(&self) -> i32 {
173 self.index
174 }
175
176 pub fn duration(&self) -> u64 {
177 self.last - self.first
178 }
179}