[Bluetooth] Clear all GATT data after unregistering all services 73/244473/3
authorPawel Wasowski <p.wasowski2@samsung.com>
Wed, 16 Sep 2020 10:03:50 +0000 (12:03 +0200)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Mon, 21 Sep 2020 08:14:15 +0000 (10:14 +0200)
This commit clears_id->gatt_h and _id->callback names mappings from
BluetoothGATTServerService when the server is stopped.

[Verification] This change is tested together with the commit
implementing reregistration of read/write callbacks and works fine.

Change-Id: I4c16674f4856bb1fa74f4db74b6bbe9119f3b29f
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/bluetooth/bluetooth_gatt_server.cc
src/bluetooth/bluetooth_gatt_server_service.cc
src/bluetooth/bluetooth_gatt_server_service.h

index 194df4b..54bdf12 100644 (file)
@@ -347,6 +347,8 @@ PlatformResult BluetoothGATTServer::UnregisterAllServicesImpl() {
     return PlatformResult{ErrorCode::INVALID_STATE_ERR};
   }
 
+  service_.ClearGATTData();
+
   auto ret = bt_gatt_server_unregister_all_services(handle_);
   if (BT_ERROR_NONE != ret) {
     LoggerE("bt_gatt_server_unregister_all_services(): %d (%s)", ret, get_error_message(ret));
index 3939c3a..e39e858 100644 (file)
@@ -690,5 +690,14 @@ common::PlatformResult BluetoothGATTServerService::NotifyAboutValueChange(
   return common::PlatformResult{};
 }
 
+void BluetoothGATTServerService::ClearGATTData() {
+  ScopeLogger();
+
+  LoggerD("Removing %zu old GATT handles and %zu callback names",
+          gatt_objects_.size(), callback_names_.size());
+  gatt_objects_.clear();
+  callback_names_.clear();
+}
+
 }  // namespace bluetooth
 }  // namespace extension
index 5ed008c..5f9c5b9 100644 (file)
@@ -47,6 +47,7 @@ class BluetoothGATTServerService {
   PlatformResult SetWriteValueRequestCallback(const picojson::value& args);
   PlatformResult SendResponse(const picojson::value& args);
   PlatformResult NotifyAboutValueChange(const picojson::value& args);
+  void ClearGATTData();
 
  private:
   BluetoothInstance& instance_;