hfp_hf_bluez5: Implement sco_connected_hint
authorDenis Kenzior <denkenz@gmail.com>
Wed, 22 Apr 2015 23:07:14 +0000 (18:07 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 13 May 2015 14:57:53 +0000 (09:57 -0500)
plugins/hfp_hf_bluez5.c

index 2bed2a12825ddcf440a960f58c20178a8ea75b8c..5ee70c55e183025d0ac9f8bcd9240b3cdd82a7e3 100644 (file)
@@ -69,6 +69,7 @@ struct hfp {
        struct hfp_slc_info info;
        DBusMessage *msg;
        struct ofono_handsfree_card *card;
+       unsigned int bcc_id;
 };
 
 static const char *none_prefix[] = { NULL };
@@ -372,8 +373,12 @@ static void bcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
        struct cb_data *cbd = user_data;
        ofono_handsfree_card_connect_cb_t cb = cbd->cb;
+       struct ofono_handsfree_card *card = cbd->user;
+       struct hfp *hfp = ofono_handsfree_card_get_data(card);
        struct ofono_error error;
 
+       hfp->bcc_id = 0;
+
        decode_at_error(&error, g_at_result_final_response(result));
 
        cb(&error, cbd->data);
@@ -390,8 +395,10 @@ static void hfp16_card_connect(struct ofono_handsfree_card *card,
                        info->ag_features & HFP_AG_FEATURE_CODEC_NEGOTIATION) {
                struct cb_data *cbd = cb_data_new(cb, data);
 
-               g_at_chat_send(info->chat, "AT+BCC", none_prefix, bcc_cb,
-                                                               cbd, g_free);
+               cbd->user = card;
+               hfp->bcc_id = g_at_chat_send(info->chat, "AT+BCC",
+                                               none_prefix, bcc_cb,
+                                               cbd, g_free);
                return;
        }
 
@@ -404,11 +411,40 @@ static void hfp16_card_connect(struct ofono_handsfree_card *card,
        ofono_handsfree_card_connect_sco(card);
 }
 
+static void hfp16_sco_connected_hint(struct ofono_handsfree_card *card)
+{
+       struct hfp *hfp = ofono_handsfree_card_get_data(card);
+       struct hfp_slc_info *info = &hfp->info;
+       struct cb_data *cbd;
+       ofono_handsfree_card_connect_cb_t cb;
+
+       /*
+        * SCO has just been connected, probably initiated by the AG.
+        * If we have any outstanding BCC requests, then lets cancel these
+        * as they're no longer needed
+        */
+
+       if (hfp->bcc_id == 0)
+               return;
+
+       cbd = g_at_chat_get_userdata(info->chat, hfp->bcc_id);
+       if (cbd == NULL)
+               return;
+
+       cb = cbd->cb;
+       CALLBACK_WITH_SUCCESS(cb, cbd->data);
+
+       /* cbd will be freed once cancel is processed */
+       g_at_chat_cancel(info->chat, hfp->bcc_id);
+       hfp->bcc_id = 0;
+}
+
 static struct ofono_handsfree_card_driver hfp16_hf_driver = {
-       .name           = HFP16_HF_DRIVER,
-       .probe          = hfp16_card_probe,
-       .remove         = hfp16_card_remove,
-       .connect        = hfp16_card_connect,
+       .name                   = HFP16_HF_DRIVER,
+       .probe                  = hfp16_card_probe,
+       .remove                 = hfp16_card_remove,
+       .connect                = hfp16_card_connect,
+       .sco_connected_hint     = hfp16_sco_connected_hint,
 };
 
 static ofono_bool_t device_path_compare(struct ofono_modem *modem,