20#include <QCoreApplication>
23#if defined(Q_OS_LINUX)
34 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsCapabilitiesCache::removeChangedEntry );
36#if defined(Q_OS_LINUX)
37 QObject::connect( &mTimer, &QTimer::timeout,
this, &QgsCapabilitiesCache::removeOutdatedEntries );
43 QCoreApplication::processEvents();
45 if ( mCachedCapabilities.contains( configFilePath ) && mCachedCapabilities[ configFilePath ].contains( key ) )
47 return &mCachedCapabilities[ configFilePath ][ key ];
57 if ( mCachedCapabilities.size() > mCacheSize )
60 const QHash<QString, QHash<QString, QDomDocument> >::iterator capIt = mCachedCapabilities.begin();
61 mFileSystemWatcher.removePath( capIt.key() );
62 mCachedCapabilities.erase( capIt );
64 QgsMessageLog::logMessage( QStringLiteral(
"Removed cached WMS capabilities document because all %1 cache slots were taken" ).arg( mCacheSize ), QStringLiteral(
"Server" ) );
67 if ( !mCachedCapabilities.contains( configFilePath ) )
69 mFileSystemWatcher.addPath( configFilePath );
70 mCachedCapabilities.insert( configFilePath, QHash<QString, QDomDocument>() );
73 mCachedCapabilities[ configFilePath ].insert( key, doc->cloneNode().toDocument() );
75#if defined(Q_OS_LINUX)
76 struct statfs sStatFS;
77 if ( statfs( configFilePath.toUtf8().constData(), &sStatFS ) == 0 &&
78 ( sStatFS.f_type == 0x6969 ||
79 sStatFS.f_type == 0x517b ||
80 sStatFS.f_type == 0xff534d42ul ||
81 sStatFS.f_type == 0xfe534d42ul ) )
83 const QFileInfo fi( configFilePath );
84 mCachedCapabilitiesTimestamps[ configFilePath ] = fi.lastModified();
92 mCachedCapabilities.remove( path );
93 mCachedCapabilitiesTimestamps.remove( path );
94 mFileSystemWatcher.removePath( path );
97void QgsCapabilitiesCache::removeChangedEntry(
const QString &path )
99 QgsDebugMsgLevel( QStringLiteral(
"Remove capabilities cache entry because file changed" ), 2 );
103void QgsCapabilitiesCache::removeOutdatedEntries()
106 for (
auto it = mCachedCapabilitiesTimestamps.constBegin(); it != mCachedCapabilitiesTimestamps.constEnd(); it++ )
108 const QString configFilePath = it.key();
109 const QFileInfo fi( configFilePath );
110 if ( !fi.exists() || it.value() < fi.lastModified() )
111 removeChangedEntry( configFilePath );
114 if ( !mCachedCapabilitiesTimestamps.isEmpty() )
116 mTimer.start( 1000 );
void removeCapabilitiesDocument(const QString &path)
Remove 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)