[][src]Attribute Macro zbus::dbus_proxy


Attribute macro for defining a D-Bus proxy (using zbus Proxy).

The macro must be applied on a trait T. A matching impl T will provide the proxy. The proxy instance can be created with the associated new() or new_for() methods. The former doesn't take any argument and uses the default service name and path. The later allows you to specify both.

Each trait method will be expanded to call to the associated D-Bus remote interface.

Trait methods accept dbus_proxy attributes:

  • name - override the D-Bus name (pascal case form by default)

  • property - expose the method as a property. If the method takes an argument, it must be a setter, with a set_ prefix. Otherwise, it's a getter.

  • signal - not yet implemented.

(the expanded impl also provides an introspect() method, for convenience)


use zbus_macros::dbus_proxy;
use zbus::{Connection, Result, fdo};
use zvariant::Value;

    interface = "org.test.SomeIface",
    default_service = "org.test.SomeService",
    default_path = "/org/test/SomeObject"
trait SomeIface {
    fn do_this(&self, with: &str, some: u32, arg: &Value) -> Result<bool>;

    fn a_property(&self) -> fdo::Result<String>;

    fn set_a_property(&self, a_property: &str) -> fdo::Result<()>;

let connection = Connection::new_session()?;
let proxy = SomeIfaceProxy::new(&connection)?;
let _ = proxy.do_this("foo", 32, &Value::new(true));
let _ = proxy.set_a_property("val");

zbus_polkit is a good example of how to bind a real D-Bus API.