Skip to main content

Connection

Struct Connection 

Source
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

Source

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.

Source

pub async fn session_bus() -> Result<Self>

Connect to the session bus and say Hello.

Source

pub async fn system_bus() -> Result<Self>

Connect to the system bus and say Hello.

Source

pub fn unique_name(&self) -> &str

The unique name the bus assigned to this connection, such as :1.42.

Source

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.

Source

pub fn default_timeout(&self) -> Option<Duration>

How long a call waits for its reply before failing, if limited.

See set_default_timeout().

Source

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.

Source

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.

Source

pub fn reply(&mut self, call: &Call, arguments: &Arguments) -> Result<()>

Reply to a method call.

Source

pub fn reply_error(&mut self, call: &Call, error: &Error) -> Result<()>

Reply to a method call with an error.

Source

pub async fn request_name( &mut self, name: &str, flags: NameFlag, ) -> Result<NameReply>

Request ownership of a well known name.

Source

pub async fn acquire_name(&mut self, name: &str, flags: NameFlag) -> Result<()>

Request ownership of a well known name, erroring unless it was acquired.

Source

pub async fn release_name(&mut self, name: &str) -> Result<()>

Release a well known name previously acquired.

Source

pub async fn add_match(&mut self, rule: &str) -> Result<()>

Add a match rule, so that the bus routes matching signals here.

Source

pub async fn remove_match(&mut self, rule: &str) -> Result<()>

Remove a match rule.

Source

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.

Source

pub async fn unwatch_name(&mut self, name: &str) -> Result<()>

Remove the interest registered by watch_name().

Source

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.

Source

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.

Source

pub async fn flush(&mut self) -> Result<()>

Write out everything which has been buffered for sending.

This is only needed before dropping the connection, since next() and call() both drive writes as a side effect.

Source

pub async fn next(&mut self) -> Result<Incoming>

Wait for the next method call or signal directed at this connection.

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.