use crate::base::SettingType;
use crate::message::base::Audience;
use crate::service_context::ExternalServiceEvent;
use crate::{config, payload_convert, service};
use std::rc::Rc;
#[derive(Clone, Debug, PartialEq)]
pub enum Payload {
Event(Event),
}
#[derive(Clone, Debug, PartialEq)]
pub enum Event {
Custom(&'static str),
CameraUpdate(camera_watcher::Event),
ConfigLoad(config::base::Event),
Earcon(earcon::Event),
MediaButtons(media_buttons::Event),
Restore(restore::Event),
ExternalServiceEvent(ExternalServiceEvent),
Handler(SettingType, handler::Event),
Source(source::Event),
}
#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)]
pub enum Address {
SettingProxy(SettingType),
}
pub(crate) mod camera_watcher {
#[derive(PartialEq, Clone, Debug, Eq, Hash)]
pub enum Event {
OnSWMuteState(bool),
}
impl From<bool> for Event {
fn from(muted: bool) -> Self {
Self::OnSWMuteState(muted)
}
}
}
pub(crate) mod earcon {
#[derive(PartialEq, Clone, Debug, Eq, Hash)]
pub enum Event {
Suppressed(EarconType),
}
#[derive(PartialEq, Clone, Debug, Eq, Hash)]
pub enum EarconType {
Volume,
}
}
pub(crate) mod source {
use crate::job::source::{Error, Id};
#[derive(PartialEq, Clone, Copy, Debug, Eq, Hash)]
pub enum Event {
Start(Id),
Complete(Id, Result<(), CompleteError>),
}
#[derive(PartialEq, Clone, Copy, Debug, Eq, Hash)]
pub enum CompleteError {
Unexpected,
InvalidInput,
InvalidPolicyInput,
Unsupported,
}
impl From<Error> for CompleteError {
fn from(err: Error) -> Self {
match err {
Error::Unexpected(_) => CompleteError::Unexpected,
Error::InvalidInput(_) => CompleteError::InvalidInput,
Error::InvalidPolicyInput(_) => CompleteError::InvalidPolicyInput,
Error::Unsupported => CompleteError::Unsupported,
}
}
}
}
pub(crate) mod handler {
use crate::handler::base::Request;
use crate::handler::setting_handler::ExitResult;
#[derive(PartialEq, Clone, Debug)]
pub enum Event {
Exit(ExitResult),
Request(Action, Request),
Teardown,
}
#[derive(PartialEq, Clone, Debug)]
pub enum Action {
Execute,
Retry,
Timeout,
AttemptsExceeded,
}
}
pub(crate) mod media_buttons {
use crate::input::MediaButtons;
#[derive(PartialEq, Clone, Debug)]
pub enum Event {
OnButton(MediaButtons),
}
impl From<MediaButtons> for Event {
fn from(button_types: MediaButtons) -> Self {
Self::OnButton(button_types)
}
}
}
pub(crate) mod restore {
use crate::base::SettingType;
#[derive(PartialEq, Clone, Debug, Eq, Hash)]
pub enum Event {
NoOp(SettingType),
}
}
payload_convert!(Event, Payload);
#[derive(Clone, Debug)]
pub struct Publisher {
messenger: service::message::Messenger,
}
impl Publisher {
pub(crate) async fn create(
delegate: &service::message::Delegate,
messenger_type: service::message::MessengerType,
) -> Publisher {
let (messenger, _) = delegate
.create(messenger_type)
.await
.expect("should be able to retrieve messenger for publisher");
Publisher { messenger }
}
pub(crate) fn send_event(&self, event: Event) {
let _ = self.messenger.message(Payload::Event(event).into(), Audience::EventSink);
}
}
pub(crate) mod subscriber {
use super::*;
use futures::future::LocalBoxFuture;
pub type BlueprintHandle = Rc<dyn Blueprint>;
pub trait Blueprint {
fn create(&self, delegate: service::message::Delegate) -> LocalBoxFuture<'static, ()>;
}
}