mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 01:12:30 -04:00
manager/user: Dynamically add or remove the TdpLimit1 interface if needed
This commit is contained in:
parent
6086e23cc8
commit
c8eb661bec
2 changed files with 54 additions and 14 deletions
|
@ -146,6 +146,7 @@ struct Manager2 {
|
||||||
|
|
||||||
struct PerformanceProfile1 {
|
struct PerformanceProfile1 {
|
||||||
proxy: Proxy<'static>,
|
proxy: Proxy<'static>,
|
||||||
|
tdp_limit_manager: Option<Box<dyn TdpLimitManager>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Storage1 {
|
struct Storage1 {
|
||||||
|
@ -492,8 +493,29 @@ impl PerformanceProfile1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_performance_profile(&self, profile: &str) -> zbus::Result<()> {
|
async fn set_performance_profile(
|
||||||
self.proxy.call("SetPerformanceProfile", &(profile)).await
|
&self,
|
||||||
|
profile: &str,
|
||||||
|
#[zbus(connection)] connection: &Connection,
|
||||||
|
) -> zbus::Result<()> {
|
||||||
|
let _: () = self.proxy.call("SetPerformanceProfile", &(profile)).await?;
|
||||||
|
if self.tdp_limit_manager.is_some() {
|
||||||
|
let connection = connection.clone();
|
||||||
|
let manager = tdp_limit_manager().await.map_err(to_zbus_error)?;
|
||||||
|
let proxy = self.proxy.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if manager.is_active().await.map_err(to_zbus_error)? {
|
||||||
|
let tdp_limit = TdpLimit1 { proxy, manager };
|
||||||
|
connection.object_server().at(MANAGER_PATH, tdp_limit).await
|
||||||
|
} else {
|
||||||
|
connection
|
||||||
|
.object_server()
|
||||||
|
.remove::<TdpLimit1, _>(MANAGER_PATH)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
|
@ -654,6 +676,7 @@ async fn create_config_interfaces(
|
||||||
};
|
};
|
||||||
let performance_profile = PerformanceProfile1 {
|
let performance_profile = PerformanceProfile1 {
|
||||||
proxy: proxy.clone(),
|
proxy: proxy.clone(),
|
||||||
|
tdp_limit_manager: tdp_limit_manager().await.ok(),
|
||||||
};
|
};
|
||||||
let storage = Storage1 {
|
let storage = Storage1 {
|
||||||
proxy: proxy.clone(),
|
proxy: proxy.clone(),
|
||||||
|
@ -676,6 +699,20 @@ async fn create_config_interfaces(
|
||||||
object_server.at(MANAGER_PATH, fan_control).await?;
|
object_server.at(MANAGER_PATH, fan_control).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Ok(manager) = tdp_limit_manager().await {
|
||||||
|
if manager.is_active().await? {
|
||||||
|
object_server
|
||||||
|
.at(
|
||||||
|
MANAGER_PATH,
|
||||||
|
TdpLimit1 {
|
||||||
|
proxy: proxy.clone(),
|
||||||
|
manager,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref config) = config.performance_profile {
|
if let Some(ref config) = config.performance_profile {
|
||||||
if !get_available_platform_profiles(&config.platform_profile_name)
|
if !get_available_platform_profiles(&config.platform_profile_name)
|
||||||
.await
|
.await
|
||||||
|
@ -802,18 +839,6 @@ pub(crate) async fn create_interfaces(
|
||||||
|
|
||||||
object_server.at(MANAGER_PATH, manager2).await?;
|
object_server.at(MANAGER_PATH, manager2).await?;
|
||||||
|
|
||||||
if let Ok(manager) = tdp_limit_manager().await {
|
|
||||||
object_server
|
|
||||||
.at(
|
|
||||||
MANAGER_PATH,
|
|
||||||
TdpLimit1 {
|
|
||||||
proxy: proxy.clone(),
|
|
||||||
manager,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if steam_deck_variant().await.unwrap_or_default() == SteamDeckVariant::Galileo {
|
if steam_deck_variant().await.unwrap_or_default() == SteamDeckVariant::Galileo {
|
||||||
object_server.at(MANAGER_PATH, wifi_debug).await?;
|
object_server.at(MANAGER_PATH, wifi_debug).await?;
|
||||||
}
|
}
|
||||||
|
|
15
src/power.rs
15
src/power.rs
|
@ -107,6 +107,9 @@ pub(crate) trait TdpLimitManager: Send + Sync {
|
||||||
async fn get_tdp_limit(&self) -> Result<u32>;
|
async fn get_tdp_limit(&self) -> Result<u32>;
|
||||||
async fn set_tdp_limit(&self, limit: u32) -> Result<()>;
|
async fn set_tdp_limit(&self, limit: u32) -> Result<()>;
|
||||||
async fn get_tdp_limit_range(&self) -> Result<RangeInclusive<u32>>;
|
async fn get_tdp_limit_range(&self) -> Result<RangeInclusive<u32>>;
|
||||||
|
async fn is_active(&self) -> Result<bool> {
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn tdp_limit_manager() -> Result<Box<dyn TdpLimitManager>> {
|
pub(crate) async fn tdp_limit_manager() -> Result<Box<dyn TdpLimitManager>> {
|
||||||
|
@ -531,6 +534,18 @@ impl TdpLimitManager for LenovoWmiTdpLimitManager {
|
||||||
.map_err(|e| anyhow!("Error parsing value: {e}"))?;
|
.map_err(|e| anyhow!("Error parsing value: {e}"))?;
|
||||||
Ok(min..=max)
|
Ok(min..=max)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn is_active(&self) -> Result<bool> {
|
||||||
|
let config = platform_config().await?;
|
||||||
|
if let Some(config) = config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|config| config.performance_profile.as_ref())
|
||||||
|
{
|
||||||
|
Ok(get_platform_profile(&config.platform_profile_name).await? == "custom")
|
||||||
|
} else {
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_max_charge_level() -> Result<i32> {
|
pub(crate) async fn get_max_charge_level() -> Result<i32> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue