From e63f53aefdecc7ae54986fedb459cb7b40859abd Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Mon, 29 Jan 2018 13:49:51 +0300 Subject: Reduce quantity of "reinterpret_cast" calls ... that simplified a code a bit. Change-Id: Ice7d082f005bfc36e86909784fb6fe38c6f6811f Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_win.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bluetooth/qlowenergycontroller_win.cpp b/src/bluetooth/qlowenergycontroller_win.cpp index b05d20e6..9f10a167 100644 --- a/src/bluetooth/qlowenergycontroller_win.cpp +++ b/src/bluetooth/qlowenergycontroller_win.cpp @@ -321,19 +321,22 @@ static QByteArray getGattCharacteristicValue( QByteArray valueBuffer; USHORT valueBufferSize = 0; for (;;) { + const auto valuePtr = valueBuffer.isEmpty() + ? NULL + : reinterpret_cast(valueBuffer.data()); + const HRESULT hr = ::BluetoothGATTGetCharacteristicValue( hService, gattCharacteristic, valueBufferSize, - valueBuffer.isEmpty() ? NULL : reinterpret_cast(valueBuffer.data()), + valuePtr, &valueBufferSize, BLUETOOTH_GATT_FLAG_NONE); if (SUCCEEDED(hr)) { *systemErrorCode = NO_ERROR; - const PBTH_LE_GATT_CHARACTERISTIC_VALUE value = reinterpret_cast< - PBTH_LE_GATT_CHARACTERISTIC_VALUE>(valueBuffer.data()); - return QByteArray(reinterpret_cast(&value->Data[0]), value->DataSize); + return QByteArray(reinterpret_cast(&valuePtr->Data[0]), + valuePtr->DataSize); } else { const DWORD error = WIN32_FROM_HRESULT(hr); if (error == ERROR_MORE_DATA) { @@ -421,20 +424,22 @@ static QByteArray getGattDescriptorValue( QByteArray valueBuffer; USHORT valueBufferSize = 0; for (;;) { + const auto valuePtr = valueBuffer.isEmpty() + ? NULL + : reinterpret_cast(valueBuffer.data()); + const HRESULT hr = ::BluetoothGATTGetDescriptorValue( hService, gattDescriptor, valueBufferSize, - valueBuffer.isEmpty() ? NULL : reinterpret_cast(valueBuffer.data()), + valuePtr, &valueBufferSize, BLUETOOTH_GATT_FLAG_NONE); if (SUCCEEDED(hr)) { *systemErrorCode = NO_ERROR; - const PBTH_LE_GATT_DESCRIPTOR_VALUE value = reinterpret_cast< - PBTH_LE_GATT_DESCRIPTOR_VALUE>(valueBuffer.data()); - - return QByteArray(reinterpret_cast(&value->Data[0]), value->DataSize); + return QByteArray(reinterpret_cast(&valuePtr->Data[0]), + valuePtr->DataSize); } else { const DWORD error = WIN32_FROM_HRESULT(hr); if (error == ERROR_MORE_DATA) { -- cgit v1.2.3