Prepare for experimental release

This commit is contained in:
NGnius (Graham) 2022-06-12 21:30:01 -04:00
parent ccd3969185
commit 0ca02591bd
10 changed files with 36 additions and 6 deletions

View file

@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "GPL-3.0-only" license = "GPL-3.0-only"
repository = "https://github.com/NGnius/usdpl-rs" repository = "https://github.com/NGnius/usdpl-rs"
readme = "../README.md" readme = "README.md"
description = "Universal Steam Deck Plugin Library back-end"
[features] [features]
default = [] default = []

9
usdpl-back/README.md Normal file
View file

@ -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

View file

@ -5,13 +5,14 @@ use std::io::{Read, Write};
use usdpl_core::serdes::{Dumpable, Loadable, Primitive}; use usdpl_core::serdes::{Dumpable, Loadable, Primitive};
use usdpl_core::{RemoteCallResponse, socket}; 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> { pub struct Instance<'a> {
calls: HashMap<String, &'a mut dyn FnMut(Vec<Primitive>) -> Vec<Primitive>>, calls: HashMap<String, &'a mut dyn FnMut(Vec<Primitive>) -> Vec<Primitive>>,
port: u16, port: u16,
} }
impl<'a> Instance<'a> { impl<'a> Instance<'a> {
/// Initialise an instance of the back-end
#[inline] #[inline]
pub fn new(port_usdpl: u16) -> Self { pub fn new(port_usdpl: u16) -> Self {
Instance { Instance {
@ -21,8 +22,8 @@ impl<'a> Instance<'a> {
} }
/// Register a function which can be invoked by the front-end /// Register a function which can be invoked by the front-end
pub fn register<F: (FnMut(Vec<Primitive>) -> Vec<Primitive>) + Send + Sync>(&mut self, name: String, f: &'a mut F) -> &mut Self { pub fn register<S: std::convert::Into<String>, F: (FnMut(Vec<Primitive>) -> Vec<Primitive>) + Send + Sync>(&mut self, name: S, f: &'a mut F) -> &mut Self {
self.calls.insert(name, f); self.calls.insert(name.into(), f);
self self
} }

View file

@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "GPL-3.0-only" license = "GPL-3.0-only"
repository = "https://github.com/NGnius/usdpl-rs" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

6
usdpl-core/README.md Normal file
View file

@ -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

View file

@ -1,5 +1,6 @@
use crate::serdes::{Primitive, Loadable, Dumpable}; 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 struct RemoteCall {
pub id: u64, pub id: u64,
pub function: String, 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 struct RemoteCallResponse {
pub id: u64, pub id: u64,
pub response: Vec<Primitive>, pub response: Vec<Primitive>,

View file

@ -1,5 +1,7 @@
use super::{Loadable, Dumpable}; 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 { pub enum Primitive {
Empty, Empty,
String(String), String(String),
@ -111,6 +113,12 @@ impl std::convert::Into<Primitive> for String {
} }
} }
impl std::convert::Into<Primitive> for &str {
fn into(self) -> Primitive {
Primitive::String(self.to_string())
}
}
impl std::convert::Into<Primitive> for () { impl std::convert::Into<Primitive> for () {
fn into(self) -> Primitive { fn into(self) -> Primitive {
Primitive::Empty Primitive::Empty

View file

@ -13,6 +13,7 @@ pub fn socket_addr(port: u16) -> SocketAddr {
SocketAddr::V4(SocketAddrV4::new(HOST, port)) SocketAddr::V4(SocketAddrV4::new(HOST, port))
} }
/// Accepted Packet types and the data they contain
pub enum Packet { pub enum Packet {
Call(RemoteCall), Call(RemoteCall),
CallResponse(RemoteCallResponse), CallResponse(RemoteCallResponse),
@ -25,6 +26,7 @@ pub enum Packet {
} }
impl Packet { impl Packet {
/// Byte representing the packet type -- the first byte of any packet in USDPL
const fn discriminant(&self) -> u8 { const fn discriminant(&self) -> u8 {
match self { match self {
Self::Call(_) => 1, Self::Call(_) => 1,

View file

@ -1,12 +1,12 @@
[package] [package]
name = "usdpl" name = "usdpl"
description = "WASM front-end library for USDPL"
version = "0.1.0" version = "0.1.0"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"] authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
edition = "2021" edition = "2021"
license = "GPL-3.0-only" license = "GPL-3.0-only"
repository = "https://github.com/NGnius/usdpl-rs" repository = "https://github.com/NGnius/usdpl-rs"
readme = "../README.md" readme = "../README.md"
description = "Universal Steam Deck Plugin Library front-end designed for WASM"
[lib] [lib]
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]

0
usdpl-front/README.md Normal file
View file