manager/user: Move relevant methods to Manager2, update as specified

This commit is contained in:
Vicki Pfau 2024-07-29 20:23:26 -07:00
parent a661df64a1
commit 41382c7158
5 changed files with 62 additions and 62 deletions

View file

@ -31,17 +31,6 @@
-->
<property name="Version" type="u" access="read"/>
<!--
HardwareCurrentlySupported:
Reports whether the current hardware is supported or not.
Valid states: 0 = Unsupported, 1 = Supported
Since: 7
-->
<property name="HardwareCurrentlySupported" type="u" access="read"/>
<!--
GpuPerformanceLevel:
@ -170,15 +159,6 @@
-->
<property name="GpuPowerProfile" type="u" access="readwrite"/>
<!--
ReloadConfig:
Reloads the configuration from disk.
Since: 9
-->
<method name="ReloadConfig"/>
</interface>
</node>

View file

@ -14,7 +14,7 @@ use steamos_manager::hardware::FanControlState;
use steamos_manager::power::{CPUScalingGovernor, GPUPerformanceLevel, GPUPowerProfile};
use steamos_manager::proxy::{
AmbientLightSensor1Proxy, CpuScaling1Proxy, FactoryReset1Proxy, FanControl1Proxy,
HdmiCec1Proxy, ManagerProxy, Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy,
HdmiCec1Proxy, Manager2Proxy, ManagerProxy, Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy,
WifiPowerManagement1Proxy,
};
use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement};
@ -203,6 +203,7 @@ async fn main() -> Result<()> {
println!("ALS calibration gain: {gain}");
}
Commands::GetHardwareCurrentlySupported => {
let proxy = Manager2Proxy::new(&conn).await?;
let supported = proxy.hardware_currently_supported().await?;
println!("Hardware currently supported: {supported}");
}

View file

