OSDN Git Service

introduce gatt::connection_manager::get_apps_connecting_to
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 9 Nov 2018 17:40:04 +0000 (18:40 +0100)
committerJakub Pawlowski <jpawlowski@google.com>
Sat, 10 Nov 2018 08:38:12 +0000 (09:38 +0100)
This is to clean up the interface, and don't expose internal control
structures.

Test: compilation
Change-Id: Id2afc5efb4c14be0b787cfabbe21fc1961381cb7

stack/gatt/connection_manager.cc
stack/gatt/connection_manager.h
stack/gatt/gatt_main.cc

index 8197936..850e834 100644 (file)
 
 #include <base/logging.h>
 #include <list>
-#include <unordered_set>
+#include <set>
 
 #include "stack/btm/btm_ble_bgconn.h"
 
 struct tGATT_BG_CONN_DEV {
-  std::unordered_set<tGATT_IF> gatt_if;
+  std::set<tGATT_IF> gatt_if;
   RawAddress remote_bda;
 };
 
@@ -48,10 +48,13 @@ std::list<tGATT_BG_CONN_DEV>::iterator gatt_find_bg_dev_it(
 
 }  // namespace
 
-/** Returns true if this is one of the background devices for the application,
- * false otherwise */
-bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if) {
-  return p_dev->gatt_if.count(gatt_if);
+/** background connection device from the list. Returns pointer to the device
+ * record, or nullptr if not found */
+std::set<tGATT_IF> get_apps_connecting_to(const RawAddress& address) {
+  for (tGATT_BG_CONN_DEV& dev : bgconn_dev)
+    if (dev.remote_bda == address) return dev.gatt_if;
+
+  return std::set<tGATT_IF>();
 }
 
 /** background connection device from the list. Returns pointer to the device
index a39a4de..331f701 100644 (file)
 
 #pragma once
 
-#include <unordered_set>
+#include <set>
 
 #include "types/raw_address.h"
 
 typedef uint8_t tGATT_IF;
 
-struct tGATT_BG_CONN_DEV;
-
 namespace gatt {
 namespace connection_manager {
 
@@ -39,7 +37,6 @@ extern void reset(bool after_reset);
 
 extern void on_app_deregistered(tGATT_IF gatt_if);
 
-extern bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if);
-extern tGATT_BG_CONN_DEV* gatt_find_bg_dev(const RawAddress& remote_bda);
+extern std::set<tGATT_IF> get_apps_connecting_to(const RawAddress& remote_bda);
 }  // namespace connection_manager
 }  // namespace gatt
index c7010ea..51877ee 100644 (file)
@@ -801,15 +801,14 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) {
   tGATT_REG* p_reg;
   uint16_t conn_id;
 
-  tGATT_BG_CONN_DEV* p_bg_dev =
-      gatt::connection_manager::gatt_find_bg_dev(p_tcb->peer_bda);
+  std::set<tGATT_IF> apps =
+      gatt::connection_manager::get_apps_connecting_to(p_tcb->peer_bda);
 
   /* notifying all applications for the connection up event */
   for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
     if (!p_reg->in_use) continue;
 
-    if (p_bg_dev && gatt::connection_manager::gatt_is_bg_dev_for_app(
-                        p_bg_dev, p_reg->gatt_if))
+    if (apps.find(p_reg->gatt_if) != apps.end())
       gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
 
     if (p_reg->app_cb.p_conn_cb) {