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
20extern crate libc;
21
22#[allow(missing_docs)]
23extern crate libdbus_sys as ffi;
24
25pub use crate::message::{Message, MessageType};
26
27pub mod message;
28
29pub mod ffidisp;
30
31mod error;
32pub use error::{Error, MethodErr};
33
34pub mod channel;
35
36mod filters;
37
38pub mod blocking;
39
40#[cfg(feature = "futures")]
41pub mod nonblock;
42
43pub mod strings;
44pub use crate::strings::{Signature, Path};
45
46pub mod arg;
47
48// pub mod tree;
49
50static INITDBUS: std::sync::Once = std::sync::Once::new();
51
52use std::ffi::{CString, CStr};
53use std::os::raw::c_char;
54
55fn init_dbus() {
56 INITDBUS.call_once(|| {
57 if unsafe { ffi::dbus_threads_init_default() } == 0 {
58 panic!("Out of memory when trying to initialize D-Bus library!");
59 }
60 });
61}
62
63fn c_str_to_slice(c: & *const c_char) -> Option<&str> {
64 if c.is_null() { None }
65 else { std::str::from_utf8( unsafe { CStr::from_ptr(*c).to_bytes() }).ok() }
66}
67
68fn to_c_str(n: &str) -> CString { CString::new(n.as_bytes()).unwrap() }
69