1use eva_common::events::NodeInfo;
2use serde::{Deserialize, Serialize};
3
4pub const PS_ITEM_STATE_TOPIC: &str = "ST/";
5pub const PS_ITEM_BULK_STATE_TOPIC: &str = "STBULK/";
6pub const PS_NODE_STATE_TOPIC: &str = "NODE/ST/";
7
8#[derive(Deserialize, Serialize, Copy, Clone)]
9#[serde(rename_all = "lowercase")]
10#[repr(u8)]
11pub enum NodeStatus {
12 Running = 1,
13 Terminating = 0xef,
14}
15
16#[derive(Deserialize, Serialize)]
17pub struct PsNodeStatus {
18 status: NodeStatus,
19 info: Option<NodeInfo>,
20 #[serde(default = "eva_common::tools::default_true")]
21 api_enabled: bool,
22}
23
24impl PsNodeStatus {
25 #[inline]
26 pub fn new_running() -> Self {
27 Self {
28 status: NodeStatus::Running,
29 info: None,
30 api_enabled: true,
31 }
32 }
33 #[inline]
34 pub fn new_terminating() -> Self {
35 Self {
36 status: NodeStatus::Terminating,
37 info: None,
38 api_enabled: true,
39 }
40 }
41 #[inline]
42 pub fn with_info(mut self, info: NodeInfo) -> Self {
43 self.info = Some(info);
44 self
45 }
46 #[inline]
47 pub fn with_api_disabled(mut self) -> Self {
48 self.api_enabled = false;
49 self
50 }
51 #[inline]
52 pub fn status(&self) -> NodeStatus {
53 self.status
54 }
55 #[inline]
56 pub fn info(&self) -> Option<&NodeInfo> {
57 self.info.as_ref()
58 }
59 #[inline]
60 pub fn take_info(&mut self) -> Option<NodeInfo> {
61 self.info.take()
62 }
63 #[inline]
64 pub fn is_api_enabled(&self) -> bool {
65 self.api_enabled
66 }
67}