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

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

Issue 1739383002: Implement read & write remote GATT characteristic value for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 "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 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 787 }
788 *out_counts = actual_length; 788 *out_counts = actual_length;
789 789
790 if (FAILED(hr)) { 790 if (FAILED(hr)) {
791 out_included_descriptors->reset(nullptr); 791 out_included_descriptors->reset(nullptr);
792 *out_counts = 0; 792 *out_counts = 0;
793 } 793 }
794 return hr; 794 return hr;
795 } 795 }
796 796
797 HRESULT BluetoothLowEnergyWrapper::ReadTheValueOfACharacteristic(
798 base::FilePath& service_path,
799 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
800 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) {
801 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
802 if (!file.IsValid())
803 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
804
805 USHORT required_length = 0;
806 HRESULT hr = BluetoothGATTGetCharacteristicValue(
807 file.GetPlatformFile(), characteristic, 0, NULL, &required_length,
808 BLUETOOTH_GATT_FLAG_NONE);
809 if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA))
810 return hr;
811
812 out_value->reset(
813 (PBTH_LE_GATT_CHARACTERISTIC_VALUE)(new UCHAR[required_length]));
814 USHORT actual_length = required_length;
815 hr = BluetoothGATTGetCharacteristicValue(
816 file.GetPlatformFile(), characteristic, (ULONG)required_length,
817 out_value->get(), &actual_length, BLUETOOTH_GATT_FLAG_NONE);
818 if (SUCCEEDED(hr) && required_length != actual_length) {
819 LOG(ERROR) << "Retrieved characteristic value size is not equal to expected"
820 << " actual_length " << actual_length << " required_length "
821 << required_length;
822 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER);
823 }
824
825 if (FAILED(hr)) {
826 out_value->reset(nullptr);
827 }
828 return hr;
829 }
830
831 HRESULT BluetoothLowEnergyWrapper::WriteTheValueOfACharacteristic(
832 base::FilePath& service_path,
833 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
834 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) {
835 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ |
836 base::File::FLAG_WRITE);
837 if (!file.IsValid())
838 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
839
840 return BluetoothGATTSetCharacteristicValue(file.GetPlatformFile(),
841 characteristic, new_value, NULL,
842 BLUETOOTH_GATT_FLAG_NONE);
843 }
844
797 } // namespace win 845 } // namespace win
798 } // namespace device 846 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698