/* 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;
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;
}
/* 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;
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;
}
/* 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;
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;
}
/* 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;
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;
}
/* 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;
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;
}
/* 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;
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;
}
/* 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;
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;
}
/* 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;
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;
}
pa_strbuf_puts(buf, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE);
pa_strbuf_puts(buf, "<node>\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;
pa_strbuf_printf(buf, " <interface name=\"%s\">\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, " <method name=\"%s\">\n", method_handler->method_name);
for (i = 0; i < method_handler->n_arguments; ++i)
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;
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;
}
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));
}
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));
}
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));
}
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));
}
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)))
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;
}