pub struct Proxy<'a> { /* private fields */ }
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::new_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
sourceimpl<'a> Proxy<'a>
impl<'a> Proxy<'a>
sourcepub fn new(
conn: &Connection,
destination: &'a str,
path: &'a str,
interface: &'a str
) -> Result<Self>
pub fn new(
conn: &Connection,
destination: &'a str,
path: &'a str,
interface: &'a str
) -> Result<Self>
Create a new Proxy
for the given destination/path/interface.
sourcepub fn new_owned(
conn: Connection,
destination: String,
path: String,
interface: String
) -> Result<Self>
pub fn new_owned(
conn: Connection,
destination: String,
path: String,
interface: String
) -> Result<Self>
Create a new Proxy
for the given destination/path/interface, taking ownership of all
passed arguments.
sourcepub fn connection(&self) -> &Connection
pub fn connection(&self) -> &Connection
Get a reference to the associated connection.
sourcepub fn destination(&self) -> &str
pub fn destination(&self) -> &str
Get a reference to the destination service name.
sourcepub fn introspect(&self) -> Result<String>
pub fn introspect(&self) -> Result<String>
Introspect the associated object, and return the XML description.
See the xml module for parsing the result.
sourcepub fn get_property<T>(&self, property_name: &str) -> Result<T> where
T: TryFrom<OwnedValue>,
pub fn get_property<T>(&self, property_name: &str) -> Result<T> where
T: TryFrom<OwnedValue>,
Get the property property_name
.
Effectively, call the Get
method of the org.freedesktop.DBus.Properties
interface.
sourcepub fn set_property<'t, T: 't>(
&self,
property_name: &str,
value: T
) -> Result<()> where
T: Into<Value<'t>>,
pub fn set_property<'t, T: 't>(
&self,
property_name: &str,
value: T
) -> Result<()> where
T: Into<Value<'t>>,
Set the property property_name
.
Effectively, call the Set
method of the org.freedesktop.DBus.Properties
interface.
sourcepub fn call_method<B>(&self, method_name: &str, body: &B) -> Result<Message> where
B: Serialize + Type,
pub fn call_method<B>(&self, method_name: &str, body: &B) -> Result<Message> where
B: Serialize + Type,
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).
sourcepub fn call<B, R>(&self, method_name: &str, body: &B) -> Result<R> where
B: Serialize + Type,
R: DeserializeOwned + Type,
pub fn call<B, R>(&self, method_name: &str, body: &B) -> Result<R> where
B: Serialize + Type,
R: DeserializeOwned + Type,
Call a method and return the reply body.
Use call_method
instead if you need to deserialize the reply manually/separately.
sourcepub fn connect_signal<H>(
&self,
signal_name: &'static str,
handler: H
) -> Result<()> where
H: FnMut(&Message) -> Result<()> + Send + 'static,
pub fn connect_signal<H>(
&self,
signal_name: &'static str,
handler: H
) -> Result<()> where
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.
If the associated connnection is to a bus, a match rule is added for the signal on the bus so that the bus sends us the signals.
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 connnection is not a bus
connection.
sourcepub fn disconnect_signal(&self, signal_name: &'static str) -> Result<bool>
pub fn disconnect_signal(&self, signal_name: &'static str) -> Result<bool>
Deregister the handler for the signal named signal_name
.
If the associated connnection is to a bus, the match rule is removed for the signal on the
bus so that the bus stops sending us the signal. This method returns Ok(true)
if a
handler was registered for signal_name
and was removed by this call; 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 connnection is not a bus
connection.
sourcepub fn next_signal(&self) -> Result<Option<Message>>
pub fn next_signal(&self) -> Result<Option<Message>>
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.
sourcepub fn handle_signal(&self, msg: &Message) -> Result<bool>
pub fn handle_signal(&self, msg: &Message) -> Result<bool>
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.
Trait Implementations
sourceimpl<'c> AsMut<Proxy<'c>> for IntrospectableProxy<'c>
impl<'c> AsMut<Proxy<'c>> for IntrospectableProxy<'c>
sourceimpl<'c> AsMut<Proxy<'c>> for PropertiesProxy<'c>
impl<'c> AsMut<Proxy<'c>> for PropertiesProxy<'c>
sourceimpl<'c> AsMut<Proxy<'c>> for ObjectManagerProxy<'c>
impl<'c> AsMut<Proxy<'c>> for ObjectManagerProxy<'c>
sourceimpl<'c> AsMut<Proxy<'c>> for MonitoringProxy<'c>
impl<'c> AsMut<Proxy<'c>> for MonitoringProxy<'c>
sourceimpl<'c> AsMut<Proxy<'c>> for StatsProxy<'c>
impl<'c> AsMut<Proxy<'c>> for StatsProxy<'c>
sourceimpl<'c> AsRef<Proxy<'c>> for IntrospectableProxy<'c>
impl<'c> AsRef<Proxy<'c>> for IntrospectableProxy<'c>
sourceimpl<'c> AsRef<Proxy<'c>> for PropertiesProxy<'c>
impl<'c> AsRef<Proxy<'c>> for PropertiesProxy<'c>
sourceimpl<'c> AsRef<Proxy<'c>> for ObjectManagerProxy<'c>
impl<'c> AsRef<Proxy<'c>> for ObjectManagerProxy<'c>
sourceimpl<'c> AsRef<Proxy<'c>> for MonitoringProxy<'c>
impl<'c> AsRef<Proxy<'c>> for MonitoringProxy<'c>
sourceimpl<'c> AsRef<Proxy<'c>> for StatsProxy<'c>
impl<'c> AsRef<Proxy<'c>> for StatsProxy<'c>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Proxy<'a>
impl<'a> Send for Proxy<'a>
impl<'a> Sync for Proxy<'a>
impl<'a> Unpin for Proxy<'a>
impl<'a> UnwindSafe for Proxy<'a>
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