| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return result; | 64 return result; |
| 65 } | 65 } |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 BluetoothRemoteGattCharacteristicMac::BluetoothRemoteGattCharacteristicMac( | 68 BluetoothRemoteGattCharacteristicMac::BluetoothRemoteGattCharacteristicMac( |
| 69 BluetoothRemoteGattServiceMac* gatt_service, | 69 BluetoothRemoteGattServiceMac* gatt_service, |
| 70 CBCharacteristic* cb_characteristic) | 70 CBCharacteristic* cb_characteristic) |
| 71 : gatt_service_(gatt_service), | 71 : gatt_service_(gatt_service), |
| 72 cb_characteristic_(cb_characteristic, base::scoped_policy::RETAIN), | 72 cb_characteristic_(cb_characteristic, base::scoped_policy::RETAIN), |
| 73 characteristic_value_read_or_write_in_progress_(false), | 73 characteristic_value_read_or_write_in_progress_(false), |
| 74 start_notifications_in_progress_(false), |
| 74 weak_ptr_factory_(this) { | 75 weak_ptr_factory_(this) { |
| 75 uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID( | 76 uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID( |
| 76 [cb_characteristic_.get() UUID]); | 77 [cb_characteristic_.get() UUID]); |
| 77 identifier_ = base::SysNSStringToUTF8( | 78 identifier_ = base::SysNSStringToUTF8( |
| 78 [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), | 79 [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), |
| 79 (void*)cb_characteristic_]); | 80 (void*)cb_characteristic_]); |
| 80 } | 81 } |
| 81 | 82 |
| 82 BluetoothRemoteGattCharacteristicMac::~BluetoothRemoteGattCharacteristicMac() {} | 83 BluetoothRemoteGattCharacteristicMac::~BluetoothRemoteGattCharacteristicMac() {} |
| 83 | 84 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 BluetoothRemoteGattCharacteristicMac::GetDescriptor( | 126 BluetoothRemoteGattCharacteristicMac::GetDescriptor( |
| 126 const std::string& identifier) const { | 127 const std::string& identifier) const { |
| 127 NOTIMPLEMENTED(); | 128 NOTIMPLEMENTED(); |
| 128 return nullptr; | 129 return nullptr; |
| 129 } | 130 } |
| 130 | 131 |
| 131 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( | 132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( |
| 132 const NotifySessionCallback& callback, | 133 const NotifySessionCallback& callback, |
| 133 const ErrorCallback& error_callback) { | 134 const ErrorCallback& error_callback) { |
| 134 if (IsNotifying()) { | 135 if (IsNotifying()) { |
| 136 VLOG(2) << "Already notifying. Creating notify session."; |
| 135 std::unique_ptr<BluetoothGattNotifySessionMac> notify_session( | 137 std::unique_ptr<BluetoothGattNotifySessionMac> notify_session( |
| 136 new BluetoothGattNotifySessionMac(weak_ptr_factory_.GetWeakPtr())); | 138 new BluetoothGattNotifySessionMac(weak_ptr_factory_.GetWeakPtr())); |
| 137 base::ThreadTaskRunnerHandle::Get()->PostTask( | 139 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 138 FROM_HERE, | 140 FROM_HERE, |
| 139 base::Bind(callback, base::Passed(std::move(notify_session)))); | 141 base::Bind(callback, base::Passed(std::move(notify_session)))); |
| 140 return; | 142 return; |
| 141 } | 143 } |
| 144 |
| 142 if (!SupportsNotificationsOrIndications()) { | 145 if (!SupportsNotificationsOrIndications()) { |
| 143 base::ThreadTaskRunnerHandle::Get()->PostTask( | 146 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 144 FROM_HERE, | 147 FROM_HERE, |
| 145 base::Bind(error_callback, | 148 base::Bind(error_callback, |
| 146 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); | 149 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
| 147 return; | 150 return; |
| 148 } | 151 } |
| 152 |
| 149 start_notify_session_callbacks_.push_back( | 153 start_notify_session_callbacks_.push_back( |
| 150 std::make_pair(callback, error_callback)); | 154 std::make_pair(callback, error_callback)); |
| 151 if (start_notifications_in_progress_) | 155 |
| 156 if (start_notifications_in_progress_) { |
| 157 VLOG(2) << "Start Notifications already in progress. " |
| 158 << "Request has been queued."; |
| 152 return; | 159 return; |
| 160 } |
| 161 |
| 153 [gatt_service_->GetCBPeripheral() setNotifyValue:YES | 162 [gatt_service_->GetCBPeripheral() setNotifyValue:YES |
| 154 forCharacteristic:cb_characteristic_.get()]; | 163 forCharacteristic:cb_characteristic_.get()]; |
| 155 start_notifications_in_progress_ = true; | 164 start_notifications_in_progress_ = true; |
| 156 } | 165 } |
| 157 | 166 |
| 158 void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( | 167 void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( |
| 159 const ValueCallback& callback, | 168 const ValueCallback& callback, |
| 160 const ErrorCallback& error_callback) { | 169 const ErrorCallback& error_callback) { |
| 161 if (!IsReadable()) { | 170 if (!IsReadable()) { |
| 162 base::ThreadTaskRunnerHandle::Get()->PostTask( | 171 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) | 332 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) |
| 324 ? CBCharacteristicWriteWithResponse | 333 ? CBCharacteristicWriteWithResponse |
| 325 : CBCharacteristicWriteWithoutResponse; | 334 : CBCharacteristicWriteWithoutResponse; |
| 326 } | 335 } |
| 327 | 336 |
| 328 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() | 337 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() |
| 329 const { | 338 const { |
| 330 return cb_characteristic_.get(); | 339 return cb_characteristic_.get(); |
| 331 } | 340 } |
| 332 } // namespace device. | 341 } // namespace device. |
| OLD | NEW |