use std::path::PathBuf;
pub type DispatchFn = fn();
#[derive(Debug)]
pub struct Session(String);
#[macro_export]
macro_rules! ServiceMacro {
($entry:ident, $function:ident, $t:ident) => {
fn $entry() {
$function(None, None);
}
};
}
#[macro_export]
macro_rules! DispatchAsync {
($self:ident, $function:ident) => {{
$function().await;
let r: Result<(), u32> = Ok(());
r
}};
}
#[cfg(feature = "async")]
#[macro_export]
macro_rules! ServiceAsyncMacro {
($entry:ident, $function:ident, $t:ident) => {
async fn $entry() {
$function().await;
}
};
}
pub struct ServiceConfig {
arguments: Vec<String>,
description: String,
binary: PathBuf,
username: Option<String>,
pub config_path: PathBuf,
}
impl ServiceConfig {
pub fn new(
arguments: Vec<String>,
description: String,
binary: PathBuf,
username: Option<String>,
) -> Self {
Self {
arguments,
description,
binary,
config_path: PathBuf::new(),
username,
}
}
}
#[derive(Debug)]
pub enum CreateError {
NoSystemCtl,
SystemCtlFailed,
SystemCtlReloadFailed,
FileIoError(std::io::Error),
}
#[derive(Debug)]
pub enum StartStopError {
NoSystemCtl,
SystemCtlFailed,
}
impl From<StartStopError> for CreateError {
fn from(value: StartStopError) -> Self {
match value {
StartStopError::NoSystemCtl => Self::NoSystemCtl,
StartStopError::SystemCtlFailed => Self::SystemCtlFailed,
}
}
}
pub struct Service {
name: String,
}
impl Service {
pub fn new(name: String) -> Self {
Self { name }
}
pub fn exists(&self) -> bool {
false
}
pub fn new_log(&self, level: super::LogLevel) {
simple_logger::SimpleLogger::new().init().unwrap();
log::set_max_level(level.level_filter());
}
pub fn create(&mut self, config: ServiceConfig) -> Result<(), CreateError> {
Err(CreateError::NoSystemCtl)
}
pub fn start(&mut self) -> Result<(), StartStopError> {
Err(StartStopError::NoSystemCtl)
}
pub fn stop(&mut self) -> Result<(), StartStopError> {
Err(StartStopError::NoSystemCtl)
}
pub fn delete(&mut self) -> Result<(), std::io::Error> {
Ok(())
}
pub fn dispatch(&self, service_main: DispatchFn) -> Result<(), u32> {
service_main();
Ok(())
}
}