Bugfixes to session handler. Add extra profile commands

- Better handling of session tracking
- List all profile data
- Get active profile name
- Get active profile data
This commit is contained in:
Luke D Jones
2021-03-23 18:53:17 +13:00
parent 301c532b65
commit 5a7d31fdf6
19 changed files with 203 additions and 329 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "daemon"
version = "3.2.2"
version = "3.2.3"
license = "MPL-2.0"
readme = "README.md"
authors = ["Luke <luke@ljones.dev>"]

View File

@@ -1,6 +1,5 @@
use log::{error, info, warn};
use rog_fan_curve::Curve;
use rog_types::gfx_vendors::GfxVendors;
use rog_types::{gfx_vendors::GfxVendors, profile::Profile};
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fs::{File, OpenOptions};
@@ -136,45 +135,3 @@ impl Config {
.unwrap_or_else(|err| error!("Could not write config: {}", err));
}
}
#[derive(Deserialize, Serialize)]
pub struct Profile {
pub min_percentage: u8,
pub max_percentage: u8,
pub turbo: bool,
pub fan_preset: u8,
pub fan_curve: Option<Curve>,
}
#[deprecated]
pub type CPUSettings = Profile;
impl Default for Profile {
fn default() -> Self {
Profile {
min_percentage: 0,
max_percentage: 100,
turbo: false,
fan_preset: 0,
fan_curve: None,
}
}
}
impl Profile {
pub fn new(
min_percentage: u8,
max_percentage: u8,
turbo: bool,
fan_preset: u8,
fan_curve: Option<Curve>,
) -> Self {
Profile {
min_percentage,
max_percentage,
turbo,
fan_preset,
fan_curve,
}
}
}

View File

@@ -1,8 +1,8 @@
use rog_types::{aura_modes::AuraEffect, gfx_vendors::GfxVendors};
use rog_types::{aura_modes::AuraEffect, gfx_vendors::GfxVendors, profile::Profile};
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
use crate::config::{Config, Profile};
use crate::config::{Config};
/// for parsing old v2.1.2 config
#[allow(dead_code)]

View File

@@ -1,10 +1,10 @@
use crate::error::RogError;
use crate::{
config::{Config, Profile},
config::{Config},
GetSupported,
};
use log::{info, warn};
use rog_types::profile::{FanLevel, ProfileEvent};
use rog_types::profile::{FanLevel, ProfileEvent, Profile};
use serde_derive::{Deserialize, Serialize};
use std::fs::OpenOptions;
use std::io::Write;
@@ -90,60 +90,59 @@ impl DbusFanAndCpu {
}
/// Fetch the active profile name
fn active_profile_name(&mut self) -> String {
fn active_profile_name(&mut self) -> zbus::fdo::Result<String> {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() {
cfg.read();
return cfg.active_profile.clone();
return Ok(cfg.active_profile.clone());
}
}
"Failed".to_string()
Err(Error::Failed("Failed to get active profile name".to_string()))
}
// TODO: Profile can't implement Type because of Curve
/// Fetch the active profile details
fn profile(&mut self) -> String {
fn profile(&mut self) -> zbus::fdo::Result<String> {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() {
cfg.read();
if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) {
if let Ok(json) = serde_json::to_string(profile) {
return json;
if let Ok(json) = serde_json::to_string_pretty(profile) {
return Ok(json);
}
}
}
}
"Failed".to_string()
Err(Error::Failed("Failed to get active profile details".to_string()))
}
fn profiles(&mut self) -> String {
/// Fetch all profile data
fn profiles(&mut self) -> zbus::fdo::Result<String> {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() {
cfg.read();
if let Ok(json) = serde_json::to_string(&cfg.power_profiles) {
return json;
if let Ok(json) = serde_json::to_string_pretty(&cfg.power_profiles) {
return Ok(json);
}
}
}
"Failed".to_string()
Err(Error::Failed("Failed to get all profile details".to_string()))
}
fn profile_names(&self) -> String {
fn profile_names(&self) -> zbus::fdo::Result<Vec<String>> {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() {
cfg.read();
let profile_names: String = cfg
let profile_names = cfg
.power_profiles
.keys()
.cloned()
.collect::<Vec<String>>()
.join(", ");
return profile_names;
.collect::<Vec<String>>();
return Ok(profile_names);
}
}
"Failed".to_string()
Err(Error::Failed("Failed to get all profile names".to_string()))
}
fn remove(&self, profile: &str) -> zbus::fdo::Result<()> {
@@ -172,7 +171,7 @@ impl DbusFanAndCpu {
}
}
return Err(Error::Failed("Failed to lock configuration".to_string()));
Err(Error::Failed("Failed to lock configuration".to_string()))
}
#[dbus_interface(signal)]

View File

