From: Pawel Andruszkiewicz
Date: Fri, 7 Aug 2015 12:00:24 +0000 (+0200)
Subject: [BluetoothLE] Correctly handle unregistration of characteristic listeners.
X-Git-Tag: submit/tizen/20151026.073646^2^2~207^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a535fd0222131a0570f7f49d74c3371cbe05da9;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[BluetoothLE] Correctly handle unregistration of characteristic listeners.
[Verification] Manually tested, fixes potential crashes.
Change-Id: Id88923232b8c75bd87b0481158042c7edc221a0d
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc
index 24cfdaac..dd4be35f 100755
--- a/src/bluetooth/bluetooth_gatt_service.cc
+++ b/src/bluetooth/bluetooth_gatt_service.cc
@@ -65,9 +65,12 @@ BluetoothGATTService::BluetoothGATTService(BluetoothInstance& instance) :
BluetoothGATTService::~BluetoothGATTService() {
LoggerD("Entered");
- for (auto it : gatt_clients_) {
+ for (auto it : gatt_characteristic_) {
// unregister callback, ignore errors
- bt_gatt_client_unset_characteristic_value_changed_cb(it.second);
+ bt_gatt_client_unset_characteristic_value_changed_cb(it);
+ }
+
+ for (auto it : gatt_clients_) {
LoggerD("destroying client for address: %s", it.first.c_str());
bt_gatt_client_destroy(it.second);
}
@@ -477,6 +480,7 @@ void BluetoothGATTService::AddValueChangeListener(const picojson::value& args,
LoggerE("bt_gatt_client_set_characteristic_value_changed_cb() failed with: %d", ret);
ReportError(util::GetBluetoothError(ret, "Failed to register listener"), &out);
} else {
+ gatt_characteristic_.push_back(handle);
ReportSuccess(out);
}
}
@@ -500,6 +504,7 @@ void BluetoothGATTService::RemoveValueChangeListener(
LoggerE("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d", ret);
ReportError(util::GetBluetoothError(ret, "Failed to unregister listener"), &out);
} else {
+ gatt_characteristic_.erase(std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle), gatt_characteristic_.end());
ReportSuccess(out);
}
}
diff --git a/src/bluetooth/bluetooth_gatt_service.h b/src/bluetooth/bluetooth_gatt_service.h
index 7c493b0c..0ae0e365 100755
--- a/src/bluetooth/bluetooth_gatt_service.h
+++ b/src/bluetooth/bluetooth_gatt_service.h
@@ -69,6 +69,7 @@ class BluetoothGATTService {
void* user_data);
std::map gatt_clients_;
+ std::vector gatt_characteristic_;
BluetoothInstance& instance_;
};