pub mod clients;
use std::{fmt::Display, rc::Rc};
use serde::Deserialize;
use thiserror::Error;
use crate::root::Environment;
fn default_update_rate() -> i64 {
1000
}
#[derive(Debug, Deserialize, Clone, Copy)]
pub struct ProcessSettings {
#[serde(default = "default_update_rate")]
pub update_rate: i64,
}
pub trait Service {
fn bind(&mut self, env: Rc<Environment>) -> Result<(), ServiceError>;
fn init(&self) -> Result<(), ServiceError>;
fn run(&self) -> Result<(), ServiceError>;
}
pub trait ServiceNew {
type Settings;
fn new(env: Option<Rc<Environment>>, settings: Self::Settings) -> Result<Self, ServiceError>
where
Self: Sized;
}
#[derive(Debug, Error)]
pub enum ServiceError {
#[error("Trying to run a service \"{0}\" not bound to any environment")]
RunWithNoEnv(String),
#[error("Custom error occured in service \"{0}\": \n \"{1}\"")]
Custom(String, anyhow::Error),
}
#[derive(Debug, Clone)]
pub enum ServiceList {
Keyboard,
Custom(String),
}
impl Display for ServiceList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Keyboard => write!(f, "Keyboard"),
Self::Custom(name) => write!(f, "{name}"),
}
}
}