Add an object server
This is an interface / object server and associated derive macro.
See the test example in object_server.rs:
#[dbus_interface(interface = "org.freedesktop.MyIface")]
impl MyIfaceImpl {
fn ping(&mut self) -> u32 {
self.count += 1;
self.count
}
fn quit(&mut self, val: bool) {
*self.quit.borrow_mut() = val;
}
fn test_error(&self) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::Failed("error raised".to_string()))
}
}
Deriving from a trait (so proxy and interface would share the same trait for ex) wouldn't be convenient, since the interface implementation may freely have &self
or &mut self
. It may or may not throw Result
, and those Result
may be more strictly typed than zbus::Result
(as with fdo::Result
usage above). Iow, rust trait is more strict and specific to the implementation than a mere DBus interface.
I choose to give the ownership of the interface to the dispatcher, and using dynamic dispatch. This is considerably simpler than other solution I have seen elsewhere, and should make no measurable difference. Simplicity first. If you need shared state, you can have refcell fields, as done with quit
in the example.
It supports some introspection already, which allows to finally nicely interact with busctl/gbus/dfeet for ex.
There are certainly improvements in many area possible.