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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 // Only notify observers once per device. | 395 // Only notify observers once per device. |
396 if (devices_.count(device_address)) | 396 if (devices_.count(device_address)) |
397 return; | 397 return; |
398 | 398 |
399 devices_[device_address] = new BluetoothClassicDeviceMac(device); | 399 devices_[device_address] = new BluetoothClassicDeviceMac(device); |
400 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 400 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
401 observers_, | 401 observers_, |
402 DeviceAdded(this, devices_[device_address])); | 402 DeviceAdded(this, devices_[device_address])); |
403 } | 403 } |
404 | 404 |
405 // TODO(krstnmnlsn): Implement method. http://crbug.com/496987. | |
406 void BluetoothAdapterMac::LowEnergyDeviceUpdated( | 405 void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
407 CBPeripheral* peripheral, | 406 CBPeripheral* peripheral, |
408 NSDictionary* advertisementData, | 407 NSDictionary* advertisementData, |
409 int rssi) { | 408 int rssi) { |
409 std::string device_address = | |
410 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | |
411 BluetoothDevice*& device_reference = devices_[device_address]; | |
412 | |
413 if (!device_reference) { | |
414 // A new device has been found. | |
415 device_reference = | |
416 new BluetoothLowEnergyDeviceMac(peripheral, advertisementData, rssi); | |
417 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | |
scheib
2015/07/13 18:24:39
Only one of DeviceAdded or DeviceChanged should be
krstnmnlsn
2015/07/13 20:40:43
Right, thanks. This is what I get for cutting and
| |
418 DeviceAdded(this, device_reference)); | |
419 | |
420 } else { | |
421 if (static_cast<BluetoothLowEnergyDeviceMac*>(device_reference) | |
422 ->GetIdentifier() != | |
423 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) { | |
424 // Collision, two identifiers map to the same hash address. With a 48 bit | |
425 // hash the probability of this occuring with 10,000 devices | |
426 // simultaneously present is 1e-6 (see | |
427 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We | |
428 // ignore the second device by returning. | |
429 return; | |
430 } | |
431 // A device has an update. | |
432 static_cast<BluetoothLowEnergyDeviceMac*>(device_reference) | |
433 ->Update(peripheral, advertisementData, rssi); | |
434 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | |
435 DeviceChanged(this, device_reference)); | |
436 return; | |
437 } | |
410 } | 438 } |
411 | 439 |
412 void BluetoothAdapterMac::RemoveTimedOutDevices() { | 440 void BluetoothAdapterMac::RemoveTimedOutDevices() { |
413 // Notify observers if any previously seen devices are no longer available, | 441 // Notify observers if any previously seen devices are no longer available, |
414 // i.e. if they are no longer paired, connected, nor recently discovered via | 442 // i.e. if they are no longer paired, connected, nor recently discovered via |
415 // an inquiry. | 443 // an inquiry. |
416 std::set<std::string> removed_devices; | 444 std::set<std::string> removed_devices; |
417 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { | 445 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { |
418 BluetoothDevice* device = it->second; | 446 BluetoothDevice* device = it->second; |
419 if (device->IsPaired() || device->IsConnected()) | 447 if (device->IsPaired() || device->IsConnected()) |
(...skipping 18 matching lines...) Expand all Loading... | |
438 } | 466 } |
439 | 467 |
440 void BluetoothAdapterMac::AddPairedDevices() { | 468 void BluetoothAdapterMac::AddPairedDevices() { |
441 // Add any new paired devices. | 469 // Add any new paired devices. |
442 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 470 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
443 ClassicDeviceAdded(device); | 471 ClassicDeviceAdded(device); |
444 } | 472 } |
445 } | 473 } |
446 | 474 |
447 } // namespace device | 475 } // namespace device |
OLD | NEW |