Akonadi

collectionscheduler.h
1/*
2 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QMultiMap>
10#include <QMutex>
11#include <QThread>
12
13#include "akthread.h"
14#include "entities.h"
15
16namespace Akonadi
17{
18namespace Server
19{
20class Collection;
21class PauseableTimer;
22
23class CollectionScheduler : public AkThread
24{
26
27protected:
28 explicit CollectionScheduler(const QString &threadName, QThread::Priority priority, QObject *parent = nullptr);
29
30public:
31 ~CollectionScheduler() override;
32
33 void collectionChanged(qint64 collectionId);
34 void collectionRemoved(qint64 collectionId);
35 void collectionAdded(qint64 collectionId);
36
37 /**
38 * Sets the minimum timeout interval.
39 *
40 * Default value is 5.
41 *
42 * @p intervalMinutes Minimum timeout interval in minutes.
43 */
44 void setMinimumInterval(int intervalMinutes);
45 [[nodiscard]] int minimumInterval() const;
46
47 using TimePoint = std::chrono::steady_clock::time_point;
48
49 /**
50 * @return the timestamp (in seconds since epoch) when collectionExpired
51 * will next be called on the given collection, or 0 if we don't know about the collection.
52 * Only used by the unittest.
53 */
54 TimePoint nextScheduledTime(qint64 collectionId) const;
55
56 /**
57 * @return the next timeout
58 */
59 std::chrono::milliseconds currentTimerInterval() const;
60
61protected:
62 void init() override;
63 void quit() override;
64
65 virtual bool shouldScheduleCollection(const Collection &collection) = 0;
66 virtual bool hasChanged(const Collection &collection, const Collection &changed) = 0;
67 /**
68 * @return Return cache timeout in minutes
69 */
70 virtual int collectionScheduleInterval(const Collection &collection) = 0;
71 /**
72 * Called when it's time to do something on that collection.
73 * Notice: this method is called in the secondary thread
74 */
75 virtual void collectionExpired(const Collection &collection) = 0;
76
77 void inhibit(bool inhibit = true);
78
79private Q_SLOTS:
80 void schedulerTimeout();
81 void startScheduler();
82 void scheduleCollection(/*sic!*/ Akonadi::Server::Collection collection, bool shouldStartScheduler = true);
83
84private:
85 using ScheduleMap = QMultiMap<TimePoint /*timestamp*/, Collection>;
86 ScheduleMap::const_iterator constFind(qint64 collectionId) const;
87 ScheduleMap::iterator find(qint64 collectionId);
88 ScheduleMap::const_iterator constLowerBound(TimePoint timestamp) const;
89
90 mutable QMutex mScheduleLock;
91 ScheduleMap mSchedule;
92 PauseableTimer *mScheduler = nullptr;
93 int mMinInterval = 5;
94};
95
96} // namespace Server
97} // namespace Akonadi
Helper integration between Akonadi and Qt.
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:58:37 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.