OSDN Git Service

Remove bta_gattc_id2handle
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 4 Mar 2016 19:46:08 +0000 (11:46 -0800)
committerJakub Pawlowski <jpawlowski@google.com>
Wed, 9 Mar 2016 04:52:45 +0000 (20:52 -0800)
Now that the instance id is equal to handle, we no longer need this
mapping function.

Bug: 27455533
Change-Id: I6760f8fc81460df8520d4ebf1899ed256ce5ad1e

bta/gatt/bta_gattc_act.c
bta/gatt/bta_gattc_api.c
bta/gatt/bta_gattc_cache.c
bta/gatt/bta_gattc_int.h
bta/gatt/bta_gattc_utils.c

index 5b63f75..26fc5bc 100644 (file)
@@ -1083,38 +1083,33 @@ void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 *******************************************************************************/
 void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    if (!bta_gattc_enqueue(p_clcb, p_data))
+        return;
+
     UINT16 handle = 0;
     tGATT_READ_PARAM    read_param;
     tBTA_GATT_STATUS    status;
 
     memset (&read_param, 0 ,sizeof(tGATT_READ_PARAM));
 
-    if (bta_gattc_enqueue(p_clcb, p_data))
-    {
-        if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
-                                          &p_data->api_read.srvc_id,
-                                          &p_data->api_read.char_id,
-                                          p_data->api_read.p_descr_type)) == 0)
-        {
-            status = BTA_GATT_ERROR;
-        }
-        else
-        {
-            read_param.by_handle.handle = handle;
-            read_param.by_handle.auth_req = p_data->api_read.auth_req;
+    if (p_data->api_write.p_descr_type == NULL)
+        handle = p_data->api_write.char_id.inst_id;
+    else
+        handle = p_data->api_write.p_descr_type->inst_id;
 
-            status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_BY_HANDLE, &read_param);
-        }
+    read_param.by_handle.handle = handle;
+    read_param.by_handle.auth_req = p_data->api_read.auth_req;
 
-        /* read fail */
-        if (status != BTA_GATT_OK)
-        {
-            /* Dequeue the data, if it was enqueued */
-            if (p_clcb->p_q_cmd == p_data)
-                p_clcb->p_q_cmd = NULL;
+    status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_BY_HANDLE, &read_param);
 
-            bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_READ, status, NULL);
-        }
+    /* read fail */
+    if (status != BTA_GATT_OK)
+    {
+        /* Dequeue the data, if it was enqueued */
+        if (p_clcb->p_q_cmd == p_data)
+            p_clcb->p_q_cmd = NULL;
+
+        bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_READ, status, NULL);
     }
 }
 /*******************************************************************************
@@ -1142,22 +1137,11 @@ void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
         {
             handle = 0;
 
-            if (p_id->id_type == BTA_GATT_TYPE_CHAR)
-            {
-                handle = bta_gattc_id2handle(p_clcb->p_srcb,
-                                     &p_id->id_value.char_id.srvc_id,
-                                     &p_id->id_value.char_id.char_id,
-                                     NULL);
-            }
-            else if (p_id->id_type == BTA_GATT_TYPE_CHAR_DESCR)
-            {
-                handle = bta_gattc_id2handle(p_clcb->p_srcb,
-                                     &p_id->id_value.char_descr_id.char_id.srvc_id,
-                                     &p_id->id_value.char_descr_id.char_id.char_id,
-                                     &p_id->id_value.char_descr_id.descr_id);
-            }
-            else
-            {
+            if (p_id->id_type == BTA_GATT_TYPE_CHAR) {
+                handle = p_id->id_value.char_id.char_id.inst_id;
+            } else if (p_id->id_type == BTA_GATT_TYPE_CHAR_DESCR) {
+                handle = p_id->id_value.char_descr_id.descr_id.inst_id;
+            } else {
                 APPL_TRACE_ERROR("invalud ID type: %d", p_id->id_type);
             }
 
@@ -1197,43 +1181,38 @@ void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 *******************************************************************************/
 void bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    if (!bta_gattc_enqueue(p_clcb, p_data))
+        return;
+
     UINT16              handle = 0;
     tBTA_GATT_STATUS    status = BTA_GATT_OK;
 
-    if (bta_gattc_enqueue(p_clcb, p_data))
-    {
-        if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
-                                          &p_data->api_write.srvc_id,
-                                          &p_data->api_write.char_id,
-                                          p_data->api_write.p_descr_type)) == 0)
-        {
-            status = BTA_GATT_ERROR;
-        }
-        else
-        {
-            tGATT_VALUE attr;
+    if (p_data->api_write.p_descr_type == NULL)
+        handle = p_data->api_write.char_id.inst_id;
+    else
+        handle = p_data->api_write.p_descr_type->inst_id;
 
-            attr.conn_id = p_clcb->bta_conn_id;
-            attr.handle = handle;
-            attr.offset = p_data->api_write.offset;
-            attr.len    = p_data->api_write.len;
-            attr.auth_req = p_data->api_write.auth_req;
+    tGATT_VALUE attr;
 
-            if (p_data->api_write.p_value)
-                memcpy(attr.value, p_data->api_write.p_value, p_data->api_write.len);
+    attr.conn_id = p_clcb->bta_conn_id;
+    attr.handle = handle;
+    attr.offset = p_data->api_write.offset;
+    attr.len    = p_data->api_write.len;
+    attr.auth_req = p_data->api_write.auth_req;
 
-            status = GATTC_Write(p_clcb->bta_conn_id, p_data->api_write.write_type, &attr);
-        }
+    if (p_data->api_write.p_value)
+        memcpy(attr.value, p_data->api_write.p_value, p_data->api_write.len);
 
