[Bluetooth] Remove redundant Destroy* functions 80/244480/3
authorPawel Wasowski <p.wasowski2@samsung.com>
Wed, 16 Sep 2020 14:03:51 +0000 (16:03 +0200)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Mon, 21 Sep 2020 07:55:05 +0000 (09:55 +0200)
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 <p.wasowski2@samsung.com>
src/bluetooth/bluetooth_gatt_server.cc
src/bluetooth/bluetooth_gatt_server.h
src/bluetooth/bluetooth_gatt_server_service.h

index 194df4bb6e5f1932250a124d7d850d9cadf8315e..e8bdf4204d4bb14e2b2ebfba0e1f72e3a5a51f3b 100644 (file)
@@ -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{}};
index 1b4875342ab5a307a1b5c680721e665069022059..4061f6314f137b9237708bb9e1465cd8cd8c4b37 100644 (file)
@@ -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_;
index 5ed008cdbeeaa3e6fee3b9b7b61afacf4d0bbe9e..661f2df115e2aba50fb5be0247c34ef5662f5b14 100644 (file)
@@ -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<int, bt_gatt_h> gatt_objects_;
@@ -58,9 +62,6 @@ class BluetoothGATTServerService {
     std::map<std::pair<bt_gatt_h, std::string>, 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);