From a2b698dc40dcdae827811c0df0a9e0665ce7d699 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Fri, 1 Feb 2013 20:33:08 -0300 Subject: [PATCH] hfp_hf_bluez5: Add Profile RequestDisconnection This patch implements RequestDisconnection method of the Profile1 interface. This method gets called when the profile gets disconnected. The profile implementation needs to cleanup the resources related to the informed device. --- plugins/hfp_hf_bluez5.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c index cd3f9a65..0d6bdd95 100644 --- a/plugins/hfp_hf_bluez5.c +++ b/plugins/hfp_hf_bluez5.c @@ -340,11 +340,40 @@ static DBusMessage *profile_cancel(DBusConnection *conn, static DBusMessage *profile_disconnection(DBusConnection *conn, DBusMessage *msg, void *user_data) { + struct ofono_modem *modem; + struct hfp *hfp; + const char *device; + struct hfp_slc_info *info; + DBusMessageIter entry; + DBG("Profile handler RequestDisconnection"); - return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE - ".NotImplemented", - "Implementation not provided"); + if (dbus_message_iter_init(msg, &entry) == FALSE) + goto error; + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_OBJECT_PATH) + goto error; + + dbus_message_iter_get_basic(&entry, &device); + + modem = g_hash_table_lookup(modem_hash, device); + if (modem == NULL) + goto error; + + ofono_modem_set_powered(modem, FALSE); + + hfp = ofono_modem_get_data(modem); + info = &hfp->info; + + g_at_chat_unref(info->chat); + info->chat = NULL; + + return dbus_message_new_method_return(msg); + +error: + return g_dbus_create_error(msg, + BLUEZ_ERROR_INTERFACE ".Rejected", + "Invalid arguments in method call"); } static const GDBusMethodTable profile_methods[] = {