Skip to content
Permalink
Browse files

Merge branch 'wms_filewatch'

  • Loading branch information
mhugent committed May 13, 2011
2 parents 6327b2e + 5579560 commit 3ec80591413fed4126f6cd3416897805c909d3c8
@@ -62,6 +62,8 @@ SET ( qgis_mapserv_SRCS

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

SET (qgis_mapserv_RCCS
@@ -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
@@ -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 3ec8059

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