[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 194df4bb6e5f1932250a124d7d850d9cadf8315e..54bdf12a0f8f19ec89d363b570ee46edefd4dbd2 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 3939c3ae79e996701541a0824eab4e3cce9c90ec..e39e85802b59ce9bd73a3a8ed1ec53d9124df4df 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 5ed008cdbeeaa3e6fee3b9b7b61afacf4d0bbe9e..5f9c5b93343d6b475ce459bdd1ca584852f24d9e 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_;