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 const base::Closure& callback, |
| 273 const ErrorCallback& error_callback) { |
| 274 NOTIMPLEMENTED(); |
| 275 } |
| 276 |
| 277 void BluetoothRemoteGattCharacteristicWin::UnsubscribeFromNotifications( |
| 278 const base::Closure& callback, |
| 279 const ErrorCallback& error_callback) { |
| 280 NOTIMPLEMENTED(); |
| 281 } |
| 282 |
265 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( | 283 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( |
266 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, | 284 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, |
267 uint16_t num, | 285 uint16_t num, |
268 HRESULT hr) { | 286 HRESULT hr) { |
269 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 287 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
270 | 288 |
271 UpdateIncludedDescriptors(descriptors.get(), num); | 289 UpdateIncludedDescriptors(descriptors.get(), num); |
272 if (!characteristic_added_notified_) { | 290 if (!characteristic_added_notified_) { |
273 characteristic_added_notified_ = true; | 291 characteristic_added_notified_ = true; |
274 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); | 292 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 HRESULT hr) { | 433 HRESULT hr) { |
416 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 434 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
417 | 435 |
418 gatt_event_registeration_in_progress_ = false; | 436 gatt_event_registeration_in_progress_ = false; |
419 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; | 437 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; |
420 callbacks.swap(start_notify_session_callbacks_); | 438 callbacks.swap(start_notify_session_callbacks_); |
421 if (SUCCEEDED(hr)) { | 439 if (SUCCEEDED(hr)) { |
422 gatt_event_handle_ = event_handle; | 440 gatt_event_handle_ = event_handle; |
423 for (const auto& callback : callbacks) { | 441 for (const auto& callback : callbacks) { |
424 callback.first.Run(base::WrapUnique( | 442 callback.first.Run(base::WrapUnique( |
425 new BluetoothGattNotifySessionWin(weak_ptr_factory_.GetWeakPtr()))); | 443 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr()))); |
426 } | 444 } |
427 } else { | 445 } else { |
428 for (const auto& callback : callbacks) | 446 for (const auto& callback : callbacks) |
429 callback.second.Run(HRESULTToGattErrorCode(hr)); | 447 callback.second.Run(HRESULTToGattErrorCode(hr)); |
430 } | 448 } |
431 } | 449 } |
432 | 450 |
433 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { | 451 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { |
434 // Explicitly reset to null to ensure that calling GetDescriptor() on the | 452 // Explicitly reset to null to ensure that calling GetDescriptor() on the |
435 // removed descriptor in GattDescriptorRemoved() returns null. | 453 // removed descriptor in GattDescriptorRemoved() returns null. |
436 for (auto& entry : included_descriptors_) | 454 for (auto& entry : included_descriptors_) |
437 entry.second.reset(); | 455 entry.second.reset(); |
438 included_descriptors_.clear(); | 456 included_descriptors_.clear(); |
439 } | 457 } |
440 | 458 |
441 } // namespace device. | 459 } // namespace device. |
OLD | NEW |