Akonadi

searchtaskmanager.h
1/*
2 SPDX-FileCopyrightText: 2013, 2014 Daniel Vrátil <dvratil@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akthread.h"
10
11#include "agentmanagerinterface.h"
12#include "exception.h"
13#include <QList>
14#include <QMap>
15#include <QMutex>
16#include <QSet>
17#include <QStringList>
18#include <QWaitCondition>
19
20namespace Akonadi
21{
22namespace Server
23{
24class Connection;
25class AgentSearchInstance;
26
27class SearchTask
28{
29public:
30 QByteArray id;
31 QString query;
32 QStringList mimeTypes;
33 QList<qint64> collections;
34 bool complete;
35
36 QMutex sharedLock;
37 QWaitCondition notifier;
38
39 QList<QPair<QString /* resource */, qint64 /* collection */>> queries;
40 QSet<qint64> pendingResults;
41};
42
43class SearchTaskManager : public AkThread
44{
46
47protected:
48 /**
49 * Use AkThread::create() to create and start a new SearchTaskManager thread.
50 */
51 explicit SearchTaskManager();
52
53public:
54 ~SearchTaskManager() override;
55
56 void registerInstance(const QString &id);
57 void unregisterInstance(const QString &id);
58
59 void addTask(SearchTask *task);
60
61 void pushResults(const QByteArray &searchId, const QSet<qint64> &ids, Connection *connection);
62
63private Q_SLOTS:
64 void searchLoop();
65
66private:
67 class ResourceTask
68 {
69 public:
70 QString resourceId;
71 qint64 collectionId;
72 SearchTask *parentTask;
73 QSet<qint64> results;
74
75 qint64 timestamp;
76 };
77
78 using TasksMap = QMap<QString, ResourceTask *>;
79
80 bool mShouldStop;
81
82 TasksMap::Iterator cancelRunningTask(TasksMap::Iterator &iter);
83 bool allResourceTasksCompleted(SearchTask *agentSearchTask) const;
84
86 QMutex mInstancesLock;
87
88 QWaitCondition mWait;
89 QMutex mLock;
90
91 QList<SearchTask *> mTasklist;
92
93 QMap<QString /* resource */, ResourceTask *> mRunningTasks;
94 QList<ResourceTask *> mPendingResults;
95};
96
97AKONADI_EXCEPTION_MAKE_INSTANCE(SearchException);
98
99} // namespace Server
100} // namespace Akonadi
Helper integration between Akonadi and Qt.
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.