in crates/zbus/src/lib.rs [346:441]
fn freedesktop_api() {
let connection = blocking::Connection::session()
.map_err(|e| {
debug!("error: {}", e);
e
})
.unwrap();
let reply = connection
.call_method(
Some("org.freedesktop.DBus"),
"/org/freedesktop/DBus",
Some("org.freedesktop.DBus"),
"RequestName",
&(
"org.freedesktop.zbus.sync",
BitFlags::from(RequestNameFlags::ReplaceExisting),
),
)
.unwrap();
let body = reply.body();
assert!(body.signature().map(|s| s == "u").unwrap());
let reply: RequestNameReply = body.deserialize().unwrap();
assert_eq!(reply, RequestNameReply::PrimaryOwner);
let reply = connection
.call_method(
Some("org.freedesktop.DBus"),
"/org/freedesktop/DBus",
Some("org.freedesktop.DBus"),
"GetId",
&(),
)
.unwrap();
let body = reply.body();
assert!(body.signature().map(|s| s == <&str>::signature()).unwrap());
let id: &str = body.deserialize().unwrap();
debug!("Unique ID of the bus: {}", id);
let reply = connection
.call_method(
Some("org.freedesktop.DBus"),
"/org/freedesktop/DBus",
Some("org.freedesktop.DBus"),
"NameHasOwner",
&"org.freedesktop.zbus.sync",
)
.unwrap();
let body = reply.body();
assert!(body.signature().map(|s| s == bool::signature()).unwrap());
assert!(body.deserialize::<bool>().unwrap());
let reply = connection
.call_method(
Some("org.freedesktop.DBus"),
"/org/freedesktop/DBus",
Some("org.freedesktop.DBus"),
"GetNameOwner",
&"org.freedesktop.zbus.sync",
)
.unwrap();
let body = reply.body();
assert!(body.signature().map(|s| s == <&str>::signature()).unwrap());
assert_eq!(
body.deserialize::<UniqueName<'_>>().unwrap(),
*connection.unique_name().unwrap(),
);
let reply = connection
.call_method(
Some("org.freedesktop.DBus"),
"/org/freedesktop/DBus",
Some("org.freedesktop.DBus"),
"GetConnectionCredentials",
&"org.freedesktop.DBus",
)
.unwrap();
let body = reply.body();
assert!(body.signature().map(|s| s == "a{sv}").unwrap());
let hashmap: HashMap<&str, OwnedValue> = body.deserialize().unwrap();
let pid: u32 = (&hashmap["ProcessID"]).try_into().unwrap();
debug!("DBus bus PID: {}", pid);
#[cfg(unix)]
{
let uid: u32 = (&hashmap["UnixUserID"]).try_into().unwrap();
debug!("DBus bus UID: {}", uid);
}
}