[bluetooth] Ignoring undocumented exceptions in removeValueChangeListener. 26/195726/4
authorMichal Michalski <m.michalski2@partner.samsung.com>
Mon, 17 Dec 2018 14:25:20 +0000 (15:25 +0100)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Wed, 19 Dec 2018 15:18:27 +0000 (15:18 +0000)
Calling removeValueChangeListener was throwing undocumented errors.
This commit supresses those exceptions to match the documentation.

[Verification] Exception is not thrown (verified by modified TCT test).

Change-Id: I4df3b810d27d48da7a0194473984e59d1beb067b
Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
src/bluetooth/bluetooth_gatt_service.cc

index 1200a7b..270a772 100644 (file)
@@ -513,26 +513,22 @@ void BluetoothGATTService::RemoveValueChangeListener(const picojson::value& args
   ScopeLogger();
   const auto& address = args.get("address").get<std::string>();
   if (!IsStillConnected(address)) {
-    LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out,
-                      ("Device with address %s is no longer connected", address.c_str()));
-    return;
-  }
-
-  bt_gatt_h handle = (bt_gatt_h) static_cast<long>(args.get(kHandle).get<double>());
+    LoggerW("Device with address %s is no longer connected", address.c_str());
+  } else {
+      bt_gatt_h handle = (bt_gatt_h) static_cast<long>(args.get(kHandle).get<double>());
 
-  int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle);
+      int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle);
 
-  if (BT_ERROR_NONE != ret) {
-    LogAndReportError(
-        util::GetBluetoothError(ret, "Failed to unregister listener"), &out,
-        ("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret,
-         get_error_message(ret)));
-  } else {
-    gatt_characteristic_.erase(
-        std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle),
-        gatt_characteristic_.end());
-    ReportSuccess(out);
+      if (BT_ERROR_NONE != ret) {
+        LoggerW("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret,
+                get_error_message(ret));
+      } else {
+        gatt_characteristic_.erase(
+            std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle),
+            gatt_characteristic_.end());
+      }
   }
+  ReportSuccess(out);
 }
 
 common::PlatformResult BluetoothGATTService::GetServiceAllUuids(const std::string& address,