OLD | NEW |
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/bluetooth_remote_gatt_characteristic_mac.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { | 252 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { |
253 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); | 253 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); |
254 // This method is called when the characteristic is read and when a | 254 // This method is called when the characteristic is read and when a |
255 // notification is received. | 255 // notification is received. |
256 if (characteristic_value_read_or_write_in_progress_) { | 256 if (characteristic_value_read_or_write_in_progress_) { |
257 std::pair<ValueCallback, ErrorCallback> callbacks; | 257 std::pair<ValueCallback, ErrorCallback> callbacks; |
258 callbacks.swap(read_characteristic_value_callbacks_); | 258 callbacks.swap(read_characteristic_value_callbacks_); |
259 characteristic_value_read_or_write_in_progress_ = false; | 259 characteristic_value_read_or_write_in_progress_ = false; |
260 if (error) { | 260 if (error) { |
| 261 BluetoothGattService::GattErrorCode error_code = |
| 262 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
261 VLOG(1) << *this | 263 VLOG(1) << *this |
262 << ": Bluetooth error while reading for characteristic, domain: " | 264 << ": Bluetooth error while reading for characteristic, domain: " |
263 << base::SysNSStringToUTF8(error.domain) | 265 << error << ", error code: " << error_code; |
264 << ", error code: " << error.code; | |
265 BluetoothGattService::GattErrorCode error_code = | |
266 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | |
267 callbacks.second.Run(error_code); | 266 callbacks.second.Run(error_code); |
268 return; | 267 return; |
269 } | 268 } |
270 VLOG(1) << *this << ": Read request arrived."; | 269 VLOG(1) << *this << ": Read request arrived."; |
271 UpdateValue(); | 270 UpdateValue(); |
272 callbacks.first.Run(value_); | 271 callbacks.first.Run(value_); |
273 } else if (IsNotifying()) { | 272 } else if (IsNotifying()) { |
274 VLOG(1) << *this << ": Notification arrived."; | 273 VLOG(1) << *this << ": Notification arrived."; |
275 UpdateValue(); | 274 UpdateValue(); |
276 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( | 275 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( |
(...skipping 20 matching lines...) Expand all Loading... |
297 // In case of buggy device, nothing should be done if receiving extra | 296 // In case of buggy device, nothing should be done if receiving extra |
298 // write confirmation. | 297 // write confirmation. |
299 VLOG(1) << *this | 298 VLOG(1) << *this |
300 << ": Write notification while no write operation pending."; | 299 << ": Write notification while no write operation pending."; |
301 return; | 300 return; |
302 } | 301 } |
303 std::pair<base::Closure, ErrorCallback> callbacks; | 302 std::pair<base::Closure, ErrorCallback> callbacks; |
304 callbacks.swap(write_characteristic_value_callbacks_); | 303 callbacks.swap(write_characteristic_value_callbacks_); |
305 characteristic_value_read_or_write_in_progress_ = false; | 304 characteristic_value_read_or_write_in_progress_ = false; |
306 if (error) { | 305 if (error) { |
307 VLOG(1) << *this | |
308 << ": Bluetooth error while writing for characteristic, domain: " | |
309 << base::SysNSStringToUTF8(error.domain) | |
310 << ", error code: " << error.code; | |
311 BluetoothGattService::GattErrorCode error_code = | 306 BluetoothGattService::GattErrorCode error_code = |
312 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 307 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
| 308 VLOG(1) << *this |
| 309 << ": Bluetooth error while writing for characteristic, error: " |
| 310 << error << ", error code: " << error_code; |
313 callbacks.second.Run(error_code); | 311 callbacks.second.Run(error_code); |
314 return; | 312 return; |
315 } | 313 } |
316 VLOG(1) << *this << ": Write value succeeded."; | 314 VLOG(1) << *this << ": Write value succeeded."; |
317 callbacks.first.Run(); | 315 callbacks.first.Run(); |
318 } | 316 } |
319 | 317 |
320 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( | 318 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( |
321 NSError* error) { | 319 NSError* error) { |
322 PendingNotifyCallbacks reentrant_safe_callbacks; | 320 PendingNotifyCallbacks reentrant_safe_callbacks; |
323 if (!subscribe_to_notification_callbacks_.first.is_null()) { | 321 if (!subscribe_to_notification_callbacks_.first.is_null()) { |
324 DCHECK([GetCBCharacteristic() isNotifying] || error); | 322 DCHECK([GetCBCharacteristic() isNotifying] || error); |
325 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); | 323 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); |
326 } else if (!unsubscribe_from_notification_callbacks_.first.is_null()) { | 324 } else if (!unsubscribe_from_notification_callbacks_.first.is_null()) { |
327 DCHECK(![GetCBCharacteristic() isNotifying] || error); | 325 DCHECK(![GetCBCharacteristic() isNotifying] || error); |
328 reentrant_safe_callbacks.swap(unsubscribe_from_notification_callbacks_); | 326 reentrant_safe_callbacks.swap(unsubscribe_from_notification_callbacks_); |
329 } else { | 327 } else { |
330 VLOG(1) << *this << ": No pending notification update for characteristic."; | 328 VLOG(1) << *this << ": No pending notification update for characteristic."; |
331 return; | 329 return; |
332 } | 330 } |
333 if (error) { | 331 if (error) { |
| 332 BluetoothGattService::GattErrorCode error_code = |
| 333 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
334 VLOG(1) << *this | 334 VLOG(1) << *this |
335 << ": Bluetooth error while modifying notification state for " | 335 << ": Bluetooth error while modifying notification state for " |
336 "characteristic, domain: " | 336 "characteristic, error: " |
337 << base::SysNSStringToUTF8(error.domain) | 337 << error << ", error code: " << error_code; |
338 << ", error code: " << error.code << ", localized description: " | |
339 << base::SysNSStringToUTF8(error.localizedDescription); | |
340 BluetoothGattService::GattErrorCode error_code = | |
341 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | |
342 reentrant_safe_callbacks.second.Run(error_code); | 338 reentrant_safe_callbacks.second.Run(error_code); |
343 return; | 339 return; |
344 } | 340 } |
345 reentrant_safe_callbacks.first.Run(); | 341 reentrant_safe_callbacks.first.Run(); |
346 } | 342 } |
347 | 343 |
348 void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() { | 344 void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() { |
349 DCHECK(!is_discovery_complete_); | 345 DCHECK(!is_discovery_complete_); |
350 VLOG(1) << *this << ": Did discover descriptors."; | 346 VLOG(1) << *this << ": Did discover descriptors."; |
351 std::unordered_set<std::string> descriptor_identifier_to_remove; | 347 std::unordered_set<std::string> descriptor_identifier_to_remove; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 const BluetoothRemoteGattServiceMac* service_mac = | 444 const BluetoothRemoteGattServiceMac* service_mac = |
449 static_cast<const BluetoothRemoteGattServiceMac*>( | 445 static_cast<const BluetoothRemoteGattServiceMac*>( |
450 characteristic.GetService()); | 446 characteristic.GetService()); |
451 return out << "<BluetoothRemoteGattCharacteristicMac " | 447 return out << "<BluetoothRemoteGattCharacteristicMac " |
452 << characteristic.GetUUID().canonical_value() << "/" | 448 << characteristic.GetUUID().canonical_value() << "/" |
453 << &characteristic | 449 << &characteristic |
454 << ", service: " << service_mac->GetUUID().canonical_value() << "/" | 450 << ", service: " << service_mac->GetUUID().canonical_value() << "/" |
455 << service_mac << ">"; | 451 << service_mac << ">"; |
456 } | 452 } |
457 } // namespace device. | 453 } // namespace device. |
OLD | NEW |