From ad150903af3cd0fde75d25dd17c690b750307a37 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 17 Mar 2021 01:50:16 +0000 Subject: [PATCH] Forwarded error from ProfileProxy::profile_names instead of 'expecting' there. Handled error up in main by logging. Reorganized code in ctrl_fan_cpu to keep consistent code structure --- asusctl/src/main.rs | 4 ++++ daemon/src/ctrl_fan_cpu.rs | 20 ++++++++++++++++++++ rog-dbus/src/zbus_profile.rs | 8 ++++++++ rog-types/src/profile.rs | 2 ++ 4 files changed, 34 insertions(+) diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index d78371e2..56aa8107 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -365,6 +365,7 @@ fn handle_profile( ) -> Result<(), Box> { if !cmd.next && !cmd.create + && !cmd.list && cmd.curve.is_none() && cmd.max_percentage.is_none() && cmd.min_percentage.is_none() @@ -393,6 +394,9 @@ fn handle_profile( } if cmd.next { dbus.proxies().profile().next_fan()?; + } else if cmd.list { + let profile_names = dbus.proxies().profile().profile_names()?; + println!("Available profiles are {}", profile_names); } else { dbus.proxies() .profile() diff --git a/daemon/src/ctrl_fan_cpu.rs b/daemon/src/ctrl_fan_cpu.rs index 5dc7599f..a397dad2 100644 --- a/daemon/src/ctrl_fan_cpu.rs +++ b/daemon/src/ctrl_fan_cpu.rs @@ -127,8 +127,28 @@ impl DbusFanAndCpu { "Failed".to_string() } + fn profile_names(&self) -> String { + if let Ok(ctrl) = self.inner.try_lock() { + if let Ok(mut cfg) = ctrl.config.try_lock() { + cfg.read(); + + let profile_names: String = cfg + .power_profiles + .keys() + .cloned() + .collect::>() + .join(", "); + + return profile_names; + } + } + + "Failed".to_string() + } + #[dbus_interface(signal)] fn notify_profile(&self, profile: &str) -> zbus::Result<()> {} + } impl crate::ZbusAdd for DbusFanAndCpu { diff --git a/rog-dbus/src/zbus_profile.rs b/rog-dbus/src/zbus_profile.rs index de01b999..5e692916 100644 --- a/rog-dbus/src/zbus_profile.rs +++ b/rog-dbus/src/zbus_profile.rs @@ -41,6 +41,9 @@ trait Daemon { /// Profiles method fn profiles(&self) -> zbus::Result; + /// ProfileNames method + fn profile_names(&self) -> zbus::Result; + /// SetProfile method fn set_profile(&self, profile: &str) -> zbus::Result<()>; @@ -82,6 +85,11 @@ impl<'a> ProfileProxy<'a> { self.0.set_profile(&serde_json::to_string(cmd).unwrap()) } + #[inline] + pub fn profile_names(&self) -> Result { + self.0.profile_names() + } + #[inline] pub fn connect_notify_profile( &self, diff --git a/rog-types/src/profile.rs b/rog-types/src/profile.rs index 2450d8c4..ea222cf4 100644 --- a/rog-types/src/profile.rs +++ b/rog-types/src/profile.rs @@ -80,6 +80,8 @@ pub struct ProfileCommand { pub next: bool, #[options(help = "create the profile if it doesn't exist")] pub create: bool, + #[options(help = "list available profiles")] + pub list: bool, #[options(meta = "", help = "enable or disable cpu turbo")] pub turbo: Option,