1use crate::base::SettingType;
6use crate::message::base::Audience;
7use crate::service_context::ExternalServiceEvent;
8use crate::{config, payload_convert, service};
9use std::rc::Rc;
10
11#[derive(Clone, Debug, PartialEq)]
12pub enum Payload {
13 Event(Event),
14}
15
16#[derive(Clone, Debug, PartialEq)]
19pub enum Event {
20 Custom(&'static str),
21 CameraUpdate(camera_watcher::Event),
22 ConfigLoad(config::base::Event),
23 Earcon(earcon::Event),
24 MediaButtons(media_buttons::Event),
25 Restore(restore::Event),
26 ExternalServiceEvent(ExternalServiceEvent),
27 Handler(SettingType, handler::Event),
28 Source(source::Event),
29}
30
31#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)]
32pub enum Address {
33 SettingProxy(SettingType),
34}
35
36pub(crate) mod camera_watcher {
37 #[derive(PartialEq, Clone, Debug, Eq, Hash)]
38 pub enum Event {
39 OnSWMuteState(bool),
41 }
42
43 impl From<bool> for Event {
44 fn from(muted: bool) -> Self {
45 Self::OnSWMuteState(muted)
46 }
47 }
48}
49
50pub(crate) mod earcon {
51 #[derive(PartialEq, Clone, Debug, Eq, Hash)]
52 pub enum Event {
53 Suppressed(EarconType),
56 }
57
58 #[derive(PartialEq, Clone, Debug, Eq, Hash)]
59 pub enum EarconType {
60 Volume,
61 }
62}
63
64pub(crate) mod source {
65 use crate::job::source::{Error, Id};
66
67 #[derive(PartialEq, Clone, Copy, Debug, Eq, Hash)]
68 pub enum Event {
69 Start(Id),
70 Complete(Id, Result<(), CompleteError>),
71 }
72
73 #[derive(PartialEq, Clone, Copy, Debug, Eq, Hash)]
74 pub enum CompleteError {
75 Unexpected,
76 InvalidInput,
77 InvalidPolicyInput,
78 Unsupported,
79 }
80
81 impl From<Error> for CompleteError {
82 fn from(err: Error) -> Self {
83 match err {
84 Error::Unexpected(_) => CompleteError::Unexpected,
85 Error::InvalidInput(_) => CompleteError::InvalidInput,
86 Error::InvalidPolicyInput(_) => CompleteError::InvalidPolicyInput,
87 Error::Unsupported => CompleteError::Unsupported,
88 }
89 }
90 }
91}
92
93pub(crate) mod handler {
94 use crate::handler::base::Request;
95 use crate::handler::setting_handler::ExitResult;
96
97 #[derive(PartialEq, Clone, Debug)]
98 pub enum Event {
99 Exit(ExitResult),
100 Request(Action, Request),
101 Teardown,
102 }
103
104 #[derive(PartialEq, Clone, Debug)]
106 pub enum Action {
107 Execute,
108 Retry,
109 Timeout,
110 AttemptsExceeded,
111 }
112}
113
114pub(crate) mod media_buttons {
115 use crate::input::MediaButtons;
116
117 #[derive(PartialEq, Clone, Debug)]
118 pub enum Event {
119 OnButton(MediaButtons),
120 }
121
122 impl From<MediaButtons> for Event {
123 fn from(button_types: MediaButtons) -> Self {
124 Self::OnButton(button_types)
125 }
126 }
127}
128
129pub(crate) mod restore {
130 use crate::base::SettingType;
131
132 #[derive(PartialEq, Clone, Debug, Eq, Hash)]
133 pub enum Event {
134 NoOp(SettingType),
136 }
137}
138
139payload_convert!(Event, Payload);
140
141#[derive(Clone, Debug)]
144pub struct Publisher {
145 messenger: service::message::Messenger,
146}
147
148impl Publisher {
149 pub(crate) async fn create(
150 delegate: &service::message::Delegate,
151 messenger_type: service::message::MessengerType,
152 ) -> Publisher {
153 let (messenger, _) = delegate
154 .create(messenger_type)
155 .await
156 .expect("should be able to retrieve messenger for publisher");
157
158 Publisher { messenger }
159 }
160
161 pub(crate) fn send_event(&self, event: Event) {
163 let _ = self.messenger.message(Payload::Event(event).into(), Audience::EventSink);
164 }
165}
166
167pub(crate) mod subscriber {
168 use super::*;
169 use futures::future::LocalBoxFuture;
170
171 pub type BlueprintHandle = Rc<dyn Blueprint>;
172
173 pub trait Blueprint {
176 fn create(&self, delegate: service::message::Delegate) -> LocalBoxFuture<'static, ()>;
177 }
178}