From 5f0279eb1f16e5c76d0bc7649fca1b42b1c695c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 5 Nov 2021 02:40:19 +0400 Subject: [PATCH] demo: teach to connect to a different bus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- qemu-rdw/src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/qemu-rdw/src/main.rs b/qemu-rdw/src/main.rs index 9314a3f..5c89190 100644 --- a/qemu-rdw/src/main.rs +++ b/qemu-rdw/src/main.rs @@ -25,6 +25,7 @@ struct App { #[derive(Debug, Default)] struct AppOptions { vm_name: Option, + address: Option, list: bool, } @@ -39,6 +40,14 @@ impl App { "VM name", Some("VM-NAME"), ); + app.add_main_option( + "address", + glib::Char(b'a' as _), + glib::OptionFlags::NONE, + glib::OptionArg::String, + "D-Bus bus address", + None, + ); app.add_main_option( "list", glib::Char(0), @@ -64,6 +73,9 @@ impl App { println!("Version: {}", env!("CARGO_PKG_VERSION")); return 0; } + if let Some(arg) = opt.lookup_value("address", None) { + app_opt.address = arg.get::(); + } if opt.lookup_value("list", None).is_some() { app_opt.list = true; } @@ -96,7 +108,12 @@ impl App { let app_clone = app_clone.clone(); let opt_clone = opt.clone(); MainContext::default().spawn_local(async move { - let conn = zbus::ConnectionBuilder::session() + let builder = if let Some(addr) = &opt_clone.borrow().address { + zbus::ConnectionBuilder::address(addr.as_str()) + } else { + zbus::ConnectionBuilder::session() + }; + let conn = builder .unwrap() .internal_executor(false) .build()