feat: add hostname1-zbus
This commit is contained in:
parent
c81f428ace
commit
a5024e0a3d
4 changed files with 209 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ resolver = "2"
|
|||
members = [
|
||||
"cosmic-settings-daemon",
|
||||
"geoclue2",
|
||||
"hostname1",
|
||||
"mpris2",
|
||||
"networkmanager",
|
||||
"switcheroo-control",
|
||||
|
|
|
|||
16
hostname1/Cargo.toml
Normal file
16
hostname1/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "hostname1-zbus"
|
||||
version = "0.1.0"
|
||||
description = "dbus bindings for org.freedesktop.hostname1 with zbus"
|
||||
repository = "https://github.com/pop-os/dbus-settings-bindings"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
categories = ["os::linux-apis"]
|
||||
keywords = ["dbus", "hostname", "hostname1", "zbus", "org.freedesktop.hostname1"]
|
||||
|
||||
[dependencies]
|
||||
zbus = "3.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
pico-args = "0.5.0"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
67
hostname1/examples/hostnamectl.rs
Normal file
67
hostname1/examples/hostnamectl.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use std::process::ExitCode;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
let proxy = hostname1_zbus::Hostname1Proxy::new(&connection).await?;
|
||||
|
||||
let mut parser = pico_args::Arguments::from_env();
|
||||
|
||||
match parser.subcommand()?.as_deref() {
|
||||
Some("hostname") => match parser.subcommand()?.as_deref() {
|
||||
Some("set") => match parser.free_from_str::<String>().ok().as_deref() {
|
||||
Some(new_hostname) => {
|
||||
if let Err(why) = proxy.set_hostname(&new_hostname, false).await {
|
||||
eprintln!("error: could not set hostname: {why}");
|
||||
return Ok(ExitCode::FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
None => {
|
||||
eprintln!("error: hostname argument not set");
|
||||
return Ok(ExitCode::FAILURE);
|
||||
}
|
||||
},
|
||||
|
||||
_ => {
|
||||
println!("{}", proxy.hostname().await?);
|
||||
}
|
||||
},
|
||||
|
||||
Some("static-hostname") => match parser.subcommand()?.as_deref() {
|
||||
Some("set") => match parser.free_from_str::<String>().ok().as_deref() {
|
||||
Some(new_hostname) => {
|
||||
if let Err(why) = proxy.set_static_hostname(&new_hostname, false).await {
|
||||
eprintln!("error: could not set hostname: {why}");
|
||||
return Ok(ExitCode::FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
None => {
|
||||
eprintln!("error: hostname argument not set");
|
||||
return Ok(ExitCode::FAILURE);
|
||||
}
|
||||
},
|
||||
|
||||
_ => {
|
||||
println!("{}", proxy.static_hostname().await?);
|
||||
}
|
||||
},
|
||||
|
||||
_ => print_help(),
|
||||
}
|
||||
|
||||
Ok(ExitCode::SUCCESS)
|
||||
}
|
||||
|
||||
fn print_help() {
|
||||
println!(
|
||||
"\
|
||||
hostnamectl
|
||||
|
||||
USAGE:
|
||||
hostnamectl hostname
|
||||
hostnamectl hostname set NAME
|
||||
"
|
||||
);
|
||||
}
|
||||
125
hostname1/src/lib.rs
Normal file
125
hostname1/src/lib.rs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.hostname1`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `3.1.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/hostname1' from service 'org.freedesktop.hostname1' on system bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This DBus object implements
|
||||
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.freedesktop.hostname1",
|
||||
default_service = "org.freedesktop.hostname1",
|
||||
default_path = "/org/freedesktop/hostname1"
|
||||
)]
|
||||
trait Hostname1 {
|
||||
/// Describe method
|
||||
fn describe(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetProductUUID method
|
||||
#[dbus_proxy(name = "GetProductUUID")]
|
||||
fn get_product_uuid(&self, interactive: bool) -> zbus::Result<Vec<u8>>;
|
||||
|
||||
/// SetChassis method
|
||||
fn set_chassis(&self, chassis: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetDeployment method
|
||||
fn set_deployment(&self, deployment: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetHostname method
|
||||
fn set_hostname(&self, hostname: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetIconName method
|
||||
fn set_icon_name(&self, icon: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetLocation method
|
||||
fn set_location(&self, location: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetPrettyHostname method
|
||||
fn set_pretty_hostname(&self, hostname: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetStaticHostname method
|
||||
fn set_static_hostname(&self, hostname: &str, interactive: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Chassis property
|
||||
#[dbus_proxy(property)]
|
||||
fn chassis(&self) -> zbus::Result<String>;
|
||||
|
||||
/// DefaultHostname property
|
||||
#[dbus_proxy(property)]
|
||||
fn default_hostname(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Deployment property
|
||||
#[dbus_proxy(property)]
|
||||
fn deployment(&self) -> zbus::Result<String>;
|
||||
|
||||
/// HardwareModel property
|
||||
#[dbus_proxy(property)]
|
||||
fn hardware_model(&self) -> zbus::Result<String>;
|
||||
|
||||
/// HardwareVendor property
|
||||
#[dbus_proxy(property)]
|
||||
fn hardware_vendor(&self) -> zbus::Result<String>;
|
||||
|
||||
/// HomeURL property
|
||||
#[dbus_proxy(property, name = "HomeURL")]
|
||||
fn home_url(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Hostname property
|
||||
#[dbus_proxy(property)]
|
||||
fn hostname(&self) -> zbus::Result<String>;
|
||||
|
||||
/// HostnameSource property
|
||||
#[dbus_proxy(property)]
|
||||
fn hostname_source(&self) -> zbus::Result<String>;
|
||||
|
||||
/// IconName property
|
||||
#[dbus_proxy(property)]
|
||||
fn icon_name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// KernelName property
|
||||
#[dbus_proxy(property)]
|
||||
fn kernel_name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// KernelRelease property
|
||||
#[dbus_proxy(property)]
|
||||
fn kernel_release(&self) -> zbus::Result<String>;
|
||||
|
||||
/// KernelVersion property
|
||||
#[dbus_proxy(property)]
|
||||
fn kernel_version(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Location property
|
||||
#[dbus_proxy(property)]
|
||||
fn location(&self) -> zbus::Result<String>;
|
||||
|
||||
/// OperatingSystemCPEName property
|
||||
#[dbus_proxy(property, name = "OperatingSystemCPEName")]
|
||||
fn operating_system_cpename(&self) -> zbus::Result<String>;
|
||||
|
||||
/// OperatingSystemPrettyName property
|
||||
#[dbus_proxy(property)]
|
||||
fn operating_system_pretty_name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// PrettyHostname property
|
||||
#[dbus_proxy(property)]
|
||||
fn pretty_hostname(&self) -> zbus::Result<String>;
|
||||
|
||||
/// StaticHostname property
|
||||
#[dbus_proxy(property)]
|
||||
fn static_hostname(&self) -> zbus::Result<String>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue