From 245ff1f6008dd909c7544b3427c8e372d6612f0b Mon Sep 17 00:00:00 2001 From: Pawel Wasowski Date: Wed, 16 Sep 2020 12:03:50 +0200 Subject: [PATCH] [Bluetooth] Clear all GATT data after unregistering all services 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 --- src/bluetooth/bluetooth_gatt_server.cc | 2 ++ src/bluetooth/bluetooth_gatt_server_service.cc | 9 +++++++++ src/bluetooth/bluetooth_gatt_server_service.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/bluetooth/bluetooth_gatt_server.cc b/src/bluetooth/bluetooth_gatt_server.cc index 194df4bb..54bdf12a 100644 --- a/src/bluetooth/bluetooth_gatt_server.cc +++ b/src/bluetooth/bluetooth_gatt_server.cc @@ -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)); diff --git a/src/bluetooth/bluetooth_gatt_server_service.cc b/src/bluetooth/bluetooth_gatt_server_service.cc index 3939c3ae..e39e8580 100644 --- a/src/bluetooth/bluetooth_gatt_server_service.cc +++ b/src/bluetooth/bluetooth_gatt_server_service.cc @@ -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 diff --git a/src/bluetooth/bluetooth_gatt_server_service.h b/src/bluetooth/bluetooth_gatt_server_service.h index 5ed008cd..5f9c5b93 100644 --- a/src/bluetooth/bluetooth_gatt_server_service.h +++ b/src/bluetooth/bluetooth_gatt_server_service.h @@ -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_; -- 2.34.1