generated from Patagia/template-nix
This commit is contained in:
parent
8e99ab4555
commit
d8c9107839
18 changed files with 1012 additions and 51 deletions
1
systemd-ipc/.gitignore
vendored
Normal file
1
systemd-ipc/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
17
systemd-ipc/Cargo.toml
Normal file
17
systemd-ipc/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "systemd-ipc"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_derive = "1.0.217"
|
||||
serde_json = "1.0.135"
|
||||
varlink = "11.0.1"
|
||||
|
||||
[build-dependencies]
|
||||
varlink_generator = "10.1.0"
|
||||
walkdir = "2.5.0"
|
||||
|
||||
[package.metadata.cargo-machete]
|
||||
ignored = ["serde"]
|
12
systemd-ipc/build.rs
Normal file
12
systemd-ipc/build.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
extern crate varlink_generator;
|
||||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
fn main() {
|
||||
// walk dir to find varlink files
|
||||
for entry in WalkDir::new("src").into_iter().filter_map(|e| e.ok()) {
|
||||
if entry.file_name().to_str().unwrap().ends_with(".varlink") {
|
||||
varlink_generator::cargo_build_tosource(&entry.path().display().to_string(), true);
|
||||
}
|
||||
}
|
||||
}
|
2
systemd-ipc/src/addrs.rs
Normal file
2
systemd-ipc/src/addrs.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
#[allow(dead_code)]
|
||||
pub const SYSTEMD_HOSTNAME: &str = "unix:/run/systemd/io.systemd.Hostname";
|
32
systemd-ipc/src/io.systemd.hostname.varlink
Normal file
32
systemd-ipc/src/io.systemd.hostname.varlink
Normal file
|
@ -0,0 +1,32 @@
|
|||
interface io.systemd.Hostname
|
||||
|
||||
method Describe() -> (
|
||||
Hostname: string,
|
||||
StaticHostname: ?string,
|
||||
PrettyHostname: ?string,
|
||||
DefaultHostname: ?string,
|
||||
HostnameSource: string,
|
||||
IconName: ?string,
|
||||
Chassis: ?string,
|
||||
Deployment: ?string,
|
||||
Location: ?string,
|
||||
KernelName: string,
|
||||
KernelRelease: string,
|
||||
KernelVersion: string,
|
||||
OperatingSystemPrettyName: ?string,
|
||||
OperatingSystemCPEName: ?string,
|
||||
OperatingSystemHomeURL: ?string,
|
||||
OperatingSystemSupportEnd: ?int,
|
||||
OperatingSystemReleaseData: ?[]string,
|
||||
MachineInformationData: ?[]string,
|
||||
HardwareVendor: ?string,
|
||||
HardwareModel: ?string,
|
||||
HardwareSerial: ?string,
|
||||
FirmwareVersion: ?string,
|
||||
FirmwareVendor: ?string,
|
||||
FirmwareDate: ?int,
|
||||
MachineID: string,
|
||||
BootID: string,
|
||||
ProductUUID: ?string,
|
||||
VSockCID: ?int
|
||||
)
|
295
systemd-ipc/src/io_systemd_hostname.rs
Normal file
295
systemd-ipc/src/io_systemd_hostname.rs
Normal file
|
@ -0,0 +1,295 @@
|
|||
#![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<Box<dyn std::error::Error + 'static + Send + Sync>>,
|
||||
pub Option<&'static str>,
|
||||
);
|
||||
impl Error {
|
||||
#[allow(dead_code)]
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl From<ErrorKind> 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<T> = std::result::Result<T, Error>;
|
||||
impl From<varlink::Error> 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::<varlink::Error>())
|
||||
.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 Describe_Reply {
|
||||
pub r#Hostname: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#StaticHostname: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#PrettyHostname: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#DefaultHostname: Option<String>,
|
||||
pub r#HostnameSource: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#IconName: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#Chassis: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#Deployment: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#Location: Option<String>,
|
||||
pub r#KernelName: String,
|
||||
pub r#KernelRelease: String,
|
||||
pub r#KernelVersion: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemPrettyName: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemCPEName: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemHomeURL: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemSupportEnd: Option<i64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemReleaseData: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#MachineInformationData: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#HardwareVendor: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#HardwareModel: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#HardwareSerial: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#FirmwareVersion: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#FirmwareVendor: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#FirmwareDate: Option<i64>,
|
||||
pub r#MachineID: String,
|
||||
pub r#BootID: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#ProductUUID: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#VSockCID: Option<i64>,
|
||||
}
|
||||
impl varlink::VarlinkReply for Describe_Reply {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Describe_Args {}
|
||||
pub trait Call_Describe: VarlinkCallError {
|
||||
fn reply(
|
||||
&mut self,
|
||||
r#Hostname: String,
|
||||
r#StaticHostname: Option<String>,
|
||||
r#PrettyHostname: Option<String>,
|
||||
r#DefaultHostname: Option<String>,
|
||||
r#HostnameSource: String,
|
||||
r#IconName: Option<String>,
|
||||
r#Chassis: Option<String>,
|
||||
r#Deployment: Option<String>,
|
||||
r#Location: Option<String>,
|
||||
r#KernelName: String,
|
||||
r#KernelRelease: String,
|
||||
r#KernelVersion: String,
|
||||
r#OperatingSystemPrettyName: Option<String>,
|
||||
r#OperatingSystemCPEName: Option<String>,
|
||||
r#OperatingSystemHomeURL: Option<String>,
|
||||
r#OperatingSystemSupportEnd: Option<i64>,
|
||||
r#OperatingSystemReleaseData: Option<Vec<String>>,
|
||||
r#MachineInformationData: Option<Vec<String>>,
|
||||
r#HardwareVendor: Option<String>,
|
||||
r#HardwareModel: Option<String>,
|
||||
r#HardwareSerial: Option<String>,
|
||||
r#FirmwareVersion: Option<String>,
|
||||
r#FirmwareVendor: Option<String>,
|
||||
r#FirmwareDate: Option<i64>,
|
||||
r#MachineID: String,
|
||||
r#BootID: String,
|
||||
r#ProductUUID: Option<String>,
|
||||
r#VSockCID: Option<i64>,
|
||||
) -> varlink::Result<()> {
|
||||
self.reply_struct(
|
||||
Describe_Reply {
|
||||
r#Hostname,
|
||||
r#StaticHostname,
|
||||
r#PrettyHostname,
|
||||
r#DefaultHostname,
|
||||
r#HostnameSource,
|
||||
r#IconName,
|
||||
r#Chassis,
|
||||
r#Deployment,
|
||||
r#Location,
|
||||
r#KernelName,
|
||||
r#KernelRelease,
|
||||
r#KernelVersion,
|
||||
r#OperatingSystemPrettyName,
|
||||
r#OperatingSystemCPEName,
|
||||
r#OperatingSystemHomeURL,
|
||||
r#OperatingSystemSupportEnd,
|
||||
r#OperatingSystemReleaseData,
|
||||
r#MachineInformationData,
|
||||
r#HardwareVendor,
|
||||
r#HardwareModel,
|
||||
r#HardwareSerial,
|
||||
r#FirmwareVersion,
|
||||
r#FirmwareVendor,
|
||||
r#FirmwareDate,
|
||||
r#MachineID,
|
||||
r#BootID,
|
||||
r#ProductUUID,
|
||||
r#VSockCID,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<'a> Call_Describe for varlink::Call<'a> {}
|
||||
pub trait VarlinkInterface {
|
||||
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()>;
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
_call: &mut varlink::Call,
|
||||
_bufreader: &mut dyn BufRead,
|
||||
) -> varlink::Result<Vec<u8>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
pub trait VarlinkClientInterface {
|
||||
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error>;
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub struct VarlinkClient {
|
||||
connection: Arc<RwLock<varlink::Connection>>,
|
||||
}
|
||||
impl VarlinkClient {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(connection: Arc<RwLock<varlink::Connection>>) -> Self {
|
||||
VarlinkClient { connection }
|
||||
}
|
||||
}
|
||||
impl VarlinkClientInterface for VarlinkClient {
|
||||
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error> {
|
||||
varlink::MethodCall::<Describe_Args, Describe_Reply, Error>::new(
|
||||
self.connection.clone(),
|
||||
"io.systemd.Hostname.Describe",
|
||||
Describe_Args {},
|
||||
)
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub struct VarlinkInterfaceProxy {
|
||||
inner: Box<dyn VarlinkInterface + Send + Sync>,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn new(inner: Box<dyn VarlinkInterface + Send + Sync>) -> VarlinkInterfaceProxy {
|
||||
VarlinkInterfaceProxy { inner }
|
||||
}
|
||||
impl varlink::Interface for VarlinkInterfaceProxy {
|
||||
fn get_description(&self) -> &'static str {
|
||||
"interface io.systemd.Hostname\n\nmethod Describe() -> (\n\tHostname: string,\n\tStaticHostname: ?string,\n\tPrettyHostname: ?string,\n\tDefaultHostname: ?string,\n\tHostnameSource: string,\n\tIconName: ?string,\n\tChassis: ?string,\n\tDeployment: ?string,\n\tLocation: ?string,\n\tKernelName: string,\n\tKernelRelease: string,\n\tKernelVersion: string,\n\tOperatingSystemPrettyName: ?string,\n\tOperatingSystemCPEName: ?string,\n\tOperatingSystemHomeURL: ?string,\n\tOperatingSystemSupportEnd: ?int,\n\tOperatingSystemReleaseData: ?[]string,\n\tMachineInformationData: ?[]string,\n\tHardwareVendor: ?string,\n\tHardwareModel: ?string,\n\tHardwareSerial: ?string,\n\tFirmwareVersion: ?string,\n\tFirmwareVendor: ?string,\n\tFirmwareDate: ?int,\n\tMachineID: string,\n\tBootID: string,\n\tProductUUID: ?string,\n\tVSockCID: ?int\n)\n"
|
||||
}
|
||||
fn get_name(&self) -> &'static str {
|
||||
"io.systemd.Hostname"
|
||||
}
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
call: &mut varlink::Call,
|
||||
bufreader: &mut dyn BufRead,
|
||||
) -> varlink::Result<Vec<u8>> {
|
||||
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() {
|
||||
"io.systemd.Hostname.Describe" => self.inner.describe(call as &mut dyn Call_Describe),
|
||||
m => call.reply_method_not_found(String::from(m)),
|
||||
}
|
||||
}
|
||||
}
|
2
systemd-ipc/src/lib.rs
Normal file
2
systemd-ipc/src/lib.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod addrs;
|
||||
pub mod io_systemd_hostname;
|
Loading…
Add table
Add a link
Reference in a new issue