mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-17 19:56:41 -04:00
Add steamosctl.
Add a second binary which is a command-line utility to get and set the properties of the DBus api. Add commands to set wifi debug mode and backend.
This commit is contained in:
parent
c3011c93aa
commit
8788e99245
6 changed files with 327 additions and 30 deletions
28
src/bin/steamos-manager.rs
Normal file
28
src/bin/steamos-manager.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright © 2023 Collabora Ltd.
|
||||
* Copyright © 2024 Valve Software
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
|
||||
use steamos_manager::{RootDaemon, UserDaemon};
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
/// Run the root manager daemon
|
||||
#[arg(short, long)]
|
||||
root: bool,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
if args.root {
|
||||
RootDaemon().await
|
||||
} else {
|
||||
UserDaemon().await
|
||||
}
|
||||
}
|
89
src/bin/steamosctl.rs
Normal file
89
src/bin/steamosctl.rs
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright © 2023 Collabora Ltd.
|
||||
* Copyright © 2024 Valve Software
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
use steamos_manager::{ManagerProxy, WifiBackend};
|
||||
use zbus::fdo::PropertiesProxy;
|
||||
use zbus::names::InterfaceName;
|
||||
use zbus::{zvariant, Connection};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Optionally get all properties
|
||||
#[arg(short, long)]
|
||||
all_properties: bool,
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
SetWifiBackend {
|
||||
// Set the wifi backend to given string if possible
|
||||
// Supported values are iwd|wpa_supplicant
|
||||
#[arg(short, long)]
|
||||
backend: String,
|
||||
},
|
||||
|
||||
SetWifiDebugMode {
|
||||
// Set wifi debug mode to given value
|
||||
// 1 for on, 0 for off currently
|
||||
#[arg(short, long)]
|
||||
mode: u32,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// This is a command-line utility that calls api using dbus
|
||||
|
||||
// First set up which command line arguments we support
|
||||
let args = Args::parse();
|
||||
|
||||
// Then get a connection to the service
|
||||
let conn = Connection::system().await?;
|
||||
let proxy = ManagerProxy::builder(&conn).build().await?;
|
||||
|
||||
if args.all_properties {
|
||||
let properties_proxy = PropertiesProxy::new(
|
||||
&conn,
|
||||
"com.steampowered.SteamOSManager1",
|
||||
"/com/steampowered/SteamOSManager1",
|
||||
)
|
||||
.await?;
|
||||
let name = InterfaceName::try_from("com.steampowered.SteamOSManager1.Manager")?;
|
||||
let properties = properties_proxy
|
||||
.get_all(zvariant::Optional::from(Some(name)))
|
||||
.await?;
|
||||
for (key, value) in properties.iter() {
|
||||
let val = value.deref();
|
||||
println!("{key}: {val}");
|
||||
}
|
||||
}
|
||||
|
||||
// Then process arguments
|
||||
match &args.command {
|
||||
Some(Commands::SetWifiBackend { backend }) => match WifiBackend::from_str(backend) {
|
||||
Ok(b) => {
|
||||
proxy.set_wifi_backend(b as u32).await?;
|
||||
}
|
||||
Err(_) => {
|
||||
println!("Unknown wifi backend {backend}");
|
||||
}
|
||||
},
|
||||
Some(Commands::SetWifiDebugMode { mode }) => {
|
||||
proxy.set_wifi_debug_mode(*mode, 20000).await?;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::Parser;
|
||||
use std::future::Future;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tokio::fs::File;
|
||||
|
@ -22,6 +21,7 @@ mod hardware;
|
|||
mod manager;
|
||||
mod power;
|
||||
mod process;
|
||||
mod proxy;
|
||||
mod root;
|
||||
mod sls;
|
||||
mod systemd;
|
||||
|
@ -32,9 +32,14 @@ mod wifi;
|
|||
#[cfg(test)]
|
||||
mod testing;
|
||||
|
||||
pub use proxy::ManagerProxy;
|
||||
pub use root::daemon as RootDaemon;
|
||||
pub use user::daemon as UserDaemon;
|
||||
pub use wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement};
|
||||
|
||||
const API_VERSION: u32 = 8;
|
||||
|
||||
trait Service
|
||||
pub trait Service
|
||||
where
|
||||
Self: Sized + Send,
|
||||
{
|
||||
|
@ -67,13 +72,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
/// Run the root manager daemon
|
||||
#[arg(short, long)]
|
||||
root: bool,
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub fn path<S: AsRef<str>>(path: S) -> PathBuf {
|
||||
PathBuf::from(path.as_ref())
|
||||
|
@ -156,16 +154,6 @@ pub fn zbus_to_zbus_fdo(error: zbus::Error) -> zbus::fdo::Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
if args.root {
|
||||
root::daemon().await
|
||||
} else {
|
||||
user::daemon().await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::testing;
|
140
src/proxy.rs
Normal file
140
src/proxy.rs
Normal file
|
@ -0,0 +1,140 @@
|
|||
//! # D-Bus interface proxy for: `com.steampowered.SteamOSManager1.Manager`
|
||||
//! and `com.steampowered.SteamOSManager1.Subprocess`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `4.1.0` from D-Bus introspection data.
|
||||
//! Source: `com.steampowered.SteamOSManager1.xml`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the [Writing a client proxy] section of the zbus
|
||||
//! documentation.
|
||||
//!
|
||||
//!
|
||||
//! [Writing a client proxy]: https://dbus2.github.io/zbus/client.html
|
||||
//! [D-Bus standard interfaces]: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces,
|
||||
use zbus::proxy;
|
||||
|
||||
#[proxy(
|
||||
default_service = "com.steampowered.SteamOSManager1",
|
||||
default_path = "/com/steampowered/SteamOSManager1",
|
||||
interface = "com.steampowered.SteamOSManager1.Manager"
|
||||
)]
|
||||
trait Manager {
|
||||
/// FormatDevice method
|
||||
fn format_device(
|
||||
&self,
|
||||
device: &str,
|
||||
label: &str,
|
||||
validate: bool,
|
||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// GetAlsIntegrationTimeFileDescriptor method
|
||||
fn get_als_integration_time_file_descriptor(&self) -> zbus::Result<zbus::zvariant::OwnedFd>;
|
||||
|
||||
/// PrepareFactoryReset method
|
||||
fn prepare_factory_reset(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// SetWifiDebugMode method
|
||||
fn set_wifi_debug_mode(&self, mode: u32, buffer_size: u32) -> zbus::Result<()>;
|
||||
|
||||
/// TrimDevices method
|
||||
fn trim_devices(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// UpdateBIOS method
|
||||
fn update_bios(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// UpdateDock method
|
||||
fn update_dock(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// AlsCalibrationGain property
|
||||
#[zbus(property)]
|
||||
fn als_calibration_gain(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// FanControlState property
|
||||
#[zbus(property)]
|
||||
fn fan_control_state(&self) -> zbus::Result<u32>;
|
||||
#[zbus(property)]
|
||||
fn set_fan_control_state(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// GpuPerformanceLevel property
|
||||
#[zbus(property)]
|
||||
fn gpu_performance_level(&self) -> zbus::Result<u32>;
|
||||
#[zbus(property)]
|
||||
fn set_gpu_performance_level(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// HardwareCurrentlySupported property
|
||||
#[zbus(property)]
|
||||
fn hardware_currently_supported(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// ManualGpuClock property
|
||||
#[zbus(property)]
|
||||
fn manual_gpu_clock(&self) -> zbus::Result<u32>;
|
||||
#[zbus(property)]
|
||||
fn set_manual_gpu_clock(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// ManualGpuClockMax property
|
||||
#[zbus(property)]
|
||||
fn manual_gpu_clock_max(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// ManualGpuClockMin property
|
||||
#[zbus(property)]
|
||||
fn manual_gpu_clock_min(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// TdpLimit property
|
||||
#[zbus(property)]
|
||||
fn tdp_limit(&self) -> zbus::Result<u32>;
|
||||
#[zbus(property)]
|
||||
fn set_tdp_limit(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// TdpLimitMax property
|
||||
#[zbus(property)]
|
||||
fn tdp_limit_max(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// TdpLimitMin property
|
||||
#[zbus(property)]
|
||||
fn tdp_limit_min(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Version property
|
||||
#[zbus(property)]
|
||||
fn version(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// WifiBackend property
|
||||
#[zbus(property)]
|
||||
fn wifi_backend(&self) -> zbus::Result<u32>;
|
||||
#[zbus(property)]
|
||||
fn set_wifi_backend(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// WifiDebugModeState property
|
||||
#[zbus(property)]
|
||||
fn wifi_debug_mode_state(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// WifiPowerManagementState property
|
||||
#[zbus(property)]
|
||||
fn wifi_power_management_state(&self) -> zbus::Result<u32>;
|
||||
#[zbus(property)]
|
||||
fn set_wifi_power_management_state(&self, value: u32) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[proxy(
|
||||
interface = "com.steampowered.SteamOSManager1.SubProcess",
|
||||
assume_defaults = true
|
||||
)]
|
||||
trait SubProcess {
|
||||
/// Cancel method
|
||||
fn cancel(&self) -> zbus::Result<()>;
|
||||
|
||||
/// ExitCode method
|
||||
fn exit_code(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// WaitForExitCode method
|
||||
fn wait_for_exit_code(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// Kill method
|
||||
fn kill(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Pause method
|
||||
fn pause(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Resume method
|
||||
fn resume(&self) -> zbus::Result<()>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue