summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_win.cpp
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2018-01-29 13:49:51 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2018-02-28 11:39:29 +0000
commite63f53aefdecc7ae54986fedb459cb7b40859abd (patch)
treef0b21b13c13cc2289a750e545e19fb6ff0c97681 /src/bluetooth/qlowenergycontroller_win.cpp
parentbb570997e645413efec1a4426baf997cf36767bd (diff)
Reduce quantity of "reinterpret_cast" calls
... that simplified a code a bit. Change-Id: Ice7d082f005bfc36e86909784fb6fe38c6f6811f Reviewed-by: Lubomir I. Ivanov <neolit123@gmail.com> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_win.cpp')
-rw-r--r--src/bluetooth/qlowenergycontroller_win.cpp23
1 files 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<PBTH_LE_GATT_CHARACTERISTIC_VALUE>(valueBuffer.data());
+
const HRESULT hr = ::BluetoothGATTGetCharacteristicValue(
hService,
gattCharacteristic,
valueBufferSize,
- valueBuffer.isEmpty() ? NULL : reinterpret_cast<PBTH_LE_GATT_CHARACTERISTIC_VALUE>(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<const char *>(&value->Data[0]), value->DataSize);
+ return QByteArray(reinterpret_cast<const char *>(&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<PBTH_LE_GATT_DESCRIPTOR_VALUE>(valueBuffer.data());
+
const HRESULT hr = ::BluetoothGATTGetDescriptorValue(
hService,
gattDescriptor,
valueBufferSize,
- valueBuffer.isEmpty() ? NULL : reinterpret_cast<PBTH_LE_GATT_DESCRIPTOR_VALUE>(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<const char *>(&value->Data[0]), value->DataSize);
+ return QByteArray(reinterpret_cast<const char *>(&valuePtr->Data[0]),
+ valuePtr->DataSize);
} else {
const DWORD error = WIN32_FROM_HRESULT(hr);
if (error == ERROR_MORE_DATA) {