1 /***************************************************************************
2                               qgscapabilitiescache.h
3                               ----------------------
4   begin                : May 11th, 2011
5   copyright            : (C) 2011 by Marco Hugentobler
6   email                : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef QGSCAPABILITIESCACHE_H
19 #define QGSCAPABILITIESCACHE_H
20 
21 #include <QDomDocument>
22 #include <QFileSystemWatcher>
23 #include <QHash>
24 #include <QObject>
25 #include <QDateTime>
26 #include <QTimer>
27 
28 #include "qgis_server.h"
29 
30 /**
31  * \ingroup server
32  * \brief A cache for capabilities xml documents (by configuration file path)
33  */
34 class SERVER_EXPORT QgsCapabilitiesCache : public QObject
35 {
36     Q_OBJECT
37   public:
38     QgsCapabilitiesCache();
39 
40     /**
41      * Returns cached capabilities document (or 0 if document for configuration file not in cache)
42      * \param configFilePath the progect file path
43      * \param key key used to separate different version in different cache
44      */
45     const QDomDocument *searchCapabilitiesDocument( const QString &configFilePath, const QString &key );
46 
47     /**
48      * Inserts new capabilities document (creates a copy of the document, does not take ownership)
49      * \param configFilePath the project file path
50      * \param key key used to separate different version in different cache
51      * \param doc the DOM document
52      */
53     void insertCapabilitiesDocument( const QString &configFilePath, const QString &key, const QDomDocument *doc );
54 
55     /**
56      * Remove capabilities document
57      * \param path the project file path
58      * \since QGIS 2.16
59      */
60     void removeCapabilitiesDocument( const QString &path );
61 
62   private:
63     QHash< QString, QHash< QString, QDomDocument > > mCachedCapabilities;
64     QHash< QString, QDateTime> mCachedCapabilitiesTimestamps;
65     QFileSystemWatcher mFileSystemWatcher;
66     QTimer mTimer;
67 
68   private slots:
69     //! Removes changed entry from this cache
70     void removeChangedEntry( const QString &path );
71     //! Remove outdated enties
72     void removeOutdatedEntries();
73 };
74 
75 #endif // QGSCAPABILITIESCACHE_H
76