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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 } | 750 } |
751 *out_counts = actual_length; | 751 *out_counts = actual_length; |
752 | 752 |
753 if (FAILED(hr)) { | 753 if (FAILED(hr)) { |
754 out_included_characteristics->reset(nullptr); | 754 out_included_characteristics->reset(nullptr); |
755 *out_counts = 0; | 755 *out_counts = 0; |
756 } | 756 } |
757 return hr; | 757 return hr; |
758 } | 758 } |
759 | 759 |
760 HRESULT BluetoothLowEnergyWrapper::ReadDescriptorsOfACharacteristic( | |
761 base::FilePath& service_path, | |
762 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | |
763 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors, | |
764 USHORT* out_counts) { | |
765 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | |
766 if (!file.IsValid()) | |
767 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); | |
768 | |
769 USHORT required_length = 0; | |
770 HRESULT hr = BluetoothGATTGetDescriptors( | |
771 file.GetPlatformFile(), characteristic, 0, NULL, &required_length, | |
772 BLUETOOTH_GATT_FLAG_NONE); | |
773 if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA)) | |
774 return hr; | |
775 | |
776 out_included_descriptors->reset(new BTH_LE_GATT_DESCRIPTOR[required_length]); | |
777 USHORT actual_length = required_length; | |
scheib
2016/03/01 00:06:22
I overlooked that you did not address this in prev
gogerald1
2016/03/01 17:00:13
Done.
| |
778 hr = BluetoothGATTGetDescriptors(file.GetPlatformFile(), characteristic, | |
779 actual_length, | |
780 out_included_descriptors->get(), | |
781 &required_length, BLUETOOTH_GATT_FLAG_NONE); | |
782 if (SUCCEEDED(hr) && required_length != actual_length) { | |
783 LOG(ERROR) << "Retrieved # of descriptors is not equal to expected" | |
784 << " actual_length " << actual_length << " required_length " | |
785 << required_length; | |
786 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); | |
787 } | |
788 *out_counts = actual_length; | |
789 | |
790 if (FAILED(hr)) { | |
791 out_included_descriptors->reset(nullptr); | |
792 *out_counts = 0; | |
793 } | |
794 return hr; | |
795 } | |
796 | |
760 } // namespace win | 797 } // namespace win |
761 } // namespace device | 798 } // namespace device |
OLD | NEW |