1/*
2 Copyright (c) 2014 Daniel Vrátil <dvratil@redhat.com>
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 <QTimer>
25#include <QMultiMap>
26#include <QMutex>
27
28#include "entities.h"
29
30namespace Akonadi {
31namespace Server {
32
33class Collection;
34class PauseableTimer;
35
36class CollectionScheduler : public QThread
37{
38 Q_OBJECT
39
40public:
41 CollectionScheduler(QObject *parent = 0);
42 virtual ~CollectionScheduler();
43
44 void collectionChanged(qint64 collectionId);
45 void collectionRemoved(qint64 collectionId);
46 void collectionAdded(qint64 collectionId);
47
48 /**
49 * Sets the minimum timeout interval.
50 *
51 * Default value is 5.
52 *
53 * @p intervalMinutes Minimum timeout interval in minutes.
54 */
55 void setMinimumInterval(int intervalMinutes);
56 int minimumInterval() const;
57
58protected:
59 virtual void run();
60
61 virtual bool shouldScheduleCollection(const Collection &collection) = 0;
62 virtual bool hasChanged(const Collection &collection, const Collection &changed) = 0;
63 /**
64 * @return Return cache timeout in minutes
65 */
66 virtual int collectionScheduleInterval(const Collection &collection) = 0;
67 virtual void collectionExpired(const Collection &collection) = 0;
68
69 void inhibit(bool inhibit = true);
70
71protected Q_SLOTS:
72 void initScheduler();
73 void schedulerTimeout();
74 void startScheduler();
75 void scheduleCollection(/*sic!*/ Collection collection, bool shouldStartScheduler = true);
76
77protected:
78 QMutex mScheduleLock;
79 QMultiMap<uint /*timestamp*/, Collection> mSchedule;
80 PauseableTimer *mScheduler;
81 int mMinInterval;
82};
83
84} // namespace Server
85} // namespace Akonadi
86
87#endif // AKONADI_SERVER_COLLECTIONSCHEDULER_H
88