@ -28,8 +28,9 @@ pub(crate) enum HardwareVariant {
#[derive(PartialEq, Debug, Copy, Clone)]
#[repr(u32)]
pub(crate) enum HardwareCurrentlySupported {
Unsupported = 0,
Supported = 1,
Unknown = 0,
UnsupportedPrototype = 1,
Supported = 2,
}
#[derive(PartialEq, Debug, Copy, Clone)]
@ -54,8 +55,11 @@ impl TryFrom<u32> for HardwareCurrentlySupported {
type Error = &'static str;
fn try_from(v: u32) -> Result<Self, Self::Error> {
match v {
x if x == HardwareCurrentlySupported::Unsupported as u32 => {
Ok(HardwareCurrentlySupported::Unsupported)
x if x == HardwareCurrentlySupported::Unknown as u32 => {
Ok(HardwareCurrentlySupported::Unknown)
}
x if x == HardwareCurrentlySupported::UnsupportedPrototype as u32 => {
Ok(HardwareCurrentlySupported::UnsupportedPrototype)
}
x if x == HardwareCurrentlySupported::Supported as u32 => {
Ok(HardwareCurrentlySupported::Supported)
@ -68,7 +72,8 @@ impl TryFrom<u32> for HardwareCurrentlySupported {
impl fmt::Display for HardwareCurrentlySupported {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
HardwareCurrentlySupported::Unsupported => write!(f, "Unsupported"),
HardwareCurrentlySupported::Unknown => write!(f, "Unknown"),
HardwareCurrentlySupported::UnsupportedPrototype => write!(f, "Unsupported Prototype"),
HardwareCurrentlySupported::Supported => write!(f, "Supported"),
}
}
@ -129,7 +134,7 @@ pub(crate) async fn check_support() -> Result<HardwareCurrentlySupported> {
Ok(match res {
0 => HardwareCurrentlySupported::Supported,
_ => HardwareCurrentlySupported::Unsupported,
_ => HardwareCurrentlySupported::UnsupportedPrototype,
})
}
@ -226,13 +231,15 @@ pub mod test {
#[test]
fn hardware_currently_supported_roundtrip() {
enum_roundtrip!(HardwareCurrentlySupported {
0: u32 = Unsupported,
1: u32 = Supported,
0: u32 = Unknown,
1: u32 = UnsupportedPrototype,
2: u32 = Supported,
});
assert!(HardwareCurrentlySupported::try_from(2).is_err());
assert!(HardwareCurrentlySupported::try_from(3).is_err());
assert_eq!(HardwareCurrentlySupported::Unknown.to_string(), "Unknown");
assert_eq!(
HardwareCurrentlySupported::Unsupported.to_string(),
"Unsupported"
HardwareCurrentlySupported::UnsupportedPrototype.to_string(),
"Unsupported Prototype"
);
assert_eq!(
HardwareCurrentlySupported::Supported.to_string(),

View file

@ -19,7 +19,7 @@ use crate::cec::{HdmiCecControl, HdmiCecState};
use crate::daemon::user::Command;
use crate::daemon::DaemonCommand;
use crate::error::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo};
use crate::hardware::check_support;
use crate::hardware::{check_support, HardwareCurrentlySupported};
use crate::job::JobManagerCommand;
use crate::power::{
get_available_cpu_scaling_governors, get_cpu_scaling_governor, get_gpu_clocks,
@ -93,7 +93,6 @@ macro_rules! setter {
struct SteamOSManager {
proxy: Proxy<'static>,
channel: Sender<Command>,
}
struct AmbientLightSensor1 {
@ -116,6 +115,11 @@ struct HdmiCec1 {
hdmi_cec: HdmiCecControl<'static>,
}
struct Manager2 {
proxy: Proxy<'static>,
channel: Sender<Command>,
}
struct Storage1 {
proxy: Proxy<'static>,
job_manager: UnboundedSender<JobManagerCommand>,
@ -139,11 +143,10 @@ impl SteamOSManager {
pub async fn new(
system_conn: Connection,
proxy: Proxy<'static>,
channel: Sender<Command>,
job_manager: UnboundedSender<JobManagerCommand>,
) -> Result<Self> {
job_manager.send(JobManagerCommand::MirrorConnection(system_conn))?;
Ok(SteamOSManager { proxy, channel })
Ok(SteamOSManager { proxy })
}
}
@ -154,14 +157,6 @@ impl SteamOSManager {
API_VERSION
}
#[zbus(property(emits_changed_signal = "const"))]
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)),
}
}
#[zbus(property(emits_changed_signal = "false"))]
async fn gpu_power_profiles(&self) -> fdo::Result<HashMap<u32, String>> {
get_gpu_power_profiles().await.map_err(to_zbus_fdo_error)
@ -286,15 +281,6 @@ impl SteamOSManager {
.await
.map_err(to_zbus_error)
}
async fn reload_config(&self) -> fdo::Result<()> {
self.channel
.send(DaemonCommand::ReadConfig)
.await
.inspect_err(|message| error!("Error sending ReadConfig command: {message}"))
.map_err(to_zbus_fdo_error)?;
method!(self, "ReloadConfig")
}
}
#[interface(name = "com.steampowered.SteamOSManager1.AmbientLightSensor1")]
@ -399,6 +385,26 @@ impl HdmiCec1 {
}
}
#[interface(name = "com.steampowered.SteamOSManager1.Manager2")]
impl Manager2 {
#[zbus(property(emits_changed_signal = "const"))]
async fn hardware_currently_supported(&self) -> u32 {
match check_support().await {
Ok(res) => res as u32,
Err(_) => HardwareCurrentlySupported::Unknown as u32,
}
}
async fn reload_config(&self) -> fdo::Result<()> {
self.channel
.send(DaemonCommand::ReadConfig)
.await
.inspect_err(|message| error!("Error sending ReadConfig command: {message}"))
.map_err(to_zbus_fdo_error)?;
method!(self, "ReloadConfig")
}
}
#[interface(name = "com.steampowered.SteamOSManager1.Storage1")]
impl Storage1 {
async fn format_device(
@ -462,8 +468,7 @@ pub(crate) async fn create_interfaces(
.build()
.await?;
let manager =
SteamOSManager::new(system.clone(), proxy.clone(), daemon, job_manager.clone()).await?;
let manager = SteamOSManager::new(system.clone(), proxy.clone(), job_manager.clone()).await?;
let als = AmbientLightSensor1 {
proxy: proxy.clone(),
@ -478,6 +483,10 @@ pub(crate) async fn create_interfaces(
proxy: proxy.clone(),
};
let hdmi_cec = HdmiCec1::new(&session).await?;
let manager2 = Manager2 {
proxy: proxy.clone(),
channel: daemon,
};
let storage = Storage1 {
proxy: proxy.clone(),
job_manager: job_manager.clone(),
@ -501,6 +510,7 @@ pub(crate) async fn create_interfaces(
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, manager2).await?;
object_server.at(MANAGER_PATH, storage).await?;
object_server.at(MANAGER_PATH, update_bios).await?;
object_server.at(MANAGER_PATH, update_dock).await?;
@ -620,6 +630,15 @@ mod test {
.unwrap());
}
#[tokio::test]
async fn interface_matches_manager2() {
let test = start().await.expect("start");
assert!(test_interface_matches::<Manager2>(&test.connection)
.await
.unwrap());
}
#[tokio::test]
async fn interface_matches_storage1() {
let test = start().await.expect("start");

View file

@ -19,9 +19,6 @@ use zbus::proxy;
assume_defaults = true
)]
trait Manager {
/// ReloadConfig method
fn reload_config(&self) -> zbus::Result<()>;
/// SetWifiDebugMode method
fn set_wifi_debug_mode(&self, mode: u32, buffer_size: u32) -> zbus::Result<()>;
@ -41,10 +38,6 @@ trait Manager {
#[zbus(property)]
fn gpu_power_profiles(&self) -> zbus::Result<std::collections::HashMap<u32, String>>;
/// HardwareCurrentlySupported property
#[zbus(property)]
fn hardware_currently_supported(&self) -> zbus::Result<u32>;
/// ManualGpuClock property
#[zbus(property)]
fn manual_gpu_clock(&self) -> zbus::Result<u32>;