diff options
author | Søren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com> | 2009-04-13 18:58:19 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com> | 2009-04-13 18:58:19 -0400 |
commit | b11170fb38c6ddf0ee4666839796462c3d555708 (patch) | |
tree | 1aae4b14e57bfcea35f0a0176b82efbb63f4552f | |
parent | fd7007163770f5f5bb7ef699a5c4ee153958b441 (diff) |
Use a dispatch status function
-rw-r--r-- | dbus.c | 60 |
1 files changed, 49 insertions, 11 deletions
@@ -88,19 +88,9 @@ struct nul_dbus_type_t static void process_watch (DBusWatch *watch, int flags) { - DBusConnection *connection; - DBusMessage *msg; + g_print ("Handling\n"); dbus_watch_handle (watch, flags); - - connection = dbus_watch_get_data (watch); - - while ((msg = dbus_connection_borrow_message (connection))) - { - dbus_connection_return_message (connection, msg); - - dbus_connection_dispatch (connection); - } } static void @@ -665,6 +655,48 @@ make_ptr_array (gpointer first, va_list parameters) return array; } +static dbus_int32_t idle_id_slot = -1; + +static int +get_idle_id (DBusConnection *connection) +{ + if (idle_id_slot == -1) + dbus_connection_allocate_data_slot (&idle_id_slot); + + return (int)dbus_connection_get_data (connection, idle_id_slot); +} + +static void +set_idle_id (DBusConnection *connection, int id) +{ + if (idle_id_slot == -1) + dbus_connection_allocate_data_slot (&idle_id_slot); + + dbus_connection_set_data (connection, idle_id_slot, (void *)id, NULL); +} + +static gboolean +do_dispatch (gpointer data) +{ + DBusConnection *connection = data; + + while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS) + ; + + set_idle_id (connection, 0); + + return FALSE; +} + +static void +on_dispatch_status_changed (DBusConnection *connection, + DBusDispatchStatus new_status, + void *data) +{ + if (!get_idle_id (connection)) + set_idle_id (connection, g_idle_add (do_dispatch, connection)); +} + static DBusConnection * ensure_connection (DBusConnection **connection, DBusBusType type, @@ -676,6 +708,10 @@ ensure_connection (DBusConnection **connection, if (*connection) { + dbus_connection_set_dispatch_status_function ( + *connection, + on_dispatch_status_changed, *connection, NULL); + dbus_connection_set_watch_functions ( *connection, add_watch, remove_watch, toggle_watch, @@ -686,6 +722,8 @@ ensure_connection (DBusConnection **connection, add_timeout, remove_timeout, toggle_timeout, *connection, NULL); } + + do_dispatch (*connection); } return *connection; |