Add MinecraftService and change Interface trait
I found out I did a design mistake (#2)
This commit is contained in:
parent
e25cfe94d2
commit
ba5e5ece69
@ -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<Arc<RwLock<structs::DaemonService>>>
|
||||
daemon: Option<Arc<RwLock<structs::DaemonService>>>,
|
||||
minecraft: Option<Arc<RwLock<structs::MinecraftService>>>
|
||||
}
|
||||
|
||||
impl ObjectPathData {
|
||||
pub fn daemon(&self) -> Option<Arc<RwLock<structs::DaemonService>>> {
|
||||
self.daemon.clone()
|
||||
}
|
||||
|
||||
pub fn minecraft(&self) -> Option<Arc<RwLock<structs::MinecraftService>>> {
|
||||
self.minecraft.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<structs::DaemonService> 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<structs::MinecraftService> 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<tokio::sync::RwLock<_>>| {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
@ -1,7 +1,6 @@
|
||||
use tokio::task::JoinHandle;
|
||||
use super::errors::ServiceError;
|
||||
pub trait org_ddnss_sfs_mc_Service {
|
||||
|
||||
fn start(&mut self) -> Result<Option<JoinHandle<()>>, ServiceError>;
|
||||
fn stop(&mut self) -> Result<Option<JoinHandle<()>>, ServiceError>;
|
||||
fn is_running(&self) -> bool;
|
||||
|
Loading…
Reference in New Issue
Block a user