summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Lemanissier <eric.lemanissier@gmail.com>2018-06-19 13:02:39 +0200
committerEric Lemanissier <eric.lemanissier@gmail.com>2018-06-21 07:38:59 +0000
commit62efb446b56bc489c998f90e307aa12e72cb6b8e (patch)
treee52e3255677737858bbdb3836e4554de77a9fd41 /src
parent3a90cf6d46dc6f34ccedb7f02515573d1db4704a (diff)
downloadqtconnectivity-62efb446b56bc489c998f90e307aa12e72cb6b8e.tar.gz
win32: modernize qbluetooth*discoveryagent
arguments pass by ref NULL and 0 replaced with nullptr ::ZeroMemory replaced by default initialization range based for loop Change-Id: I393806f19155ee31e4ebe7f33ce22e9d14eafe40 Reviewed-by: Lubomir I. Ivanov <neolit123@gmail.com> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h6
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp41
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_p.h6
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_win.cpp9
4 files changed, 28 insertions, 34 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 489ed807..d60e89fa 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -96,7 +96,7 @@ class ThreadWorkerClassic : public QObject
{
Q_OBJECT
public:
- Q_INVOKABLE void discover(QVariant hSearch);
+ Q_INVOKABLE void discover(const QVariant &hSearch);
signals:
void discoveryCompleted(const QVariant res);
};
@@ -198,9 +198,9 @@ private:
void finishDiscovery(QBluetoothDeviceDiscoveryAgent::Error errorCode, const QString &errorText);
void startLeDevicesDiscovery();
- void completeLeDevicesDiscovery(const QVariant res);
+ void completeLeDevicesDiscovery(const QVariant &res);
void startClassicDevicesDiscovery(Qt::HANDLE hSearch = nullptr);
- void completeClassicDevicesDiscovery(const QVariant res);
+ void completeClassicDevicesDiscovery(const QVariant &res);
void processDiscoveredDevice(const QBluetoothDeviceInfo &foundDevice);
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp
index 3d1b0c4b..1192677e 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp
@@ -77,7 +77,7 @@ static QString devicePropertyString(
deviceInfoData,
registryProperty,
&propertyRegDataType,
- propertyBuffer.isEmpty() ? NULL : reinterpret_cast<PBYTE>(propertyBuffer.data()),
+ propertyBuffer.isEmpty() ? nullptr : reinterpret_cast<PBYTE>(propertyBuffer.data()),
propertyBuffer.size(),
&propertyBufferSize)) {
@@ -132,8 +132,7 @@ static QBluetoothDeviceInfo createClassicDeviceInfo(const BLUETOOTH_DEVICE_INFO
static QBluetoothDeviceInfo findFirstClassicDevice(
DWORD *systemErrorCode, HBLUETOOTH_DEVICE_FIND *hSearch)
{
- BLUETOOTH_DEVICE_SEARCH_PARAMS searchParams;
- ::ZeroMemory(&searchParams, sizeof(searchParams));
+ BLUETOOTH_DEVICE_SEARCH_PARAMS searchParams = {0};
searchParams.dwSize = sizeof(searchParams);
searchParams.cTimeoutMultiplier = 10; // 12.8 sec
searchParams.fIssueInquiry = TRUE;
@@ -141,10 +140,9 @@ static QBluetoothDeviceInfo findFirstClassicDevice(
searchParams.fReturnConnected = TRUE;
searchParams.fReturnRemembered = TRUE;
searchParams.fReturnUnknown = TRUE;
- searchParams.hRadio = NULL;
+ searchParams.hRadio = nullptr;
- BLUETOOTH_DEVICE_INFO deviceInfo;
- ::ZeroMemory(&deviceInfo, sizeof(deviceInfo));
+ BLUETOOTH_DEVICE_INFO deviceInfo = {0};
deviceInfo.dwSize = sizeof(deviceInfo);
const HBLUETOOTH_DEVICE_FIND hFind = ::BluetoothFindFirstDevice(
@@ -165,8 +163,7 @@ static QBluetoothDeviceInfo findFirstClassicDevice(
static QBluetoothDeviceInfo findNextClassicDevice(
DWORD *systemErrorCode, HBLUETOOTH_DEVICE_FIND hSearch)
{
- BLUETOOTH_DEVICE_INFO deviceInfo;
- ::ZeroMemory(&deviceInfo, sizeof(deviceInfo));
+ BLUETOOTH_DEVICE_INFO deviceInfo = {0};
deviceInfo.dwSize = sizeof(deviceInfo);
QBluetoothDeviceInfo foundDevice;
@@ -192,8 +189,8 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices(
const QUuid deviceInterfaceGuid("781aee18-7733-4ce4-add0-91f41c67b592");
const HDEVINFO hDeviceInfo = ::SetupDiGetClassDevs(
reinterpret_cast<const GUID *>(&deviceInterfaceGuid),
- NULL,
- 0,
+ nullptr,
+ nullptr,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hDeviceInfo == INVALID_HANDLE_VALUE) {
@@ -207,13 +204,12 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices(
QVector<LeDeviceEntry> cachedEntries;
for (;;) {
- SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
- ::ZeroMemory(&deviceInterfaceData, sizeof(deviceInterfaceData));
+ SP_DEVICE_INTERFACE_DATA deviceInterfaceData = {0};
deviceInterfaceData.cbSize = sizeof(deviceInterfaceData);
if (!::SetupDiEnumDeviceInterfaces(
hDeviceInfo,
- NULL,
+ nullptr,
reinterpret_cast<const GUID *>(&deviceInterfaceGuid),
index++,
&deviceInterfaceData)) {
@@ -225,18 +221,17 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices(
if (!::SetupDiGetDeviceInterfaceDetail(
hDeviceInfo,
&deviceInterfaceData,
- NULL,
+ nullptr,
deviceInterfaceDetailDataSize,
&deviceInterfaceDetailDataSize,
- NULL)) {
+ nullptr)) {
if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
*systemErrorCode = ::GetLastError();
break;
}
}
- SP_DEVINFO_DATA deviceInfoData;
- ::ZeroMemory(&deviceInfoData, sizeof(deviceInfoData));
+ SP_DEVINFO_DATA deviceInfoData = {0};
deviceInfoData.cbSize = sizeof(deviceInfoData);
QByteArray deviceInterfaceDetailDataBuffer(
@@ -317,9 +312,9 @@ QString QBluetoothDeviceDiscoveryAgentPrivate::discoveredLeDeviceSystemPath(
enumerateLeDevices(&dummyErrorCode);
QMutexLocker locker(cachedLeDeviceEntriesGuard());
- for (int i = 0; i < cachedLeDeviceEntries()->count(); ++i) {
- if (cachedLeDeviceEntries()->at(i).deviceAddress == deviceAddress)
- return cachedLeDeviceEntries()->at(i).devicePath;
+ for (const LeDeviceEntry &e: *cachedLeDeviceEntries) {
+ if (e.deviceAddress == deviceAddress)
+ return e.devicePath;
}
return QString();
}
@@ -468,7 +463,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startLeDevicesDiscovery()
QMetaObject::invokeMethod(threadWorkerLE, "discover", Qt::QueuedConnection);
}
-void QBluetoothDeviceDiscoveryAgentPrivate::completeLeDevicesDiscovery(const QVariant res)
+void QBluetoothDeviceDiscoveryAgentPrivate::completeLeDevicesDiscovery(const QVariant &res)
{
if (pendingCancel && !pendingStart) {
cancelDiscovery();
@@ -500,7 +495,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startClassicDevicesDiscovery(Qt::HAN
Q_ARG(QVariant, QVariant::fromValue(hSearch)));
}
-void QBluetoothDeviceDiscoveryAgentPrivate::completeClassicDevicesDiscovery(const QVariant res)
+void QBluetoothDeviceDiscoveryAgentPrivate::completeClassicDevicesDiscovery(const QVariant &res)
{
const DiscoveryResult result = res.value<DiscoveryResult>();
if (pendingCancel && !pendingStart) {
@@ -574,7 +569,7 @@ void ThreadWorkerLE::discover()
emit discoveryCompleted(res);
}
-void ThreadWorkerClassic::discover(QVariant search)
+void ThreadWorkerClassic::discover(const QVariant &search)
{
Qt::HANDLE hSearch = search.value<Qt::HANDLE>();
const QVariant res = discoverClassicDevicesStatic(hSearch);
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.h b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
index cbaab458..c845b528 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
@@ -82,8 +82,8 @@ class ThreadWorkerFind : public QObject
{
Q_OBJECT
public:
- Q_INVOKABLE void findFirst(const QVariant data);
- Q_INVOKABLE void findNext(const QVariant data);
+ Q_INVOKABLE void findFirst(const QVariant &data);
+ Q_INVOKABLE void findNext(const QVariant &data);
signals:
void findFinished(QVariant result);
};
@@ -167,7 +167,7 @@ public:
void _q_hostModeStateChanged(QBluetoothLocalDevice::HostMode state);
#endif
#ifdef QT_WIN_BLUETOOTH
- void _q_nextSdpScan(QVariant input);
+ void _q_nextSdpScan(const QVariant &input);
#endif
private:
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_win.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_win.cpp
index 8ee0f663..35ab558e 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_win.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_win.cpp
@@ -345,8 +345,7 @@ static FindServiceResult findFirstService(HANDLE hSearch, const QBluetoothAddres
GUID protocol = L2CAP_PROTOCOL_UUID; //Search for L2CAP and RFCOMM services
- WSAQUERYSET serviceQuery;
- ::ZeroMemory(&serviceQuery, sizeof(serviceQuery));
+ WSAQUERYSET serviceQuery = {0};
serviceQuery.dwSize = sizeof(WSAQUERYSET); //As specified by the windows documentation
serviceQuery.lpServiceClassId = &protocol; //The protocal of the service what is being queried
serviceQuery.dwNameSpace = NS_BTH; //As specified by the windows documentation
@@ -417,7 +416,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::stop()
pendingStop = true;
}
-void QBluetoothServiceDiscoveryAgentPrivate::_q_nextSdpScan(QVariant input)
+void QBluetoothServiceDiscoveryAgentPrivate::_q_nextSdpScan(const QVariant &input)
{
Q_Q(QBluetoothServiceDiscoveryAgent);
auto result = input.value<FindServiceResult>();
@@ -456,7 +455,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_nextSdpScan(QVariant input)
}
}
-void ThreadWorkerFind::findFirst(const QVariant data)
+void ThreadWorkerFind::findFirst(const QVariant &data)
{
auto args = data.value<FindServiceArguments>();
FindServiceResult result = findFirstService(args.hSearch, args.address);
@@ -464,7 +463,7 @@ void ThreadWorkerFind::findFirst(const QVariant data)
emit findFinished(QVariant::fromValue(result));
}
- void ThreadWorkerFind::findNext(const QVariant data)
+ void ThreadWorkerFind::findNext(const QVariant &data)
{
auto args = data.value<FindServiceArguments>();
FindServiceResult result = findNextService(args.hSearch, args.systemError);