From ba5e5ece69e1565a47bc88acd6acdeb4fdd21f11 Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Thu, 17 Sep 2020 17:27:49 +0200 Subject: [PATCH] Add MinecraftService and change Interface trait I found out I did a design mistake (#2) --- sfsmcd/src/ifaces/mod.rs | 36 ++++++++++++++++++++++++++++++------ sfsmcd/src/ifaces/structs.rs | 7 ++----- sfsmcd/src/ifaces/traits.rs | 1 - 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/sfsmcd/src/ifaces/mod.rs b/sfsmcd/src/ifaces/mod.rs index 878a6bf..77dca0b 100644 --- a/sfsmcd/src/ifaces/mod.rs +++ b/sfsmcd/src/ifaces/mod.rs @@ -16,6 +16,7 @@ mod errors; pub trait Interface { fn path() -> Path<'static>; + fn default_path(&self) -> Path<'static>; } #[derive(Clone, Debug, Default)] @@ -25,19 +26,34 @@ pub struct Data { #[derive(Debug)] pub struct ObjectPathData { - daemon: Option>> + daemon: Option>>, + minecraft: Option>> } impl ObjectPathData { pub fn daemon(&self) -> Option>> { self.daemon.clone() } + + pub fn minecraft(&self) -> Option>> { + self.minecraft.clone() + } } impl From for ObjectPathData { fn from(d: structs::DaemonService) -> Self { Self { - daemon: Some(Arc::new(RwLock::new(d))) + daemon: Some(Arc::new(RwLock::new(d))), + minecraft: None + } + } +} + +impl From for ObjectPathData { + fn from(m: structs::MinecraftService) -> Self { + Self { + daemon: None, + minecraft: Some(Arc::new(RwLock::new(m))) } } } @@ -75,10 +91,10 @@ macro_rules! handle_org_ddnss_sfs_mc_Service { ($m:ident, |$data:ident| $($f:tt)+) => { $crate::handle_iface_generic!($m, no_path, path, |$data: std::sync::Arc>| { let $data = if path == &DaemonService::path() { - $data.daemon().ok_or(no_path) - } else { - Err(no_path) - }?; + $data.daemon() + } else if path == &MinecraftService::path() { + $data.minecraft() + } else {None}.ok_or(no_path)?; } $($f)+) }; } @@ -98,12 +114,20 @@ pub mod Service { impl Interface for DaemonService { fn path() -> Path<'static> { + Self.default_path() + } + + fn default_path(&self) -> Path<'static> { Path::new("/").unwrap() } } impl Interface for MinecraftService { fn path() -> Path<'static> { + Self.default_path() + } + + fn default_path(&self) -> Path<'static> { Path::new("/minecraft").unwrap() } } diff --git a/sfsmcd/src/ifaces/structs.rs b/sfsmcd/src/ifaces/structs.rs index 270e312..d8a4286 100644 --- a/sfsmcd/src/ifaces/structs.rs +++ b/sfsmcd/src/ifaces/structs.rs @@ -1,7 +1,4 @@ -use std::sync::Arc; -// use tokio::task::JoinHandle; - -#[derive(Debug, Default)] +#[derive(Debug, Default, Copy, Clone)] pub struct DaemonService; -#[derive(Debug, Default)] +#[derive(Debug, Default, Copy, Clone)] pub struct MinecraftService; \ No newline at end of file diff --git a/sfsmcd/src/ifaces/traits.rs b/sfsmcd/src/ifaces/traits.rs index 551731b..f731b8d 100644 --- a/sfsmcd/src/ifaces/traits.rs +++ b/sfsmcd/src/ifaces/traits.rs @@ -1,7 +1,6 @@ use tokio::task::JoinHandle; use super::errors::ServiceError; pub trait org_ddnss_sfs_mc_Service { - fn start(&mut self) -> Result>, ServiceError>; fn stop(&mut self) -> Result>, ServiceError>; fn is_running(&self) -> bool;