diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2009-04-02 10:49:39 -0300 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2009-04-02 10:49:39 -0300 |
commit | 0f973bf056a939e3ae1b6c310aa916af11db9984 (patch) | |
tree | 79ebd88ec1fcb5c39b358c5982c1cdcf366390f3 | |
parent | fa8b3acb6a38efa00ec7fd7148b02acb174134f7 (diff) | |
download | obexd-0f973bf056a939e3ae1b6c310aa916af11db9984.tar.gz |
Fix gdbus watch function not handling multiple dbus connections.
gdbus was only adding a message filter for the very first connection given
by the user, this caused a bug in agent registration since it has a diffent
connection than previous watches it won't detect agent disappearing from the
bus.
-rw-r--r-- | gdbus/watch.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/gdbus/watch.c b/gdbus/watch.c index 38bf3d7..2354ed5 100644 --- a/gdbus/watch.c +++ b/gdbus/watch.c @@ -37,6 +37,9 @@ #define error(fmt...) #define debug(fmt...) +static DBusHandlerResult name_exit_filter(DBusConnection *connection, + DBusMessage *message, void *user_data); + static guint listener_id = 0; static GSList *name_listeners = NULL; @@ -62,13 +65,11 @@ static struct name_data *name_data_find(DBusConnection *connection, current != NULL; current = current->next) { struct name_data *data = current->data; - if (name == NULL && data->name == NULL) { - if (connection == data->connection) - return data; - } else { - if (strcmp(name, data->name) == 0) - return data; - } + if (connection != data->connection) + continue; + + if (name == NULL || g_str_equal(name, data->name)) + return data; } return NULL; @@ -165,10 +166,18 @@ static void name_data_remove(DBusConnection *connection, g_free(cb); } - if (!data->callbacks) { - name_listeners = g_slist_remove(name_listeners, data); - name_data_free(data); - } + if (data->callbacks) + return; + + name_listeners = g_slist_remove(name_listeners, data); + name_data_free(data); + + /* Remove filter if there are no listeners left for the connection */ + data = name_data_find(connection, NULL); + if (!data) + dbus_connection_remove_filter(connection, + name_exit_filter, + NULL); } static gboolean add_match(DBusConnection *connection, const char *name) @@ -263,6 +272,12 @@ static DBusHandlerResult name_exit_filter(DBusConnection *connection, name_listeners = g_slist_remove(name_listeners, data); name_data_free(data); + /* Remove filter if there no listener left for the connection */ + data = name_data_find(connection, NULL); + if (!data) + dbus_connection_remove_filter(connection, name_exit_filter, + NULL); + remove_match(connection, name); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -275,7 +290,7 @@ guint g_dbus_add_service_watch(DBusConnection *connection, const char *name, { int first; - if (!listener_id) { + if (!name_data_find(connection, NULL)) { if (!dbus_connection_add_filter(connection, name_exit_filter, NULL, NULL)) { error("dbus_connection_add_filter() failed"); @@ -354,6 +369,12 @@ remove: name_listeners = g_slist_remove(name_listeners, data); name_data_free(data); + /* Remove filter if there are no listeners left for the connection */ + data = name_data_find(connection, NULL); + if (!data) + dbus_connection_remove_filter(connection, name_exit_filter, + NULL); + return TRUE; } |