Struct dbus::blocking::LocalConnection
source · [−]pub struct LocalConnection { /* private fields */ }
Expand description
A connection to D-Bus, thread local + non-async version
Implementations
sourceimpl LocalConnection
impl LocalConnection
sourcepub fn new_session() -> Result<Self, Error>
pub fn new_session() -> Result<Self, Error>
Create a new connection to the session bus.
sourcepub fn new_system() -> Result<Self, Error>
pub fn new_system() -> Result<Self, Error>
Create a new connection to the system-wide bus.
sourcepub fn unique_name(&self) -> BusName<'_>
pub fn unique_name(&self) -> BusName<'_>
Get the connection’s unique name.
It’s usually something like “:1.54”
sourcepub 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>
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.
sourcepub fn request_name<'a, N: Into<BusName<'a>>>(
&self,
name: N,
allow_replacement: bool,
replace_existing: bool,
do_not_queue: bool
) -> Result<RequestNameReply, Error>
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.
sourcepub fn release_name<'a, N: Into<BusName<'a>>>(
&self,
name: N
) -> Result<ReleaseNameReply, Error>
pub fn release_name<'a, N: Into<BusName<'a>>>(
&self,
name: N
) -> Result<ReleaseNameReply, Error>
Release a previously requested name on the D-Bus.
sourcepub fn add_match<S: ReadAll, F>(
&self,
match_rule: MatchRule<'static>,
f: F
) -> Result<Token, Error>where
F: FnMut(S, &Self, &Message) -> bool + 'static,
pub fn add_match<S: ReadAll, F>(
&self,
match_rule: MatchRule<'static>,
f: F
) -> Result<Token, Error>where
F: FnMut(S, &Self, &Message) -> bool + 'static,
Adds a new match to the connection, and sets up a callback when this message arrives.
If multiple MatchRule
s 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”.
sourcepub fn add_match_no_cb(&self, match_str: &str) -> Result<(), Error>
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.
sourcepub fn remove_match_no_cb(&self, match_str: &str) -> Result<(), Error>
pub fn remove_match_no_cb(&self, match_str: &str) -> Result<(), Error>
Removes a match from the connection, without removing any callbacks.
sourcepub fn remove_match(&self, id: Token) -> Result<(), Error>
pub fn remove_match(&self, id: Token) -> Result<(), Error>
Removes a previously added match and callback from the connection.
sourcepub fn set_signal_match_mode(&self, match_all: bool)
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.
sourcepub fn process(&self, timeout: Duration) -> Result<bool, Error>
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.