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