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 #pragma once
8 
9 #include "akthread.h"
10 
11 #include "agentmanagerinterface.h"
12 #include "exception.h"
13 #include <QMap>
14 #include <QMutex>
15 #include <QSet>
16 #include <QStringList>
17 #include <QVector>
18 #include <QWaitCondition>
19 
20 namespace Akonadi
21 {
22 namespace Server
23 {
24 class Connection;
25 class AgentSearchInstance;
26 
27 class SearchTask
28 {
29 public:
30  QByteArray id;
31  QString query;
33  QVector<qint64> collections;
34  bool complete;
35 
36  QMutex sharedLock;
38 
39  QVector<QPair<QString /* resource */, qint64 /* collection */>> queries;
40  QSet<qint64> pendingResults;
41 };
42 
43 class SearchTaskManager : public AkThread
44 {
45  Q_OBJECT
46 
47 public:
48  explicit SearchTaskManager();
49  ~SearchTaskManager() override;
50 
51  void registerInstance(const QString &id);
52  void unregisterInstance(const QString &id);
53 
54  void addTask(SearchTask *task);
55 
56  void pushResults(const QByteArray &searchId, const QSet<qint64> &ids, Connection *connection);
57 
58 private Q_SLOTS:
59  void searchLoop();
60 
61 private:
62  class ResourceTask
63  {
64  public:
65  QString resourceId;
66  qint64 collectionId;
67  SearchTask *parentTask;
68  QSet<qint64> results;
69 
70  qint64 timestamp;
71  };
72 
73  using TasksMap = QMap<QString, ResourceTask *>;
74 
75  bool mShouldStop;
76 
77  TasksMap::Iterator cancelRunningTask(TasksMap::Iterator &iter);
78  bool allResourceTasksCompleted(SearchTask *agentSearchTask) const;
79 
81  QMutex mInstancesLock;
82 
83  QWaitCondition mWait;
84  QMutex mLock;
85 
86  QVector<SearchTask *> mTasklist;
87 
88  QMap<QString /* resource */, ResourceTask *> mRunningTasks;
89  QVector<ResourceTask *> mPendingResults;
90 };
91 
92 AKONADI_EXCEPTION_MAKE_INSTANCE(SearchException);
93 
94 } // namespace Server
95 } // namespace Akonadi
96 
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
PHONON_EXPORT Notifier * notifier()
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
QStringList mimeTypes(Mode mode=Writing)
typedef Iterator
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.