| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 device_uuids_.ClearServiceUUIDs(); | 314 device_uuids_.ClearServiceUUIDs(); |
| 315 SetGattServicesDiscoveryComplete(false); | 315 SetGattServicesDiscoveryComplete(false); |
| 316 adapter_->NotifyDeviceChanged(this); | 316 adapter_->NotifyDeviceChanged(this); |
| 317 DiscoverPrimaryServices(); | 317 DiscoverPrimaryServices(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void BluetoothLowEnergyDeviceMac::DidUpdateValue( | 320 void BluetoothLowEnergyDeviceMac::DidUpdateValue( |
| 321 CBCharacteristic* characteristic, | 321 CBCharacteristic* characteristic, |
| 322 NSError* error) { | 322 NSError* error) { |
| 323 BluetoothRemoteGattServiceMac* gatt_service = | 323 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac = |
| 324 GetBluetoothRemoteGattServiceMac(characteristic.service); | 324 GetBluetoothRemoteGattCharacteristicMac(characteristic); |
| 325 DCHECK(gatt_service); | 325 DCHECK(gatt_characteristic_mac); |
| 326 gatt_service->DidUpdateValue(characteristic, error); | 326 gatt_characteristic_mac->DidUpdateValue(error); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void BluetoothLowEnergyDeviceMac::DidWriteValue( | 329 void BluetoothLowEnergyDeviceMac::DidWriteValue( |
| 330 CBCharacteristic* characteristic, | 330 CBCharacteristic* characteristic, |
| 331 NSError* error) { | 331 NSError* error) { |
| 332 BluetoothRemoteGattServiceMac* gatt_service = | 332 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac = |
| 333 GetBluetoothRemoteGattServiceMac(characteristic.service); | 333 GetBluetoothRemoteGattCharacteristicMac(characteristic); |
| 334 DCHECK(gatt_service); | 334 DCHECK(gatt_characteristic_mac); |
| 335 gatt_service->DidWriteValue(characteristic, error); | 335 gatt_characteristic_mac->DidWriteValue(error); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState( | 338 void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState( |
| 339 CBCharacteristic* characteristic, | 339 CBCharacteristic* characteristic, |
| 340 NSError* error) { | 340 NSError* error) { |
| 341 BluetoothRemoteGattServiceMac* gatt_service = | 341 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac = |
| 342 GetBluetoothRemoteGattServiceMac(characteristic.service); | 342 GetBluetoothRemoteGattCharacteristicMac(characteristic); |
| 343 DCHECK(gatt_service); | 343 DCHECK(gatt_characteristic_mac); |
| 344 gatt_service->DidUpdateNotificationState(characteristic, error); | 344 gatt_characteristic_mac->DidUpdateNotificationState(error); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors( | 347 void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors( |
| 348 CBCharacteristic* cb_characteristic, | 348 CBCharacteristic* cb_characteristic, |
| 349 NSError* error) { | 349 NSError* error) { |
| 350 if (error) { | 350 if (error) { |
| 351 // TODO(http://crbug.com/609320): Need to pass the error. | 351 // TODO(http://crbug.com/609320): Need to pass the error. |
| 352 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 352 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
| 353 VLOG(1) << *this << ": Can't discover descriptors: " | 353 VLOG(1) << *this << ": Can't discover descriptors: " |
| 354 << BluetoothAdapterMac::String(error); | 354 << BluetoothAdapterMac::String(error); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 for (auto it = gatt_services_.begin(); it != gatt_services_.end(); ++it) { | 467 for (auto it = gatt_services_.begin(); it != gatt_services_.end(); ++it) { |
| 468 BluetoothRemoteGattService* gatt_service = it->second.get(); | 468 BluetoothRemoteGattService* gatt_service = it->second.get(); |
| 469 BluetoothRemoteGattServiceMac* gatt_service_mac = | 469 BluetoothRemoteGattServiceMac* gatt_service_mac = |
| 470 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); | 470 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); |
| 471 if (gatt_service_mac->GetService() == cb_service) | 471 if (gatt_service_mac->GetService() == cb_service) |
| 472 return gatt_service_mac; | 472 return gatt_service_mac; |
| 473 } | 473 } |
| 474 return nullptr; | 474 return nullptr; |
| 475 } | 475 } |
| 476 | 476 |
| 477 BluetoothRemoteGattCharacteristicMac* |
| 478 BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattCharacteristicMac( |
| 479 CBCharacteristic* cb_characteristic) const { |
| 480 CBService* cb_service = [cb_characteristic service]; |
| 481 BluetoothRemoteGattServiceMac* gatt_service_mac = |
| 482 GetBluetoothRemoteGattServiceMac(cb_service); |
| 483 if (!gatt_service_mac) { |
| 484 return nullptr; |
| 485 } |
| 486 return gatt_service_mac->GetBluetoothRemoteGattCharacteristicMac( |
| 487 cb_characteristic); |
| 488 } |
| 489 |
| 477 BluetoothRemoteGattDescriptorMac* | 490 BluetoothRemoteGattDescriptorMac* |
| 478 BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattDescriptorMac( | 491 BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattDescriptorMac( |
| 479 CBDescriptor* cb_descriptor) const { | 492 CBDescriptor* cb_descriptor) const { |
| 480 CBCharacteristic* cb_characteristic = cb_descriptor.characteristic; | 493 CBCharacteristic* cb_characteristic = cb_descriptor.characteristic; |
| 481 BluetoothRemoteGattServiceMac* gatt_service = | 494 BluetoothRemoteGattServiceMac* gatt_service = |
| 482 GetBluetoothRemoteGattServiceMac(cb_characteristic.service); | 495 GetBluetoothRemoteGattServiceMac(cb_characteristic.service); |
| 483 DCHECK(gatt_service); | 496 DCHECK(gatt_service); |
| 484 BluetoothRemoteGattCharacteristicMac* gatt_characteristic = | 497 BluetoothRemoteGattCharacteristicMac* gatt_characteristic = |
| 485 gatt_service->GetBluetoothRemoteGattCharacteristicMac(cb_characteristic); | 498 gatt_service->GetBluetoothRemoteGattCharacteristicMac(cb_characteristic); |
| 486 DCHECK(gatt_characteristic); | 499 DCHECK(gatt_characteristic); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. | 535 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. |
| 523 base::Optional<std::string> name = device.GetName(); | 536 base::Optional<std::string> name = device.GetName(); |
| 524 const char* is_gatt_connected = | 537 const char* is_gatt_connected = |
| 525 device.IsGattConnected() ? "GATT connected" : "GATT disconnected"; | 538 device.IsGattConnected() ? "GATT connected" : "GATT disconnected"; |
| 526 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" | 539 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" |
| 527 << &device << ", " << is_gatt_connected << ", \"" | 540 << &device << ", " << is_gatt_connected << ", \"" |
| 528 << name.value_or("Unnamed device") << "\">"; | 541 << name.value_or("Unnamed device") << "\">"; |
| 529 } | 542 } |
| 530 | 543 |
| 531 } // namespace device | 544 } // namespace device |
| OLD | NEW |