mirror of
https://github.com/OMGeeky/gdriver2.git
synced 2026-02-23 15:38:32 +01:00
Initial prototype
This prototype has basic IPC working, with starting actions and waiting for actions or just getting information
This commit is contained in:
17
gdriver-common/Cargo.toml
Normal file
17
gdriver-common/Cargo.toml
Normal 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 "}
|
||||
33
gdriver-common/src/config.rs
Normal file
33
gdriver-common/src/config.rs
Normal 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();
|
||||
}
|
||||
23
gdriver-common/src/drive_structure.rs
Normal file
23
gdriver-common/src/drive_structure.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
3
gdriver-common/src/ipc.rs
Normal file
3
gdriver-common/src/ipc.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub mod gdriver_service;
|
||||
pub mod sample;
|
||||
21
gdriver-common/src/ipc/gdriver_service.rs
Normal file
21
gdriver-common/src/ipc/gdriver_service.rs
Normal 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,
|
||||
}
|
||||
5
gdriver-common/src/ipc/sample.rs
Normal file
5
gdriver-common/src/ipc/sample.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#[tarpc::service]
|
||||
pub trait World {
|
||||
/// Returns a greeting for name.
|
||||
async fn hello(name: String) -> String;
|
||||
}
|
||||
7
gdriver-common/src/lib.rs
Normal file
7
gdriver-common/src/lib.rs
Normal 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;
|
||||
4
gdriver-common/src/prelude.rs
Normal file
4
gdriver-common/src/prelude.rs
Normal 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>>;
|
||||
Reference in New Issue
Block a user