Struct zbus::Connection [−][src]
pub struct Connection { /* fields omitted */ }
Expand description
A D-Bus connection.
A connection to a D-Bus bus, or a direct peer.
Once created, the connection is authenticated and negotiated and messages can be sent or received, such as method calls or signals.
For higher-level message handling (typed functions, introspection, documentation reasons etc),
it is recommended to wrap the low-level D-Bus messages into Rust functions with the
dbus_proxy
and dbus_interface
macros instead of doing it directly on a Connection
.
Typically, a connection is made to the session bus with new_session
, or to the system bus
with new_system
. Then the connection is shared with the Proxy
and ObjectServer
instances.
Connection
implements Clone
and cloning it is a very cheap operation, as the underlying
data is not cloned. This makes it very convenient to share the connection between different
parts of your code. Connection
also implements std::marker::Sync
andstd::marker::Send
so you can send and share a connection instance across threads as well.
Connection
keeps an internal ringbuffer of incoming message. The maximum capacity of this
ringbuffer is configurable through the set_max_queued
method. The default size is 64. When
the buffer is full, messages are dropped to create room, starting from the oldest one.
Implementations
Create and open a D-Bus connection from a UnixStream
.
The connection may either be set up for a bus connection, or not (for peer-to-peer communications).
Upon successful return, the connection is fully established and negotiated: D-Bus messages can be sent and received.
Create a Connection
to the session/user message bus.
Create a Connection
to the system-wide message bus.
Create a Connection
for the given D-Bus address.
Create a server Connection
for the given UnixStream
and the server guid
.
The connection will wait for incoming client authentication handshake & negotiation messages, for peer-to-peer communications.
Upon successful return, the connection is fully established and negotiated: D-Bus messages can be sent and received.
Max number of messages to queue.
Set the max number of messages to queue.
Since typically you’d want to set this at instantiation time, this method takes ownership
of self
and returns an owned Connection
instance so you can use the builder pattern to
set the value.
Example
let conn = zbus::Connection::new_session()?.set_max_queued(30); assert_eq!(conn.max_queued(), 30); // Do something useful with `conn`..
The server’s GUID.
The unique name as assigned by the message bus or None
if not a message bus connection.
Fetch the next message from the connection.
Read from the connection until a message is received or an error is reached. Return the message on success.
Send msg
to the peer.
The connection sets a unique serial number on the message before sending it off.
On successfully sending off msg
, the assigned serial number is returned.
Send a method call.
Create a method-call message, send it over the connection, then wait for the reply. Incoming
messages are received through receive_message
until the matching method reply (error or
return) is received.
On successful reply, an Ok(Message)
is returned. On error, an Err
is returned. D-Bus
error replies are returned as MethodError
.
pub fn emit_signal<'p, B, E>(
&self,
destination: Option<&str>,
path: impl TryInto<ObjectPath<'p>, Error = E>,
iface: &str,
signal_name: &str,
body: &B
) -> Result<()> where
B: Serialize + Type,
E: Into<MessageError>,
[src]
pub fn emit_signal<'p, B, E>(
&self,
destination: Option<&str>,
path: impl TryInto<ObjectPath<'p>, Error = E>,
iface: &str,
signal_name: &str,
body: &B
) -> Result<()> where
B: Serialize + Type,
E: Into<MessageError>,
[src]Emit a signal.
Create a signal message, and send it over the connection.
Reply to a message.
Given an existing message (likely a method call), send a reply back to the caller with the
given body
.
Returns the message serial number.
Reply an error to a message.
Given an existing message (likely a method call), send an error reply back to the caller
with the given error_name
and body
.
Returns the message serial number.
Checks if self
is a connection to a message bus.
This will return false
for p2p connections.
Get a reference to the underlying async Connection.
Get the underlying async Connection, consuming self
.
Trait Implementations
Performs the conversion.
Performs the conversion.
Auto Trait Implementations
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V