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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 712 ScopedVector<BluetoothLowEnergyServiceInfo>* services, |
713 std::string* error) { | 713 std::string* error) { |
714 if (!IsBluetoothLowEnergySupported()) { | 714 if (!IsBluetoothLowEnergySupported()) { |
715 *error = kPlatformNotSupported; | 715 *error = kPlatformNotSupported; |
716 return false; | 716 return false; |
717 } | 717 } |
718 | 718 |
719 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); | 719 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); |
720 } | 720 } |
721 | 721 |
722 HRESULT BluetoothLowEnergyWrapper::ReadIncludedServicesOfAService( | |
723 base::FilePath& service_path, | |
724 const PBTH_LE_GATT_SERVICE service, | |
725 scoped_ptr<BTH_LE_GATT_SERVICE>* out_included_services, | |
726 USHORT* out_counts) { | |
727 HRESULT hr = S_OK; | |
728 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | |
729 if (!file.IsValid()) { | |
730 hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); | |
731 return hr; | |
732 } | |
733 | |
734 USHORT required_length = 0; | |
735 hr = BluetoothGATTGetIncludedServices(file.GetPlatformFile(), service, 0, | |
736 NULL, &required_length, | |
737 BLUETOOTH_GATT_FLAG_NONE); | |
738 if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA)) { | |
739 return hr; | |
740 } | |
741 | |
742 (*out_included_services).reset(new BTH_LE_GATT_SERVICE[required_length]); | |
ortuno
2016/02/19 17:33:05
You do this in a couple of places: why don't use a
gogerald1
2016/02/19 22:45:02
Done.
| |
743 USHORT actual_length = required_length; | |
744 hr = BluetoothGATTGetIncludedServices( | |
745 file.GetPlatformFile(), service, actual_length, | |
746 (*out_included_services).get(), &required_length, | |
747 BLUETOOTH_GATT_FLAG_NONE); | |
748 if (SUCCEEDED(hr) && required_length != actual_length) { | |
749 LOG(ERROR) << "Retrieved included services is not equal to expected" | |
750 << " actual_length " << actual_length << " required_length " | |
751 << required_length; | |
752 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); | |
753 } | |
754 *out_counts = actual_length; | |
755 | |
756 if (FAILED(hr)) { | |
757 (*out_included_services).reset(nullptr); | |
758 *out_counts = 0; | |
759 } | |
760 return hr; | |
761 } | |
762 | |
763 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService( | |
764 base::FilePath& service_path, | |
765 const PBTH_LE_GATT_SERVICE service, | |
766 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, | |
767 USHORT* out_counts) { | |
768 HRESULT hr = S_OK; | |
769 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | |
770 if (!file.IsValid()) { | |
771 hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); | |
772 return hr; | |
773 } | |
774 | |
775 USHORT required_length = 0; | |
776 hr = BluetoothGATTGetCharacteristics(file.GetPlatformFile(), service, 0, NULL, | |
777 &required_length, | |
778 BLUETOOTH_GATT_FLAG_NONE); | |
779 if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA)) { | |
780 return hr; | |
781 } | |
782 | |
783 (*out_included_characteristics) | |
784 .reset(new BTH_LE_GATT_CHARACTERISTIC[required_length]); | |
785 USHORT actual_length = required_length; | |
786 hr = BluetoothGATTGetCharacteristics( | |
787 file.GetPlatformFile(), service, actual_length, | |
788 (*out_included_characteristics).get(), &required_length, | |
789 BLUETOOTH_GATT_FLAG_NONE); | |
790 if (SUCCEEDED(hr) && required_length != actual_length) { | |
791 LOG(ERROR) << "Retrieved charactersitics is not equal to expected" | |
792 << " actual_length " << actual_length << " required_length " | |
793 << required_length; | |
794 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); | |
795 } | |
796 *out_counts = actual_length; | |
797 | |
798 if (FAILED(hr)) { | |
799 (*out_included_characteristics).reset(nullptr); | |
800 *out_counts = 0; | |
801 } | |
802 return hr; | |
803 } | |
804 | |
722 } // namespace win | 805 } // namespace win |
723 } // namespace device | 806 } // namespace device |
OLD | NEW |