mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-04 21:50:36 -04:00
manager/user: Move relevant methods to WifiDebug1, update as specified
This commit is contained in:
parent
4f3a5547d6
commit
576135cd7a
3 changed files with 78 additions and 7 deletions
|
@ -8,6 +8,7 @@
|
|||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use steamos_manager::cec::HdmiCecState;
|
||||
use steamos_manager::hardware::FanControlState;
|
||||
|
@ -15,7 +16,7 @@ use steamos_manager::power::{CPUScalingGovernor, GPUPerformanceLevel, GPUPowerPr
|
|||
use steamos_manager::proxy::{
|
||||
AmbientLightSensor1Proxy, CpuScaling1Proxy, FactoryReset1Proxy, FanControl1Proxy,
|
||||
GpuPerformanceLevel1Proxy, GpuPowerProfile1Proxy, HdmiCec1Proxy, Manager2Proxy, ManagerProxy,
|
||||
Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy, WifiPowerManagement1Proxy,
|
||||
Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy, WifiDebug1Proxy, WifiPowerManagement1Proxy,
|
||||
};
|
||||
use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement};
|
||||
use zbus::fdo::PropertiesProxy;
|
||||
|
@ -129,8 +130,7 @@ enum Commands {
|
|||
/// Valid modes are on, off
|
||||
mode: WifiDebugMode,
|
||||
/// The size of the debug buffer, in bytes
|
||||
#[arg(default_value_t = 20000)]
|
||||
buffer: u32,
|
||||
buffer: Option<u32>,
|
||||
},
|
||||
|
||||
/// Get wifi debug mode
|
||||
|
@ -327,19 +327,29 @@ async fn main() -> Result<()> {
|
|||
println!("TDP limit min: {value}");
|
||||
}
|
||||
Commands::SetWifiBackend { backend } => {
|
||||
proxy.set_wifi_backend(*backend as u32).await?;
|
||||
let proxy = WifiDebug1Proxy::new(&conn).await?;
|
||||
proxy.set_wifi_backend(backend.to_string().as_str()).await?;
|
||||
}
|
||||
Commands::GetWifiBackend => {
|
||||
let proxy = WifiDebug1Proxy::new(&conn).await?;
|
||||
let backend = proxy.wifi_backend().await?;
|
||||
match WifiBackend::try_from(backend) {
|
||||
match WifiBackend::try_from(backend.as_str()) {
|
||||
Ok(be) => println!("Wifi backend: {}", be),
|
||||
Err(_) => println!("Got unknown value {backend} from backend"),
|
||||
}
|
||||
}
|
||||
Commands::SetWifiDebugMode { mode, buffer } => {
|
||||
proxy.set_wifi_debug_mode(*mode as u32, *buffer).await?;
|
||||
let proxy = WifiDebug1Proxy::new(&conn).await?;
|
||||
let mut options = HashMap::<&str, &zvariant::Value<'_>>::new();
|
||||
let buffer_size;
|
||||
if let Some(size) = buffer {
|
||||
buffer_size = Some(zvariant::Value::U32(*size));
|
||||
options.insert("buffer_size", buffer_size.as_ref().unwrap());
|
||||
}
|
||||
proxy.set_wifi_debug_mode(*mode as u32, options).await?;
|
||||
}
|
||||
Commands::GetWifiDebugMode => {
|
||||
let proxy = WifiDebug1Proxy::new(&conn).await?;
|
||||
let mode = proxy.wifi_debug_mode_state().await?;
|
||||
match WifiDebugMode::try_from(mode) {
|
||||
Ok(m) => println!("Wifi debug mode: {}", m),
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
use anyhow::Result;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use tokio::fs::File;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
@ -231,7 +232,7 @@ impl SteamOSManager {
|
|||
async fn set_wifi_debug_mode(
|
||||
&mut self,
|
||||
mode: u32,
|
||||
buffer_size: u32,
|
||||
options: HashMap<&str, zvariant::Value<'_>>,
|
||||
#[zbus(signal_context)] ctx: SignalContext<'_>,
|
||||
) -> fdo::Result<()> {
|
||||
// Set the wifi debug mode to mode, using an int for flexibility going forward but only
|
||||
|
@ -240,6 +241,11 @@ impl SteamOSManager {
|
|||
Ok(mode) => mode,
|
||||
Err(e) => return Err(fdo::Error::InvalidArgs(e.to_string())),
|
||||
};
|
||||
let buffer_size = match options.get("buffer_size").map(|v| v.downcast_ref::<u32>()) {
|
||||
Some(Ok(v)) => v,
|
||||
None => 20000,
|
||||
Some(Err(e)) => return Err(fdo::Error::InvalidArgs(e.to_string())),
|
||||
};
|
||||
match set_wifi_debug_mode(
|
||||
wanted_mode,
|
||||
buffer_size,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
use anyhow::Result;
|
||||
use std::collections::HashMap;
|
||||
use tokio::sync::mpsc::{Sender, UnboundedSender};
|
||||
use tokio::sync::oneshot;
|
||||
use tracing::error;
|
||||
|
@ -142,6 +143,10 @@ struct UpdateDock1 {
|
|||
job_manager: UnboundedSender<JobManagerCommand>,
|
||||
}
|
||||
|
||||
struct WifiDebug1 {
|
||||
proxy: Proxy<'static>,
|
||||
}
|
||||
|
||||
struct WifiPowerManagement1 {
|
||||
proxy: Proxy<'static>,
|
||||
}
|
||||
|
@ -462,6 +467,43 @@ impl UpdateDock1 {
|
|||
}
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.WifiDebug1")]
|
||||
impl WifiDebug1 {
|
||||
#[zbus(property)]
|
||||
async fn wifi_debug_mode_state(&self) -> fdo::Result<u32> {
|
||||
getter!(self, "WifiDebugModeState")
|
||||
}
|
||||
|
||||
async fn set_wifi_debug_mode(
|
||||
&self,
|
||||
mode: u32,
|
||||
options: HashMap<&str, zvariant::Value<'_>>,
|
||||
#[zbus(signal_context)] ctx: SignalContext<'_>,
|
||||
) -> fdo::Result<()> {
|
||||
method!(self, "SetWifiDebugMode", mode, options)?;
|
||||
self.wifi_debug_mode_state_changed(&ctx)
|
||||
.await
|
||||
.map_err(zbus_to_zbus_fdo)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "false"))]
|
||||
async fn wifi_backend(&self) -> fdo::Result<String> {
|
||||
match get_wifi_backend().await {
|
||||
Ok(backend) => Ok(backend.to_string()),
|
||||
Err(e) => Err(to_zbus_fdo_error(e)),
|
||||
}
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_wifi_backend(&self, backend: &str) -> zbus::Result<()> {
|
||||
self.proxy
|
||||
.call("SetWifiBackend", &(backend))
|
||||
.await
|
||||
.map_err(to_zbus_error)
|
||||
}
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.WifiPowerManagement1")]
|
||||
impl WifiPowerManagement1 {
|
||||
#[zbus(property(emits_changed_signal = "false"))]
|
||||
|
@ -532,6 +574,9 @@ pub(crate) async fn create_interfaces(
|
|||
proxy: proxy.clone(),
|
||||
job_manager: job_manager.clone(),
|
||||
};
|
||||
let wifi_debug = WifiDebug1 {
|
||||
proxy: proxy.clone(),
|
||||
};
|
||||
let wifi_power_management = WifiPowerManagement1 {
|
||||
proxy: proxy.clone(),
|
||||
};
|
||||
|
@ -551,6 +596,7 @@ pub(crate) async fn create_interfaces(
|
|||
object_server.at(MANAGER_PATH, storage).await?;
|
||||
object_server.at(MANAGER_PATH, update_bios).await?;
|
||||
object_server.at(MANAGER_PATH, update_dock).await?;
|
||||
object_server.at(MANAGER_PATH, wifi_debug).await?;
|
||||
object_server
|
||||
.at(MANAGER_PATH, wifi_power_management)
|
||||
.await?;
|
||||
|
@ -733,4 +779,13 @@ mod test {
|
|||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn interface_matches_wifi_debug() {
|
||||
let test = start().await.expect("start");
|
||||
|
||||
assert!(test_interface_matches::<WifiDebug1>(&test.connection)
|
||||
.await
|
||||
.unwrap());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue