diff --git a/src/ffi.rs b/src/ffi.rs index 02deae42..f8d9e7a7 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -6,6 +6,7 @@ pub type DBusConnection = c_void; pub type DBusMessage = c_void; pub type DBusCallback = extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> DBusHandlerResult; pub type DBusWatch = c_void; +pub type DBusPendingCall = c_void; #[repr(C)] #[derive(Debug, PartialEq, Copy, Clone)] @@ -34,6 +35,8 @@ pub const DBUS_TYPE_STRUCT: c_int = 'r' as c_int; pub const DBUS_TYPE_OBJECT_PATH: c_int = 'o' as c_int; pub const DBUS_TYPE_SIGNATURE: c_int = 'g' as c_int; +pub const DBUS_TIMEOUT_INFINITE: c_int = 0x7fffffff; + #[repr(C)] #[derive(Debug, PartialEq, Copy, Clone)] pub enum DBusNameFlag { @@ -133,6 +136,9 @@ pub type DBusAddWatchFunction = Option; pub type DBusWatchToggledFunction = Option; +pub type DBusPendingCallNotifyFunction = Option; +pub type DBusFreeFunction = Option; + #[repr(C)] pub struct DBusObjectPathVTable { pub unregister_function: Option, @@ -162,6 +168,8 @@ extern "C" { pub fn dbus_connection_set_exit_on_disconnect(conn: *mut DBusConnection, enable: u32); pub fn dbus_connection_send_with_reply_and_block(conn: *mut DBusConnection, message: *mut DBusMessage, timeout_milliseconds: c_int, error: *mut DBusError) -> *mut DBusMessage; + pub fn dbus_connection_send_with_reply(conn: *mut DBusConnection, + message: *mut DBusMessage, pending_return: *mut *mut DBusPendingCall, timeout_milliseconds: c_int) -> u32; pub fn dbus_connection_send(conn: *mut DBusConnection, message: *mut DBusMessage, serial: *mut u32) -> u32; pub fn dbus_connection_read_write_dispatch(conn: *mut DBusConnection, @@ -174,12 +182,12 @@ extern "C" { pub fn dbus_connection_list_registered(conn: *mut DBusConnection, parent_path: *const c_char, child_entries: *mut *mut *mut c_char) -> u32; pub fn dbus_connection_add_filter(conn: *mut DBusConnection, function: DBusHandleMessageFunction, - user_data: *mut c_void, free_data_function: Option) -> u32; + user_data: *mut c_void, free_data_function: DBusFreeFunction) -> u32; pub fn dbus_connection_remove_filter(conn: *mut DBusConnection, function: DBusHandleMessageFunction, user_data: *mut c_void) -> u32; pub fn dbus_connection_set_watch_functions(conn: *mut DBusConnection, add_function: DBusAddWatchFunction, remove_function: DBusRemoveWatchFunction, toggled_function: DBusWatchToggledFunction, - data: *mut c_void, free_data_function: Option) -> u32; + data: *mut c_void, free_data_function: DBusFreeFunction) -> u32; pub fn dbus_error_init(error: *mut DBusError); pub fn dbus_error_free(error: *mut DBusError); @@ -240,4 +248,10 @@ extern "C" { pub fn dbus_watch_get_flags(watch: *mut DBusWatch) -> c_uint; pub fn dbus_watch_get_unix_fd(watch: *mut DBusWatch) -> c_int; pub fn dbus_watch_handle(watch: *mut DBusWatch, flags: c_uint) -> u32; + + pub fn dbus_pending_call_ref(pending: *mut DBusPendingCall) -> *mut DBusPendingCall; + pub fn dbus_pending_call_unref(pending: *mut DBusPendingCall); + pub fn dbus_pending_call_set_notify(pending: *mut DBusPendingCall, n: DBusPendingCallNotifyFunction, + user_data: *mut c_void, free_user_data: DBusFreeFunction) -> u32; + pub fn dbus_pending_call_steal_reply(pending: *mut DBusPendingCall) -> *mut DBusMessage; } diff --git a/src/lib.rs b/src/lib.rs index ad95fd0b..73179bec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ use std::os::raw::c_char; #[allow(missing_docs)] mod ffi; mod message; +mod pending; mod prop; mod objpath; mod watch; diff --git a/src/pending.rs b/src/pending.rs new file mode 100644 index 00000000..2d54068c --- /dev/null +++ b/src/pending.rs @@ -0,0 +1,22 @@ +use super::ffi; + +pub struct PendingCall { + pc: *mut ffi::DBusPendingCall, +} + +impl Drop for PendingCall { + fn drop(&mut self) { + unsafe { ffi::dbus_pending_call_unref(self.pc) }; + } +} + +pub fn pending_call_from_ptr(ptr: *mut ffi::DBusMessage, add_ref: bool) -> PendingCall { + if add_ref { + unsafe { ffi::dbus_pending_call_ref(ptr) }; + } + PendingCall { pc: ptr } +} + +pub fn get_pending_call_ptr<'a>(pc: &PendingCall) -> *mut ffi::DBusPendingCall { + pc.pc +} \ No newline at end of file