Skip to content
Permalink
Browse files

[QGIS-Server] Enhance config cache

Add xmlDocument and server config in cache

xmlDocument and server config will be opened once for every requested W*S
Every requested W*S will point to the same server config and xmlDocument
  • Loading branch information
rldhont committed Nov 5, 2014
1 parent fda637b commit 4a4dc6bb46485fa8f796821e2ea009a8dd43f358
@@ -42,21 +42,27 @@ QgsConfigCache::~QgsConfigCache()

QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
{
QDomDocument* doc = xmlDocument( filePath );
return new QgsServerProjectParser( doc, filePath );
}

QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
QgsServerProjectParser* p = mServerConfigCache.object( filePath );
if ( !p )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
p = new QgsWCSProjectParser( doc, filePath );
p = new QgsServerProjectParser( doc, filePath );
mServerConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
return p;
}

QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
if ( !p )
{
p = new QgsWCSProjectParser( filePath );
mWCSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
@@ -70,13 +76,7 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
QgsWFSProjectParser* p = mWFSConfigCache.object( filePath );
if ( !p )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}

p = new QgsWFSProjectParser( doc, filePath );
p = new QgsWFSProjectParser( filePath );
mWFSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
@@ -105,7 +105,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 );
@@ -117,6 +117,12 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c

QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
{
// first get cache
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
if ( xmlDoc )
return xmlDoc;

// i it's first access
//first open file
QFile configFile( filePath );
if ( !configFile.exists() )
@@ -132,7 +138,7 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
}

//then create xml document
QDomDocument* xmlDoc = new QDomDocument();
xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
@@ -142,11 +148,14 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
delete xmlDoc;
return 0;
}
mXmlDocumentCache.insert( filePath, xmlDoc );
return xmlDoc;
}

void QgsConfigCache::removeChangedEntry( const QString& path )
{
mXmlDocumentCache.remove( path );
mServerConfigCache.remove( path );
mWMSConfigCache.remove( path );
mWFSConfigCache.remove( path );
mWCSConfigCache.remove( path );
@@ -52,6 +52,8 @@ 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, QgsServerProjectParser> mServerConfigCache;
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;
@@ -17,10 +17,12 @@

#include "qgswcsprojectparser.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 )
{
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

QgsWCSProjectParser::~QgsWCSProjectParser()
@@ -29,19 +31,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" );
@@ -55,12 +57,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;
@@ -75,7 +77,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() ) );
@@ -137,12 +139,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;
@@ -162,7 +164,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;
@@ -186,7 +188,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();
@@ -366,7 +368,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;
@@ -379,7 +381,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;
@@ -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;
@@ -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 4a4dc6b

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