From 0ca02591bd1de35efd85085289deb489069f8af6 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 12 Jun 2022 21:30:01 -0400 Subject: [PATCH] Prepare for experimental release --- usdpl-back/Cargo.toml | 3 ++- usdpl-back/README.md | 9 +++++++++ usdpl-back/src/instance.rs | 7 ++++--- usdpl-core/Cargo.toml | 3 ++- usdpl-core/README.md | 6 ++++++ usdpl-core/src/remote_call.rs | 2 ++ usdpl-core/src/serdes/primitive.rs | 8 ++++++++ usdpl-core/src/socket.rs | 2 ++ usdpl-front/Cargo.toml | 2 +- usdpl-front/README.md | 0 10 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 usdpl-back/README.md create mode 100644 usdpl-core/README.md create mode 100644 usdpl-front/README.md diff --git a/usdpl-back/Cargo.toml b/usdpl-back/Cargo.toml index 0380033..7b5d1fb 100644 --- a/usdpl-back/Cargo.toml +++ b/usdpl-back/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2021" license = "GPL-3.0-only" repository = "https://github.com/NGnius/usdpl-rs" -readme = "../README.md" +readme = "README.md" +description = "Universal Steam Deck Plugin Library back-end" [features] default = [] diff --git a/usdpl-back/README.md b/usdpl-back/README.md new file mode 100644 index 0000000..b83b4d4 --- /dev/null +++ b/usdpl-back/README.md @@ -0,0 +1,9 @@ +# usdpl-back + +Back-end library for plugins. +Targets x86_64 (native Steam Deck ISA). + +This is a minimalist TCP server for handling events from the front-end. + + +License: GPL-3.0-only diff --git a/usdpl-back/src/instance.rs b/usdpl-back/src/instance.rs index 50b298d..da15010 100644 --- a/usdpl-back/src/instance.rs +++ b/usdpl-back/src/instance.rs @@ -5,13 +5,14 @@ use std::io::{Read, Write}; use usdpl_core::serdes::{Dumpable, Loadable, Primitive}; use usdpl_core::{RemoteCallResponse, socket}; -/// Instance for interacting with the front-end +/// Back-end instance for interacting with the front-end pub struct Instance<'a> { calls: HashMap) -> Vec>, port: u16, } impl<'a> Instance<'a> { + /// Initialise an instance of the back-end #[inline] pub fn new(port_usdpl: u16) -> Self { Instance { @@ -21,8 +22,8 @@ impl<'a> Instance<'a> { } /// Register a function which can be invoked by the front-end - pub fn register) -> Vec) + Send + Sync>(&mut self, name: String, f: &'a mut F) -> &mut Self { - self.calls.insert(name, f); + pub fn register, F: (FnMut(Vec) -> Vec) + Send + Sync>(&mut self, name: S, f: &'a mut F) -> &mut Self { + self.calls.insert(name.into(), f); self } diff --git a/usdpl-core/Cargo.toml b/usdpl-core/Cargo.toml index 890b0aa..dbedfd9 100644 --- a/usdpl-core/Cargo.toml +++ b/usdpl-core/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2021" license = "GPL-3.0-only" repository = "https://github.com/NGnius/usdpl-rs" -readme = "../README.md" +readme = "README.md" +description = "Universal Steam Deck Plugin Library core" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/usdpl-core/README.md b/usdpl-core/README.md new file mode 100644 index 0000000..e5e1f3a --- /dev/null +++ b/usdpl-core/README.md @@ -0,0 +1,6 @@ +# usdpl-core + +Datatypes and constants core the back-end and front-end libraries' operation. +This contains serialization functionality and networking datatypes. + +License: GPL-3.0-only diff --git a/usdpl-core/src/remote_call.rs b/usdpl-core/src/remote_call.rs index 539dd55..afbba21 100644 --- a/usdpl-core/src/remote_call.rs +++ b/usdpl-core/src/remote_call.rs @@ -1,5 +1,6 @@ use crate::serdes::{Primitive, Loadable, Dumpable}; +/// Remote call packet representing a function to call on the back-end, sent from the front-end pub struct RemoteCall { pub id: u64, pub function: String, @@ -46,6 +47,7 @@ impl Dumpable for RemoteCall { } } +/// Remote call response packet representing the response from a remote call after the back-end has executed it. pub struct RemoteCallResponse { pub id: u64, pub response: Vec, diff --git a/usdpl-core/src/serdes/primitive.rs b/usdpl-core/src/serdes/primitive.rs index 4ccbdca..6d401fe 100644 --- a/usdpl-core/src/serdes/primitive.rs +++ b/usdpl-core/src/serdes/primitive.rs @@ -1,5 +1,7 @@ use super::{Loadable, Dumpable}; +/// Primitive types supported for communication between the USDPL back- and front-end. +/// These are used for sending over the TCP connection. pub enum Primitive { Empty, String(String), @@ -111,6 +113,12 @@ impl std::convert::Into for String { } } +impl std::convert::Into for &str { + fn into(self) -> Primitive { + Primitive::String(self.to_string()) + } +} + impl std::convert::Into for () { fn into(self) -> Primitive { Primitive::Empty diff --git a/usdpl-core/src/socket.rs b/usdpl-core/src/socket.rs index 7acd7f2..f4f0948 100644 --- a/usdpl-core/src/socket.rs +++ b/usdpl-core/src/socket.rs @@ -13,6 +13,7 @@ pub fn socket_addr(port: u16) -> SocketAddr { SocketAddr::V4(SocketAddrV4::new(HOST, port)) } +/// Accepted Packet types and the data they contain pub enum Packet { Call(RemoteCall), CallResponse(RemoteCallResponse), @@ -25,6 +26,7 @@ pub enum Packet { } impl Packet { + /// Byte representing the packet type -- the first byte of any packet in USDPL const fn discriminant(&self) -> u8 { match self { Self::Call(_) => 1, diff --git a/usdpl-front/Cargo.toml b/usdpl-front/Cargo.toml index 56f28ae..c02746d 100644 --- a/usdpl-front/Cargo.toml +++ b/usdpl-front/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "usdpl" -description = "WASM front-end library for USDPL" version = "0.1.0" authors = ["NGnius (Graham) "] edition = "2021" license = "GPL-3.0-only" repository = "https://github.com/NGnius/usdpl-rs" readme = "../README.md" +description = "Universal Steam Deck Plugin Library front-end designed for WASM" [lib] crate-type = ["cdylib", "rlib"] diff --git a/usdpl-front/README.md b/usdpl-front/README.md new file mode 100644 index 0000000..e69de29