Merge branch 'work/whiting/get_pipeline_output' into 'master'

Add get_pipeline_output to get output from 3 commands.

See merge request holo/steamos-manager!1
This commit is contained in:
Jeremy Whiting 2023-10-06 18:28:49 +00:00
commit dee6376309

View file

@ -24,7 +24,7 @@
*/ */
use std::ffi::OsStr; use std::ffi::OsStr;
use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError}; use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError, Redirection};
use zbus_macros::dbus_interface; use zbus_macros::dbus_interface;
pub struct SMManager { pub struct SMManager {
} }
@ -45,6 +45,20 @@ fn run_script(name: &str, argv: &[impl AsRef<OsStr>]) -> bool {
} }
} }
fn script_output(argv: &[impl AsRef<OsStr>]) -> Result<String, PopenError> {
// Run given command and return the output given
let mut process = Popen::create(argv, PopenConfig {
stdout: Redirection::Pipe,
..Default::default()
})?;
let (output, _err) = process.communicate(None)?;
let _exit_status = process.wait()?;
match output {
Some(output_strings) => Ok(output_strings),
None => Err(PopenError::LogicError("Error getting output"))
}
}
#[dbus_interface(name = "com.steampowered.SteamOSManager1")] #[dbus_interface(name = "com.steampowered.SteamOSManager1")]
impl SMManager { impl SMManager {
const API_VERSION: u32 = 1; const API_VERSION: u32 = 1;
@ -79,6 +93,18 @@ impl SMManager {
run_script("check hardware support", &["jupiter-check-support"]) run_script("check hardware support", &["jupiter-check-support"])
} }
async fn read_als_calibration(&self) -> f32 {
// Run script to get calibration value
let result = script_output(&["/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain"]);
let mut value: f32 = -1.0;
match result {
Ok(as_string) => value = as_string.trim().parse().unwrap(),
Err(message) => println!("Unable to run als calibration script : {}", message),
}
value
}
/// A version property. /// A version property.
#[dbus_interface(property)] #[dbus_interface(property)]
async fn version(&self) -> u32 { async fn version(&self) -> u32 {