Skip to content

Commit

Permalink
Merge pull request #1689 from rldhont/server_cache_project_config
Browse files Browse the repository at this point in the history
[QGIS-Server] Enhance config cache
  • Loading branch information
mhugent committed Nov 21, 2014
2 parents 6c836f0 + d663599 commit 7de1dff
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 162 deletions.
39 changes: 25 additions & 14 deletions src/mapserver/qgsconfigcache.cpp
Expand Up @@ -43,6 +43,10 @@ QgsConfigCache::~QgsConfigCache()
QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
return new QgsServerProjectParser( doc, filePath );
}

Expand All @@ -56,7 +60,7 @@ QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
return 0;
}
p = new QgsWCSProjectParser( doc, filePath );
p = new QgsWCSProjectParser( filePath );
mWCSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
Expand All @@ -75,8 +79,7 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
{
return 0;
}

p = new QgsWFSProjectParser( doc, filePath );
p = new QgsWFSProjectParser( filePath );
mWFSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
Expand Down Expand Up @@ -105,7 +108,7 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c
}
else
{
p = new QgsWMSProjectParser( doc, filePath );
p = new QgsWMSProjectParser( filePath );
}
mWMSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
Expand All @@ -130,23 +133,31 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
QgsMessageLog::logMessage( "Error, cannot open configuration file '" + filePath + "'", "Server", QgsMessageLog::CRITICAL );
return 0;
}

//then create xml document
QDomDocument* xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )

// first get cache
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
if ( !xmlDoc )
{
QgsMessageLog::logMessage( "Error parsing file '" + filePath +
QString( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), "Server", QgsMessageLog::CRITICAL );
delete xmlDoc;
return 0;
//then create xml document
xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
{
QgsMessageLog::logMessage( "Error parsing file '" + filePath +
QString( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), "Server", QgsMessageLog::CRITICAL );
delete xmlDoc;
return 0;
}
mXmlDocumentCache.insert( filePath, xmlDoc );
mFileSystemWatcher.addPath( filePath );
}
return xmlDoc;
}

void QgsConfigCache::removeChangedEntry( const QString& path )
{
mXmlDocumentCache.remove( path );
mWMSConfigCache.remove( path );
mWFSConfigCache.remove( path );
mWCSConfigCache.remove( path );
Expand Down
1 change: 1 addition & 0 deletions src/mapserver/qgsconfigcache.h
Expand Up @@ -52,6 +52,7 @@ class QgsConfigCache: public QObject
/**Returns xml document for project file / sld or 0 in case of errors*/
QDomDocument* xmlDocument( const QString& filePath );

QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;
Expand Down
29 changes: 16 additions & 13 deletions src/mapserver/qgswcsprojectparser.cpp
Expand Up @@ -16,11 +16,14 @@
***************************************************************************/

#include "qgswcsprojectparser.h"
#include "qgsconfigcache.h"
#include "qgsconfigparserutils.h"
#include "qgsconfigcache.h"
#include "qgsrasterlayer.h"

QgsWCSProjectParser::QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath ): mProjectParser( xmlDoc, filePath )
QgsWCSProjectParser::QgsWCSProjectParser( const QString& filePath )
{
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

QgsWCSProjectParser::~QgsWCSProjectParser()
Expand All @@ -29,19 +32,19 @@ QgsWCSProjectParser::~QgsWCSProjectParser()

void QgsWCSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
mProjectParser.serviceCapabilities( parentElement, doc, "WCS" );
mProjectParser->serviceCapabilities( parentElement, doc, "WCS" );
}

QString QgsWCSProjectParser::wcsServiceUrl() const
{
QString url;

if ( !mProjectParser.xmlDocument() )
if ( !mProjectParser->xmlDocument() )
{
return url;
}

QDomElement propertiesElem = mProjectParser.propertiesElem();
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( !propertiesElem.isNull() )
{
QDomElement wcsUrlElem = propertiesElem.firstChildElement( "WCSUrl" );
Expand All @@ -55,12 +58,12 @@ QString QgsWCSProjectParser::wcsServiceUrl() const

QString QgsWCSProjectParser::serviceUrl() const
{
return mProjectParser.serviceUrl();
return mProjectParser->serviceUrl();
}

void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
Expand All @@ -75,7 +78,7 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( layer && wcsLayersId.contains( layer->id() ) )
{
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
Expand Down Expand Up @@ -137,12 +140,12 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
QStringList QgsWCSProjectParser::wcsLayers() const
{
QStringList wcsList;
if ( !mProjectParser.xmlDocument() )
if ( !mProjectParser->xmlDocument() )
{
return wcsList;
}

QDomElement propertiesElem = mProjectParser.propertiesElem();
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( propertiesElem.isNull() )
{
return wcsList;
Expand All @@ -162,7 +165,7 @@ QStringList QgsWCSProjectParser::wcsLayers() const

void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
Expand All @@ -186,7 +189,7 @@ void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElemen
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( !layer )
continue;
QString coveName = layer->name();
Expand Down Expand Up @@ -366,7 +369,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
{
QList<QgsMapLayer*> layerList;

const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return layerList;
Expand All @@ -379,7 +382,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem, useCache );
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem, useCache );
QgsRasterLayer* layer = dynamic_cast<QgsRasterLayer*>( mLayer );
if ( !layer || !wcsLayersId.contains( layer->id() ) )
return layerList;
Expand Down
4 changes: 2 additions & 2 deletions src/mapserver/qgswcsprojectparser.h
Expand Up @@ -23,7 +23,7 @@
class QgsWCSProjectParser
{
public:
QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath );
QgsWCSProjectParser( const QString& filePath );
~QgsWCSProjectParser();

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
Expand All @@ -35,7 +35,7 @@ class QgsWCSProjectParser
QList<QgsMapLayer*> mapLayerFromCoverage( const QString& cName, bool useCache = true ) const;

private:
QgsServerProjectParser mProjectParser;
QgsServerProjectParser* mProjectParser;
};

#endif // QGSWCSPROJECTPARSER_H

0 comments on commit 7de1dff

Please sign in to comment.