Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 VLOG(1) << *this << ": Can't discover characteristics: " | 247 VLOG(1) << *this << ": Can't discover characteristics: " |
| 248 << BluetoothAdapterMac::String(error); | 248 << BluetoothAdapterMac::String(error); |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 | 251 |
| 252 if (!IsGattConnected()) { | 252 if (!IsGattConnected()) { |
| 253 VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected."; | 253 VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected."; |
| 254 // Don't create characteristics if the device disconnected. | 254 // Don't create characteristics if the device disconnected. |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 if (IsGattServicesDiscoveryComplete()) { | |
| 258 // This should never happens, just in case it happens with a device, | |
|
scheib
2017/04/18 04:43:21
"never happen"
jlebel
2017/04/29 22:08:07
Done.
| |
| 259 // this notification should be ignored. | |
| 260 VLOG(1) << *this | |
| 261 << ": Discovery complete, ignoring DidDiscoverCharacteristics."; | |
| 262 return; | |
| 263 } | |
| 257 | 264 |
| 258 BluetoothRemoteGattServiceMac* gatt_service = | 265 BluetoothRemoteGattServiceMac* gatt_service = |
| 259 GetBluetoothRemoteGattService(cb_service); | 266 GetBluetoothRemoteGattService(cb_service); |
| 260 DCHECK(gatt_service); | 267 DCHECK(gatt_service); |
| 261 gatt_service->DidDiscoverCharacteristics(); | 268 gatt_service->DidDiscoverCharacteristics(); |
| 262 SendNotificationIfDiscoveryComplete(); | 269 SendNotificationIfDiscoveryComplete(); |
| 263 } | 270 } |
| 264 | 271 |
| 265 void BluetoothLowEnergyDeviceMac::DidModifyServices( | 272 void BluetoothLowEnergyDeviceMac::DidModifyServices( |
| 266 NSArray* invalidatedServices) { | 273 NSArray* invalidatedServices) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 325 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
| 319 VLOG(1) << *this << ": Can't discover descriptors: " | 326 VLOG(1) << *this << ": Can't discover descriptors: " |
| 320 << BluetoothAdapterMac::String(error); | 327 << BluetoothAdapterMac::String(error); |
| 321 return; | 328 return; |
| 322 } | 329 } |
| 323 if (!IsGattConnected()) { | 330 if (!IsGattConnected()) { |
| 324 VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected."; | 331 VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected."; |
| 325 // Don't discover descriptors if the device disconnected. | 332 // Don't discover descriptors if the device disconnected. |
| 326 return; | 333 return; |
| 327 } | 334 } |
| 335 if (IsGattServicesDiscoveryComplete()) { | |
| 336 // This should never happens, just in case it happens with a device, | |
|
scheib
2017/04/18 04:43:21
ditto
jlebel
2017/04/29 22:08:07
Done.
| |
| 337 // this notification should be ignored. | |
| 338 VLOG(1) << *this | |
| 339 << ": Discovery complete, ignoring DidDiscoverDescriptors."; | |
| 340 return; | |
| 341 } | |
| 328 BluetoothRemoteGattServiceMac* gatt_service = | 342 BluetoothRemoteGattServiceMac* gatt_service = |
| 329 GetBluetoothRemoteGattService(cb_characteristic.service); | 343 GetBluetoothRemoteGattService(cb_characteristic.service); |
| 330 DCHECK(gatt_service); | 344 DCHECK(gatt_service); |
| 331 gatt_service->DidDiscoverDescriptors(cb_characteristic); | 345 gatt_service->DidDiscoverDescriptors(cb_characteristic); |
| 332 SendNotificationIfDiscoveryComplete(); | 346 SendNotificationIfDiscoveryComplete(); |
| 333 } | 347 } |
| 334 | 348 |
| 335 // static | 349 // static |
| 336 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( | 350 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( |
| 337 CBPeripheral* peripheral) { | 351 CBPeripheral* peripheral) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 353 } | 367 } |
| 354 | 368 |
| 355 void BluetoothLowEnergyDeviceMac::DiscoverPrimaryServices() { | 369 void BluetoothLowEnergyDeviceMac::DiscoverPrimaryServices() { |
| 356 VLOG(1) << *this << ": DiscoverPrimaryServices, pending count " | 370 VLOG(1) << *this << ": DiscoverPrimaryServices, pending count " |
| 357 << discovery_pending_count_; | 371 << discovery_pending_count_; |
| 358 ++discovery_pending_count_; | 372 ++discovery_pending_count_; |
| 359 [GetPeripheral() discoverServices:nil]; | 373 [GetPeripheral() discoverServices:nil]; |
| 360 } | 374 } |
| 361 | 375 |
| 362 void BluetoothLowEnergyDeviceMac::SendNotificationIfDiscoveryComplete() { | 376 void BluetoothLowEnergyDeviceMac::SendNotificationIfDiscoveryComplete() { |
| 377 DCHECK(!IsGattServicesDiscoveryComplete()); | |
| 363 // Notify when all services have been discovered. | 378 // Notify when all services have been discovered. |
| 364 bool discovery_complete = | 379 bool discovery_complete = |
| 365 discovery_pending_count_ == 0 && | 380 discovery_pending_count_ == 0 && |
| 366 std::find_if_not( | 381 std::find_if_not( |
| 367 gatt_services_.begin(), | 382 gatt_services_.begin(), |
| 368 gatt_services_.end(), [](GattServiceMap::value_type & pair) { | 383 gatt_services_.end(), [](GattServiceMap::value_type & pair) { |
| 369 BluetoothRemoteGattService* gatt_service = pair.second.get(); | 384 BluetoothRemoteGattService* gatt_service = pair.second.get(); |
| 370 return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service) | 385 return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service) |
| 371 ->IsDiscoveryComplete(); | 386 ->IsDiscoveryComplete(); |
| 372 }) == gatt_services_.end(); | 387 }) == gatt_services_.end(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 std::ostream& operator<<(std::ostream& out, | 447 std::ostream& operator<<(std::ostream& out, |
| 433 const BluetoothLowEnergyDeviceMac& device) { | 448 const BluetoothLowEnergyDeviceMac& device) { |
| 434 // TODO(crbug.com/703878): Should use | 449 // TODO(crbug.com/703878): Should use |
| 435 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. | 450 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. |
| 436 base::Optional<std::string> name = device.GetName(); | 451 base::Optional<std::string> name = device.GetName(); |
| 437 const char* name_cstr = name ? name->c_str() : ""; | 452 const char* name_cstr = name ? name->c_str() : ""; |
| 438 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" | 453 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" |
| 439 << &device << ", \"" << name_cstr << "\">"; | 454 << &device << ", \"" << name_cstr << "\">"; |
| 440 } | 455 } |
| 441 } // namespace device | 456 } // namespace device |
| OLD | NEW |