Skip to content
Permalink
Browse files

[FEATURE]: use file watcher in wms server to check for updates in pro…

…ject files
  • Loading branch information
mhugent committed May 13, 2011
1 parent 07da493 commit d4109ce2dcec3d1e65b97e4aae5af94f2166e5aa
Showing with 33 additions and 2 deletions.
  1. +1 −0 src/mapserver/CMakeLists.txt
  2. +22 −1 src/mapserver/qgsconfigcache.cpp
  3. +10 −1 src/mapserver/qgsconfigcache.h
@@ -62,6 +62,7 @@ SET ( qgis_mapserv_SRCS

SET (qgis_mapserv_MOC_HDRS
qgsftptransaction.h
qgsconfigcache.h
)

SET (qgis_mapserv_RCCS
@@ -20,9 +20,11 @@
#include "qgsmslayercache.h"
#include "qgsprojectparser.h"
#include "qgssldparser.h"
#include <QCoreApplication>

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

QgsConfigCache::~QgsConfigCache()
@@ -36,6 +38,7 @@ QgsConfigCache::~QgsConfigCache()

QgsConfigParser* QgsConfigCache::searchConfiguration( const QString& filePath )
{
QCoreApplication::processEvents(); //check for updates from file system watcher
QgsConfigParser* p = 0;
QHash<QString, QgsConfigParser*>::const_iterator configIt = mCachedConfigurations.find( filePath );
if ( configIt == mCachedConfigurations.constEnd() )
@@ -63,7 +66,12 @@ QgsConfigParser* QgsConfigCache::insertConfiguration( const QString& filePath )
{
//remove a cache entry to avoid memory problems
QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations.begin();
mCachedConfigurations.erase( configIt );
if ( configIt != mCachedConfigurations.end() )
{
mFileSystemWatcher.removePath( configIt.key() );
delete configIt.value();
mCachedConfigurations.erase( configIt );
}
}

//first open file
@@ -107,6 +115,19 @@ QgsConfigParser* QgsConfigCache::insertConfiguration( const QString& filePath )
}

mCachedConfigurations.insert( filePath, configParser );
mFileSystemWatcher.addPath( filePath );
delete configFile;
return configParser;
}

void QgsConfigCache::removeChangedEntry( const QString& path )
{
QgsMSDebugMsg( "Remove config cache entry because file changed" );
QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations.find( path );
if ( configIt != mCachedConfigurations.end() )
{
delete configIt.value();
mCachedConfigurations.erase( configIt );
}
mFileSystemWatcher.removePath( path );
}
@@ -18,14 +18,17 @@
#ifndef QGSCONFIGCACHE_H
#define QGSCONFIGCACHE_H

#include <QFileSystemWatcher>
#include <QHash>
#include <QObject>
#include <QString>

class QgsConfigParser;

/**A cache for configuration XML (useful because of the mapfile parameter)*/
class QgsConfigCache
class QgsConfigCache: public QObject
{
Q_OBJECT
public:
QgsConfigCache();
~QgsConfigCache();
@@ -40,6 +43,12 @@ class QgsConfigCache
QgsConfigParser* insertConfiguration( const QString& filePath );
/**Cached XML configuration documents. Key: file path, value: config parser. Default configuration has key '$default$'*/
QHash<QString, QgsConfigParser*> mCachedConfigurations;
/**Check for configuration file updates (remove entry from cache if file changes)*/
QFileSystemWatcher mFileSystemWatcher;

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

#endif // QGSCONFIGCACHE_H

0 comments on commit d4109ce

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