From e156603bd6f63ab800c6a87706fdbf57b5ed1a64 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Sat, 9 Nov 2024 11:44:45 +0000 Subject: [PATCH] moss: Add basic scaffolding for upcoming varlink integration While not currently used, this now adds relevant build + cargo changes to integrate varlink with moss, such that when the time is right we can add RPC over varlink to moss for integration into packagekitd, lichen, etc. This change is landing early as multiple ongoing large PRs would constantly need rebasing thanks to lockfile cruft. Signed-off-by: Ikey Doherty --- Cargo.lock | 216 +++++++++++++++----- Cargo.toml | 3 + moss/Cargo.toml | 5 + moss/build.rs | 6 + moss/src/lib.rs | 2 + moss/src/varlink/com.serpentos.moss.varlink | 4 + moss/src/varlink/com_serpentos_moss.rs | 177 ++++++++++++++++ moss/src/varlink/mod.rs | 6 + 8 files changed, 372 insertions(+), 47 deletions(-) create mode 100644 moss/build.rs create mode 100644 moss/src/varlink/com.serpentos.moss.varlink create mode 100644 moss/src/varlink/com_serpentos_moss.rs create mode 100644 moss/src/varlink/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 2c9b2462..e7b8ab71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,15 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anstream" version = "0.6.15" @@ -194,7 +203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" dependencies = [ "async-lock", - "cfg-if", + "cfg-if 1.0.0", "concurrent-queue", "futures-io", "futures-lite", @@ -229,7 +238,7 @@ dependencies = [ "async-signal", "async-task", "blocking", - "cfg-if", + "cfg-if 1.0.0", "event-listener", "futures-lite", "rustix", @@ -244,7 +253,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -256,7 +265,7 @@ dependencies = [ "async-io", "async-lock", "atomic-waker", - "cfg-if", + "cfg-if 1.0.0", "futures-core", "futures-io", "rustix", @@ -279,7 +288,7 @@ checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -301,7 +310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -330,7 +339,7 @@ dependencies = [ "arrayref", "arrayvec", "cc", - "cfg-if", + "cfg-if 1.0.0", "constant_time_eq", "memmap2", "rayon-core", @@ -468,6 +477,12 @@ dependencies = [ "shlex", ] +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -486,6 +501,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chainerror" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce1bb7fb0c258a6600d699950da347a7a9dad66c3ce815769b5f11cf8fce78e" + [[package]] name = "charset" version = "0.1.5" @@ -577,7 +598,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -693,7 +714,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -826,7 +847,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.77", ] [[package]] @@ -837,7 +858,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -865,7 +886,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn", + "syn 2.0.77", ] [[package]] @@ -902,7 +923,7 @@ dependencies = [ "dsl_auto_type", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -922,7 +943,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" dependencies = [ - "syn", + "syn 2.0.77", ] [[package]] @@ -967,7 +988,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -994,7 +1015,7 @@ version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1021,7 +1042,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1186,7 +1207,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1229,13 +1250,22 @@ dependencies = [ "version_check", ] +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + [[package]] name = "getrandom" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -1289,7 +1319,7 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crunchy", ] @@ -1490,7 +1520,7 @@ dependencies = [ "proc-macro2", "quote", "strum", - "syn", + "syn 2.0.77", "thiserror", ] @@ -1513,7 +1543,7 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1764,6 +1794,7 @@ dependencies = [ "rayon", "reqwest", "serde", + "serde_derive", "serpent_buildinfo", "sha2", "stone", @@ -1774,6 +1805,8 @@ dependencies = [ "triggers", "tui", "url", + "varlink", + "varlink_generator", "vfs", "xxhash-rust", "zbus", @@ -1786,7 +1819,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "libc", ] @@ -1797,7 +1830,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "cfg_aliases 0.1.1", "libc", ] @@ -1809,7 +1842,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "cfg_aliases 0.2.1", "libc", "memoffset", @@ -1905,13 +1938,40 @@ version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", "windows-targets 0.52.6", ] +[[package]] +name = "peg" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367" +dependencies = [ + "peg-macros", + "peg-runtime", +] + +[[package]] +name = "peg-macros" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d" +dependencies = [ + "peg-runtime", + "proc-macro2", + "quote", +] + +[[package]] +name = "peg-runtime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1945,7 +2005,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2011,7 +2071,7 @@ version = "3.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "concurrent-queue", "hermit-abi 0.4.0", "pin-project-lite", @@ -2275,7 +2335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", - "cfg-if", + "cfg-if 1.0.0", "getrandom", "libc", "spin", @@ -2414,7 +2474,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2437,7 +2497,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2488,7 +2548,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", ] @@ -2499,7 +2559,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", ] @@ -2631,7 +2691,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.77", ] [[package]] @@ -2650,6 +2710,17 @@ dependencies = [ "uuid", ] +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.77" @@ -2676,7 +2747,7 @@ version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "once_cell", "rustix", @@ -2700,7 +2771,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2710,7 +2781,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d3b04d33c9633b8662b167b847c7ab521f83d1ae20f2321b65b5b925e532e36" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "libc", "log", "rustversion", @@ -2799,7 +2870,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2918,7 +2989,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -3000,6 +3071,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unix_socket" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564" +dependencies = [ + "cfg-if 0.1.10", + "libc", +] + [[package]] name = "unsafe-libyaml" version = "0.2.11" @@ -3039,6 +3120,47 @@ dependencies = [ "getrandom", ] +[[package]] +name = "varlink" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "409e275987d74665c23610c0959c133360cafd761c1a6ddb1ca6d0685c8cef5d" +dependencies = [ + "libc", + "serde", + "serde_derive", + "serde_json", + "tempfile", + "uds_windows", + "unix_socket", + "winapi", +] + +[[package]] +name = "varlink_generator" +version = "10.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d8ff746c5b65d4bfb3a50f630b85cfb6a9d59f18720126e3ebd6bc98527fa51" +dependencies = [ + "chainerror", + "getopts", + "proc-macro2", + "quote", + "syn 1.0.109", + "varlink_parser", +] + +[[package]] +name = "varlink_parser" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35fb9f3c1e8ccb33cdb6c84a4477ef3f3884ce6f4b70514ef1fbf7686eae921e" +dependencies = [ + "ansi_term", + "chainerror", + "peg", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -3090,7 +3212,7 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "wasm-bindgen-macro", ] @@ -3106,7 +3228,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -3116,7 +3238,7 @@ version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -3140,7 +3262,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3477,7 +3599,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.77", "zvariant_utils", ] @@ -3510,7 +3632,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -3569,7 +3691,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.77", "zvariant_utils", ] @@ -3581,5 +3703,5 @@ checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] diff --git a/Cargo.toml b/Cargo.toml index 71384412..c9610df9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ rayon = "1.10.0" regex = "1.10.5" reqwest = { version = "0.12.5", default-features = false, features = ["brotli", "charset", "deflate", "gzip", "http2", "rustls-tls", "stream", "zstd"] } serde = { version = "1.0.204", features = ["derive"] } +serde_derive = "1.0.204" serde_json = "1.0.120" serde_yaml = "0.9.34" sha2 = "0.10.8" @@ -55,6 +56,8 @@ tokio = { version = "1.38.0", features = ["full"] } tokio-stream = { version = "0.1.15", features = ["time"] } tokio-util = { version = "0.7.11", features = ["io"] } url = { version = "2.5.2", features = ["serde"] } +varlink = "11.0.1" +varlink_generator = "10.1.0" xxhash-rust = { version = "0.8.11", features = ["xxh3"] } zstd = { version = "0.13.2", features = ["zstdmt"] } mailparse = "0.15.0" diff --git a/moss/Cargo.toml b/moss/Cargo.toml index 9b81d627..6fe9ec93 100644 --- a/moss/Cargo.toml +++ b/moss/Cargo.toml @@ -4,6 +4,9 @@ edition.workspace = true version.workspace = true rust-version.workspace = true +[build-dependencies] +varlink_generator.workspace = true + [dependencies] config = { path = "../crates/config" } container = { path = "../crates/container" } @@ -34,12 +37,14 @@ nix.workspace = true rayon.workspace = true reqwest.workspace = true serde.workspace = true +serde_derive.workspace = true sha2.workspace = true strum.workspace = true tokio.workspace = true tokio-util.workspace = true thiserror.workspace = true url.workspace = true +varlink.workspace = true xxhash-rust.workspace = true zbus.workspace = true diff --git a/moss/build.rs b/moss/build.rs new file mode 100644 index 00000000..e049882e --- /dev/null +++ b/moss/build.rs @@ -0,0 +1,6 @@ +extern crate varlink_generator; + +fn main() { + println!("cargo:rerun-if-changed=src/varlink/com.serpentos.moss.varlink"); + varlink_generator::cargo_build_tosource("src/varlink/com.serpentos.moss.varlink", true); +} diff --git a/moss/src/lib.rs b/moss/src/lib.rs index f1cb8cf8..ce2fe88e 100644 --- a/moss/src/lib.rs +++ b/moss/src/lib.rs @@ -23,3 +23,5 @@ pub mod request; pub mod runtime; pub mod signal; pub mod state; + +mod varlink; diff --git a/moss/src/varlink/com.serpentos.moss.varlink b/moss/src/varlink/com.serpentos.moss.varlink new file mode 100644 index 00000000..d2c9c344 --- /dev/null +++ b/moss/src/varlink/com.serpentos.moss.varlink @@ -0,0 +1,4 @@ +interface com.serpentos.moss + +# Placeholder until we add real varlink API +method Version() -> (version: string) \ No newline at end of file diff --git a/moss/src/varlink/com_serpentos_moss.rs b/moss/src/varlink/com_serpentos_moss.rs new file mode 100644 index 00000000..ec68a010 --- /dev/null +++ b/moss/src/varlink/com_serpentos_moss.rs @@ -0,0 +1,177 @@ +#![doc = "This file was automatically generated by the varlink rust generator"] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +use serde_derive::{Deserialize, Serialize}; +use std::io::BufRead; +use std::sync::{Arc, RwLock}; +use varlink::{self, CallTrait}; +#[allow(dead_code)] +#[derive(Clone, PartialEq, Debug)] +#[allow(clippy::enum_variant_names)] +pub enum ErrorKind { + Varlink_Error, + VarlinkReply_Error, +} +impl ::std::fmt::Display for ErrorKind { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + match self { + ErrorKind::Varlink_Error => write!(f, "Varlink Error"), + ErrorKind::VarlinkReply_Error => write!(f, "Varlink error reply"), + } + } +} +pub struct Error( + pub ErrorKind, + pub Option>, + pub Option<&'static str>, +); +impl Error { + #[allow(dead_code)] + pub fn kind(&self) -> &ErrorKind { + &self.0 + } +} +impl From for Error { + fn from(e: ErrorKind) -> Self { + Error(e, None, None) + } +} +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + self.1 + .as_ref() + .map(|e| e.as_ref() as &(dyn std::error::Error + 'static)) + } +} +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } +} +impl std::fmt::Debug for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + use std::error::Error as StdError; + if let Some(ref o) = self.2 { + std::fmt::Display::fmt(o, f)?; + } + std::fmt::Debug::fmt(&self.0, f)?; + if let Some(e) = self.source() { + std::fmt::Display::fmt("\nCaused by:\n", f)?; + std::fmt::Debug::fmt(&e, f)?; + } + Ok(()) + } +} +#[allow(dead_code)] +pub type Result = std::result::Result; +impl From for Error { + fn from(e: varlink::Error) -> Self { + match e.kind() { + varlink::ErrorKind::VarlinkErrorReply(r) => Error( + ErrorKind::from(r), + Some(Box::from(e)), + Some(concat!(file!(), ":", line!(), ": ")), + ), + _ => Error( + ErrorKind::Varlink_Error, + Some(Box::from(e)), + Some(concat!(file!(), ":", line!(), ": ")), + ), + } + } +} +#[allow(dead_code)] +impl Error { + pub fn source_varlink_kind(&self) -> Option<&varlink::ErrorKind> { + use std::error::Error as StdError; + let mut s: &dyn StdError = self; + while let Some(c) = s.source() { + let k = self + .source() + .and_then(|e| e.downcast_ref::()) + .map(|e| e.kind()); + if k.is_some() { + return k; + } + s = c; + } + None + } +} +impl From<&varlink::Reply> for ErrorKind { + #[allow(unused_variables)] + fn from(e: &varlink::Reply) -> Self { + match e { + _ => ErrorKind::VarlinkReply_Error, + } + } +} +pub trait VarlinkCallError: varlink::CallTrait {} +impl<'a> VarlinkCallError for varlink::Call<'a> {} +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Version_Reply { + pub r#version: String, +} +impl varlink::VarlinkReply for Version_Reply {} +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Version_Args {} +pub trait Call_Version: VarlinkCallError { + fn reply(&mut self, r#version: String) -> varlink::Result<()> { + self.reply_struct(Version_Reply { r#version }.into()) + } +} +impl<'a> Call_Version for varlink::Call<'a> {} +pub trait VarlinkInterface { + fn version(&self, call: &mut dyn Call_Version) -> varlink::Result<()>; + fn call_upgraded(&self, _call: &mut varlink::Call, _bufreader: &mut dyn BufRead) -> varlink::Result> { + Ok(Vec::new()) + } +} +pub trait VarlinkClientInterface { + fn version(&mut self) -> varlink::MethodCall; +} +#[allow(dead_code)] +pub struct VarlinkClient { + connection: Arc>, +} +impl VarlinkClient { + #[allow(dead_code)] + pub fn new(connection: Arc>) -> Self { + VarlinkClient { connection } + } +} +impl VarlinkClientInterface for VarlinkClient { + fn version(&mut self) -> varlink::MethodCall { + varlink::MethodCall::::new( + self.connection.clone(), + "com.serpentos.moss.Version", + Version_Args {}, + ) + } +} +#[allow(dead_code)] +pub struct VarlinkInterfaceProxy { + inner: Box, +} +#[allow(dead_code)] +pub fn new(inner: Box) -> VarlinkInterfaceProxy { + VarlinkInterfaceProxy { inner } +} +impl varlink::Interface for VarlinkInterfaceProxy { + fn get_description(&self) -> &'static str { + "interface com.serpentos.moss\n\n# Placeholder until we add real varlink API\nmethod Version() -> (version: string)" + } + fn get_name(&self) -> &'static str { + "com.serpentos.moss" + } + fn call_upgraded(&self, call: &mut varlink::Call, bufreader: &mut dyn BufRead) -> varlink::Result> { + self.inner.call_upgraded(call, bufreader) + } + fn call(&self, call: &mut varlink::Call) -> varlink::Result<()> { + let req = call.request.unwrap(); + match req.method.as_ref() { + "com.serpentos.moss.Version" => self.inner.version(call as &mut dyn Call_Version), + m => call.reply_method_not_found(String::from(m)), + } + } +} diff --git a/moss/src/varlink/mod.rs b/moss/src/varlink/mod.rs new file mode 100644 index 00000000..6954e3f9 --- /dev/null +++ b/moss/src/varlink/mod.rs @@ -0,0 +1,6 @@ +// SPDX-FileCopyrightText: Copyright © 2020-2024 Serpent OS Developers +// +// SPDX-License-Identifier: MPL-2.0 + +#[allow(dead_code)] +mod com_serpentos_moss;