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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm

Issue 2051333004: Implement BluetoothGattNotifySession::Stop on Android, 2nd attempt (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make the rest of the methods in BluetoothGattNotifySession virtual 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_mac.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "device/bluetooth/bluetooth_adapter_mac.h" 11 #include "device/bluetooth/bluetooth_adapter_mac.h"
12 #include "device/bluetooth/bluetooth_device_mac.h" 12 #include "device/bluetooth/bluetooth_device_mac.h"
13 #include "device/bluetooth/bluetooth_gatt_notify_session_mac.h" 13 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
14 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" 14 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
15 15
16 namespace device { 16 namespace device {
17 17
18 namespace { 18 namespace {
19 19
20 static BluetoothGattCharacteristic::Properties ConvertProperties( 20 static BluetoothGattCharacteristic::Properties ConvertProperties(
21 CBCharacteristicProperties cb_property) { 21 CBCharacteristicProperties cb_property) {
22 BluetoothGattCharacteristic::Properties result = 22 BluetoothGattCharacteristic::Properties result =
23 BluetoothGattCharacteristic::PROPERTY_NONE; 23 BluetoothGattCharacteristic::PROPERTY_NONE;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const std::string& identifier) const { 127 const std::string& identifier) const {
128 NOTIMPLEMENTED(); 128 NOTIMPLEMENTED();
129 return nullptr; 129 return nullptr;
130 } 130 }
131 131
132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( 132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession(
133 const NotifySessionCallback& callback, 133 const NotifySessionCallback& callback,
134 const ErrorCallback& error_callback) { 134 const ErrorCallback& error_callback) {
135 if (IsNotifying()) { 135 if (IsNotifying()) {
136 VLOG(2) << "Already notifying. Creating notify session."; 136 VLOG(2) << "Already notifying. Creating notify session.";
137 std::unique_ptr<BluetoothGattNotifySessionMac> notify_session( 137 std::unique_ptr<BluetoothGattNotifySession> notify_session(
138 new BluetoothGattNotifySessionMac(weak_ptr_factory_.GetWeakPtr())); 138 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr()));
139 base::ThreadTaskRunnerHandle::Get()->PostTask( 139 base::ThreadTaskRunnerHandle::Get()->PostTask(
140 FROM_HERE, 140 FROM_HERE,
141 base::Bind(callback, base::Passed(std::move(notify_session)))); 141 base::Bind(callback, base::Passed(std::move(notify_session))));
142 return; 142 return;
143 } 143 }
144 144
145 if (!SupportsNotificationsOrIndications()) { 145 if (!SupportsNotificationsOrIndications()) {
146 base::ThreadTaskRunnerHandle::Get()->PostTask( 146 base::ThreadTaskRunnerHandle::Get()->PostTask(
147 FROM_HERE, 147 FROM_HERE,
148 base::Bind(error_callback, 148 base::Bind(error_callback,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 forCharacteristic:cb_characteristic_ 216 forCharacteristic:cb_characteristic_
217 type:write_type]; 217 type:write_type];
218 if (write_type == CBCharacteristicWriteWithoutResponse) { 218 if (write_type == CBCharacteristicWriteWithoutResponse) {
219 base::ThreadTaskRunnerHandle::Get()->PostTask( 219 base::ThreadTaskRunnerHandle::Get()->PostTask(
220 FROM_HERE, 220 FROM_HERE,
221 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, 221 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue,
222 base::Unretained(this), nil)); 222 base::Unretained(this), nil));
223 } 223 }
224 } 224 }
225 225
226 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications(
227 const base::Closure& callback,
228 const ErrorCallback& error_callback) {
229 NOTIMPLEMENTED();
ortuno 2016/07/28 21:59:30 Can you open an issue that mentions that this need
tommyt 2016/08/01 12:48:27 I have created https://crbug.com/633191
230 }
231
232 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications(
233 const base::Closure& callback,
234 const ErrorCallback& error_callback) {
235 NOTIMPLEMENTED();
236 }
237
226 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { 238 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) {
227 // This method is called when the characteristic is read and when a 239 // This method is called when the characteristic is read and when a
228 // notification is received. 240 // notification is received.
229 if (characteristic_value_read_or_write_in_progress_) { 241 if (characteristic_value_read_or_write_in_progress_) {
230 std::pair<ValueCallback, ErrorCallback> callbacks; 242 std::pair<ValueCallback, ErrorCallback> callbacks;
231 callbacks.swap(read_characteristic_value_callbacks_); 243 callbacks.swap(read_characteristic_value_callbacks_);
232 characteristic_value_read_or_write_in_progress_ = false; 244 characteristic_value_read_or_write_in_progress_ = false;
233 if (error) { 245 if (error) {
234 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " 246 VLOG(1) << "Bluetooth error while reading for characteristic, domain: "
235 << base::SysNSStringToUTF8(error.domain) 247 << base::SysNSStringToUTF8(error.domain)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 << ", error code: " << error.code << ", localized description: " 311 << ", error code: " << error.code << ", localized description: "
300 << base::SysNSStringToUTF8(error.localizedDescription); 312 << base::SysNSStringToUTF8(error.localizedDescription);
301 BluetoothGattService::GattErrorCode error_code = 313 BluetoothGattService::GattErrorCode error_code =
302 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); 314 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
303 for (const auto& callback : reentrant_safe_callbacks) { 315 for (const auto& callback : reentrant_safe_callbacks) {
304 callback.second.Run(error_code); 316 callback.second.Run(error_code);
305 } 317 }
306 return; 318 return;
307 } 319 }
308 for (const auto& callback : reentrant_safe_callbacks) { 320 for (const auto& callback : reentrant_safe_callbacks) {
309 callback.first.Run(base::MakeUnique<BluetoothGattNotifySessionMac>( 321 callback.first.Run(base::MakeUnique<BluetoothGattNotifySession>(
310 weak_ptr_factory_.GetWeakPtr())); 322 weak_ptr_factory_.GetWeakPtr()));
311 } 323 }
312 } 324 }
313 325
314 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { 326 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const {
315 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; 327 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ;
316 } 328 }
317 329
318 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const { 330 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const {
319 BluetoothGattCharacteristic::Properties properties = GetProperties(); 331 BluetoothGattCharacteristic::Properties properties = GetProperties();
(...skipping 12 matching lines...) Expand all
332 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) 344 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE)
333 ? CBCharacteristicWriteWithResponse 345 ? CBCharacteristicWriteWithResponse
334 : CBCharacteristicWriteWithoutResponse; 346 : CBCharacteristicWriteWithoutResponse;
335 } 347 }
336 348
337 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() 349 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic()
338 const { 350 const {
339 return cb_characteristic_.get(); 351 return cb_characteristic_.get();
340 } 352 }
341 } // namespace device. 353 } // namespace device.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698