Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: device/bluetooth/bluetooth_low_energy_win.cc

Issue 2614753004: Remove ScopedVector from bluetooth. (Closed)
Patch Set: last win bits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Windows 8 exposes BLE devices only if they are visible and paired. This 365 // Windows 8 exposes BLE devices only if they are visible and paired. This
366 // might change in the future if Windows offers a public API for discovering 366 // might change in the future if Windows offers a public API for discovering
367 // and pairing BLE devices. 367 // and pairing BLE devices.
368 device_info->visible = true; 368 device_info->visible = true;
369 device_info->authenticated = true; 369 device_info->authenticated = true;
370 return true; 370 return true;
371 } 371 }
372 372
373 bool CollectBluetoothLowEnergyDeviceServices( 373 bool CollectBluetoothLowEnergyDeviceServices(
374 const base::FilePath& device_path, 374 const base::FilePath& device_path,
375 ScopedVector<BluetoothLowEnergyServiceInfo>* services, 375 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services,
376 std::string* error) { 376 std::string* error) {
377 base::File file(device_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 377 base::File file(device_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
378 if (!file.IsValid()) { 378 if (!file.IsValid()) {
379 *error = file.ErrorToString(file.error_details()); 379 *error = file.ErrorToString(file.error_details());
380 return false; 380 return false;
381 } 381 }
382 382
383 USHORT required_length; 383 USHORT required_length;
384 HRESULT hr = BluetoothGATTGetServices(file.GetPlatformFile(), 384 HRESULT hr = BluetoothGATTGetServices(file.GetPlatformFile(),
385 0, 385 0,
(...skipping 15 matching lines...) Expand all
401 BLUETOOTH_GATT_FLAG_NONE); 401 BLUETOOTH_GATT_FLAG_NONE);
402 if (!CheckHResult(hr, kDeviceInfoError, error)) 402 if (!CheckHResult(hr, kDeviceInfoError, error))
403 return false; 403 return false;
404 if (!CheckExpectedLength( 404 if (!CheckExpectedLength(
405 actual_length, required_length, kDeviceInfoError, error)) { 405 actual_length, required_length, kDeviceInfoError, error)) {
406 return false; 406 return false;
407 } 407 }
408 408
409 for (USHORT i = 0; i < actual_length; ++i) { 409 for (USHORT i = 0; i < actual_length; ++i) {
410 BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]); 410 BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]);
411 BluetoothLowEnergyServiceInfo* service_info = 411 auto service_info = base::MakeUnique<BluetoothLowEnergyServiceInfo>();
412 new BluetoothLowEnergyServiceInfo();
413 service_info->uuid = gatt_service.ServiceUuid; 412 service_info->uuid = gatt_service.ServiceUuid;
414 service_info->attribute_handle = gatt_service.AttributeHandle; 413 service_info->attribute_handle = gatt_service.AttributeHandle;
415 services->push_back(service_info); 414 services->push_back(std::move(service_info));
416 } 415 }
417 416
418 return true; 417 return true;
419 } 418 }
420 419
421 bool CollectBluetoothLowEnergyDeviceInfo( 420 bool CollectBluetoothLowEnergyDeviceInfo(
422 const ScopedDeviceInfoSetHandle& device_info_handle, 421 const ScopedDeviceInfoSetHandle& device_info_handle,
423 PSP_DEVICE_INTERFACE_DATA device_interface_data, 422 PSP_DEVICE_INTERFACE_DATA device_interface_data,
424 std::unique_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info, 423 std::unique_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info,
425 std::string* error) { 424 std::string* error) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 534 }
536 535
537 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT 536 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT
538 // service devices according to |device_interface_guid|. 537 // service devices according to |device_interface_guid|.
539 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds 538 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds
540 // Bluetooth low energy devices. |device_interface_guid| = 539 // Bluetooth low energy devices. |device_interface_guid| =
541 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy 540 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy
542 // Gatt service devices. 541 // Gatt service devices.
543 bool EnumerateKnownBLEOrBLEGattServiceDevices( 542 bool EnumerateKnownBLEOrBLEGattServiceDevices(
544 GUID guid, 543 GUID guid,
545 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 544 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices,
546 std::string* error) { 545 std::string* error) {
547 ScopedDeviceInfoSetHandle info_set_handle; 546 ScopedDeviceInfoSetHandle info_set_handle;
548 HRESULT hr = OpenBluetoothLowEnergyDevices(guid, &info_set_handle); 547 HRESULT hr = OpenBluetoothLowEnergyDevices(guid, &info_set_handle);
549 if (FAILED(hr)) { 548 if (FAILED(hr)) {
550 *error = FormatBluetoothError(kDeviceEnumError, hr); 549 *error = FormatBluetoothError(kDeviceEnumError, hr);
551 return false; 550 return false;
552 } 551 }
553 552
554 for (DWORD i = 0;; ++i) { 553 for (DWORD i = 0;; ++i) {
555 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info; 554 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 670 }
672 671
673 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {} 672 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {}
674 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {} 673 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {}
675 674
676 bool BluetoothLowEnergyWrapper::IsBluetoothLowEnergySupported() { 675 bool BluetoothLowEnergyWrapper::IsBluetoothLowEnergySupported() {
677 return base::win::GetVersion() >= base::win::VERSION_WIN8; 676 return base::win::GetVersion() >= base::win::VERSION_WIN8;
678 } 677 }
679 678
680 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices( 679 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices(
681 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 680 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices,
682 std::string* error) { 681 std::string* error) {
683 if (!IsBluetoothLowEnergySupported()) { 682 if (!IsBluetoothLowEnergySupported()) {
684 *error = kPlatformNotSupported; 683 *error = kPlatformNotSupported;
685 return false; 684 return false;
686 } 685 }
687 686
688 return EnumerateKnownBLEOrBLEGattServiceDevices( 687 return EnumerateKnownBLEOrBLEGattServiceDevices(
689 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error); 688 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error);
690 } 689 }
691 690
692 bool BluetoothLowEnergyWrapper:: 691 bool BluetoothLowEnergyWrapper::
693 EnumerateKnownBluetoothLowEnergyGattServiceDevices( 692 EnumerateKnownBluetoothLowEnergyGattServiceDevices(
694 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 693 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices,
695 std::string* error) { 694 std::string* error) {
696 if (!IsBluetoothLowEnergySupported()) { 695 if (!IsBluetoothLowEnergySupported()) {
697 *error = kPlatformNotSupported; 696 *error = kPlatformNotSupported;
698 return false; 697 return false;
699 } 698 }
700 699
701 return EnumerateKnownBLEOrBLEGattServiceDevices( 700 return EnumerateKnownBLEOrBLEGattServiceDevices(
702 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error); 701 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error);
703 } 702 }
704 703
705 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices( 704 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices(
706 const base::FilePath& device_path, 705 const base::FilePath& device_path,
707 ScopedVector<BluetoothLowEnergyServiceInfo>* services, 706 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services,
708 std::string* error) { 707 std::string* error) {
709 if (!IsBluetoothLowEnergySupported()) { 708 if (!IsBluetoothLowEnergySupported()) {
710 *error = kPlatformNotSupported; 709 *error = kPlatformNotSupported;
711 return false; 710 return false;
712 } 711 }
713 712
714 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); 713 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error);
715 } 714 }
716 715
717 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService( 716 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService(
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ | 863 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ |
865 base::File::FLAG_WRITE); 864 base::File::FLAG_WRITE);
866 if (!file.IsValid()) 865 if (!file.IsValid())
867 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); 866 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
868 return BluetoothGATTSetDescriptorValue(file.GetPlatformFile(), descriptor, 867 return BluetoothGATTSetDescriptorValue(file.GetPlatformFile(), descriptor,
869 new_value, BLUETOOTH_GATT_FLAG_NONE); 868 new_value, BLUETOOTH_GATT_FLAG_NONE);
870 } 869 }
871 870
872 } // namespace win 871 } // namespace win
873 } // namespace device 872 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_win.h ('k') | device/bluetooth/bluetooth_low_energy_win_fake.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698