Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 1229473005: BluetoothAdapterMac::LowEnergyDeviceUpdated() Implemented (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hash
Patch Set: s/advertisementData/advertisement_data Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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* advertisement_data, 407 NSDictionary* advertisement_data,
409 int rssi) {} 408 int rssi) {
409 std::string device_address =
410 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
411 // Get a reference to the actual device pointer held by |devices_| (if
412 // |device_address| has no entry in the map a NULL pointer is created by the
413 // std::map [] operator).
414 BluetoothDevice*& device_reference = devices_[device_address];
415 if (!device_reference) {
416 // A new device has been found.
417 device_reference =
418 new BluetoothLowEnergyDeviceMac(peripheral, advertisement_data, rssi);
419 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
420 DeviceAdded(this, device_reference));
421 return;
422 }
423
424 if (static_cast<BluetoothLowEnergyDeviceMac*>(device_reference)
425 ->GetIdentifier() !=
426 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) {
427 // Collision, two identifiers map to the same hash address. With a 48 bit
428 // hash the probability of this occuring with 10,000 devices
429 // simultaneously present is 1e-6 (see
430 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We
431 // ignore the second device by returning.
432 return;
433 }
434
435 // A device has an update.
436 static_cast<BluetoothLowEnergyDeviceMac*>(device_reference)
437 ->Update(peripheral, advertisement_data, rssi);
438 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
439 DeviceChanged(this, device_reference));
440 }
410 441
411 void BluetoothAdapterMac::RemoveTimedOutDevices() { 442 void BluetoothAdapterMac::RemoveTimedOutDevices() {
412 // Notify observers if any previously seen devices are no longer available, 443 // Notify observers if any previously seen devices are no longer available,
413 // i.e. if they are no longer paired, connected, nor recently discovered via 444 // i.e. if they are no longer paired, connected, nor recently discovered via
414 // an inquiry. 445 // an inquiry.
415 std::set<std::string> removed_devices; 446 std::set<std::string> removed_devices;
416 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { 447 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) {
417 BluetoothDevice* device = it->second; 448 BluetoothDevice* device = it->second;
418 if (device->IsPaired() || device->IsConnected()) 449 if (device->IsPaired() || device->IsConnected())
419 continue; 450 continue;
(...skipping 17 matching lines...) Expand all
437 } 468 }
438 469
439 void BluetoothAdapterMac::AddPairedDevices() { 470 void BluetoothAdapterMac::AddPairedDevices() {
440 // Add any new paired devices. 471 // Add any new paired devices.
441 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 472 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
442 ClassicDeviceAdded(device); 473 ClassicDeviceAdded(device);
443 } 474 }
444 } 475 }
445 476
446 } // namespace device 477 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698