daemon: inotify for panel_od and gu_mux_mode

This commit is contained in:
Luke D. Jones
2022-09-21 19:04:28 +12:00
parent a44a1bfa89
commit 56285916cd
8 changed files with 73 additions and 15 deletions

1
Cargo.lock generated
View File

@@ -575,6 +575,7 @@ name = "daemon"
version = "4.4.0"
dependencies = [
"async-trait",
"concat-idents",
"env_logger",
"inotify",
"log",

View File

@@ -45,3 +45,4 @@ toml = "^0.5.8"
sysfs-class = "^0.1.2" # used for backlight control and baord ID
inotify = "0.10.0"
concat-idents = "1.1.3"

View File

@@ -154,7 +154,7 @@ impl CtrlRogBios {
Self::notify_gpu_mux_mode(&ctxt, mode).await.ok();
}
fn gpu_mux_mode(&self) -> GpuMode {
fn get_gpu_mux_mode(&self) -> GpuMode {
match self.platform.get_gpu_mux_mode() {
Ok(m) => GpuMode::from_mux(m),
Err(e) => {
@@ -203,6 +203,7 @@ impl CtrlRogBios {
overdrive: bool,
) {
if self
.platform
.set_panel_od(overdrive)
.map_err(|err| {
warn!("CtrlRogBios: set_panel_overdrive {}", err);
@@ -214,25 +215,29 @@ impl CtrlRogBios {
lock.panel_od = overdrive;
lock.write();
}
Self::notify_panel_overdrive(&ctxt, overdrive).await.ok();
Self::notify_panel_od(&ctxt, overdrive).await.ok();
}
}
fn panel_overdrive(&self) -> bool {
self.platform
/// Get the `panel_od` value from platform. Updates the stored value in internal config also.
fn get_panel_od(&self) -> bool {
let od = self
.platform
.get_panel_od()
.map_err(|err| {
warn!("CtrlRogBios: get panel overdrive {}", err);
err
})
.unwrap_or(false)
.unwrap_or(false);
if let Ok(mut lock) = self.config.try_lock() {
lock.panel_od = od;
lock.write();
}
od
}
#[dbus_interface(signal)]
async fn notify_panel_overdrive(
signal_ctxt: &SignalContext<'_>,
overdrive: bool,
) -> zbus::Result<()> {
async fn notify_panel_od(signal_ctxt: &SignalContext<'_>, overdrive: bool) -> zbus::Result<()> {
}
}
@@ -257,12 +262,50 @@ impl crate::Reloadable for CtrlRogBios {
}
}
macro_rules! watch_item {
($name:ident) => {
concat_idents::concat_idents!(fn_name = watch_, $name {
async fn fn_name<'a>(
&self,
executor: &mut Executor<'a>,
signal_ctxt: SignalContext<'a>,
) -> Result<(), RogError> {
let ctrl = self.clone();
concat_idents::concat_idents!(watch_fn = monitor_, $name {
let mut watch = self.platform.watch_fn()?;
executor
.spawn(async move {
let mut buffer = [0; 1024];
loop {
if let Ok(events) = watch.read_events_blocking(&mut buffer) {
for _ in events {
let value = concat_idents::concat_idents!(get_fn = get_, $name { ctrl.get_fn() });
concat_idents::concat_idents!(notif_fn = notify_, $name {
Self::notif_fn(&signal_ctxt, value).await.unwrap();
});
}
}
}
})
.detach();
});
Ok(())
}
});
};
}
impl CtrlRogBios {
watch_item!(panel_od);
watch_item!(gpu_mux_mode);
}
#[async_trait]
impl CtrlTask for CtrlRogBios {
async fn create_tasks<'a>(
&self,
executor: &mut Executor<'a>,
_: SignalContext<'a>,
signal_ctxt: SignalContext<'a>,
) -> Result<(), RogError> {
let platform1 = self.clone();
let platform2 = self.clone();
@@ -301,6 +344,10 @@ impl CtrlTask for CtrlRogBios {
)
.await;
self.watch_panel_od(executor, signal_ctxt.clone()).await?;
self.watch_gpu_mux_mode(executor, signal_ctxt.clone())
.await?;
Ok(())
}
}

View File

@@ -222,7 +222,7 @@ impl CtrlTask for ProfileZbus {
async fn create_tasks<'a>(
&self,
executor: &mut Executor<'a>,
signal: SignalContext<'a>,
signal_ctxt: SignalContext<'a>,
) -> Result<(), RogError> {
let ctrl = self.inner.clone();
let mut inotify = Inotify::init()?;
@@ -247,7 +247,9 @@ impl CtrlTask for ProfileZbus {
}
if let Some(active_profile) = active_profile {
Self::notify_profile(&signal, active_profile).await.ok();
Self::notify_profile(&signal_ctxt, active_profile)
.await
.ok();
}
}
}

View File

@@ -86,7 +86,7 @@ pub fn start_notifications(
.spawn(async move {
let conn = zbus::Connection::system().await.unwrap();
let proxy = RogBiosProxy::new(&conn).await.unwrap();
if let Ok(p) = proxy.receive_notify_panel_overdrive().await {
if let Ok(p) = proxy.receive_notify_panel_od().await {
p.for_each(|_| {
bios_notified.store(true, Ordering::SeqCst);
future::ready(())

View File

@@ -55,5 +55,5 @@ trait RogBios {
/// NotifyPanelOverdrive signal
#[dbus_proxy(signal)]
fn notify_panel_overdrive(&self, overdrive: bool) -> zbus::Result<()>;
fn notify_panel_od(&self, overdrive: bool) -> zbus::Result<()>;
}

View File

@@ -127,5 +127,6 @@ macro_rules! attr_u8_array {
crate::has_attr!($attr_name $item);
crate::get_attr_u8_array!($attr_name $item);
crate::set_attr_u8_array!($attr_name $item);
crate::watch_attr!($attr_name $item);
};
}

View File

@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{path::PathBuf, str::FromStr};
use log::{info, warn};
use serde::{Deserialize, Serialize};
@@ -20,6 +20,7 @@ use crate::{
#[derive(Debug, PartialEq, PartialOrd, Clone)]
pub struct AsusPlatform {
path: PathBuf,
pp_path: PathBuf,
}
impl AsusPlatform {
@@ -44,6 +45,7 @@ impl AsusPlatform {
info!("Found platform support at {:?}", device.sysname());
return Ok(Self {
path: device.syspath().to_owned(),
pp_path: PathBuf::from_str("/sys/firmware/acpi").unwrap(),
});
}
Err(PlatformError::MissingFunction(
@@ -55,6 +57,10 @@ impl AsusPlatform {
attr_bool!("egpu_enable", path);
attr_bool!("panel_od", path);
attr_u8!("gpu_mux_mode", path);
attr_u8!("throttle_thermal_policy", path);
// The acpi platform_profile support
attr_u8!("platform_profile", pp_path);
}
#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Clone, Copy)]