Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.cc

Issue 2728623004: Fix getting notified twice after subscribe to notifications and call readValue (Closed)
Patch Set: updated test code Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 27 matching lines...) Expand all
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ( 42 BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ(
43 BluetoothRemoteGattServiceBlueZ* service, 43 BluetoothRemoteGattServiceBlueZ* service,
44 const dbus::ObjectPath& object_path) 44 const dbus::ObjectPath& object_path)
45 : BluetoothGattCharacteristicBlueZ(object_path), 45 : BluetoothGattCharacteristicBlueZ(object_path),
46 has_notify_session_(false), 46 has_notify_session_(false),
47 service_(service), 47 service_(service),
48 num_of_characteristic_value_read_in_progress_(0),
48 weak_ptr_factory_(this) { 49 weak_ptr_factory_(this) {
49 VLOG(1) << "Creating remote GATT characteristic with identifier: " 50 VLOG(1) << "Creating remote GATT characteristic with identifier: "
50 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); 51 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
51 bluez::BluezDBusManager::Get() 52 bluez::BluezDBusManager::Get()
52 ->GetBluetoothGattDescriptorClient() 53 ->GetBluetoothGattDescriptorClient()
53 ->AddObserver(this); 54 ->AddObserver(this);
54 55
55 // Add all known GATT characteristic descriptors. 56 // Add all known GATT characteristic descriptors.
56 const std::vector<dbus::ObjectPath>& gatt_descs = 57 const std::vector<dbus::ObjectPath>& gatt_descs =
57 bluez::BluezDBusManager::Get() 58 bluez::BluezDBusManager::Get()
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return iter->second; 178 return iter->second;
178 } 179 }
179 180
180 void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic( 181 void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic(
181 const ValueCallback& callback, 182 const ValueCallback& callback,
182 const ErrorCallback& error_callback) { 183 const ErrorCallback& error_callback) {
183 VLOG(1) << "Sending GATT characteristic read request to characteristic: " 184 VLOG(1) << "Sending GATT characteristic read request to characteristic: "
184 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() 185 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value()
185 << "."; 186 << ".";
186 187
188 DCHECK_GE(num_of_characteristic_value_read_in_progress_, 0);
189 ++num_of_characteristic_value_read_in_progress_;
190
187 bluez::BluezDBusManager::Get() 191 bluez::BluezDBusManager::Get()
188 ->GetBluetoothGattCharacteristicClient() 192 ->GetBluetoothGattCharacteristicClient()
189 ->ReadValue(object_path(), callback, 193 ->ReadValue(
190 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError, 194 object_path(), callback,
191 weak_ptr_factory_.GetWeakPtr(), error_callback)); 195 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnReadError,
196 weak_ptr_factory_.GetWeakPtr(), error_callback));
192 } 197 }
193 198
194 void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic( 199 void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic(
195 const std::vector<uint8_t>& value, 200 const std::vector<uint8_t>& value,
196 const base::Closure& callback, 201 const base::Closure& callback,
197 const ErrorCallback& error_callback) { 202 const ErrorCallback& error_callback) {
198 VLOG(1) << "Sending GATT characteristic write request to characteristic: " 203 VLOG(1) << "Sending GATT characteristic write request to characteristic: "
199 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() 204 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value()
200 << ", with value: " << value << "."; 205 << ", with value: " << value << ".";
201 206
202 bluez::BluezDBusManager::Get() 207 bluez::BluezDBusManager::Get()
203 ->GetBluetoothGattCharacteristicClient() 208 ->GetBluetoothGattCharacteristicClient()
204 ->WriteValue(object_path(), value, callback, 209 ->WriteValue(
205 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError, 210 object_path(), value, callback,
206 weak_ptr_factory_.GetWeakPtr(), error_callback)); 211 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnWriteError,
212 weak_ptr_factory_.GetWeakPtr(), error_callback));
207 } 213 }
208 214
209 void BluetoothRemoteGattCharacteristicBlueZ::SubscribeToNotifications( 215 void BluetoothRemoteGattCharacteristicBlueZ::SubscribeToNotifications(
210 device::BluetoothRemoteGattDescriptor* ccc_descriptor, 216 device::BluetoothRemoteGattDescriptor* ccc_descriptor,
211 const base::Closure& callback, 217 const base::Closure& callback,
212 const ErrorCallback& error_callback) { 218 const ErrorCallback& error_callback) {
213 bluez::BluezDBusManager::Get() 219 bluez::BluezDBusManager::Get()
214 ->GetBluetoothGattCharacteristicClient() 220 ->GetBluetoothGattCharacteristicClient()
215 ->StartNotify( 221 ->StartNotify(
216 object_path(), 222 object_path(),
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 const std::string& error_name, 352 const std::string& error_name,
347 const std::string& error_message) { 353 const std::string& error_message) {
348 VLOG(1) << "Call to stop notifications failed for characteristic: " 354 VLOG(1) << "Call to stop notifications failed for characteristic: "
349 << object_path().value() << ": " << error_name << ", " 355 << object_path().value() << ": " << error_name << ", "
350 << error_message; 356 << error_message;
351 357
352 // Since this is a best effort operation, treat this as success. 358 // Since this is a best effort operation, treat this as success.
353 OnStopNotifySuccess(callback); 359 OnStopNotifySuccess(callback);
354 } 360 }
355 361
356 void BluetoothRemoteGattCharacteristicBlueZ::OnError( 362 void BluetoothRemoteGattCharacteristicBlueZ::OnReadError(
357 const ErrorCallback& error_callback, 363 const ErrorCallback& error_callback,
358 const std::string& error_name, 364 const std::string& error_name,
359 const std::string& error_message) { 365 const std::string& error_message) {
366 VLOG(1) << "Operation failed: " << error_name
367 << ", message: " << error_message;
368 --num_of_characteristic_value_read_in_progress_;
369 DCHECK_GE(num_of_characteristic_value_read_in_progress_, 0);
370 error_callback.Run(
371 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name));
372 }
373
374 void BluetoothRemoteGattCharacteristicBlueZ::OnWriteError(
375 const ErrorCallback& error_callback,
376 const std::string& error_name,
377 const std::string& error_message) {
360 VLOG(1) << "Operation failed: " << error_name 378 VLOG(1) << "Operation failed: " << error_name
361 << ", message: " << error_message; 379 << ", message: " << error_message;
362 error_callback.Run( 380 error_callback.Run(
363 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); 381 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name));
364 } 382 }
365 383
366 } // namespace bluez 384 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698