| 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 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(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 BluetoothLowEnergyDeviceInfo* device_info = |
| 75 new BluetoothLowEnergyDeviceInfo(); | 75 new BluetoothLowEnergyDeviceInfo(); |
| 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(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()); |
| (...skipping 536 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 |