| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 const char kPlatformNotSupported[] = | 10 const char kPlatformNotSupported[] = |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 BluetoothAddressToCanonicalString(device->device_info->address); | 145 BluetoothAddressToCanonicalString(device->device_info->address); |
| 146 service_info->AttributeHandle = | 146 service_info->AttributeHandle = |
| 147 GenerateAUniqueAttributeHandle(string_device_address); | 147 GenerateAUniqueAttributeHandle(string_device_address); |
| 148 service_info->ServiceUuid = CanonicalStringToBTH_LE_UUID(uuid); | 148 service_info->ServiceUuid = CanonicalStringToBTH_LE_UUID(uuid); |
| 149 service->service_info.reset(service_info); | 149 service->service_info.reset(service_info); |
| 150 device->primary_services[std::to_string(service_info->AttributeHandle)] = | 150 device->primary_services[std::to_string(service_info->AttributeHandle)] = |
| 151 make_scoped_ptr(service); | 151 make_scoped_ptr(service); |
| 152 return service; | 152 return service; |
| 153 } | 153 } |
| 154 | 154 |
| 155 BLEDevice* BluetoothLowEnergyWrapperFake::GetSimulatedBLEDevice( |
| 156 std::string device_address) { |
| 157 BLEDevicesMap::iterator it_d = simulated_devices_.find(device_address); |
| 158 if (it_d == simulated_devices_.end()) |
| 159 return nullptr; |
| 160 return it_d->second.get(); |
| 161 } |
| 162 |
| 155 USHORT BluetoothLowEnergyWrapperFake::GenerateAUniqueAttributeHandle( | 163 USHORT BluetoothLowEnergyWrapperFake::GenerateAUniqueAttributeHandle( |
| 156 std::string device_address) { | 164 std::string device_address) { |
| 157 scoped_ptr<std::set<USHORT>>& set_of_ushort = | 165 scoped_ptr<std::set<USHORT>>& set_of_ushort = |
| 158 attribute_handle_table_[device_address]; | 166 attribute_handle_table_[device_address]; |
| 159 if (set_of_ushort) { | 167 if (set_of_ushort) { |
| 160 USHORT max_attribute_handle = *set_of_ushort->rbegin(); | 168 USHORT max_attribute_handle = *set_of_ushort->rbegin(); |
| 161 if (max_attribute_handle < 0xFFFF) { | 169 if (max_attribute_handle < 0xFFFF) { |
| 162 USHORT new_attribute_handle = max_attribute_handle + 1; | 170 USHORT new_attribute_handle = max_attribute_handle + 1; |
| 163 set_of_ushort->insert(new_attribute_handle); | 171 set_of_ushort->insert(new_attribute_handle); |
| 164 return new_attribute_handle; | 172 return new_attribute_handle; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 193 std::string sub_path = std::to_string(service_attribute_handle); | 201 std::string sub_path = std::to_string(service_attribute_handle); |
| 194 return resident_device_path + L"/" + | 202 return resident_device_path + L"/" + |
| 195 base::string16(sub_path.begin(), sub_path.end()); | 203 base::string16(sub_path.begin(), sub_path.end()); |
| 196 } | 204 } |
| 197 | 205 |
| 198 base::string16 | 206 base::string16 |
| 199 BluetoothLowEnergyWrapperFake::ExtractDeviceAddressFromDevicePath( | 207 BluetoothLowEnergyWrapperFake::ExtractDeviceAddressFromDevicePath( |
| 200 base::string16 path) { | 208 base::string16 path) { |
| 201 std::size_t found = path.find('/'); | 209 std::size_t found = path.find('/'); |
| 202 if (found != base::string16::npos) { | 210 if (found != base::string16::npos) { |
| 203 return path.substr(0, found - 1); | 211 return path.substr(0, found); |
| 204 } | 212 } |
| 205 return path; | 213 return path; |
| 206 } | 214 } |
| 207 | 215 |
| 208 base::string16 | 216 base::string16 |
| 209 BluetoothLowEnergyWrapperFake::ExtractServiceAttributeHandleFromDevicePath( | 217 BluetoothLowEnergyWrapperFake::ExtractServiceAttributeHandleFromDevicePath( |
| 210 base::string16 path) { | 218 base::string16 path) { |
| 211 std::size_t found = path.find('/'); | 219 std::size_t found = path.find('/'); |
| 212 if (found == base::string16::npos) | 220 if (found == base::string16::npos) |
| 213 return base::string16(); | 221 return base::string16(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 230 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( | 238 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( |
| 231 const BLUETOOTH_ADDRESS& btha) { | 239 const BLUETOOTH_ADDRESS& btha) { |
| 232 std::string result = base::StringPrintf( | 240 std::string result = base::StringPrintf( |
| 233 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], | 241 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], |
| 234 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); | 242 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); |
| 235 return result; | 243 return result; |
| 236 } | 244 } |
| 237 | 245 |
| 238 } // namespace win | 246 } // namespace win |
| 239 } // namespace device | 247 } // namespace device |
| OLD | NEW |