diff --git a/Cargo.lock b/Cargo.lock index 6c740a2a..9d9eafaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,6 @@ dependencies = [ name = "asusd" version = "5.0.7" dependencies = [ - "async-trait", "cargo-husky", "concat-idents", "config-traits", diff --git a/Cargo.toml b/Cargo.toml index 645424c1..c3fb35c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,9 +5,9 @@ resolver = "2" [workspace.package] version = "5.0.7" +rust-version = "1.75" [workspace.dependencies] -async-trait = "^0.1" tokio = { version = "^1.23.0", default-features = false, features = ["macros", "sync"]} concat-idents = "^1.1" dirs = "^4.0" diff --git a/README.md b/README.md index 7097c868..e51fbb19 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ A gui is now in the repo - ROG Control Center. At this time it is still a WIP, b # BUILDING -Requirements are rust >= 1.57 installed from rustup.io if the distro provided version is too old, and `make`. +Requirements are rust >= 1.75 installed from rustup.io if the distro provided version is too old, and `make`. **Ubuntu (unsuported):** diff --git a/asusd/Cargo.toml b/asusd/Cargo.toml index bd0b9058..92a670f9 100644 --- a/asusd/Cargo.toml +++ b/asusd/Cargo.toml @@ -23,7 +23,6 @@ dmi_id = { path = "../dmi-id" } futures-lite = "*" udev.workspace = true -async-trait.workspace = true tokio.workspace = true # cli and logging diff --git a/asusd/src/ctrl_anime/trait_impls.rs b/asusd/src/ctrl_anime/trait_impls.rs index 81b580bf..229b7cb0 100644 --- a/asusd/src/ctrl_anime/trait_impls.rs +++ b/asusd/src/ctrl_anime/trait_impls.rs @@ -1,7 +1,6 @@ use std::sync::atomic::Ordering; use std::sync::Arc; -use async_trait::async_trait; use config_traits::StdConfig; use log::warn; use logind_zbus::manager::ManagerProxy; @@ -35,7 +34,6 @@ async fn get_logind_manager<'a>() -> ManagerProxy<'a> { pub struct CtrlAnimeZbus(pub Arc>); /// The struct with the main dbus methods requires this trait -#[async_trait] impl crate::ZbusRun for CtrlAnimeZbus { async fn add_to_server(self, server: &mut Connection) { Self::add_to_server_helper(self, ANIME_ZBUS_PATH, server).await; @@ -259,7 +257,6 @@ impl CtrlAnimeZbus { } } -#[async_trait] impl crate::CtrlTask for CtrlAnimeZbus { fn zbus_path() -> &'static str { ANIME_ZBUS_PATH @@ -385,7 +382,6 @@ impl crate::CtrlTask for CtrlAnimeZbus { } } -#[async_trait] impl crate::Reloadable for CtrlAnimeZbus { async fn reload(&mut self) -> Result<(), RogError> { if let Some(lock) = self.0.try_lock() { diff --git a/asusd/src/ctrl_aura/trait_impls.rs b/asusd/src/ctrl_aura/trait_impls.rs index 0e9ed21f..3523c050 100644 --- a/asusd/src/ctrl_aura/trait_impls.rs +++ b/asusd/src/ctrl_aura/trait_impls.rs @@ -1,7 +1,6 @@ use std::collections::BTreeMap; use std::sync::Arc; -use async_trait::async_trait; use config_traits::StdConfig; use log::{debug, error, info, warn}; use rog_aura::advanced::UsbPackets; @@ -33,7 +32,6 @@ impl CtrlAuraZbus { } } -#[async_trait] impl crate::ZbusRun for CtrlAuraZbus { async fn add_to_server(self, server: &mut Connection) { Self::add_to_server_helper(self, AURA_ZBUS_PATH, server).await; @@ -205,7 +203,6 @@ impl CtrlAuraZbus { } } -#[async_trait] impl CtrlTask for CtrlAuraZbus { fn zbus_path() -> &'static str { AURA_ZBUS_PATH @@ -278,7 +275,6 @@ impl CtrlTask for CtrlAuraZbus { } } -#[async_trait] impl crate::Reloadable for CtrlAuraZbus { async fn reload(&mut self) -> Result<(), RogError> { let mut ctrl = self.0.lock().await; diff --git a/asusd/src/ctrl_fancurves.rs b/asusd/src/ctrl_fancurves.rs index 2e3daf05..500d21f3 100644 --- a/asusd/src/ctrl_fancurves.rs +++ b/asusd/src/ctrl_fancurves.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use std::sync::Arc; -use async_trait::async_trait; use config_traits::{StdConfig, StdConfigLoad}; use futures_lite::StreamExt; use log::{debug, error, info, warn}; @@ -241,14 +240,12 @@ impl CtrlFanCurveZbus { } } -#[async_trait] impl crate::ZbusRun for CtrlFanCurveZbus { async fn add_to_server(self, server: &mut Connection) { Self::add_to_server_helper(self, FAN_CURVE_ZBUS_PATH, server).await; } } -#[async_trait] impl CtrlTask for CtrlFanCurveZbus { fn zbus_path() -> &'static str { FAN_CURVE_ZBUS_PATH @@ -292,7 +289,6 @@ impl CtrlTask for CtrlFanCurveZbus { } } -#[async_trait] impl crate::Reloadable for CtrlFanCurveZbus { /// Fetch the active profile and use that to set all related components up async fn reload(&mut self) -> Result<(), RogError> { diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 69ede817..03e89a27 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -1,7 +1,6 @@ use std::process::Command; use std::sync::Arc; -use async_trait::async_trait; use config_traits::StdConfig; use log::{debug, error, info, warn}; use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP}; @@ -522,14 +521,12 @@ impl CtrlPlatform { } } -#[async_trait] impl crate::ZbusRun for CtrlPlatform { async fn add_to_server(self, server: &mut Connection) { Self::add_to_server_helper(self, ZBUS_PATH, server).await; } } -#[async_trait] impl crate::Reloadable for CtrlPlatform { async fn reload(&mut self) -> Result<(), RogError> { if self.platform.has_panel_od() { @@ -592,7 +589,6 @@ impl CtrlPlatform { task_watch_item_notify!(nv_temp_target platform); } -#[async_trait] impl CtrlTask for CtrlPlatform { fn zbus_path() -> &'static str { ZBUS_PATH diff --git a/asusd/src/lib.rs b/asusd/src/lib.rs index 2364b332..476cd99b 100644 --- a/asusd/src/lib.rs +++ b/asusd/src/lib.rs @@ -15,7 +15,6 @@ pub mod error; use std::future::Future; use std::time::Duration; -use async_trait::async_trait; use dmi_id::DMIID; use futures_lite::stream::StreamExt; use log::{debug, info, warn}; @@ -130,34 +129,33 @@ pub fn print_board_info() { info!("Board name: {}", dmi.board_name); } -#[async_trait] pub trait Reloadable { - async fn reload(&mut self) -> Result<(), RogError>; + fn reload(&mut self) -> impl std::future::Future> + Send; } - -#[async_trait] pub trait ZbusRun { - async fn add_to_server(self, server: &mut Connection); + fn add_to_server(self, server: &mut Connection) + -> impl std::future::Future + Send; - async fn add_to_server_helper( + fn add_to_server_helper( iface: impl zbus::Interface, path: &str, server: &mut Connection, - ) { - server - .object_server() - .at(&ObjectPath::from_str_unchecked(path), iface) - .await - .map_err(|err| { - warn!("{}: add_to_server {}", path, err); - err - }) - .ok(); + ) -> impl std::future::Future + Send { + async move { + server + .object_server() + .at(&ObjectPath::from_str_unchecked(path), iface) + .await + .map_err(|err| { + warn!("{}: add_to_server {}", path, err); + err + }) + .ok(); + } } } /// Set up a task to run on the async executor -#[async_trait] pub trait CtrlTask { fn zbus_path() -> &'static str; @@ -168,7 +166,10 @@ pub trait CtrlTask { /// Implement to set up various tasks that may be required, using the /// `Executor`. No blocking loops are allowed, or they must be run on a /// separate thread. - async fn create_tasks(&self, signal: SignalContext<'static>) -> Result<(), RogError>; + fn create_tasks( + &self, + signal: SignalContext<'static>, + ) -> impl std::future::Future> + Send; // /// Create a timed repeating task // async fn repeating_task(&self, millis: u64, mut task: impl FnMut() + Send + @@ -186,7 +187,7 @@ pub trait CtrlTask { /// /// The closures can potentially block, so execution time should be the /// minimal possible such as save a variable. - async fn create_sys_event_tasks< + fn create_sys_event_tasks< Fut1, Fut2, Fut3, @@ -201,7 +202,8 @@ pub trait CtrlTask { mut on_prepare_for_shutdown: F2, mut on_lid_change: F3, mut on_external_power_change: F4, - ) where + ) -> impl std::future::Future + Send + where F1: FnMut(bool) -> Fut1, F2: FnMut(bool) -> Fut2, F3: FnMut(bool) -> Fut3, @@ -211,70 +213,72 @@ pub trait CtrlTask { Fut3: Future + Send, Fut4: Future + Send, { - let connection = Connection::system() - .await - .expect("Controller could not create dbus connection"); + async { + let connection = Connection::system() + .await + .expect("Controller could not create dbus connection"); - let manager = ManagerProxy::builder(&connection) - .cache_properties(CacheProperties::No) - .build() - .await - .expect("Controller could not create ManagerProxy"); + let manager = ManagerProxy::builder(&connection) + .cache_properties(CacheProperties::No) + .build() + .await + .expect("Controller could not create ManagerProxy"); - let manager1 = manager.clone(); - tokio::spawn(async move { - if let Ok(mut notif) = manager1.receive_prepare_for_shutdown().await { - while let Some(event) = notif.next().await { - // blocks thread :| - if let Ok(args) = event.args() { - debug!("Doing on_prepare_for_shutdown({})", args.start); - on_prepare_for_shutdown(args.start).await; + let manager1 = manager.clone(); + tokio::spawn(async move { + if let Ok(mut notif) = manager1.receive_prepare_for_shutdown().await { + while let Some(event) = notif.next().await { + // blocks thread :| + if let Ok(args) = event.args() { + debug!("Doing on_prepare_for_shutdown({})", args.start); + on_prepare_for_shutdown(args.start).await; + } } } - } - }); + }); - let manager2 = manager.clone(); - tokio::spawn(async move { - if let Ok(mut notif) = manager2.receive_prepare_for_sleep().await { - while let Some(event) = notif.next().await { - // blocks thread :| - if let Ok(args) = event.args() { - debug!("Doing on_prepare_for_sleep({})", args.start); - on_prepare_for_sleep(args.start).await; + let manager2 = manager.clone(); + tokio::spawn(async move { + if let Ok(mut notif) = manager2.receive_prepare_for_sleep().await { + while let Some(event) = notif.next().await { + // blocks thread :| + if let Ok(args) = event.args() { + debug!("Doing on_prepare_for_sleep({})", args.start); + on_prepare_for_sleep(args.start).await; + } } } - } - }); + }); - let manager3 = manager.clone(); - tokio::spawn(async move { - let mut last_power = manager3.on_external_power().await.unwrap_or_default(); + let manager3 = manager.clone(); + tokio::spawn(async move { + let mut last_power = manager3.on_external_power().await.unwrap_or_default(); - loop { - if let Ok(next) = manager3.on_external_power().await { - if next != last_power { - last_power = next; - on_external_power_change(next).await; + loop { + if let Ok(next) = manager3.on_external_power().await { + if next != last_power { + last_power = next; + on_external_power_change(next).await; + } } + sleep(Duration::from_secs(2)).await; } - sleep(Duration::from_secs(2)).await; - } - }); + }); - tokio::spawn(async move { - let mut last_lid = manager.lid_closed().await.unwrap_or_default(); - // need to loop on these as they don't emit signals - loop { - if let Ok(next) = manager.lid_closed().await { - if next != last_lid { - last_lid = next; - on_lid_change(next).await; + tokio::spawn(async move { + let mut last_lid = manager.lid_closed().await.unwrap_or_default(); + // need to loop on these as they don't emit signals + loop { + if let Ok(next) = manager.lid_closed().await { + if next != last_lid { + last_lid = next; + on_lid_change(next).await; + } } + sleep(Duration::from_secs(2)).await; } - sleep(Duration::from_secs(2)).await; - } - }); + }); + } } }