Akonadi

akthread.h
1/*
2 SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QObject>
10#include <QThread>
11
12#include <atomic>
13#include <type_traits>
14
15namespace Akonadi
16{
17namespace Server
18{
19
20class AkThread : public QObject
21{
23public:
24 enum StartMode {
25 AutoStart,
26 ManualStart,
27 NoThread // for unit-tests
28 };
29
30 template<typename T, typename... Args>
31 static std::enable_if_t<std::is_base_of_v<AkThread, T>, std::unique_ptr<T>> create(Args &&...args) noexcept
32 {
33 // Workaround T having a protected constructor
34 struct TConstructor : T {
35 explicit TConstructor(Args &&...args)
36 : T(std::forward<Args>(args)...)
37 {
38 }
39 };
40 std::unique_ptr<T> thread = std::make_unique<TConstructor>(std::forward<Args>(args)...);
41 if (thread->m_startMode == AkThread::AutoStart) {
42 thread->startThread();
43 }
44 return thread;
45 }
46
47 ~AkThread() override;
48
49 bool isInitialized() const
50 {
51 return m_initialized;
52 }
53
54 void waitForInitialized();
55
57 void initialized();
58
59protected:
60 explicit AkThread(const QString &objectName, QThread::Priority priority = QThread::InheritPriority, QObject *parent = nullptr);
61 explicit AkThread(const QString &objectName, StartMode startMode, QThread::Priority priority = QThread::InheritPriority, QObject *parent = nullptr);
62
63 void quitThread();
64 void startThread();
65
66protected Q_SLOTS:
67 virtual void init();
68 virtual void quit();
69
70private:
71 StartMode m_startMode = AutoStart;
72 bool m_quitCalled = false;
73 std::atomic_bool m_initialized = false;
74};
75
76} // namespace Server
77} // namespace Akonadi
Helper integration between Akonadi and Qt.
KGuiItem forward(BidiMode useBidi=IgnoreRTL)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QThread * thread() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Aug 30 2024 11:47:54 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.