| 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_win.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "device/bluetooth/bluetooth_adapter_win.h" | 11 #include "device/bluetooth/bluetooth_adapter_win.h" |
| 12 #include "device/bluetooth/bluetooth_gatt_notify_session_win.h" | 12 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 13 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" | 13 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" |
| 14 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" |
| 15 #include "device/bluetooth/bluetooth_task_manager_win.h" | 15 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 16 | 16 |
| 17 namespace device { | 17 namespace device { |
| 18 | 18 |
| 19 BluetoothRemoteGattCharacteristicWin::BluetoothRemoteGattCharacteristicWin( | 19 BluetoothRemoteGattCharacteristicWin::BluetoothRemoteGattCharacteristicWin( |
| 20 BluetoothRemoteGattServiceWin* parent_service, | 20 BluetoothRemoteGattServiceWin* parent_service, |
| 21 BTH_LE_GATT_CHARACTERISTIC* characteristic_info, | 21 BTH_LE_GATT_CHARACTERISTIC* characteristic_info, |
| 22 scoped_refptr<base::SequencedTaskRunner>& ui_task_runner) | 22 scoped_refptr<base::SequencedTaskRunner>& ui_task_runner) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return it->second.get(); | 138 return it->second.get(); |
| 139 return nullptr; | 139 return nullptr; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void BluetoothRemoteGattCharacteristicWin::StartNotifySession( | 142 void BluetoothRemoteGattCharacteristicWin::StartNotifySession( |
| 143 const NotifySessionCallback& callback, | 143 const NotifySessionCallback& callback, |
| 144 const ErrorCallback& error_callback) { | 144 const ErrorCallback& error_callback) { |
| 145 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 145 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 146 | 146 |
| 147 if (IsNotifying()) { | 147 if (IsNotifying()) { |
| 148 std::unique_ptr<BluetoothGattNotifySessionWin> notify_session( | 148 std::unique_ptr<BluetoothGattNotifySession> notify_session( |
| 149 new BluetoothGattNotifySessionWin(weak_ptr_factory_.GetWeakPtr())); | 149 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr())); |
| 150 ui_task_runner_->PostTask( | 150 ui_task_runner_->PostTask( |
| 151 FROM_HERE, | 151 FROM_HERE, |
| 152 base::Bind(callback, base::Passed(std::move(notify_session)))); | 152 base::Bind(callback, base::Passed(std::move(notify_session)))); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 if (!characteristic_info_->IsNotifiable && | 156 if (!characteristic_info_->IsNotifiable && |
| 157 !characteristic_info_->IsIndicatable) { | 157 !characteristic_info_->IsIndicatable) { |
| 158 ui_task_runner_->PostTask( | 158 ui_task_runner_->PostTask( |
| 159 FROM_HERE, | 159 FROM_HERE, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 190 ->GetWinDescriptorInfo(), | 190 ->GetWinDescriptorInfo(), |
| 191 base::Bind( | 191 base::Bind( |
| 192 &BluetoothRemoteGattCharacteristicWin::GattEventRegistrationCallback, | 192 &BluetoothRemoteGattCharacteristicWin::GattEventRegistrationCallback, |
| 193 weak_ptr_factory_.GetWeakPtr()), | 193 weak_ptr_factory_.GetWeakPtr()), |
| 194 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | 194 base::Bind(&BluetoothRemoteGattCharacteristicWin:: |
| 195 OnGattCharacteristicValueChanged, | 195 OnGattCharacteristicValueChanged, |
| 196 weak_ptr_factory_.GetWeakPtr())); | 196 weak_ptr_factory_.GetWeakPtr())); |
| 197 gatt_event_registeration_in_progress_ = true; | 197 gatt_event_registeration_in_progress_ = true; |
| 198 } | 198 } |
| 199 | 199 |
| 200 void BluetoothRemoteGattCharacteristicWin::StopNotifySession( |
| 201 BluetoothGattNotifySession* session, |
| 202 const base::Closure& callback) { |
| 203 NOTIMPLEMENTED(); |
| 204 } |
| 205 |
| 200 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( | 206 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( |
| 201 const ValueCallback& callback, | 207 const ValueCallback& callback, |
| 202 const ErrorCallback& error_callback) { | 208 const ErrorCallback& error_callback) { |
| 203 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 209 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 204 | 210 |
| 205 if (!characteristic_info_.get()->IsReadable) { | 211 if (!characteristic_info_.get()->IsReadable) { |
| 206 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); | 212 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); |
| 207 return; | 213 return; |
| 208 } | 214 } |
| 209 | 215 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 parent_service_->GetServicePath(), characteristic_info_.get(), | 261 parent_service_->GetServicePath(), characteristic_info_.get(), |
| 256 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | 262 base::Bind(&BluetoothRemoteGattCharacteristicWin:: |
| 257 OnGetIncludedDescriptorsCallback, | 263 OnGetIncludedDescriptorsCallback, |
| 258 weak_ptr_factory_.GetWeakPtr())); | 264 weak_ptr_factory_.GetWeakPtr())); |
| 259 } | 265 } |
| 260 | 266 |
| 261 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { | 267 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { |
| 262 return characteristic_info_->AttributeHandle; | 268 return characteristic_info_->AttributeHandle; |
| 263 } | 269 } |
| 264 | 270 |
| 271 void BluetoothRemoteGattCharacteristicWin::SubscribeToNotifications( |
| 272 BluetoothRemoteGattDescriptor* ccc_descriptor, |
| 273 const base::Closure& callback, |
| 274 const ErrorCallback& error_callback) { |
| 275 NOTIMPLEMENTED(); |
| 276 } |
| 277 |
| 278 void BluetoothRemoteGattCharacteristicWin::UnsubscribeFromNotifications( |
| 279 BluetoothRemoteGattDescriptor* ccc_descriptor, |
| 280 const base::Closure& callback, |
| 281 const ErrorCallback& error_callback) { |
| 282 NOTIMPLEMENTED(); |
| 283 } |
| 284 |
| 265 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( | 285 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( |
| 266 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, | 286 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, |
| 267 uint16_t num, | 287 uint16_t num, |
| 268 HRESULT hr) { | 288 HRESULT hr) { |
| 269 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 289 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 270 | 290 |
| 271 UpdateIncludedDescriptors(descriptors.get(), num); | 291 UpdateIncludedDescriptors(descriptors.get(), num); |
| 272 if (!characteristic_added_notified_) { | 292 if (!characteristic_added_notified_) { |
| 273 characteristic_added_notified_ = true; | 293 characteristic_added_notified_ = true; |
| 274 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); | 294 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 HRESULT hr) { | 435 HRESULT hr) { |
| 416 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 436 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 417 | 437 |
| 418 gatt_event_registeration_in_progress_ = false; | 438 gatt_event_registeration_in_progress_ = false; |
| 419 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; | 439 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; |
| 420 callbacks.swap(start_notify_session_callbacks_); | 440 callbacks.swap(start_notify_session_callbacks_); |
| 421 if (SUCCEEDED(hr)) { | 441 if (SUCCEEDED(hr)) { |
| 422 gatt_event_handle_ = event_handle; | 442 gatt_event_handle_ = event_handle; |
| 423 for (const auto& callback : callbacks) { | 443 for (const auto& callback : callbacks) { |
| 424 callback.first.Run(base::WrapUnique( | 444 callback.first.Run(base::WrapUnique( |
| 425 new BluetoothGattNotifySessionWin(weak_ptr_factory_.GetWeakPtr()))); | 445 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr()))); |
| 426 } | 446 } |
| 427 } else { | 447 } else { |
| 428 for (const auto& callback : callbacks) | 448 for (const auto& callback : callbacks) |
| 429 callback.second.Run(HRESULTToGattErrorCode(hr)); | 449 callback.second.Run(HRESULTToGattErrorCode(hr)); |
| 430 } | 450 } |
| 431 } | 451 } |
| 432 | 452 |
| 433 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { | 453 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { |
| 434 // Explicitly reset to null to ensure that calling GetDescriptor() on the | 454 // Explicitly reset to null to ensure that calling GetDescriptor() on the |
| 435 // removed descriptor in GattDescriptorRemoved() returns null. | 455 // removed descriptor in GattDescriptorRemoved() returns null. |
| 436 for (auto& entry : included_descriptors_) | 456 for (auto& entry : included_descriptors_) |
| 437 entry.second.reset(); | 457 entry.second.reset(); |
| 438 included_descriptors_.clear(); | 458 included_descriptors_.clear(); |
| 439 } | 459 } |
| 440 | 460 |
| 441 } // namespace device. | 461 } // namespace device. |
| OLD | NEW |