Skip to content
Permalink
Browse files

Use a file watcher also for capabilities cache

  • Loading branch information
mhugent committed May 13, 2011
1 parent d4109ce commit 55795600db8f76365ebd7b1202467608dd544f18
Showing with 27 additions and 1 deletion.
  1. +1 −0 src/mapserver/CMakeLists.txt
  2. +17 −0 src/mapserver/qgscapabilitiescache.cpp
  3. +9 −1 src/mapserver/qgscapabilitiescache.h
@@ -62,6 +62,7 @@ SET ( qgis_mapserv_SRCS

SET (qgis_mapserv_MOC_HDRS
qgsftptransaction.h
qgscapabilitiescache.h
qgsconfigcache.h
)

@@ -16,9 +16,12 @@
***************************************************************************/

#include "qgscapabilitiescache.h"
#include "qgsmapserverlogger.h"
#include <QCoreApplication>

QgsCapabilitiesCache::QgsCapabilitiesCache()
{
QObject::connect( &mFileSystemWatcher, SIGNAL( fileChanged( const QString& ) ), this, SLOT( removeChangedEntry( const QString& ) ) );
}

QgsCapabilitiesCache::~QgsCapabilitiesCache()
@@ -27,6 +30,7 @@ QgsCapabilitiesCache::~QgsCapabilitiesCache()

const QDomDocument* QgsCapabilitiesCache::searchCapabilitiesDocument( const QString& configFilePath ) const
{
QCoreApplication::processEvents(); //get updates from file system watcher
QHash< QString, QDomDocument >::const_iterator it = mCachedCapabilities.find( configFilePath );
if( it == mCachedCapabilities.constEnd() )
{
@@ -44,7 +48,20 @@ void QgsCapabilitiesCache::insertCapabilitiesDocument( const QString& configFile
{
//remove another cache entry to avoid memory problems
QHash<QString, QDomDocument>::iterator capIt = mCachedCapabilities.begin();
mFileSystemWatcher.removePath( capIt.key() );
mCachedCapabilities.erase( capIt );
}
mCachedCapabilities.insert( configFilePath, doc->cloneNode().toDocument() );
mFileSystemWatcher.addPath( configFilePath );
}

void QgsCapabilitiesCache::removeChangedEntry( const QString& path )
{
QgsMSDebugMsg( "Remove capabilities cache entry because file changed" );
QHash< QString, QDomDocument >::iterator it = mCachedCapabilities.find( path );
if( it != mCachedCapabilities.end() )
{
mCachedCapabilities.erase( it );
}
mFileSystemWatcher.removePath( path );
}
@@ -19,11 +19,14 @@
#define QGSCAPABILITIESCACHE_H

#include <QDomDocument>
#include <QFileSystemWatcher>
#include <QHash>
#include <QObject>

/**A cache for capabilities xml documents (by configuration file path)*/
class QgsCapabilitiesCache
class QgsCapabilitiesCache: public QObject
{
Q_OBJECT
public:
QgsCapabilitiesCache();
~QgsCapabilitiesCache();
@@ -35,6 +38,11 @@ class QgsCapabilitiesCache

private:
QHash< QString, QDomDocument > mCachedCapabilities;
QFileSystemWatcher mFileSystemWatcher;

private slots:
/**Removes changed entry from this cache*/
void removeChangedEntry( const QString& path );
};

#endif // QGSCAPABILITIESCACHE_H

0 comments on commit 5579560

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