diff options
| author | Ingo Klöcker <[email protected]> | 2023-01-03 11:29:48 +0000 |
|---|---|---|
| committer | Ingo Klöcker <[email protected]> | 2023-01-04 11:16:04 +0000 |
| commit | 18c2c0b2509069951829bb0bdd9b39dc467f5e6e (patch) | |
| tree | fc17f8fc2a6d34547cd898d541bb535539225d21 /lang/qt/src/threadedjobmixin.h | |
| parent | qt: Explicitly instantiate private job classes (diff) | |
| download | gpgme-18c2c0b2509069951829bb0bdd9b39dc467f5e6e.tar.gz gpgme-18c2c0b2509069951829bb0bdd9b39dc467f5e6e.zip | |
qt: Support deferred start of jobs
* lang/qt/src/job.cpp, lang/qt/src/job.h (Job::startNow): New method.
* lang/qt/src/job_p.h (JobPrivate::start): New pure virtual method.
* lang/qt/src/qgpgmechangeexpiryjob.cpp
(QGpgMEChangeExpiryJobPrivate::start): New.
* lang/qt/src/qgpgmeencryptjob.cpp (QGpgMEEncryptJobPrivate::start):
New.
* lang/qt/src/qgpgmeimportjob.cpp (QGpgMEImportJobPrivate::start): New.
* lang/qt/src/qgpgmelistallkeysjob.cpp
(QGpgMEListAllKeysJobPrivate::start): New.
* lang/qt/src/qgpgmesignencryptjob.cpp
(QGpgMESignEncryptJobPrivate::start): New.
* lang/qt/src/threadedjobmixin.h (Thread::hasFunction): New method.
(ThreadedJobMixin::run, ThreadedJobMixin::setWorkerFunction): New
methods.
--
startNow() starts a deferred job for which the worker function has been
set before.
GnuPG-bug-id: 6323
Diffstat (limited to '')
| -rw-r--r-- | lang/qt/src/threadedjobmixin.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lang/qt/src/threadedjobmixin.h b/lang/qt/src/threadedjobmixin.h index ef30ab36..f50ac43d 100644 --- a/lang/qt/src/threadedjobmixin.h +++ b/lang/qt/src/threadedjobmixin.h @@ -103,6 +103,12 @@ public: m_function = function; } + bool hasFunction() + { + const QMutexLocker locker(&m_mutex); + return static_cast<bool>(m_function); + } + T_result result() const { const QMutexLocker locker(&m_mutex); @@ -127,6 +133,12 @@ public: typedef ThreadedJobMixin<T_base, T_result> mixin_type; typedef T_result result_type; + void run() + { + Q_ASSERT(m_thread.hasFunction() && "Call setWorkerFunction() before run()"); + m_thread.start(); + } + protected: static_assert(std::tuple_size<T_result>::value > 2, "Result tuple too small"); @@ -167,6 +179,12 @@ protected: } template <typename T_binder> + void setWorkerFunction(const T_binder &func) + { + m_thread.setFunction([this, func]() { return func(this->context()); }); + } + + template <typename T_binder> void run(const T_binder &func) { m_thread.setFunction(std::bind(func, this->context())); |
