Struct zbus::blocking::object_server::ObjectServer

source ·
pub struct ObjectServer { /* private fields */ }
Expand description

A blocking wrapper of crate::ObjectServer.

§Example

This example exposes the org.myiface.Example.Quit method on the /org/zbus/path path.

use zbus::{blocking::Connection, interface};
use event_listener::{Event, Listener};

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 }
    }
}

#[interface(name = "org.myiface.Example")]
impl Example {
    // This will be the "Quit" D-Bus method.
    fn quit(&mut self) {
        self.quit_event.notify(1);
    }

    // See `interface` documentation to learn
    // how to expose properties & signals as well.
}

let connection = Connection::session()?;

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)?;

quit_listener.wait();

Implementations§

source§

impl ObjectServer

source

pub 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::blocking::connection::Builder::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.

source

pub 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.

source

pub 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 to emit signals outside of a dispatched handler:

struct MyIface;
#[interface(name = "org.myiface.MyIface")]
impl MyIface {
    #[zbus(signal)]
    async fn emit_signal(ctxt: &SignalContext<'_>) -> zbus::Result<()>;
}

let iface_ref = connection
    .object_server()
    .interface::<_, MyIface>(path)?;
block_on(MyIface::emit_signal(iface_ref.signal_context()))?;
source

pub fn inner(&self) -> &ObjectServer

Get a reference to the underlying async ObjectServer.

source

pub fn into_inner(self) -> ObjectServer

Get the underlying async ObjectServer, consuming self.

Trait Implementations§

source§

impl Debug for ObjectServer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ObjectServer> for ObjectServer

source§

fn from(server: ObjectServer) -> Self

Converts to this type from the input type.
source§

impl From<ObjectServer> for ObjectServer

source§

fn from(azync: ObjectServer) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more