Emits the CardAdded signal using the Handfree Audio Manager interface
when a Audio Card is removed. The common way to trigger this action is
when the service level connection is disconnected.
---
 src/handsfree-audio.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 39d90c5..fcebce8 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -202,6 +202,8 @@ static const GDBusMethodTable am_methods[] = {
 static const GDBusSignalTable am_signals[] = {
        { GDBUS_SIGNAL("CardAdded",
                GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
+       { GDBUS_SIGNAL("CardRemoved",
+               GDBUS_ARGS({ "path", "o" })) },
        { }
 };
 
@@ -226,6 +228,25 @@ static void am_emit_card_added(const char *path, struct 
audio_card *card)
        g_dbus_send_message(ofono_dbus_get_connection(), signal);
 }
 
+static void am_emit_card_removed(const char *path)
+{
+       DBusMessage *signal;
+       DBusMessageIter iter;
+
+       signal = dbus_message_new_signal("/", HFP_AUDIO_MANAGER_INTERFACE,
+                                                               "CardRemoved");
+       if (signal == NULL) {
+               ofono_error("Unable to allocate new CardRemoved signal");
+               return;
+       }
+
+       dbus_message_iter_init_append(signal, &iter);
+
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+       g_dbus_send_message(ofono_dbus_get_connection(), signal);
+}
+
 void ofono_handsfree_audio_ref(void)
 {
        ref_count += 1;
@@ -301,6 +322,8 @@ char *ofono_handsfree_card_create(const char *remote)
 
 void ofono_handsfree_card_remove(const char *path)
 {
+       am_emit_card_removed(path);
+
        g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
                                                HFP_AUDIO_CARD_INTERFACE);
 
-- 
1.7.11.7

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to