Struct tokio_dbus::Connection
source · pub struct Connection { /* private fields */ }
Expand description
An asynchronous D-Bus client.
Implementations§
source§impl Connection
impl Connection
sourcepub async fn session_bus() -> Result<Self>
pub async fn session_bus() -> Result<Self>
Shorthand for connecting the client to the system bus using the default configuration.
sourcepub async fn system_bus() -> Result<Self>
pub async fn system_bus() -> Result<Self>
Shorthand for connecting the client to the system bus using the default configuration.
sourcepub async fn wait(&mut self) -> Result<()>
pub async fn wait(&mut self) -> Result<()>
Wait for the next incoming message on this connection.
This is the main entry of this connection, and is required to call to have it make progress when passing D-Bus messages.
If you just want to block while sending messages, use flush()
instead.
§Examples
use tokio_dbus::{Connection, Message};
let mut c = Connection::session_bus().await?;
c.wait().await?;
let message: Message<'_> = c.last_message()?;
sourcepub async fn wait_no_deferred(&mut self) -> Result<()>
pub async fn wait_no_deferred(&mut self) -> Result<()>
Wait for the next incoming message on this connection ignoring messages
that have been deferred through RecvBuf::defer
.
§Examples
use tokio_dbus::{Connection, Message};
let mut c = Connection::session_bus().await?;
c.wait_no_deferred().await?;
let message: Message<'_> = c.last_message()?;
sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
Flush all outgoing messages and return when the send buffer is empty.
§Examples
use tokio_dbus::Connection;
let mut c = Connection::session_bus().await?;
c.flush().await?;
sourcepub fn method_call<'a>(
&mut self,
path: &'a ObjectPath,
member: &'a str
) -> Message<'a>
pub fn method_call<'a>( &mut self, path: &'a ObjectPath, member: &'a str ) -> Message<'a>
Construct a new Message
corresponding to a method call.
sourcepub fn write_message(&mut self, message: Message<'_>) -> Result<()>
pub fn write_message(&mut self, message: Message<'_>) -> Result<()>
sourcepub fn last_message(&self) -> Result<Message<'_>>
pub fn last_message(&self) -> Result<Message<'_>>
sourcepub fn buffers(&mut self) -> (&RecvBuf, &mut SendBuf, &mut BodyBuf)
pub fn buffers(&mut self) -> (&RecvBuf, &mut SendBuf, &mut BodyBuf)
Access the underlying buffers of the connection.
The RecvBuf
instance is used to access messages received after a
call to wait()
, through the RecvBuf::last_message()
.
The returned BodyBuf
is the internal buffer that the client uses to
construct message bodies. It is empty when it’s returned.
This is useful, because it permits using all parts of the connection without running into borrowing issues.
For example, this wouldn’t work:
use tokio_dbus::{Connection, Message};
let mut c = Connection::session_bus().await?;
c.wait().await?;
let message: Message<'_> = c.last_message()?;
let m = message.method_return();
c.write_message(m);
Because calling write_message()
needs mutable access to the
Connection
.
We can address this by using buffers()
:
use tokio_dbus::{Connection, Message};
let mut c = Connection::session_bus().await?;
c.wait().await?;
let (recv, send, body) = c.buffers();
let message: Message<'_> = recv.last_message()?;
let m = message.method_return(send.next_serial()).with_body(body);
send.write_message(m);