OSDN Git Service

Simplfy BTA_SdpSearch
authorZach Johnson <zachoverflow@google.com>
Fri, 28 Aug 2020 22:08:56 +0000 (15:08 -0700)
committerZach Johnson <zachoverflow@google.com>
Fri, 28 Aug 2020 22:10:04 +0000 (15:10 -0700)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I7b3459a08d98db2f2de3e4beaf94117e0fdb1a1c

bta/sdp/bta_sdp_act.cc
bta/sdp/bta_sdp_api.cc
bta/sdp/bta_sdp_int.h

index 20fa298..c435d79 100644 (file)
@@ -418,16 +418,11 @@ void bta_sdp_enable(tBTA_SDP_DM_CBACK* p_cback) {
  * Returns      void
  *
  ******************************************************************************/
-void bta_sdp_search(tBTA_SDP_API_SEARCH* p_data) {
-  if (p_data == NULL) {
-    APPL_TRACE_DEBUG("SDP control block handle is null");
-    return;
-  }
+void bta_sdp_search(const RawAddress bd_addr, const bluetooth::Uuid uuid) {
   tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
 
   APPL_TRACE_DEBUG("%s in, sdp_active:%d", __func__, bta_sdp_cb.sdp_active);
 
-  const Uuid& uuid = p_data->uuid;
   if (bta_sdp_cb.sdp_active != BTA_SDP_ACTIVE_NONE) {
     /* SDP is still in progress */
     status = BTA_SDP_BUSY;
@@ -435,18 +430,17 @@ void bta_sdp_search(tBTA_SDP_API_SEARCH* p_data) {
       tBTA_SDP_SEARCH_COMP result;
       memset(&result, 0, sizeof(result));
       result.uuid = uuid;
-      result.remote_addr = p_data->bd_addr;
+      result.remote_addr = bd_addr;
       result.status = status;
       tBTA_SDP bta_sdp;
       bta_sdp.sdp_search_comp = result;
       bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, &bta_sdp, NULL);
     }
-    osi_free(p_data);
     return;
   }
 
   bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_YES;
-  bta_sdp_cb.remote_addr = p_data->bd_addr;
+  bta_sdp_cb.remote_addr = bd_addr;
 
   /* initialize the search for the uuid */
   APPL_TRACE_DEBUG("%s init discovery with UUID: %s", __func__,
@@ -456,9 +450,9 @@ void bta_sdp_search(tBTA_SDP_API_SEARCH* p_data) {
 
   Uuid* bta_sdp_search_uuid = (Uuid*)osi_malloc(sizeof(Uuid));
   *bta_sdp_search_uuid = uuid;
-  if (!SDP_ServiceSearchAttributeRequest2(
-          p_data->bd_addr, p_bta_sdp_cfg->p_sdp_db, bta_sdp_search_cback,
-          (void*)bta_sdp_search_uuid)) {
+  if (!SDP_ServiceSearchAttributeRequest2(bd_addr, p_bta_sdp_cfg->p_sdp_db,
+                                          bta_sdp_search_cback,
+                                          (void*)bta_sdp_search_uuid)) {
     bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
 
     /* failed to start SDP. report the failure right away */
@@ -466,7 +460,7 @@ void bta_sdp_search(tBTA_SDP_API_SEARCH* p_data) {
       tBTA_SDP_SEARCH_COMP result;
       memset(&result, 0, sizeof(result));
       result.uuid = uuid;
-      result.remote_addr = p_data->bd_addr;
+      result.remote_addr = bd_addr;
       result.status = status;
       tBTA_SDP bta_sdp;
       bta_sdp.sdp_search_comp = result;
@@ -476,7 +470,6 @@ void bta_sdp_search(tBTA_SDP_API_SEARCH* p_data) {
   /*
   else report the result when the cback is called
   */
-  osi_free(p_data);
 }
 
 /*******************************************************************************
index a74db86..61b9284 100644 (file)
@@ -76,17 +76,7 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK* p_cback) {
  ******************************************************************************/
 tBTA_SDP_STATUS BTA_SdpSearch(const RawAddress& bd_addr,
                               const bluetooth::Uuid& uuid) {
-  tBTA_SDP_API_SEARCH* p_msg =
-      (tBTA_SDP_API_SEARCH*)osi_malloc(sizeof(tBTA_SDP_API_SEARCH));
-
-  APPL_TRACE_API("%s", __func__);
-
-  p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
-  p_msg->bd_addr = bd_addr;
-  p_msg->uuid = uuid;
-
-  do_in_main_thread(FROM_HERE, base::Bind(bta_sdp_search, p_msg));
-
+  do_in_main_thread(FROM_HERE, base::Bind(bta_sdp_search, bd_addr, uuid));
   return BTA_SDP_SUCCESS;
 }
 
index 51361ae..72a69ad 100644 (file)
@@ -52,13 +52,6 @@ enum {
 /* data type for BTA_SDP_API_SEARCH_EVT */
 typedef struct {
   BT_HDR hdr;
-  RawAddress bd_addr;
-  bluetooth::Uuid uuid;
-} tBTA_SDP_API_SEARCH;
-
-/* data type for BTA_SDP_API_SEARCH_EVT */
-typedef struct {
-  BT_HDR hdr;
   void* user_data;
 } tBTA_SDP_API_RECORD_USER;
 
@@ -66,7 +59,6 @@ typedef struct {
 typedef union {
   /* GKI event buffer header */
   BT_HDR hdr;
-  tBTA_SDP_API_SEARCH get_search;
   tBTA_SDP_API_RECORD_USER record;
 } tBTA_SDP_MSG;
 
@@ -86,7 +78,8 @@ extern tBTA_SDP_CFG* p_bta_sdp_cfg;
 extern bool bta_sdp_sm_execute(BT_HDR* p_msg);
 
 extern void bta_sdp_enable(tBTA_SDP_DM_CBACK* p_cback);
-extern void bta_sdp_search(tBTA_SDP_API_SEARCH* p_data);
+extern void bta_sdp_search(const RawAddress bd_addr,
+                           const bluetooth::Uuid uuid);
 extern void bta_sdp_create_record(tBTA_SDP_API_RECORD_USER* p_data);
 extern void bta_sdp_remove_record(tBTA_SDP_API_RECORD_USER* p_data);