mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Send signals using the correct context for each
This commit is contained in:
@@ -52,13 +52,15 @@ impl CtrlPower {
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
Self::notify_charge_control_end_threshold(&ctxt, limit).await?;
|
||||
Self::notify_charge_control_end_threshold(&ctxt, limit)
|
||||
.await
|
||||
.ok();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn charge_control_end_threshold(&self) -> u8 {
|
||||
loop {
|
||||
if let Some(config) = self.config.try_lock() {
|
||||
if let Some(mut config) = self.config.try_lock() {
|
||||
let limit = self
|
||||
.power
|
||||
.get_charge_control_end_threshold()
|
||||
@@ -67,11 +69,10 @@ impl CtrlPower {
|
||||
err
|
||||
})
|
||||
.unwrap_or(100);
|
||||
if let Some(mut config) = self.config.try_lock() {
|
||||
config.read();
|
||||
config.bat_charge_limit = limit;
|
||||
config.write();
|
||||
}
|
||||
|
||||
config.read();
|
||||
config.bat_charge_limit = limit;
|
||||
config.write();
|
||||
|
||||
return config.bat_charge_limit;
|
||||
}
|
||||
@@ -207,7 +208,6 @@ impl CtrlTask for CtrlPower {
|
||||
.await?;
|
||||
|
||||
let ctrl = self.clone();
|
||||
dbg!("CtrlPower");
|
||||
tokio::spawn(async move {
|
||||
let mut online = 10;
|
||||
loop {
|
||||
|
||||
@@ -216,7 +216,6 @@ impl CtrlTask for ProfileZbus {
|
||||
lock.write_profile_curve_to_platform().unwrap();
|
||||
lock.save_config();
|
||||
}
|
||||
|
||||
Self::notify_profile(&signal_ctxt.clone(), lock.config.active_profile)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
@@ -10,6 +10,7 @@ use daemon::ctrl_anime::CtrlAnime;
|
||||
use log::LevelFilter;
|
||||
use log::{error, info, warn};
|
||||
use tokio::time::sleep;
|
||||
use zbus::SignalContext;
|
||||
|
||||
use daemon::ctrl_anime::{config::AnimeConfig, trait_impls::CtrlAnimeZbus};
|
||||
use daemon::ctrl_aura::{config::AuraConfig, controller::CtrlKbdLed, trait_impls::CtrlKbdLedZbus};
|
||||
@@ -78,7 +79,8 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
match CtrlPlatform::new(config.clone()) {
|
||||
Ok(ctrl) => {
|
||||
start_tasks(ctrl, &mut connection).await?;
|
||||
let sig_ctx = CtrlPlatform::signal_context(&connection)?;
|
||||
start_tasks(ctrl, &mut connection, sig_ctx).await?;
|
||||
}
|
||||
Err(err) => {
|
||||
error!("CtrlPlatform: {}", err);
|
||||
@@ -87,7 +89,8 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
match CtrlPower::new(config.clone()) {
|
||||
Ok(ctrl) => {
|
||||
start_tasks(ctrl, &mut connection).await?;
|
||||
let sig_ctx = CtrlPower::signal_context(&connection)?;
|
||||
start_tasks(ctrl, &mut connection, sig_ctx).await?;
|
||||
}
|
||||
Err(err) => {
|
||||
error!("CtrlPower: {}", err);
|
||||
@@ -99,7 +102,8 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
match CtrlPlatformProfile::new(profile_config) {
|
||||
Ok(ctrl) => {
|
||||
let zbus = ProfileZbus(Arc::new(Mutex::new(ctrl)));
|
||||
start_tasks(zbus, &mut connection).await?;
|
||||
let sig_ctx = ProfileZbus::signal_context(&connection)?;
|
||||
start_tasks(zbus, &mut connection, sig_ctx).await?;
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Profile control: {}", err);
|
||||
@@ -112,7 +116,8 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
match CtrlAnime::new(AnimeConfig::load()) {
|
||||
Ok(ctrl) => {
|
||||
let zbus = CtrlAnimeZbus(Arc::new(Mutex::new(ctrl)));
|
||||
start_tasks(zbus, &mut connection).await?;
|
||||
let sig_ctx = CtrlAnimeZbus::signal_context(&connection)?;
|
||||
start_tasks(zbus, &mut connection, sig_ctx).await?;
|
||||
}
|
||||
Err(err) => {
|
||||
info!("AniMe control: {}", err);
|
||||
@@ -124,7 +129,8 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
match CtrlKbdLed::new(laptop, aura_config) {
|
||||
Ok(ctrl) => {
|
||||
let zbus = CtrlKbdLedZbus(Arc::new(Mutex::new(ctrl)));
|
||||
start_tasks(zbus, &mut connection).await?;
|
||||
let sig_ctx = CtrlKbdLedZbus::signal_context(&connection)?;
|
||||
start_tasks(zbus, &mut connection, sig_ctx).await?;
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Keyboard control: {}", err);
|
||||
@@ -140,7 +146,11 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn start_tasks<T>(mut zbus: T, connection: &mut Connection) -> Result<(), Box<dyn Error>>
|
||||
async fn start_tasks<T>(
|
||||
mut zbus: T,
|
||||
connection: &mut Connection,
|
||||
signal_ctx: SignalContext<'static>,
|
||||
) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
T: ZbusRun + Reloadable + CtrlTask + Clone,
|
||||
{
|
||||
@@ -151,8 +161,6 @@ where
|
||||
.unwrap_or_else(|err| warn!("Controller error: {}", err));
|
||||
zbus.add_to_server(connection).await;
|
||||
|
||||
task.create_tasks(CtrlKbdLedZbus::signal_context(connection)?)
|
||||
.await
|
||||
.ok();
|
||||
task.create_tasks(signal_ctx).await.ok();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -64,8 +64,9 @@ macro_rules! task_watch_item {
|
||||
let mut buffer = [0; 32];
|
||||
watch.event_stream(&mut buffer).unwrap().for_each(|_| async {
|
||||
let value = ctrl.$name();
|
||||
dbg!(&value);
|
||||
concat_idents::concat_idents!(notif_fn = notify_, $name {
|
||||
Self::notif_fn(&signal_ctxt, value).await.unwrap();
|
||||
Self::notif_fn(&signal_ctxt, value).await.ok();
|
||||
});
|
||||
}).await;
|
||||
});
|
||||
|
||||
@@ -70,5 +70,5 @@ trait Profile {
|
||||
|
||||
/// NotifyProfile signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_profile(&self, profile: Profile) -> zbus::Result<Profile>;
|
||||
async fn notify_profile(&self, profile: Profile) -> zbus::Result<Profile>;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ macro_rules! watch_attr {
|
||||
path.push($attr_name);
|
||||
if let Some(path) = path.to_str() {
|
||||
let mut inotify = inotify::Inotify::init()?;
|
||||
inotify.add_watch(path, inotify::WatchMask::MODIFY)
|
||||
inotify.add_watch(path, inotify::WatchMask::CLOSE_WRITE)
|
||||
.map_err(|e| {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
PlatformError::AttrNotFound(format!("{}", $attr_name))
|
||||
|
||||
Reference in New Issue
Block a user