Skip to content

Commit

Permalink
Add DBusPendingCall functions
Browse files Browse the repository at this point in the history
  • Loading branch information
albel727 committed Jun 11, 2017
1 parent 724429a commit 63e453c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -133,6 +136,9 @@ pub type DBusAddWatchFunction = Option<extern fn(watch: *mut DBusWatch, user_dat
pub type DBusRemoveWatchFunction = Option<extern fn(watch: *mut DBusWatch, user_data: *mut c_void)>;
pub type DBusWatchToggledFunction = Option<extern fn(watch: *mut DBusWatch, user_data: *mut c_void)>;

pub type DBusPendingCallNotifyFunction = Option<extern fn(pending: *mut DBusPendingCall, user_data: *mut c_void)>;
pub type DBusFreeFunction = Option<extern fn(memory: *mut c_void)>;

#[repr(C)]
pub struct DBusObjectPathVTable {
pub unregister_function: Option<extern fn(conn: *mut DBusConnection, user_data: *mut c_void)>,
Expand Down Expand Up @@ -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,
Expand All @@ -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<extern fn(memory: *mut c_void)>) -> 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<extern fn(memory: *mut c_void)>) -> 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);
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions src/pending.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 63e453c

Please sign in to comment.