mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-15 10:46:41 -04:00
Merge branch 'endrift/cleanup' into 'master'
Minor cleanup See merge request holo/steamos-manager!23
This commit is contained in:
commit
95671ebce7
14 changed files with 142 additions and 127 deletions
|
@ -8,7 +8,7 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use steamos_manager::{RootDaemon, UserDaemon};
|
use steamos_manager::daemon;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
@ -21,8 +21,8 @@ struct Args {
|
||||||
pub async fn main() -> Result<()> {
|
pub async fn main() -> Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
if args.root {
|
if args.root {
|
||||||
RootDaemon().await
|
daemon::root().await
|
||||||
} else {
|
} else {
|
||||||
UserDaemon().await
|
daemon::user().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ use clap::{Parser, Subcommand};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use steamos_manager::{ManagerProxy, WifiBackend};
|
use steamos_manager::proxy::ManagerProxy;
|
||||||
|
use steamos_manager::wifi::WifiBackend;
|
||||||
use zbus::fdo::PropertiesProxy;
|
use zbus::fdo::PropertiesProxy;
|
||||||
use zbus::names::InterfaceName;
|
use zbus::names::InterfaceName;
|
||||||
use zbus::{zvariant, Connection};
|
use zbus::{zvariant, Connection};
|
||||||
|
|
|
@ -17,7 +17,13 @@ use zbus::connection::Connection;
|
||||||
use crate::sls::{LogLayer, LogReceiver};
|
use crate::sls::{LogLayer, LogReceiver};
|
||||||
use crate::{reload, Service};
|
use crate::{reload, Service};
|
||||||
|
|
||||||
pub struct Daemon {
|
mod root;
|
||||||
|
mod user;
|
||||||
|
|
||||||
|
pub use root::daemon as root;
|
||||||
|
pub use user::daemon as user;
|
||||||
|
|
||||||
|
pub(crate) struct Daemon {
|
||||||
services: JoinSet<Result<()>>,
|
services: JoinSet<Result<()>>,
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
sigterm: Signal,
|
sigterm: Signal,
|
||||||
|
@ -25,7 +31,7 @@ pub struct Daemon {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Daemon {
|
impl Daemon {
|
||||||
pub async fn new<S: SubscriberExt + Send + Sync + for<'a> LookupSpan<'a>>(
|
pub(crate) async fn new<S: SubscriberExt + Send + Sync + for<'a> LookupSpan<'a>>(
|
||||||
subscriber: S,
|
subscriber: S,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
) -> Result<Daemon> {
|
) -> Result<Daemon> {
|
||||||
|
@ -51,13 +57,13 @@ impl Daemon {
|
||||||
Ok(daemon)
|
Ok(daemon)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_service<S: Service + 'static>(&mut self, service: S) {
|
pub(crate) fn add_service<S: Service + 'static>(&mut self, service: S) {
|
||||||
let token = self.token.clone();
|
let token = self.token.clone();
|
||||||
self.services
|
self.services
|
||||||
.spawn(async move { service.start(token).await });
|
.spawn(async move { service.start(token).await });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self) -> Result<()> {
|
pub(crate) async fn run(&mut self) -> Result<()> {
|
||||||
ensure!(
|
ensure!(
|
||||||
!self.services.is_empty(),
|
!self.services.is_empty(),
|
||||||
"Can't run a daemon with no services attached."
|
"Can't run a daemon with no services attached."
|
|
@ -14,7 +14,7 @@ use zbus::ConnectionBuilder;
|
||||||
|
|
||||||
use crate::daemon::Daemon;
|
use crate::daemon::Daemon;
|
||||||
use crate::ds_inhibit::Inhibitor;
|
use crate::ds_inhibit::Inhibitor;
|
||||||
use crate::manager;
|
use crate::manager::root::SteamOSManager;
|
||||||
use crate::sls::ftrace::Ftrace;
|
use crate::sls::ftrace::Ftrace;
|
||||||
|
|
||||||
async fn create_connection() -> Result<Connection> {
|
async fn create_connection() -> Result<Connection> {
|
||||||
|
@ -22,7 +22,7 @@ async fn create_connection() -> Result<Connection> {
|
||||||
.name("com.steampowered.SteamOSManager1")?
|
.name("com.steampowered.SteamOSManager1")?
|
||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
let manager = manager::SteamOSManager::new(connection.clone()).await?;
|
let manager = SteamOSManager::new(connection.clone()).await?;
|
||||||
connection
|
connection
|
||||||
.object_server()
|
.object_server()
|
||||||
.at("/com/steampowered/SteamOSManager1", manager)
|
.at("/com/steampowered/SteamOSManager1", manager)
|
|
@ -13,19 +13,22 @@ use zbus::connection::Connection;
|
||||||
use zbus::ConnectionBuilder;
|
use zbus::ConnectionBuilder;
|
||||||
|
|
||||||
use crate::daemon::Daemon;
|
use crate::daemon::Daemon;
|
||||||
use crate::user_manager::SteamOSManagerUser;
|
use crate::manager::user::SteamOSManager;
|
||||||
|
|
||||||
async fn create_connection(system_conn: &Connection) -> Result<Connection> {
|
async fn create_connections() -> Result<(Connection, Connection)> {
|
||||||
|
let system = Connection::system().await?;
|
||||||
let connection = ConnectionBuilder::session()?
|
let connection = ConnectionBuilder::session()?
|
||||||
.name("com.steampowered.SteamOSManager1")?
|
.name("com.steampowered.SteamOSManager1")?
|
||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
let manager = SteamOSManagerUser::new(connection.clone(), system_conn).await?;
|
|
||||||
|
let manager = SteamOSManager::new(connection.clone(), &system).await?;
|
||||||
connection
|
connection
|
||||||
.object_server()
|
.object_server()
|
||||||
.at("/com/steampowered/SteamOSManager1", manager)
|
.at("/com/steampowered/SteamOSManager1", manager)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(connection)
|
|
||||||
|
Ok((connection, system))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn daemon() -> Result<()> {
|
pub async fn daemon() -> Result<()> {
|
||||||
|
@ -35,15 +38,7 @@ pub async fn daemon() -> Result<()> {
|
||||||
let stdout_log = fmt::layer();
|
let stdout_log = fmt::layer();
|
||||||
let subscriber = Registry::default().with(stdout_log);
|
let subscriber = Registry::default().with(stdout_log);
|
||||||
|
|
||||||
let system = match Connection::system().await {
|
let (_session, system) = match create_connections().await {
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => {
|
|
||||||
let _guard = tracing::subscriber::set_default(subscriber);
|
|
||||||
error!("Error connecting to DBus: {}", e);
|
|
||||||
bail!(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let _session = match create_connection(&system).await {
|
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _guard = tracing::subscriber::set_default(subscriber);
|
let _guard = tracing::subscriber::set_default(subscriber);
|
23
src/error.rs
Normal file
23
src/error.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Collabora Ltd.
|
||||||
|
* Copyright © 2024 Valve Software
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
use zbus::fdo;
|
||||||
|
|
||||||
|
pub fn to_zbus_fdo_error<S: ToString>(error: S) -> fdo::Error {
|
||||||
|
fdo::Error::Failed(error.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_zbus_error<S: ToString>(error: S) -> zbus::Error {
|
||||||
|
zbus::Error::Failure(error.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn zbus_to_zbus_fdo(error: zbus::Error) -> fdo::Error {
|
||||||
|
match error {
|
||||||
|
zbus::Error::FDO(error) => *error,
|
||||||
|
error => fdo::Error::Failed(error.to_string()),
|
||||||
|
}
|
||||||
|
}
|
37
src/lib.rs
37
src/lib.rs
|
@ -15,28 +15,22 @@ use tokio_util::sync::CancellationToken;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
mod cec;
|
mod cec;
|
||||||
mod daemon;
|
|
||||||
mod ds_inhibit;
|
mod ds_inhibit;
|
||||||
|
mod error;
|
||||||
mod hardware;
|
mod hardware;
|
||||||
mod manager;
|
mod manager;
|
||||||
mod power;
|
mod power;
|
||||||
mod process;
|
mod process;
|
||||||
mod proxy;
|
|
||||||
mod root;
|
|
||||||
mod sls;
|
mod sls;
|
||||||
mod systemd;
|
mod systemd;
|
||||||
mod user;
|
|
||||||
mod user_manager;
|
pub mod daemon;
|
||||||
mod wifi;
|
pub mod proxy;
|
||||||
|
pub mod wifi;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod testing;
|
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;
|
const API_VERSION: u32 = 8;
|
||||||
|
|
||||||
pub trait Service
|
pub trait Service
|
||||||
|
@ -85,18 +79,18 @@ pub fn path<S: AsRef<str>>(path: S) -> PathBuf {
|
||||||
.join(path.as_ref().trim_start_matches('/'))
|
.join(path.as_ref().trim_start_matches('/'))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn write_synced<P: AsRef<Path>>(path: P, bytes: &[u8]) -> Result<()> {
|
pub(crate) async fn write_synced<P: AsRef<Path>>(path: P, bytes: &[u8]) -> Result<()> {
|
||||||
let mut file = File::create(path.as_ref()).await?;
|
let mut file = File::create(path.as_ref()).await?;
|
||||||
file.write_all(bytes).await?;
|
file.write_all(bytes).await?;
|
||||||
Ok(file.sync_data().await?)
|
Ok(file.sync_data().await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_comm(pid: u32) -> Result<String> {
|
pub(crate) fn read_comm(pid: u32) -> Result<String> {
|
||||||
let comm = std::fs::read_to_string(path(format!("/proc/{}/comm", pid)))?;
|
let comm = std::fs::read_to_string(path(format!("/proc/{}/comm", pid)))?;
|
||||||
Ok(comm.trim_end().to_string())
|
Ok(comm.trim_end().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_appid(pid: u32) -> Result<Option<u64>> {
|
pub(crate) fn get_appid(pid: u32) -> Result<Option<u64>> {
|
||||||
let environ = std::fs::read_to_string(path(format!("/proc/{}/environ", pid)))?;
|
let environ = std::fs::read_to_string(path(format!("/proc/{}/environ", pid)))?;
|
||||||
for env_var in environ.split('\0') {
|
for env_var in environ.split('\0') {
|
||||||
let (key, value) = match env_var.split_once('=') {
|
let (key, value) = match env_var.split_once('=') {
|
||||||
|
@ -139,21 +133,6 @@ async fn reload() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_zbus_fdo_error<S: ToString>(error: S) -> zbus::fdo::Error {
|
|
||||||
zbus::fdo::Error::Failed(error.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_zbus_error<S: ToString>(error: S) -> zbus::Error {
|
|
||||||
zbus::Error::Failure(error.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn zbus_to_zbus_fdo(error: zbus::Error) -> zbus::fdo::Error {
|
|
||||||
match error {
|
|
||||||
zbus::Error::FDO(error) => *error,
|
|
||||||
error => zbus::fdo::Error::Failed(error.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::testing;
|
use crate::testing;
|
||||||
|
|
9
src/manager/mod.rs
Normal file
9
src/manager/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Collabora Ltd.
|
||||||
|
* Copyright © 2024 Valve Software
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub(crate) mod root;
|
||||||
|
pub(crate) mod user;
|
|
@ -10,8 +10,9 @@ use anyhow::Result;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use zbus::zvariant::Fd;
|
use zbus::zvariant::Fd;
|
||||||
use zbus::{interface, Connection, SignalContext};
|
use zbus::{fdo, interface, Connection, SignalContext};
|
||||||
|
|
||||||
|
use crate::error::{to_zbus_error, to_zbus_fdo_error};
|
||||||
use crate::hardware::{check_support, variant, FanControl, FanControlState, HardwareVariant};
|
use crate::hardware::{check_support, variant, FanControl, FanControlState, HardwareVariant};
|
||||||
use crate::power::{
|
use crate::power::{
|
||||||
get_gpu_clocks, get_gpu_performance_level, get_tdp_limit, set_gpu_clocks,
|
get_gpu_clocks, get_gpu_performance_level, get_tdp_limit, set_gpu_clocks,
|
||||||
|
@ -22,7 +23,7 @@ use crate::wifi::{
|
||||||
get_wifi_backend, get_wifi_power_management_state, set_wifi_backend, set_wifi_debug_mode,
|
get_wifi_backend, get_wifi_power_management_state, set_wifi_backend, set_wifi_debug_mode,
|
||||||
set_wifi_power_management_state, WifiBackend, WifiDebugMode, WifiPowerManagement,
|
set_wifi_power_management_state, WifiBackend, WifiDebugMode, WifiPowerManagement,
|
||||||
};
|
};
|
||||||
use crate::{to_zbus_error, to_zbus_fdo_error, API_VERSION};
|
use crate::API_VERSION;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
|
@ -67,7 +68,7 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn wifi_power_management_state(&self) -> zbus::fdo::Result<u32> {
|
async fn wifi_power_management_state(&self) -> fdo::Result<u32> {
|
||||||
match get_wifi_power_management_state().await {
|
match get_wifi_power_management_state().await {
|
||||||
Ok(state) => Ok(state as u32),
|
Ok(state) => Ok(state as u32),
|
||||||
Err(e) => Err(to_zbus_fdo_error(e)),
|
Err(e) => Err(to_zbus_fdo_error(e)),
|
||||||
|
@ -78,7 +79,7 @@ impl SteamOSManager {
|
||||||
async fn set_wifi_power_management_state(&self, state: u32) -> zbus::Result<()> {
|
async fn set_wifi_power_management_state(&self, state: u32) -> zbus::Result<()> {
|
||||||
let state = match WifiPowerManagement::try_from(state) {
|
let state = match WifiPowerManagement::try_from(state) {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()),
|
Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string()).into()),
|
||||||
};
|
};
|
||||||
set_wifi_power_management_state(state)
|
set_wifi_power_management_state(state)
|
||||||
.await
|
.await
|
||||||
|
@ -86,7 +87,7 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn fan_control_state(&self) -> zbus::fdo::Result<u32> {
|
async fn fan_control_state(&self) -> fdo::Result<u32> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fan_control
|
.fan_control
|
||||||
.get_state()
|
.get_state()
|
||||||
|
@ -98,7 +99,7 @@ impl SteamOSManager {
|
||||||
async fn set_fan_control_state(&self, state: u32) -> zbus::Result<()> {
|
async fn set_fan_control_state(&self, state: u32) -> zbus::Result<()> {
|
||||||
let state = match FanControlState::try_from(state) {
|
let state = match FanControlState::try_from(state) {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()),
|
Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string()).into()),
|
||||||
};
|
};
|
||||||
// Run what steamos-polkit-helpers/jupiter-fan-control does
|
// Run what steamos-polkit-helpers/jupiter-fan-control does
|
||||||
self.fan_control
|
self.fan_control
|
||||||
|
@ -108,7 +109,7 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn hardware_currently_supported(&self) -> zbus::fdo::Result<u32> {
|
async fn hardware_currently_supported(&self) -> fdo::Result<u32> {
|
||||||
match check_support().await {
|
match check_support().await {
|
||||||
Ok(res) => Ok(res as u32),
|
Ok(res) => Ok(res as u32),
|
||||||
Err(e) => Err(to_zbus_fdo_error(e)),
|
Err(e) => Err(to_zbus_fdo_error(e)),
|
||||||
|
@ -132,26 +133,26 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_als_integration_time_file_descriptor(&self) -> zbus::fdo::Result<Fd> {
|
async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result<Fd> {
|
||||||
// Get the file descriptor for the als integration time sysfs path
|
// Get the file descriptor for the als integration time sysfs path
|
||||||
let result = File::create(ALS_INTEGRATION_PATH).await;
|
let result = File::create(ALS_INTEGRATION_PATH).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(f) => Ok(Fd::Owned(std::os::fd::OwnedFd::from(f.into_std().await))),
|
Ok(f) => Ok(Fd::Owned(std::os::fd::OwnedFd::from(f.into_std().await))),
|
||||||
Err(message) => {
|
Err(message) => {
|
||||||
error!("Error opening sysfs file for giving file descriptor: {message}");
|
error!("Error opening sysfs file for giving file descriptor: {message}");
|
||||||
Err(zbus::fdo::Error::IOError(message.to_string()))
|
Err(fdo::Error::IOError(message.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_bios(&mut self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
async fn update_bios(&mut self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
// Update the bios as needed
|
// Update the bios as needed
|
||||||
self.process_manager
|
self.process_manager
|
||||||
.get_command_object_path("/usr/bin/jupiter-biosupdate", &["--auto"], "updating BIOS")
|
.get_command_object_path("/usr/bin/jupiter-biosupdate", &["--auto"], "updating BIOS")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_dock(&mut self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
async fn update_dock(&mut self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
// Update the dock firmware as needed
|
// Update the dock firmware as needed
|
||||||
self.process_manager
|
self.process_manager
|
||||||
.get_command_object_path(
|
.get_command_object_path(
|
||||||
|
@ -162,7 +163,7 @@ impl SteamOSManager {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn trim_devices(&mut self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
async fn trim_devices(&mut self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
// Run steamos-trim-devices script
|
// Run steamos-trim-devices script
|
||||||
self.process_manager
|
self.process_manager
|
||||||
.get_command_object_path(
|
.get_command_object_path(
|
||||||
|
@ -178,7 +179,7 @@ impl SteamOSManager {
|
||||||
device: &str,
|
device: &str,
|
||||||
label: &str,
|
label: &str,
|
||||||
validate: bool,
|
validate: bool,
|
||||||
) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
let mut args = vec!["--label", label, "--device", device];
|
let mut args = vec!["--label", label, "--device", device];
|
||||||
if !validate {
|
if !validate {
|
||||||
args.push("--skip-validation");
|
args.push("--skip-validation");
|
||||||
|
@ -193,7 +194,7 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn gpu_performance_level(&self) -> zbus::fdo::Result<u32> {
|
async fn gpu_performance_level(&self) -> fdo::Result<u32> {
|
||||||
match get_gpu_performance_level().await {
|
match get_gpu_performance_level().await {
|
||||||
Ok(level) => Ok(level as u32),
|
Ok(level) => Ok(level as u32),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -216,7 +217,7 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn manual_gpu_clock(&self) -> zbus::fdo::Result<u32> {
|
async fn manual_gpu_clock(&self) -> fdo::Result<u32> {
|
||||||
get_gpu_clocks()
|
get_gpu_clocks()
|
||||||
.await
|
.await
|
||||||
.inspect_err(|message| error!("Error getting manual GPU clock: {message}"))
|
.inspect_err(|message| error!("Error getting manual GPU clock: {message}"))
|
||||||
|
@ -244,7 +245,7 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn tdp_limit(&self) -> zbus::fdo::Result<u32> {
|
async fn tdp_limit(&self) -> fdo::Result<u32> {
|
||||||
get_tdp_limit().await.map_err(to_zbus_fdo_error)
|
get_tdp_limit().await.map_err(to_zbus_fdo_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,12 +277,12 @@ impl SteamOSManager {
|
||||||
mode: u32,
|
mode: u32,
|
||||||
buffer_size: u32,
|
buffer_size: u32,
|
||||||
#[zbus(signal_context)] ctx: SignalContext<'_>,
|
#[zbus(signal_context)] ctx: SignalContext<'_>,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> fdo::Result<()> {
|
||||||
// Set the wifi debug mode to mode, using an int for flexibility going forward but only
|
// Set the wifi debug mode to mode, using an int for flexibility going forward but only
|
||||||
// doing things on 0 or 1 for now
|
// doing things on 0 or 1 for now
|
||||||
let wanted_mode = match WifiDebugMode::try_from(mode) {
|
let wanted_mode = match WifiDebugMode::try_from(mode) {
|
||||||
Ok(mode) => mode,
|
Ok(mode) => mode,
|
||||||
Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())),
|
Err(e) => return Err(fdo::Error::InvalidArgs(e.to_string())),
|
||||||
};
|
};
|
||||||
match set_wifi_debug_mode(
|
match set_wifi_debug_mode(
|
||||||
wanted_mode,
|
wanted_mode,
|
||||||
|
@ -305,7 +306,7 @@ impl SteamOSManager {
|
||||||
|
|
||||||
/// WifiBackend property.
|
/// WifiBackend property.
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn wifi_backend(&self) -> zbus::fdo::Result<u32> {
|
async fn wifi_backend(&self) -> fdo::Result<u32> {
|
||||||
match get_wifi_backend().await {
|
match get_wifi_backend().await {
|
||||||
Ok(backend) => Ok(backend as u32),
|
Ok(backend) => Ok(backend as u32),
|
||||||
Err(e) => Err(to_zbus_fdo_error(e)),
|
Err(e) => Err(to_zbus_fdo_error(e)),
|
||||||
|
@ -313,15 +314,15 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_wifi_backend(&mut self, backend: u32) -> zbus::fdo::Result<()> {
|
async fn set_wifi_backend(&mut self, backend: u32) -> fdo::Result<()> {
|
||||||
if self.wifi_debug_mode == WifiDebugMode::On {
|
if self.wifi_debug_mode == WifiDebugMode::On {
|
||||||
return Err(zbus::fdo::Error::Failed(String::from(
|
return Err(fdo::Error::Failed(String::from(
|
||||||
"operation not supported when wifi_debug_mode=on",
|
"operation not supported when wifi_debug_mode=on",
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let backend = match WifiBackend::try_from(backend) {
|
let backend = match WifiBackend::try_from(backend) {
|
||||||
Ok(backend) => backend,
|
Ok(backend) => backend,
|
||||||
Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())),
|
Err(e) => return Err(fdo::Error::InvalidArgs(e.to_string())),
|
||||||
};
|
};
|
||||||
set_wifi_backend(backend)
|
set_wifi_backend(backend)
|
||||||
.await
|
.await
|
|
@ -10,10 +10,11 @@ use anyhow::Result;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use zbus::proxy::Builder;
|
use zbus::proxy::Builder;
|
||||||
use zbus::zvariant::Fd;
|
use zbus::zvariant::Fd;
|
||||||
use zbus::{interface, Connection, Proxy, SignalContext};
|
use zbus::{fdo, interface, Connection, Proxy, SignalContext};
|
||||||
|
|
||||||
use crate::cec::{HdmiCecControl, HdmiCecState};
|
use crate::cec::{HdmiCecControl, HdmiCecState};
|
||||||
use crate::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo, API_VERSION};
|
use crate::error::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo};
|
||||||
|
use crate::API_VERSION;
|
||||||
|
|
||||||
macro_rules! method {
|
macro_rules! method {
|
||||||
($self:expr, $method:expr, $($args:expr),+) => {
|
($self:expr, $method:expr, $($args:expr),+) => {
|
||||||
|
@ -50,14 +51,14 @@ macro_rules! setter {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SteamOSManagerUser {
|
pub struct SteamOSManager {
|
||||||
proxy: Proxy<'static>,
|
proxy: Proxy<'static>,
|
||||||
hdmi_cec: HdmiCecControl<'static>,
|
hdmi_cec: HdmiCecControl<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SteamOSManagerUser {
|
impl SteamOSManager {
|
||||||
pub async fn new(connection: Connection, system_conn: &Connection) -> Result<Self> {
|
pub async fn new(connection: Connection, system_conn: &Connection) -> Result<Self> {
|
||||||
Ok(SteamOSManagerUser {
|
Ok(SteamOSManager {
|
||||||
hdmi_cec: HdmiCecControl::new(&connection).await?,
|
hdmi_cec: HdmiCecControl::new(&connection).await?,
|
||||||
proxy: Builder::new(system_conn)
|
proxy: Builder::new(system_conn)
|
||||||
.destination("com.steampowered.SteamOSManager1")?
|
.destination("com.steampowered.SteamOSManager1")?
|
||||||
|
@ -71,14 +72,14 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[interface(name = "com.steampowered.SteamOSManager1.Manager")]
|
#[interface(name = "com.steampowered.SteamOSManager1.Manager")]
|
||||||
impl SteamOSManagerUser {
|
impl SteamOSManager {
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn version(&self) -> u32 {
|
async fn version(&self) -> u32 {
|
||||||
API_VERSION
|
API_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn hdmi_cec_state(&self) -> zbus::fdo::Result<u32> {
|
async fn hdmi_cec_state(&self) -> fdo::Result<u32> {
|
||||||
match self.hdmi_cec.get_enabled_state().await {
|
match self.hdmi_cec.get_enabled_state().await {
|
||||||
Ok(state) => Ok(state as u32),
|
Ok(state) => Ok(state as u32),
|
||||||
Err(e) => Err(to_zbus_fdo_error(e)),
|
Err(e) => Err(to_zbus_fdo_error(e)),
|
||||||
|
@ -89,7 +90,7 @@ impl SteamOSManagerUser {
|
||||||
async fn set_hdmi_cec_state(&self, state: u32) -> zbus::Result<()> {
|
async fn set_hdmi_cec_state(&self, state: u32) -> zbus::Result<()> {
|
||||||
let state = match HdmiCecState::try_from(state) {
|
let state = match HdmiCecState::try_from(state) {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()),
|
Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string()).into()),
|
||||||
};
|
};
|
||||||
self.hdmi_cec
|
self.hdmi_cec
|
||||||
.set_enabled_state(state)
|
.set_enabled_state(state)
|
||||||
|
@ -98,12 +99,12 @@ impl SteamOSManagerUser {
|
||||||
.map_err(to_zbus_error)
|
.map_err(to_zbus_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn prepare_factory_reset(&self) -> zbus::fdo::Result<u32> {
|
async fn prepare_factory_reset(&self) -> fdo::Result<u32> {
|
||||||
method!(self, "PrepareFactoryReset")
|
method!(self, "PrepareFactoryReset")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn wifi_power_management_state(&self) -> zbus::fdo::Result<u32> {
|
async fn wifi_power_management_state(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "WifiPowerManagementState")
|
getter!(self, "WifiPowerManagementState")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn fan_control_state(&self) -> zbus::fdo::Result<u32> {
|
async fn fan_control_state(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "FanControlState")
|
getter!(self, "FanControlState")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,16 +124,16 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn hardware_currently_supported(&self) -> zbus::fdo::Result<u32> {
|
async fn hardware_currently_supported(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "HardwareCurrentlySupported")
|
getter!(self, "HardwareCurrentlySupported")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn als_calibration_gain(&self) -> zbus::fdo::Result<f64> {
|
async fn als_calibration_gain(&self) -> fdo::Result<f64> {
|
||||||
getter!(self, "AlsCalibrationGain")
|
getter!(self, "AlsCalibrationGain")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_als_integration_time_file_descriptor(&self) -> zbus::fdo::Result<Fd> {
|
async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result<Fd> {
|
||||||
let m = self
|
let m = self
|
||||||
.proxy
|
.proxy
|
||||||
.call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &())
|
.call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &())
|
||||||
|
@ -144,15 +145,15 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_bios(&self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
async fn update_bios(&self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
method!(self, "UpdateBios")
|
method!(self, "UpdateBios")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_dock(&self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
async fn update_dock(&self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
method!(self, "UpdateDock")
|
method!(self, "UpdateDock")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn trim_devices(&self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
async fn trim_devices(&self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
method!(self, "TrimDevices")
|
method!(self, "TrimDevices")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,12 +162,12 @@ impl SteamOSManagerUser {
|
||||||
device: &str,
|
device: &str,
|
||||||
label: &str,
|
label: &str,
|
||||||
validate: bool,
|
validate: bool,
|
||||||
) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
method!(self, "FormatDevice", device, label, validate)
|
method!(self, "FormatDevice", device, label, validate)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn gpu_performance_level(&self) -> zbus::fdo::Result<u32> {
|
async fn gpu_performance_level(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "GpuPerformanceLevel")
|
getter!(self, "GpuPerformanceLevel")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn manual_gpu_clock(&self) -> zbus::fdo::Result<u32> {
|
async fn manual_gpu_clock(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "ManualGpuClock")
|
getter!(self, "ManualGpuClock")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,17 +187,17 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn manual_gpu_clock_min(&self) -> zbus::fdo::Result<u32> {
|
async fn manual_gpu_clock_min(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "ManualGpuClockMin")
|
getter!(self, "ManualGpuClockMin")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn manual_gpu_clock_max(&self) -> zbus::fdo::Result<u32> {
|
async fn manual_gpu_clock_max(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "ManualGpuClockMax")
|
getter!(self, "ManualGpuClockMax")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn tdp_limit(&self) -> zbus::fdo::Result<u32> {
|
async fn tdp_limit(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "TdpLimit")
|
getter!(self, "TdpLimit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,17 +207,17 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn tdp_limit_min(&self) -> zbus::fdo::Result<u32> {
|
async fn tdp_limit_min(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "TdpLimitMin")
|
getter!(self, "TdpLimitMin")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn tdp_limit_max(&self) -> zbus::fdo::Result<u32> {
|
async fn tdp_limit_max(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "TdpLimitMax")
|
getter!(self, "TdpLimitMax")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn wifi_debug_mode_state(&self) -> zbus::fdo::Result<u32> {
|
async fn wifi_debug_mode_state(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "WifiDebugModeState")
|
getter!(self, "WifiDebugModeState")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +226,7 @@ impl SteamOSManagerUser {
|
||||||
mode: u32,
|
mode: u32,
|
||||||
buffer_size: u32,
|
buffer_size: u32,
|
||||||
#[zbus(signal_context)] ctx: SignalContext<'_>,
|
#[zbus(signal_context)] ctx: SignalContext<'_>,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> fdo::Result<()> {
|
||||||
method!(self, "SetWifiDebugMode", mode, buffer_size)?;
|
method!(self, "SetWifiDebugMode", mode, buffer_size)?;
|
||||||
self.wifi_debug_mode_state_changed(&ctx)
|
self.wifi_debug_mode_state_changed(&ctx)
|
||||||
.await
|
.await
|
||||||
|
@ -234,7 +235,7 @@ impl SteamOSManagerUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn wifi_backend(&self) -> zbus::fdo::Result<u32> {
|
async fn wifi_backend(&self) -> fdo::Result<u32> {
|
||||||
getter!(self, "WifiBackend")
|
getter!(self, "WifiBackend")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +269,7 @@ mod test {
|
||||||
.build()
|
.build()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let manager = SteamOSManagerUser::new(connection.clone(), &connection)
|
let manager = SteamOSManager::new(connection.clone(), &connection)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
connection
|
connection
|
||||||
|
@ -306,7 +307,7 @@ mod test {
|
||||||
let manager_ref = test
|
let manager_ref = test
|
||||||
.connection
|
.connection
|
||||||
.object_server()
|
.object_server()
|
||||||
.interface::<_, SteamOSManagerUser>("/com/steampowered/SteamOSManager1")
|
.interface::<_, SteamOSManager>("/com/steampowered/SteamOSManager1")
|
||||||
.await
|
.await
|
||||||
.expect("interface");
|
.expect("interface");
|
||||||
let manager = manager_ref.get().await;
|
let manager = manager_ref.get().await;
|
|
@ -15,9 +15,9 @@ use std::os::unix::process::ExitStatusExt;
|
||||||
use std::process::ExitStatus;
|
use std::process::ExitStatus;
|
||||||
use tokio::process::{Child, Command};
|
use tokio::process::{Child, Command};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use zbus::interface;
|
use zbus::{fdo, interface};
|
||||||
|
|
||||||
use crate::to_zbus_fdo_error;
|
use crate::error::to_zbus_fdo_error;
|
||||||
|
|
||||||
const PROCESS_PREFIX: &str = "/com/steampowered/SteamOSManager1/Process";
|
const PROCESS_PREFIX: &str = "/com/steampowered/SteamOSManager1/Process";
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl ProcessManager {
|
||||||
executable: &str,
|
executable: &str,
|
||||||
args: &[impl AsRef<OsStr>],
|
args: &[impl AsRef<OsStr>],
|
||||||
operation_name: &str,
|
operation_name: &str,
|
||||||
) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
|
||||||
// Run the given executable and give back an object path
|
// Run the given executable and give back an object path
|
||||||
let path = format!("{}{}", PROCESS_PREFIX, self.next_process);
|
let path = format!("{}{}", PROCESS_PREFIX, self.next_process);
|
||||||
self.next_process += 1;
|
self.next_process += 1;
|
||||||
|
@ -128,9 +128,9 @@ impl SubProcess {
|
||||||
|
|
||||||
#[interface(name = "com.steampowered.SteamOSManager1.SubProcess")]
|
#[interface(name = "com.steampowered.SteamOSManager1.SubProcess")]
|
||||||
impl SubProcess {
|
impl SubProcess {
|
||||||
pub async fn pause(&mut self) -> zbus::fdo::Result<()> {
|
pub async fn pause(&mut self) -> fdo::Result<()> {
|
||||||
if self.paused {
|
if self.paused {
|
||||||
return Err(zbus::fdo::Error::Failed("Already paused".to_string()));
|
return Err(fdo::Error::Failed("Already paused".to_string()));
|
||||||
}
|
}
|
||||||
// Pause the given process if possible
|
// Pause the given process if possible
|
||||||
// Return true on success, false otherwise
|
// Return true on success, false otherwise
|
||||||
|
@ -139,17 +139,17 @@ impl SubProcess {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn resume(&mut self) -> zbus::fdo::Result<()> {
|
pub async fn resume(&mut self) -> fdo::Result<()> {
|
||||||
// Resume the given process if possible
|
// Resume the given process if possible
|
||||||
if !self.paused {
|
if !self.paused {
|
||||||
return Err(zbus::fdo::Error::Failed("Not paused".to_string()));
|
return Err(fdo::Error::Failed("Not paused".to_string()));
|
||||||
}
|
}
|
||||||
let result = self.send_signal(Signal::SIGCONT).map_err(to_zbus_fdo_error);
|
let result = self.send_signal(Signal::SIGCONT).map_err(to_zbus_fdo_error);
|
||||||
self.paused = false;
|
self.paused = false;
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cancel(&mut self) -> zbus::fdo::Result<()> {
|
pub async fn cancel(&mut self) -> fdo::Result<()> {
|
||||||
if self.try_wait().map_err(to_zbus_fdo_error)?.is_none() {
|
if self.try_wait().map_err(to_zbus_fdo_error)?.is_none() {
|
||||||
self.send_signal(Signal::SIGTERM)
|
self.send_signal(Signal::SIGTERM)
|
||||||
.map_err(to_zbus_fdo_error)?;
|
.map_err(to_zbus_fdo_error)?;
|
||||||
|
@ -160,14 +160,14 @@ impl SubProcess {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn kill(&mut self) -> zbus::fdo::Result<()> {
|
pub async fn kill(&mut self) -> fdo::Result<()> {
|
||||||
match self.try_wait().map_err(to_zbus_fdo_error)? {
|
match self.try_wait().map_err(to_zbus_fdo_error)? {
|
||||||
Some(_) => Ok(()),
|
Some(_) => Ok(()),
|
||||||
None => self.send_signal(signal::SIGKILL).map_err(to_zbus_fdo_error),
|
None => self.send_signal(signal::SIGKILL).map_err(to_zbus_fdo_error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn wait(&mut self) -> zbus::fdo::Result<i32> {
|
pub async fn wait(&mut self) -> fdo::Result<i32> {
|
||||||
if self.paused {
|
if self.paused {
|
||||||
self.resume().await?;
|
self.resume().await?;
|
||||||
}
|
}
|
||||||
|
@ -175,16 +175,14 @@ impl SubProcess {
|
||||||
let code = match self.exit_code_internal().await.map_err(to_zbus_fdo_error) {
|
let code = match self.exit_code_internal().await.map_err(to_zbus_fdo_error) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
return Err(zbus::fdo::Error::Failed(
|
return Err(fdo::Error::Failed("Unable to get exit code".to_string()));
|
||||||
"Unable to get exit code".to_string(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.exit_code = Some(code);
|
self.exit_code = Some(code);
|
||||||
Ok(code)
|
Ok(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn exit_code(&mut self) -> zbus::fdo::Result<i32> {
|
pub async fn exit_code(&mut self) -> fdo::Result<i32> {
|
||||||
match self.try_wait() {
|
match self.try_wait() {
|
||||||
Ok(Some(i)) => Ok(i),
|
Ok(Some(i)) => Ok(i),
|
||||||
_ => Err(zbus::fdo::Error::Failed(
|
_ => Err(zbus::fdo::Error::Failed(
|
||||||
|
@ -275,14 +273,14 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pause_process.pause().await.unwrap_err(),
|
pause_process.pause().await.unwrap_err(),
|
||||||
zbus::fdo::Error::Failed("Already paused".to_string())
|
fdo::Error::Failed("Already paused".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
pause_process.resume().await.expect("resume");
|
pause_process.resume().await.expect("resume");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pause_process.resume().await.unwrap_err(),
|
pause_process.resume().await.unwrap_err(),
|
||||||
zbus::fdo::Error::Failed("Not paused".to_string())
|
fdo::Error::Failed("Not paused".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sleep gives 0 exit code when done, -1 when we haven't waited for it yet
|
// Sleep gives 0 exit code when done, -1 when we haven't waited for it yet
|
||||||
|
|
|
@ -116,6 +116,7 @@ trait Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proxy(
|
#[proxy(
|
||||||
|
default_service = "com.steampowered.SteamOSManager1",
|
||||||
interface = "com.steampowered.SteamOSManager1.SubProcess",
|
interface = "com.steampowered.SteamOSManager1.SubProcess",
|
||||||
assume_defaults = true
|
assume_defaults = true
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -119,6 +119,7 @@ mod test {
|
||||||
use nix::unistd;
|
use nix::unistd;
|
||||||
use tokio::fs::{create_dir_all, read_to_string, write};
|
use tokio::fs::{create_dir_all, read_to_string, write};
|
||||||
use tokio::sync::mpsc::{error, unbounded_channel, UnboundedSender};
|
use tokio::sync::mpsc::{error, unbounded_channel, UnboundedSender};
|
||||||
|
use zbus::fdo;
|
||||||
|
|
||||||
struct MockTrace {
|
struct MockTrace {
|
||||||
traces: UnboundedSender<(String, HashMap<String, zvariant::OwnedValue>)>,
|
traces: UnboundedSender<(String, HashMap<String, zvariant::OwnedValue>)>,
|
||||||
|
@ -130,7 +131,7 @@ mod test {
|
||||||
&mut self,
|
&mut self,
|
||||||
trace: &str,
|
trace: &str,
|
||||||
data: HashMap<&str, zvariant::Value<'_>>,
|
data: HashMap<&str, zvariant::Value<'_>>,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> fdo::Result<()> {
|
||||||
let _ = self.traces.send((
|
let _ = self.traces.send((
|
||||||
String::from(trace),
|
String::from(trace),
|
||||||
HashMap::from_iter(
|
HashMap::from_iter(
|
||||||
|
|
12
src/wifi.rs
12
src/wifi.rs
|
@ -124,7 +124,7 @@ impl fmt::Display for WifiBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> {
|
pub(crate) async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> {
|
||||||
// Copy override.conf file into place or out of place depending
|
// Copy override.conf file into place or out of place depending
|
||||||
// on install value
|
// on install value
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ async fn start_tracing(buffer_size: u32) -> Result<()> {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_wifi_debug_mode(
|
pub(crate) async fn set_wifi_debug_mode(
|
||||||
mode: WifiDebugMode,
|
mode: WifiDebugMode,
|
||||||
buffer_size: u32,
|
buffer_size: u32,
|
||||||
should_trace: bool,
|
should_trace: bool,
|
||||||
|
@ -225,7 +225,7 @@ pub async fn set_wifi_debug_mode(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_wifi_backend() -> Result<WifiBackend> {
|
pub(crate) async fn get_wifi_backend() -> Result<WifiBackend> {
|
||||||
let wifi_backend_contents = fs::read_to_string(path(WIFI_BACKEND_PATH))
|
let wifi_backend_contents = fs::read_to_string(path(WIFI_BACKEND_PATH))
|
||||||
.await?
|
.await?
|
||||||
.trim()
|
.trim()
|
||||||
|
@ -240,11 +240,11 @@ pub async fn get_wifi_backend() -> Result<WifiBackend> {
|
||||||
bail!("WiFi backend not found in config");
|
bail!("WiFi backend not found in config");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_wifi_backend(backend: WifiBackend) -> Result<()> {
|
pub(crate) async fn set_wifi_backend(backend: WifiBackend) -> Result<()> {
|
||||||
run_script("/usr/bin/steamos-wifi-set-backend", &[backend.to_string()]).await
|
run_script("/usr/bin/steamos-wifi-set-backend", &[backend.to_string()]).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
|
pub(crate) async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
|
||||||
let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?;
|
let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?;
|
||||||
for line in output.lines() {
|
for line in output.lines() {
|
||||||
return Ok(match line.trim() {
|
return Ok(match line.trim() {
|
||||||
|
@ -256,7 +256,7 @@ pub async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
|
||||||
bail!("Failed to query power management state")
|
bail!("Failed to query power management state")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> {
|
pub(crate) async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> {
|
||||||
let state = match state {
|
let state = match state {
|
||||||
WifiPowerManagement::Disabled => "off",
|
WifiPowerManagement::Disabled => "off",
|
||||||
WifiPowerManagement::Enabled => "on",
|
WifiPowerManagement::Enabled => "on",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue