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

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: Address Giovanni's review comments 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 BluetoothRemoteGattDescriptor* ccc_descriptor,
228 const base::Closure& callback,
229 const ErrorCallback& error_callback) {
230 NOTIMPLEMENTED();
231 }
232
233 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications(
234 BluetoothRemoteGattDescriptor* ccc_descriptor,
235 const base::Closure& callback,
236 const ErrorCallback& error_callback) {
237 NOTIMPLEMENTED();
238 }
239
226 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { 240 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) {
227 // This method is called when the characteristic is read and when a 241 // This method is called when the characteristic is read and when a
228 // notification is received. 242 // notification is received.
229 if (characteristic_value_read_or_write_in_progress_) { 243 if (characteristic_value_read_or_write_in_progress_) {
230 std::pair<ValueCallback, ErrorCallback> callbacks; 244 std::pair<ValueCallback, ErrorCallback> callbacks;
231 callbacks.swap(read_characteristic_value_callbacks_); 245 callbacks.swap(read_characteristic_value_callbacks_);
232 characteristic_value_read_or_write_in_progress_ = false; 246 characteristic_value_read_or_write_in_progress_ = false;
233 if (error) { 247 if (error) {
234 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " 248 VLOG(1) << "Bluetooth error while reading for characteristic, domain: "
235 << base::SysNSStringToUTF8(error.domain) 249 << base::SysNSStringToUTF8(error.domain)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 << ", error code: " << error.code << ", localized description: " 313 << ", error code: " << error.code << ", localized description: "
300 << base::SysNSStringToUTF8(error.localizedDescription); 314 << base::SysNSStringToUTF8(error.localizedDescription);
301 BluetoothGattService::GattErrorCode error_code = 315 BluetoothGattService::GattErrorCode error_code =
302 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); 316 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
303 for (const auto& callback : reentrant_safe_callbacks) { 317 for (const auto& callback : reentrant_safe_callbacks) {
304 callback.second.Run(error_code); 318 callback.second.Run(error_code);
305 } 319 }
306 return; 320 return;
307 } 321 }
308 for (const auto& callback : reentrant_safe_callbacks) { 322 for (const auto& callback : reentrant_safe_callbacks) {
309 callback.first.Run(base::MakeUnique<BluetoothGattNotifySessionMac>( 323 callback.first.Run(base::MakeUnique<BluetoothGattNotifySession>(
310 weak_ptr_factory_.GetWeakPtr())); 324 weak_ptr_factory_.GetWeakPtr()));
311 } 325 }
312 } 326 }
313 327
314 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { 328 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const {
315 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; 329 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ;
316 } 330 }
317 331
318 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const { 332 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const {
319 BluetoothGattCharacteristic::Properties properties = GetProperties(); 333 BluetoothGattCharacteristic::Properties properties = GetProperties();
(...skipping 12 matching lines...) Expand all
332 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) 346 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE)
333 ? CBCharacteristicWriteWithResponse 347 ? CBCharacteristicWriteWithResponse
334 : CBCharacteristicWriteWithoutResponse; 348 : CBCharacteristicWriteWithoutResponse;
335 } 349 }
336 350
337 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() 351 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic()
338 const { 352 const {
339 return cb_characteristic_.get(); 353 return cb_characteristic_.get();
340 } 354 }
341 } // namespace device. 355 } // namespace device.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698