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 // TODO(http://crbug.com/636270): Remove this method and use the base version. |
| 204 // Instead, we should implement SubscribeToNotifications and |
| 205 // UnsubscribeFromNotifications. |
| 206 |
| 207 ui_task_runner_->PostTask(FROM_HERE, callback); |
| 208 } |
| 209 |
200 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( | 210 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( |
201 const ValueCallback& callback, | 211 const ValueCallback& callback, |
202 const ErrorCallback& error_callback) { | 212 const ErrorCallback& error_callback) { |
203 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 213 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
204 | 214 |
205 if (!characteristic_info_.get()->IsReadable) { | 215 if (!characteristic_info_.get()->IsReadable) { |
206 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); | 216 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); |
207 return; | 217 return; |
208 } | 218 } |
209 | 219 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 parent_service_->GetServicePath(), characteristic_info_.get(), | 265 parent_service_->GetServicePath(), characteristic_info_.get(), |
256 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | 266 base::Bind(&BluetoothRemoteGattCharacteristicWin:: |
257 OnGetIncludedDescriptorsCallback, | 267 OnGetIncludedDescriptorsCallback, |
258 weak_ptr_factory_.GetWeakPtr())); | 268 weak_ptr_factory_.GetWeakPtr())); |
259 } | 269 } |
260 | 270 |
261 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { | 271 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { |
262 return characteristic_info_->AttributeHandle; | 272 return characteristic_info_->AttributeHandle; |
263 } | 273 } |
264 | 274 |
| 275 void BluetoothRemoteGattCharacteristicWin::SubscribeToNotifications( |
| 276 BluetoothRemoteGattDescriptor* ccc_descriptor, |
| 277 const base::Closure& callback, |
| 278 const ErrorCallback& error_callback) { |
| 279 // TODO(http://crbug.com/636270): Implement this method |
| 280 NOTIMPLEMENTED(); |
| 281 } |
| 282 |
| 283 void BluetoothRemoteGattCharacteristicWin::UnsubscribeFromNotifications( |
| 284 BluetoothRemoteGattDescriptor* ccc_descriptor, |
| 285 const base::Closure& callback, |
| 286 const ErrorCallback& error_callback) { |
| 287 // TODO(http://crbug.com/636270): Implement this method |
| 288 NOTIMPLEMENTED(); |
| 289 } |
| 290 |
265 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( | 291 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( |
266 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, | 292 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, |
267 uint16_t num, | 293 uint16_t num, |
268 HRESULT hr) { | 294 HRESULT hr) { |
269 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 295 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
270 | 296 |
271 UpdateIncludedDescriptors(descriptors.get(), num); | 297 UpdateIncludedDescriptors(descriptors.get(), num); |
272 if (!characteristic_added_notified_) { | 298 if (!characteristic_added_notified_) { |
273 characteristic_added_notified_ = true; | 299 characteristic_added_notified_ = true; |
274 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); | 300 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 HRESULT hr) { | 441 HRESULT hr) { |
416 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 442 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
417 | 443 |
418 gatt_event_registeration_in_progress_ = false; | 444 gatt_event_registeration_in_progress_ = false; |
419 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; | 445 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; |
420 callbacks.swap(start_notify_session_callbacks_); | 446 callbacks.swap(start_notify_session_callbacks_); |
421 if (SUCCEEDED(hr)) { | 447 if (SUCCEEDED(hr)) { |
422 gatt_event_handle_ = event_handle; | 448 gatt_event_handle_ = event_handle; |
423 for (const auto& callback : callbacks) { | 449 for (const auto& callback : callbacks) { |
424 callback.first.Run(base::WrapUnique( | 450 callback.first.Run(base::WrapUnique( |
425 new BluetoothGattNotifySessionWin(weak_ptr_factory_.GetWeakPtr()))); | 451 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr()))); |
426 } | 452 } |
427 } else { | 453 } else { |
428 for (const auto& callback : callbacks) | 454 for (const auto& callback : callbacks) |
429 callback.second.Run(HRESULTToGattErrorCode(hr)); | 455 callback.second.Run(HRESULTToGattErrorCode(hr)); |
430 } | 456 } |
431 } | 457 } |
432 | 458 |
433 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { | 459 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { |
434 // Explicitly reset to null to ensure that calling GetDescriptor() on the | 460 // Explicitly reset to null to ensure that calling GetDescriptor() on the |
435 // removed descriptor in GattDescriptorRemoved() returns null. | 461 // removed descriptor in GattDescriptorRemoved() returns null. |
436 for (auto& entry : included_descriptors_) | 462 for (auto& entry : included_descriptors_) |
437 entry.second.reset(); | 463 entry.second.reset(); |
438 included_descriptors_.clear(); | 464 included_descriptors_.clear(); |
439 } | 465 } |
440 | 466 |
441 } // namespace device. | 467 } // namespace device. |
OLD | NEW |