OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_adapter_mac.h" | 5 #include "device/bluetooth/bluetooth_adapter_mac.h" |
6 | 6 |
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> | 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> | 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 438 } |
439 | 439 |
440 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { | 440 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { |
441 std::string device_address = | 441 std::string device_address = |
442 BluetoothClassicDeviceMac::GetDeviceAddress(device); | 442 BluetoothClassicDeviceMac::GetDeviceAddress(device); |
443 | 443 |
444 // Only notify observers once per device. | 444 // Only notify observers once per device. |
445 if (devices_.count(device_address)) | 445 if (devices_.count(device_address)) |
446 return; | 446 return; |
447 | 447 |
448 devices_[device_address] = new BluetoothClassicDeviceMac(device); | 448 devices_[device_address] = new BluetoothClassicDeviceMac(this, device); |
449 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 449 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
450 observers_, | 450 observers_, |
451 DeviceAdded(this, devices_[device_address])); | 451 DeviceAdded(this, devices_[device_address])); |
452 } | 452 } |
453 | 453 |
454 void BluetoothAdapterMac::LowEnergyDeviceUpdated( | 454 void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
455 CBPeripheral* peripheral, | 455 CBPeripheral* peripheral, |
456 NSDictionary* advertisement_data, | 456 NSDictionary* advertisement_data, |
457 int rssi) { | 457 int rssi) { |
458 std::string device_address = | 458 std::string device_address = |
459 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 459 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
460 // Get a reference to the actual device pointer held by |devices_| (if | 460 // Get a reference to the actual device pointer held by |devices_| (if |
461 // |device_address| has no entry in the map a NULL pointer is created by the | 461 // |device_address| has no entry in the map a NULL pointer is created by the |
462 // std::map [] operator). | 462 // std::map [] operator). |
463 BluetoothDevice*& device_reference = devices_[device_address]; | 463 BluetoothDevice*& device_reference = devices_[device_address]; |
464 if (!device_reference) { | 464 if (!device_reference) { |
465 VLOG(1) << "LowEnergyDeviceUpdated new device"; | 465 VLOG(1) << "LowEnergyDeviceUpdated new device"; |
466 // A new device has been found. | 466 // A new device has been found. |
467 device_reference = | 467 device_reference = new BluetoothLowEnergyDeviceMac( |
468 new BluetoothLowEnergyDeviceMac(peripheral, advertisement_data, rssi); | 468 this, peripheral, advertisement_data, rssi); |
469 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 469 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
470 DeviceAdded(this, device_reference)); | 470 DeviceAdded(this, device_reference)); |
471 return; | 471 return; |
472 } | 472 } |
473 | 473 |
474 std::string stored_device_id = device_reference->GetIdentifier(); | 474 std::string stored_device_id = device_reference->GetIdentifier(); |
475 std::string updated_device_id = | 475 std::string updated_device_id = |
476 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral); | 476 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral); |
477 if (stored_device_id != updated_device_id) { | 477 if (stored_device_id != updated_device_id) { |
478 VLOG(1) << "LowEnergyDeviceUpdated stored_device_id != updated_device_id: " | 478 VLOG(1) << "LowEnergyDeviceUpdated stored_device_id != updated_device_id: " |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 527 } |
528 | 528 |
529 void BluetoothAdapterMac::AddPairedDevices() { | 529 void BluetoothAdapterMac::AddPairedDevices() { |
530 // Add any new paired devices. | 530 // Add any new paired devices. |
531 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 531 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
532 ClassicDeviceAdded(device); | 532 ClassicDeviceAdded(device); |
533 } | 533 } |
534 } | 534 } |
535 | 535 |
536 } // namespace device | 536 } // namespace device |
OLD | NEW |