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