-        /* write fail */
-        if (status != BTA_GATT_OK)
-        {
-            /* Dequeue the data, if it was enqueued */
-            if (p_clcb->p_q_cmd == p_data)
-                p_clcb->p_q_cmd = NULL;
+    status = GATTC_Write(p_clcb->bta_conn_id, p_data->api_write.write_type, &attr);
 
-            bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_WRITE, status, NULL);
-        }
+    /* write fail */
+    if (status != BTA_GATT_OK)
+    {
+        /* Dequeue the data, if it was enqueued */
+        if (p_clcb->p_q_cmd == p_data)
+            p_clcb->p_q_cmd = NULL;
+
+        bta_gattc_cmpl_sendmsg(p_clcb->bta_conn_id, GATTC_OPTYPE_WRITE, status, NULL);
     }
 }
 /*******************************************************************************
@@ -1273,30 +1252,16 @@ void bta_gattc_execute(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 *******************************************************************************/
 void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
-    UINT16 handle;
+    UINT16 handle = p_data->api_confirm.char_id.inst_id;
 
-    if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
-                                      &p_data->api_confirm.srvc_id,
-                                      &p_data->api_confirm.char_id,
-                                      NULL)) == 0)
-    {
-        APPL_TRACE_ERROR("Can not map service/char ID into valid handle");
-    }
-    else
-    {
-        if (GATTC_SendHandleValueConfirm(p_data->api_confirm.hdr.layer_specific, handle)
-            != GATT_SUCCESS)
-        {
+    if (GATTC_SendHandleValueConfirm(p_data->api_confirm.hdr.layer_specific, handle)
+        != GATT_SUCCESS) {
             APPL_TRACE_ERROR("bta_gattc_confirm to handle [0x%04x] failed", handle);
-        }
-        else
-        {
-            /* if over BR_EDR, inform PM for mode change */
-            if (p_clcb->transport == BTA_TRANSPORT_BR_EDR)
-            {
-                bta_sys_busy(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
-                bta_sys_idle(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
-            }
+    } else {
+        /* if over BR_EDR, inform PM for mode change */
+        if (p_clcb->transport == BTA_TRANSPORT_BR_EDR) {
+            bta_sys_busy(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
+            bta_sys_idle(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
         }
     }
 }
index 3f135b1..8e6d1d4 100644 (file)
@@ -571,6 +571,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
 
     memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
     memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));
+    p_buf->p_descr_type = NULL;
 
     p_buf->write_type = write_type;
     p_buf->len = len;
@@ -657,6 +658,7 @@ void BTA_GATTC_PrepareWrite  (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
 
     memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
     memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));
+    p_buf->p_descr_type = NULL;
 
     p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
     p_buf->offset   = offset;
index 42c4a8d..31cc2ef 100644 (file)
@@ -903,26 +903,7 @@ void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT
         }
     }
 }
-/*******************************************************************************
-**
-** Function         bta_gattc_id2handle
-**
-** Description      map GATT ID to handle in a given cache.
-**
-** Returns          the handle mapped. 0 if not found.
-**
-*******************************************************************************/
-UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service_id,
-                           tBTA_GATT_ID *p_char_id, tBTA_GATT_ID *p_descr_uuid)
-{
-    if (!p_service_id || !p_srcb->p_srvc_cache || list_is_empty(p_srcb->p_srvc_cache))
-        return 0;
 
-    if (p_descr_uuid == NULL)
-        return p_char_id->inst_id;
-
-    return p_descr_uuid->inst_id;
-}
 /*******************************************************************************
 **
 ** Function         bta_gattc_handle2id
index cf50901..878c19b 100644 (file)
@@ -489,7 +489,6 @@ extern tBTA_GATTC_CLCB * bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg)
 
 extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
 
-extern UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service_id, tBTA_GATT_ID *p_char_id, tBTA_GATT_ID *p_descr_uuid);
 extern BOOLEAN bta_gattc_handle2id(tBTA_GATTC_SERV *p_srcb, UINT16 handle, tBTA_GATT_SRVC_ID *service_id, tBTA_GATT_ID *char_id, tBTA_GATT_ID *p_type);
 extern BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_precise);
 extern BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB  *p_clreg, tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY  *p_notify);
index 1ac010b..3fb5cde 100644 (file)
@@ -581,8 +581,7 @@ void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id,
                     /* It's enough to get service or characteristic handle, as
                      * clear boundaries are always around service.
                      */
-                    handle = bta_gattc_id2handle(p_srcb, &p_clrcb->notif_reg[i].char_id.srvc_id,
-                                                 &p_clrcb->notif_reg[i].char_id.char_id, NULL);
+                    handle = p_clrcb->notif_reg[i].char_id.char_id.inst_id;
                     if (handle >= start_handle && handle <= end_handle)
                         memset(&p_clrcb->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
             }