manager/user: Move trivial changes to new interfaces

This commit is contained in:
Vicki Pfau 2024-07-26 18:08:38 -07:00
parent c75ac60c9d
commit a661df64a1
4 changed files with 363 additions and 363 deletions

View file

@ -31,44 +31,6 @@
--> -->
<property name="Version" type="u" access="read"/> <property name="Version" type="u" access="read"/>
<!--
PrepareFactoryReset:
Perform factory reset of device. Runs steamos-factory-reset script for
now.
@returns: Status of reset operation.
Valid statuses: 0 = Unknown, 1 = RebootRequired
Since: 7
-->
<method name="PrepareFactoryReset">
<arg type="u" name="status" direction="out"/>
</method>
<!--
WifiPowerManagementState:
Controls the Wi-Fi chip's power management features.
Valid states: 0 = Disabled, 1 = Enabled
Since: 7
-->
<property name="WifiPowerManagementState" type="u" access="readwrite"/>
<!--
FanControlState:
Controls whether the OS or the BIOS should manage fan speed.
Valid states: 0 = BIOS, 1 = OS
Since: 7
-->
<property name="FanControlState" type="u" access="readwrite"/>
<!-- <!--
HardwareCurrentlySupported: HardwareCurrentlySupported:
@ -80,99 +42,6 @@
--> -->
<property name="HardwareCurrentlySupported" type="u" access="read"/> <property name="HardwareCurrentlySupported" type="u" access="read"/>
<!--
AlsCalibrationGain:
Provides the ALS calibration value.
Note: Will be -1.0 if ALS calibration is unavailable.
Since: 7
-->
<property name="AlsCalibrationGain" type="d" access="read"/>
<!--
GetAlsIntegrationTimeFileDescriptor:
Get the ALS integration time file descriptor.
@descriptor: A file descriptor that can be written to to set ALS
integration time. Will be null if unable to open file or other error
occurred.
Since: 7
-->
<method name="GetAlsIntegrationTimeFileDescriptor">
<arg type="h" name="descriptor" direction="out"/>
</method>
<!--
UpdateBios:
Perform a BIOS update.
@jobpath: An object path that can be used to pause/resume/cancel the
operation.
Since: 8
-->
<method name="UpdateBios">
<arg type="o" name="jobpath" direction="out"/>
</method>
<!--
UpdateDock:
Perform a Dock Firmware update.
@jobpath: An object path that can be used to pause/resume/cancel the
operation.
Since: 8
-->
<method name="UpdateDock">
<arg type="o" name="jobpath" direction="out"/>
</method>
<!--
TrimDevices:
Perform fstrim on relevant disk devices.
Calling this over fstrim is is important as some devices are not safe
to trim unless some kernel quirks are available.
@jobpath: An object path that can be used to pause/resume/cancel the
operation.
Since: 8
-->
<method name="TrimDevices">
<arg type="o" name="jobpath" direction="out"/>
</method>
<!--
FormatDevice:
Format and optionally validate a storage device to a steam compatible
filesystem.
@device: Which device to format, e.g. /dev/mmcblk0.
@label: Filesystem label to assign to the formatted device.
@validate: When set runs common checks for conterfeit flash media
before formatting, i.e. f3probe.
@jobpath: An object path that can be used to pause/resume/cancel the
operation.
Since: 8
-->
<method name="FormatDevice">
<arg type="s" name="device" direction="in"/>
<arg type="s" name="label" direction="in"/>
<arg type="b" name="validate" direction="in"/>
<arg type="o" name="jobpath" direction="out"/>
</method>
<!-- <!--
GpuPerformanceLevel: GpuPerformanceLevel:
@ -280,18 +149,6 @@
--> -->
<property name="WifiBackend" type="u" access="readwrite"/> <property name="WifiBackend" type="u" access="readwrite"/>
<!--
HdmiCecState:
The current state of HDMI-CEC features on the system.
Valid states: 0 = Disabled, 1 = Control Only, 2 = Control And Wake
Since: 8
-->
<property name="HdmiCecState" type="u" access="readwrite"/>
<!-- <!--
GpuPowerProfiles: GpuPowerProfiles:
@ -322,25 +179,6 @@
--> -->
<method name="ReloadConfig"/> <method name="ReloadConfig"/>
<!--
CpuGovernors:
Enumerate the supported CPU governors on the system.
Since: 9
-->
<property name="AvailableCpuScalingGovernors" type="as" access="read"/>
<!--
CpuGovernor:
The current governor used for the system's CPUs. Valid values come from
thethe CpuGovernors property.
Since: 9
-->
<property name="CpuScalingGovernor" type="s" access="readwrite"/>
</interface> </interface>
</node> </node>

