Clean up zbus::fdo into fdo where possible

This commit is contained in:
Vicki Pfau 2024-05-08 14:57:14 -07:00
parent fd500229d6
commit 58223d988b
4 changed files with 59 additions and 60 deletions

View file

@ -10,7 +10,7 @@ use anyhow::Result;
use tokio::fs::File;
use tracing::error;
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};
@ -68,7 +68,7 @@ impl SteamOSManager {
}
#[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 {
Ok(state) => Ok(state as u32),
Err(e) => Err(to_zbus_fdo_error(e)),
@ -79,7 +79,7 @@ impl SteamOSManager {
async fn set_wifi_power_management_state(&self, state: u32) -> zbus::Result<()> {
let state = match WifiPowerManagement::try_from(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)
.await
@ -87,7 +87,7 @@ impl SteamOSManager {
}
#[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
.fan_control
.get_state()
@ -99,7 +99,7 @@ impl SteamOSManager {
async fn set_fan_control_state(&self, state: u32) -> zbus::Result<()> {
let state = match FanControlState::try_from(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
self.fan_control
@ -109,7 +109,7 @@ impl SteamOSManager {
}
#[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 {
Ok(res) => Ok(res as u32),
Err(e) => Err(to_zbus_fdo_error(e)),
@ -133,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
let result = File::create(ALS_INTEGRATION_PATH).await;
match result {
Ok(f) => Ok(Fd::Owned(std::os::fd::OwnedFd::from(f.into_std().await))),
Err(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
self.process_manager
.get_command_object_path("/usr/bin/jupiter-biosupdate", &["--auto"], "updating BIOS")
.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
self.process_manager
.get_command_object_path(
@ -163,7 +163,7 @@ impl SteamOSManager {
.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
self.process_manager
.get_command_object_path(
@ -179,7 +179,7 @@ impl SteamOSManager {
device: &str,
label: &str,
validate: bool,
) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
let mut args = vec!["--label", label, "--device", device];
if !validate {
args.push("--skip-validation");
@ -194,7 +194,7 @@ impl SteamOSManager {
}
#[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 {
Ok(level) => Ok(level as u32),
Err(e) => {
@ -217,7 +217,7 @@ impl SteamOSManager {
}
#[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()
.await
.inspect_err(|message| error!("Error getting manual GPU clock: {message}"))
@ -245,7 +245,7 @@ impl SteamOSManager {
}
#[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)
}
@ -277,12 +277,12 @@ impl SteamOSManager {
mode: u32,
buffer_size: u32,
#[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
// doing things on 0 or 1 for now
let wanted_mode = match WifiDebugMode::try_from(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(
wanted_mode,
@ -306,7 +306,7 @@ impl SteamOSManager {
/// WifiBackend property.
#[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 {
Ok(backend) => Ok(backend as u32),
Err(e) => Err(to_zbus_fdo_error(e)),
@ -314,15 +314,15 @@ impl SteamOSManager {
}
#[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 {
return Err(zbus::fdo::Error::Failed(String::from(
return Err(fdo::Error::Failed(String::from(
"operation not supported when wifi_debug_mode=on",
)));
}
let backend = match WifiBackend::try_from(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)
.await

View file

@ -15,7 +15,7 @@ use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus;
use tokio::process::{Child, Command};
use tracing::error;
use zbus::interface;
use zbus::{fdo, interface};
use crate::error::to_zbus_fdo_error;
@ -48,7 +48,7 @@ impl ProcessManager {
executable: &str,
args: &[impl AsRef<OsStr>],
operation_name: &str,
) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
// Run the given executable and give back an object path
let path = format!("{}{}", PROCESS_PREFIX, self.next_process);
self.next_process += 1;
@ -128,9 +128,9 @@ impl SubProcess {
#[interface(name = "com.steampowered.SteamOSManager1.SubProcess")]
impl SubProcess {
pub async fn pause(&mut self) -> zbus::fdo::Result<()> {
pub async fn pause(&mut self) -> fdo::Result<()> {
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
// Return true on success, false otherwise
@ -139,17 +139,17 @@ impl SubProcess {
result
}
pub async fn resume(&mut self) -> zbus::fdo::Result<()> {
pub async fn resume(&mut self) -> fdo::Result<()> {
// Resume the given process if possible
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);
self.paused = false;
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() {
self.send_signal(Signal::SIGTERM)
.map_err(to_zbus_fdo_error)?;
@ -160,14 +160,14 @@ impl SubProcess {
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)? {
Some(_) => Ok(()),
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 {
self.resume().await?;
}
@ -175,16 +175,14 @@ impl SubProcess {
let code = match self.exit_code_internal().await.map_err(to_zbus_fdo_error) {
Ok(v) => v,
Err(_) => {
return Err(zbus::fdo::Error::Failed(
"Unable to get exit code".to_string(),
));
return Err(fdo::Error::Failed("Unable to get exit code".to_string()));
}
};
self.exit_code = Some(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() {
Ok(Some(i)) => Ok(i),
_ => Err(zbus::fdo::Error::Failed(
@ -275,14 +273,14 @@ mod test {
assert_eq!(
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");
assert_eq!(
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

View file

@ -119,6 +119,7 @@ mod test {
use nix::unistd;
use tokio::fs::{create_dir_all, read_to_string, write};
use tokio::sync::mpsc::{error, unbounded_channel, UnboundedSender};
use zbus::fdo;
struct MockTrace {
traces: UnboundedSender<(String, HashMap<String, zvariant::OwnedValue>)>,
@ -130,7 +131,7 @@ mod test {
&mut self,
trace: &str,
data: HashMap<&str, zvariant::Value<'_>>,
) -> zbus::fdo::Result<()> {
) -> fdo::Result<()> {
let _ = self.traces.send((
String::from(trace),
HashMap::from_iter(

View file

@ -10,7 +10,7 @@ use anyhow::Result;
use tracing::error;
use zbus::proxy::Builder;
use zbus::zvariant::Fd;
use zbus::{interface, Connection, Proxy, SignalContext};
use zbus::{fdo, interface, Connection, Proxy, SignalContext};
use crate::cec::{HdmiCecControl, HdmiCecState};
use crate::error::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo};
@ -79,7 +79,7 @@ impl SteamOSManagerUser {
}
#[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 {
Ok(state) => Ok(state as u32),
Err(e) => Err(to_zbus_fdo_error(e)),
@ -90,7 +90,7 @@ impl SteamOSManagerUser {
async fn set_hdmi_cec_state(&self, state: u32) -> zbus::Result<()> {
let state = match HdmiCecState::try_from(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
.set_enabled_state(state)
@ -99,12 +99,12 @@ impl SteamOSManagerUser {
.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")
}
#[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")
}
@ -114,7 +114,7 @@ impl SteamOSManagerUser {
}
#[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")
}
@ -124,16 +124,16 @@ impl SteamOSManagerUser {
}
#[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")
}
#[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")
}
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
.proxy
.call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &())
@ -145,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")
}
async fn update_dock(&self) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
async fn update_dock(&self) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
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")
}
@ -162,12 +162,12 @@ impl SteamOSManagerUser {
device: &str,
label: &str,
validate: bool,
) -> zbus::fdo::Result<zbus::zvariant::OwnedObjectPath> {
) -> fdo::Result<zbus::zvariant::OwnedObjectPath> {
method!(self, "FormatDevice", device, label, validate)
}
#[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")
}
@ -177,7 +177,7 @@ impl SteamOSManagerUser {
}
#[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")
}
@ -187,17 +187,17 @@ impl SteamOSManagerUser {
}
#[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")
}
#[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")
}
#[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")
}
@ -207,17 +207,17 @@ impl SteamOSManagerUser {
}
#[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")
}
#[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")
}
#[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")
}
@ -226,7 +226,7 @@ impl SteamOSManagerUser {
mode: u32,
buffer_size: u32,
#[zbus(signal_context)] ctx: SignalContext<'_>,
) -> zbus::fdo::Result<()> {
) -> fdo::Result<()> {
method!(self, "SetWifiDebugMode", mode, buffer_size)?;
self.wifi_debug_mode_state_changed(&ctx)
.await
@ -235,7 +235,7 @@ impl SteamOSManagerUser {
}
#[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")
}