From c74b60a827bdf2a295ff88c7811d106ef62f3a39 Mon Sep 17 00:00:00 2001 From: Pawel Wasowski Date: Wed, 16 Sep 2020 16:03:51 +0200 Subject: [PATCH] [Bluetooth] Remove redundant Destroy* functions Destroy* functions from BluetoothGATTServer class were removed, because they internally destroyed nested GATT objects. Such behavior is safe, but redundant, because the native methods already destroy nested objects. Their usages were replaced by their counterparts from BluetoothGATTServerService class. [Verification] The code compiles. Tested in chrome console together with https://review.tizen.org/gerrit/#/c/platform/core/api/webapi-plugins/+/244481/ No issues observed. Change-Id: Ied428687fd4467fe9418afa9f87446c3a9b5b147 Signed-off-by: Pawel Wasowski --- src/bluetooth/bluetooth_gatt_server.cc | 54 +------------------ src/bluetooth/bluetooth_gatt_server.h | 4 -- src/bluetooth/bluetooth_gatt_server_service.h | 7 +-- 3 files changed, 5 insertions(+), 60 deletions(-) diff --git a/src/bluetooth/bluetooth_gatt_server.cc b/src/bluetooth/bluetooth_gatt_server.cc index 194df4bb..e8bdf420 100644 --- a/src/bluetooth/bluetooth_gatt_server.cc +++ b/src/bluetooth/bluetooth_gatt_server.cc @@ -365,7 +365,7 @@ PlatformResult BluetoothGATTServer::DestroyAllGATTObjects() { return PlatformResult{ErrorCode::INVALID_STATE_ERR}; } - auto ret = bt_gatt_server_foreach_services(handle_, DestroyService, nullptr); + auto ret = bt_gatt_server_foreach_services(handle_, BluetoothGATTServerService::DestroyService, nullptr); if (BT_ERROR_NONE != ret) { LoggerE("bt_gatt_server_unregister_all_services(): %d (%s)", ret, get_error_message(ret)); return BluetoothErrorToPlatformResult(ret); @@ -379,58 +379,6 @@ PlatformResult BluetoothGATTServer::DestroyAllGATTObjects() { */ } -bool BluetoothGATTServer::DestroyService(int total, int index, bt_gatt_h handle, void* user_data) { - ScopeLogger("total: %d, index: %d, handle: %p", total, index, handle); - - auto ret = bt_gatt_service_foreach_included_services(handle, DestroyService, nullptr); - if (BT_ERROR_NONE != ret) { - LoggerE("bt_gatt_service_foreach_included_servics(): %d (%s)", ret, get_error_message(ret)); - } - LoggerD("bt_gatt_service_foreach_included_servics(): success"); - - ret = bt_gatt_service_foreach_characteristics(handle, DestroyCharacteristic, nullptr); - if (BT_ERROR_NONE != ret) { - LoggerE("bt_gatt_service_foreach_characteristics(): %d (%s)", ret, get_error_message(ret)); - } - LoggerD("bt_gatt_service_foreach_characteristics(): success"); - - ret = bt_gatt_service_destroy(handle); - if (BT_ERROR_NONE != ret) { - LoggerE("bt_gatt_service_destroy(): %d (%s)", ret, get_error_message(ret)); - } - - return true; -} - -bool BluetoothGATTServer::DestroyCharacteristic(int total, int index, bt_gatt_h handle, - void* user_data) { - ScopeLogger("total: %d, index: %d, handle: %p", total, index, handle); - - auto ret = bt_gatt_characteristic_foreach_descriptors(handle, DestroyDescriptor, nullptr); - if (BT_ERROR_NONE != ret) { - LoggerE("bt_gatt_characteristic_foreach_descriptors(): %d (%s)", ret, get_error_message(ret)); - } - LoggerD("bt_gatt_characteristic_foreach_descriptors(): success"); - - ret = bt_gatt_characteristic_destroy(handle); - if (BT_ERROR_NONE != ret) { - LoggerE("bt_gatt_characteristic_destroy(): %d (%s)", ret, get_error_message(ret)); - } - - return true; -} - -bool BluetoothGATTServer::DestroyDescriptor(int total, int index, bt_gatt_h handle, - void* user_data) { - ScopeLogger("total: %d, index: %d, handle: %p", total, index, handle); - - auto ret = bt_gatt_descriptor_destroy(handle); - if (BT_ERROR_NONE != ret) { - LoggerE("bt_gatt_descriptor_destroy(): %d (%s)", ret, get_error_message(ret)); - } - return true; -} - void BluetoothGATTServer::PowerStateChangeCb(bool state) { ScopeLogger(); picojson::value result{picojson::object{}}; diff --git a/src/bluetooth/bluetooth_gatt_server.h b/src/bluetooth/bluetooth_gatt_server.h index 1b487534..4061f631 100644 --- a/src/bluetooth/bluetooth_gatt_server.h +++ b/src/bluetooth/bluetooth_gatt_server.h @@ -46,10 +46,6 @@ class BluetoothGATTServer { bool IsRunning(); void NotifyAboutValueChange(const picojson::value& args, picojson::object& out); - static bool DestroyService(int total, int index, bt_gatt_h handle, void* user_data); - static bool DestroyCharacteristic(int total, int index, bt_gatt_h handle, void* user_data); - static bool DestroyDescriptor(int total, int index, bt_gatt_h handle, void* user_data); - private: BluetoothInstance& instance_; BluetoothGATTServerService& service_; diff --git a/src/bluetooth/bluetooth_gatt_server_service.h b/src/bluetooth/bluetooth_gatt_server_service.h index 5ed008cd..661f2df1 100644 --- a/src/bluetooth/bluetooth_gatt_server_service.h +++ b/src/bluetooth/bluetooth_gatt_server_service.h @@ -48,6 +48,10 @@ class BluetoothGATTServerService { PlatformResult SendResponse(const picojson::value& args); PlatformResult NotifyAboutValueChange(const picojson::value& args); + static bool DestroyService(int total, int index, bt_gatt_h handle, void* user_data); + static bool DestroyCharacteristic(int total, int index, bt_gatt_h handle, void* user_data); + static bool DestroyDescriptor(int total, int index, bt_gatt_h handle, void* user_data); + private: BluetoothInstance& instance_; std::map gatt_objects_; @@ -58,9 +62,6 @@ class BluetoothGATTServerService { std::map, std::string>& callback_names_map_; } rw_request_callback_data_; - static bool DestroyService(int total, int index, bt_gatt_h handle, void* user_data); - static bool DestroyCharacteristic(int total, int index, bt_gatt_h handle, void* user_data); - static bool DestroyDescriptor(int total, int index, bt_gatt_h handle, void* user_data); static void NotifyCallback(int result, const char* remote_address, bt_gatt_server_h server, bt_gatt_h characteristic, bool completed, void* user_data); -- 2.34.1