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

829
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,13 +7,14 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
zbus = "^1.9" zbus = "^2.2"
# serialisation # serialisation
serde_json = "^1.0" serde_json = "^1.0"
rog_dbus = { path = "../rog-dbus" } rog_dbus = { path = "../rog-dbus" }
rog_aura = { path = "../rog-aura" } rog_aura = { path = "../rog-aura" }
rog_supported = { path = "../rog-supported" } rog_supported = { path = "../rog-supported" }
rog_profiles = { path = "../rog-profiles" } rog_profiles = { path = "../rog-profiles" }
futures = { version = "0.3.19", features = ["executor", "thread-pool"] }
[dependencies.notify-rust] [dependencies.notify-rust]
version = "^4.3" version = "^4.3"

View File

@@ -1,10 +1,16 @@
use futures::{executor::ThreadPool, StreamExt};
use notify_rust::{Hint, Notification, NotificationHandle}; use notify_rust::{Hint, Notification, NotificationHandle};
use rog_aura::AuraEffect; use rog_aura::AuraEffect;
use rog_dbus::{DbusProxies, Signals}; use rog_dbus::{
zbus_charge::ChargeProxy, zbus_led::LedProxy, zbus_profile::ProfileProxy,
zbus_rogbios::RogBiosProxy,
};
use rog_profiles::Profile; use rog_profiles::Profile;
use std::error::Error; use std::{
use std::thread::sleep; error::Error,
use std::time::Duration; future,
sync::{Arc, Mutex},
};
const NOTIF_HEADER: &str = "ROG Control"; const NOTIF_HEADER: &str = "ROG Control";
@@ -14,7 +20,7 @@ macro_rules! notify {
notif.close(); notif.close();
} }
if let Ok(x) = $notifier($data) { if let Ok(x) = $notifier($data) {
$last_notif = Some(x); $last_notif.replace(x);
} }
}; };
} }
@@ -29,43 +35,110 @@ macro_rules! base_notification {
}; };
} }
type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("asus-notify version {}", env!("CARGO_PKG_VERSION")); println!("asus-notify version {}", env!("CARGO_PKG_VERSION"));
println!(" rog-dbus version {}", rog_dbus::VERSION); println!(" rog-dbus version {}", rog_dbus::VERSION);
let (proxies, conn) = DbusProxies::new()?; let last_notification: SharedHandle = Arc::new(Mutex::new(None));
let signals = Signals::new(&proxies)?;
let mut last_notification: Option<NotificationHandle> = None; let thread_pool = ThreadPool::new()?;
// BIOS notif
let x = last_notification.clone();
thread_pool.spawn_ok(async move {
let conn = zbus::Connection::system().await.unwrap();
let proxy = RogBiosProxy::new(&conn).await.unwrap();
if let Ok(p) = proxy.receive_notify_post_boot_sound().await {
p.for_each(|e| {
if let Ok(out) = e.args() {
if let Ok(ref mut lock) = x.try_lock() {
notify!(do_post_sound_notif, lock, &out.sound());
}
}
future::ready(())
})
.await;
};
});
let recv = proxies.setup_recv(conn); // Charge notif
let mut err_count = 0; let x = last_notification.clone();
thread_pool.spawn_ok(async move {
let conn = zbus::Connection::system().await.unwrap();
let proxy = ChargeProxy::new(&conn).await.unwrap();
if let Ok(p) = proxy.receive_notify_charge().await {
p.for_each(|e| {
if let Ok(out) = e.args() {
if let Ok(ref mut lock) = x.try_lock() {
notify!(do_charge_notif, lock, &out.limit);
}
}
future::ready(())
})
.await;
};
});
// Profile notif
let x = last_notification.clone();
thread_pool.spawn_ok(async move {
let conn = zbus::Connection::system().await.unwrap();
let proxy = ProfileProxy::new(&conn).await.unwrap();
if let Ok(p) = proxy.receive_notify_profile().await {
p.for_each(|e| {
if let Ok(out) = e.args() {
if let Ok(ref mut lock) = x.try_lock() {
notify!(do_thermal_notif, lock, &out.profile);
}
}
future::ready(())
})
.await;
};
});
// LED notif
thread_pool.spawn_ok(async move {
let conn = zbus::Connection::system().await.unwrap();
let proxy = LedProxy::new(&conn).await.unwrap();
if let Ok(p) = proxy.receive_notify_led().await {
p.for_each(|e| {
if let Ok(out) = e.args() {
if let Ok(ref mut lock) = last_notification.try_lock() {
notify!(do_led_notif, lock, &out.data);
}
}
future::ready(())
})
.await;
};
});
loop { loop {
sleep(Duration::from_millis(100)); std::thread::sleep(std::time::Duration::from_millis(1000));
if let Err(err) = recv.next_signal() { // if err_count < 3 {
if err_count < 3 { // err_count += 1;
err_count += 1; // println!("{}", err);
println!("{}", err); // }
} // if err_count == 3 {
if err_count == 3 { // err_count += 1;
err_count += 1; // println!("Max error count reached. Spooling silently.");
println!("Max error count reached. Spooling silently."); // }
} // sleep(Duration::from_millis(2000));
sleep(Duration::from_millis(2000)); // continue;
continue; // }
} // err_count = 0;
err_count = 0;
if let Ok(data) = signals.led_mode.try_recv() { // if let Ok(data) = signals.led_mode.try_recv() {
notify!(do_led_notif, last_notification, &data); // notify!(do_led_notif, last_notification, &data);
} // }
if let Ok(data) = signals.profile.try_recv() { // if let Ok(data) = signals.profile.try_recv() {
notify!(do_thermal_notif, last_notification, &data); // notify!(do_thermal_notif, last_notification, &data);
} // }
if let Ok(data) = signals.charge.try_recv() { // if let Ok(data) = signals.charge.try_recv() {
notify!(do_charge_notif, last_notification, &data); // notify!(do_charge_notif, last_notification, &data);
} // }
} }
} }
@@ -101,3 +174,7 @@ fn do_led_notif(ledmode: &AuraEffect) -> Result<NotificationHandle, notify_rust:
fn do_charge_notif(limit: &u8) -> Result<NotificationHandle, notify_rust::error::Error> { fn do_charge_notif(limit: &u8) -> Result<NotificationHandle, notify_rust::error::Error> {
base_notification!(&format!("Battery charge limit changed to {}", limit)) base_notification!(&format!("Battery charge limit changed to {}", limit))
} }
fn do_post_sound_notif(on: &bool) -> Result<NotificationHandle, notify_rust::error::Error> {
base_notification!(&format!("BIOS Post sound {}", on))
}

View File

