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 "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 address.ullLong = BLUETOOTH_NULL_ADDRESS; | 604 address.ullLong = BLUETOOTH_NULL_ADDRESS; |
605 } | 605 } |
606 | 606 |
607 BluetoothLowEnergyDeviceInfo::~BluetoothLowEnergyDeviceInfo() { | 607 BluetoothLowEnergyDeviceInfo::~BluetoothLowEnergyDeviceInfo() { |
608 } | 608 } |
609 | 609 |
610 bool IsBluetoothLowEnergySupported() { | 610 bool IsBluetoothLowEnergySupported() { |
611 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 611 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
612 } | 612 } |
613 | 613 |
614 bool EnumerateKnownBluetoothLowEnergyDevices( | 614 bool ExtractBluetoothAddressFromDeviceInstanceIdForTesting( |
615 const std::string& instance_id, | |
616 BLUETOOTH_ADDRESS* btha, | |
617 std::string* error) { | |
618 return ExtractBluetoothAddressFromDeviceInstanceId(instance_id, btha, error); | |
619 } | |
620 | |
621 static BluetoothLowEnergyHub* instance_ = nullptr; | |
scheib
2016/01/29 04:35:50
I think you'll want a base/lazy_instance.h as you
gogerald1
2016/02/02 22:00:20
Done.
| |
622 BluetoothLowEnergyHub* BluetoothLowEnergyHub::GetInstance() { | |
623 if (instance_ == nullptr) { | |
624 instance_ = new BluetoothLowEnergyHub(); | |
625 } | |
626 return instance_; | |
627 } | |
628 | |
629 void BluetoothLowEnergyHub::SetInstanceForTest( | |
630 BluetoothLowEnergyHub* instance) { | |
631 if (instance_ != nullptr) | |
632 delete instance_; | |
scheib
2016/01/29 04:35:50
The if isn't needed. just delete, it works on null
gogerald1
2016/02/02 22:00:20
Done.
| |
633 instance_ = instance; | |
634 } | |
635 | |
636 BluetoothLowEnergyHub::BluetoothLowEnergyHub() {} | |
637 BluetoothLowEnergyHub::~BluetoothLowEnergyHub() {} | |
638 | |
639 bool BluetoothLowEnergyHub::EnumerateKnownBluetoothLowEnergyDevices( | |
615 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 640 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
616 std::string* error) { | 641 std::string* error) { |
617 if (!IsBluetoothLowEnergySupported()) { | 642 if (!IsBluetoothLowEnergySupported()) { |
618 *error = kPlatformNotSupported; | 643 *error = kPlatformNotSupported; |
619 return false; | 644 return false; |
620 } | 645 } |
621 | 646 |
622 ScopedDeviceInfoSetHandle info_set_handle; | 647 ScopedDeviceInfoSetHandle info_set_handle; |
623 HRESULT hr = OpenBluetoothLowEnergyDevices(&info_set_handle); | 648 HRESULT hr = OpenBluetoothLowEnergyDevices(&info_set_handle); |
624 if (FAILED(hr)) { | 649 if (FAILED(hr)) { |
625 *error = FormatBluetoothError(kDeviceEnumError, hr); | 650 *error = FormatBluetoothError(kDeviceEnumError, hr); |
626 return false; | 651 return false; |
627 } | 652 } |
628 | 653 |
629 for (DWORD i = 0;; ++i) { | 654 for (DWORD i = 0;; ++i) { |
630 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info; | 655 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info; |
631 DeviceInfoResult result = EnumerateSingleBluetoothLowEnergyDevice( | 656 DeviceInfoResult result = EnumerateSingleBluetoothLowEnergyDevice( |
632 info_set_handle, i, &device_info, error); | 657 info_set_handle, i, &device_info, error); |
633 switch (result) { | 658 switch (result) { |
634 case kNoMoreDevices: | 659 case kNoMoreDevices: |
635 return true; | 660 return true; |
636 case kError: | 661 case kError: |
637 return false; | 662 return false; |
638 case kOk: | 663 case kOk: |
639 devices->push_back(device_info.Pass()); | 664 devices->push_back(device_info.Pass()); |
640 } | 665 } |
641 } | 666 } |
642 } | 667 } |
643 | 668 |
644 bool EnumerateKnownBluetoothLowEnergyServices( | 669 bool BluetoothLowEnergyHub::EnumerateKnownBluetoothLowEnergyServices( |
645 const base::FilePath& device_path, | 670 const base::FilePath& device_path, |
646 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 671 ScopedVector<BluetoothLowEnergyServiceInfo>* services, |
647 std::string* error) { | 672 std::string* error) { |
648 if (!IsBluetoothLowEnergySupported()) { | 673 if (!IsBluetoothLowEnergySupported()) { |
649 *error = kPlatformNotSupported; | 674 *error = kPlatformNotSupported; |
650 return false; | 675 return false; |
651 } | 676 } |
652 | 677 |
653 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); | 678 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); |
654 } | 679 } |
655 | 680 |
656 bool ExtractBluetoothAddressFromDeviceInstanceIdForTesting( | |
657 const std::string& instance_id, | |
658 BLUETOOTH_ADDRESS* btha, | |
659 std::string* error) { | |
660 return ExtractBluetoothAddressFromDeviceInstanceId(instance_id, btha, error); | |
661 } | |
662 | |
663 } // namespace win | 681 } // namespace win |
664 } // namespace device | 682 } // namespace device |
OLD | NEW |