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

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: now with readable logic 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* 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];
armansito 2015/07/15 18:14:42 Please add a comment here explaining why you're us
krstnmnlsn 2015/07/15 20:38:14 Done.
412
armansito 2015/07/15 18:14:42 Remove extra space here.
krstnmnlsn 2015/07/15 20:38:14 Done.
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_,
418 DeviceAdded(this, device_reference));
419 return;
420 }
421
422 if (static_cast<BluetoothLowEnergyDeviceMac*>(device_reference)
423 ->GetIdentifier() !=
424 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) {
425 // Collision, two identifiers map to the same hash address. With a 48 bit
426 // hash the probability of this occuring with 10,000 devices
427 // simultaneously present is 1e-6 (see
428 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We
429 // ignore the second device by returning.
430 return;
431 }
432
433 // A device has an update.
434 static_cast<BluetoothLowEnergyDeviceMac*>(device_reference)
435 ->Update(peripheral, advertisementData, rssi);
436 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
437 DeviceChanged(this, device_reference));
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
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
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