Fix profile controller not detecting if platform_profile is changed

Closes #313
This commit is contained in:
Luke D. Jones
2023-01-07 11:44:30 +13:00
parent 8011ba3009
commit 022a144705
5 changed files with 122 additions and 22 deletions

View File

@@ -82,6 +82,21 @@ pub fn write_attr_u8_array(device: &mut Device, attr: &str, values: &[u8]) -> Re
.map_err(|e| PlatformError::IoPath(attr.into(), e))
}
pub fn read_attr_string(device: &Device, attr_name: &str) -> Result<String> {
if let Some(value) = device.attribute_value(attr_name) {
let tmp = value.to_string_lossy().to_string();
return Ok(tmp);
}
Err(PlatformError::AttrNotFound(attr_name.to_owned()))
}
pub fn write_attr_string(device: &mut Device, attr: &str, value: &str) -> Result<()> {
let tmp = value.trim();
device
.set_attribute_value(attr, tmp)
.map_err(|e| PlatformError::IoPath(attr.into(), e))
}
#[cfg(test)]
mod tests {
#[test]

View File

@@ -141,3 +141,37 @@ macro_rules! attr_u8_array {
$crate::watch_attr!($attr_name $item);
};
}
#[macro_export]
macro_rules! get_attr_string {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = get_, $attr_name {
$(#[$doc_comment])*
pub fn fn_name(&self) -> Result<String> {
$crate::read_attr_string(&to_device(&self.$item)?, $attr_name)
}
});
};
}
#[macro_export]
macro_rules! set_attr_string {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = set_, $attr_name {
$(#[$doc_comment])*
pub fn fn_name(&self, values: &str) -> Result<()> {
$crate::write_attr_string(&mut to_device(&self.$item)?, $attr_name, values)
}
});
};
}
#[macro_export]
macro_rules! attr_string {
($attr_name:literal, $item:ident) => {
$crate::has_attr!($attr_name $item);
$crate::get_attr_string!($attr_name $item);
$crate::set_attr_string!($attr_name $item);
$crate::watch_attr!($attr_name $item);
};
}

View File

@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use zbus::zvariant::Type;
use crate::error::{PlatformError, Result};
use crate::{attr_bool, attr_u8, to_device};
use crate::{attr_bool, attr_string, attr_u8, to_device};
/// The "platform" device provides access to things like:
/// - `dgpu_disable`
@@ -36,7 +36,7 @@ impl AsusPlatform {
attr_u8!("throttle_thermal_policy", path);
// The acpi platform_profile support
attr_u8!("platform_profile", pp_path);
attr_string!("platform_profile", pp_path);
pub fn new() -> Result<Self> {
let mut enumerator = udev::Enumerator::new().map_err(|err| {