Finalise zbus3 conversion

This commit is contained in:
Luke D. Jones
2022-01-16 22:28:53 +13:00
parent bac2ba6f09
commit a85e2f6130
33 changed files with 1093 additions and 1077 deletions

View File

@@ -2,6 +2,7 @@ use std::sync::{Arc, Mutex};
use crate::error::RogError;
use crate::{CtrlTask, GetSupported};
use async_trait::async_trait;
use log::{info, warn};
use rog_profiles::error::ProfileError;
use rog_profiles::{FanCurveProfiles, Profile};
@@ -135,8 +136,9 @@ impl CtrlProfileTask {
}
}
#[async_trait]
impl CtrlTask for CtrlProfileTask {
fn do_task(&self) -> Result<(), RogError> {
async fn do_task(&self) -> Result<(), RogError> {
if let Ok(ref mut lock) = self.ctrl.try_lock() {
let new_profile = Profile::get_active_profile().unwrap();
if new_profile != lock.config.active_profile {

View File

@@ -1,13 +1,19 @@
use async_trait::async_trait;
use log::warn;
use rog_profiles::fan_curve_set::CurveData;
use rog_profiles::fan_curve_set::FanCurveSet;
use rog_profiles::Profile;
use zbus::Connection;
use zbus::SignalContext;
use std::sync::Arc;
use std::sync::Mutex;
use zbus::{dbus_interface, fdo::Error};
use zvariant::ObjectPath;
use crate::error::RogError;
use crate::CtrlTask;
use super::controller::CtrlPlatformProfile;
static UNSUPPORTED_MSG: &str =
@@ -161,25 +167,32 @@ impl ProfileZbus {
}
#[dbus_interface(signal)]
fn notify_profile(&self, profile: &Profile) -> zbus::Result<()> {}
async fn notify_profile(
signal_ctxt: &SignalContext<'_>,
profile: &Profile,
) -> zbus::Result<()> {
}
}
impl ProfileZbus {
fn do_notification(&self) {
if let Ok(ctrl) = self.inner.try_lock() {
self.notify_profile(&ctrl.config.active_profile)
.unwrap_or_else(|err| warn!("{}", err));
if let Ok(_ctrl) = self.inner.try_lock() {
// self.notify_profile(&ctrl.config.active_profile)
// .unwrap_or_else(|err| warn!("{}", err));
}
}
}
#[async_trait]
impl crate::ZbusAdd for ProfileZbus {
fn add_to_server(self, server: &mut zbus::ObjectServer) {
async fn add_to_server(self, server: &mut Connection) {
server
.object_server()
.at(
&ObjectPath::from_str_unchecked("/org/asuslinux/Profile"),
self,
)
.await
.map_err(|err| {
warn!("DbusFanAndCpu: add_to_server {}", err);
err
@@ -187,3 +200,18 @@ impl crate::ZbusAdd for ProfileZbus {
.ok();
}
}
#[async_trait]
impl CtrlTask for ProfileZbus {
async fn do_task(&self) -> Result<(), RogError> {
if let Ok(ref mut lock) = self.inner.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()?;
lock.save_config();
}
}
Ok(())
}
}