Skip to content

Commit

Permalink
[FEATURE]: use file watcher in wms server to check for updates in pro…
Browse files Browse the repository at this point in the history
…ject files
  • Loading branch information
mhugent committed May 13, 2011
1 parent 07da493 commit d4109ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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
qgsconfigcache.h
)

SET (qgis_mapserv_RCCS
Expand Down
23 changes: 22 additions & 1 deletion src/mapserver/qgsconfigcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}
11 changes: 10 additions & 1 deletion src/mapserver/qgsconfigcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.