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 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 NSDictionary* service_data = | 532 NSDictionary* service_data = |
533 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; | 533 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
534 for (CBUUID* uuid in service_data) { | 534 for (CBUUID* uuid in service_data) { |
535 NSData* data = [service_data objectForKey:uuid]; | 535 NSData* data = [service_data objectForKey:uuid]; |
536 const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]); | 536 const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]); |
537 size_t length = [data length]; | 537 size_t length = [data length]; |
538 service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]), | 538 service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]), |
539 std::vector<uint8_t>(bytes, bytes + length)); | 539 std::vector<uint8_t>(bytes, bytes + length)); |
540 } | 540 } |
541 | 541 |
542 device_mac->UpdateAdvertisementData(std::move(advertised_uuids), | 542 // Get Tx Power. |
543 std::move(service_data_map)); | 543 base::Optional<int8_t> clamped_tx_power; |
544 NSNumber* tx_power = | |
545 [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey]; | |
546 clamped_tx_power = | |
547 tx_power == nil ? base::nullopt | |
Jeffrey Yasskin
2016/08/24 04:32:02
Either make this the initialization of the variabl
ortuno
2016/08/24 21:29:09
Done. hmm I wonder why I declared the variable up
| |
548 : base::make_optional<int8_t>( | |
549 BluetoothDevice::ClampPower([tx_power intValue])); | |
550 | |
551 device_mac->UpdateAdvertisementData( | |
552 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids), | |
553 std::move(service_data_map), | |
554 clamped_tx_power ? &clamped_tx_power.value() : nullptr); | |
544 | 555 |
545 if (is_new_device) { | 556 if (is_new_device) { |
546 std::string device_address = | 557 std::string device_address = |
547 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 558 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
548 devices_.add(device_address, std::unique_ptr<BluetoothDevice>(device_mac)); | 559 devices_.add(device_address, std::unique_ptr<BluetoothDevice>(device_mac)); |
549 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 560 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
550 DeviceAdded(this, device_mac)); | 561 DeviceAdded(this, device_mac)); |
551 } else { | 562 } else { |
552 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 563 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
553 DeviceChanged(this, device_mac)); | 564 DeviceChanged(this, device_mac)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 std::string device_address = | 636 std::string device_address = |
626 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 637 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
627 DevicesMap::const_iterator iter = devices_.find(device_address); | 638 DevicesMap::const_iterator iter = devices_.find(device_address); |
628 if (iter == devices_.end()) { | 639 if (iter == devices_.end()) { |
629 return nil; | 640 return nil; |
630 } | 641 } |
631 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); | 642 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); |
632 } | 643 } |
633 | 644 |
634 } // namespace device | 645 } // namespace device |
OLD | NEW |