summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_win.cpp
diff options
context:
space:
mode:
authorLubomir I. Ivanov (VMware) <neolit123@gmail.com>2018-03-19 19:05:16 +0200
committerLubomir I. Ivanov <neolit123@gmail.com>2018-03-29 19:31:36 +0000
commit2648bb9395e9bf5df0f35d9ecac54797d84ef71a (patch)
tree3226f022244ce9c369a99b91ebf53746aaead5f2 /src/bluetooth/qlowenergycontroller_win.cpp
parentd75664c75d82accc1cbca0032750dd7d28d1777c (diff)
qlecontroller_win: read descriptors in a separate thread
Add support for the ThreadWorkerJob type ReadDesc in QLowEnergyControllerPrivateWin32. This type of job is responsible for reading GATT descriptors in a separate thread using the previously implemented ThreadWorkerJob scheme: - ThreadWorker::runPendingJob() - QLowEnergyControllerPrivateWin32::jobFinished() The blocking function in this case is getGattDescriptorValue(). Change-Id: I19298323f8ebc630b4dc34ae2e71c7e3c603beae Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_win.cpp')
-rw-r--r--src/bluetooth/qlowenergycontroller_win.cpp74
1 files changed, 48 insertions, 26 deletions
diff --git a/src/bluetooth/qlowenergycontroller_win.cpp b/src/bluetooth/qlowenergycontroller_win.cpp
index bb968194..9b2ab6a2 100644
--- a/src/bluetooth/qlowenergycontroller_win.cpp
+++ b/src/bluetooth/qlowenergycontroller_win.cpp
@@ -1106,6 +1106,7 @@ void QLowEnergyControllerPrivateWin32::jobFinished(const ThreadWorkerJob &job)
const QLowEnergyCharacteristic ch(service, charHandle);
emit service->characteristicRead(ch, data.value);
}
+ break;
case ThreadWorkerJob::WriteDescr:
{
WriteDescData data = job.data.value<WriteDescData>();
@@ -1170,7 +1171,33 @@ void QLowEnergyControllerPrivateWin32::jobFinished(const ThreadWorkerJob &job)
const QLowEnergyDescriptor dscr(service, charHandle, descriptorHandle);
emit service->descriptorWritten(dscr, data.newValue);
}
+ break;
case ThreadWorkerJob::ReadDescr:
+ {
+ ReadDescData data = job.data.value<ReadDescData>();
+ const QLowEnergyHandle descriptorHandle = static_cast<QLowEnergyHandle>(data.gattDescriptor.AttributeHandle);
+ const QLowEnergyHandle charHandle = static_cast<QLowEnergyHandle>(data.gattDescriptor.CharacteristicHandle);
+ const QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
+ QLowEnergyServicePrivate::CharData &charDetails = service->characteristicList[charHandle];
+ const QLowEnergyServicePrivate::DescData &dscrDetails = charDetails.descriptorList[descriptorHandle];
+ closeSystemDevice(data.hService);
+
+ if (data.systemErrorCode != NO_ERROR) {
+ qCWarning(QT_BT_WINDOWS) << "Unable to get value for descriptor"
+ << dscrDetails.uuid.toString()
+ << "for characteristic"
+ << charDetails.uuid.toString()
+ << "of the service" << service->uuid.toString()
+ << ":" << qt_error_string(data.systemErrorCode);
+ service->setError(QLowEnergyService::DescriptorReadError);
+ return;
+ }
+
+ updateValueOfDescriptor(charHandle, descriptorHandle, data.value, false);
+
+ QLowEnergyDescriptor dscr(service, charHandle, descriptorHandle);
+ emit service->descriptorRead(dscr, data.value);
+ }
break;
}
@@ -1191,14 +1218,14 @@ void QLowEnergyControllerPrivateWin32::readDescriptor(
if (!charDetails.descriptorList.contains(descriptorHandle))
return;
- int systemErrorCode = NO_ERROR;
-
- const HANDLE hService = openSystemService(
- remoteDevice, service->uuid, QIODevice::ReadOnly, &systemErrorCode);
+ ReadDescData data;
+ data.systemErrorCode = NO_ERROR;
+ data.hService = openSystemService(
+ remoteDevice, service->uuid, QIODevice::ReadOnly, &data.systemErrorCode);
- if (systemErrorCode != NO_ERROR) {
+ if (data.systemErrorCode != NO_ERROR) {
qCWarning(QT_BT_WINDOWS) << "Unable to open service" << service->uuid.toString()
- << ":" << qt_error_string(systemErrorCode);
+ << ":" << qt_error_string(data.systemErrorCode);
service->setError(QLowEnergyService::DescriptorReadError);
return;
}
@@ -1206,29 +1233,15 @@ void QLowEnergyControllerPrivateWin32::readDescriptor(
const QLowEnergyServicePrivate::DescData &dscrDetails
= charDetails.descriptorList[descriptorHandle];
- BTH_LE_GATT_DESCRIPTOR gattDescriptor = recoverNativeLeGattDescriptor(
+ data.gattDescriptor = recoverNativeLeGattDescriptor(
service->startHandle, charHandle, descriptorHandle, dscrDetails);
- const QByteArray value = getGattDescriptorValue(
- hService, const_cast<PBTH_LE_GATT_DESCRIPTOR>(
- &gattDescriptor), &systemErrorCode);
- closeSystemDevice(hService);
-
- if (systemErrorCode != NO_ERROR) {
- qCWarning(QT_BT_WINDOWS) << "Unable to get value for descriptor"
- << dscrDetails.uuid.toString()
- << "for characteristic"
- << charDetails.uuid.toString()
- << "of the service" << service->uuid.toString()
- << ":" << qt_error_string(systemErrorCode);
- service->setError(QLowEnergyService::DescriptorReadError);
- return;
- }
-
- updateValueOfDescriptor(charHandle, descriptorHandle, value, false);
+ ThreadWorkerJob job;
+ job.operation = ThreadWorkerJob::ReadDescr;
+ job.data = QVariant::fromValue(data);
- QLowEnergyDescriptor dscr(service, charHandle, descriptorHandle);
- emit service->descriptorRead(dscr, value);
+ QMetaObject::invokeMethod(threadWorker, "putJob", Qt::QueuedConnection,
+ Q_ARG(ThreadWorkerJob, job));
}
void QLowEnergyControllerPrivateWin32::writeDescriptor(
@@ -1316,7 +1329,16 @@ void ThreadWorker::runPendingJob()
data.newValue, &data.systemErrorCode);
job.data = QVariant::fromValue(data);
}
+ break;
case ThreadWorkerJob::ReadDescr:
+ {
+ ReadDescData data = job.data.value<ReadDescData>();
+ data.value = getGattDescriptorValue(
+ data.hService,
+ const_cast<PBTH_LE_GATT_DESCRIPTOR>(&data.gattDescriptor),
+ &data.systemErrorCode);
+ job.data = QVariant::fromValue(data);
+ }
break;
}