job: Add method to mirror jobs from an already-running daemon

This commit is contained in:
Vicki Pfau 2024-07-09 17:16:46 -07:00
parent 0626012748
commit 3c56afe921
3 changed files with 36 additions and 4 deletions

View file

@ -12,11 +12,14 @@ use nix::sys::signal::Signal;
use nix::unistd::Pid;
use std::collections::HashMap;
use std::ffi::OsStr;
use std::io::Cursor;
use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus;
use tokio::process::{Child, Command};
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::proxy::JobProxy;
@ -117,6 +120,24 @@ impl JobManager {
self.mirrored_jobs.insert(name, object_path.to_owned());
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")]