Akonadi

cachecleaner.h
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "collectionscheduler.h"
10 
11 #include <QMutex>
12 
13 namespace Akonadi
14 {
15 namespace Server
16 {
17 class Collection;
18 class CacheCleaner;
19 class AkonadiServer;
20 
21 /**
22  * A RAII helper class to temporarily stop the CacheCleaner. This allows long-lasting
23  * operations to safely retrieve all data from resource and perform an operation on them
24  * (like move or copy) without risking that the cache will be cleaned in the meanwhile
25  *
26  * The inhibitor is recursive, so it's possible to create multiple instances of the
27  * CacheCleanerInhibitor and the CacheCleaner will be inhibited until all instances
28  * are destroyed again. However it's not possible to inhibit a single inhibitor
29  * multiple times.
30  */
32 {
33 public:
34  explicit CacheCleanerInhibitor(AkonadiServer &akonadi, bool inhibit = true);
36 
37  void inhibit();
38  void uninhibit();
39 
40 private:
41  Q_DISABLE_COPY(CacheCleanerInhibitor)
42  static QMutex sLock;
43  static int sInhibitCount;
44 
45  CacheCleaner *mCleaner = nullptr;
46  bool mInhibited = false;
47 };
48 
49 /**
50  Cache cleaner.
51  */
52 class CacheCleaner : public CollectionScheduler
53 {
54  Q_OBJECT
55 
56 public:
57  /**
58  Creates a new cache cleaner thread.
59  @param parent The parent object.
60  */
61  explicit CacheCleaner(QObject *parent = nullptr);
62  ~CacheCleaner() override;
63 
64 protected:
65  void collectionExpired(const Collection &collection) override;
66  int collectionScheduleInterval(const Collection &collection) override;
67  bool hasChanged(const Collection &collection, const Collection &changed) override;
68  bool shouldScheduleCollection(const Collection &collection) override;
69 
70 private:
71  friend class CacheCleanerInhibitor;
72 };
73 
74 } // namespace Server
75 } // namespace Akonadi
76 
Q_OBJECTQ_OBJECT
CacheCleaner(QObject *parent=nullptr)
Creates a new cache cleaner thread.
Represents a collection of PIM items.
Definition: collection.h:61
A RAII helper class to temporarily stop the CacheCleaner.
Definition: cachecleaner.h:31
QObject * parent() const const
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:01:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.