Struct zbus::ObjectServer
source · [−]pub struct ObjectServer { /* private fields */ }
Expand description
An object server, holding server-side D-Bus objects & interfaces.
Object servers hold interfaces on various object paths, and expose them over D-Bus.
All object paths will have the standard interfaces implemented on your behalf, such as
org.freedesktop.DBus.Introspectable
or org.freedesktop.DBus.Properties
.
Example
This example exposes the org.myiface.Example.Quit
method on the /org/zbus/path
path.
use zbus::{Connection, ObjectServer, dbus_interface};
use std::sync::Arc;
use event_listener::Event;
struct Example {
// Interfaces are owned by the ObjectServer. They can have
// `&mut self` methods.
quit_event: Event,
}
impl Example {
fn new(quit_event: Event) -> Self {
Self { quit_event }
}
}
#[dbus_interface(name = "org.myiface.Example")]
impl Example {
// This will be the "Quit" D-Bus method.
async fn quit(&mut self) {
self.quit_event.notify(1);
}
// See `dbus_interface` documentation to learn
// how to expose properties & signals as well.
}
let connection = Connection::session().await?;
let quit_event = Event::new();
let quit_listener = quit_event.listen();
let interface = Example::new(quit_event);
connection
.object_server()
.at("/org/zbus/path", interface)
.await?;
quit_listener.await;
Implementations
sourceimpl ObjectServer
impl ObjectServer
sourcepub async fn at<'p, P, I>(&self, path: P, iface: I) -> Result<bool> where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
pub async fn at<'p, P, I>(&self, path: P, iface: I) -> Result<bool> where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
Register a D-Bus Interface
at a given path. (see the example above)
Typically you’d want your interfaces to be registered immediately after the associated
connection is established and therefore use zbus::ConnectionBuilder::serve_at
instead.
However, there are situations where you’d need to register interfaces dynamically and that’s
where this method becomes useful.
If the interface already exists at this path, returns false.
sourcepub async fn remove<'p, I, P>(&self, path: P) -> Result<bool> where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
pub async fn remove<'p, I, P>(&self, path: P) -> Result<bool> where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
Unregister a D-Bus Interface
at a given path.
If there are no more interfaces left at that path, destroys the object as well. Returns whether the object was destroyed.
sourcepub async fn interface<'p, P, I>(&self, path: P) -> Result<InterfaceRef<I>> where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
pub async fn interface<'p, P, I>(&self, path: P) -> Result<InterfaceRef<I>> where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
Get the interface at the given path.
Errors
If the interface is not registered at the given path, Error::InterfaceNotFound
error is
returned.
Examples
The typical use of this is property changes outside of a dispatched handler:
struct MyIface(u32);
#[dbus_interface(name = "org.myiface.MyIface")]
impl MyIface {
#[dbus_interface(property)]
async fn count(&self) -> u32 {
self.0
}
}
let iface_ref = connection
.object_server()
.interface::<_, MyIface>(path).await?;
let mut iface = iface_ref.get_mut().await;
iface.0 = 42;
iface.count_changed(iface_ref.signal_context()).await?;
Trait Implementations
sourceimpl Debug for ObjectServer
impl Debug for ObjectServer
sourceimpl From<ObjectServer> for ObjectServer
impl From<ObjectServer> for ObjectServer
sourcefn from(server: ObjectServer) -> Self
fn from(server: ObjectServer) -> Self
Converts to this type from the input type.
sourceimpl From<ObjectServer> for ObjectServer
impl From<ObjectServer> for ObjectServer
sourcefn from(azync: ObjectServer) -> Self
fn from(azync: ObjectServer) -> Self
Converts to this type from the input type.
Auto Trait Implementations
impl !RefUnwindSafe for ObjectServer
impl Send for ObjectServer
impl Sync for ObjectServer
impl Unpin for ObjectServer
impl !UnwindSafe for ObjectServer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more