From 06232e2965ee02d62ca566fcbf5e805c571b574a Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Sun, 9 Aug 2009 09:04:15 +0300 Subject: dbus: Take advantage of the PA_HASHMAP_FOREACH macro. --- src/modules/dbus/iface-core.c | 64 ++++++++++++++----------------------- src/modules/module-stream-restore.c | 8 ++--- src/pulsecore/protocol-dbus.c | 30 +++++++---------- 3 files changed, 38 insertions(+), 64 deletions(-) diff --git a/src/modules/dbus/iface-core.c b/src/modules/dbus/iface-core.c index e40cb979..685ba63b 100644 --- a/src/modules/dbus/iface-core.c +++ b/src/modules/dbus/iface-core.c @@ -542,7 +542,7 @@ static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *ms /* The caller frees the array, but not the strings. */ static const char **get_cards(pa_dbusiface_core *c, unsigned *n) { const char **cards; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_card *card; @@ -556,10 +556,8 @@ static const char **get_cards(pa_dbusiface_core *c, unsigned *n) { cards = pa_xnew(const char *, *n); - for (i = 0, card = pa_hashmap_iterate(c->cards, &state, NULL); card; ++i, card = pa_hashmap_iterate(c->cards, &state, NULL)) - cards[i] = pa_dbusiface_card_get_path(card); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(card, c->cards, state) + cards[i++] = pa_dbusiface_card_get_path(card); return cards; } @@ -583,7 +581,7 @@ static void handle_get_cards(DBusConnection *conn, DBusMessage *msg, void *userd /* The caller frees the array, but not the strings. */ static const char **get_sinks(pa_dbusiface_core *c, unsigned *n) { const char **sinks; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_device *sink; @@ -597,10 +595,8 @@ static const char **get_sinks(pa_dbusiface_core *c, unsigned *n) { sinks = pa_xnew(const char *, *n); - for (i = 0, sink = pa_hashmap_iterate(c->sinks_by_index, &state, NULL); sink; ++i, sink = pa_hashmap_iterate(c->sinks_by_index, &state, NULL)) - sinks[i] = pa_dbusiface_device_get_path(sink); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(sink, c->sinks_by_index, state) + sinks[i++] = pa_dbusiface_device_get_path(sink); return sinks; } @@ -671,7 +667,7 @@ static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, voi /* The caller frees the array, but not the strings. */ static const char **get_sources(pa_dbusiface_core *c, unsigned *n) { const char **sources; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_device *source; @@ -685,10 +681,8 @@ static const char **get_sources(pa_dbusiface_core *c, unsigned *n) { sources = pa_xnew(const char *, *n); - for (i = 0, source = pa_hashmap_iterate(c->sources_by_index, &state, NULL); source; ++i, source = pa_hashmap_iterate(c->sources_by_index, &state, NULL)) - sources[i] = pa_dbusiface_device_get_path(source); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(source, c->sources_by_index, state) + sources[i++] = pa_dbusiface_device_get_path(source); return sources; } @@ -759,7 +753,7 @@ static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, v /* The caller frees the array, but not the strings. */ static const char **get_playback_streams(pa_dbusiface_core *c, unsigned *n) { const char **streams; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_stream *stream; @@ -773,10 +767,8 @@ static const char **get_playback_streams(pa_dbusiface_core *c, unsigned *n) { streams = pa_xnew(const char *, *n); - for (i = 0, stream = pa_hashmap_iterate(c->playback_streams, &state, NULL); stream; ++i, stream = pa_hashmap_iterate(c->playback_streams, &state, NULL)) - streams[i] = pa_dbusiface_stream_get_path(stream); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(stream, c->playback_streams, state) + streams[i++] = pa_dbusiface_stream_get_path(stream); return streams; } @@ -800,7 +792,7 @@ static void handle_get_playback_streams(DBusConnection *conn, DBusMessage *msg, /* The caller frees the array, but not the strings. */ static const char **get_record_streams(pa_dbusiface_core *c, unsigned *n) { const char **streams; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_stream *stream; @@ -814,10 +806,8 @@ static const char **get_record_streams(pa_dbusiface_core *c, unsigned *n) { streams = pa_xnew(const char *, *n); - for (i = 0, stream = pa_hashmap_iterate(c->record_streams, &state, NULL); stream; ++i, stream = pa_hashmap_iterate(c->record_streams, &state, NULL)) - streams[i] = pa_dbusiface_stream_get_path(stream); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(stream, c->record_streams, state) + streams[i++] = pa_dbusiface_stream_get_path(stream); return streams; } @@ -841,7 +831,7 @@ static void handle_get_record_streams(DBusConnection *conn, DBusMessage *msg, vo /* The caller frees the array, but not the strings. */ static const char **get_samples(pa_dbusiface_core *c, unsigned *n) { const char **samples; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_sample *sample; @@ -855,10 +845,8 @@ static const char **get_samples(pa_dbusiface_core *c, unsigned *n) { samples = pa_xnew(const char *, *n); - for (i = 0, sample = pa_hashmap_iterate(c->samples, &state, NULL); sample; ++i, sample = pa_hashmap_iterate(c->samples, &state, NULL)) - samples[i] = pa_dbusiface_sample_get_path(sample); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(sample, c->samples, state) + samples[i++] = pa_dbusiface_sample_get_path(sample); return samples; } @@ -882,7 +870,7 @@ static void handle_get_samples(DBusConnection *conn, DBusMessage *msg, void *use /* The caller frees the array, but not the strings. */ static const char **get_modules(pa_dbusiface_core *c, unsigned *n) { const char **modules; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_module *module; @@ -896,10 +884,8 @@ static const char **get_modules(pa_dbusiface_core *c, unsigned *n) { modules = pa_xnew(const char *, *n); - for (i = 0, module = pa_hashmap_iterate(c->modules, &state, NULL); module; ++i, module = pa_hashmap_iterate(c->modules, &state, NULL)) - modules[i] = pa_dbusiface_module_get_path(module); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(module, c->modules, state) + modules[i++] = pa_dbusiface_module_get_path(module); return modules; } @@ -923,7 +909,7 @@ static void handle_get_modules(DBusConnection *conn, DBusMessage *msg, void *use /* The caller frees the array, but not the strings. */ static const char **get_clients(pa_dbusiface_core *c, unsigned *n) { const char **clients; - unsigned i; + unsigned i = 0; void *state = NULL; pa_dbusiface_client *client; @@ -937,10 +923,8 @@ static const char **get_clients(pa_dbusiface_core *c, unsigned *n) { clients = pa_xnew(const char *, *n); - for (i = 0, client = pa_hashmap_iterate(c->clients, &state, NULL); client; ++i, client = pa_hashmap_iterate(c->clients, &state, NULL)) - clients[i] = pa_dbusiface_client_get_path(client); - - pa_assert(i == *n); + PA_HASHMAP_FOREACH(client, c->clients, state) + clients[i++] = pa_dbusiface_client_get_path(client); return clients; } diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index bccdf938..e9063031 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -553,10 +553,8 @@ static const char **get_entries(struct userdata *u, unsigned *n) { entries = pa_xnew(const char *, *n); - while ((de = pa_hashmap_iterate(u->dbus_entries, &state, NULL))) { - entries[i] = de->object_path; - ++i; - } + PA_HASHMAP_FOREACH(de, u->dbus_entries, state) + entries[i++] = de->object_path; return entries; } @@ -1747,7 +1745,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio struct dbus_entry *de; void *state = NULL; - while ((de = pa_hashmap_iterate(u->dbus_entries, &state, NULL))) { + PA_HASHMAP_FOREACH(de, u->dbus_entries, state) { send_entry_removed_signal(de); dbus_entry_free(pa_hashmap_remove(u->dbus_entries, de->entry_name)); } diff --git a/src/pulsecore/protocol-dbus.c b/src/pulsecore/protocol-dbus.c index 06098673..5cbd0d91 100644 --- a/src/pulsecore/protocol-dbus.c +++ b/src/pulsecore/protocol-dbus.c @@ -186,7 +186,7 @@ static void update_introspection(struct object_entry *oe) { pa_strbuf_puts(buf, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); pa_strbuf_puts(buf, "\n"); - while ((iface_entry = pa_hashmap_iterate(oe->interfaces, &interfaces_state, NULL))) { + PA_HASHMAP_FOREACH(iface_entry, oe->interfaces, interfaces_state) { pa_dbus_method_handler *method_handler; pa_dbus_property_handler *property_handler; void *handlers_state = NULL; @@ -195,7 +195,7 @@ static void update_introspection(struct object_entry *oe) { pa_strbuf_printf(buf, " \n", iface_entry->name); - while ((method_handler = pa_hashmap_iterate(iface_entry->method_handlers, &handlers_state, NULL))) { + PA_HASHMAP_FOREACH(method_handler, iface_entry->method_handlers, handlers_state) { pa_strbuf_printf(buf, " \n", method_handler->method_name); for (i = 0; i < method_handler->n_arguments; ++i) @@ -278,7 +278,7 @@ static enum find_result_t find_handler_by_property(struct object_entry *obj_entr pa_assert(iface_entry); pa_assert(property_handler); - while ((*iface_entry = pa_hashmap_iterate(obj_entry->interfaces, &state, NULL))) { + PA_HASHMAP_FOREACH(*iface_entry, obj_entry->interfaces, state) { if ((*property_handler = pa_hashmap_get((*iface_entry)->property_handlers, property))) { if (dbus_message_has_member(msg, "Get")) return (*property_handler)->get_cb ? FOUND_GET_PROPERTY : PROPERTY_ACCESS_DENIED; @@ -303,7 +303,7 @@ static enum find_result_t find_handler_by_method(struct object_entry *obj_entry, pa_assert(iface_entry); pa_assert(method_handler); - while ((*iface_entry = pa_hashmap_iterate(obj_entry->interfaces, &state, NULL))) { + PA_HASHMAP_FOREACH(*iface_entry, obj_entry->interfaces, state) { if ((*method_handler = pa_hashmap_get((*iface_entry)->method_handlers, method))) return FOUND_METHOD; } @@ -497,7 +497,7 @@ static void register_object(pa_dbus_protocol *p, struct object_entry *obj_entry) pa_assert(p); pa_assert(obj_entry); - while ((conn_entry = pa_hashmap_iterate(p->connections, &state, NULL))) + PA_HASHMAP_FOREACH(conn_entry, p->connections, state) pa_assert_se(dbus_connection_register_object_path(conn_entry->connection, obj_entry->path, &vtable, p)); } @@ -652,7 +652,7 @@ static void unregister_object(pa_dbus_protocol *p, struct object_entry *obj_entr pa_assert(p); pa_assert(obj_entry); - while ((conn_entry = pa_hashmap_iterate(p->connections, &state, NULL))) + PA_HASHMAP_FOREACH(conn_entry, p->connections, state) pa_assert_se(dbus_connection_unregister_object_path(conn_entry->connection, obj_entry->path)); } @@ -742,7 +742,7 @@ static void register_all_objects(pa_dbus_protocol *p, DBusConnection *conn) { pa_assert(p); pa_assert(conn); - while ((obj_entry = pa_hashmap_iterate(p->objects, &state, NULL))) + PA_HASHMAP_FOREACH(obj_entry, p->objects, state) pa_assert_se(dbus_connection_register_object_path(conn, obj_entry->path, &vtable, p)); } @@ -777,7 +777,7 @@ static void unregister_all_objects(pa_dbus_protocol *p, DBusConnection *conn) { pa_assert(p); pa_assert(conn); - while ((obj_entry = pa_hashmap_iterate(p->objects, &state, NULL))) + PA_HASHMAP_FOREACH(obj_entry, p->objects, state) pa_assert_se(dbus_connection_unregister_object_path(conn, obj_entry->path)); } @@ -904,13 +904,7 @@ void pa_dbus_protocol_send_signal(pa_dbus_protocol *p, DBusMessage *signal) { pa_assert(signal); pa_assert(dbus_message_get_type(signal) == DBUS_MESSAGE_TYPE_SIGNAL); - /* XXX: We have to do some linear searching to find connections that want - * to receive the signal. This shouldn't be very significant performance - * problem, and adding an (object path, signal name) -> connection mapping - * would be likely to create substantial complexity. */ - - while ((conn_entry = pa_hashmap_iterate(p->connections, &state, NULL))) { - + PA_HASHMAP_FOREACH(conn_entry, p->connections, state) { if ((conn_entry->listening_for_all_signals /* Case 1: listening for all signals */ && (pa_idxset_get_by_data(conn_entry->all_signals_objects, dbus_message_get_path(signal), NULL) || pa_idxset_isempty(conn_entry->all_signals_objects))) @@ -943,10 +937,8 @@ const char **pa_dbus_protocol_get_extensions(pa_dbus_protocol *p, unsigned *n) { extensions = pa_xnew(const char *, *n); - while ((ext_name = pa_idxset_iterate(p->extensions, &state, NULL))) { - extensions[i] = ext_name; - ++i; - } + while ((ext_name = pa_idxset_iterate(p->extensions, &state, NULL))) + extensions[i++] = ext_name; return extensions; } -- cgit