Akonadi

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

KDE's Doxygen guidelines are available online.