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

Unified 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: fix conversion from 'size_t' to 'ULONG' error on trybot Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_low_energy_win.cc
diff --git a/device/bluetooth/bluetooth_low_energy_win.cc b/device/bluetooth/bluetooth_low_energy_win.cc
index 4d885658da2678a402898d566c1a13300baf365a..e17a527a708a8575663d0032126fa17cd0b48e9c 100644
--- a/device/bluetooth/bluetooth_low_energy_win.cc
+++ b/device/bluetooth/bluetooth_low_energy_win.cc
@@ -789,5 +789,53 @@ HRESULT BluetoothLowEnergyWrapper::ReadDescriptorsOfACharacteristic(
return hr;
}
+HRESULT BluetoothLowEnergyWrapper::ReadTheValueOfACharacteristic(
+ base::FilePath& service_path,
+ const PBTH_LE_GATT_CHARACTERISTIC characteristic,
+ scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) {
+ base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ if (!file.IsValid())
+ return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
+
+ USHORT allocated_length = 0;
+ HRESULT hr = BluetoothGATTGetCharacteristicValue(
+ file.GetPlatformFile(), characteristic, 0, NULL, &allocated_length,
+ BLUETOOTH_GATT_FLAG_NONE);
+ if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA))
+ return hr;
+
+ out_value->reset(
+ (PBTH_LE_GATT_CHARACTERISTIC_VALUE)(new UCHAR[allocated_length]));
+ USHORT out_length = 0;
+ hr = BluetoothGATTGetCharacteristicValue(
+ file.GetPlatformFile(), characteristic, (ULONG)allocated_length,
+ out_value->get(), &out_length, BLUETOOTH_GATT_FLAG_NONE);
+ if (SUCCEEDED(hr) && allocated_length != out_length) {
+ LOG(ERROR) << "Retrieved characteristic value size is not equal to expected"
+ << " allocated_length " << allocated_length << " got "
+ << out_length;
+ hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER);
+ }
+
+ if (FAILED(hr)) {
+ out_value->reset(nullptr);
+ }
+ return hr;
+}
+
+HRESULT BluetoothLowEnergyWrapper::WriteTheValueOfACharacteristic(
+ base::FilePath& service_path,
+ const PBTH_LE_GATT_CHARACTERISTIC characteristic,
+ PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) {
+ base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_WRITE);
+ if (!file.IsValid())
+ return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
+
+ return BluetoothGATTSetCharacteristicValue(file.GetPlatformFile(),
+ characteristic, new_value, NULL,
+ BLUETOOTH_GATT_FLAG_NONE);
+}
+
} // namespace win
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698