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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = | 261 BluetoothGattService::GattErrorCode error_code = |
262 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 262 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
263 VLOG(1) << *this | 263 VLOG(1) << *this |
264 << ": Bluetooth error while reading for characteristic, domain: " | 264 << ": Bluetooth error while reading for characteristic, domain: " |
265 << error << ", error code: " << error_code; | 265 << BluetoothAdapterMac::String(error) |
| 266 << ", error code: " << error_code; |
266 callbacks.second.Run(error_code); | 267 callbacks.second.Run(error_code); |
267 return; | 268 return; |
268 } | 269 } |
269 VLOG(1) << *this << ": Read request arrived."; | 270 VLOG(1) << *this << ": Read request arrived."; |
270 UpdateValue(); | 271 UpdateValue(); |
271 callbacks.first.Run(value_); | 272 callbacks.first.Run(value_); |
272 } else if (IsNotifying()) { | 273 } else if (IsNotifying()) { |
273 VLOG(1) << *this << ": Notification arrived."; | 274 VLOG(1) << *this << ": Notification arrived."; |
274 UpdateValue(); | 275 UpdateValue(); |
275 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( | 276 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( |
(...skipping 24 matching lines...) Expand all Loading... |
300 return; | 301 return; |
301 } | 302 } |
302 std::pair<base::Closure, ErrorCallback> callbacks; | 303 std::pair<base::Closure, ErrorCallback> callbacks; |
303 callbacks.swap(write_characteristic_value_callbacks_); | 304 callbacks.swap(write_characteristic_value_callbacks_); |
304 characteristic_value_read_or_write_in_progress_ = false; | 305 characteristic_value_read_or_write_in_progress_ = false; |
305 if (error) { | 306 if (error) { |
306 BluetoothGattService::GattErrorCode error_code = | 307 BluetoothGattService::GattErrorCode error_code = |
307 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 308 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
308 VLOG(1) << *this | 309 VLOG(1) << *this |
309 << ": Bluetooth error while writing for characteristic, error: " | 310 << ": Bluetooth error while writing for characteristic, error: " |
310 << error << ", error code: " << error_code; | 311 << BluetoothAdapterMac::String(error) |
| 312 << ", error code: " << error_code; |
311 callbacks.second.Run(error_code); | 313 callbacks.second.Run(error_code); |
312 return; | 314 return; |
313 } | 315 } |
314 VLOG(1) << *this << ": Write value succeeded."; | 316 VLOG(1) << *this << ": Write value succeeded."; |
315 callbacks.first.Run(); | 317 callbacks.first.Run(); |
316 } | 318 } |
317 | 319 |
318 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( | 320 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( |
319 NSError* error) { | 321 NSError* error) { |
320 PendingNotifyCallbacks reentrant_safe_callbacks; | 322 PendingNotifyCallbacks reentrant_safe_callbacks; |
321 if (!subscribe_to_notification_callbacks_.first.is_null()) { | 323 if (!subscribe_to_notification_callbacks_.first.is_null()) { |
322 DCHECK([GetCBCharacteristic() isNotifying] || error); | 324 DCHECK([GetCBCharacteristic() isNotifying] || error); |
323 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); | 325 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); |
324 } else if (!unsubscribe_from_notification_callbacks_.first.is_null()) { | 326 } else if (!unsubscribe_from_notification_callbacks_.first.is_null()) { |
325 DCHECK(![GetCBCharacteristic() isNotifying] || error); | 327 DCHECK(![GetCBCharacteristic() isNotifying] || error); |
326 reentrant_safe_callbacks.swap(unsubscribe_from_notification_callbacks_); | 328 reentrant_safe_callbacks.swap(unsubscribe_from_notification_callbacks_); |
327 } else { | 329 } else { |
328 VLOG(1) << *this << ": No pending notification update for characteristic."; | 330 VLOG(1) << *this << ": No pending notification update for characteristic."; |
329 return; | 331 return; |
330 } | 332 } |
331 if (error) { | 333 if (error) { |
332 BluetoothGattService::GattErrorCode error_code = | 334 BluetoothGattService::GattErrorCode error_code = |
333 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 335 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
334 VLOG(1) << *this | 336 VLOG(1) << *this |
335 << ": Bluetooth error while modifying notification state for " | 337 << ": Bluetooth error while modifying notification state for " |
336 "characteristic, error: " | 338 "characteristic, error: " |
337 << error << ", error code: " << error_code; | 339 << BluetoothAdapterMac::String(error) |
| 340 << ", error code: " << error_code; |
338 reentrant_safe_callbacks.second.Run(error_code); | 341 reentrant_safe_callbacks.second.Run(error_code); |
339 return; | 342 return; |
340 } | 343 } |
341 reentrant_safe_callbacks.first.Run(); | 344 reentrant_safe_callbacks.first.Run(); |
342 } | 345 } |
343 | 346 |
344 void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() { | 347 void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() { |
345 DCHECK(!is_discovery_complete_); | 348 DCHECK(!is_discovery_complete_); |
346 VLOG(1) << *this << ": Did discover descriptors."; | 349 VLOG(1) << *this << ": Did discover descriptors."; |
347 std::unordered_set<std::string> descriptor_identifier_to_remove; | 350 std::unordered_set<std::string> descriptor_identifier_to_remove; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 const BluetoothRemoteGattServiceMac* service_mac = | 447 const BluetoothRemoteGattServiceMac* service_mac = |
445 static_cast<const BluetoothRemoteGattServiceMac*>( | 448 static_cast<const BluetoothRemoteGattServiceMac*>( |
446 characteristic.GetService()); | 449 characteristic.GetService()); |
447 return out << "<BluetoothRemoteGattCharacteristicMac " | 450 return out << "<BluetoothRemoteGattCharacteristicMac " |
448 << characteristic.GetUUID().canonical_value() << "/" | 451 << characteristic.GetUUID().canonical_value() << "/" |
449 << &characteristic | 452 << &characteristic |
450 << ", service: " << service_mac->GetUUID().canonical_value() << "/" | 453 << ", service: " << service_mac->GetUUID().canonical_value() << "/" |
451 << service_mac << ">"; | 454 << service_mac << ">"; |
452 } | 455 } |
453 } // namespace device. | 456 } // namespace device. |
OLD | NEW |