diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2012-12-14 18:23:39 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-19 03:49:11 +0100 |
commit | 272a8649511c6a0ab782ce434b0f8dca7294493c (patch) | |
tree | 92f9a5969a2e92078979fbdb816faeccdf570990 /gdbus | |
parent | ebae80d0e56a216a6f50e5792d42dd721889f621 (diff) | |
download | connman-272a8649511c6a0ab782ce434b0f8dca7294493c.tar.gz connman-272a8649511c6a0ab782ce434b0f8dca7294493c.tar.bz2 connman-272a8649511c6a0ab782ce434b0f8dca7294493c.zip |
gdbus: Use a GPtrArray for the match rules
Diffstat (limited to 'gdbus')
-rw-r--r-- | gdbus/client.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/gdbus/client.c b/gdbus/client.c index c489c601..eca5c10a 100644 --- a/gdbus/client.c +++ b/gdbus/client.c @@ -36,7 +36,7 @@ struct GDBusClient { char *service_name; char *unique_name; char *base_path; - char *match_rules[4]; + GPtrArray *match_rules; DBusPendingCall *pending_call; GDBusWatchFunction connect_func; void *connect_data; @@ -765,7 +765,7 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection, const char *service, const char *path) { GDBusClient *client; - int i; + unsigned int i; if (connection == NULL) return NULL; @@ -786,26 +786,31 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection, get_name_owner(client, client->service_name); - client->match_rules[0] = g_strdup_printf("type='signal',sender='%s'," - "path='%s',interface='%s'," + client->match_rules = g_ptr_array_new_full(4, g_free); + + g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal'," + "sender='%s',path='%s',interface='%s'," "member='NameOwnerChanged',arg0='%s'", DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, client->service_name); - client->match_rules[1] = g_strdup_printf("type='signal',sender='%s'," + DBUS_INTERFACE_DBUS, client->service_name)); + g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal'," + "sender='%s'," "path='/',interface='%s.ObjectManager'," "member='InterfacesAdded'", - client->service_name, DBUS_INTERFACE_DBUS); - client->match_rules[2] = g_strdup_printf("type='signal',sender='%s'," + client->service_name, DBUS_INTERFACE_DBUS)); + g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal'," + "sender='%s'," "path='/',interface='%s.ObjectManager'," "member='InterfacesRemoved'", - client->service_name, DBUS_INTERFACE_DBUS); - client->match_rules[3] = g_strdup_printf("type='signal',sender='%s'," - "path_namespace='%s'", - client->service_name, client->base_path); + client->service_name, DBUS_INTERFACE_DBUS)); + g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal'," + "sender='%s',path_namespace='%s'", + client->service_name, client->base_path)); - for (i = 0; i < 4; i++) + for (i = 0; i < client->match_rules->len; i++) { modify_match(client->dbus_conn, "AddMatch", - client->match_rules[i]); + g_ptr_array_index(client->match_rules, i)); + } return g_dbus_client_ref(client); } @@ -822,7 +827,7 @@ GDBusClient *g_dbus_client_ref(GDBusClient *client) void g_dbus_client_unref(GDBusClient *client) { - int i; + unsigned int i; if (client == NULL) return; @@ -835,12 +840,13 @@ void g_dbus_client_unref(GDBusClient *client) dbus_pending_call_unref(client->pending_call); } - for (i = 0; i < 4; i++) { + for (i = 0; i < client->match_rules->len; i++) { modify_match(client->dbus_conn, "RemoveMatch", - client->match_rules[i]); - g_free(client->match_rules[i]); + g_ptr_array_index(client->match_rules, i)); } + g_ptr_array_free(client->match_rules, TRUE); + dbus_connection_remove_filter(client->dbus_conn, message_filter, client); |