card-restore: Watch for profiles added after card creation.

This patch adds the ability to restore profiles if they are added after
card creation.

Adding profiles after card creation mainly happens for bluetooth cards.

Buglink: https://bugs.freedesktop.org/show_bug.cgi?id=65349
This commit is contained in:
poljar (Damir Jelić) 2013-07-25 16:39:01 +02:00 committed by Tanu Kaskinen
parent 0157f4b25f
commit b8bf331b39

View file

@ -64,7 +64,8 @@ struct userdata {
pa_module *module; pa_module *module;
pa_hook_slot *card_new_hook_slot; pa_hook_slot *card_new_hook_slot;
pa_hook_slot *card_put_hook_slot; pa_hook_slot *card_put_hook_slot;
pa_hook_slot *card_profile_hook_slot; pa_hook_slot *card_profile_changed_hook_slot;
pa_hook_slot *card_profile_added_hook_slot;
pa_hook_slot *port_offset_hook_slot; pa_hook_slot *port_offset_hook_slot;
pa_time_event *save_time_event; pa_time_event *save_time_event;
pa_database *database; pa_database *database;
@ -380,7 +381,7 @@ finish:
return PA_HOOK_OK; return PA_HOOK_OK;
} }
static pa_hook_result_t card_profile_change_callback(pa_core *c, pa_card *card, struct userdata *u) { static pa_hook_result_t card_profile_changed_callback(pa_core *c, pa_card *card, struct userdata *u) {
struct entry *entry; struct entry *entry;
pa_assert(card); pa_assert(card);
@ -403,6 +404,24 @@ static pa_hook_result_t card_profile_change_callback(pa_core *c, pa_card *card,
return PA_HOOK_OK; return PA_HOOK_OK;
} }
static pa_hook_result_t card_profile_added_callback(pa_core *c, pa_card_profile *profile, struct userdata *u) {
struct entry *entry;
pa_assert(profile);
if (!(entry = entry_read(u, profile->card->name)))
return PA_HOOK_OK;
if (pa_safe_streq(entry->profile, profile->name)) {
if (pa_card_set_profile(profile->card, profile->name, true) >= 0)
pa_log_info("Restored profile '%s' for card %s.", profile->name, profile->card->name);
}
entry_free(entry);
return PA_HOOK_OK;
}
static pa_hook_result_t port_offset_change_callback(pa_core *c, pa_device_port *port, struct userdata *u) { static pa_hook_result_t port_offset_change_callback(pa_core *c, pa_device_port *port, struct userdata *u) {
struct entry *entry; struct entry *entry;
pa_card *card; pa_card *card;
@ -487,7 +506,8 @@ int pa__init(pa_module*m) {
u->card_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u); u->card_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u);
u->card_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) card_put_hook_callback, u); u->card_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) card_put_hook_callback, u);
u->card_profile_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_change_callback, u); u->card_profile_changed_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_changed_callback, u);
u->card_profile_added_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u);
u->port_offset_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u); u->port_offset_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
u->hooks_connected = true; u->hooks_connected = true;
@ -526,7 +546,8 @@ void pa__done(pa_module*m) {
if (u->hooks_connected) { if (u->hooks_connected) {
pa_hook_slot_free(u->card_new_hook_slot); pa_hook_slot_free(u->card_new_hook_slot);
pa_hook_slot_free(u->card_put_hook_slot); pa_hook_slot_free(u->card_put_hook_slot);
pa_hook_slot_free(u->card_profile_hook_slot); pa_hook_slot_free(u->card_profile_changed_hook_slot);
pa_hook_slot_free(u->card_profile_added_hook_slot);
pa_hook_slot_free(u->port_offset_hook_slot); pa_hook_slot_free(u->port_offset_hook_slot);
} }