[go: up one dir, main page]

Connection

Struct Connection 

Source
pub struct Connection { /* private fields */ }
Expand description

A connection to D-Bus, non-async version where callbacks are Send but not Sync.

Implementations§

Source§

impl Connection

Source

pub fn new_session() -> Result<Self, Error>

Create a new connection to the session bus.

Source

pub fn new_system() -> Result<Self, Error>

Create a new connection to the system-wide bus.

Source

pub fn unique_name(&self) -> BusName<'_>

Get the connection’s unique name.

It’s usually something like “:1.54”

Source

pub fn with_proxy<'a, 'b, D: Into<BusName<'a>>, P: Into<Path<'a>>>( &'b self, dest: D, path: P, timeout: Duration, ) -> Proxy<'a, &'b Self>

Create a convenience struct for easier calling of many methods on the same destination and path.

Source

pub fn request_name<'a, N: Into<BusName<'a>>>( &self, name: N, allow_replacement: bool, replace_existing: bool, do_not_queue: bool, ) -> Result<RequestNameReply, Error>

Request a name on the D-Bus.

For detailed information on the flags and return values, see the libdbus documentation.

Source

pub fn release_name<'a, N: Into<BusName<'a>>>( &self, name: N, ) -> Result<ReleaseNameReply, Error>

Release a previously requested name on the D-Bus.

Source

pub fn add_match<S: ReadAll, F>( &self, match_rule: MatchRule<'static>, f: F, ) -> Result<Token, Error>
where F: FnMut(S, &Self, &Message) -> bool + Send + 'static,

Adds a new match to the connection, and sets up a callback when this message arrives.

If multiple MatchRules match the same message, then by default only the first match will get the callback. This behaviour can be changed for signal messages by calling set_signal_match_mode.

The returned value can be used to remove the match. The match is also removed if the callback returns “false”.

Source

pub fn add_match_no_cb(&self, match_str: &str) -> Result<(), Error>

Adds a new match to the connection, without setting up a callback when this message arrives.

Source

pub fn remove_match_no_cb(&self, match_str: &str) -> Result<(), Error>

Removes a match from the connection, without removing any callbacks.

Source

pub fn remove_match(&self, id: Token) -> Result<(), Error>

Removes a previously added match and callback from the connection.

Source

pub fn set_signal_match_mode(&self, match_all: bool)

If true, configures the connection to send signal messages to all matching MatchRule filters added with add_match rather than just the first one. This comes with the following gotchas:

  • The messages might be duplicated, so the message serial might be lost (this is generally not a problem for signals).
  • Panicking inside a match callback might mess with other callbacks, causing them to be permanently dropped.
  • Removing other matches from inside a match callback is not supported.

This is false by default, for a newly-created connection.

Source

pub fn process(&self, timeout: Duration) -> Result<bool, Error>

Tries to handle an incoming message if there is one. If there isn’t one, it will wait up to timeout

This method only takes “&self” instead of “&mut self”, but it is a logic error to call it recursively and might lead to panics or deadlocks.

For SyncConnection: It is also a logic error to call this method from one thread, while calling this or other methods from other threads. This can lead to messages being lost.

Returns true when there was a message to process, and false when time out reached.

Source

pub fn channel(&self) -> &Channel

The channel for this connection

Trait Implementations§

Source§

impl BlockingSender for Connection

Source§

fn send_with_reply_and_block( &self, msg: Message, timeout: Duration, ) -> Result<Message, Error>

Sends a message over the D-Bus and blocks, waiting for a reply or a timeout. This is used for method calls. Read more
Source§

impl From<Channel> for Connection

Source§

fn from(channel: Channel) -> Connection

Converts to this type from the input type.
Source§

impl<S: ReadAll, F: FnMut(S, &Connection, &Message) -> bool + Send + 'static> MakeSignal<Box<dyn FnMut(Message, &Connection) -> bool + Send>, S, Connection> for F

Source§

fn make( self, mstr: String, ) -> Box<dyn FnMut(Message, &Connection) -> bool + Send + 'static>

Internal helper trait
Source§

impl MatchingReceiver for Connection

Source§

type F = Box<dyn FnMut(Message, &Connection) -> bool + Send>

Type of callback
Source§

fn start_receive(&self, m: MatchRule<'static>, f: Self::F) -> Token

Add a callback to be called in case a message matches. Read more
Source§

fn stop_receive(&self, id: Token) -> Option<(MatchRule<'static>, Self::F)>

Remove a previously added callback.
Source§

impl Sender for Connection

Source§

fn send(&self, msg: Message) -> Result<u32, ()>

Schedules a message for sending. Read more

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.