expand service methods a bit

(without implementations, just the trait)
This commit is contained in:
OMGeeky
2024-01-31 19:19:11 +01:00
parent 1f8105943c
commit 6d3640ce78
6 changed files with 47 additions and 9 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target
.idea

View File

@@ -1,2 +1,2 @@
pub(crate) type Result<T> = StdResult<T, Box<dyn Error>>;
use std::{error::Error, result::Result as StdResult};
pub(crate) use std::{error::Error, result::Result as StdResult};

View File

@@ -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<DriveId, GetFileByPathError> {
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<bool, UpdateChangesError> {
todo!()
}
async fn update_changes(
self,
context: ::tarpc::context::Context,
) -> StdResult<(), UpdateChangesError> {
todo!()
}
}
async fn long_running_task(drive: &Arc<Mutex<Drive>>) {
thread::sleep(Duration::seconds(10).to_std().unwrap());

View File

@@ -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<T> From<T> for DriveId

View File

@@ -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<String, BackendActionError>;
async fn get_file_by_path(path: PathBuf) -> StdResult<DriveId, GetFileByPathError>;
/// Returns true if the file was had remote changes and was updadet
async fn update_changes_for_file(id: DriveId) -> StdResult<bool, UpdateChangesError>;
async fn update_changes() -> StdResult<(), UpdateChangesError>;
async fn do_something2(req: BackendActionRequest) -> StdResult<String, BackendActionError>;
}
#[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 {}

View File

@@ -2,3 +2,4 @@ pub use crate::config::Configuration;
pub use crate::config::CONFIGURATION;
pub use crate::ipc;
pub(crate) type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub(crate) use std::result::Result as StdResult;