Initial prototype

This prototype has basic IPC working, with starting actions and waiting for actions or just getting information
This commit is contained in:
OMGeeky
2024-01-31 15:38:52 +01:00
commit 1f8105943c
21 changed files with 1873 additions and 0 deletions

17
gdriver-common/Cargo.toml Normal file
View File

@@ -0,0 +1,17 @@
[package]
name = "gdriver-common"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde.workspace = true
tarpc.workspace = true
tokio.workspace = true
futures.workspace = true
lazy_static.workspace = true
confique={ version = "0.2" }
#[patch.crates-io]
#confique = {path="~/Documents/git/OMGeeky/confique "}

View File

@@ -0,0 +1,33 @@
use super::*;
use crate::prelude::*;
use confique::{Config, Partial};
use std::net::{IpAddr, Ipv6Addr};
const IP_DEFAULT: IpAddr = IpAddr::V6(Ipv6Addr::LOCALHOST);
#[derive(Debug, Serialize, Deserialize, Config, Clone)]
pub struct Configuration {
#[config(default = 33333)]
pub port: u16,
// #[config(default = Test)]
pub ip: std::net::IpAddr,
}
pub fn load_config() -> Result<Configuration> {
Ok(add_default_locations(Config::builder()).load()?)
}
pub fn load_config_with_path(path: &Path) -> Result<Configuration> {
Ok(add_default_locations(Config::builder().file(path)).load()?)
}
fn add_default_locations(
builder: confique::Builder<Configuration>,
) -> confique::Builder<Configuration> {
type P = <Configuration as Config>::Partial;
let prebuilt = P {
ip: Some(IP_DEFAULT),
..P::empty()
};
builder.env().file("config.toml").preloaded(prebuilt)
}
use lazy_static::lazy_static;
lazy_static! {
pub static ref CONFIGURATION: Configuration = load_config().unwrap();
}

View File

@@ -0,0 +1,23 @@
pub mod drive_id {
use lazy_static::lazy_static;
lazy_static! {
pub static ref ROOT_ID: DriveId = DriveId(String::from("root"));
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DriveId(pub String);
impl<T> From<T> for DriveId
where
T: Into<String>,
{
fn from(s: T) -> Self {
DriveId(s.into())
}
}
impl AsRef<str> for DriveId {
fn as_ref(&self) -> &str {
&self.0
}
}
}

View File

@@ -0,0 +1,3 @@
use serde::{Deserialize, Serialize};
pub mod gdriver_service;
pub mod sample;

View File

@@ -0,0 +1,21 @@
use serde::{Deserialize, Serialize};
#[tarpc::service]
pub trait GDriverService {
async fn do_something2(
req: BackendActionRequest,
) -> std::result::Result<String, BackendActionError>;
}
#[derive(Debug, Serialize, Deserialize)]
pub enum BackendActionRequest {
ShutdownGracefully,
UpdateChanges,
Ping,
RunLong,
StartLong,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum BackendActionError {
Unknown,
CouldNotComplete,
}

View File

@@ -0,0 +1,5 @@
#[tarpc::service]
pub trait World {
/// Returns a greeting for name.
async fn hello(name: String) -> String;
}

View File

@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};
use std::path::Path;
pub mod prelude;
pub mod config;
pub mod ipc;
pub mod drive_structure;

View File

@@ -0,0 +1,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>>;