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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 FROM_HERE, | 203 FROM_HERE, |
204 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, | 204 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, |
205 base::Unretained(this), nil)); | 205 base::Unretained(this), nil)); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( | 209 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( |
210 BluetoothRemoteGattDescriptor* ccc_descriptor, | 210 BluetoothRemoteGattDescriptor* ccc_descriptor, |
211 const base::Closure& callback, | 211 const base::Closure& callback, |
212 const ErrorCallback& error_callback) { | 212 const ErrorCallback& error_callback) { |
213 DCHECK(subscribe_to_notification_callback_.first.is_null()); | 213 DCHECK(subscribe_to_notification_callbacks_.first.is_null()); |
214 DCHECK(subscribe_to_notification_callback_.second.is_null()); | 214 DCHECK(subscribe_to_notification_callbacks_.second.is_null()); |
215 subscribe_to_notification_callback_ = | 215 subscribe_to_notification_callbacks_ = |
216 std::make_pair(callback, error_callback); | 216 std::make_pair(callback, error_callback); |
217 [GetCBPeripheral() setNotifyValue:YES | 217 [GetCBPeripheral() setNotifyValue:YES |
218 forCharacteristic:cb_characteristic_.get()]; | 218 forCharacteristic:cb_characteristic_.get()]; |
219 } | 219 } |
220 | 220 |
221 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( | 221 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( |
222 BluetoothRemoteGattDescriptor* ccc_descriptor, | 222 BluetoothRemoteGattDescriptor* ccc_descriptor, |
223 const base::Closure& callback, | 223 const base::Closure& callback, |
224 const ErrorCallback& error_callback) { | 224 const ErrorCallback& error_callback) { |
225 // TODO(http://crbug.com/633191): Implement this method | 225 // TODO(http://crbug.com/633191): Implement this method |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 BluetoothGattService::GattErrorCode error_code = | 287 BluetoothGattService::GattErrorCode error_code = |
288 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 288 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
289 callbacks.second.Run(error_code); | 289 callbacks.second.Run(error_code); |
290 return; | 290 return; |
291 } | 291 } |
292 callbacks.first.Run(); | 292 callbacks.first.Run(); |
293 } | 293 } |
294 | 294 |
295 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( | 295 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( |
296 NSError* error) { | 296 NSError* error) { |
297 PendingNotifyCallback reentrant_safe_callbacks; | 297 PendingNotifyCallbacks reentrant_safe_callbacks; |
298 reentrant_safe_callbacks.swap(subscribe_to_notification_callback_); | 298 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); |
299 if (error) { | 299 if (error) { |
300 VLOG(1) << "Bluetooth error while modifying notification state for " | 300 VLOG(1) << "Bluetooth error while modifying notification state for " |
301 "characteristic, domain: " | 301 "characteristic, domain: " |
302 << base::SysNSStringToUTF8(error.domain) | 302 << base::SysNSStringToUTF8(error.domain) |
303 << ", error code: " << error.code << ", localized description: " | 303 << ", error code: " << error.code << ", localized description: " |
304 << base::SysNSStringToUTF8(error.localizedDescription); | 304 << base::SysNSStringToUTF8(error.localizedDescription); |
305 BluetoothGattService::GattErrorCode error_code = | 305 BluetoothGattService::GattErrorCode error_code = |
306 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 306 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
307 if (!reentrant_safe_callbacks.second.is_null()) { | 307 if (!reentrant_safe_callbacks.second.is_null()) { |
308 reentrant_safe_callbacks.second.Run(error_code); | 308 reentrant_safe_callbacks.second.Run(error_code); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 pair) { | 400 pair) { |
401 return pair.second->GetCBDescriptor() == cb_descriptor; | 401 return pair.second->GetCBDescriptor() == cb_descriptor; |
402 }); | 402 }); |
403 if (found == gatt_descriptor_macs_.end()) { | 403 if (found == gatt_descriptor_macs_.end()) { |
404 return nullptr; | 404 return nullptr; |
405 } else { | 405 } else { |
406 return found->second.get(); | 406 return found->second.get(); |
407 } | 407 } |
408 } | 408 } |
409 } // namespace device. | 409 } // namespace device. |
OLD | NEW |