aboutsummaryrefslogtreecommitdiff
path: root/gdbus
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2009-04-02 10:49:39 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2009-04-03 12:23:08 +0300
commit9cf730b6266aad1f11a72e80163e3e9e5c22260b (patch)
treef7818c29270e6523ca58938f7869b56d10811df8 /gdbus
parent167546e0a2e767ff0bb431570f83237a672054b0 (diff)
downloadbluez-9cf730b6266aad1f11a72e80163e3e9e5c22260b.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.
Diffstat (limited to 'gdbus')
-rw-r--r--gdbus/watch.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/gdbus/watch.c b/gdbus/watch.c
index 38bf3d75..2354ed5d 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;
}