pub struct Channel { /* private fields */ }
Expand description
Low-level connection - handles read/write to the socket
You probably do not need to worry about this as you would typically use the various blocking and non-blocking “Connection” structs instead.
This version avoids dbus_connection_dispatch, and thus avoids callbacks from that function. Instead the same functionality is implemented in the various blocking and non-blocking “Connection” components.
Blocking operations are clearly marked as such, although if you try to access the connection from several threads at the same time, blocking might occur due to an internal mutex inside the dbus library.
Implementations
sourceimpl Channel
impl Channel
sourcepub fn get_private(bus: BusType) -> Result<Channel, Error>
pub fn get_private(bus: BusType) -> Result<Channel, Error>
Creates a new D-Bus connection.
Blocking: until the connection is up and running.
sourcepub fn open_private(address: &str) -> Result<Channel, Error>
pub fn open_private(address: &str) -> Result<Channel, Error>
Creates a new D-Bus connection to a remote address.
Note: for all common cases (System / Session bus) you probably want “get_private” instead.
Blocking: until the connection is established.
sourcepub fn register(&mut self) -> Result<(), Error>
pub fn register(&mut self) -> Result<(), Error>
Registers a new D-Bus connection with the bus.
Note: get_private
does this automatically, useful with open_private
Blocking: until a “Hello” response is received from the server.
sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Gets whether the connection is currently open.
sourcepub fn unique_name(&self) -> Option<&str>
pub fn unique_name(&self) -> Option<&str>
Get the connection’s unique name.
It’s usually something like “:1.54”
sourcepub fn send(&self, msg: Message) -> Result<u32, ()>
pub fn send(&self, msg: Message) -> Result<u32, ()>
Puts a message into libdbus out queue, and tries to send it.
Returns a serial number than can be used to match against a reply.
Note: usually the message is sent when this call happens, but in case internal D-Bus buffers are full, it will be left in the out queue. Call “flush” or “read_write” to retry flushing the out queue.
sourcepub fn send_with_reply_and_block(
&self,
msg: Message,
timeout: Duration
) -> Result<Message, Error>
pub fn send_with_reply_and_block(
&self,
msg: Message,
timeout: Duration
) -> Result<Message, Error>
Sends a message over the D-Bus and waits for a reply. This is used for method calls.
Blocking: until a reply is received or the timeout expires.
Note: In case of an error reply, this is returned as an Err(), not as a Ok(Message) with the error type.
Note: In case pop_message and send_with_reply_and_block is called in parallel from different threads, they might race to retreive the reply message from the internal queue.
sourcepub fn flush(&self)
pub fn flush(&self)
Flush the queue of outgoing messages.
Blocking: until the outgoing queue is empty.
sourcepub fn read_write(&self, timeout: Option<Duration>) -> Result<(), ()>
pub fn read_write(&self, timeout: Option<Duration>) -> Result<(), ()>
Read and write to the connection.
Incoming messages are put in the internal queue, outgoing messages are written.
Blocking: If there are no messages, for up to timeout, or forever if timeout is None. For non-blocking behaviour, set timeout to Some(0).
sourcepub fn has_messages_to_send(&self) -> bool
pub fn has_messages_to_send(&self) -> bool
Gets whether the output message buffer is non-empty
sourcepub fn pop_message(&self) -> Option<Message>
pub fn pop_message(&self) -> Option<Message>
Removes a message from the incoming queue, or returns None if the queue is empty.
Use “read_write” first, so that messages are put into the incoming queue. For unhandled messages, please call MessageDispatcher::default_dispatch to return default replies for method calls.
sourcepub fn blocking_pop_message(
&self,
timeout: Duration
) -> Result<Option<Message>, Error>
pub fn blocking_pop_message(
&self,
timeout: Duration
) -> Result<Option<Message>, Error>
Removes a message from the incoming queue, or waits until timeout if the queue is empty.
sourcepub fn set_watch_enabled(&mut self, enable: bool)
pub fn set_watch_enabled(&mut self, enable: bool)
Enables watch tracking, a prequisite for calling watch.
(In theory, this could panic in case libdbus ever changes to listen to something else than one file descriptor, but this should be extremely unlikely to ever happen.)