mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
dbus: Take advantage of the PA_HASHMAP_FOREACH macro.
This commit is contained in:
parent
fcf68752e6
commit
06232e2965
3 changed files with 38 additions and 64 deletions
|
|
@ -542,7 +542,7 @@ static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *ms
|
||||||
/* The caller frees the array, but not the strings. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_cards(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_cards(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **cards;
|
const char **cards;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_card *card;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(card, c->cards, state)
|
||||||
cards[i] = pa_dbusiface_card_get_path(card);
|
cards[i++] = pa_dbusiface_card_get_path(card);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return cards;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_sinks(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_sinks(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **sinks;
|
const char **sinks;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_device *sink;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(sink, c->sinks_by_index, state)
|
||||||
sinks[i] = pa_dbusiface_device_get_path(sink);
|
sinks[i++] = pa_dbusiface_device_get_path(sink);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return sinks;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_sources(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_sources(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **sources;
|
const char **sources;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_device *source;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(source, c->sources_by_index, state)
|
||||||
sources[i] = pa_dbusiface_device_get_path(source);
|
sources[i++] = pa_dbusiface_device_get_path(source);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return sources;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_playback_streams(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_playback_streams(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **streams;
|
const char **streams;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_stream *stream;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(stream, c->playback_streams, state)
|
||||||
streams[i] = pa_dbusiface_stream_get_path(stream);
|
streams[i++] = pa_dbusiface_stream_get_path(stream);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return streams;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_record_streams(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_record_streams(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **streams;
|
const char **streams;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_stream *stream;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(stream, c->record_streams, state)
|
||||||
streams[i] = pa_dbusiface_stream_get_path(stream);
|
streams[i++] = pa_dbusiface_stream_get_path(stream);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return streams;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_samples(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_samples(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **samples;
|
const char **samples;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_sample *sample;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(sample, c->samples, state)
|
||||||
samples[i] = pa_dbusiface_sample_get_path(sample);
|
samples[i++] = pa_dbusiface_sample_get_path(sample);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return samples;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_modules(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_modules(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **modules;
|
const char **modules;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_module *module;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(module, c->modules, state)
|
||||||
modules[i] = pa_dbusiface_module_get_path(module);
|
modules[i++] = pa_dbusiface_module_get_path(module);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return modules;
|
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. */
|
/* The caller frees the array, but not the strings. */
|
||||||
static const char **get_clients(pa_dbusiface_core *c, unsigned *n) {
|
static const char **get_clients(pa_dbusiface_core *c, unsigned *n) {
|
||||||
const char **clients;
|
const char **clients;
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
pa_dbusiface_client *client;
|
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);
|
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))
|
PA_HASHMAP_FOREACH(client, c->clients, state)
|
||||||
clients[i] = pa_dbusiface_client_get_path(client);
|
clients[i++] = pa_dbusiface_client_get_path(client);
|
||||||
|
|
||||||
pa_assert(i == *n);
|
|
||||||
|
|
||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -553,10 +553,8 @@ static const char **get_entries(struct userdata *u, unsigned *n) {
|
||||||
|
|
||||||
entries = pa_xnew(const char *, *n);
|
entries = pa_xnew(const char *, *n);
|
||||||
|
|
||||||
while ((de = pa_hashmap_iterate(u->dbus_entries, &state, NULL))) {
|
PA_HASHMAP_FOREACH(de, u->dbus_entries, state)
|
||||||
entries[i] = de->object_path;
|
entries[i++] = de->object_path;
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
@ -1747,7 +1745,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
|
||||||
struct dbus_entry *de;
|
struct dbus_entry *de;
|
||||||
void *state = NULL;
|
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);
|
send_entry_removed_signal(de);
|
||||||
dbus_entry_free(pa_hashmap_remove(u->dbus_entries, de->entry_name));
|
dbus_entry_free(pa_hashmap_remove(u->dbus_entries, de->entry_name));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE);
|
||||||
pa_strbuf_puts(buf, "<node>\n");
|
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_method_handler *method_handler;
|
||||||
pa_dbus_property_handler *property_handler;
|
pa_dbus_property_handler *property_handler;
|
||||||
void *handlers_state = NULL;
|
void *handlers_state = NULL;
|
||||||
|
|
@ -195,7 +195,7 @@ static void update_introspection(struct object_entry *oe) {
|
||||||
|
|
||||||
pa_strbuf_printf(buf, " <interface name=\"%s\">\n", iface_entry->name);
|
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);
|
pa_strbuf_printf(buf, " <method name=\"%s\">\n", method_handler->method_name);
|
||||||
|
|
||||||
for (i = 0; i < method_handler->n_arguments; ++i)
|
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(iface_entry);
|
||||||
pa_assert(property_handler);
|
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 ((*property_handler = pa_hashmap_get((*iface_entry)->property_handlers, property))) {
|
||||||
if (dbus_message_has_member(msg, "Get"))
|
if (dbus_message_has_member(msg, "Get"))
|
||||||
return (*property_handler)->get_cb ? FOUND_GET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
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(iface_entry);
|
||||||
pa_assert(method_handler);
|
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)))
|
if ((*method_handler = pa_hashmap_get((*iface_entry)->method_handlers, method)))
|
||||||
return FOUND_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(p);
|
||||||
pa_assert(obj_entry);
|
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_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(p);
|
||||||
pa_assert(obj_entry);
|
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_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(p);
|
||||||
pa_assert(conn);
|
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_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(p);
|
||||||
pa_assert(conn);
|
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_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(signal);
|
||||||
pa_assert(dbus_message_get_type(signal) == DBUS_MESSAGE_TYPE_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
|
PA_HASHMAP_FOREACH(conn_entry, p->connections, state) {
|
||||||
* 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))) {
|
|
||||||
|
|
||||||
if ((conn_entry->listening_for_all_signals /* Case 1: listening for all signals */
|
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_get_by_data(conn_entry->all_signals_objects, dbus_message_get_path(signal), NULL)
|
||||||
|| pa_idxset_isempty(conn_entry->all_signals_objects)))
|
|| 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);
|
extensions = pa_xnew(const char *, *n);
|
||||||
|
|
||||||
while ((ext_name = pa_idxset_iterate(p->extensions, &state, NULL))) {
|
while ((ext_name = pa_idxset_iterate(p->extensions, &state, NULL)))
|
||||||
extensions[i] = ext_name;
|
extensions[i++] = ext_name;
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue