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 session
, or to the system bus
with 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
Max number of messages to queue.
Set the max number of messages to queue.
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.
pub fn call_method<'d, 'p, 'i, 'm, D, P, I, M, B>(
&self,
destination: Option<D>,
path: P,
iface: Option<I>,
method_name: M,
body: &B
) -> Result<Arc<Message>> where
D: TryInto<BusName<'d>>,
P: TryInto<ObjectPath<'p>>,
I: TryInto<InterfaceName<'i>>,
M: TryInto<MemberName<'m>>,
D::Error: Into<Error>,
P::Error: Into<Error>,
I::Error: Into<Error>,
M::Error: Into<Error>,
B: Serialize + Type,
pub fn call_method<'d, 'p, 'i, 'm, D, P, I, M, B>(
&self,
destination: Option<D>,
path: P,
iface: Option<I>,
method_name: M,
body: &B
) -> Result<Arc<Message>> where
D: TryInto<BusName<'d>>,
P: TryInto<ObjectPath<'p>>,
I: TryInto<InterfaceName<'i>>,
M: TryInto<MemberName<'m>>,
D::Error: Into<Error>,
P::Error: Into<Error>,
I::Error: Into<Error>,
M::Error: Into<Error>,
B: Serialize + Type,
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<'d, 'p, 'i, 'm, D, P, I, M, B>(
&self,
destination: Option<D>,
path: P,
iface: I,
signal_name: M,
body: &B
) -> Result<()> where
D: TryInto<BusName<'d>>,
P: TryInto<ObjectPath<'p>>,
I: TryInto<InterfaceName<'i>>,
M: TryInto<MemberName<'m>>,
D::Error: Into<Error>,
P::Error: Into<Error>,
I::Error: Into<Error>,
M::Error: Into<Error>,
B: Serialize + Type,
pub fn emit_signal<'d, 'p, 'i, 'm, D, P, I, M, B>(
&self,
destination: Option<D>,
path: P,
iface: I,
signal_name: M,
body: &B
) -> Result<()> where
D: TryInto<BusName<'d>>,
P: TryInto<ObjectPath<'p>>,
I: TryInto<InterfaceName<'i>>,
M: TryInto<MemberName<'m>>,
D::Error: Into<Error>,
P::Error: Into<Error>,
I::Error: Into<Error>,
M::Error: Into<Error>,
B: Serialize + Type,
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