pub struct Connection { /* private fields */ }Expand description
A connection to a bus which speaks in owned Rust values.
This is the driver used by generated clients and servers. It wraps a
tokio_dbus::Connection and takes care of matching replies to calls,
buffering the messages which arrive while a call is outstanding so that they
can be dispatched later.
Incoming messages are copied out of the receive buffer so that the connection stays usable while one is being handled. Use the low level API directly if that copy matters.
Implementations§
Source§impl Connection
impl Connection
Sourcepub const DEFAULT_TIMEOUT: Duration
pub const DEFAULT_TIMEOUT: Duration
The default for how long a call waits for its reply, matching the 25 seconds every other D-Bus implementation defaults to.
Sourcepub async fn session_bus() -> Result<Self>
pub async fn session_bus() -> Result<Self>
Connect to the session bus and say Hello.
Sourcepub async fn system_bus() -> Result<Self>
pub async fn system_bus() -> Result<Self>
Connect to the system bus and say Hello.
Sourcepub fn unique_name(&self) -> &str
pub fn unique_name(&self) -> &str
The unique name the bus assigned to this connection, such as :1.42.
Sourcepub fn set_default_timeout(&mut self, timeout: Option<Duration>)
pub fn set_default_timeout(&mut self, timeout: Option<Duration>)
Set how long a call waits for its reply before failing, or None to
wait forever.
The default is DEFAULT_TIMEOUT, since the bus does not time method
calls out on its own, a peer which is alive but not reading its socket
would otherwise hang the caller forever. The timeout applies to
everything which waits for a reply, including call() and the name
and match management methods.
A call which times out fails with an error for which
Error::is_timeout() is true and whose Error::name() is
org.freedesktop.DBus.Error.NoReply. The connection itself remains
usable, a reply which arrives after the deadline is discarded.
The timeout is driven by the Tokio timer, which must be enabled on the
runtime. #[tokio::main] enables it by default.
Sourcepub fn default_timeout(&self) -> Option<Duration>
pub fn default_timeout(&self) -> Option<Duration>
How long a call waits for its reply before failing, if limited.
Sourcepub async fn call(
&mut self,
destination: &str,
path: &ObjectPath,
interface: &str,
member: &str,
arguments: &Arguments,
) -> Result<Reply>
pub async fn call( &mut self, destination: &str, path: &ObjectPath, interface: &str, member: &str, arguments: &Arguments, ) -> Result<Reply>
Call a method and wait for its reply.
An error reply is turned into an Error carrying the name the remote
end used.
The call fails with a timeout error when no reply arrives within the
configured deadline, see
set_default_timeout().
§Cancellation
This method is cancel safe. If the future is dropped before it completes, the call itself may still reach the peer, but the connection remains usable and a reply which arrives later is discarded rather than surfaced or confused with the reply to another call.
Sourcepub fn emit(
&mut self,
path: &ObjectPath,
interface: &str,
member: &str,
arguments: &Arguments,
) -> Result<()>
pub fn emit( &mut self, path: &ObjectPath, interface: &str, member: &str, arguments: &Arguments, ) -> Result<()>
Emit a signal.
Signals are buffered and written out the next time the connection makes
progress. Call flush() to force them out.
Sourcepub fn reply(&mut self, call: &Call, arguments: &Arguments) -> Result<()>
pub fn reply(&mut self, call: &Call, arguments: &Arguments) -> Result<()>
Reply to a method call.
Sourcepub fn reply_error(&mut self, call: &Call, error: &Error) -> Result<()>
pub fn reply_error(&mut self, call: &Call, error: &Error) -> Result<()>
Reply to a method call with an error.
Sourcepub async fn request_name(
&mut self,
name: &str,
flags: NameFlag,
) -> Result<NameReply>
pub async fn request_name( &mut self, name: &str, flags: NameFlag, ) -> Result<NameReply>
Request ownership of a well known name.
Sourcepub async fn acquire_name(&mut self, name: &str, flags: NameFlag) -> Result<()>
pub async fn acquire_name(&mut self, name: &str, flags: NameFlag) -> Result<()>
Request ownership of a well known name, erroring unless it was acquired.
Sourcepub async fn release_name(&mut self, name: &str) -> Result<()>
pub async fn release_name(&mut self, name: &str) -> Result<()>
Release a well known name previously acquired.
Sourcepub async fn add_match(&mut self, rule: &str) -> Result<()>
pub async fn add_match(&mut self, rule: &str) -> Result<()>
Add a match rule, so that the bus routes matching signals here.
Sourcepub async fn remove_match(&mut self, rule: &str) -> Result<()>
pub async fn remove_match(&mut self, rule: &str) -> Result<()>
Remove a match rule.
Sourcepub async fn watch_name(&mut self, name: &str) -> Result<()>
pub async fn watch_name(&mut self, name: &str) -> Result<()>
Ask the bus to route NameOwnerChanged signals for name here.
Watching a name is how a client survives its peer restarting: the
signal announces both the name going away and it being claimed again.
Decode the incoming signal with NameOwnerChanged::decode, and pair
this with name_owner() to learn the initial state, since the signal
only reports changes.
Sourcepub async fn unwatch_name(&mut self, name: &str) -> Result<()>
pub async fn unwatch_name(&mut self, name: &str) -> Result<()>
Remove the interest registered by watch_name().
Sourcepub async fn name_owner(&mut self, name: &str) -> Result<Option<String>>
pub async fn name_owner(&mut self, name: &str) -> Result<Option<String>>
The unique name currently owning name, or None when the name has no
owner.
Sourcepub fn reply_unknown_method(&mut self, call: &Call) -> Result<()>
pub fn reply_unknown_method(&mut self, call: &Call) -> Result<()>
Reply to a method call which no dispatcher recognised.
The generated dispatch functions return false for a call which is
not theirs, so that several interfaces can be served from one
connection. Once every dispatcher has declined, this produces the
standard org.freedesktop.DBus.Error.UnknownMethod reply leaving the
call unanswered would leave the caller waiting for its timeout instead.