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
#![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;
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() }