1#[doc(hidden)]
7extern crate alloc;
8
9use crate::error::Error;
11use alloc::{
12 boxed::Box,
13 string::{String, ToString},
14};
15use bitcode::{Decode, Encode};
16use core::fmt::{Debug, Display};
17#[derive(Debug, Decode, Encode, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
22pub enum OperationState {
23 Error,
25 #[default]
27 Created,
28 Configured,
30 Inactive,
32 Standby,
34 Active,
36}
37
38impl TryFrom<&str> for OperationState {
39 type Error = Box<dyn core::error::Error + Send + Sync + 'static>;
40
41 fn try_from(
42 value: &str,
43 ) -> core::result::Result<Self, Box<dyn core::error::Error + Send + Sync + 'static>> {
44 let v = value.to_lowercase();
45 match v.as_str() {
46 "created" => Ok(Self::Created),
47 "configured" => Ok(Self::Configured),
48 "inactive" => Ok(Self::Inactive),
49 "standby" => Ok(Self::Standby),
50 "active" => Ok(Self::Active),
51 _ => Err(Error::UnknownOperationState {
52 state: value.to_string(),
53 }
54 .into()),
55 }
56 }
57}
58
59impl Display for OperationState {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 match self {
62 Self::Error => write!(f, "Error"),
63 Self::Created => write!(f, "Created"),
64 Self::Configured => write!(f, "Configured"),
65 Self::Inactive => write!(f, "Inactive"),
66 Self::Standby => write!(f, "Standby"),
67 Self::Active => write!(f, "Active"),
68 }
69 }
70}
71#[derive(Debug, Decode, Encode)]
76pub enum Signal {
77 About,
79 Ping {
81 sent: i64,
83 },
84 Shutdown,
86 State {
88 state: Option<OperationState>,
90 },
91}
92#[derive(Debug, Clone)]
97pub enum TaskSignal {
98 RestartLiveliness(String),
100 RestartObservable(String),
102 RestartQueryable(String),
104 RestartSubscriber(String),
106 RestartTimer(String),
108 Shutdown,
110}
111