Skip to content

Commit

Permalink
Use a file watcher also for capabilities cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed May 13, 2011
1 parent d4109ce commit 5579560
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/mapserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ SET ( qgis_mapserv_SRCS

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

Expand Down
17 changes: 17 additions & 0 deletions src/mapserver/qgscapabilitiescache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() )
{
Expand All @@ -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 );
}
10 changes: 9 additions & 1 deletion src/mapserver/qgscapabilitiescache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.