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#include "shared/akstd.h"
13
14#include <QHash>
15class QObject;
16#include <QReadWriteLock>
17#include <QWaitCondition>
18
19#include <unordered_map>
20
21class OrgFreedesktopAkonadiResourceInterface;
22
23namespace Akonadi
24{
25namespace Server
26{
27class Collection;
28class ItemRetrievalJob;
29class AbstractItemRetrievalJob;
30
31class AbstractItemRetrievalJobFactory
32{
33public:
34 virtual ~AbstractItemRetrievalJobFactory() = default;
35
36 virtual AbstractItemRetrievalJob *retrievalJob(ItemRetrievalRequest request, QObject *parent) = 0;
37
38protected:
39 explicit AbstractItemRetrievalJobFactory() = default;
40
41private:
42 Q_DISABLE_COPY_MOVE(AbstractItemRetrievalJobFactory)
43};
44
45/** Manages and processes item retrieval requests. */
46class ItemRetrievalManager : public AkThread
47{
49protected:
50 /**
51 * Use AkThread::create() to create and start a new ItemRetrievalManager thread.
52 */
53 explicit ItemRetrievalManager(QObject *parent = nullptr);
54 explicit ItemRetrievalManager(std::unique_ptr<AbstractItemRetrievalJobFactory> factory, QObject *parent = nullptr);
55
56public:
57 ~ItemRetrievalManager() override;
58
59 /**
60 * Added for convenience. ItemRetrievalManager takes ownership over the
61 * pointer and deletes it when the request is processed.
62 */
63 virtual void requestItemDelivery(ItemRetrievalRequest request);
64
65 void triggerCollectionSync(const QString &resource, qint64 colId);
66 void triggerCollectionTreeSync(const QString &resource);
67
69 void requestFinished(const Akonadi::Server::ItemRetrievalResult &result);
70 void requestAdded();
71
72private:
73 OrgFreedesktopAkonadiResourceInterface *resourceInterface(const QString &id);
74 QList<AbstractItemRetrievalJob *> scheduleJobsForIdleResourcesLocked();
75
76private Q_SLOTS:
77 void init() override;
78
79 void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
80 void processRequest();
81 void retrievalJobFinished(Akonadi::Server::AbstractItemRetrievalJob *job);
82
83protected:
84 std::unique_ptr<AbstractItemRetrievalJobFactory> mJobFactory;
85
86 /// Protects mPendingRequests and every Request object posted to it
88 /// Used to let requesting threads wait until the request has been processed
90
91 /// Pending requests queues, one per resource
92 std::unordered_map<QString, std::list<ItemRetrievalRequest>> mPendingRequests;
93 /// Currently running jobs, one per resource
95
96 // resource dbus interface cache
97 std::unordered_map<QString, std::unique_ptr<OrgFreedesktopAkonadiResourceInterface>> mResourceInterfaces;
98};
99
100} // namespace Server
101} // 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
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 11:57:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.