Commit 4a8a3f52 authored by Marc-André Lureau's avatar Marc-André Lureau
Browse files

zb: use generic ProxyBuilder


Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
parent bf0669ec
......@@ -18,9 +18,11 @@ use std::{
use async_io::block_on;
use zvariant::{ObjectPath, OwnedValue, Value};
use crate::{azync::Connection, Error, Message, Result};
use crate::fdo::{self, AsyncIntrospectableProxyBuilder, AsyncPropertiesProxyBuilder};
use crate::{
azync::Connection,
fdo::{self, AsyncIntrospectableProxy, AsyncPropertiesProxy},
Error, Message, Result,
};
type SignalHandler = Box<dyn for<'msg> FnMut(&'msg Message) -> BoxFuture<'msg, Result<()>> + Send>;
......@@ -274,12 +276,12 @@ impl<'a> Proxy<'a> {
///
/// See the [xml](xml/index.html) module for parsing the result.
pub async fn introspect(&self) -> fdo::Result<String> {
AsyncIntrospectableProxyBuilder::new(&self.inner.conn)?
let proxy: AsyncIntrospectableProxy<'_> = ProxyBuilder::new(&self.inner.conn)
.destination(self.inner.destination.as_ref())
.path(&self.inner.path)?
.build()?
.introspect()
.await
.build();
proxy.introspect().await
}
/// Get the property `property_name`.
......@@ -289,10 +291,12 @@ impl<'a> Proxy<'a> {
where
T: TryFrom<OwnedValue>,
{
AsyncPropertiesProxyBuilder::new(&self.inner.conn)?
let proxy: AsyncPropertiesProxy<'_> = ProxyBuilder::new(&self.inner.conn)
.destination(self.inner.destination.as_ref())
.path(&self.inner.path)?
.build()?
.build();
proxy
.get(&self.inner.interface, property_name)
.await?
.try_into()
......@@ -306,10 +310,12 @@ impl<'a> Proxy<'a> {
where
T: Into<Value<'t>>,
{
AsyncPropertiesProxyBuilder::new(&self.inner.conn)?
let proxy: AsyncPropertiesProxy<'_> = ProxyBuilder::new(&self.inner.conn)
.destination(self.inner.destination.as_ref())
.path(&self.inner.path)?
.build()?
.build();
proxy
.set(&self.inner.interface, property_name, &value.into())
.await
}
......
......@@ -606,13 +606,11 @@ mod tests {
) -> zbus::Result<(OwnedValue, OwnedObjectPath)>;
}
let proxy = SecretProxyBuilder::new(&conn)
.unwrap()
let proxy: SecretProxy<'_> = zbus::azync::ProxyBuilder::new(&conn.clone().into())
.destination(&service_name)
.path("/org/freedesktop/secrets")
.unwrap()
.build()
.unwrap();
.build();
proxy.open_session("plain", &Value::from("")).unwrap();
......
......@@ -551,7 +551,8 @@ mod tests {
use zvariant::derive::Type;
use crate::{
dbus_interface, dbus_proxy, fdo, Connection, MessageHeader, MessageType, ObjectServer,
azync::ProxyBuilder, dbus_interface, dbus_proxy, fdo, Connection, MessageHeader,
MessageType, ObjectServer,
};
#[derive(Deserialize, Serialize, Type)]
......@@ -706,15 +707,15 @@ mod tests {
fn my_iface_test(tx: Sender<()>) -> std::result::Result<u32, Box<dyn Error>> {
let conn = Connection::new_session()?;
let proxy = MyIfaceProxyBuilder::new(&conn)?
let proxy: MyIfaceProxy<'_> = ProxyBuilder::new(&conn.clone().into())
.destination("org.freedesktop.MyService")
.path("/org/freedesktop/MyService")?
.build()?;
.build();
let props_proxy = zbus::fdo::PropertiesProxyBuilder::new(&conn)?
let props_proxy: zbus::fdo::PropertiesProxy<'_> = ProxyBuilder::new(&conn.clone().into())
.destination("org.freedesktop.MyService")
.path("/org/freedesktop/MyService")?
.build()?;
.build();
props_proxy
.connect_properties_changed(|_, changed, _| {
......@@ -773,10 +774,10 @@ mod tests {
let val = proxy.ping()?;
proxy.create_obj("MyObj")?;
let my_obj_proxy = MyIfaceProxyBuilder::new(&conn)?
let my_obj_proxy: MyIfaceProxy<'_> = ProxyBuilder::new(&conn.clone().into())
.destination("org.freedesktop.MyService")
.path("/zbus/test/MyObj")?
.build()?;
.build();
my_obj_proxy.ping()?;
proxy.destroy_obj("MyObj")?;
assert!(my_obj_proxy.introspect().is_err());
......
......@@ -154,7 +154,7 @@ impl<'r, 'p> SignalReceiver<'r, 'p> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{dbus_interface, dbus_proxy, fdo};
use crate::{azync::ProxyBuilder, dbus_interface, dbus_proxy, fdo};
use std::{
cell::RefCell,
rc::Rc,
......@@ -172,10 +172,10 @@ mod tests {
let conn = Connection::new_session()?;
let mut receiver = SignalReceiver::new(conn.clone());
let proxy1 = MultiSignalProxyBuilder::new(&conn)?
let proxy1: MultiSignalProxy<'_> = ProxyBuilder::new(&conn.clone().into())
.destination("org.freedesktop.zbus.MultiSignal")
.path("/org/freedesktop/zbus/MultiSignal/1")?
.build()?;
.build();
let proxy1_str = Arc::new(Mutex::new(None));
let clone = proxy1_str.clone();
proxy1.connect_some_signal(move |s| {
......@@ -185,10 +185,10 @@ mod tests {
})?;
receiver.receive_for(&proxy1)?;
let proxy2 = MultiSignalProxyBuilder::new(&conn)?
let proxy2: MultiSignalProxy<'_> = ProxyBuilder::new(&conn.clone().into())
.destination("org.freedesktop.zbus.MultiSignal")
.path("/org/freedesktop/zbus/MultiSignal/2")?
.build()?;
.build();
let proxy2_str = Arc::new(Mutex::new(None));
let clone = proxy2_str.clone();
proxy2.connect_some_signal(move |s| {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment