Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc

Issue 2051333004: Implement BluetoothGattNotifySession::Stop on Android, 2nd attempt (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error on windows Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 callback.Run();
ortuno 2016/08/19 19:13:27 Why not have it post a task as well?
tommyt 2016/08/22 06:34:12 Done.
205 }
206
200 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( 207 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic(
201 const ValueCallback& callback, 208 const ValueCallback& callback,
202 const ErrorCallback& error_callback) { 209 const ErrorCallback& error_callback) {
203 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 210 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
204 211
205 if (!characteristic_info_.get()->IsReadable) { 212 if (!characteristic_info_.get()->IsReadable) {
206 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); 213 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED);
207 return; 214 return;
208 } 215 }
209 216
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 parent_service_->GetServicePath(), characteristic_info_.get(), 262 parent_service_->GetServicePath(), characteristic_info_.get(),
256 base::Bind(&BluetoothRemoteGattCharacteristicWin:: 263 base::Bind(&BluetoothRemoteGattCharacteristicWin::
257 OnGetIncludedDescriptorsCallback, 264 OnGetIncludedDescriptorsCallback,
258 weak_ptr_factory_.GetWeakPtr())); 265 weak_ptr_factory_.GetWeakPtr()));
259 } 266 }
260 267
261 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { 268 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const {
262 return characteristic_info_->AttributeHandle; 269 return characteristic_info_->AttributeHandle;
263 } 270 }
264 271
272 void BluetoothRemoteGattCharacteristicWin::SubscribeToNotifications(
273 BluetoothRemoteGattDescriptor* ccc_descriptor,
274 const base::Closure& callback,
275 const ErrorCallback& error_callback) {
276 // TODO(http://crbug.com/636270): Implement this method
277 NOTIMPLEMENTED();
278 }
279
280 void BluetoothRemoteGattCharacteristicWin::UnsubscribeFromNotifications(
281 BluetoothRemoteGattDescriptor* ccc_descriptor,
282 const base::Closure& callback,
283 const ErrorCallback& error_callback) {
284 // TODO(http://crbug.com/636270): Implement this method
285 NOTIMPLEMENTED();
286 }
287
265 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback( 288 void BluetoothRemoteGattCharacteristicWin::OnGetIncludedDescriptorsCallback(
266 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors, 289 std::unique_ptr<BTH_LE_GATT_DESCRIPTOR> descriptors,
267 uint16_t num, 290 uint16_t num,
268 HRESULT hr) { 291 HRESULT hr) {
269 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 292 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
270 293
271 UpdateIncludedDescriptors(descriptors.get(), num); 294 UpdateIncludedDescriptors(descriptors.get(), num);
272 if (!characteristic_added_notified_) { 295 if (!characteristic_added_notified_) {
273 characteristic_added_notified_ = true; 296 characteristic_added_notified_ = true;
274 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this); 297 parent_service_->GetWinAdapter()->NotifyGattCharacteristicAdded(this);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 HRESULT hr) { 438 HRESULT hr) {
416 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 439 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
417 440
418 gatt_event_registeration_in_progress_ = false; 441 gatt_event_registeration_in_progress_ = false;
419 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks; 442 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> callbacks;
420 callbacks.swap(start_notify_session_callbacks_); 443 callbacks.swap(start_notify_session_callbacks_);
421 if (SUCCEEDED(hr)) { 444 if (SUCCEEDED(hr)) {
422 gatt_event_handle_ = event_handle; 445 gatt_event_handle_ = event_handle;
423 for (const auto& callback : callbacks) { 446 for (const auto& callback : callbacks) {
424 callback.first.Run(base::WrapUnique( 447 callback.first.Run(base::WrapUnique(
425 new BluetoothGattNotifySessionWin(weak_ptr_factory_.GetWeakPtr()))); 448 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr())));
426 } 449 }
427 } else { 450 } else {
428 for (const auto& callback : callbacks) 451 for (const auto& callback : callbacks)
429 callback.second.Run(HRESULTToGattErrorCode(hr)); 452 callback.second.Run(HRESULTToGattErrorCode(hr));
430 } 453 }
431 } 454 }
432 455
433 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { 456 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() {
434 // Explicitly reset to null to ensure that calling GetDescriptor() on the 457 // Explicitly reset to null to ensure that calling GetDescriptor() on the
435 // removed descriptor in GattDescriptorRemoved() returns null. 458 // removed descriptor in GattDescriptorRemoved() returns null.
436 for (auto& entry : included_descriptors_) 459 for (auto& entry : included_descriptors_)
437 entry.second.reset(); 460 entry.second.reset();
438 included_descriptors_.clear(); 461 included_descriptors_.clear();
439 } 462 }
440 463
441 } // namespace device. 464 } // namespace device.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698