[go: up one dir, main page]

dbus/
lib.rs

1//! D-Bus bindings for Rust
2//!
3//! [D-Bus](http://dbus.freedesktop.org/) is a message bus, and is mainly used in Linux
4//! for communication between processes. It is present by default on almost every
5//! Linux distribution out there, and runs in two instances - one per session, and one
6//! system-wide.
7//!
8//! In addition to the API documentation, which you're currently reading, you might want to
9//! look in the examples directory, which contains many examples and some additional documents.
10//! README.md also contains a few quick "getting started" examples (as well as information about
11//! the `futures` and `no-string-validation` features).
12//!
13//! In addition to this crate, there are some companion crates:
14//!  * dbus-tokio for integrating D-Bus with [Tokio](http://tokio.rs)
15//!  * dbus-codegen for generating code from D-Bus introspection data
16//!  * libdbus-sys contains the raw bindings to the C libdbus library.
17
18#![warn(missing_docs)]
19
20// We have io-lifetimes and native-channel which are not ready yet
21// so for now allow them in the codebase and silence the warning
22#![allow(unexpected_cfgs)]
23
24extern crate libc;
25
26#[allow(missing_docs)]
27extern crate libdbus_sys as ffi;
28
29pub use crate::message::{Message, MessageType};
30
31pub mod message;
32
33pub mod ffidisp;
34
35mod error;
36pub use error::{Error, MethodErr, Result};
37
38pub mod channel;
39
40mod filters;
41
42pub mod blocking;
43
44#[cfg(feature = "futures")]
45pub mod nonblock;
46
47pub mod strings;
48pub use crate::strings::{Signature, Path};
49
50pub mod arg;
51
52// pub mod tree;
53
54static INITDBUS: std::sync::
55
56use std::ffi::{CString, CStr};
57use std::os::raw::c_char;
58
59fn init_dbus() {
60    INITDBUS.call_once(|| {
61        if unsafe { ffi::dbus_threads_init_default() } == 0 {
62            panic!("Out of memory when trying to initialize D-Bus library!");
63        }
64    });
65}
66
67fn c_str_to_slice(c: & *const c_char) -> Option<&str> {
68    if c.is_null() { None }
69    else { std::str::from_utf8( unsafe { CStr::from_ptr(*c).to_bytes() }).ok() }
70}
71
72fn to_c_str(n: &str) -> CString { CString::new(n.as_bytes()).unwrap() }