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

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

Issue 1950033002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@servicescan_cleanup
Patch Set: Addressing comments Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_low_energy_device_mac.h" 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h"
6 6
7 #import <CoreFoundation/CoreFoundation.h> 7 #import <CoreFoundation/CoreFoundation.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 GetBluetoothRemoteGattService(cb_service); 251 GetBluetoothRemoteGattService(cb_service);
252 if (!gatt_service) { 252 if (!gatt_service) {
253 gatt_service = new BluetoothRemoteGattServiceMac(this, cb_service, 253 gatt_service = new BluetoothRemoteGattServiceMac(this, cb_service,
254 true /* is_primary */); 254 true /* is_primary */);
255 auto result_iter = gatt_services_.add(gatt_service->GetIdentifier(), 255 auto result_iter = gatt_services_.add(gatt_service->GetIdentifier(),
256 base::WrapUnique(gatt_service)); 256 base::WrapUnique(gatt_service));
257 DCHECK(result_iter.second); 257 DCHECK(result_iter.second);
258 adapter_->NotifyGattServiceAdded(gatt_service); 258 adapter_->NotifyGattServiceAdded(gatt_service);
259 } 259 }
260 } 260 }
261 // TODO(http://crbug.com/609064): Services are fully discovered once all 261 for (GattServiceMap::const_iterator it = gatt_services_.begin();
262 // characteristics have been found. 262 it != gatt_services_.end(); ++it) {
263 SetGattServicesDiscoveryComplete(true); 263 device::BluetoothRemoteGattService* gatt_service = it->second;
264 adapter_->NotifyGattServicesDiscovered(this); 264 device::BluetoothRemoteGattServiceMac* gatt_service_mac =
265 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
266 gatt_service_mac->DiscoverCharacteristics();
267 }
268 }
269
270 void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics(
271 CBService* cb_service,
272 NSError* error) {
273 if (error) {
274 // TODO(http://crbug.com/609320): Need to pass the error.
275 // TODO(http://crbug.com/609844): Decide what to do if we fail to discover
msarda 2016/06/14 09:15:05 Do not use we in comments.
jlebel 2016/06/15 16:16:36 Done.
276 // a device services.
277 VLOG(1) << "Can't discover characteristics: "
278 << error.localizedDescription.UTF8String << " (" << error.domain
279 << ": " << error.code << ")";
280 return;
281 }
282 BluetoothRemoteGattServiceMac* gatt_service =
283 GetBluetoothRemoteGattService(cb_service);
284 DCHECK(gatt_service);
285 gatt_service->DidDiscoverCharacteristics();
286
287 // Notify when all services have been discovered.
288 bool discovery_complete = true;
289 for (GattServiceMap::const_iterator it = gatt_services_.begin();
ortuno 2016/06/13 20:51:19 I think you could do: bool discovery_complete = s
jlebel 2016/06/15 16:16:36 Done.
290 it != gatt_services_.end(); ++it) {
291 device::BluetoothRemoteGattService* gatt_service = it->second;
ortuno 2016/06/13 20:51:19 Why do you need "device::" here?
jlebel 2016/06/15 16:16:36 Done.
292 device::BluetoothRemoteGattServiceMac* gatt_service_mac =
293 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
294 discovery_complete = gatt_service_mac->IsDiscoveryComplete();
295 if (!discovery_complete) {
msarda 2016/06/14 09:15:05 I think this could just be: if (!gatt_service_mac-
jlebel 2016/06/15 16:16:36 Done.
296 break;
297 }
298 }
299 if (discovery_complete) {
300 SetGattServicesDiscoveryComplete(true);
301 adapter_->NotifyGattServicesDiscovered(this);
302 }
265 } 303 }
266 304
267 void BluetoothLowEnergyDeviceMac::DidModifyServices( 305 void BluetoothLowEnergyDeviceMac::DidModifyServices(
268 NSArray* invalidatedServices) { 306 NSArray* invalidatedServices) {
269 for (CBService* cb_service in invalidatedServices) { 307 for (CBService* cb_service in invalidatedServices) {
270 BluetoothRemoteGattServiceMac* gatt_service = 308 BluetoothRemoteGattServiceMac* gatt_service =
271 GetBluetoothRemoteGattService(cb_service); 309 GetBluetoothRemoteGattService(cb_service);
272 DCHECK(gatt_service); 310 DCHECK(gatt_service);
273 std::unique_ptr<BluetoothRemoteGattService> scoped_service = 311 std::unique_ptr<BluetoothRemoteGattService> scoped_service =
274 gatt_services_.take_and_erase(gatt_service->GetIdentifier()); 312 gatt_services_.take_and_erase(gatt_service->GetIdentifier());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 GattServiceMap gatt_services_swapped; 366 GattServiceMap gatt_services_swapped;
329 gatt_services_swapped.swap(gatt_services_); 367 gatt_services_swapped.swap(gatt_services_);
330 gatt_services_swapped.clear(); 368 gatt_services_swapped.clear();
331 if (create_gatt_connection_error_callbacks_.empty()) { 369 if (create_gatt_connection_error_callbacks_.empty()) {
332 // TODO(http://crbug.com/585897): Need to pass the error. 370 // TODO(http://crbug.com/585897): Need to pass the error.
333 DidDisconnectGatt(); 371 DidDisconnectGatt();
334 } else { 372 } else {
335 DidFailToConnectGatt(error_code); 373 DidFailToConnectGatt(error_code);
336 } 374 }
337 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698