typedef uint32_t role_indexes_t[NUM_ROLES];
+static const char* role_names[NUM_ROLES] = {
+ "none",
+ "video",
+ "music",
+ "game",
+ "event",
+ "phone",
+ "animation",
+ "production",
+ "a11y",
+};
+
struct userdata {
pa_core *core;
pa_module *module;
pa_log_debug(" Highest priority devices per-role:");
pa_log_debug(" Sinks:");
- dump_database_helper(u, ROLE_NONE, "None: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Video: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Music: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Game: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Event: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Phone: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Anim: ", TRUE);
- dump_database_helper(u, ROLE_NONE, "Prodtn:", TRUE);
- dump_database_helper(u, ROLE_NONE, "Ally: ", TRUE);
+ for (uint32_t role = ROLE_NONE; role < NUM_ROLES; ++role) {
+ char name[13];
+ uint32_t len = PA_MAX(12u, strlen(role_names[role]));
+ for (int i = 0; i < 12; ++i) name[i] = ' ';
+ strncpy(name, role_names[role], len);
+ name[len] = ':';
+ name[0] -= 32;
+ name[12] = '\0';
+ dump_database_helper(u, role, name, TRUE);
+ }
pa_log_debug(" Sources:");
- dump_database_helper(u, ROLE_NONE, "None: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Video: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Music: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Game: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Event: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Phone: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Anim: ", FALSE);
- dump_database_helper(u, ROLE_NONE, "Prodtn:", FALSE);
- dump_database_helper(u, ROLE_NONE, "Ally: ", FALSE);
+ for (uint32_t role = ROLE_NONE; role < NUM_ROLES; ++role) {
+ char name[13];
+ uint32_t len = PA_MAX(12u, strlen(role_names[role]));
+ for (int i = 0; i < 12; ++i) name[i] = ' ';
+ strncpy(name, role_names[role], len);
+ name[len] = ':';
+ name[0] -= 32;
+ name[12] = '\0';
+ dump_database_helper(u, role, name, FALSE);
+ }
pa_log_debug("Completed database dump");
}
if (strcmp(role, "") == 0)
return ROLE_NONE;
- if (strcmp(role, "video") == 0)
- return ROLE_VIDEO;
- if (strcmp(role, "music") == 0)
- return ROLE_MUSIC;
- if (strcmp(role, "game") == 0)
- return ROLE_GAME;
- if (strcmp(role, "event") == 0)
- return ROLE_EVENT;
- if (strcmp(role, "phone") == 0)
- return ROLE_PHONE;
- if (strcmp(role, "animation") == 0)
- return ROLE_ANIMATION;
- if (strcmp(role, "production") == 0)
- return ROLE_PRODUCTION;
- if (strcmp(role, "a11y") == 0)
- return ROLE_A11Y;
+ for (uint32_t i = ROLE_NONE; i < NUM_ROLES; ++i)
+ if (strcmp(role, role_names[i]) == 0)
+ return i;
+
return PA_INVALID_INDEX;
}
pa_datum_free(&key);
if ((e = read_entry(u, name))) {
- pa_tagstruct_puts(reply, name);
- pa_tagstruct_puts(reply, e->description);
+ pa_tagstruct_puts(reply, name);
+ pa_tagstruct_puts(reply, e->description);
+ pa_tagstruct_puts(reply, "audio-card"); /** @todo store the icon */
+ pa_tagstruct_put_boolean(reply, TRUE); /** @todo show current available */
+ pa_tagstruct_putu32(reply, NUM_ROLES);
+
+ for (uint32_t i = ROLE_NONE; i < NUM_ROLES; ++i) {
+ pa_tagstruct_puts(reply, role_names[i]);
+ pa_tagstruct_putu32(reply, e->priority[i]);
+ }
- pa_xfree(e);
+ pa_xfree(e);
}
pa_xfree(name);
#include <pulse/context.h>
#include <pulse/gccmacro.h>
+#include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
#include <pulsecore/pstream-util.h>
while (!pa_tagstruct_eof(t)) {
pa_ext_device_manager_info i;
+ pa_bool_t available;
memset(&i, 0, sizeof(i));
+ available = FALSE;
if (pa_tagstruct_gets(t, &i.name) < 0 ||
- pa_tagstruct_gets(t, &i.description) < 0) {
+ pa_tagstruct_gets(t, &i.description) < 0 ||
+ pa_tagstruct_gets(t, &i.icon) < 0 ||
+ pa_tagstruct_get_boolean(t, &available) < 0 ||
+ pa_tagstruct_getu32(t, &i.n_role_priorities) < 0) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
goto finish;
}
+ i.available = (uint8_t)available;
+
+ if (i.n_role_priorities > 0) {
+ uint32_t j;
+ i.role_priorities = pa_xnew0(pa_ext_device_manager_role_priority_info, i.n_role_priorities+1);
+
+ for (j = 0; j < i.n_role_priorities; j++) {
+
+ if (pa_tagstruct_gets(t, &i.role_priorities[j].role) < 0 ||
+ pa_tagstruct_getu32(t, &i.role_priorities[j].priority) < 0) {
+
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ pa_xfree(i.role_priorities);
+ goto finish;
+ }
+ }
+
+ /* Terminate with an extra NULL entry, just to make sure */
+ i.role_priorities[j].role = NULL;
+ i.role_priorities[j].priority = 0;
+ }
if (o->callback) {
pa_ext_device_manager_read_cb_t cb = (pa_ext_device_manager_read_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_xfree(i.role_priorities);
}
}