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 {
|
pub trait Interface {
|
||||||
fn path() -> Path<'static>;
|
fn path() -> Path<'static>;
|
||||||
|
fn default_path(&self) -> Path<'static>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
@ -25,19 +26,34 @@ pub struct Data {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ObjectPathData {
|
pub struct ObjectPathData {
|
||||||
daemon: Option<Arc<RwLock<structs::DaemonService>>>
|
daemon: Option<Arc<RwLock<structs::DaemonService>>>,
|
||||||
|
minecraft: Option<Arc<RwLock<structs::MinecraftService>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectPathData {
|
impl ObjectPathData {
|
||||||
pub fn daemon(&self) -> Option<Arc<RwLock<structs::DaemonService>>> {
|
pub fn daemon(&self) -> Option<Arc<RwLock<structs::DaemonService>>> {
|
||||||
self.daemon.clone()
|
self.daemon.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn minecraft(&self) -> Option<Arc<RwLock<structs::MinecraftService>>> {
|
||||||
|
self.minecraft.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<structs::DaemonService> for ObjectPathData {
|
impl From<structs::DaemonService> for ObjectPathData {
|
||||||
fn from(d: structs::DaemonService) -> Self {
|
fn from(d: structs::DaemonService) -> Self {
|
||||||
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)+) => {
|
($m:ident, |$data:ident| $($f:tt)+) => {
|
||||||
$crate::handle_iface_generic!($m, no_path, path, |$data: std::sync::Arc<tokio::sync::RwLock<_>>| {
|
$crate::handle_iface_generic!($m, no_path, path, |$data: std::sync::Arc<tokio::sync::RwLock<_>>| {
|
||||||
let $data = if path == &DaemonService::path() {
|
let $data = if path == &DaemonService::path() {
|
||||||
$data.daemon().ok_or(no_path)
|
$data.daemon()
|
||||||
} else {
|
} else if path == &MinecraftService::path() {
|
||||||
Err(no_path)
|
$data.minecraft()
|
||||||
}?;
|
} else {None}.ok_or(no_path)?;
|
||||||
} $($f)+)
|
} $($f)+)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -98,12 +114,20 @@ pub mod Service {
|
|||||||
|
|
||||||
impl Interface for DaemonService {
|
impl Interface for DaemonService {
|
||||||
fn path() -> Path<'static> {
|
fn path() -> Path<'static> {
|
||||||
|
Self.default_path()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_path(&self) -> Path<'static> {
|
||||||
Path::new("/").unwrap()
|
Path::new("/").unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interface for MinecraftService {
|
impl Interface for MinecraftService {
|
||||||
fn path() -> Path<'static> {
|
fn path() -> Path<'static> {
|
||||||
|
Self.default_path()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_path(&self) -> Path<'static> {
|
||||||
Path::new("/minecraft").unwrap()
|
Path::new("/minecraft").unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
use std::sync::Arc;
|
#[derive(Debug, Default, Copy, Clone)]
|
||||||
// use tokio::task::JoinHandle;
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct DaemonService;
|
pub struct DaemonService;
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Copy, Clone)]
|
||||||
pub struct MinecraftService;
|
pub struct MinecraftService;
|
@ -1,7 +1,6 @@
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use super::errors::ServiceError;
|
use super::errors::ServiceError;
|
||||||
pub trait org_ddnss_sfs_mc_Service {
|
pub trait org_ddnss_sfs_mc_Service {
|
||||||
|
|
||||||
fn start(&mut self) -> Result<Option<JoinHandle<()>>, ServiceError>;
|
fn start(&mut self) -> Result<Option<JoinHandle<()>>, ServiceError>;
|
||||||
fn stop(&mut self) -> Result<Option<JoinHandle<()>>, ServiceError>;
|
fn stop(&mut self) -> Result<Option<JoinHandle<()>>, ServiceError>;
|
||||||
fn is_running(&self) -> bool;
|
fn is_running(&self) -> bool;
|
||||||
|
Loading…
Reference in New Issue
Block a user