OSDN Git Service

Split gatt_update_auto_connect_dev into separate add/remove functions
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 25 Oct 2018 21:04:14 +0000 (23:04 +0200)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 25 Oct 2018 21:25:09 +0000 (23:25 +0200)
Test: compilation, no functional changes
Change-Id: I58b5d565753e0c1b99a3b06b27074b593f3b903b

stack/gatt/gatt_api.cc
stack/gatt/gatt_int.h
stack/gatt/gatt_utils.cc

index 2d37e9d..e1ac2f7 100644 (file)
@@ -1124,7 +1124,7 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
                               initiating_phys);
   else {
     if (transport == BT_TRANSPORT_LE)
-      status = gatt_update_auto_connect_dev(gatt_if, true, bd_addr);
+      status = gatt_auto_connect_dev_add(p_reg, bd_addr);
     else {
       LOG(ERROR) << "Unsupported transport for background connection";
     }
@@ -1152,9 +1152,13 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
                         bool is_direct) {
   LOG(INFO) << __func__ << ": gatt_if=" << +gatt_if;
 
-  if (gatt_if && !gatt_get_regcb(gatt_if)) {
-    LOG(ERROR) << "gatt_if=" << +gatt_if << " is not registered";
-    return false;
+  tGATT_REG* p_reg;
+  if (gatt_if) {
+    p_reg = gatt_get_regcb(gatt_if);
+    if (!p_reg) {
+      LOG(ERROR) << "gatt_if=" << +gatt_if << " is not registered";
+      return false;
+    }
   }
 
   if (is_direct) {
@@ -1183,7 +1187,7 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
   }
   // is not direct
 
-  if (gatt_if) return gatt_remove_bg_dev_for_app(gatt_if, bd_addr);
+  if (gatt_if) return gatt_auto_connect_dev_remove(p_reg, bd_addr);
 
   if (!gatt_clear_bg_dev_for_addr(bd_addr)) {
     LOG(ERROR)
index 5052918..060b317 100644 (file)
@@ -473,11 +473,11 @@ extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle);
 extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg);
 
 /* for background connection */
-extern bool gatt_update_auto_connect_dev(tGATT_IF gatt_if, bool add,
+extern bool gatt_auto_connect_dev_add(tGATT_REG* p_reg,
+                                      const RawAddress& bd_addr);
+extern bool gatt_auto_connect_dev_remove(tGATT_REG* p_reg,
                                          const RawAddress& bd_addr);
 extern bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if);
-extern bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if,
-                                       const RawAddress& bd_addr);
 extern uint8_t gatt_clear_bg_dev_for_addr(const RawAddress& bd_addr);
 extern tGATT_BG_CONN_DEV* gatt_find_bg_dev(const RawAddress& remote_bda);
 extern void gatt_deregister_bgdev_list(tGATT_IF gatt_if);
index d92f423..25095a9 100644 (file)
@@ -1359,16 +1359,6 @@ bool gatt_add_bg_dev_list(tGATT_REG* p_reg, const RawAddress& bd_addr) {
   return true;
 }
 
-/** Remove the application interface for the specified background device */
-bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, const RawAddress& bd_addr) {
-  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
-  bool status;
-
-  if (p_tcb) gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false);
-  status = gatt_update_auto_connect_dev(gatt_if, false, bd_addr);
-  return status;
-}
-
 /** Removes all registrations for background connection for given device.
  * Returns true if anything was removed, false otherwise */
 uint8_t gatt_clear_bg_dev_for_addr(const RawAddress& bd_addr) {
@@ -1397,6 +1387,7 @@ bool gatt_remove_bg_dev_from_list(tGATT_REG* p_reg, const RawAddress& bd_addr) {
   gatt_cb.bgconn_dev.erase(dev_it);
   return true;
 }
+
 /** deregister all related back ground connetion device. */
 void gatt_deregister_bgdev_list(tGATT_IF gatt_if) {
   auto it = gatt_cb.bgconn_dev.begin();
@@ -1414,48 +1405,33 @@ void gatt_deregister_bgdev_list(tGATT_IF gatt_if) {
   }
 }
 
-/*******************************************************************************
- *
- * Function         gatt_reset_bgdev_list
- *
- * Description      reset bg device list
- *
- * Returns          pointer to the device record
- *
- ******************************************************************************/
+/** reset bg device list */
 void gatt_reset_bgdev_list(void) { gatt_cb.bgconn_dev.clear(); }
-/*******************************************************************************
- *
- * Function         gatt_update_auto_connect_dev
- *
- * Description      This function add or remove a device for background
- *                  connection procedure.
+
+/**
+ * This function add a device for background connection procedure.
  *
- * Parameters       gatt_if: Application ID.
- *                  add: add peer device
+ * Parameters       p_reg: application record,
  *                  bd_addr: peer device address.
  *
  * Returns          true if connection started; false otherwise.
- *
- ******************************************************************************/
-bool gatt_update_auto_connect_dev(tGATT_IF gatt_if, bool add,
-                                  const RawAddress& bd_addr) {
-  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
-
+ */
+bool gatt_auto_connect_dev_add(tGATT_REG* p_reg, const RawAddress& bd_addr) {
   VLOG(1) << __func__;
-  /* Make sure app is registered */
-  tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
-  if (!p_reg) {
-    LOG(ERROR) << __func__ << " gatt_if is not registered " << +gatt_if;
-    return false;
-  }
 
-  if (!add) return gatt_remove_bg_dev_from_list(p_reg, bd_addr);
+  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
 
   bool ret = gatt_add_bg_dev_list(p_reg, bd_addr);
   if (ret && p_tcb != NULL) {
     /* if a connected device, update the link holding number */
-    gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true);
+    gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
   }
   return ret;
 }
+
+/** Remove the application interface for the specified background device */
+bool gatt_auto_connect_dev_remove(tGATT_REG* p_reg, const RawAddress& bd_addr) {
+  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
+  if (p_tcb) gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, false, false);
+  return gatt_remove_bg_dev_from_list(p_reg, bd_addr);
+}