From 6d3640ce782ca78e30c4767c552e741184449eb0 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Wed, 31 Jan 2024 19:19:11 +0100 Subject: [PATCH] expand service methods a bit (without implementations, just the trait) --- .gitignore | 1 + gdriver-backend/src/prelude.rs | 2 +- gdriver-backend/src/service.rs | 31 ++++++++++++++++++++--- gdriver-common/src/drive_structure.rs | 3 ++- gdriver-common/src/ipc/gdriver_service.rs | 18 ++++++++++--- gdriver-common/src/prelude.rs | 1 + 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..3a8cabc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.idea diff --git a/gdriver-backend/src/prelude.rs b/gdriver-backend/src/prelude.rs index 5ba7ac2..273e762 100644 --- a/gdriver-backend/src/prelude.rs +++ b/gdriver-backend/src/prelude.rs @@ -1,2 +1,2 @@ pub(crate) type Result = StdResult>; -use std::{error::Error, result::Result as StdResult}; +pub(crate) use std::{error::Error, result::Result as StdResult}; diff --git a/gdriver-backend/src/service.rs b/gdriver-backend/src/service.rs index d2b4d58..5f706d8 100644 --- a/gdriver-backend/src/service.rs +++ b/gdriver-backend/src/service.rs @@ -1,10 +1,9 @@ -use std::{sync::Arc, thread}; - use chrono::Duration; use gdriver_common::{ - drive_structure::drive_id::ROOT_ID, - ipc::gdriver_service::{BackendActionError, BackendActionRequest, GDriverService}, + drive_structure::drive_id::{DriveId, ROOT_ID}, + ipc::gdriver_service::*, }; +use std::{path::PathBuf, sync::Arc, thread}; use tokio::sync::Mutex; use crate::drive::Drive; @@ -52,6 +51,30 @@ impl GDriverService for GdriverServer { } } } + + async fn get_file_by_path( + self, + context: ::tarpc::context::Context, + path: PathBuf, + ) -> StdResult { + todo!() + } + + #[doc = " Returns true if the file was had remote changes and was updadet"] + async fn update_changes_for_file( + self, + context: ::tarpc::context::Context, + id: DriveId, + ) -> StdResult { + todo!() + } + + async fn update_changes( + self, + context: ::tarpc::context::Context, + ) -> StdResult<(), UpdateChangesError> { + todo!() + } } async fn long_running_task(drive: &Arc>) { thread::sleep(Duration::seconds(10).to_std().unwrap()); diff --git a/gdriver-common/src/drive_structure.rs b/gdriver-common/src/drive_structure.rs index 5921a03..136098c 100644 --- a/gdriver-common/src/drive_structure.rs +++ b/gdriver-common/src/drive_structure.rs @@ -1,10 +1,11 @@ pub mod drive_id { use lazy_static::lazy_static; + use serde::{Deserialize, Serialize}; lazy_static! { pub static ref ROOT_ID: DriveId = DriveId(String::from("root")); } - #[derive(Debug, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct DriveId(pub String); impl From for DriveId diff --git a/gdriver-common/src/ipc/gdriver_service.rs b/gdriver-common/src/ipc/gdriver_service.rs index a70872e..5bfb3a0 100644 --- a/gdriver-common/src/ipc/gdriver_service.rs +++ b/gdriver-common/src/ipc/gdriver_service.rs @@ -1,10 +1,17 @@ +use crate::prelude::*; +use std::path::PathBuf; + use serde::{Deserialize, Serialize}; +use crate::drive_structure::drive_id::DriveId; + #[tarpc::service] pub trait GDriverService { - async fn do_something2( - req: BackendActionRequest, - ) -> std::result::Result; + async fn get_file_by_path(path: PathBuf) -> StdResult; + /// Returns true if the file was had remote changes and was updadet + async fn update_changes_for_file(id: DriveId) -> StdResult; + async fn update_changes() -> StdResult<(), UpdateChangesError>; + async fn do_something2(req: BackendActionRequest) -> StdResult; } #[derive(Debug, Serialize, Deserialize)] pub enum BackendActionRequest { @@ -19,3 +26,8 @@ pub enum BackendActionError { Unknown, CouldNotComplete, } + +#[derive(Debug, Serialize, Deserialize)] +pub enum GetFileByPathError {} +#[derive(Debug, Serialize, Deserialize)] +pub enum UpdateChangesError {} diff --git a/gdriver-common/src/prelude.rs b/gdriver-common/src/prelude.rs index 30be711..b257a93 100644 --- a/gdriver-common/src/prelude.rs +++ b/gdriver-common/src/prelude.rs @@ -2,3 +2,4 @@ pub use crate::config::Configuration; pub use crate::config::CONFIGURATION; pub use crate::ipc; pub(crate) type Result = std::result::Result>; +pub(crate) use std::result::Result as StdResult;