diff options
author | Lubomir I. Ivanov (VMware) <neolit123@gmail.com> | 2017-11-28 17:26:09 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-02-28 13:37:03 +0000 |
commit | 43eebc049aef3b858dd1d38ebe4bf9b395891722 (patch) | |
tree | 858ba6dc45e366192d90ecae0417551d75f2d0b5 /src/bluetooth/qlowenergycontroller_win_p.h | |
parent | ec54c731ad96df1b024fa4467a1f000672e5b7a6 (diff) |
Add a thread for QLowEnergyControllerPrivateWin32
Create a re-usable thread ('thread') and worker ('treadWorker')
in QLowEnergyControllerPrivateWin32 that have the same lifespan
as the controller object.
Add "job" support (ThreadWorkerJob) for the thread so that jobs
are scheduled and executed sequentially.
Each job should have a data struct. For writing that is
WriteCharData.
Handle writing of characteristics in:
QLowEnergyControllerPrivateWin32::writeCharacteristic()
QLowEnergyControllerPrivateWin32::jobFinished()
ThreadWorker::runPendingJob()
The above jobFinished() and runPendingJob() use a `switch`
to determine the ThreadWorkerJob type.
Change-Id: I3331e0d4adc29565a88fd792f9a54833881ea694
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_win_p.h')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_win_p.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergycontroller_win_p.h b/src/bluetooth/qlowenergycontroller_win_p.h index 9c2d4f92..64f824e6 100644 --- a/src/bluetooth/qlowenergycontroller_win_p.h +++ b/src/bluetooth/qlowenergycontroller_win_p.h @@ -59,8 +59,47 @@ #include "qlowenergycontroller.h" #include "qlowenergycontrollerbase_p.h" +#include <windows/qwinlowenergybluetooth_p.h> + QT_BEGIN_NAMESPACE +class QThread; +class QLowEnergyControllerPrivateWin32; + +class ThreadWorkerJob +{ +public: + enum Operation { WriteChar, ReadChar, WriteDescr, ReadDescr }; + Operation operation; + QVariant data; +}; + +Q_DECLARE_METATYPE(ThreadWorkerJob) + +struct WriteCharData +{ + QByteArray newValue; + QLowEnergyService::WriteMode mode; + HANDLE hService; + DWORD flags; + BTH_LE_GATT_CHARACTERISTIC gattCharacteristic; + int systemErrorCode; +}; + +Q_DECLARE_METATYPE(WriteCharData) + +class ThreadWorker : public QObject +{ + Q_OBJECT +public: + Q_INVOKABLE void putJob(const ThreadWorkerJob &job); + Q_INVOKABLE void runPendingJob(); +signals: + void jobFinished(const ThreadWorkerJob &job); +private: + QVector<ThreadWorkerJob> m_jobs; +}; + class QLowEnergyServiceData; extern void registerQLowEnergyControllerMetaType(); @@ -105,9 +144,13 @@ public: void addToGenericAttributeList(const QLowEnergyServiceData &service, QLowEnergyHandle startHandle) override; +public slots: + void jobFinished(const ThreadWorkerJob &job); protected: void customEvent(QEvent *e); private: + QThread *thread = nullptr; + ThreadWorker *threadWorker = nullptr; QString deviceSystemPath; }; |