| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 434 } |
| 435 | 435 |
| 436 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { | 436 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { |
| 437 std::string device_address = | 437 std::string device_address = |
| 438 BluetoothClassicDeviceMac::GetDeviceAddress(device); | 438 BluetoothClassicDeviceMac::GetDeviceAddress(device); |
| 439 | 439 |
| 440 // Only notify observers once per device. | 440 // Only notify observers once per device. |
| 441 if (devices_.count(device_address)) | 441 if (devices_.count(device_address)) |
| 442 return; | 442 return; |
| 443 | 443 |
| 444 devices_[device_address] = new BluetoothClassicDeviceMac(device); | 444 devices_[device_address] = new BluetoothClassicDeviceMac(this, device); |
| 445 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 445 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| 446 observers_, | 446 observers_, |
| 447 DeviceAdded(this, devices_[device_address])); | 447 DeviceAdded(this, devices_[device_address])); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void BluetoothAdapterMac::LowEnergyDeviceUpdated( | 450 void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
| 451 CBPeripheral* peripheral, | 451 CBPeripheral* peripheral, |
| 452 NSDictionary* advertisement_data, | 452 NSDictionary* advertisement_data, |
| 453 int rssi) { | 453 int rssi) { |
| 454 std::string device_address = | 454 std::string device_address = |
| 455 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 455 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
| 456 // Get a reference to the actual device pointer held by |devices_| (if | 456 // Get a reference to the actual device pointer held by |devices_| (if |
| 457 // |device_address| has no entry in the map a NULL pointer is created by the | 457 // |device_address| has no entry in the map a NULL pointer is created by the |
| 458 // std::map [] operator). | 458 // std::map [] operator). |
| 459 BluetoothDevice*& device_reference = devices_[device_address]; | 459 BluetoothDevice*& device_reference = devices_[device_address]; |
| 460 if (!device_reference) { | 460 if (!device_reference) { |
| 461 // A new device has been found. | 461 // A new device has been found. |
| 462 device_reference = | 462 device_reference = new BluetoothLowEnergyDeviceMac( |
| 463 new BluetoothLowEnergyDeviceMac(peripheral, advertisement_data, rssi); | 463 this, peripheral, advertisement_data, rssi); |
| 464 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 464 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 465 DeviceAdded(this, device_reference)); | 465 DeviceAdded(this, device_reference)); |
| 466 return; | 466 return; |
| 467 } | 467 } |
| 468 | 468 |
| 469 if (static_cast<BluetoothLowEnergyDeviceMac*>(device_reference) | 469 if (static_cast<BluetoothLowEnergyDeviceMac*>(device_reference) |
| 470 ->GetIdentifier() != | 470 ->GetIdentifier() != |
| 471 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) { | 471 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) { |
| 472 // Collision, two identifiers map to the same hash address. With a 48 bit | 472 // Collision, two identifiers map to the same hash address. With a 48 bit |
| 473 // hash the probability of this occuring with 10,000 devices | 473 // hash the probability of this occuring with 10,000 devices |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 516 } |
| 517 | 517 |
| 518 void BluetoothAdapterMac::AddPairedDevices() { | 518 void BluetoothAdapterMac::AddPairedDevices() { |
| 519 // Add any new paired devices. | 519 // Add any new paired devices. |
| 520 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 520 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
| 521 ClassicDeviceAdded(device); | 521 ClassicDeviceAdded(device); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 } // namespace device | 525 } // namespace device |
| OLD | NEW |