Akonadi

collectionscheduler.h
1 /*
2  Copyright (c) 2014 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #ifndef AKONADI_SERVER_COLLECTIONSCHEDULER_H
21 #define AKONADI_SERVER_COLLECTIONSCHEDULER_H
22 
23 #include <QThread>
24 #include <QMultiMap>
25 #include <QMutex>
26 
27 #include "entities.h"
28 #include "akthread.h"
29 
30 namespace Akonadi
31 {
32 namespace Server
33 {
34 
35 class Collection;
36 class PauseableTimer;
37 
38 class CollectionScheduler : public AkThread
39 {
40  Q_OBJECT
41 
42 public:
43  explicit CollectionScheduler(const QString &threadName, QThread::Priority priority, QObject *parent = nullptr);
44  ~CollectionScheduler() override;
45 
46  void collectionChanged(qint64 collectionId);
47  void collectionRemoved(qint64 collectionId);
48  void collectionAdded(qint64 collectionId);
49 
57  void setMinimumInterval(int intervalMinutes);
58  Q_REQUIRED_RESULT int minimumInterval() const;
59 
60  using TimePoint = std::chrono::steady_clock::time_point;
61 
67  TimePoint nextScheduledTime(qint64 collectionId) const;
68 
72  std::chrono::milliseconds currentTimerInterval() const;
73 
74 protected:
75  void init() override;
76  void quit() override;
77 
78  virtual bool shouldScheduleCollection(const Collection &collection) = 0;
79  virtual bool hasChanged(const Collection &collection, const Collection &changed) = 0;
83  virtual int collectionScheduleInterval(const Collection &collection) = 0;
88  virtual void collectionExpired(const Collection &collection) = 0;
89 
90  void inhibit(bool inhibit = true);
91 
92 private Q_SLOTS:
93  void schedulerTimeout();
94  void startScheduler();
95  void scheduleCollection(/*sic!*/ Akonadi::Server::Collection collection, bool shouldStartScheduler = true);
96 
97 private:
98  using ScheduleMap = QMultiMap<TimePoint /*timestamp*/, Collection>;
99  ScheduleMap::const_iterator constFind(qint64 collectionId) const;
100  ScheduleMap::iterator find(qint64 collectionId);
101  ScheduleMap::const_iterator constLowerBound(TimePoint timestamp) const;
102 
103  mutable QMutex mScheduleLock;
104  ScheduleMap mSchedule;
105  PauseableTimer *mScheduler = nullptr;
106  int mMinInterval = 5;
107 };
108 
109 } // namespace Server
110 } // namespace Akonadi
111 
112 #endif // AKONADI_SERVER_COLLECTIONSCHEDULER_H
StandardShortcut find(const QKeySequence &keySeq)
Q_OBJECTQ_OBJECT
QCA_EXPORT void init()
KDEGAMES_EXPORT QAction * quit(const QObject *recvr, const char *slot, QObject *parent)
Helper integration between Akonadi and Qt.
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.