From: Pawel Wasowski Date: Wed, 16 Sep 2020 10:03:50 +0000 (+0200) Subject: [Bluetooth] Clear all GATT data after unregistering all services X-Git-Tag: submit/tizen/20200923.101308~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F73%2F244473%2F3;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [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 --- 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_;