1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! D-Bus bindings for Rust
//!
//! [D-Bus](http://dbus.freedesktop.org/) is a message bus, and is mainly used in Linux
//! for communication between processes. It is present by default on almost every
//! Linux distribution out there, and runs in two instances - one per session, and one
//! system-wide.
//!
//! In addition to the API documentation, which you're currently reading, you might want to
//! look in the examples directory, which contains many examples and some additional documents.
//! README.md also contains a few quick "getting started" examples (as well as information about
//! the `futures` and `no-string-validation` features).
//!
//! In addition to this crate, there are some companion crates:
//!  * dbus-tokio for integrating D-Bus with [Tokio](http://tokio.rs)
//!  * dbus-codegen for generating code from D-Bus introspection data
//!  * libdbus-sys contains the raw bindings to the C libdbus library.

#![warn(missing_docs)]

extern crate libc;

#[allow(missing_docs)]
extern crate libdbus_sys as ffi;

pub use crate::message::{Message, MessageType};

pub mod message;

pub mod ffidisp;

mod error;
pub use error::{Error, MethodErr};

pub mod channel;

mod filters;

pub mod blocking;

#[cfg(feature = "futures")]
pub mod nonblock;

pub mod strings;
pub use crate::strings::{Signature, Path};

pub mod arg;

// pub mod tree;

static INITDBUS: std::sync::Once = std::sync::Once::new();

use std::ffi::{CString, CStr};
use std::os::raw::c_char;

fn init_dbus() {
    INITDBUS.call_once(|| {
        if unsafe { ffi::dbus_threads_init_default() } == 0 {
            panic!("Out of memory when trying to initialize D-Bus library!");
        }
    });
}

fn c_str_to_slice(c: & *const c_char) -> Option<&str> {
    if c.is_null() { None }
    else { std::str::from_utf8( unsafe { CStr::from_ptr(*c).to_bytes() }).ok() }
}

fn to_c_str(n: &str) -> CString { CString::new(n.as_bytes()).unwrap() }