Struct zbus::Proxy [−][src]
pub struct Proxy<'a> { /* fields omitted */ }Expand description
A client-side interface proxy.
A Proxy is a helper to interact with an interface on a remote object.
Example
use std::result::Result; use std::error::Error; use zbus::{Connection, Proxy}; fn main() -> Result<(), Box<dyn Error>> { let connection = Connection::session()?; let p = Proxy::new( &connection, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", )?; // owned return value let _id: String = p.call("GetId", &())?; // borrowed return value let _id: &str = p.call_method("GetId", &())?.body()?; Ok(()) }
Note
It is recommended to use the dbus_proxy macro, which provides a more convenient and
type-safe façade Proxy derived from a Rust trait.
Current limitations:
At the moment, Proxy doesn’t:
- cache properties
- track the current name owner
- prevent auto-launching
Implementations
Create a new Proxy for the given destination/path/interface.
Create a new Proxy for the given destination/path/interface, taking ownership of all
passed arguments.
Get a reference to the associated connection.
Get a reference to the destination service name.
Get a reference to the object path.
Get a reference to the interface.
Introspect the associated object, and return the XML description.
See the xml module for parsing the result.
Get the property property_name.
Get the property value from the cache or call the Get method of the
org.freedesktop.DBus.Properties interface.
Set the property property_name.
Effectively, call the Set method of the org.freedesktop.DBus.Properties interface.
Call a method and return the reply.
Typically, you would want to use call method instead. Use this method if you need to
deserialize the reply message manually (this way, you can avoid the memory
allocation/copying, by deserializing the reply to an unowned type).
Call a method and return the reply body.
Use call_method instead if you need to deserialize the reply manually/separately.
pub fn connect_signal<M, H>(
&self,
signal_name: M,
handler: H
) -> Result<SignalHandlerId> where
M: TryInto<MemberName<'static>>,
M::Error: Into<Error>,
H: FnMut(&Message) -> Result<()> + Send + 'static,
pub fn connect_signal<M, H>(
&self,
signal_name: M,
handler: H
) -> Result<SignalHandlerId> where
M: TryInto<MemberName<'static>>,
M::Error: Into<Error>,
H: FnMut(&Message) -> Result<()> + Send + 'static,
Register a handler for signal named signal_name.
Once a handler is successfully registered, call Self::next_signal to wait for the next
signal to arrive and be handled by its registered handler. A unique ID for the handler is
returned, which can be used to deregister this handler using Self::disconnect_signal
method.
Errors
This method can fail if addition of the relevant match rule on the bus fails. You can
safely unwrap the Result if you’re certain that associated connection is not a bus
connection.
Deregister the signal handler with the ID handler_id.
This method returns Ok(true) if a handler with the id handler_id is found and removed;
Ok(false) otherwise.
Errors
This method can fail if removal of the relevant match rule on the bus fails. You can
safely unwrap the Result if you’re certain that associated connection is not a bus
connection.
pub fn connect_property_changed<H>(
&self,
property_name: &'static str,
handler: H
) -> Result<PropertyChangedHandlerId> where
H: FnMut(Option<&Value<'_>>) + Send + 'static,
pub fn connect_property_changed<H>(
&self,
property_name: &'static str,
handler: H
) -> Result<PropertyChangedHandlerId> where
H: FnMut(Option<&Value<'_>>) + Send + 'static,
Register a changed handler for the property named property_name.
Once a handler is successfully registered, call Self::next_signal to wait for the next
signal to arrive and be handled by its registered handler. A unique ID for the handler is
returned, which can be used to deregister this handler using
Self::disconnect_property_changed method.
Errors
The current implementation requires cached properties. It returns an Error::Unsupported
if the proxy isn’t setup with cache.
pub fn disconnect_property_changed(
&self,
handler_id: PropertyChangedHandlerId
) -> Result<bool>
pub fn disconnect_property_changed(
&self,
handler_id: PropertyChangedHandlerId
) -> Result<bool>
Deregister the property handler with the ID handler_id.
This method returns Ok(true) if a handler with the id handler_id is found and removed;
Ok(false) otherwise.
Receive and handle the next incoming signal on the associated connection.
This method will wait for signal messages on the associated connection and call any
handlers registered through the Self::connect_signal method. Signal handlers can be
registered and deregistered from another threads during the call to this method.
If the signal message was handled by a handler, Ok(None) is returned. Otherwise, the
received message is returned.
Errors
Apart from general I/O errors that can result from socket communications, calling this method will also result in an error if the destination service has not yet registered its well-known name with the bus (assuming you’re using the well-known name as destination).
Handle the provided signal message.
Call any handlers registered through the Self::connect_signal method for the provided
signal message.
If no errors are encountered, Ok(true) is returned if a handler was found and called for,
the signal; Ok(false) otherwise.
Get the underlying async Proxy, consuming self.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Proxy<'a>
impl<'a> !UnwindSafe for Proxy<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more