OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.h" | 5 #include "device/bluetooth/bluetooth_low_energy_win.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/files/file.h" | 9 #include "base/files/file.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
11 #include "base/win/scoped_handle.h" | 13 #include "base/win/scoped_handle.h" |
12 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 static device::win::BluetoothLowEnergyWrapper* g_instance_ = nullptr; | 18 static device::win::BluetoothLowEnergyWrapper* g_instance_ = nullptr; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 &required_length, | 198 &required_length, |
197 0); | 199 0); |
198 if (!CheckSuccess(!!success, kDeviceInfoError, error)) | 200 if (!CheckSuccess(!!success, kDeviceInfoError, error)) |
199 return false; | 201 return false; |
200 if (!CheckExpectedLength( | 202 if (!CheckExpectedLength( |
201 actual_length, required_length, kDeviceInfoError, error)) { | 203 actual_length, required_length, kDeviceInfoError, error)) { |
202 return false; | 204 return false; |
203 } | 205 } |
204 | 206 |
205 (*value) = scoped_ptr<DevicePropertyValue>( | 207 (*value) = scoped_ptr<DevicePropertyValue>( |
206 new DevicePropertyValue(prop_type, prop_value.Pass(), actual_length)); | 208 new DevicePropertyValue(prop_type, std::move(prop_value), actual_length)); |
207 return true; | 209 return true; |
208 } | 210 } |
209 | 211 |
210 bool CollectBluetoothLowEnergyDeviceRegistryProperty( | 212 bool CollectBluetoothLowEnergyDeviceRegistryProperty( |
211 const ScopedDeviceInfoSetHandle& device_info_handle, | 213 const ScopedDeviceInfoSetHandle& device_info_handle, |
212 PSP_DEVINFO_DATA device_info_data, | 214 PSP_DEVINFO_DATA device_info_data, |
213 DWORD property_id, | 215 DWORD property_id, |
214 scoped_ptr<DeviceRegistryPropertyValue>* value, | 216 scoped_ptr<DeviceRegistryPropertyValue>* value, |
215 std::string* error) { | 217 std::string* error) { |
216 ULONG required_length = 0; | 218 ULONG required_length = 0; |
(...skipping 18 matching lines...) Expand all Loading... |
235 actual_length, | 237 actual_length, |
236 &required_length); | 238 &required_length); |
237 if (!CheckSuccess(!!success, kDeviceInfoError, error)) | 239 if (!CheckSuccess(!!success, kDeviceInfoError, error)) |
238 return false; | 240 return false; |
239 if (!CheckExpectedLength( | 241 if (!CheckExpectedLength( |
240 actual_length, required_length, kDeviceInfoError, error)) { | 242 actual_length, required_length, kDeviceInfoError, error)) { |
241 return false; | 243 return false; |
242 } | 244 } |
243 | 245 |
244 (*value) = DeviceRegistryPropertyValue::Create( | 246 (*value) = DeviceRegistryPropertyValue::Create( |
245 property_type, property_value.Pass(), actual_length).Pass(); | 247 property_type, std::move(property_value), actual_length); |
246 return true; | 248 return true; |
247 } | 249 } |
248 | 250 |
249 bool CollectBluetoothLowEnergyDeviceInstanceId( | 251 bool CollectBluetoothLowEnergyDeviceInstanceId( |
250 const ScopedDeviceInfoSetHandle& device_info_handle, | 252 const ScopedDeviceInfoSetHandle& device_info_handle, |
251 PSP_DEVINFO_DATA device_info_data, | 253 PSP_DEVINFO_DATA device_info_data, |
252 scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo>& device_info, | 254 scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo>& device_info, |
253 std::string* error) { | 255 std::string* error) { |
254 ULONG required_length = 0; | 256 ULONG required_length = 0; |
255 BOOL success = SetupDiGetDeviceInstanceId( | 257 BOOL success = SetupDiGetDeviceInstanceId( |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 return false; | 474 return false; |
473 } | 475 } |
474 if (!CollectBluetoothLowEnergyDeviceAddress( | 476 if (!CollectBluetoothLowEnergyDeviceAddress( |
475 device_info_handle, &device_info_data, result, error)) { | 477 device_info_handle, &device_info_data, result, error)) { |
476 return false; | 478 return false; |
477 } | 479 } |
478 if (!CollectBluetoothLowEnergyDeviceStatus( | 480 if (!CollectBluetoothLowEnergyDeviceStatus( |
479 device_info_handle, &device_info_data, result, error)) { | 481 device_info_handle, &device_info_data, result, error)) { |
480 return false; | 482 return false; |
481 } | 483 } |
482 (*device_info) = result.Pass(); | 484 (*device_info) = std::move(result); |
483 return true; | 485 return true; |
484 } | 486 } |
485 | 487 |
486 enum DeviceInfoResult { kOk, kError, kNoMoreDevices }; | 488 enum DeviceInfoResult { kOk, kError, kNoMoreDevices }; |
487 | 489 |
488 // For |device_interface_guid| see the Note of below | 490 // For |device_interface_guid| see the Note of below |
489 // EnumerateKnownBLEOrBLEGattServiceDevices interface. | 491 // EnumerateKnownBLEOrBLEGattServiceDevices interface. |
490 DeviceInfoResult EnumerateSingleBluetoothLowEnergyDevice( | 492 DeviceInfoResult EnumerateSingleBluetoothLowEnergyDevice( |
491 GUID device_interface_guid, | 493 GUID device_interface_guid, |
492 const ScopedDeviceInfoSetHandle& device_info_handle, | 494 const ScopedDeviceInfoSetHandle& device_info_handle, |
(...skipping 30 matching lines...) Expand all Loading... |
523 // EnumerateKnownBLEOrBLEGattServiceDevices interface. | 525 // EnumerateKnownBLEOrBLEGattServiceDevices interface. |
524 HRESULT OpenBluetoothLowEnergyDevices(GUID device_interface_guid, | 526 HRESULT OpenBluetoothLowEnergyDevices(GUID device_interface_guid, |
525 ScopedDeviceInfoSetHandle* handle) { | 527 ScopedDeviceInfoSetHandle* handle) { |
526 GUID BluetoothClassGUID = device_interface_guid; | 528 GUID BluetoothClassGUID = device_interface_guid; |
527 ScopedDeviceInfoSetHandle result(SetupDiGetClassDevs( | 529 ScopedDeviceInfoSetHandle result(SetupDiGetClassDevs( |
528 &BluetoothClassGUID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); | 530 &BluetoothClassGUID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); |
529 if (!result.IsValid()) { | 531 if (!result.IsValid()) { |
530 return HRESULT_FROM_WIN32(::GetLastError()); | 532 return HRESULT_FROM_WIN32(::GetLastError()); |
531 } | 533 } |
532 | 534 |
533 (*handle) = result.Pass(); | 535 (*handle) = std::move(result); |
534 return S_OK; | 536 return S_OK; |
535 } | 537 } |
536 | 538 |
537 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT | 539 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT |
538 // service devices according to |device_interface_guid|. | 540 // service devices according to |device_interface_guid|. |
539 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds | 541 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds |
540 // Bluetooth low energy devices. |device_interface_guid| = | 542 // Bluetooth low energy devices. |device_interface_guid| = |
541 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy | 543 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy |
542 // Gatt service devices. | 544 // Gatt service devices. |
543 bool EnumerateKnownBLEOrBLEGattServiceDevices( | 545 bool EnumerateKnownBLEOrBLEGattServiceDevices( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 CHECK_GE(character_size, 1u); | 586 CHECK_GE(character_size, 1u); |
585 WCHAR* value_string = reinterpret_cast<WCHAR*>(value.get()); | 587 WCHAR* value_string = reinterpret_cast<WCHAR*>(value.get()); |
586 value_string[character_size - 1] = 0; | 588 value_string[character_size - 1] = 0; |
587 break; | 589 break; |
588 } | 590 } |
589 case REG_DWORD: { | 591 case REG_DWORD: { |
590 CHECK_EQ(value_size, sizeof(DWORD)); | 592 CHECK_EQ(value_size, sizeof(DWORD)); |
591 break; | 593 break; |
592 } | 594 } |
593 } | 595 } |
594 return scoped_ptr<DeviceRegistryPropertyValue>( | 596 return make_scoped_ptr(new DeviceRegistryPropertyValue( |
595 new DeviceRegistryPropertyValue(property_type, value.Pass(), value_size)); | 597 property_type, std::move(value), value_size)); |
596 } | 598 } |
597 | 599 |
598 DeviceRegistryPropertyValue::DeviceRegistryPropertyValue( | 600 DeviceRegistryPropertyValue::DeviceRegistryPropertyValue( |
599 DWORD property_type, | 601 DWORD property_type, |
600 scoped_ptr<uint8_t[]> value, | 602 scoped_ptr<uint8_t[]> value, |
601 size_t value_size) | 603 size_t value_size) |
602 : property_type_(property_type), | 604 : property_type_(property_type), |
603 value_(value.Pass()), | 605 value_(std::move(value)), |
604 value_size_(value_size) { | 606 value_size_(value_size) {} |
605 } | |
606 | 607 |
607 DeviceRegistryPropertyValue::~DeviceRegistryPropertyValue() { | 608 DeviceRegistryPropertyValue::~DeviceRegistryPropertyValue() { |
608 } | 609 } |
609 | 610 |
610 std::string DeviceRegistryPropertyValue::AsString() const { | 611 std::string DeviceRegistryPropertyValue::AsString() const { |
611 CHECK_EQ(property_type_, static_cast<DWORD>(REG_SZ)); | 612 CHECK_EQ(property_type_, static_cast<DWORD>(REG_SZ)); |
612 WCHAR* value_string = reinterpret_cast<WCHAR*>(value_.get()); | 613 WCHAR* value_string = reinterpret_cast<WCHAR*>(value_.get()); |
613 return base::SysWideToUTF8(value_string); | 614 return base::SysWideToUTF8(value_string); |
614 } | 615 } |
615 | 616 |
616 DWORD DeviceRegistryPropertyValue::AsDWORD() const { | 617 DWORD DeviceRegistryPropertyValue::AsDWORD() const { |
617 CHECK_EQ(property_type_, static_cast<DWORD>(REG_DWORD)); | 618 CHECK_EQ(property_type_, static_cast<DWORD>(REG_DWORD)); |
618 DWORD* value = reinterpret_cast<DWORD*>(value_.get()); | 619 DWORD* value = reinterpret_cast<DWORD*>(value_.get()); |
619 return *value; | 620 return *value; |
620 } | 621 } |
621 | 622 |
622 DevicePropertyValue::DevicePropertyValue(DEVPROPTYPE property_type, | 623 DevicePropertyValue::DevicePropertyValue(DEVPROPTYPE property_type, |
623 scoped_ptr<uint8_t[]> value, | 624 scoped_ptr<uint8_t[]> value, |
624 size_t value_size) | 625 size_t value_size) |
625 : property_type_(property_type), | 626 : property_type_(property_type), |
626 value_(value.Pass()), | 627 value_(std::move(value)), |
627 value_size_(value_size) { | 628 value_size_(value_size) {} |
628 } | |
629 | 629 |
630 DevicePropertyValue::~DevicePropertyValue() { | 630 DevicePropertyValue::~DevicePropertyValue() { |
631 } | 631 } |
632 | 632 |
633 uint32_t DevicePropertyValue::AsUint32() const { | 633 uint32_t DevicePropertyValue::AsUint32() const { |
634 CHECK_EQ(property_type_, static_cast<DEVPROPTYPE>(DEVPROP_TYPE_UINT32)); | 634 CHECK_EQ(property_type_, static_cast<DEVPROPTYPE>(DEVPROP_TYPE_UINT32)); |
635 CHECK_EQ(value_size_, sizeof(uint32_t)); | 635 CHECK_EQ(value_size_, sizeof(uint32_t)); |
636 return *reinterpret_cast<uint32_t*>(value_.get()); | 636 return *reinterpret_cast<uint32_t*>(value_.get()); |
637 } | 637 } |
638 | 638 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 | 784 |
785 if (FAILED(hr)) { | 785 if (FAILED(hr)) { |
786 out_included_descriptors->reset(nullptr); | 786 out_included_descriptors->reset(nullptr); |
787 *out_counts = 0; | 787 *out_counts = 0; |
788 } | 788 } |
789 return hr; | 789 return hr; |
790 } | 790 } |
791 | 791 |
792 } // namespace win | 792 } // namespace win |
793 } // namespace device | 793 } // namespace device |
OLD | NEW |