| 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" | 
| 11 #include "device/bluetooth/bluetooth_adapter_mac.h" | 11 #include "device/bluetooth/bluetooth_adapter_mac.h" | 
| 12 #include "device/bluetooth/bluetooth_device_mac.h" | 12 #include "device/bluetooth/bluetooth_device_mac.h" | 
| 13 #include "device/bluetooth/bluetooth_gatt_notify_session_mac.h" | 13 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 
| 14 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" | 
| 15 | 15 | 
| 16 namespace device { | 16 namespace device { | 
| 17 | 17 | 
| 18 namespace { | 18 namespace { | 
| 19 | 19 | 
| 20 static BluetoothGattCharacteristic::Properties ConvertProperties( | 20 static BluetoothGattCharacteristic::Properties ConvertProperties( | 
| 21     CBCharacteristicProperties cb_property) { | 21     CBCharacteristicProperties cb_property) { | 
| 22   BluetoothGattCharacteristic::Properties result = | 22   BluetoothGattCharacteristic::Properties result = | 
| 23       BluetoothGattCharacteristic::PROPERTY_NONE; | 23       BluetoothGattCharacteristic::PROPERTY_NONE; | 
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 127     const std::string& identifier) const { | 127     const std::string& identifier) const { | 
| 128   NOTIMPLEMENTED(); | 128   NOTIMPLEMENTED(); | 
| 129   return nullptr; | 129   return nullptr; | 
| 130 } | 130 } | 
| 131 | 131 | 
| 132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( | 132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( | 
| 133     const NotifySessionCallback& callback, | 133     const NotifySessionCallback& callback, | 
| 134     const ErrorCallback& error_callback) { | 134     const ErrorCallback& error_callback) { | 
| 135   if (IsNotifying()) { | 135   if (IsNotifying()) { | 
| 136     VLOG(2) << "Already notifying. Creating notify session."; | 136     VLOG(2) << "Already notifying. Creating notify session."; | 
| 137     std::unique_ptr<BluetoothGattNotifySessionMac> notify_session( | 137     std::unique_ptr<BluetoothGattNotifySession> notify_session( | 
| 138         new BluetoothGattNotifySessionMac(weak_ptr_factory_.GetWeakPtr())); | 138         new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr())); | 
| 139     base::ThreadTaskRunnerHandle::Get()->PostTask( | 139     base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 140         FROM_HERE, | 140         FROM_HERE, | 
| 141         base::Bind(callback, base::Passed(std::move(notify_session)))); | 141         base::Bind(callback, base::Passed(std::move(notify_session)))); | 
| 142     return; | 142     return; | 
| 143   } | 143   } | 
| 144 | 144 | 
| 145   if (!SupportsNotificationsOrIndications()) { | 145   if (!SupportsNotificationsOrIndications()) { | 
| 146     base::ThreadTaskRunnerHandle::Get()->PostTask( | 146     base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 147         FROM_HERE, | 147         FROM_HERE, | 
| 148         base::Bind(error_callback, | 148         base::Bind(error_callback, | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 216                              forCharacteristic:cb_characteristic_ | 216                              forCharacteristic:cb_characteristic_ | 
| 217                                           type:write_type]; | 217                                           type:write_type]; | 
| 218   if (write_type == CBCharacteristicWriteWithoutResponse) { | 218   if (write_type == CBCharacteristicWriteWithoutResponse) { | 
| 219     base::ThreadTaskRunnerHandle::Get()->PostTask( | 219     base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 220         FROM_HERE, | 220         FROM_HERE, | 
| 221         base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, | 221         base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, | 
| 222                    base::Unretained(this), nil)); | 222                    base::Unretained(this), nil)); | 
| 223   } | 223   } | 
| 224 } | 224 } | 
| 225 | 225 | 
|  | 226 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( | 
|  | 227     BluetoothRemoteGattDescriptor* ccc_descriptor, | 
|  | 228     const base::Closure& callback, | 
|  | 229     const ErrorCallback& error_callback) { | 
|  | 230   // TODO(http://crbug.com/633191): Implement this method | 
|  | 231   NOTIMPLEMENTED(); | 
|  | 232 } | 
|  | 233 | 
|  | 234 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( | 
|  | 235     BluetoothRemoteGattDescriptor* ccc_descriptor, | 
|  | 236     const base::Closure& callback, | 
|  | 237     const ErrorCallback& error_callback) { | 
|  | 238   // TODO(http://crbug.com/633191): Implement this method | 
|  | 239   NOTIMPLEMENTED(); | 
|  | 240 } | 
|  | 241 | 
| 226 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { | 242 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { | 
| 227   // This method is called when the characteristic is read and when a | 243   // This method is called when the characteristic is read and when a | 
| 228   // notification is received. | 244   // notification is received. | 
| 229   if (characteristic_value_read_or_write_in_progress_) { | 245   if (characteristic_value_read_or_write_in_progress_) { | 
| 230     std::pair<ValueCallback, ErrorCallback> callbacks; | 246     std::pair<ValueCallback, ErrorCallback> callbacks; | 
| 231     callbacks.swap(read_characteristic_value_callbacks_); | 247     callbacks.swap(read_characteristic_value_callbacks_); | 
| 232     characteristic_value_read_or_write_in_progress_ = false; | 248     characteristic_value_read_or_write_in_progress_ = false; | 
| 233     if (error) { | 249     if (error) { | 
| 234       VLOG(1) << "Bluetooth error while reading for characteristic, domain: " | 250       VLOG(1) << "Bluetooth error while reading for characteristic, domain: " | 
| 235               << base::SysNSStringToUTF8(error.domain) | 251               << base::SysNSStringToUTF8(error.domain) | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 299             << ", error code: " << error.code << ", localized description: " | 315             << ", error code: " << error.code << ", localized description: " | 
| 300             << base::SysNSStringToUTF8(error.localizedDescription); | 316             << base::SysNSStringToUTF8(error.localizedDescription); | 
| 301     BluetoothGattService::GattErrorCode error_code = | 317     BluetoothGattService::GattErrorCode error_code = | 
| 302         BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 318         BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 
| 303     for (const auto& callback : reentrant_safe_callbacks) { | 319     for (const auto& callback : reentrant_safe_callbacks) { | 
| 304       callback.second.Run(error_code); | 320       callback.second.Run(error_code); | 
| 305     } | 321     } | 
| 306     return; | 322     return; | 
| 307   } | 323   } | 
| 308   for (const auto& callback : reentrant_safe_callbacks) { | 324   for (const auto& callback : reentrant_safe_callbacks) { | 
| 309     callback.first.Run(base::MakeUnique<BluetoothGattNotifySessionMac>( | 325     callback.first.Run(base::MakeUnique<BluetoothGattNotifySession>( | 
| 310         weak_ptr_factory_.GetWeakPtr())); | 326         weak_ptr_factory_.GetWeakPtr())); | 
| 311   } | 327   } | 
| 312 } | 328 } | 
| 313 | 329 | 
| 314 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { | 330 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { | 
| 315   return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; | 331   return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; | 
| 316 } | 332 } | 
| 317 | 333 | 
| 318 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const { | 334 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const { | 
| 319   BluetoothGattCharacteristic::Properties properties = GetProperties(); | 335   BluetoothGattCharacteristic::Properties properties = GetProperties(); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 332   return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) | 348   return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) | 
| 333              ? CBCharacteristicWriteWithResponse | 349              ? CBCharacteristicWriteWithResponse | 
| 334              : CBCharacteristicWriteWithoutResponse; | 350              : CBCharacteristicWriteWithoutResponse; | 
| 335 } | 351 } | 
| 336 | 352 | 
| 337 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() | 353 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() | 
| 338     const { | 354     const { | 
| 339   return cb_characteristic_.get(); | 355   return cb_characteristic_.get(); | 
| 340 } | 356 } | 
| 341 }  // namespace device. | 357 }  // namespace device. | 
| OLD | NEW | 
|---|