Akonadi

itemretrievalmanager.h
1/*
2 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akthread.h"
10#include "itemretrievalrequest.h"
11#include "itemretriever.h"
12
13#include <QHash>
14class QObject;
15#include <QReadWriteLock>
16#include <QWaitCondition>
17
18#include <unordered_map>
19
20class OrgFreedesktopAkonadiResourceInterface;
21
22namespace Akonadi
23{
24namespace Server
25{
26class Collection;
27class ItemRetrievalJob;
28class AbstractItemRetrievalJob;
29
30class AbstractItemRetrievalJobFactory
31{
32public:
33 virtual ~AbstractItemRetrievalJobFactory() = default;
34
35 virtual AbstractItemRetrievalJob *retrievalJob(ItemRetrievalRequest request, QObject *parent) = 0;
36
37protected:
38 explicit AbstractItemRetrievalJobFactory() = default;
39
40private:
41 Q_DISABLE_COPY_MOVE(AbstractItemRetrievalJobFactory)
42};
43
44/** Manages and processes item retrieval requests. */
45class ItemRetrievalManager : public AkThread
46{
48protected:
49 /**
50 * Use AkThread::create() to create and start a new ItemRetrievalManager thread.
51 */
52 explicit ItemRetrievalManager(QObject *parent = nullptr);
53 explicit ItemRetrievalManager(std::unique_ptr<AbstractItemRetrievalJobFactory> factory, QObject *parent = nullptr);
54
55public:
56 ~ItemRetrievalManager() override;
57
58 /**
59 * Added for convenience. ItemRetrievalManager takes ownership over the
60 * pointer and deletes it when the request is processed.
61 */
62 virtual void requestItemDelivery(ItemRetrievalRequest request);
63
64 void triggerCollectionSync(const QString &resource, qint64 colId);
65 void triggerCollectionTreeSync(const QString &resource);
66
68 void requestFinished(const Akonadi::Server::ItemRetrievalResult &result);
69 void requestAdded();
70
71private:
72 OrgFreedesktopAkonadiResourceInterface *resourceInterface(const QString &id);
73 QList<AbstractItemRetrievalJob *> scheduleJobsForIdleResourcesLocked();
74
75private Q_SLOTS:
76 void init() override;
77
78 void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
79 void processRequest();
80 void retrievalJobFinished(Akonadi::Server::AbstractItemRetrievalJob *job);
81
82protected:
83 std::unique_ptr<AbstractItemRetrievalJobFactory> mJobFactory;
84
85 /// Protects mPendingRequests and every Request object posted to it
87 /// Used to let requesting threads wait until the request has been processed
89
90 /// Pending requests queues, one per resource
91 std::unordered_map<QString, std::list<ItemRetrievalRequest>> mPendingRequests;
92 /// Currently running jobs, one per resource
94
95 // resource dbus interface cache
96 std::unordered_map<QString, std::unique_ptr<OrgFreedesktopAkonadiResourceInterface>> mResourceInterfaces;
97};
98
99} // namespace Server
100} // namespace Akonadi
Manages and processes item retrieval requests.
QWaitCondition mWaitCondition
Used to let requesting threads wait until the request has been processed.
QReadWriteLock mLock
Protects mPendingRequests and every Request object posted to it.
QHash< QString, AbstractItemRetrievalJob * > mCurrentJobs
Currently running jobs, one per resource.
ItemRetrievalManager(QObject *parent=nullptr)
Use AkThread::create() to create and start a new ItemRetrievalManager thread.
virtual void requestItemDelivery(ItemRetrievalRequest request)
Added for convenience.
std::unordered_map< QString, std::list< ItemRetrievalRequest > > mPendingRequests
Pending requests queues, one per resource.
Details of a single item retrieval request.
Helper integration between Akonadi and Qt.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
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.