From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx> If a port availability update is received and the corresponding card profile was not previously registered, it means the profile has been created dynamically. Therefore, the D-Bus objects need to be updated. --- src/modules/dbus/iface-card.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/modules/dbus/iface-card.c b/src/modules/dbus/iface-card.c index 89e3988..4db1c01 100644 --- a/src/modules/dbus/iface-card.c +++ b/src/modules/dbus/iface-card.c @@ -60,6 +60,8 @@ struct pa_dbusiface_card { pa_card_profile *active_profile; pa_proplist *proplist; + pa_hook_slot *port_available_changed_slot; + pa_dbus_protocol *dbus_protocol; pa_subscription *subscription; }; @@ -478,6 +480,29 @@ static void subscription_cb(pa_core *core, pa_subscription_event_type_t t, uint3 } } +static pa_hook_result_t port_available_changed_cb(void *hook_data, void *call_data, void *slot_data) { + pa_core *core = hook_data; + pa_dbusiface_card *c = slot_data; + pa_device_port *port = call_data; + void *state; + pa_card_profile *profile; + + if (pa_hashmap_get(c->card->ports, port->name) != port) + return PA_HOOK_OK; + + PA_HASHMAP_FOREACH(profile, port->profiles, state) { + pa_dbusiface_card_profile *p; + + if (pa_hashmap_get(c->profiles, profile->name) != NULL) + continue; + + p = pa_dbusiface_card_profile_new(c, core, profile, c->next_profile_index++); + pa_hashmap_put(c->profiles, pa_dbusiface_card_profile_get_name(p), p); + } + + return PA_HOOK_OK; +} + pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card) { pa_dbusiface_card *c = NULL; pa_card_profile *profile; @@ -504,6 +529,9 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card) pa_assert_se(pa_dbus_protocol_add_interface(c->dbus_protocol, c->path, &card_interface_info, c) >= 0); + c->port_available_changed_slot = pa_hook_connect(&card->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], PA_HOOK_NORMAL, + port_available_changed_cb, c); + return c; } @@ -520,6 +548,8 @@ void pa_dbusiface_card_free(pa_dbusiface_card *c) { pa_assert_se(pa_dbus_protocol_remove_interface(c->dbus_protocol, c->path, card_interface_info.name) >= 0); + pa_hook_slot_free(c->port_available_changed_slot); + pa_hashmap_free(c->profiles, profile_free_cb, NULL); pa_proplist_free(c->proplist); pa_dbus_protocol_unref(c->dbus_protocol); -- 1.7.11.7