@@ -8,7 +8,7 @@ use anime_cli::{AnimeActions, AnimeCommand};
use profiles_cli::{FanCurveCommand, ProfileCommand}; use profiles_cli::{FanCurveCommand, ProfileCommand};
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2}; use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2};
use rog_aura::{self, AuraEffect}; use rog_aura::{self, AuraEffect};
use rog_dbus::RogDbusClient; use rog_dbus::RogDbusClientBlocking;
use rog_profiles::error::ProfileError; use rog_profiles::error::ProfileError;
use rog_supported::SupportedFunctions; use rog_supported::SupportedFunctions;
use rog_supported::{ use rog_supported::{
@@ -47,7 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
} }
let (dbus, _) = RogDbusClient::new() let (dbus, _) = RogDbusClientBlocking::new()
.map_err(|e| { .map_err(|e| {
print_error_help(Box::new(e), None); print_error_help(Box::new(e), None);
std::process::exit(3); std::process::exit(3);
@@ -57,7 +57,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let supported = dbus let supported = dbus
.proxies() .proxies()
.supported() .supported()
.get_supported_functions() .supported_functions()
.map_err(|e| { .map_err(|e| {
print_error_help(Box::new(e), None); print_error_help(Box::new(e), None);
std::process::exit(4); std::process::exit(4);
@@ -139,7 +139,7 @@ fn do_diagnose(name: &str) -> bool {
fn do_parsed( fn do_parsed(
parsed: &CliStart, parsed: &CliStart,
supported: &SupportedFunctions, supported: &SupportedFunctions,
dbus: &RogDbusClient, dbus: &RogDbusClientBlocking,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
match &parsed.command { match &parsed.command {
Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?, Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?,
@@ -170,13 +170,13 @@ fn do_parsed(
if let Some(brightness) = &parsed.kbd_bright { if let Some(brightness) = &parsed.kbd_bright {
match brightness.level() { match brightness.level() {
None => { None => {
let level = dbus.proxies().led().get_led_brightness()?; let level = dbus.proxies().led().led_brightness()?;
println!("Current keyboard led brightness: {}", level); println!("Current keyboard led brightness: {}", level);
} }
Some(level) => dbus Some(level) => dbus
.proxies() .proxies()
.led() .led()
.set_led_brightness(<rog_aura::LedBrightness>::from(level))?, .set_brightness(<rog_aura::LedBrightness>::from(level))?,
} }
} }
@@ -193,7 +193,7 @@ fn do_parsed(
} }
if let Some(chg_limit) = parsed.chg_limit { if let Some(chg_limit) = parsed.chg_limit {
dbus.proxies().charge().write_limit(chg_limit)?; dbus.proxies().charge().set_limit(chg_limit)?;
} }
Ok(()) Ok(())
@@ -206,7 +206,7 @@ fn do_gfx() -> Result<(), Box<dyn std::error::Error>> {
} }
fn handle_anime( fn handle_anime(
dbus: &RogDbusClient, dbus: &RogDbusClientBlocking,
_supported: &AnimeSupportedFunctions, _supported: &AnimeSupportedFunctions,
cmd: &AnimeCommand, cmd: &AnimeCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -335,7 +335,7 @@ fn handle_anime(
} }
fn handle_led_mode( fn handle_led_mode(
dbus: &RogDbusClient, dbus: &RogDbusClientBlocking,
supported: &LedSupportedFunctions, supported: &LedSupportedFunctions,
mode: &LedModeCommand, mode: &LedModeCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -416,7 +416,7 @@ fn handle_led_mode(
} }
fn handle_profile( fn handle_profile(
dbus: &RogDbusClient, dbus: &RogDbusClientBlocking,
supported: &PlatformProfileFunctions, supported: &PlatformProfileFunctions,
cmd: &ProfileCommand, cmd: &ProfileCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -457,7 +457,7 @@ fn handle_profile(
} }
fn handle_fan_curve( fn handle_fan_curve(
dbus: &RogDbusClient, dbus: &RogDbusClientBlocking,
supported: &PlatformProfileFunctions, supported: &PlatformProfileFunctions,
cmd: &FanCurveCommand, cmd: &FanCurveCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -513,7 +513,7 @@ fn handle_fan_curve(
if let Some(mut curve) = cmd.data.clone() { if let Some(mut curve) = cmd.data.clone() {
let fan = cmd.fan.unwrap_or_default(); let fan = cmd.fan.unwrap_or_default();
curve.set_fan(fan); curve.set_fan(fan);
dbus.proxies().profile().set_fan_curve(curve, profile)?; dbus.proxies().profile().set_fan_curve(profile, curve)?;
} }
} }
@@ -521,7 +521,7 @@ fn handle_fan_curve(
} }
fn handle_bios_option( fn handle_bios_option(
dbus: &RogDbusClient, dbus: &RogDbusClientBlocking,
supported: &RogBiosSupportedFunctions, supported: &RogBiosSupportedFunctions,
cmd: &BiosCommand, cmd: &BiosCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -548,15 +548,15 @@ fn handle_bios_option(
} }
if let Some(opt) = cmd.post_sound_set { if let Some(opt) = cmd.post_sound_set {
dbus.proxies().rog_bios().set_post_sound(opt)?; dbus.proxies().rog_bios().set_post_boot_sound(opt)?;
} }
if cmd.post_sound_get { if cmd.post_sound_get {
let res = dbus.proxies().rog_bios().get_post_sound()? == 1; let res = dbus.proxies().rog_bios().post_boot_sound()? == 1;
println!("Bios POST sound on: {}", res); println!("Bios POST sound on: {}", res);
} }
if let Some(opt) = cmd.dedicated_gfx_set { if let Some(opt) = cmd.dedicated_gfx_set {
println!("Rebuilding initrd to include drivers"); println!("Rebuilding initrd to include drivers");
dbus.proxies().rog_bios().set_dedicated_gfx(opt)?; dbus.proxies().rog_bios().set_dedicated_graphic_mode(opt)?;
println!("The mode change is not active until you reboot, on boot the bios will make the required change"); println!("The mode change is not active until you reboot, on boot the bios will make the required change");
if opt { if opt {
println!( println!(
@@ -567,7 +567,7 @@ fn handle_bios_option(
} }
} }
if cmd.dedicated_gfx_get { if cmd.dedicated_gfx_get {
let res = dbus.proxies().rog_bios().get_dedicated_gfx()? == 1; let res = dbus.proxies().rog_bios().dedicated_graphic_mode()? == 1;
println!("Bios dedicated GPU on: {}", res); println!("Bios dedicated GPU on: {}", res);
} }
} }

View File

@@ -1,6 +1,6 @@
use rog_anime::error::AnimeError; use rog_anime::error::AnimeError;
use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2}; use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2};
use rog_dbus::RogDbusClient; use rog_dbus::RogDbusClientBlocking;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;
use std::{ use std::{
@@ -66,14 +66,14 @@ pub enum TimeType {
/// and a zbus server behind `Arc<Mutex<T>>` /// and a zbus server behind `Arc<Mutex<T>>`
pub struct CtrlAnimeInner<'a> { pub struct CtrlAnimeInner<'a> {
sequences: Sequences, sequences: Sequences,
client: RogDbusClient<'a>, client: RogDbusClientBlocking<'a>,
do_early_return: Arc<AtomicBool>, do_early_return: Arc<AtomicBool>,
} }
impl<'a> CtrlAnimeInner<'static> { impl<'a> CtrlAnimeInner<'static> {
pub fn new( pub fn new(
sequences: Sequences, sequences: Sequences,
client: RogDbusClient<'static>, client: RogDbusClientBlocking<'static>,
do_early_return: Arc<AtomicBool>, do_early_return: Arc<AtomicBool>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Ok(Self { Ok(Self {
@@ -131,7 +131,7 @@ impl<'a> CtrlAnimeInner<'static> {
pub struct CtrlAnime<'a> { pub struct CtrlAnime<'a> {
config: Arc<Mutex<UserAnimeConfig>>, config: Arc<Mutex<UserAnimeConfig>>,
client: RogDbusClient<'a>, client: RogDbusClientBlocking<'a>,
inner: Arc<Mutex<CtrlAnimeInner<'a>>>, inner: Arc<Mutex<CtrlAnimeInner<'a>>>,
/// Must be the same Atomic as in CtrlAnimeInner /// Must be the same Atomic as in CtrlAnimeInner
inner_early_return: Arc<AtomicBool>, inner_early_return: Arc<AtomicBool>,
@@ -141,7 +141,7 @@ impl<'a> CtrlAnime<'static> {
pub fn new( pub fn new(
config: Arc<Mutex<UserAnimeConfig>>, config: Arc<Mutex<UserAnimeConfig>>,
inner: Arc<Mutex<CtrlAnimeInner<'static>>>, inner: Arc<Mutex<CtrlAnimeInner<'static>>>,
client: RogDbusClient<'static>, client: RogDbusClientBlocking<'static>,
inner_early_return: Arc<AtomicBool>, inner_early_return: Arc<AtomicBool>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Ok(CtrlAnime { Ok(CtrlAnime {
@@ -350,16 +350,16 @@ impl CtrlAnime<'static> {
Err(zbus::fdo::Error::Failed("UserConfig lock fail".into())) Err(zbus::fdo::Error::Failed("UserConfig lock fail".into()))
} }
pub fn set_state(&mut self, on: bool) -> zbus::fdo::Result<()> { pub fn set_state(&mut self, on: bool) -> zbus::Result<()> {
// Operations here need to be in specific order // Operations here need to be in specific order
if on { if on {
self.client.proxies().anime().set_on_off(on)?; self.client.proxies().anime().set_on_off(on).ok();
// Let the inner loop run // Let the inner loop run
self.inner_early_return.store(false, Ordering::SeqCst); self.inner_early_return.store(false, Ordering::SeqCst);
} else { } else {
// Must make the inner run loop return early // Must make the inner run loop return early
self.inner_early_return.store(true, Ordering::SeqCst); self.inner_early_return.store(true, Ordering::SeqCst);
self.client.proxies().anime().set_on_off(on)?; self.client.proxies().anime().set_on_off(on).ok();
} }
Ok(()) Ok(())
} }

View File

@@ -1,4 +1,4 @@
use rog_dbus::RogDbusClient; use rog_dbus::RogDbusClientBlocking;
use rog_user::{ use rog_user::{
ctrl_anime::{CtrlAnime, CtrlAnimeInner}, ctrl_anime::{CtrlAnime, CtrlAnimeInner},
user_config::*, user_config::*,
@@ -17,8 +17,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!(" rog-dbus v{}", rog_dbus::VERSION); println!(" rog-dbus v{}", rog_dbus::VERSION);
println!("rog-supported v{}", rog_supported::VERSION); println!("rog-supported v{}", rog_supported::VERSION);
let (client, _) = RogDbusClient::new()?; let (client, _) = RogDbusClientBlocking::new()?;
let supported = client.proxies().supported().get_supported_functions()?; let supported = client.proxies().supported().supported_functions()?;
let mut config = UserConfig::new(); let mut config = UserConfig::new();
config.load_config()?; config.load_config()?;
@@ -44,7 +44,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
early_return.clone(), early_return.clone(),
)?)); )?));
// Need new client object for dbus control part // Need new client object for dbus control part
let (client, _) = RogDbusClient::new()?; let (client, _) = RogDbusClientBlocking::new()?;
let anime_control = CtrlAnime::new(anime_config, inner.clone(), client, early_return)?; let anime_control = CtrlAnime::new(anime_config, inner.clone(), client, early_return)?;
anime_control.add_to_server(&mut server); anime_control.add_to_server(&mut server);
// Thread using inner // Thread using inner

View File

@@ -18,11 +18,16 @@ name = "asusd"
path = "src/daemon.rs" path = "src/daemon.rs"
[dependencies] [dependencies]
rog_anime = { path = "../rog-anime" } rog_anime = { path = "../rog-anime", features = ["dbus"] }
rog_aura = { path = "../rog-aura" } rog_aura = { path = "../rog-aura", features = ["dbus"] }
rog_supported = { path = "../rog-supported" } rog_supported = { path = "../rog-supported" }
rog_profiles = { path = "../rog-profiles" } rog_profiles = { path = "../rog-profiles" }
rog_dbus = { path = "../rog-dbus" } rog_dbus = { path = "../rog-dbus" }
async-executor = "1.4.1"
async-trait = "^0.1"
futures = { version = "0.3.19", features = ["executor", "thread-pool"] }
rusb = "^0.8" rusb = "^0.8"
udev = "^0.6" udev = "^0.6"
@@ -30,10 +35,9 @@ udev = "^0.6"
log = "^0.4" log = "^0.4"
env_logger = "^0.8" env_logger = "^0.8"
zbus = "^1.9.1" zbus = "^2.0"
zvariant = "^2.6" zvariant = "^3.0"
zvariant_derive = { version = "^2.6" } logind-zbus = { version = "^2.0" } #, default-features = false, features = ["non_blocking"] }
logind-zbus = "^0.7.1"
# serialisation # serialisation
serde = "^1.0" serde = "^1.0"

View File

@@ -2,6 +2,7 @@ use log::{error, warn};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::PathBuf;
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf"; pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
@@ -24,8 +25,8 @@ impl Config {
.read(true) .read(true)
.write(true) .write(true)
.create(true) .create(true)
.open(&CONFIG_PATH) .open(&PathBuf::from(CONFIG_PATH))
.unwrap_or_else(|_| panic!("The directory /etc/asusd/ is missing")); // okay to cause panic here .unwrap_or_else(|e| panic!("Error opening {}, {}", CONFIG_PATH, e)); // okay to cause panic here
let mut buf = String::new(); let mut buf = String::new();
let config; let config;
if let Ok(read_len) = file.read_to_string(&mut buf) { if let Ok(read_len) = file.read_to_string(&mut buf) {

View File

@@ -1,7 +1,8 @@
pub mod config; pub mod config;
pub mod zbus; pub mod zbus;
use ::zbus::Connection; use ::zbus::blocking::Connection;
use async_trait::async_trait;
use log::{error, info, warn}; use log::{error, info, warn};
use logind_zbus::ManagerProxy; use logind_zbus::ManagerProxy;
use rog_anime::{ use rog_anime::{
@@ -298,7 +299,7 @@ impl CtrlAnime {
} }
pub struct CtrlAnimeTask<'a> { pub struct CtrlAnimeTask<'a> {
inner: Arc<Mutex<CtrlAnime>>, _inner: Arc<Mutex<CtrlAnime>>,
_c: Connection, _c: Connection,
manager: ManagerProxy<'a>, manager: ManagerProxy<'a>,
} }
@@ -306,80 +307,24 @@ pub struct CtrlAnimeTask<'a> {
impl<'a> CtrlAnimeTask<'a> { impl<'a> CtrlAnimeTask<'a> {
pub fn new(inner: Arc<Mutex<CtrlAnime>>) -> Self { pub fn new(inner: Arc<Mutex<CtrlAnime>>) -> Self {
let connection = let connection =
Connection::new_system().expect("CtrlAnimeTask could not create dbus connection"); Connection::system().expect("CtrlAnimeTask could not create dbus connection");
let manager = let manager =
ManagerProxy::new(&connection).expect("CtrlAnimeTask could not create ManagerProxy"); ManagerProxy::new(&connection).expect("CtrlAnimeTask could not create ManagerProxy");
let c1 = inner.clone();
// Run this action when the system starts shutting down
manager
.connect_prepare_for_shutdown(move |shutdown| {
if shutdown {
'outer: loop {
if let Ok(lock) = c1.try_lock() {
lock.thread_exit.store(true, Ordering::SeqCst);
CtrlAnime::run_thread(c1.clone(), lock.cache.shutdown.clone(), false);
break 'outer;
}
}
}
Ok(())
})
.map_err(|err| {
warn!("CtrlAnimeTask: new() {}", err);
err
})
.ok();
let c1 = inner.clone();
// Run this action when the system wakes up from sleep
manager
.connect_prepare_for_sleep(move |sleep| {
if !sleep {
// wait a fraction for things to wake up properly
std::thread::sleep(Duration::from_millis(100));
'outer: loop {
if let Ok(lock) = c1.try_lock() {
lock.thread_exit.store(true, Ordering::SeqCst);
CtrlAnime::run_thread(c1.clone(), lock.cache.wake.clone(), true);
break 'outer;
}
}
}
Ok(())
})
.map_err(|err| {
warn!("CtrlAnimeTask: new() {}", err);
err
})
.ok();
Self { Self {
inner, _inner: inner,
_c: connection, _c: connection,
manager, manager,
} }
} }
} }
#[async_trait]
impl<'a> crate::CtrlTask for CtrlAnimeTask<'a> { impl<'a> crate::CtrlTask for CtrlAnimeTask<'a> {
fn do_task(&self) -> Result<(), RogError> { async fn do_task(&self) -> Result<(), RogError> {
if let Ok(mut lock) = self.inner.try_lock() { self.manager.receive_prepare_for_shutdown()?.next();
// Refresh the config and cache incase the user has edited it self.manager.receive_prepare_for_sleep()?.next();
let config = AnimeConfig::load();
lock.cache
.init_from_config(&config)
.map_err(|err| {
warn!("CtrlAnimeTask: do_task {}", err);
err
})
.ok();
}
// Check for signals on each task iteration, this will run the callbacks
// if any signal is recieved
self.manager.next_signal()?;
Ok(()) Ok(())
} }
} }

View File

@@ -1,11 +1,12 @@
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use async_trait::async_trait;
use log::warn; use log::warn;
use rog_anime::{ use rog_anime::{
usb::{pkt_for_apply, pkt_for_set_boot, pkt_for_set_on}, usb::{pkt_for_apply, pkt_for_set_boot, pkt_for_set_on},
AnimeDataBuffer, AnimePowerStates, AnimeDataBuffer, AnimePowerStates,
}; };
use zbus::dbus_interface; use zbus::{dbus_interface, Connection, SignalContext};
use zvariant::ObjectPath; use zvariant::ObjectPath;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
@@ -15,13 +16,16 @@ use super::CtrlAnime;
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::ZbusAdd for CtrlAnimeZbus { impl crate::ZbusAdd for CtrlAnimeZbus {
fn add_to_server(self, server: &mut zbus::ObjectServer) { async fn add_to_server(self, server: &mut Connection) {
server server
.object_server()
.at( .at(
&ObjectPath::from_str_unchecked("/org/asuslinux/Anime"), &ObjectPath::from_str_unchecked("/org/asuslinux/Anime"),
self, self,
) )
.await
.map_err(|err| { .map_err(|err| {
warn!("CtrlAnimeDisplay: add_to_server {}", err); warn!("CtrlAnimeDisplay: add_to_server {}", err);
err err
@@ -71,12 +75,10 @@ impl CtrlAnimeZbus {
lock.config.awake_enabled = status; lock.config.awake_enabled = status;
lock.config.write(); lock.config.write();
let states = AnimePowerStates { // let states = AnimePowerStates {
enabled: lock.config.awake_enabled, // enabled: lock.config.awake_enabled,
boot_anim_enabled: lock.config.boot_anim_enabled, // boot_anim_enabled: lock.config.boot_anim_enabled,
}; // };
self.notify_power_states(&states)
.unwrap_or_else(|err| warn!("{}", err));
break 'outer; break 'outer;
} }
} }
@@ -91,12 +93,10 @@ impl CtrlAnimeZbus {
lock.config.boot_anim_enabled = on; lock.config.boot_anim_enabled = on;
lock.config.write(); lock.config.write();
let states = AnimePowerStates { // let states = AnimePowerStates {
enabled: lock.config.awake_enabled, // enabled: lock.config.awake_enabled,
boot_anim_enabled: lock.config.boot_anim_enabled, // boot_anim_enabled: lock.config.boot_anim_enabled,
}; // };
self.notify_power_states(&states)
.unwrap_or_else(|err| warn!("{}", err));
break 'outer; break 'outer;
} }
} }
@@ -136,5 +136,8 @@ impl CtrlAnimeZbus {
/// Notify listeners of the status of AniMe LED power and factory system-status animations /// Notify listeners of the status of AniMe LED power and factory system-status animations
#[dbus_interface(signal)] #[dbus_interface(signal)]
fn notify_power_states(&self, data: &AnimePowerStates) -> zbus::Result<()>; async fn notify_power_states(
ctxt: &SignalContext<'_>,
data: AnimePowerStates,
) -> zbus::Result<()>;
} }

View File

@@ -6,6 +6,7 @@ use crate::{
laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES}, laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES},
CtrlTask, CtrlTask,
}; };
use async_trait::async_trait;
use log::{info, warn}; use log::{info, warn};
use logind_zbus::ManagerProxy; use logind_zbus::ManagerProxy;
use rog_aura::{ use rog_aura::{
@@ -16,12 +17,12 @@ use rog_aura::{
AuraEffect, LedBrightness, LED_MSG_LEN, AuraEffect, LedBrightness, LED_MSG_LEN,
}; };
use rog_supported::LedSupportedFunctions; use rog_supported::LedSupportedFunctions;
use std::fs::OpenOptions;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::{fs::OpenOptions, thread::spawn}; use zbus::blocking::Connection;
use zbus::Connection;
use crate::GetSupported; use crate::GetSupported;
@@ -57,46 +58,46 @@ pub struct CtrlKbdLed {
pub struct CtrlKbdLedTask<'a> { pub struct CtrlKbdLedTask<'a> {
inner: Arc<Mutex<CtrlKbdLed>>, inner: Arc<Mutex<CtrlKbdLed>>,
_c: Connection, _c: Connection,
manager: ManagerProxy<'a>, _manager: ManagerProxy<'a>,
} }
impl<'a> CtrlKbdLedTask<'a> { impl<'a> CtrlKbdLedTask<'a> {
pub fn new(inner: Arc<Mutex<CtrlKbdLed>>) -> Self { pub fn new(inner: Arc<Mutex<CtrlKbdLed>>) -> Self {
let connection = let connection =
Connection::new_system().expect("CtrlKbdLedTask could not create dbus connection"); Connection::system().expect("CtrlKbdLedTask could not create dbus connection");
let manager = let manager =
ManagerProxy::new(&connection).expect("CtrlKbdLedTask could not create ManagerProxy"); ManagerProxy::new(&connection).expect("CtrlKbdLedTask could not create ManagerProxy");
let c1 = inner.clone(); // let c1 = inner.clone();
// Run this action when the system wakes up from sleep // // Run this action when the system wakes up from sleep
manager // manager
.connect_prepare_for_sleep(move |sleep| { // .connect_prepare_for_sleep(move |sleep| {
if !sleep { // if !sleep {
let c1 = c1.clone(); // let c1 = c1.clone();
spawn(move || { // spawn(move || {
// wait a fraction for things to wake up properly // // wait a fraction for things to wake up properly
//std::thread::sleep(Duration::from_millis(100)); // //std::thread::sleep(Duration::from_millis(100));
loop { // loop {
if let Ok(ref mut lock) = c1.try_lock() { // if let Ok(ref mut lock) = c1.try_lock() {
lock.set_brightness(lock.config.brightness).ok(); // lock.set_brightness(lock.config.brightness).ok();
break; // break;
} // }
} // }
}); // });
} // }
Ok(()) // Ok(())
}) // })
.map_err(|err| { // .map_err(|err| {
warn!("CtrlAnimeTask: new() {}", err); // warn!("CtrlAnimeTask: new() {}", err);
err // err
}) // })
.ok(); // .ok();
Self { Self {
inner, inner,
_c: connection, _c: connection,
manager, _manager: manager,
} }
} }
@@ -125,9 +126,11 @@ impl<'a> CtrlKbdLedTask<'a> {
} }
} }
#[async_trait]
impl<'a> CtrlTask for CtrlKbdLedTask<'a> { impl<'a> CtrlTask for CtrlKbdLedTask<'a> {
fn do_task(&self) -> Result<(), RogError> { async fn do_task(&self) -> Result<(), RogError> {
self.manager.next_signal()?; self._manager.receive_prepare_for_sleep()?.next();
if let Ok(ref mut lock) = self.inner.try_lock() { if let Ok(ref mut lock) = self.inner.try_lock() {
return Self::update_config(lock); return Self::update_config(lock);
} }

View File

@@ -1,14 +1,18 @@
use async_trait::async_trait;
use log::{error, warn}; use log::{error, warn};
use rog_aura::{AuraEffect, LedBrightness, LedPowerStates}; use rog_aura::{AuraEffect, LedBrightness, LedPowerStates};
use zbus::dbus_interface; use zbus::{dbus_interface, Connection, SignalContext};
use zvariant::ObjectPath; use zvariant::ObjectPath;
use super::controller::CtrlKbdLedZbus; use super::controller::CtrlKbdLedZbus;
#[async_trait]
impl crate::ZbusAdd for CtrlKbdLedZbus { impl crate::ZbusAdd for CtrlKbdLedZbus {
fn add_to_server(self, server: &mut zbus::ObjectServer) { async fn add_to_server(self, server: &mut Connection) {
server server
.object_server()
.at(&ObjectPath::from_str_unchecked("/org/asuslinux/Led"), self) .at(&ObjectPath::from_str_unchecked("/org/asuslinux/Led"), self)
.await
.map_err(|err| { .map_err(|err| {
error!("DbusKbdLed: add_to_server {}", err); error!("DbusKbdLed: add_to_server {}", err);
}) })
@@ -22,7 +26,7 @@ impl crate::ZbusAdd for CtrlKbdLedZbus {
#[dbus_interface(name = "org.asuslinux.Daemon")] #[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlKbdLedZbus { impl CtrlKbdLedZbus {
/// Set the keyboard brightness level (0-3) /// Set the keyboard brightness level (0-3)
fn set_brightness(&mut self, brightness: LedBrightness) { async fn set_brightness(&mut self, brightness: LedBrightness) {
if let Ok(ctrl) = self.0.try_lock() { if let Ok(ctrl) = self.0.try_lock() {
ctrl.set_brightness(brightness) ctrl.set_brightness(brightness)
.map_err(|err| warn!("{}", err)) .map_err(|err| warn!("{}", err))
@@ -31,7 +35,12 @@ impl CtrlKbdLedZbus {
} }
/// Set the keyboard LED to enabled while the device is awake /// Set the keyboard LED to enabled while the device is awake
fn set_awake_enabled(&mut self, enabled: bool) { async fn set_awake_enabled(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
enabled: bool,
) {
let mut states = None;
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.set_states_enabled(enabled, ctrl.config.sleep_anim_enabled) ctrl.set_states_enabled(enabled, ctrl.config.sleep_anim_enabled)
.map_err(|err| warn!("{}", err)) .map_err(|err| warn!("{}", err))
@@ -39,52 +48,77 @@ impl CtrlKbdLedZbus {
ctrl.config.awake_enabled = enabled; ctrl.config.awake_enabled = enabled;
ctrl.config.write(); ctrl.config.write();
let states = LedPowerStates { states = Some(LedPowerStates {
enabled: ctrl.config.awake_enabled, enabled: ctrl.config.awake_enabled,
sleep_anim_enabled: ctrl.config.sleep_anim_enabled, sleep_anim_enabled: ctrl.config.sleep_anim_enabled,
}; });
self.notify_power_states(&states) }
// Need to pull state out like this due to MutexGuard
if let Some(states) = states {
Self::notify_power_states(&ctxt, &states)
.await
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
} }
} }
/// Set the keyboard LED suspend animation to enabled while the device is suspended /// Set the keyboard LED suspend animation to enabled while the device is suspended
fn set_sleep_enabled(&mut self, enabled: bool) { async fn set_sleep_enabled(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
enabled: bool,
) {
let mut states = None;
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.set_states_enabled(ctrl.config.awake_enabled, enabled) ctrl.set_states_enabled(ctrl.config.awake_enabled, enabled)
.map_err(|err| warn!("{}", err)) .map_err(|err| warn!("{}", err))
.ok(); .ok();
ctrl.config.sleep_anim_enabled = enabled; ctrl.config.sleep_anim_enabled = enabled;
ctrl.config.write(); ctrl.config.write();
let states = LedPowerStates { states = Some(LedPowerStates {
enabled: ctrl.config.awake_enabled, enabled: ctrl.config.awake_enabled,
sleep_anim_enabled: ctrl.config.sleep_anim_enabled, sleep_anim_enabled: ctrl.config.sleep_anim_enabled,
}; });
self.notify_power_states(&states) }
if let Some(states) = states {
Self::notify_power_states(&ctxt, &states)
.await
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
} }
} }
/// Set the keyboard side LEDs to enabled /// Set the keyboard side LEDs to enabled
fn set_side_leds_enabled(&mut self, enabled: bool) { async fn set_side_leds_enabled(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
enabled: bool,
) {
let mut led = None;
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.set_side_leds_states(enabled) ctrl.set_side_leds_states(enabled)
.map_err(|err| warn!("{}", err)) .map_err(|err| warn!("{}", err))
.ok(); .ok();
ctrl.config.side_leds_enabled = enabled; ctrl.config.side_leds_enabled = enabled;
ctrl.config.write(); ctrl.config.write();
self.notify_side_leds(ctrl.config.side_leds_enabled) led = Some(enabled);
.unwrap_or_else(|err| warn!("{}", err)) }
if let Some(led) = led {
Self::notify_side_leds(&ctxt, led)
.await
.unwrap_or_else(|err| warn!("{}", err));
} }
} }
fn set_led_mode(&mut self, effect: AuraEffect) { async fn set_led_mode(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
effect: AuraEffect,
) {
let mut led = None;
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
match ctrl.do_command(effect) { match ctrl.do_command(effect) {
Ok(_) => { Ok(_) => {
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) { if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
self.notify_led(mode.clone()) led = Some(mode.clone());
.unwrap_or_else(|err| warn!("{}", err));
} }
} }
Err(err) => { Err(err) => {
@@ -92,40 +126,55 @@ impl CtrlKbdLedZbus {
} }
} }
} }
if let Some(led) = led {
Self::notify_led(&ctxt, led)
.await
.unwrap_or_else(|err| warn!("{}", err));
}
} }
fn next_led_mode(&self) { async fn next_led_mode(&self, #[zbus(signal_context)] ctxt: SignalContext<'_>) {
if let Ok(mut ctrl) = self.0.try_lock() { let mut led = None;
if let Ok(mut ctrl) = self.0.lock() {
ctrl.toggle_mode(false) ctrl.toggle_mode(false)
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) { if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
self.notify_led(mode.clone()) led = Some(mode.clone());
.unwrap_or_else(|err| warn!("{}", err));
} }
} }
if let Some(led) = led {
Self::notify_led(&ctxt, led)
.await
.unwrap_or_else(|err| warn!("{}", err));
}
} }
fn prev_led_mode(&self) { async fn prev_led_mode(&self, #[zbus(signal_context)] ctxt: SignalContext<'_>) {
if let Ok(mut ctrl) = self.0.try_lock() { let mut led = None;
if let Ok(mut ctrl) = self.0.lock() {
ctrl.toggle_mode(true) ctrl.toggle_mode(true)
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) { if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
self.notify_led(mode.clone()) led = Some(mode.clone());
.unwrap_or_else(|err| warn!("{}", err));
} }
} }
if let Some(led) = led {
Self::notify_led(&ctxt, led)
.await
.unwrap_or_else(|err| warn!("{}", err));
}
} }
fn next_led_brightness(&self) { async fn next_led_brightness(&self) {
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.next_brightness() ctrl.next_brightness()
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
} }
} }
fn prev_led_brightness(&self) { async fn prev_led_brightness(&self) {
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.prev_brightness() ctrl.prev_brightness()
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
@@ -133,7 +182,7 @@ impl CtrlKbdLedZbus {
} }
#[dbus_interface(property)] #[dbus_interface(property)]
fn awake_enabled(&self) -> bool { async fn awake_enabled(&self) -> bool {
if let Ok(ctrl) = self.0.try_lock() { if let Ok(ctrl) = self.0.try_lock() {
return ctrl.config.awake_enabled; return ctrl.config.awake_enabled;
} }
@@ -141,7 +190,7 @@ impl CtrlKbdLedZbus {
} }
#[dbus_interface(property)] #[dbus_interface(property)]
fn sleep_enabled(&self) -> bool { async fn sleep_enabled(&self) -> bool {
if let Ok(ctrl) = self.0.try_lock() { if let Ok(ctrl) = self.0.try_lock() {
return ctrl.config.sleep_anim_enabled; return ctrl.config.sleep_anim_enabled;
} }
@@ -158,7 +207,7 @@ impl CtrlKbdLedZbus {
/// Return the current mode data /// Return the current mode data
#[dbus_interface(property)] #[dbus_interface(property)]
fn led_mode(&self) -> String { async fn led_mode(&self) -> String {
if let Ok(ctrl) = self.0.try_lock() { if let Ok(ctrl) = self.0.try_lock() {
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) { if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
if let Ok(json) = serde_json::to_string(&mode) { if let Ok(json) = serde_json::to_string(&mode) {
@@ -172,7 +221,7 @@ impl CtrlKbdLedZbus {
/// Return a list of available modes /// Return a list of available modes
#[dbus_interface(property)] #[dbus_interface(property)]
fn led_modes(&self) -> String { async fn led_modes(&self) -> String {
if let Ok(ctrl) = self.0.try_lock() { if let Ok(ctrl) = self.0.try_lock() {
if let Ok(json) = serde_json::to_string(&ctrl.config.builtins) { if let Ok(json) = serde_json::to_string(&ctrl.config.builtins) {
return json; return json;
@@ -184,7 +233,7 @@ impl CtrlKbdLedZbus {
/// Return the current LED brightness /// Return the current LED brightness
#[dbus_interface(property)] #[dbus_interface(property)]
fn led_brightness(&self) -> i8 { async fn led_brightness(&self) -> i8 {
if let Ok(ctrl) = self.0.try_lock() { if let Ok(ctrl) = self.0.try_lock() {
return ctrl.get_brightness().map(|n| n as i8).unwrap_or(-1); return ctrl.get_brightness().map(|n| n as i8).unwrap_or(-1);
} }
@@ -193,11 +242,14 @@ impl CtrlKbdLedZbus {
} }
#[dbus_interface(signal)] #[dbus_interface(signal)]
fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>; async fn notify_led(signal_ctxt: &SignalContext<'_>, data: AuraEffect) -> zbus::Result<()>;
#[dbus_interface(signal)] #[dbus_interface(signal)]
fn notify_side_leds(&self, data: bool) -> zbus::Result<()>; async fn notify_side_leds(signal_ctxt: &SignalContext<'_>, data: bool) -> zbus::Result<()>;
#[dbus_interface(signal)] #[dbus_interface(signal)]
fn notify_power_states(&self, data: &LedPowerStates) -> zbus::Result<()>; async fn notify_power_states(
signal_ctxt: &SignalContext<'_>,
data: &LedPowerStates,
) -> zbus::Result<()>;
} }

View File

@@ -1,5 +1,5 @@
use crate::{config::Config, error::RogError, GetSupported}; use crate::{config::Config, error::RogError, GetSupported};
//use crate::dbus::DbusEvents; use async_trait::async_trait;
use log::{info, warn}; use log::{info, warn};
use rog_supported::ChargeSupportedFunctions; use rog_supported::ChargeSupportedFunctions;
use std::fs::OpenOptions; use std::fs::OpenOptions;
@@ -8,6 +8,8 @@ use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use zbus::dbus_interface; use zbus::dbus_interface;
use zbus::Connection;
use zbus::SignalContext;
use zvariant::ObjectPath; use zvariant::ObjectPath;
static BAT_CHARGE_PATH0: &str = "/sys/class/power_supply/BAT0/charge_control_end_threshold"; static BAT_CHARGE_PATH0: &str = "/sys/class/power_supply/BAT0/charge_control_end_threshold";
@@ -30,9 +32,13 @@ pub struct CtrlCharge {
#[dbus_interface(name = "org.asuslinux.Daemon")] #[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlCharge { impl CtrlCharge {
pub fn set_limit(&mut self, limit: u8) -> Result<(), RogError> { async fn set_limit(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
limit: u8,
) -> zbus::fdo::Result<()> {
if !(20..=100).contains(&limit) { if !(20..=100).contains(&limit) {
return Err(RogError::ChargeLimit(limit)); return Err(RogError::ChargeLimit(limit))?;
} }
if let Ok(mut config) = self.config.try_lock() { if let Ok(mut config) = self.config.try_lock() {
self.set(limit, &mut config) self.set(limit, &mut config)
@@ -41,17 +47,12 @@ impl CtrlCharge {
err err
}) })
.ok(); .ok();
self.notify_charge(limit)
.map_err(|err| {
warn!("CtrlCharge: set_limit {}", err);
err
})
.ok();
} }
Self::notify_charge(&ctxt, limit).await?;
Ok(()) Ok(())
} }
pub fn limit(&self) -> i8 { fn limit(&self) -> i8 {
if let Ok(config) = self.config.try_lock() { if let Ok(config) = self.config.try_lock() {
return config.bat_charge_limit as i8; return config.bat_charge_limit as i8;
} }
@@ -59,16 +60,19 @@ impl CtrlCharge {
} }
#[dbus_interface(signal)] #[dbus_interface(signal)]
pub fn notify_charge(&self, limit: u8) -> zbus::Result<()> {} async fn notify_charge(ctxt: &SignalContext<'_>, limit: u8) -> zbus::Result<()>;
} }
#[async_trait]
impl crate::ZbusAdd for CtrlCharge { impl crate::ZbusAdd for CtrlCharge {
fn add_to_server(self, server: &mut zbus::ObjectServer) { async fn add_to_server(self, server: &mut Connection) {
server server
.object_server()
.at( .at(
&ObjectPath::from_str_unchecked("/org/asuslinux/Charge"), &ObjectPath::from_str_unchecked("/org/asuslinux/Charge"),
self, self,
) )
.await
.map_err(|err| { .map_err(|err| {
warn!("CtrlCharge: add_to_server {}", err); warn!("CtrlCharge: add_to_server {}", err);
err err

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
use crate::{config::Config, error::RogError, GetSupported}; use crate::{config::Config, error::RogError, GetSupported};
use async_trait::async_trait;
use log::{error, info, warn}; use log::{error, info, warn};
use rog_supported::RogBiosSupportedFunctions; use rog_supported::RogBiosSupportedFunctions;
use std::fs::OpenOptions; use std::fs::OpenOptions;
@@ -8,7 +9,8 @@ use std::path::Path;
use std::process::Command; use std::process::Command;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use zbus::dbus_interface; use zbus::Connection;
use zbus::{dbus_interface, SignalContext};
use zvariant::ObjectPath; use zvariant::ObjectPath;
const INITRAMFS_PATH: &str = "/usr/sbin/update-initramfs"; const INITRAMFS_PATH: &str = "/usr/sbin/update-initramfs";
@@ -36,22 +38,23 @@ impl GetSupported for CtrlRogBios {
#[dbus_interface(name = "org.asuslinux.Daemon")] #[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlRogBios { impl CtrlRogBios {
pub fn set_dedicated_graphic_mode(&mut self, dedicated: bool) { async fn set_dedicated_graphic_mode(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
dedicated: bool,
) {
self.set_gfx_mode(dedicated) self.set_gfx_mode(dedicated)
.map_err(|err| { .map_err(|err| {
warn!("CtrlRogBios: set_asus_switch_graphic_mode {}", err); warn!("CtrlRogBios: set_asus_switch_graphic_mode {}", err);
err err
}) })
.ok(); .ok();
self.notify_dedicated_graphic_mode(dedicated) Self::notify_dedicated_graphic_mode(&ctxt, dedicated)
.map_err(|err| { .await
warn!("CtrlRogBios: notify_asus_switch_graphic_mode {}", err);
err
})
.ok(); .ok();
} }
pub fn dedicated_graphic_mode(&self) -> i8 { fn dedicated_graphic_mode(&self) -> i8 {
Self::get_gfx_mode() Self::get_gfx_mode()
.map_err(|err| { .map_err(|err| {
warn!("CtrlRogBios: get_gfx_mode {}", err); warn!("CtrlRogBios: get_gfx_mode {}", err);
@@ -61,24 +64,27 @@ impl CtrlRogBios {
} }
#[dbus_interface(signal)] #[dbus_interface(signal)]
pub fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()> {} async fn notify_dedicated_graphic_mode(
signal_ctxt: &SignalContext<'_>,
dedicated: bool,
) -> zbus::Result<()> {
}
pub fn set_post_boot_sound(&mut self, on: bool) { async fn set_post_boot_sound(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
on: bool,
) {
Self::set_boot_sound(on) Self::set_boot_sound(on)
.map_err(|err| { .map_err(|err| {
warn!("CtrlRogBios: set_post_boot_sound {}", err); warn!("CtrlRogBios: set_post_boot_sound {}", err);
err err
}) })
.ok(); .ok();
self.notify_post_boot_sound(on) Self::notify_post_boot_sound(&ctxt, on).await.ok();
.map_err(|err| {
warn!("CtrlRogBios: notify_post_boot_sound {}", err);
err
})
.ok();
} }
pub fn post_boot_sound(&self) -> i8 { fn post_boot_sound(&self) -> i8 {
Self::get_boot_sound() Self::get_boot_sound()
.map_err(|err| { .map_err(|err| {
warn!("CtrlRogBios: get_boot_sound {}", err); warn!("CtrlRogBios: get_boot_sound {}", err);
@@ -88,16 +94,19 @@ impl CtrlRogBios {
} }
#[dbus_interface(signal)] #[dbus_interface(signal)]
pub fn notify_post_boot_sound(&self, dedicated: bool) -> zbus::Result<()> {} async fn notify_post_boot_sound(ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()> {}
} }
#[async_trait]
impl crate::ZbusAdd for CtrlRogBios { impl crate::ZbusAdd for CtrlRogBios {
fn add_to_server(self, server: &mut zbus::ObjectServer) { async fn add_to_server(self, server: &mut Connection) {
server server
.object_server()
.at( .at(
&ObjectPath::from_str_unchecked("/org/asuslinux/RogBios"), &ObjectPath::from_str_unchecked("/org/asuslinux/RogBios"),
self, self,
) )
.await
.map_err(|err| { .map_err(|err| {
warn!("CtrlRogBios: add_to_server {}", err); warn!("CtrlRogBios: add_to_server {}", err);
err err

View File

@@ -1,8 +1,10 @@
use async_trait::async_trait;
use log::warn; use log::warn;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use zbus::dbus_interface; use zbus::dbus_interface;
use zbus::Connection;
use zvariant::ObjectPath; use zvariant::ObjectPath;
use zvariant_derive::Type; use zvariant::Type;
use crate::{ use crate::{
ctrl_anime::CtrlAnime, ctrl_aura::controller::CtrlKbdLed, ctrl_charge::CtrlCharge, ctrl_anime::CtrlAnime, ctrl_aura::controller::CtrlKbdLed, ctrl_charge::CtrlCharge,
@@ -30,13 +32,16 @@ impl SupportedFunctions {
} }
} }
#[async_trait]
impl crate::ZbusAdd for SupportedFunctions { impl crate::ZbusAdd for SupportedFunctions {
fn add_to_server(self, server: &mut zbus::ObjectServer) { async fn add_to_server(self, server: &mut Connection) {
server server
.object_server()
.at( .at(
&ObjectPath::from_str_unchecked("/org/asuslinux/Supported"), &ObjectPath::from_str_unchecked("/org/asuslinux/Supported"),
self, self,
) )
.await
.map_err(|err| { .map_err(|err| {
warn!("SupportedFunctions: add_to_server {}", err); warn!("SupportedFunctions: add_to_server {}", err);
err err

View File

@@ -1,12 +1,11 @@
use std::env;
use std::error::Error; use std::error::Error;
use std::io::Write; use std::io::Write;
use std::sync::Arc; use std::sync::{Arc, Mutex};
use std::sync::Mutex;
use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use std::{env, thread};
use ::zbus::{fdo, Connection, ObjectServer}; use ::zbus::Connection;
use futures::executor::ThreadPool;
use log::LevelFilter; use log::LevelFilter;
use log::{error, info, warn}; use log::{error, info, warn};
@@ -19,9 +18,7 @@ use daemon::ctrl_aura::controller::{
}; };
use daemon::ctrl_charge::CtrlCharge; use daemon::ctrl_charge::CtrlCharge;
use daemon::ctrl_profiles::config::ProfileConfig; use daemon::ctrl_profiles::config::ProfileConfig;
use daemon::ctrl_profiles::controller::CtrlProfileTask;
use daemon::ctrl_rog_bios::CtrlRogBios; use daemon::ctrl_rog_bios::CtrlRogBios;
use daemon::error::RogError;
use daemon::{ use daemon::{
config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported, config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
}; };
@@ -64,25 +61,25 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
info!(" rog-profiles v{}", rog_profiles::VERSION); info!(" rog-profiles v{}", rog_profiles::VERSION);
info!("rog-supported v{}", rog_supported::VERSION); info!("rog-supported v{}", rog_supported::VERSION);
start_daemon()?; let mut pool = ThreadPool::new()?;
futures::executor::block_on(start_daemon(&mut pool))?;
Ok(()) Ok(())
} }
/// The actual main loop for the daemon /// The actual main loop for the daemon
fn start_daemon() -> Result<(), Box<dyn Error>> { async fn start_daemon(thread_pool: &mut ThreadPool) -> Result<(), Box<dyn Error>> {
let supported = SupportedFunctions::get_supported(); let supported = SupportedFunctions::get_supported();
print_board_info(); print_board_info();
println!("{}", serde_json::to_string_pretty(&supported)?); println!("{}", serde_json::to_string_pretty(&supported)?);
// Start zbus server // Start zbus server
let connection = Connection::new_system()?; let mut connection = Connection::system().await?;
let fdo_connection = fdo::DBusProxy::new(&connection)?;
let mut object_server = ObjectServer::new(&connection);
let config = Config::load(); let config = Config::load();
let config = Arc::new(Mutex::new(config)); let config = Arc::new(Mutex::new(config));
supported.add_to_server(&mut object_server); supported.add_to_server(&mut connection).await;
match CtrlRogBios::new(config.clone()) { match CtrlRogBios::new(config.clone()) {
Ok(mut ctrl) => { Ok(mut ctrl) => {
@@ -90,7 +87,7 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
ctrl.reload() ctrl.reload()
.unwrap_or_else(|err| warn!("Battery charge limit: {}", err)); .unwrap_or_else(|err| warn!("Battery charge limit: {}", err));
// Then register to dbus server // Then register to dbus server
ctrl.add_to_server(&mut object_server); ctrl.add_to_server(&mut connection).await;
} }
Err(err) => { Err(err) => {
error!("rog_bios_control: {}", err); error!("rog_bios_control: {}", err);
@@ -103,7 +100,7 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
ctrl.reload() ctrl.reload()
.unwrap_or_else(|err| warn!("Battery charge limit: {}", err)); .unwrap_or_else(|err| warn!("Battery charge limit: {}", err));
// Then register to dbus server // Then register to dbus server
ctrl.add_to_server(&mut object_server); ctrl.add_to_server(&mut connection).await;
} }
Err(err) => { Err(err) => {
error!("charge_control: {}", err); error!("charge_control: {}", err);
@@ -118,17 +115,9 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
.unwrap_or_else(|err| warn!("Profile control: {}", err)); .unwrap_or_else(|err| warn!("Profile control: {}", err));
let tmp = Arc::new(Mutex::new(ctrl)); let tmp = Arc::new(Mutex::new(ctrl));
ProfileZbus::new(tmp.clone()).add_to_server(&mut object_server); ProfileZbus::new(tmp.clone())
.add_to_server(&mut connection)
let task = CtrlProfileTask::new(tmp); .await;
thread::Builder::new().name("profile tasks".into()).spawn(
move || -> Result<(), RogError> {
loop {
task.do_task()?;
sleep(Duration::from_millis(100));
}
},
)?;
} }
Err(err) => { Err(err) => {
error!("Profile control: {}", err); error!("Profile control: {}", err);
@@ -148,16 +137,12 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
.unwrap_or_else(|err| warn!("AniMe: {}", err)); .unwrap_or_else(|err| warn!("AniMe: {}", err));
let zbus = CtrlAnimeZbus(inner.clone()); let zbus = CtrlAnimeZbus(inner.clone());
zbus.add_to_server(&mut object_server); zbus.add_to_server(&mut connection).await;
let task = CtrlAnimeTask::new(inner); let task = CtrlAnimeTask::new(inner);
thread::Builder::new().name("anime tasks".into()).spawn( thread_pool.spawn_ok(async move {
move || -> Result<(), RogError> { task.do_task().await.ok();
loop { });
task.do_task()?;
}
},
)?;
} }
Err(err) => { Err(err) => {
error!("AniMe control: {}", err); error!("AniMe control: {}", err);
@@ -175,16 +160,14 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
.reload() .reload()
.unwrap_or_else(|err| warn!("Keyboard LED control: {}", err)); .unwrap_or_else(|err| warn!("Keyboard LED control: {}", err));
CtrlKbdLedZbus::new(inner.clone()).add_to_server(&mut object_server); CtrlKbdLedZbus::new(inner.clone())
.add_to_server(&mut connection)
.await;
let task = CtrlKbdLedTask::new(inner); let task = CtrlKbdLedTask::new(inner);
thread::Builder::new().name("keyboard tasks".into()).spawn( thread_pool.spawn_ok(async move {
move || -> Result<(), RogError> { task.do_task().await.ok();
loop { });
task.do_task()?;
}
},
)?;
} }
Err(err) => { Err(err) => {
error!("Keyboard control: {}", err); error!("Keyboard control: {}", err);
@@ -192,12 +175,11 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
} }
// Request dbus name after finishing initalizing all functions // Request dbus name after finishing initalizing all functions
fdo_connection.request_name(DBUS_NAME, fdo::RequestNameFlags::ReplaceExisting.into())?; connection.request_name(DBUS_NAME).await?;
// Loop to check errors and iterate zbus server // Loop to check errors and iterate zbus server
loop { loop {
if let Err(err) = object_server.try_handle_next() { // Nothing to do here really
error!("{}", err); std::thread::sleep(Duration::from_millis(1));
}
} }
} }

View File

@@ -30,8 +30,9 @@ pub mod ctrl_supported;
pub mod error; pub mod error;
use crate::error::RogError; use crate::error::RogError;
use async_trait::async_trait;
use config::Config; use config::Config;
use zbus::ObjectServer; use zbus::Connection;
pub static VERSION: &str = env!("CARGO_PKG_VERSION"); pub static VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -39,12 +40,14 @@ pub trait Reloadable {
fn reload(&mut self) -> Result<(), RogError>; fn reload(&mut self) -> Result<(), RogError>;
} }
#[async_trait]
pub trait ZbusAdd { pub trait ZbusAdd {
fn add_to_server(self, server: &mut ObjectServer); async fn add_to_server(self, server: &mut Connection);
} }
#[async_trait]
pub trait CtrlTask { pub trait CtrlTask {
fn do_task(&self) -> Result<(), RogError>; async fn do_task(&self) -> Result<(), RogError>;
} }
pub trait CtrlTaskComplex { pub trait CtrlTaskComplex {

View File

@@ -14,7 +14,7 @@ exclude = ["data"]
[features] [features]
default = ["dbus"] default = ["dbus"]
dbus = ["zvariant", "zvariant_derive"] dbus = ["zvariant"]
[dependencies] [dependencies]
png_pong = "^0.8.0" png_pong = "^0.8.0"
@@ -26,5 +26,5 @@ serde_derive = "^1.0"
glam = { version = "0.14.0", features = ["serde"] } glam = { version = "0.14.0", features = ["serde"] }
zvariant = { version = "^2.6", optional = true } zvariant = { version = "^3.0", optional = true }
zvariant_derive = { version = "^2.6", optional = true } #zvariant_derive = { version = "^3.0", optional = true }

View File

@@ -9,7 +9,7 @@ use std::{
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "dbus")] #[cfg(feature = "dbus")]
use zvariant_derive::Type; use zvariant::Type;
use crate::{error::AnimeError, AnimTime, AnimeGif}; use crate::{error::AnimeError, AnimTime, AnimeGif};
@@ -27,7 +27,6 @@ const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
#[cfg_attr(feature = "dbus", derive(Type))] #[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Debug, PartialEq, Copy, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Copy, Clone, Deserialize, Serialize)]
pub struct AnimePowerStates { pub struct AnimePowerStates {
pub enabled: bool, pub enabled: bool,
pub boot_anim_enabled: bool, pub boot_anim_enabled: bool,

View File

@@ -14,11 +14,10 @@ exclude = ["data"]
[features] [features]
default = ["dbus"] default = ["dbus"]
dbus = ["zvariant", "zvariant_derive"] dbus = ["zvariant"]
[dependencies] [dependencies]
serde = "^1.0" serde = "^1.0"
serde_derive = "^1.0" serde_derive = "^1.0"
zvariant = { version = "^2.6", optional = true } zvariant = { version = "^3.0", optional = true }
zvariant_derive = { version = "^2.6", optional = true }

View File

@@ -7,7 +7,7 @@ pub const LED_INIT5: [u8; 6] = [0x5e, 0x05, 0x20, 0x31, 0, 0x08];
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::str::FromStr; use std::str::FromStr;
#[cfg(feature = "dbus")] #[cfg(feature = "dbus")]
use zvariant_derive::Type; use zvariant::Type;
use crate::{error::Error, LED_MSG_LEN}; use crate::{error::Error, LED_MSG_LEN};

View File

@@ -14,6 +14,6 @@ rog_anime = { path = "../rog-anime" }
rog_aura = { path = "../rog-aura" } rog_aura = { path = "../rog-aura" }
rog_profiles = { path = "../rog-profiles" } rog_profiles = { path = "../rog-profiles" }
rog_supported = { path = "../rog-supported" } rog_supported = { path = "../rog-supported" }
zbus = "^1.9" zbus = "^2.0"
zbus_macros = "^1.9" zbus_macros = "^2.0"
zvariant = "^2.8" zvariant = "^3.0"

View File

@@ -9,51 +9,109 @@ pub mod zbus_profile;
pub mod zbus_rogbios; pub mod zbus_rogbios;
pub mod zbus_supported; pub mod zbus_supported;
use rog_anime::AnimePowerStates; // use rog_anime::AnimePowerStates;
use rog_aura::{AuraEffect, LedPowerStates}; // use rog_aura::{AuraEffect, LedPowerStates};
use rog_profiles::Profile; // use rog_profiles::Profile;
use std::sync::mpsc::{channel, Receiver}; // use std::sync::mpsc::{channel, Receiver};
use zbus::{Connection, Result, SignalReceiver}; use zbus::{blocking, Connection, Result};
pub static VERSION: &str = env!("CARGO_PKG_VERSION"); pub static VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct DbusProxiesBlocking<'a> {
anime: zbus_anime::AnimeProxyBlocking<'a>,
charge: zbus_charge::ChargeProxyBlocking<'a>,
led: zbus_led::LedProxyBlocking<'a>,
profile: zbus_profile::ProfileProxyBlocking<'a>,
rog_bios: zbus_rogbios::RogBiosProxyBlocking<'a>,
supported: zbus_supported::SupportedProxyBlocking<'a>,
}
impl<'a> DbusProxiesBlocking<'a> {
#[inline]
pub fn new() -> Result<(Self, blocking::Connection)> {
let conn = blocking::Connection::system()?;
Ok((
DbusProxiesBlocking {
anime: zbus_anime::AnimeProxyBlocking::new(&conn)?,
led: zbus_led::LedProxyBlocking::new(&conn)?,
charge: zbus_charge::ChargeProxyBlocking::new(&conn)?,
profile: zbus_profile::ProfileProxyBlocking::new(&conn)?,
rog_bios: zbus_rogbios::RogBiosProxyBlocking::new(&conn)?,
supported: zbus_supported::SupportedProxyBlocking::new(&conn)?,
},
conn,
))
}
pub fn anime(&self) -> &zbus_anime::AnimeProxyBlocking<'a> {
&self.anime
}
pub fn charge(&self) -> &zbus_charge::ChargeProxyBlocking<'a> {
&self.charge
}
pub fn led(&self) -> &zbus_led::LedProxyBlocking<'a> {
&self.led
}
pub fn profile(&self) -> &zbus_profile::ProfileProxyBlocking<'a> {
&self.profile
}
pub fn rog_bios(&self) -> &zbus_rogbios::RogBiosProxyBlocking<'a> {
&self.rog_bios
}
pub fn supported(&self) -> &zbus_supported::SupportedProxyBlocking<'a> {
&self.supported
}
}
/// This is the main way to communicate with the DBUS interface
pub struct RogDbusClientBlocking<'a> {
proxies: DbusProxiesBlocking<'a>,
}
impl<'a> RogDbusClientBlocking<'a> {
#[inline]
pub fn new() -> Result<(Self, blocking::Connection)> {
let (proxies, conn) = DbusProxiesBlocking::new()?;
Ok((RogDbusClientBlocking { proxies }, conn))
}
pub fn proxies(&self) -> &DbusProxiesBlocking {
&self.proxies
}
}
pub struct DbusProxies<'a> { pub struct DbusProxies<'a> {
anime: zbus_anime::AnimeProxy<'a>, anime: zbus_anime::AnimeProxy<'a>,
charge: zbus_charge::ChargeProxy<'a>, charge: zbus_charge::ChargeProxy<'a>,
led: zbus_led::LedProxy<'a>, led: zbus_led::LedProxy<'a>,
profile: zbus_profile::ProfileProxy<'a>, profile: zbus_profile::ProfileProxy<'a>,
rog_bios: zbus_rogbios::RogBiosProxy<'a>, rog_bios: zbus_rogbios::RogBiosProxy<'a>,
supported: zbus_supported::SupportProxy<'a>, supported: zbus_supported::SupportedProxy<'a>,
} }
impl<'a> DbusProxies<'a> { impl<'a> DbusProxies<'a> {
#[inline] #[inline]
pub fn new() -> Result<(Self, Connection)> { pub async fn new() -> Result<(DbusProxies<'a>, Connection)> {
let conn = Connection::new_system()?; let conn = Connection::system().await?;
Ok(( Ok((
DbusProxies { DbusProxies {
anime: zbus_anime::AnimeProxy::new(&conn)?, anime: zbus_anime::AnimeProxy::new(&conn).await?,
led: zbus_led::LedProxy::new(&conn)?, led: zbus_led::LedProxy::new(&conn).await?,
charge: zbus_charge::ChargeProxy::new(&conn)?, charge: zbus_charge::ChargeProxy::new(&conn).await?,
profile: zbus_profile::ProfileProxy::new(&conn)?, profile: zbus_profile::ProfileProxy::new(&conn).await?,
rog_bios: zbus_rogbios::RogBiosProxy::new(&conn)?, rog_bios: zbus_rogbios::RogBiosProxy::new(&conn).await?,
supported: zbus_supported::SupportProxy::new(&conn)?, supported: zbus_supported::SupportedProxy::new(&conn).await?,
}, },
conn, conn,
)) ))
} }
pub fn setup_recv(&'a self, conn: Connection) -> SignalReceiver<'a, 'a> {
let mut recv = SignalReceiver::new(conn);
recv.receive_for(self.anime.proxy());
recv.receive_for(self.led.proxy());
recv.receive_for(self.charge.proxy());
recv.receive_for(self.profile.proxy());
recv.receive_for(self.rog_bios.proxy());
recv.receive_for(self.supported.proxy());
recv
}
pub fn anime(&self) -> &zbus_anime::AnimeProxy<'a> { pub fn anime(&self) -> &zbus_anime::AnimeProxy<'a> {
&self.anime &self.anime
} }
@@ -74,102 +132,24 @@ impl<'a> DbusProxies<'a> {
&self.rog_bios &self.rog_bios
} }
pub fn supported(&self) -> &zbus_supported::SupportProxy<'a> { pub fn supported(&self) -> &zbus_supported::SupportedProxy<'a> {
&self.supported &self.supported
} }
} }
// Signals separated out
pub struct Signals {
pub profile: Receiver<Profile>,
pub led_mode: Receiver<AuraEffect>,
pub side_leds: Receiver<bool>,
pub led_power_state: Receiver<LedPowerStates>,
pub anime_power_state: Receiver<AnimePowerStates>,
pub charge: Receiver<u8>,
pub bios_gsync: Receiver<bool>,
pub bios_sound: Receiver<bool>,
}
impl Signals {
#[inline]
pub fn new(proxies: &DbusProxies) -> Result<Self> {
Ok(Signals {
profile: {
let (tx, rx) = channel();
proxies.profile.connect_notify_profile(tx)?;
rx
},
charge: {
let (tx, rx) = channel();
proxies.charge.connect_notify_charge(tx)?;
rx
},
led_mode: {
let (tx, rx) = channel();
proxies.led.connect_notify_led(tx)?;
rx
},
side_leds: {
let (tx, rx) = channel();
proxies.led.connect_notify_side_leds(tx)?;
rx
},
led_power_state: {
let (tx, rx) = channel();
proxies.led.connect_notify_power_states(tx)?;
rx
},
anime_power_state: {
let (tx, rx) = channel();
proxies.anime.connect_notify_power_states(tx)?;
rx
},
bios_gsync: {
let (tx, rx) = channel();
proxies.rog_bios.connect_notify_dedicated_graphic_mode(tx)?;
rx
},
bios_sound: {
let (tx, rx) = channel();
proxies.rog_bios.connect_notify_post_boot_sound(tx)?;
rx
},
})
}
}
/// This is the main way to communicate with the DBUS interface /// This is the main way to communicate with the DBUS interface
pub struct RogDbusClient<'a> { pub struct RogDbusClient<'a> {
proxies: DbusProxies<'a>, proxies: DbusProxies<'a>,
signals: Signals,
} }
impl<'a> RogDbusClient<'a> { impl<'a> RogDbusClient<'a> {
#[inline] #[inline]
pub fn new() -> Result<(Self, Connection)> { pub async fn new() -> Result<(RogDbusClient<'a>, Connection)> {
let (proxies, conn) = DbusProxies::new()?; let (proxies, conn) = DbusProxies::new().await?;
let signals = Signals::new(&proxies)?; Ok((RogDbusClient { proxies }, conn))
Ok((RogDbusClient { proxies, signals }, conn))
} }
pub fn proxies(&self) -> &DbusProxies { pub fn proxies(&self) -> &DbusProxies {
&self.proxies &self.proxies
} }
pub fn signals(&self) -> &Signals {
&self.signals
}
pub fn setup_recv(&'a self, conn: Connection) -> SignalReceiver<'a, 'a> {
let mut recv = SignalReceiver::new(conn);
recv.receive_for(self.proxies.anime.proxy());
recv.receive_for(self.proxies.led.proxy());
recv.receive_for(self.proxies.charge.proxy());
recv.receive_for(self.proxies.profile.proxy());
recv.receive_for(self.proxies.rog_bios.proxy());
recv.receive_for(self.proxies.supported.proxy());
recv
}
} }

View File

@@ -1,12 +1,11 @@
use rog_anime::{AnimeDataBuffer, AnimePowerStates}; use rog_anime::{AnimeDataBuffer, AnimePowerStates};
use std::sync::mpsc::Sender; use zbus_macros::dbus_proxy;
use zbus::{dbus_proxy, Connection, Result};
#[dbus_proxy( #[dbus_proxy(
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Anime" default_path = "/org/asuslinux/Anime"
)] )]
trait Daemon { trait Anime {
/// Set whether the AniMe will show boot, suspend, or off animations /// Set whether the AniMe will show boot, suspend, or off animations
fn set_boot_on_off(&self, status: bool) -> zbus::Result<()>; fn set_boot_on_off(&self, status: bool) -> zbus::Result<()>;
@@ -17,7 +16,7 @@ trait Daemon {
fn set_on_off(&self, status: bool) -> zbus::Result<()>; fn set_on_off(&self, status: bool) -> zbus::Result<()>;
/// Writes a data stream of length. Will force system thread to exit until it is restarted /// Writes a data stream of length. Will force system thread to exit until it is restarted
fn write(&self, input: &[u8]) -> zbus::Result<()>; fn write(&self, input: AnimeDataBuffer) -> zbus::Result<()>;
/// Get status of if the AniMe LEDs are on /// Get status of if the AniMe LEDs are on
#[dbus_proxy(property)] #[dbus_proxy(property)]
@@ -29,66 +28,5 @@ trait Daemon {
/// Notify listeners of the status of AniMe LED power and factory system-status animations /// Notify listeners of the status of AniMe LED power and factory system-status animations
#[dbus_proxy(signal)] #[dbus_proxy(signal)]
fn notify_power_states(&self, data: AnimePowerStates) -> zbus::Result<()>; fn power_states(&self, data: AnimePowerStates) -> zbus::Result<()>;
}
pub struct AnimeProxy<'a>(DaemonProxy<'a>);
impl<'a> AnimeProxy<'a> {
#[inline]
pub fn new(conn: &Connection) -> Result<Self> {
Ok(AnimeProxy(DaemonProxy::new(conn)?))
}
#[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> {
&self.0
}
/// Set whether the AniMe is displaying images/data
#[inline]
pub fn set_on_off(&self, on: bool) -> Result<()> {
self.0.set_on_off(on)
}
/// Set the global AniMe brightness
pub fn set_brightness(&self, bright: f32) -> Result<()> {
self.0.set_brightness(bright)
}
/// Set whether the AniMe will show boot, suspend, or off animations
#[inline]
pub fn set_boot_on_off(&self, on: bool) -> Result<()> {
self.0.set_boot_on_off(on)
}
/// Writes a data stream of length. Will force system thread to exit until it is restarted
#[inline]
pub fn write(&self, input: AnimeDataBuffer) -> Result<()> {
self.0.write(input.get())
}
/// Get status of if the AniMe LEDs are on
#[inline]
pub fn awake_enabled(&self) -> Result<bool> {
self.0.awake_enabled()
}
/// Get the status of if factory system-status animations are enabled
#[inline]
pub fn boot_enabled(&self) -> Result<bool> {
self.0.boot_enabled()
}
#[inline]
pub fn connect_notify_power_states(
&self,
send: Sender<AnimePowerStates>,
) -> zbus::fdo::Result<()> {
self.0.connect_notify_power_states(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
} }

View File

@@ -19,15 +19,13 @@
//! //!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. //! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use std::sync::mpsc::Sender; use zbus_macros::dbus_proxy;
use zbus::{dbus_proxy, Connection, Result};
#[dbus_proxy( #[dbus_proxy(
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Charge" default_path = "/org/asuslinux/Charge"
)] )]
trait Daemon { trait Charge {
/// Limit method /// Limit method
fn limit(&self) -> zbus::Result<i16>; fn limit(&self) -> zbus::Result<i16>;
@@ -36,38 +34,5 @@ trait Daemon {
/// NotifyCharge signal /// NotifyCharge signal
#[dbus_proxy(signal)] #[dbus_proxy(signal)]
fn notify_charge(&self, limit: u8) -> zbus::Result<()>; fn notify_charge(&self, limit: u8) -> zbus::Result<u8>;
}
pub struct ChargeProxy<'a>(DaemonProxy<'a>);
impl<'a> ChargeProxy<'a> {
#[inline]
pub fn new(conn: &Connection) -> Result<Self> {
Ok(ChargeProxy(DaemonProxy::new(conn)?))
}
#[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> {
&self.0
}
#[inline]
pub fn write_limit(&self, level: u8) -> Result<()> {
self.0.set_limit(level)
}
#[inline]
pub fn get_limit(&self) -> Result<i16> {
self.0.limit()
}
#[inline]
pub fn connect_notify_charge(&self, send: Sender<u8>) -> zbus::fdo::Result<()> {
self.0.connect_notify_charge(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
} }

View File

@@ -19,9 +19,8 @@
//! //!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. //! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use std::sync::mpsc::Sender; use zbus::{blocking::Connection, Result};
use zbus_macros::dbus_proxy;
use zbus::{dbus_proxy, Connection, Result};
use rog_aura::{AuraEffect, KeyColourArray, LedBrightness, LedPowerStates}; use rog_aura::{AuraEffect, KeyColourArray, LedBrightness, LedPowerStates};
@@ -31,7 +30,7 @@ const BLOCKING_TIME: u64 = 40; // 100ms = 10 FPS, max 50ms = 20 FPS, 40ms = 25 F
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Led" default_path = "/org/asuslinux/Led"
)] )]
trait Daemon { trait Led {
/// NextLedMode method /// NextLedMode method
fn next_led_mode(&self) -> zbus::Result<()>; fn next_led_mode(&self) -> zbus::Result<()>;
@@ -91,91 +90,19 @@ trait Daemon {
fn side_leds_enabled(&self) -> zbus::Result<bool>; fn side_leds_enabled(&self) -> zbus::Result<bool>;
} }
pub struct LedProxy<'a>(DaemonProxy<'a>); pub struct LedProxyPerkey<'a>(LedProxyBlocking<'a>);
impl<'a> LedProxy<'a> { impl<'a> LedProxyPerkey<'a> {
#[inline] #[inline]
pub fn new(conn: &Connection) -> Result<Self> { pub fn new(conn: &Connection) -> Result<Self> {
Ok(LedProxy(DaemonProxy::new(conn)?)) Ok(LedProxyPerkey(LedProxyBlocking::new(conn)?))
} }
#[inline] #[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> { pub fn proxy(&self) -> &LedProxyBlocking<'a> {
&self.0 &self.0
} }
#[inline]
pub fn get_led_brightness(&self) -> Result<i16> {
self.0.led_brightness()
}
#[inline]
pub fn set_led_brightness(&self, level: LedBrightness) -> Result<()> {
self.0.set_brightness(level)?;
Ok(())
}
/// Set the keyboard LED to enabled while the device is awake
#[inline]
pub fn set_awake_enabled(&self, enabled: bool) -> Result<()> {
self.0.set_awake_enabled(enabled)?;
Ok(())
}
/// Set the keyboard LED suspend animation to enabled while the device is suspended
#[inline]
pub fn set_sleep_enabled(&self, enabled: bool) -> Result<()> {
self.0.set_sleep_enabled(enabled)?;
Ok(())
}
/// Set the keyboard side LEDs to enabled
#[inline]
pub fn set_side_leds_enabled(&self, enabled: bool) -> Result<()> {
self.0.set_side_leds_enabled(enabled)?;
Ok(())
}
#[inline]
pub fn next_led_mode(&self) -> Result<()> {
self.0.next_led_mode()
}
#[inline]
pub fn prev_led_mode(&self) -> Result<()> {
self.0.prev_led_mode()
}
#[inline]
pub fn next_led_brightness(&self) -> Result<()> {
self.0.next_led_brightness()
}
#[inline]
pub fn prev_led_brightness(&self) -> Result<()> {
self.0.prev_led_brightness()
}
#[inline]
pub fn set_led_mode(&self, mode: &AuraEffect) -> Result<()> {
self.0.set_led_mode(mode)
}
#[inline]
pub fn awake_enabled(&self) -> Result<bool> {
self.0.awake_enabled()
}
#[inline]
pub fn sleep_enabled(&self) -> Result<bool> {
self.0.sleep_enabled()
}
#[inline]
pub fn side_leds_enabled(&self) -> Result<bool> {
self.0.side_leds_enabled()
}
/// Write a single colour block. /// Write a single colour block.
/// ///
/// Intentionally blocks for 10ms after sending to allow the block to /// Intentionally blocks for 10ms after sending to allow the block to
@@ -207,34 +134,4 @@ impl<'a> LedProxy<'a> {
// self.0.set_led_mode(&serde_json::to_string(&mode).unwrap()) // self.0.set_led_mode(&serde_json::to_string(&mode).unwrap())
Ok(()) Ok(())
} }
#[inline]
pub fn connect_notify_led(&self, send: Sender<AuraEffect>) -> zbus::fdo::Result<()> {
self.0.connect_notify_led(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
#[inline]
pub fn connect_notify_side_leds(&self, send: Sender<bool>) -> zbus::fdo::Result<()> {
self.0.connect_notify_side_leds(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
#[inline]
pub fn connect_notify_power_states(
&self,
send: Sender<LedPowerStates>,
) -> zbus::fdo::Result<()> {
self.0.connect_notify_power_states(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
} }

View File

@@ -19,19 +19,17 @@
//! //!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. //! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use std::sync::mpsc::Sender;
use rog_profiles::{ use rog_profiles::{
fan_curve_set::{CurveData, FanCurveSet}, fan_curve_set::{CurveData, FanCurveSet},
Profile, Profile,
}; };
use zbus::{dbus_proxy, Connection, Result}; use zbus_macros::dbus_proxy;
#[dbus_proxy( #[dbus_proxy(
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Profile" default_path = "/org/asuslinux/Profile"
)] )]
trait Daemon { trait Profile {
/// Get the fan-curve data for the currently active Profile /// Get the fan-curve data for the currently active Profile
fn fan_curve_data(&self, profile: Profile) -> zbus::Result<FanCurveSet>; fn fan_curve_data(&self, profile: Profile) -> zbus::Result<FanCurveSet>;
@@ -66,73 +64,5 @@ trait Daemon {
/// NotifyProfile signal /// NotifyProfile signal
#[dbus_proxy(signal)] #[dbus_proxy(signal)]
fn notify_profile(&self, profile: Profile) -> zbus::Result<()>; fn notify_profile(&self, profile: Profile) -> zbus::Result<Profile>;
}
pub struct ProfileProxy<'a>(DaemonProxy<'a>);
impl<'a> ProfileProxy<'a> {
#[inline]
pub fn new(conn: &Connection) -> Result<Self> {
Ok(ProfileProxy(DaemonProxy::new(conn)?))
}
#[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> {
&self.0
}
#[inline]
pub fn active_profile(&self) -> zbus::Result<Profile> {
self.0.active_profile()
}
#[inline]
pub fn enabled_fan_profiles(&self) -> zbus::Result<Vec<Profile>> {
self.0.enabled_fan_profiles()
}
#[inline]
pub fn fan_curve_data(&self, profile: Profile) -> zbus::Result<FanCurveSet> {
self.0.fan_curve_data(profile)
}
#[inline]
pub fn next_profile(&self) -> Result<()> {
self.0.next_profile()
}
#[inline]
pub fn profiles(&self) -> Result<Vec<Profile>> {
self.0.profiles()
}
#[inline]
pub fn set_active_profile(&self, profile: Profile) -> zbus::Result<()> {
self.0.set_active_profile(profile)
}
#[inline]
pub fn set_fan_curve_enabled(&self, profile: Profile, enabled: bool) -> zbus::Result<()> {
self.0.set_fan_curve_enabled(profile, enabled)
}
#[inline]
pub fn set_fan_curve(&self, curve: CurveData, profile: Profile) -> zbus::Result<()> {
self.0.set_fan_curve(profile, curve)
}
#[inline]
pub fn set_active_curve_to_defaults(&self) -> zbus::Result<()> {
self.0.set_active_curve_to_defaults()
}
#[inline]
pub fn connect_notify_profile(&self, send: Sender<Profile>) -> zbus::fdo::Result<()> {
self.0.connect_notify_profile(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
} }

View File

@@ -19,15 +19,13 @@
//! //!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. //! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use std::sync::mpsc::Sender; use zbus_macros::dbus_proxy;
use zbus::{dbus_proxy, Connection, Result};
#[dbus_proxy( #[dbus_proxy(
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/RogBios" default_path = "/org/asuslinux/RogBios"
)] )]
trait Daemon { trait RogBios {
/// DedicatedGraphicMode method /// DedicatedGraphicMode method
fn dedicated_graphic_mode(&self) -> zbus::Result<i16>; fn dedicated_graphic_mode(&self) -> zbus::Result<i16>;
@@ -46,60 +44,5 @@ trait Daemon {
/// NotifyPostBootSound signal /// NotifyPostBootSound signal
#[dbus_proxy(signal)] #[dbus_proxy(signal)]
fn notify_post_boot_sound(&self, dedicated: bool) -> zbus::Result<()>; fn notify_post_boot_sound(&self, sound: bool) -> zbus::Result<()>;
}
pub struct RogBiosProxy<'a>(DaemonProxy<'a>);
impl<'a> RogBiosProxy<'a> {
#[inline]
pub fn new(conn: &Connection) -> Result<Self> {
Ok(RogBiosProxy(DaemonProxy::new(conn)?))
}
#[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> {
&self.0
}
#[inline]
pub fn get_dedicated_gfx(&self) -> Result<i16> {
self.0.dedicated_graphic_mode()
}
#[inline]
pub fn set_dedicated_gfx(&self, on: bool) -> Result<()> {
self.0.set_dedicated_graphic_mode(on)
}
#[inline]
pub fn get_post_sound(&self) -> Result<i16> {
self.0.post_boot_sound()
}
#[inline]
pub fn set_post_sound(&self, on: bool) -> Result<()> {
self.0.set_post_boot_sound(on)
}
#[inline]
pub fn connect_notify_dedicated_graphic_mode(
&self,
send: Sender<bool>,
) -> zbus::fdo::Result<()> {
self.0.connect_notify_dedicated_graphic_mode(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
#[inline]
pub fn connect_notify_post_boot_sound(&self, send: Sender<bool>) -> zbus::fdo::Result<()> {
self.0.connect_notify_post_boot_sound(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
} }

View File

@@ -20,32 +20,13 @@
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. //! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use rog_supported::SupportedFunctions; use rog_supported::SupportedFunctions;
use zbus::{dbus_proxy, Connection, Result}; use zbus_macros::dbus_proxy;
#[dbus_proxy( #[dbus_proxy(
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Supported" default_path = "/org/asuslinux/Supported"
)] )]
trait Daemon { trait Supported {
/// SupportedFunctions method /// SupportedFunctions method
fn supported_functions(&self) -> zbus::Result<SupportedFunctions>; fn supported_functions(&self) -> zbus::Result<SupportedFunctions>;
} }
pub struct SupportProxy<'a>(DaemonProxy<'a>);
impl<'a> SupportProxy<'a> {
#[inline]
pub fn new(conn: &Connection) -> Result<Self> {
Ok(SupportProxy(DaemonProxy::new(conn)?))
}
#[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> {
&self.0
}
#[inline]
pub fn get_supported_functions(&self) -> Result<SupportedFunctions> {
self.0.supported_functions()
}
}

View File

@@ -13,5 +13,5 @@ udev = "^0.6"
serde = "^1.0" serde = "^1.0"
serde_derive = "^1.0" serde_derive = "^1.0"
zvariant = { version = "^2.6", optional = true } zvariant = { version = "^3.0", optional = true }
zvariant_derive = { version = "^2.6", optional = true } zvariant_derive = { version = "^3.0", optional = true }

View File

@@ -13,5 +13,5 @@ edition = "2018"
rog_aura = { path = "../rog-aura" } rog_aura = { path = "../rog-aura" }
serde = "^1.0" serde = "^1.0"
serde_derive = "^1.0" serde_derive = "^1.0"
zvariant = "^2.6" zvariant = "^3.0"
zvariant_derive = "^2.6" zvariant_derive = "^3.0"