19#include "moc_qgscapabilitiescache.cpp"
21#include <QCoreApplication>
24#if defined(Q_OS_LINUX)
35 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsCapabilitiesCache::removeChangedEntry );
37#if defined(Q_OS_LINUX)
38 QObject::connect( &mTimer, &QTimer::timeout,
this, &QgsCapabilitiesCache::removeOutdatedEntries );
44 QCoreApplication::processEvents();
46 if ( mCachedCapabilities.contains( configFilePath ) && mCachedCapabilities[ configFilePath ].contains( key ) )
48 return &mCachedCapabilities[ configFilePath ][ key ];
58 if ( mCachedCapabilities.size() > mCacheSize )
61 const QHash<QString, QHash<QString, QDomDocument> >::iterator capIt = mCachedCapabilities.begin();
62 mFileSystemWatcher.removePath( capIt.key() );
63 mCachedCapabilities.erase( capIt );
65 QgsMessageLog::logMessage( QStringLiteral(
"Removed cached WMS capabilities document because all %1 cache slots were taken" ).arg( mCacheSize ), QStringLiteral(
"Server" ) );
68 if ( !mCachedCapabilities.contains( configFilePath ) )
70 mFileSystemWatcher.addPath( configFilePath );
71 mCachedCapabilities.insert( configFilePath, QHash<QString, QDomDocument>() );
74 mCachedCapabilities[ configFilePath ].insert( key, doc->cloneNode().toDocument() );
76#if defined(Q_OS_LINUX)
77 struct statfs sStatFS;
78 if ( statfs( configFilePath.toUtf8().constData(), &sStatFS ) == 0 &&
79 ( sStatFS.f_type == 0x6969 ||
80 sStatFS.f_type == 0x517b ||
81 sStatFS.f_type == 0xff534d42ul ||
82 sStatFS.f_type == 0xfe534d42ul ) )
84 const QFileInfo fi( configFilePath );
85 mCachedCapabilitiesTimestamps[ configFilePath ] = fi.lastModified();
93 mCachedCapabilities.remove( path );
94 mCachedCapabilitiesTimestamps.remove( path );
95 mFileSystemWatcher.removePath( path );
98void QgsCapabilitiesCache::removeChangedEntry(
const QString &path )
100 QgsDebugMsgLevel( QStringLiteral(
"Remove capabilities cache entry because file changed" ), 2 );
104void QgsCapabilitiesCache::removeOutdatedEntries()
107 for (
auto it = mCachedCapabilitiesTimestamps.constBegin(); it != mCachedCapabilitiesTimestamps.constEnd(); it++ )
109 const QString configFilePath = it.key();
110 const QFileInfo fi( configFilePath );
111 if ( !fi.exists() || it.value() < fi.lastModified() )
112 removeChangedEntry( configFilePath );
115 if ( !mCachedCapabilitiesTimestamps.isEmpty() )
117 mTimer.start( 1000 );
void removeCapabilitiesDocument(const QString &path)
Removes capabilities document.
const QDomDocument * searchCapabilitiesDocument(const QString &configFilePath, const QString &key)
Returns cached capabilities document (or 0 if document for configuration file not in cache)
QgsCapabilitiesCache(int size)
void insertCapabilitiesDocument(const QString &configFilePath, const QString &key, const QDomDocument *doc)
Inserts new capabilities document (creates a copy of the document, does not take ownership)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
#define QgsDebugMsgLevel(str, level)