Skip to content

Commit d4109ce

Browse files
committedMay 13, 2011
[FEATURE]: use file watcher in wms server to check for updates in project files
1 parent 07da493 commit d4109ce

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed
 

‎src/mapserver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ SET ( qgis_mapserv_SRCS
6262

6363
SET (qgis_mapserv_MOC_HDRS
6464
qgsftptransaction.h
65+
qgsconfigcache.h
6566
)
6667

6768
SET (qgis_mapserv_RCCS

‎src/mapserver/qgsconfigcache.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
#include "qgsmslayercache.h"
2121
#include "qgsprojectparser.h"
2222
#include "qgssldparser.h"
23+
#include <QCoreApplication>
2324

2425
QgsConfigCache::QgsConfigCache()
2526
{
27+
QObject::connect( &mFileSystemWatcher, SIGNAL( fileChanged( const QString& ) ), this, SLOT( removeChangedEntry( const QString& ) ) );
2628
}
2729

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

3739
QgsConfigParser* QgsConfigCache::searchConfiguration( const QString& filePath )
3840
{
41+
QCoreApplication::processEvents(); //check for updates from file system watcher
3942
QgsConfigParser* p = 0;
4043
QHash<QString, QgsConfigParser*>::const_iterator configIt = mCachedConfigurations.find( filePath );
4144
if ( configIt == mCachedConfigurations.constEnd() )
@@ -63,7 +66,12 @@ QgsConfigParser* QgsConfigCache::insertConfiguration( const QString& filePath )
6366
{
6467
//remove a cache entry to avoid memory problems
6568
QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations.begin();
66-
mCachedConfigurations.erase( configIt );
69+
if ( configIt != mCachedConfigurations.end() )
70+
{
71+
mFileSystemWatcher.removePath( configIt.key() );
72+
delete configIt.value();
73+
mCachedConfigurations.erase( configIt );
74+
}
6775
}
6876

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

109117
mCachedConfigurations.insert( filePath, configParser );
118+
mFileSystemWatcher.addPath( filePath );
110119
delete configFile;
111120
return configParser;
112121
}
122+
123+
void QgsConfigCache::removeChangedEntry( const QString& path )
124+
{
125+
QgsMSDebugMsg( "Remove config cache entry because file changed" );
126+
QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations.find( path );
127+
if ( configIt != mCachedConfigurations.end() )
128+
{
129+
delete configIt.value();
130+
mCachedConfigurations.erase( configIt );
131+
}
132+
mFileSystemWatcher.removePath( path );
133+
}

‎src/mapserver/qgsconfigcache.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
#ifndef QGSCONFIGCACHE_H
1919
#define QGSCONFIGCACHE_H
2020

21+
#include <QFileSystemWatcher>
2122
#include <QHash>
23+
#include <QObject>
2224
#include <QString>
2325

2426
class QgsConfigParser;
2527

2628
/**A cache for configuration XML (useful because of the mapfile parameter)*/
27-
class QgsConfigCache
29+
class QgsConfigCache: public QObject
2830
{
31+
Q_OBJECT
2932
public:
3033
QgsConfigCache();
3134
~QgsConfigCache();
@@ -40,6 +43,12 @@ class QgsConfigCache
4043
QgsConfigParser* insertConfiguration( const QString& filePath );
4144
/**Cached XML configuration documents. Key: file path, value: config parser. Default configuration has key '$default$'*/
4245
QHash<QString, QgsConfigParser*> mCachedConfigurations;
46+
/**Check for configuration file updates (remove entry from cache if file changes)*/
47+
QFileSystemWatcher mFileSystemWatcher;
48+
49+
private slots:
50+
/**Removes changed entry from this cache*/
51+
void removeChangedEntry( const QString& path );
4352
};
4453

4554
#endif // QGSCONFIGCACHE_H

0 commit comments

Comments
 (0)
Please sign in to comment.