ROGCC: Use tokio instead of smol

This commit is contained in:
Luke D. Jones
2022-11-07 09:00:46 +13:00
parent 37553a5fdd
commit efc752cce6
6 changed files with 78 additions and 91 deletions

8
Cargo.lock generated
View File

@@ -2062,9 +2062,9 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"smol",
"supergfxctl", "supergfxctl",
"tempfile", "tempfile",
"tokio",
"toml", "toml",
"zbus 3.4.0", "zbus 3.4.0",
] ]
@@ -2436,7 +2436,7 @@ dependencies = [
[[package]] [[package]]
name = "supergfxctl" name = "supergfxctl"
version = "5.0.2" version = "5.0.2"
source = "git+https://gitlab.com/asus-linux/supergfxctl.git#f8f9a5a843e6960a13a5fd2c02995c7c979cbfba" source = "git+https://gitlab.com/asus-linux/supergfxctl.git#e551271c53231d650123246cab43ccd42ffe926a"
dependencies = [ dependencies = [
"env_logger", "env_logger",
"gumdrop", "gumdrop",
@@ -2599,7 +2599,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes",
"libc", "libc",
"memchr",
"mio", "mio",
"num_cpus", "num_cpus",
"pin-project-lite", "pin-project-lite",
@@ -3304,6 +3306,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"hex", "hex",
"lazy_static",
"nix 0.25.0", "nix 0.25.0",
"once_cell", "once_cell",
"ordered-stream 0.1.1", "ordered-stream 0.1.1",
@@ -3312,6 +3315,7 @@ dependencies = [
"serde_repr", "serde_repr",
"sha1 0.10.5", "sha1 0.10.5",
"static_assertions", "static_assertions",
"tokio",
"tracing", "tracing",
"uds_windows", "uds_windows",
"winapi", "winapi",

View File

@@ -21,15 +21,13 @@ rog_platform = { path = "../rog-platform" }
supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git" } supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git" }
#supergfxctl = { path = "../../supergfxctl" } #supergfxctl = { path = "../../supergfxctl" }
smol.workspace = true tokio.workspace = true
serde.workspace = true serde.workspace = true
toml.workspace = true toml.workspace = true
serde_json.workspace = true serde_json.workspace = true
serde_derive.workspace = true serde_derive.workspace = true
zbus.workspace = true zbus.workspace = true
dirs.workspace = true dirs.workspace = true
notify-rust.workspace = true notify-rust.workspace = true
nix = "^0.20.0" nix = "^0.20.0"

View File

@@ -103,7 +103,7 @@ impl<'a> RogApp<'a> {
} }
impl<'a> eframe::App for RogApp<'a> { impl<'a> eframe::App for RogApp<'a> {
/// Called each time the UI needs repainting, which may be many times per second. /// Called each time the UI needs repainting, which may be many times per second.
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
let Self { let Self {

View File

@@ -10,7 +10,7 @@ pub enum Error {
ConfigLockFail, ConfigLockFail,
XdgVars, XdgVars,
Zbus(zbus::Error), Zbus(zbus::Error),
Notification(notify_rust::error::Error) Notification(notify_rust::error::Error),
} }
impl fmt::Display for Error { impl fmt::Display for Error {

View File

@@ -1,12 +1,12 @@
use eframe::NativeOptions; use eframe::NativeOptions;
use rog_aura::layouts::KeyLayout; use rog_aura::layouts::KeyLayout;
use rog_control_center::{ use rog_control_center::{
error::Result, config::Config, error::Result, get_ipc_file, notify::start_notifications, on_tmp_dir_exists,
config::Config, get_ipc_file, notify::start_notifications, on_tmp_dir_exists,
page_states::PageDataStates, print_versions, startup_error::AppErrorShow, RogApp, page_states::PageDataStates, print_versions, startup_error::AppErrorShow, RogApp,
RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI, RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI,
}; };
use rog_platform::supported::SupportedFunctions; use rog_platform::supported::SupportedFunctions;
use tokio::runtime::Runtime;
use std::{ use std::{
fs::OpenOptions, fs::OpenOptions,
@@ -24,6 +24,11 @@ const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
fn main() -> Result<()> { fn main() -> Result<()> {
print_versions(); print_versions();
// start tokio
let rt = Runtime::new().expect("Unable to create Runtime");
// Enter the runtime so that `tokio::spawn` is available immediately.
let _enter = rt.enter();
let native_options = eframe::NativeOptions { let native_options = eframe::NativeOptions {
vsync: true, vsync: true,
decorated: true, decorated: true,
@@ -88,7 +93,9 @@ fn main() -> Result<()> {
Err(_) => on_tmp_dir_exists().unwrap(), Err(_) => on_tmp_dir_exists().unwrap(),
}; };
let states = setup_page_state_and_notifs(layout.clone(), &config, native_options.clone(), &dbus).unwrap(); let states =
setup_page_state_and_notifs(layout.clone(), &config, native_options.clone(), &dbus)
.unwrap();
loop { loop {
if !start_closed { if !start_closed {
@@ -110,6 +117,11 @@ fn main() -> Result<()> {
} }
} }
} }
// loop {
// // This is just a blocker to idle and ensure the reator reacts
// sleep(Duration::from_millis(1000)).await;
// }
Ok(()) Ok(())
} }
@@ -165,10 +177,7 @@ fn setup_page_state_and_notifs(
) )
} }
fn start_app( fn start_app(states: PageDataStates, native_options: NativeOptions) -> Result<()> {
states: PageDataStates,
native_options: NativeOptions,
) -> Result<()> {
let mut ipc_file = get_ipc_file().unwrap(); let mut ipc_file = get_ipc_file().unwrap();
ipc_file.write_all(&[SHOWING_GUI]).unwrap(); ipc_file.write_all(&[SHOWING_GUI]).unwrap();
eframe::run_native( eframe::run_native(

View File

@@ -6,17 +6,15 @@ use rog_dbus::{
}; };
use rog_platform::platform::GpuMode; use rog_platform::platform::GpuMode;
use rog_profiles::Profile; use rog_profiles::Profile;
use smol::{future, Executor};
use std::{ use std::{
fmt::Display, fmt::Display,
sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Mutex, Arc, Mutex,
}, },
thread::spawn,
}; };
use supergfxctl::pci_device::GfxPower; use supergfxctl::pci_device::GfxPower;
use zbus::export::futures_util::StreamExt; use zbus::export::futures_util::{future, StreamExt};
const NOTIF_HEADER: &str = "ROG Control"; const NOTIF_HEADER: &str = "ROG Control";
@@ -32,8 +30,7 @@ macro_rules! notify {
} }
macro_rules! recv_notif { macro_rules! recv_notif {
($executor:ident, ($proxy:ident,
$proxy:ident,
$signal:ident, $signal:ident,
$was_notified:ident, $was_notified:ident,
$last_notif:ident, $last_notif:ident,
@@ -45,8 +42,7 @@ macro_rules! recv_notif {
let notifs_enabled1 = $notif_enabled.clone(); let notifs_enabled1 = $notif_enabled.clone();
let notified = $was_notified.clone(); let notified = $was_notified.clone();
// TODO: make a macro or generic function or something... // TODO: make a macro or generic function or something...
$executor tokio::spawn(async move {
.spawn(async move {
let conn = zbus::Connection::system().await.unwrap(); let conn = zbus::Connection::system().await.unwrap();
let proxy = $proxy::new(&conn).await.unwrap(); let proxy = $proxy::new(&conn).await.unwrap();
if let Ok(p) = proxy.$signal().await { if let Ok(p) = proxy.$signal().await {
@@ -63,8 +59,7 @@ macro_rules! recv_notif {
}) })
.await; .await;
}; };
}) });
.detach();
}; };
} }
@@ -81,10 +76,8 @@ pub fn start_notifications(
) -> Result<()> { ) -> Result<()> {
let last_notification: SharedHandle = Arc::new(Mutex::new(None)); let last_notification: SharedHandle = Arc::new(Mutex::new(None));
let executor = Executor::new();
// BIOS notif // BIOS notif
recv_notif!( recv_notif!(
executor,
RogBiosProxy, RogBiosProxy,
receive_notify_post_boot_sound, receive_notify_post_boot_sound,
bios_notified, bios_notified,
@@ -96,7 +89,6 @@ pub fn start_notifications(
); );
recv_notif!( recv_notif!(
executor,
RogBiosProxy, RogBiosProxy,
receive_notify_panel_od, receive_notify_panel_od,
bios_notified, bios_notified,
@@ -108,7 +100,6 @@ pub fn start_notifications(
); );
recv_notif!( recv_notif!(
executor,
RogBiosProxy, RogBiosProxy,
receive_notify_dgpu_disable, receive_notify_dgpu_disable,
bios_notified, bios_notified,
@@ -120,7 +111,6 @@ pub fn start_notifications(
); );
recv_notif!( recv_notif!(
executor,
RogBiosProxy, RogBiosProxy,
receive_notify_egpu_enable, receive_notify_egpu_enable,
bios_notified, bios_notified,
@@ -132,7 +122,6 @@ pub fn start_notifications(
); );
recv_notif!( recv_notif!(
executor,
RogBiosProxy, RogBiosProxy,
receive_notify_gpu_mux_mode, receive_notify_gpu_mux_mode,
bios_notified, bios_notified,
@@ -145,7 +134,6 @@ pub fn start_notifications(
// Charge notif // Charge notif
recv_notif!( recv_notif!(
executor,
PowerProxy, PowerProxy,
receive_notify_charge_control_end_threshold, receive_notify_charge_control_end_threshold,
charge_notified, charge_notified,
@@ -157,7 +145,6 @@ pub fn start_notifications(
); );
recv_notif!( recv_notif!(
executor,
PowerProxy, PowerProxy,
receive_notify_mains_online, receive_notify_mains_online,
bios_notified, bios_notified,
@@ -170,7 +157,6 @@ pub fn start_notifications(
// Profile notif // Profile notif
recv_notif!( recv_notif!(
executor,
ProfileProxy, ProfileProxy,
receive_notify_profile, receive_notify_profile,
profiles_notified, profiles_notified,
@@ -184,7 +170,6 @@ pub fn start_notifications(
// LED notif // LED notif
recv_notif!( recv_notif!(
executor,
LedProxy, LedProxy,
receive_notify_led, receive_notify_led,
aura_notified, aura_notified,
@@ -195,73 +180,64 @@ pub fn start_notifications(
do_notification do_notification
); );
executor tokio::spawn(async move {
.spawn(async move { let conn = zbus::Connection::system().await.unwrap();
let conn = zbus::Connection::system().await.unwrap(); let proxy = LedProxy::new(&conn).await.unwrap();
let proxy = LedProxy::new(&conn).await.unwrap(); if let Ok(p) = proxy.receive_all_signals().await {
if let Ok(p) = proxy.receive_all_signals().await { p.for_each(|_| {
p.for_each(|_| { aura_notified.store(true, Ordering::SeqCst);
aura_notified.store(true, Ordering::SeqCst); future::ready(())
future::ready(()) })
}) .await;
.await; };
}; });
})
.detach();
executor tokio::spawn(async move {
.spawn(async move { let conn = zbus::Connection::system().await.unwrap();
let conn = zbus::Connection::system().await.unwrap(); let proxy = AnimeProxy::new(&conn).await.unwrap();
let proxy = AnimeProxy::new(&conn).await.unwrap(); if let Ok(p) = proxy.receive_power_states().await {
if let Ok(p) = proxy.receive_power_states().await { p.for_each(|_| {
p.for_each(|_| { anime_notified.store(true, Ordering::SeqCst);
anime_notified.store(true, Ordering::SeqCst); future::ready(())
future::ready(()) })
}) .await;
.await; };
}; });
})
.detach();
let notifs_enabled1 = notifs_enabled.clone(); let notifs_enabled1 = notifs_enabled.clone();
let last_notif = last_notification.clone(); let last_notif = last_notification.clone();
let bios_notified1 = bios_notified.clone(); let bios_notified1 = bios_notified.clone();
executor tokio::spawn(async move {
.spawn(async move { let conn = zbus::Connection::system().await.unwrap();
let conn = zbus::Connection::system().await.unwrap(); let proxy = supergfxctl::zbus_proxy::DaemonProxy::new(&conn)
let proxy = supergfxctl::zbus_proxy::DaemonProxy::new(&conn) .await
.await .unwrap();
.unwrap(); if let Ok(p) = proxy.receive_notify_gfx_status().await {
if let Ok(p) = proxy.receive_notify_gfx_status().await { p.for_each(|e| {
p.for_each(|e| { if let Ok(out) = e.args() {
if let Ok(out) = e.args() { if notifs_enabled1.load(Ordering::SeqCst) {
if notifs_enabled1.load(Ordering::SeqCst) { let status = out.status();
let status = out.status(); if *status != GfxPower::Unknown {
if *status != GfxPower::Unknown { // Required check because status cycles through active/unknown/suspended
// Required check because status cycles through active/unknown/suspended if let Ok(ref mut lock) = last_notif.try_lock() {
if let Ok(ref mut lock) = last_notif.try_lock() { notify!(
notify!( do_notification(
do_notification( "dGPU status changed:",
"dGPU status changed:", &format!("{status:?}",)
&format!("{status:?}",) ),
), lock
lock );
);
}
} }
} }
} }
bios_notified1.store(true, Ordering::SeqCst); }
future::ready(()) bios_notified1.store(true, Ordering::SeqCst);
}) future::ready(())
.await; })
}; .await;
}) };
.detach();
spawn(move || loop {
smol::block_on(executor.tick());
}); });
Ok(()) Ok(())
} }