Trial single inotify test

This commit is contained in:
Luke D. Jones
2022-09-20 20:57:39 +12:00
parent 62c7338b2d
commit 0c97cf710d
11 changed files with 126 additions and 48 deletions

View File

@@ -1,12 +1,9 @@
use crate::error::RogError;
use crate::{CtrlTask, GetSupported};
use async_trait::async_trait;
use crate::GetSupported;
use log::{info, warn};
use rog_platform::supported::PlatformProfileFunctions;
use rog_profiles::error::ProfileError;
use rog_profiles::{FanCurveProfiles, Profile};
use smol::Executor;
use std::sync::{Arc, Mutex};
use super::config::ProfileConfig;
@@ -129,32 +126,3 @@ impl CtrlPlatformProfile {
Ok(())
}
}
pub struct CtrlProfileTask {
ctrl: Arc<Mutex<CtrlPlatformProfile>>,
}
impl CtrlProfileTask {
pub fn new(ctrl: Arc<Mutex<CtrlPlatformProfile>>) -> Self {
Self { ctrl }
}
}
#[async_trait]
impl CtrlTask for CtrlProfileTask {
async fn create_tasks(&self, executor: &mut Executor) -> Result<(), RogError> {
let ctrl = self.ctrl.clone();
self.repeating_task(666, executor, move || {
if let Ok(ref mut lock) = ctrl.try_lock() {
let new_profile = Profile::get_active_profile().unwrap();
if new_profile != lock.config.active_profile {
lock.config.active_profile = new_profile;
lock.write_profile_curve_to_platform().unwrap();
lock.save_config();
}
}
})
.await;
Ok(())
}
}

View File

@@ -1,8 +1,12 @@
use async_trait::async_trait;
use inotify::Inotify;
use inotify::WatchMask;
use log::warn;
use rog_profiles::fan_curve_set::CurveData;
use rog_profiles::fan_curve_set::FanCurveSet;
use rog_profiles::Profile;
use rog_profiles::PLATFORM_PROFILE;
use smol::Executor;
use zbus::Connection;
use zbus::SignalContext;
@@ -10,6 +14,9 @@ use std::sync::Arc;
use std::sync::Mutex;
use zbus::{dbus_interface, fdo::Error};
use crate::error::RogError;
use crate::CtrlTask;
use super::controller::CtrlPlatformProfile;
static UNSUPPORTED_MSG: &str =
@@ -209,3 +216,45 @@ impl crate::ZbusAdd for ProfileZbus {
Self::add_to_server_helper(self, "/org/asuslinux/Profile", server).await;
}
}
#[async_trait]
impl CtrlTask for ProfileZbus {
async fn create_tasks<'a>(
&self,
executor: &mut Executor<'a>,
signal: SignalContext<'a>,
) -> Result<(), RogError> {
let ctrl = self.inner.clone();
let mut inotify = Inotify::init()?;
inotify.add_watch(PLATFORM_PROFILE, WatchMask::MODIFY)?;
executor
.spawn(async move {
let mut buffer = [0; 1024];
loop {
if let Ok(events) = inotify.read_events_blocking(&mut buffer) {
for _ in events {
let mut active_profile = None;
if let Ok(ref mut lock) = ctrl.try_lock() {
let new_profile = Profile::get_active_profile().unwrap();
if new_profile != lock.config.active_profile {
lock.config.active_profile = new_profile;
lock.write_profile_curve_to_platform().unwrap();
lock.save_config();
active_profile = Some(lock.config.active_profile);
}
}
if let Some(active_profile) = active_profile {
Self::notify_profile(&signal, active_profile).await.ok();
}
}
}
}
})
.detach();
Ok(())
}
}