mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2024-12-22 05:35:20 +00:00
demo: add an option to --wait for VM
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
e4df821fc2
commit
5bee9ea7f3
@ -19,6 +19,32 @@ pub struct Display {
|
||||
}
|
||||
|
||||
impl Display {
|
||||
pub async fn lookup(
|
||||
conn: &Connection,
|
||||
wait: bool,
|
||||
name: Option<&str>,
|
||||
) -> Result<Option<OwnedUniqueName>> {
|
||||
let mut changed = fdo::DBusProxy::new(conn)
|
||||
.await?
|
||||
.receive_name_owner_changed()
|
||||
.await?;
|
||||
loop {
|
||||
let list = Display::by_name(&conn).await?;
|
||||
if let Some(name) = name {
|
||||
let res = list.get(name);
|
||||
if res.is_some() {
|
||||
return Ok(res.cloned());
|
||||
}
|
||||
} else if !list.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
if !wait {
|
||||
return Err(Error::Failed("Can't find VM".into()));
|
||||
};
|
||||
let _ = changed.next().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn by_name(conn: &Connection) -> Result<HashMap<String, OwnedUniqueName>> {
|
||||
let mut hm = HashMap::new();
|
||||
let list = match fdo::DBusProxy::new(conn)
|
||||
|
@ -27,6 +27,7 @@ struct AppOptions {
|
||||
vm_name: Option<String>,
|
||||
address: Option<String>,
|
||||
list: bool,
|
||||
wait: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@ -56,6 +57,14 @@ impl App {
|
||||
"List available VM names",
|
||||
None,
|
||||
);
|
||||
app.add_main_option(
|
||||
"wait",
|
||||
glib::Char(0),
|
||||
glib::OptionFlags::NONE,
|
||||
glib::OptionArg::None,
|
||||
"Wait for display to be available",
|
||||
None,
|
||||
);
|
||||
app.add_main_option(
|
||||
"version",
|
||||
glib::Char(0),
|
||||
@ -79,6 +88,9 @@ impl App {
|
||||
if opt.lookup_value("list", None).is_some() {
|
||||
app_opt.list = true;
|
||||
}
|
||||
if opt.lookup_value("wait", None).is_some() {
|
||||
app_opt.wait = true;
|
||||
}
|
||||
app_opt.vm_name = opt
|
||||
.lookup_value(&glib::OPTION_REMAINING, None)
|
||||
.and_then(|args| args.child_value(0).get::<String>());
|
||||
@ -135,15 +147,11 @@ impl App {
|
||||
app_clone.inner.app.quit();
|
||||
return;
|
||||
}
|
||||
let dest = if let Some(name) = opt_clone.borrow().vm_name.as_ref() {
|
||||
let list = Display::by_name(&conn).await.unwrap();
|
||||
Some(
|
||||
list.get(name)
|
||||
.unwrap_or_else(|| panic!("Can't find VM name: {}", name))
|
||||
.clone(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
let dest = {
|
||||
let name = opt_clone.borrow().vm_name.clone();
|
||||
let wait = opt_clone.borrow().wait;
|
||||
|
||||
Display::lookup(&conn, wait, name.as_deref()).await.unwrap()
|
||||
};
|
||||
let display = Display::new(&conn, dest.as_ref()).await.unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user