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