@@ -10,6 +10,8 @@ pub enum GfxError {
DisplayManagerAction(String, ExitStatus),
DisplayManagerTimeout(String),
GsyncModeActive,
VfioBuiltin,
MissingModule(String),
}
impl fmt::Display for GfxError {
@@ -28,6 +30,14 @@ impl fmt::Display for GfxError {
f,
"Can not switch gfx modes when dedicated/G-Sync mode is active"
),
GfxError::VfioBuiltin => write!(
f,
"Can not switch to vfio mode if the modules are built in to kernel"
),
GfxError::MissingModule(m) => write!(
f,
"The module {} is missing", m
),
}
}
}

View File

@@ -2,10 +2,7 @@ use ctrl_gfx::error::GfxError;
use ctrl_gfx::*;
use ctrl_rog_bios::CtrlRogBios;
use log::{error, info, warn};
use logind_zbus::{
types::{SessionClass, SessionInfo, SessionType},
ManagerProxy, SessionProxy,
};
use logind_zbus::{ManagerProxy, SessionProxy, types::{SessionClass, SessionInfo, SessionState, SessionType}};
use rog_types::gfx_vendors::{GfxRequiredUserAction, GfxVendors};
use std::sync::mpsc;
use std::{io::Write, ops::Add, path::Path, time::Instant};
@@ -326,6 +323,12 @@ impl CtrlGraphics {
{
return Ok(());
}
if output
.stderr
.ends_with("is builtin.\n".as_bytes())
{
return Err(GfxError::VfioBuiltin.into());
}
if output.stderr.ends_with("Permission denied\n".as_bytes()) {
warn!(
"{} {} failed: {:?}",
@@ -336,6 +339,9 @@ impl CtrlGraphics {
warn!("GFX: It may be safe to ignore the above error, run `lsmod |grep {}` to confirm modules loaded", driver);
return Ok(());
}
if String::from_utf8_lossy(&output.stderr).contains(&format!("Module {} not found", driver)) {
return Err(GfxError::MissingModule(driver.into()).into());
}
if count >= MAX_TRIES {
let msg = format!(
"{} {} failed: {:?}",
@@ -350,7 +356,7 @@ impl CtrlGraphics {
}
count += 1;
std::thread::sleep(std::time::Duration::from_millis(250));
std::thread::sleep(std::time::Duration::from_millis(50));
}
}
@@ -455,7 +461,6 @@ impl CtrlGraphics {
Self::unbind_remove_nvidia(&devices)?;
}
}
Ok(())
}
@@ -468,9 +473,10 @@ impl CtrlGraphics {
if session_proxy.get_class()? == SessionClass::User {
match session_proxy.get_type()? {
SessionType::X11 | SessionType::Wayland | SessionType::MIR => {
//if session_proxy.get_active()? {
return Ok(true);
//}
match session_proxy.get_state()? {
SessionState::Online | SessionState::Active => return Ok(true),
SessionState::Closing | SessionState::Invalid => {}
}
}
_ => {}
}
@@ -499,8 +505,7 @@ impl CtrlGraphics {
loop {
let tmp = manager.list_sessions()?;
if !tmp.iter().eq(&sessions) {
warn!("GFX: Sessions list changed");
warn!("GFX: Old list:\n{:?}\nNew list:\n{:?}", &sessions, &tmp);
info!("GFX thread: Sessions list changed");
sessions = tmp;
}
@@ -523,30 +528,15 @@ impl CtrlGraphics {
sleep(SLEEP_PERIOD);
}
info!("GFX: all graphical user sessions ended, continuing");
info!("GFX thread: all graphical user sessions ended, continuing");
Self::do_display_manager_action("stop")?;
match Self::wait_display_manager_state("inactive") {
Ok(_) => info!("GFX: display-manager stopped"),
Err(err) => {
warn!("GFX: {}", err);
warn!("GFX: Retry stop display manager");
Self::do_display_manager_action("stop")?;
Self::wait_display_manager_state("inactive")?;
}
}
Self::wait_display_manager_state("inactive")?;
Self::do_vendor_tasks(vendor, &devices, &bus)?;
Self::do_display_manager_action("start")?;
if Self::wait_display_manager_state("active").is_err() {
error!("GFX: display-manager failed to start normally, attempting restart");
Self::do_display_manager_action("restart")?;
Self::wait_display_manager_state("active")?;
}
Self::do_display_manager_action("restart")?;
// Save selected mode in case of reboot
Self::save_gfx_mode(vendor, config);
info!("GFX: display-manager started");
info!("GFX thread: display-manager started");
let v: &str = vendor.into();
info!("GFX: Graphics mode changed to {} successfully", v);
@@ -560,7 +550,7 @@ impl CtrlGraphics {
info!("GFX: Cancelling previous thread");
tx.send(true)
.map_err(|err| {
warn!("GFX: {}", err);
warn!("GFX thread: {}", err);
})
.ok();
}