Skip to content
Permalink
Browse files

qgis server: track timestamps of remote projects

  • Loading branch information
jef-n committed May 15, 2019
1 parent 5f5340a commit 3017c7a1c86020051a96b92ba06ca2c61aa71baa
@@ -9,6 +9,7 @@




class QgsCapabilitiesCache : QObject
{
%Docstring
@@ -16,12 +16,24 @@
***************************************************************************/

#include "qgscapabilitiescache.h"
#include "qgslogger.h"

#include <QCoreApplication>
#include <QFileInfo>

#if defined(Q_OS_LINUX)
#include <sys/vfs.h>
#endif

#include "qgslogger.h"


QgsCapabilitiesCache::QgsCapabilitiesCache()
{
QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged, this, &QgsCapabilitiesCache::removeChangedEntry );

#if defined(Q_OS_LINUX)
QObject::connect( &mTimer, &QTimer::timeout, this, &QgsCapabilitiesCache::removeOutdatedEntries );
#endif
}

const QDomDocument *QgsCapabilitiesCache::searchCapabilitiesDocument( const QString &configFilePath, const QString &key )
@@ -55,17 +67,46 @@ void QgsCapabilitiesCache::insertCapabilitiesDocument( const QString &configFile
}

mCachedCapabilities[ configFilePath ].insert( key, doc->cloneNode().toDocument() );

#if defined(Q_OS_LINUX)
struct statfs sStatFS;
if ( statfs( configFilePath.toUtf8().constData(), &sStatFS ) == 0 &&
( sStatFS.f_type == 0x6969 /* NFS */ ||
sStatFS.f_type == 0x517b /* SMB */ ||
sStatFS.f_type == 0xff534d42 /* CIFS */ ) )
{
QFileInfo fi( configFilePath );
mCachedCapabilitiesTimestamps[ configFilePath ] = fi.lastModified();
mTimer.start( 1000 );
}
#endif
}

void QgsCapabilitiesCache::removeCapabilitiesDocument( const QString &path )
{
mCachedCapabilities.remove( path );
mCachedCapabilitiesTimestamps.remove( path );
mFileSystemWatcher.removePath( path );
}

void QgsCapabilitiesCache::removeChangedEntry( const QString &path )
{
QgsDebugMsg( QStringLiteral( "Remove capabilities cache entry because file changed" ) );
mCachedCapabilities.remove( path );
mFileSystemWatcher.removePath( path );
removeCapabilitiesDocument( path );
}

void QgsCapabilitiesCache::removeOutdatedEntries()
{
QgsDebugMsg( QStringLiteral( "Checking for outdated entries" ) );
for ( const QString &configFilePath : mCachedCapabilitiesTimestamps.keys() )
{
QFileInfo fi( configFilePath );
if ( !fi.exists() || mCachedCapabilitiesTimestamps[ configFilePath ] < fi.lastModified() )
removeChangedEntry( configFilePath );
}

if ( !mCachedCapabilitiesTimestamps.isEmpty() )
{
mTimer.start( 1000 );
}
}
@@ -22,6 +22,9 @@
#include <QFileSystemWatcher>
#include <QHash>
#include <QObject>
#include <QDateTime>
#include <QTimer>

#include "qgis_server.h"

/**
@@ -58,11 +61,15 @@ class SERVER_EXPORT QgsCapabilitiesCache : public QObject

private:
QHash< QString, QHash< QString, QDomDocument > > mCachedCapabilities;
QHash< QString, QDateTime> mCachedCapabilitiesTimestamps;
QFileSystemWatcher mFileSystemWatcher;
QTimer mTimer;

private slots:
//! Removes changed entry from this cache
void removeChangedEntry( const QString &path );
//! Remove outdated enties
void removeOutdatedEntries();
};

#endif // QGSCAPABILITIESCACHE_H

0 comments on commit 3017c7a

Please sign in to comment.
You can’t perform that action at this time.