mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-08 07:30:36 -04:00
job: Add method to mirror jobs from an already-running daemon
This commit is contained in:
parent
0626012748
commit
3c56afe921
3 changed files with 36 additions and 4 deletions
|
@ -29,4 +29,5 @@ tracing-subscriber = { version = "0.3", default-features = false, features = ["e
|
||||||
udev = "0.8"
|
udev = "0.8"
|
||||||
xdg = "2.5"
|
xdg = "2.5"
|
||||||
zbus = { version = "4", default-features = false, features = ["tokio"] }
|
zbus = { version = "4", default-features = false, features = ["tokio"] }
|
||||||
|
zbus_xml = "4"
|
||||||
strum = { version = "0.26", features = ["derive"] }
|
strum = { version = "0.26", features = ["derive"] }
|
||||||
|
|
23
src/job.rs
23
src/job.rs
|
@ -12,11 +12,14 @@ use nix::sys::signal::Signal;
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
use std::io::Cursor;
|
||||||
use std::os::unix::process::ExitStatusExt;
|
use std::os::unix::process::ExitStatusExt;
|
||||||
use std::process::ExitStatus;
|
use std::process::ExitStatus;
|
||||||
use tokio::process::{Child, Command};
|
use tokio::process::{Child, Command};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use zbus::{fdo, interface, zvariant, Connection, Interface, InterfaceRef, SignalContext};
|
use zbus::fdo::{self, IntrospectableProxy};
|
||||||
|
use zbus::{interface, zvariant, Connection, Interface, InterfaceRef, SignalContext};
|
||||||
|
use zbus_xml::Node;
|
||||||
|
|
||||||
use crate::error::{to_zbus_fdo_error, zbus_to_zbus_fdo};
|
use crate::error::{to_zbus_fdo_error, zbus_to_zbus_fdo};
|
||||||
use crate::proxy::JobProxy;
|
use crate::proxy::JobProxy;
|
||||||
|
@ -117,6 +120,24 @@ impl JobManager {
|
||||||
self.mirrored_jobs.insert(name, object_path.to_owned());
|
self.mirrored_jobs.insert(name, object_path.to_owned());
|
||||||
Ok(object_path)
|
Ok(object_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn mirror_connection(&mut self, connection: &Connection) -> fdo::Result<()> {
|
||||||
|
let proxy = IntrospectableProxy::builder(connection)
|
||||||
|
.destination("com.steampowered.SteamOSManager1")?
|
||||||
|
.path(JOB_PREFIX)?
|
||||||
|
.build()
|
||||||
|
.await?;
|
||||||
|
let introspection = proxy.introspect().await?;
|
||||||
|
let introspection =
|
||||||
|
Node::from_reader(Cursor::new(introspection)).map_err(to_zbus_fdo_error)?;
|
||||||
|
for node in introspection.nodes() {
|
||||||
|
if let Some(name) = node.name() {
|
||||||
|
self.mirror_job(connection, format!("{JOB_PREFIX}/{name}"))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[interface(name = "com.steampowered.SteamOSManager1.JobManager")]
|
#[interface(name = "com.steampowered.SteamOSManager1.JobManager")]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tokio::sync::mpsc::Sender;
|
use tokio::sync::mpsc::Sender;
|
||||||
use tracing::error;
|
use tracing::{error, warn};
|
||||||
use zbus::proxy::Builder;
|
use zbus::proxy::Builder;
|
||||||
use zbus::zvariant::{self, Fd};
|
use zbus::zvariant::{self, Fd};
|
||||||
use zbus::{fdo, interface, CacheProperties, Connection, Proxy, SignalContext};
|
use zbus::{fdo, interface, CacheProperties, Connection, Proxy, SignalContext};
|
||||||
|
@ -90,8 +90,18 @@ impl SteamOSManager {
|
||||||
system_conn: &Connection,
|
system_conn: &Connection,
|
||||||
channel: Sender<Command>,
|
channel: Sender<Command>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
|
let hdmi_cec = HdmiCecControl::new(&connection).await?;
|
||||||
|
let mut job_manager = JobManager::new(connection).await?;
|
||||||
|
if let Err(e) = job_manager.mirror_connection(system_conn).await {
|
||||||
|
warn!("Could not mirror jobs: {e}");
|
||||||
|
match e {
|
||||||
|
fdo::Error::ServiceUnknown(_) => (),
|
||||||
|
e => Err(e)?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(SteamOSManager {
|
Ok(SteamOSManager {
|
||||||
hdmi_cec: HdmiCecControl::new(&connection).await?,
|
hdmi_cec,
|
||||||
proxy: Builder::new(system_conn)
|
proxy: Builder::new(system_conn)
|
||||||
.destination("com.steampowered.SteamOSManager1")?
|
.destination("com.steampowered.SteamOSManager1")?
|
||||||
.path("/com/steampowered/SteamOSManager1")?
|
.path("/com/steampowered/SteamOSManager1")?
|
||||||
|
@ -99,7 +109,7 @@ impl SteamOSManager {
|
||||||
.cache_properties(CacheProperties::No)
|
.cache_properties(CacheProperties::No)
|
||||||
.build()
|
.build()
|
||||||
.await?,
|
.await?,
|
||||||
job_manager: JobManager::new(connection).await?,
|
job_manager,
|
||||||
channel,
|
channel,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue