Akonadi

searchtaskmanager.h
1 /*
2  Copyright (c) 2013, 2014 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #ifndef AKONADI_SEARCHTASKMANAGER_H
21 #define AKONADI_SEARCHTASKMANAGER_H
22 
23 #include "akthread.h"
24 
25 #include <QMap>
26 #include <QVector>
27 #include <QSet>
28 #include <QStringList>
29 #include <QMutex>
30 #include <QWaitCondition>
31 #include "exception.h"
32 #include "agentmanagerinterface.h"
33 
34 namespace Akonadi
35 {
36 namespace Server
37 {
38 
39 class AkonadiServer;
40 class Connection;
41 class AgentSearchInstance;
42 
43 class SearchTask
44 {
45 public:
46  QByteArray id;
47  QString query;
49  QVector<qint64> collections;
50  bool complete;
51 
52  QMutex sharedLock;
54 
55  QVector<QPair<QString /* resource */, qint64 /* collection */> > queries;
56  QSet<qint64> pendingResults;
57 };
58 
59 class SearchTaskManager : public AkThread
60 {
61  Q_OBJECT
62 
63 public:
64  explicit SearchTaskManager();
65  ~SearchTaskManager() override;
66 
67  void registerInstance(const QString &id);
68  void unregisterInstance(const QString &id);
69 
70  void addTask(SearchTask *task);
71 
72  void pushResults(const QByteArray &searchId, const QSet<qint64> &ids, Connection *connection);
73 
74 private Q_SLOTS:
75  void searchLoop();
76 
77 private:
78  class ResourceTask
79  {
80  public:
81  QString resourceId;
82  qint64 collectionId;
83  SearchTask *parentTask;
84  QSet<qint64> results;
85 
86  qint64 timestamp;
87  };
88 
89  typedef QMap<QString /* resource */, ResourceTask *> TasksMap;
90 
91  bool mShouldStop;
92 
93  TasksMap::Iterator cancelRunningTask(TasksMap::Iterator &iter);
94  bool allResourceTasksCompleted(SearchTask *agentSearchTask) const;
95 
97  QMutex mInstancesLock;
98 
99  QWaitCondition mWait;
100  QMutex mLock;
101 
102  QVector<SearchTask *> mTasklist;
103 
104  QMap<QString /* resource */, ResourceTask *> mRunningTasks;
105  QVector<ResourceTask *> mPendingResults;
106 };
107 
108 AKONADI_EXCEPTION_MAKE_INSTANCE(SearchException);
109 
110 } // namespace Server
111 } // namespace Akonadi
112 
113 #endif // AKONADI_SEARCHTASKMANAGER_H
PHONON_EXPORT Notifier * notifier()
std::optional< QSqlQuery > query(const QString &queryStatement)
Returns the cached (and prepared) query for queryStatement.
Definition: querycache.cpp:108
QStringList mimeTypes(Types)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jun 2 2020 23:09:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.