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
pub mod cpuload;
pub mod meminfo;
pub mod report;
#[cfg(feature = "enable_ipcon")]
pub mod ipcon;
use serde::{de::DeserializeOwned, Serialize};
#[allow(unused)]
use std::sync::mpsc::{Receiver, Sender};
use std::sync::Arc;
use std::{error::Error, fmt::Display};
#[allow(unused)]
use tracing::{debug, error, info, warn};
use error_stack::Result;
#[derive(Debug)]
pub enum InfomgrError {
IOError,
InvalidData,
#[cfg(feature = "enable_ipcon")]
IpconError,
Unexpected,
}
impl Display for InfomgrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let err_str = match self {
InfomgrError::IOError => "IO error",
InfomgrError::InvalidData => "Invalid data",
#[cfg(feature = "enable_ipcon")]
InfomgrError::IpconError => "Ipcon error",
_ => "Unexpected data",
};
write!(f, "{}", err_str)
}
}
impl Error for InfomgrError {}
pub trait InfoCon {
fn sender<T>(&mut self, source: Arc<String>, receiver: Receiver<T>) -> Result<(), InfomgrError>
where
T: 'static + Serialize + Send;
fn receiver<T>(
&mut self,
source: Arc<String>,
sender: Sender<Option<T>>,
) -> Result<(), InfomgrError>
where
T: 'static + DeserializeOwned + Send;
}