Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_low_energy_win_fake.h" | 5 #include "device/bluetooth/bluetooth_low_energy_win_fake.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 BluetoothLowEnergyWrapperFake::BluetoothLowEnergyWrapperFake() | 36 BluetoothLowEnergyWrapperFake::BluetoothLowEnergyWrapperFake() |
| 37 : observer_(nullptr) {} | 37 : observer_(nullptr) {} |
| 38 BluetoothLowEnergyWrapperFake::~BluetoothLowEnergyWrapperFake() {} | 38 BluetoothLowEnergyWrapperFake::~BluetoothLowEnergyWrapperFake() {} |
| 39 | 39 |
| 40 bool BluetoothLowEnergyWrapperFake::IsBluetoothLowEnergySupported() { | 40 bool BluetoothLowEnergyWrapperFake::IsBluetoothLowEnergySupported() { |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyDevices( | 44 bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyDevices( |
| 45 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 45 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices, |
| 46 std::string* error) { | 46 std::string* error) { |
| 47 if (!IsBluetoothLowEnergySupported()) { | 47 if (!IsBluetoothLowEnergySupported()) { |
| 48 *error = kPlatformNotSupported; | 48 *error = kPlatformNotSupported; |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 | 51 |
| 52 for (auto& device : simulated_devices_) { | 52 for (auto& device : simulated_devices_) { |
| 53 if (device.second->marked_as_deleted) | 53 if (device.second->marked_as_deleted) |
| 54 continue; | 54 continue; |
| 55 BluetoothLowEnergyDeviceInfo* device_info = | 55 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info( |
| 56 new BluetoothLowEnergyDeviceInfo(); | 56 new BluetoothLowEnergyDeviceInfo()); |
| 57 *device_info = *(device.second->device_info); | 57 *device_info = *(device.second->device_info); |
| 58 devices->push_back(device_info); | 58 devices->push_back(std::move(device_info)); |
| 59 } | 59 } |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool BluetoothLowEnergyWrapperFake:: | 63 bool BluetoothLowEnergyWrapperFake:: |
| 64 EnumerateKnownBluetoothLowEnergyGattServiceDevices( | 64 EnumerateKnownBluetoothLowEnergyGattServiceDevices( |
| 65 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 65 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices, |
| 66 std::string* error) { | 66 std::string* error) { |
| 67 if (!IsBluetoothLowEnergySupported()) { | 67 if (!IsBluetoothLowEnergySupported()) { |
| 68 *error = kPlatformNotSupported; | 68 *error = kPlatformNotSupported; |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 | 71 |
| 72 for (auto& device : simulated_devices_) { | 72 for (auto& device : simulated_devices_) { |
| 73 for (auto& service : device.second->primary_services) { | 73 for (auto& service : device.second->primary_services) { |
| 74 BluetoothLowEnergyDeviceInfo* device_info = | 74 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info( |
| 75 new BluetoothLowEnergyDeviceInfo(); | 75 new BluetoothLowEnergyDeviceInfo()); |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:14
Use base::MakeUnique.
dougt
2016/12/22 01:18:03
Done.
| |
| 76 *device_info = *(device.second->device_info); | 76 *device_info = *(device.second->device_info); |
| 77 base::string16 path = GenerateGattServiceDevicePath( | 77 base::string16 path = GenerateGattServiceDevicePath( |
| 78 device.second->device_info->path.value(), | 78 device.second->device_info->path.value(), |
| 79 service.second->service_info->AttributeHandle); | 79 service.second->service_info->AttributeHandle); |
| 80 device_info->path = base::FilePath(path); | 80 device_info->path = base::FilePath(path); |
| 81 devices->push_back(device_info); | 81 devices->push_back(std::move(device_info)); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyServices( | 87 bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyServices( |
| 88 const base::FilePath& device_path, | 88 const base::FilePath& device_path, |
| 89 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 89 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services, |
| 90 std::string* error) { | 90 std::string* error) { |
| 91 if (!IsBluetoothLowEnergySupported()) { | 91 if (!IsBluetoothLowEnergySupported()) { |
| 92 *error = kPlatformNotSupported; | 92 *error = kPlatformNotSupported; |
| 93 return false; | 93 return false; |
| 94 } | 94 } |
| 95 | 95 |
| 96 base::string16 device_address = | 96 base::string16 device_address = |
| 97 ExtractDeviceAddressFromDevicePath(device_path.value()); | 97 ExtractDeviceAddressFromDevicePath(device_path.value()); |
| 98 std::vector<std::string> service_attribute_handles = | 98 std::vector<std::string> service_attribute_handles = |
| 99 ExtractServiceAttributeHandlesFromDevicePath(device_path.value()); | 99 ExtractServiceAttributeHandlesFromDevicePath(device_path.value()); |
| 100 | 100 |
| 101 BLEDevicesMap::iterator it_d = simulated_devices_.find( | 101 BLEDevicesMap::iterator it_d = simulated_devices_.find( |
| 102 std::string(device_address.begin(), device_address.end())); | 102 std::string(device_address.begin(), device_address.end())); |
| 103 CHECK(it_d != simulated_devices_.end()); | 103 CHECK(it_d != simulated_devices_.end()); |
| 104 | 104 |
| 105 // |service_attribute_handles| is empty means |device_path| is a BLE device | 105 // |service_attribute_handles| is empty means |device_path| is a BLE device |
| 106 // path, otherwise it is a BLE GATT service device path. | 106 // path, otherwise it is a BLE GATT service device path. |
| 107 if (service_attribute_handles.empty()) { | 107 if (service_attribute_handles.empty()) { |
| 108 // Return all primary services for BLE device. | 108 // Return all primary services for BLE device. |
| 109 for (auto& primary_service : it_d->second->primary_services) { | 109 for (auto& primary_service : it_d->second->primary_services) { |
| 110 BluetoothLowEnergyServiceInfo* service_info = | 110 std::unique_ptr<BluetoothLowEnergyServiceInfo> service_info( |
| 111 new BluetoothLowEnergyServiceInfo(); | 111 new BluetoothLowEnergyServiceInfo()); |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:14
Use base::MakeUnique.
dougt
2016/12/22 01:18:03
Done.
| |
| 112 service_info->uuid = primary_service.second->service_info->ServiceUuid; | 112 service_info->uuid = primary_service.second->service_info->ServiceUuid; |
| 113 service_info->attribute_handle = | 113 service_info->attribute_handle = |
| 114 primary_service.second->service_info->AttributeHandle; | 114 primary_service.second->service_info->AttributeHandle; |
| 115 services->push_back(service_info); | 115 services->push_back(std::move(service_info)); |
| 116 } | 116 } |
| 117 } else { | 117 } else { |
| 118 // Return corresponding GATT service for BLE GATT service device. | 118 // Return corresponding GATT service for BLE GATT service device. |
| 119 GattService* target_service = | 119 GattService* target_service = |
| 120 GetSimulatedGattService(it_d->second.get(), service_attribute_handles); | 120 GetSimulatedGattService(it_d->second.get(), service_attribute_handles); |
| 121 BluetoothLowEnergyServiceInfo* service_info = | 121 std::unique_ptr<BluetoothLowEnergyServiceInfo> service_info( |
| 122 new BluetoothLowEnergyServiceInfo(); | 122 new BluetoothLowEnergyServiceInfo()); |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:14
Use base::MakeUnique.
dougt
2016/12/22 01:18:03
Done.
| |
| 123 service_info->uuid = target_service->service_info->ServiceUuid; | 123 service_info->uuid = target_service->service_info->ServiceUuid; |
| 124 service_info->attribute_handle = | 124 service_info->attribute_handle = |
| 125 target_service->service_info->AttributeHandle; | 125 target_service->service_info->AttributeHandle; |
| 126 services->push_back(service_info); | 126 services->push_back(std::move(service_info)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 HRESULT BluetoothLowEnergyWrapperFake::ReadCharacteristicsOfAService( | 132 HRESULT BluetoothLowEnergyWrapperFake::ReadCharacteristicsOfAService( |
| 133 base::FilePath& service_path, | 133 base::FilePath& service_path, |
| 134 const PBTH_LE_GATT_SERVICE service, | 134 const PBTH_LE_GATT_SERVICE service, |
| 135 std::unique_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, | 135 std::unique_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, |
| 136 USHORT* out_counts) { | 136 USHORT* out_counts) { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( | 636 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( |
| 637 const BLUETOOTH_ADDRESS& btha) { | 637 const BLUETOOTH_ADDRESS& btha) { |
| 638 std::string result = base::StringPrintf( | 638 std::string result = base::StringPrintf( |
| 639 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], | 639 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], |
| 640 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); | 640 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); |
| 641 return result; | 641 return result; |
| 642 } | 642 } |
| 643 | 643 |
| 644 } // namespace win | 644 } // namespace win |
| 645 } // namespace device | 645 } // namespace device |
| OLD | NEW |