View file

@ -12,7 +12,11 @@ use std::ops::Deref;
use steamos_manager::cec::HdmiCecState; use steamos_manager::cec::HdmiCecState;
use steamos_manager::hardware::FanControlState; use steamos_manager::hardware::FanControlState;
use steamos_manager::power::{CPUScalingGovernor, GPUPerformanceLevel, GPUPowerProfile}; use steamos_manager::power::{CPUScalingGovernor, GPUPerformanceLevel, GPUPowerProfile};
use steamos_manager::proxy::ManagerProxy; use steamos_manager::proxy::{
AmbientLightSensor1Proxy, CpuScaling1Proxy, FactoryReset1Proxy, FanControl1Proxy,
HdmiCec1Proxy, ManagerProxy, Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy,
WifiPowerManagement1Proxy,
};
use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement}; use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement};
use zbus::fdo::PropertiesProxy; use zbus::fdo::PropertiesProxy;
use zbus::names::InterfaceName; use zbus::names::InterfaceName;
@ -194,6 +198,7 @@ async fn main() -> Result<()> {
} }
} }
Commands::GetAlsCalibrationGain => { Commands::GetAlsCalibrationGain => {
let proxy = AmbientLightSensor1Proxy::new(&conn).await?;
let gain = proxy.als_calibration_gain().await?; let gain = proxy.als_calibration_gain().await?;
println!("ALS calibration gain: {gain}"); println!("ALS calibration gain: {gain}");
} }
@ -206,9 +211,11 @@ async fn main() -> Result<()> {
println!("Version: {version}"); println!("Version: {version}");
} }
Commands::SetFanControlState { state } => { Commands::SetFanControlState { state } => {
let proxy = FanControl1Proxy::new(&conn).await?;
proxy.set_fan_control_state(*state as u32).await?; proxy.set_fan_control_state(*state as u32).await?;
} }
Commands::GetFanControlState => { Commands::GetFanControlState => {
let proxy = FanControl1Proxy::new(&conn).await?;
let state = proxy.fan_control_state().await?; let state = proxy.fan_control_state().await?;
match FanControlState::try_from(state) { match FanControlState::try_from(state) {
Ok(s) => println!("Fan control state: {}", s), Ok(s) => println!("Fan control state: {}", s),
@ -216,6 +223,7 @@ async fn main() -> Result<()> {
} }
} }
Commands::GetAvailableCpuScalingGovernors => { Commands::GetAvailableCpuScalingGovernors => {
let proxy = CpuScaling1Proxy::new(&conn).await?;
let governors = proxy.available_cpu_scaling_governors().await?; let governors = proxy.available_cpu_scaling_governors().await?;
println!("Governors:\n"); println!("Governors:\n");
for name in governors { for name in governors {
@ -223,6 +231,7 @@ async fn main() -> Result<()> {
} }
} }
Commands::GetCpuScalingGovernor => { Commands::GetCpuScalingGovernor => {
let proxy = CpuScaling1Proxy::new(&conn).await?;
let governor = proxy.cpu_scaling_governor().await?; let governor = proxy.cpu_scaling_governor().await?;
let governor_type = CPUScalingGovernor::try_from(governor.as_str()); let governor_type = CPUScalingGovernor::try_from(governor.as_str());
match governor_type { match governor_type {
@ -235,6 +244,7 @@ async fn main() -> Result<()> {
} }
} }
Commands::SetCpuScalingGovernor { governor } => { Commands::SetCpuScalingGovernor { governor } => {
let proxy = CpuScaling1Proxy::new(&conn).await?;
proxy proxy
.set_cpu_scaling_governor(governor.to_string().as_str()) .set_cpu_scaling_governor(governor.to_string().as_str())
.await?; .await?;
@ -324,9 +334,11 @@ async fn main() -> Result<()> {
} }
} }
Commands::SetWifiPowerManagementState { state } => { Commands::SetWifiPowerManagementState { state } => {
let proxy = WifiPowerManagement1Proxy::new(&conn).await?;
proxy.set_wifi_power_management_state(*state as u32).await?; proxy.set_wifi_power_management_state(*state as u32).await?;
} }
Commands::GetWifiPowerManagementState => { Commands::GetWifiPowerManagementState => {
let proxy = WifiPowerManagement1Proxy::new(&conn).await?;
let state = proxy.wifi_power_management_state().await?; let state = proxy.wifi_power_management_state().await?;
match WifiPowerManagement::try_from(state) { match WifiPowerManagement::try_from(state) {
Ok(s) => println!("Wifi power management state: {}", s), Ok(s) => println!("Wifi power management state: {}", s),
@ -334,9 +346,11 @@ async fn main() -> Result<()> {
} }
} }
Commands::SetHdmiCecState { state } => { Commands::SetHdmiCecState { state } => {
let proxy = HdmiCec1Proxy::new(&conn).await?;
proxy.set_hdmi_cec_state(*state as u32).await?; proxy.set_hdmi_cec_state(*state as u32).await?;
} }
Commands::GetHdmiCecState => { Commands::GetHdmiCecState => {
let proxy = HdmiCec1Proxy::new(&conn).await?;
let state = proxy.hdmi_cec_state().await?; let state = proxy.hdmi_cec_state().await?;
match HdmiCecState::try_from(state) { match HdmiCecState::try_from(state) {
Ok(s) => println!("HDMI-CEC state: {}", s.to_human_readable()), Ok(s) => println!("HDMI-CEC state: {}", s.to_human_readable()),
@ -344,15 +358,19 @@ async fn main() -> Result<()> {
} }
} }
Commands::UpdateBios => { Commands::UpdateBios => {
let proxy = UpdateBios1Proxy::new(&conn).await?;
let _ = proxy.update_bios().await?; let _ = proxy.update_bios().await?;
} }
Commands::UpdateDock => { Commands::UpdateDock => {
let proxy = UpdateDock1Proxy::new(&conn).await?;
let _ = proxy.update_dock().await?; let _ = proxy.update_dock().await?;
} }
Commands::FactoryReset => { Commands::FactoryReset => {
let proxy = FactoryReset1Proxy::new(&conn).await?;
let _ = proxy.prepare_factory_reset().await?; let _ = proxy.prepare_factory_reset().await?;
} }
Commands::TrimDevices => { Commands::TrimDevices => {
let proxy = Storage1Proxy::new(&conn).await?;
let _ = proxy.trim_devices().await?; let _ = proxy.trim_devices().await?;
} }
} }

View file

@ -29,6 +29,8 @@ use crate::power::{
use crate::wifi::{get_wifi_backend, get_wifi_power_management_state}; use crate::wifi::{get_wifi_backend, get_wifi_power_management_state};
use crate::API_VERSION; use crate::API_VERSION;
const MANAGER_PATH: &str = "/com/steampowered/SteamOSManager1";
macro_rules! method { macro_rules! method {
($self:expr, $method:expr, $($args:expr),+) => { ($self:expr, $method:expr, $($args:expr),+) => {
$self.proxy $self.proxy
@ -91,33 +93,57 @@ macro_rules! setter {
struct SteamOSManager { struct SteamOSManager {
proxy: Proxy<'static>, proxy: Proxy<'static>,
hdmi_cec: HdmiCecControl<'static>,
channel: Sender<Command>, channel: Sender<Command>,
}
struct AmbientLightSensor1 {
proxy: Proxy<'static>,
}
struct CpuScaling1 {
proxy: Proxy<'static>,
}
struct FactoryReset1 {
proxy: Proxy<'static>,
}
struct FanControl1 {
proxy: Proxy<'static>,
}
struct HdmiCec1 {
hdmi_cec: HdmiCecControl<'static>,
}
struct Storage1 {
proxy: Proxy<'static>,
job_manager: UnboundedSender<JobManagerCommand>, job_manager: UnboundedSender<JobManagerCommand>,
} }
struct UpdateBios1 {
proxy: Proxy<'static>,
job_manager: UnboundedSender<JobManagerCommand>,
}
struct UpdateDock1 {
proxy: Proxy<'static>,
job_manager: UnboundedSender<JobManagerCommand>,
}
struct WifiPowerManagement1 {
proxy: Proxy<'static>,
}
impl SteamOSManager { impl SteamOSManager {
pub async fn new( pub async fn new(
connection: Connection,
system_conn: Connection, system_conn: Connection,
proxy: Proxy<'static>,
channel: Sender<Command>, channel: Sender<Command>,
job_manager: UnboundedSender<JobManagerCommand>, job_manager: UnboundedSender<JobManagerCommand>,
) -> Result<Self> { ) -> Result<Self> {
let hdmi_cec = HdmiCecControl::new(&connection).await?;
let proxy = Builder::new(&system_conn)
.destination("com.steampowered.SteamOSManager1")?
.path("/com/steampowered/SteamOSManager1")?
.interface("com.steampowered.SteamOSManager1.RootManager")?
.cache_properties(CacheProperties::No)
.build()
.await?;
job_manager.send(JobManagerCommand::MirrorConnection(system_conn))?; job_manager.send(JobManagerCommand::MirrorConnection(system_conn))?;
Ok(SteamOSManager { Ok(SteamOSManager { proxy, channel })
hdmi_cec,
proxy,
job_manager,
channel,
})
} }
} }
@ -128,57 +154,6 @@ impl SteamOSManager {
API_VERSION API_VERSION
} }
#[zbus(property(emits_changed_signal = "false"))]
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)),
}
}
#[zbus(property)]
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(fdo::Error::InvalidArgs(err.to_string()).into()),
};
self.hdmi_cec
.set_enabled_state(state)
.await
.inspect_err(|message| error!("Error setting CEC state: {message}"))
.map_err(to_zbus_error)
}
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) -> fdo::Result<u32> {
match get_wifi_power_management_state().await {
Ok(state) => Ok(state as u32),
Err(e) => Err(to_zbus_fdo_error(e)),
}
}
#[zbus(property)]
async fn set_wifi_power_management_state(&self, state: u32) -> zbus::Result<()> {
self.proxy
.call("SetWifiPowerManagementState", &(state))
.await
.map_err(to_zbus_error)
}
#[zbus(property(emits_changed_signal = "false"))]
async fn fan_control_state(&self) -> fdo::Result<u32> {
getter!(self, "FanControlState")
}
#[zbus(property)]
async fn set_fan_control_state(&self, state: u32) -> zbus::Result<()> {
setter!(self, "FanControlState", state)
}
#[zbus(property(emits_changed_signal = "const"))] #[zbus(property(emits_changed_signal = "const"))]
async fn hardware_currently_supported(&self) -> fdo::Result<u32> { async fn hardware_currently_supported(&self) -> fdo::Result<u32> {
match check_support().await { match check_support().await {
@ -187,72 +162,6 @@ impl SteamOSManager {
} }
} }
#[zbus(property(emits_changed_signal = "false"))]
async fn als_calibration_gain(&self) -> fdo::Result<f64> {
getter!(self, "AlsCalibrationGain")
}
async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result<Fd> {
let m = self
.proxy
.call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &())
.await
.map_err(zbus_to_zbus_fdo)?;
match m.body().deserialize::<Fd>() {
Ok(fd) => fd.try_to_owned().map_err(to_zbus_fdo_error),
Err(e) => Err(zbus_to_zbus_fdo(e)),
}
}
async fn update_bios(&mut self) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "UpdateBios")
}
async fn update_dock(&mut self) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "UpdateDock")
}
async fn trim_devices(&mut self) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "TrimDevices")
}
async fn format_device(
&mut self,
device: &str,
label: &str,
validate: bool,
) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "FormatDevice", device, label, validate)
}
#[zbus(property(emits_changed_signal = "false"))]
async fn available_cpu_scaling_governors(&self) -> fdo::Result<Vec<String>> {
let governors = get_available_cpu_scaling_governors()
.await
.map_err(to_zbus_fdo_error)?;
let mut result = Vec::new();
for g in governors {
result.push(g.to_string());
}
Ok(result)
}
#[zbus(property(emits_changed_signal = "false"))]
async fn cpu_scaling_governor(&self) -> fdo::Result<String> {
let governor = get_cpu_scaling_governor()
.await
.map_err(to_zbus_fdo_error)?;
Ok(governor.to_string())
}
#[zbus(property)]
async fn set_cpu_scaling_governor(&self, governor: String) -> zbus::Result<()> {
self.proxy
.call("SetCpuScalingGovernor", &(governor))
.await
.map_err(to_zbus_error)
}
#[zbus(property(emits_changed_signal = "false"))] #[zbus(property(emits_changed_signal = "false"))]
async fn gpu_power_profiles(&self) -> fdo::Result<HashMap<u32, String>> { async fn gpu_power_profiles(&self) -> fdo::Result<HashMap<u32, String>> {
get_gpu_power_profiles().await.map_err(to_zbus_fdo_error) get_gpu_power_profiles().await.map_err(to_zbus_fdo_error)
@ -388,16 +297,215 @@ impl SteamOSManager {
} }
} }
#[interface(name = "com.steampowered.SteamOSManager1.AmbientLightSensor1")]
impl AmbientLightSensor1 {
#[zbus(property(emits_changed_signal = "false"))]
async fn als_calibration_gain(&self) -> fdo::Result<f64> {
getter!(self, "AlsCalibrationGain")
}
async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result<Fd> {
let m = self
.proxy
.call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &())
.await
.map_err(zbus_to_zbus_fdo)?;
match m.body().deserialize::<Fd>() {
Ok(fd) => fd.try_to_owned().map_err(to_zbus_fdo_error),
Err(e) => Err(zbus_to_zbus_fdo(e)),
}
}
}
#[interface(name = "com.steampowered.SteamOSManager1.CpuScaling1")]
impl CpuScaling1 {
#[zbus(property(emits_changed_signal = "false"))]
async fn available_cpu_scaling_governors(&self) -> fdo::Result<Vec<String>> {
let governors = get_available_cpu_scaling_governors()
.await
.map_err(to_zbus_fdo_error)?;
let mut result = Vec::new();
for g in governors {
result.push(g.to_string());
}
Ok(result)
}
#[zbus(property(emits_changed_signal = "false"))]
async fn cpu_scaling_governor(&self) -> fdo::Result<String> {
let governor = get_cpu_scaling_governor()
.await
.map_err(to_zbus_fdo_error)?;
Ok(governor.to_string())
}
#[zbus(property)]
async fn set_cpu_scaling_governor(&self, governor: String) -> zbus::Result<()> {
self.proxy
.call("SetCpuScalingGovernor", &(governor))
.await
.map_err(to_zbus_error)
}
}
#[interface(name = "com.steampowered.SteamOSManager1.FactoryReset1")]
impl FactoryReset1 {
async fn prepare_factory_reset(&self) -> fdo::Result<u32> {
method!(self, "PrepareFactoryReset")
}
}
#[interface(name = "com.steampowered.SteamOSManager1.FanControl1")]
impl FanControl1 {
#[zbus(property(emits_changed_signal = "false"))]
async fn fan_control_state(&self) -> fdo::Result<u32> {
getter!(self, "FanControlState")
}
#[zbus(property)]
async fn set_fan_control_state(&self, state: u32) -> zbus::Result<()> {
setter!(self, "FanControlState", state)
}
}
impl HdmiCec1 {
async fn new(connection: &Connection) -> Result<HdmiCec1> {
let hdmi_cec = HdmiCecControl::new(connection).await?;
Ok(HdmiCec1 { hdmi_cec })
}
}
#[interface(name = "com.steampowered.SteamOSManager1.HdmiCec1")]
impl HdmiCec1 {
#[zbus(property(emits_changed_signal = "false"))]
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)),
}
}
#[zbus(property)]
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(fdo::Error::InvalidArgs(err.to_string()).into()),
};
self.hdmi_cec
.set_enabled_state(state)
.await
.inspect_err(|message| error!("Error setting CEC state: {message}"))
.map_err(to_zbus_error)
}
}
#[interface(name = "com.steampowered.SteamOSManager1.Storage1")]
impl Storage1 {
async fn format_device(
&mut self,
device: &str,
label: &str,
validate: bool,
) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "FormatDevice", device, label, validate)
}
async fn trim_devices(&mut self) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "TrimDevices")
}
}
#[interface(name = "com.steampowered.SteamOSManager1.UpdateBios1")]
impl UpdateBios1 {
async fn update_bios(&mut self) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "UpdateBios")
}
}
#[interface(name = "com.steampowered.SteamOSManager1.UpdateDock1")]
impl UpdateDock1 {
async fn update_dock(&mut self) -> fdo::Result<zvariant::OwnedObjectPath> {
job_method!(self, "UpdateDock")
}
}
#[interface(name = "com.steampowered.SteamOSManager1.WifiPowerManagement1")]
impl WifiPowerManagement1 {
#[zbus(property(emits_changed_signal = "false"))]
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)),
}
}
#[zbus(property)]
async fn set_wifi_power_management_state(&self, state: u32) -> zbus::Result<()> {
self.proxy
.call("SetWifiPowerManagementState", &(state))
.await
.map_err(to_zbus_error)
}
}
pub(crate) async fn create_interfaces( pub(crate) async fn create_interfaces(
session: Connection, session: Connection,
system: Connection, system: Connection,
daemon: Sender<Command>, daemon: Sender<Command>,
job_manager: UnboundedSender<JobManagerCommand>, job_manager: UnboundedSender<JobManagerCommand>,
) -> Result<()> { ) -> Result<()> {
let manager = SteamOSManager::new(session.clone(), system.clone(), daemon, job_manager).await?; let proxy = Builder::<Proxy>::new(&system)
session .destination("com.steampowered.SteamOSManager1")?
.object_server() .path("/com/steampowered/SteamOSManager1")?
.at("/com/steampowered/SteamOSManager1", manager) .interface("com.steampowered.SteamOSManager1.RootManager")?
.cache_properties(CacheProperties::No)
.build()
.await?;
let manager =
SteamOSManager::new(system.clone(), proxy.clone(), daemon, job_manager.clone()).await?;
let als = AmbientLightSensor1 {
proxy: proxy.clone(),
};
let cpu_scaling = CpuScaling1 {
proxy: proxy.clone(),
};
let factory_reset = FactoryReset1 {
proxy: proxy.clone(),
};
let fan_control = FanControl1 {
proxy: proxy.clone(),
};
let hdmi_cec = HdmiCec1::new(&session).await?;
let storage = Storage1 {
proxy: proxy.clone(),
job_manager: job_manager.clone(),
};
let update_bios = UpdateBios1 {
proxy: proxy.clone(),
job_manager: job_manager.clone(),
};
let update_dock = UpdateDock1 {
proxy: proxy.clone(),
job_manager: job_manager.clone(),
};
let wifi_power_management = WifiPowerManagement1 {
proxy: proxy.clone(),
};
let object_server = session.object_server();
object_server.at(MANAGER_PATH, manager).await?;
object_server.at(MANAGER_PATH, als).await?;
object_server.at(MANAGER_PATH, cpu_scaling).await?;
object_server.at(MANAGER_PATH, factory_reset).await?;
object_server.at(MANAGER_PATH, fan_control).await?;
object_server.at(MANAGER_PATH, hdmi_cec).await?;
object_server.at(MANAGER_PATH, storage).await?;
object_server.at(MANAGER_PATH, update_bios).await?;
object_server.at(MANAGER_PATH, update_dock).await?;
object_server
.at(MANAGER_PATH, wifi_power_management)
.await?; .await?;
Ok(()) Ok(())
@ -413,7 +521,7 @@ mod test {
use std::time::Duration; use std::time::Duration;
use tokio::sync::mpsc::unbounded_channel; use tokio::sync::mpsc::unbounded_channel;
use tokio::time::sleep; use tokio::time::sleep;
use zbus::Connection; use zbus::{Connection, Interface};
struct TestHandle { struct TestHandle {
_handle: testing::TestHandle, _handle: testing::TestHandle,
@ -425,12 +533,7 @@ mod test {
let (tx_ctx, _rx_ctx) = channel::<UserContext>(); let (tx_ctx, _rx_ctx) = channel::<UserContext>();
let (tx_job, _rx_job) = unbounded_channel::<JobManagerCommand>(); let (tx_job, _rx_job) = unbounded_channel::<JobManagerCommand>();
let connection = handle.new_dbus().await?; let connection = handle.new_dbus().await?;
let manager = create_interfaces(connection.clone(), connection.clone(), tx_ctx, tx_job).await?;
SteamOSManager::new(connection.clone(), connection.clone(), tx_ctx, tx_job).await?;
connection
.object_server()
.at("/com/steampowered/SteamOSManager1", manager)
.await?;
sleep(Duration::from_millis(1)).await; sleep(Duration::from_millis(1)).await;
@ -446,7 +549,7 @@ mod test {
let remote = testing::InterfaceIntrospection::from_remote::<SteamOSManager, _>( let remote = testing::InterfaceIntrospection::from_remote::<SteamOSManager, _>(
&test.connection, &test.connection,
"/com/steampowered/SteamOSManager1", MANAGER_PATH,
) )
.await .await
.expect("remote"); .expect("remote");
@ -458,4 +561,100 @@ mod test {
.expect("local"); .expect("local");
assert!(remote.compare(&local)); assert!(remote.compare(&local));
} }
async fn test_interface_matches<I: Interface>(connection: &Connection) -> Result<bool> {
let remote =
testing::InterfaceIntrospection::from_remote::<I, _>(connection, MANAGER_PATH).await?;
let local = testing::InterfaceIntrospection::from_local(
"com.steampowered.SteamOSManager1.xml",
I::name().to_string(),
)
.await?;
Ok(remote.compare(&local))
}
#[tokio::test]
async fn interface_matches_ambient_light_sensor1() {
let test = start().await.expect("start");
assert!(
test_interface_matches::<AmbientLightSensor1>(&test.connection)
.await
.unwrap()
);
}
#[tokio::test]
async fn interface_matches_cpu_scaling1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<CpuScaling1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_factory_reset1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<FactoryReset1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_fan_control1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<FanControl1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_hdmi_cec1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<HdmiCec1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_storage1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<Storage1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_update_bios1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<UpdateBios1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_update_dock1() {
let test = start().await.expect("start");
assert!(test_interface_matches::<UpdateDock1>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_wifi_power_management1() {
let test = start().await.expect("start");
assert!(
test_interface_matches::<WifiPowerManagement1>(&test.connection)
.await
.unwrap()
);
}
} }

View file

@ -19,55 +19,12 @@ use zbus::proxy;
assume_defaults = true assume_defaults = true
)] )]
trait 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>;
/// ReloadConfig method /// ReloadConfig method
fn reload_config(&self) -> zbus::Result<()>; fn reload_config(&self) -> zbus::Result<()>;
/// SetWifiDebugMode method /// SetWifiDebugMode method
fn set_wifi_debug_mode(&self, mode: u32, buffer_size: u32) -> zbus::Result<()>; 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>;
/// AvailableCpuScalingGovernors property
#[zbus(property)]
fn available_cpu_scaling_governors(&self) -> zbus::Result<Vec<String>>;
/// CpuScalingGovernor property
#[zbus(property)]
fn cpu_scaling_governor(&self) -> zbus::Result<String>;
#[zbus(property)]
fn set_cpu_scaling_governor(&self, value: &str) -> zbus::Result<()>;
/// 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 /// GpuPerformanceLevel property
#[zbus(property)] #[zbus(property)]
fn gpu_performance_level(&self) -> zbus::Result<u32>; fn gpu_performance_level(&self) -> zbus::Result<u32>;
@ -88,12 +45,6 @@ trait Manager {
#[zbus(property)] #[zbus(property)]
fn hardware_currently_supported(&self) -> zbus::Result<u32>; fn hardware_currently_supported(&self) -> zbus::Result<u32>;
/// HdmiCecState property
#[zbus(property)]
fn hdmi_cec_state(&self) -> zbus::Result<u32>;
#[zbus(property)]
fn set_hdmi_cec_state(&self, value: u32) -> zbus::Result<()>;
/// ManualGpuClock property /// ManualGpuClock property
#[zbus(property)] #[zbus(property)]
fn manual_gpu_clock(&self) -> zbus::Result<u32>; fn manual_gpu_clock(&self) -> zbus::Result<u32>;
@ -135,10 +86,4 @@ trait Manager {
/// WifiDebugModeState property /// WifiDebugModeState property
#[zbus(property)] #[zbus(property)]
fn wifi_debug_mode_state(&self) -> zbus::Result<u32>; 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<()>;
} }