Skip to content

Commit c62ca9f

Browse files
committedDec 8, 2011
[FEATURE] WMS server: add support for WMS 1.1.1 and port to QMap (from std::map)
Thanks Marco Lechner for the initial WMS 1.1.1 patch.
1 parent 9c89965 commit c62ca9f

24 files changed

+466
-538
lines changed
 

‎src/mapserver/qgis_map_serv.cpp

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int main( int argc, char * argv[] )
223223
theRequestHandler = new QgsGetRequestHandler();
224224
}
225225

226-
std::map<QString, QString> parameterMap;
226+
QMap<QString, QString> parameterMap;
227227

228228
try
229229
{
@@ -237,17 +237,11 @@ int main( int argc, char * argv[] )
237237
}
238238

239239
//set admin config file to wms server object
240-
QString configFilePath = defaultConfigFilePath;
241-
std::map<QString, QString>::const_iterator mapFileIt = parameterMap.find( "MAP" );
242-
if ( mapFileIt != parameterMap.end() )
243-
{
244-
configFilePath = mapFileIt->second;
245-
QgsDebugMsg( QString( "Configuration file path set to: %1" ).arg( defaultConfigFilePath ) );
246-
}
247-
else
240+
if ( !parameterMap.contains( "MAP" ) )
248241
{
249242
QgsDebugMsg( QString( "Using default configuration file path: %1" ).arg( defaultConfigFilePath ) );
250243
}
244+
QString configFilePath = parameterMap.value( "MAP", defaultConfigFilePath );
251245

252246
QgsConfigParser* adminConfigParser = QgsConfigCache::instance()->searchConfiguration( configFilePath );
253247
if ( !adminConfigParser )
@@ -261,14 +255,9 @@ int main( int argc, char * argv[] )
261255
adminConfigParser->setParameterMap( parameterMap );
262256

263257
//request to WMS?
264-
QString serviceString( "WMS" );
265-
std::map<QString, QString>::const_iterator serviceIt = parameterMap.find( "SERVICE" );
266-
if ( serviceIt != parameterMap.end() )
267-
{
268-
serviceString = serviceIt->second;
269-
}
258+
QString serviceString = parameterMap.value( "SERVICE", "WMS" );
270259
#if 0
271-
else
260+
if ( !parameterMap.contains( "SERVICE" ) )
272261
{
273262
QgsDebugMsg( "unable to find 'SERVICE' parameter, exiting..." );
274263
theRequestHandler->sendServiceException( QgsMapServiceException( "ServiceNotSpecified", "Service not specified. The SERVICE parameter is mandatory" ) );
@@ -292,8 +281,8 @@ int main( int argc, char * argv[] )
292281

293282

294283
//request type
295-
std::map<QString, QString>::const_iterator requestIt = parameterMap.find( "REQUEST" );
296-
if ( requestIt == parameterMap.end() )
284+
QString request = parameterMap.value( "REQUEST" );
285+
if ( request.isEmpty() )
297286
{
298287
//do some error handling
299288
QgsDebugMsg( "unable to find 'REQUEST' parameter, exiting..." );
@@ -303,16 +292,18 @@ int main( int argc, char * argv[] )
303292
continue;
304293
}
305294

306-
if ( requestIt->second == "GetCapabilities" )
295+
QString version = parameterMap.value( "VERSION", "1.3.0" );
296+
297+
if ( request == "GetCapabilities" )
307298
{
308-
const QDomDocument* capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath );
299+
const QDomDocument* capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath, version );
309300
if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
310301
{
311302
QgsDebugMsg( "Capabilities document not found in cache" );
312303
QDomDocument doc;
313304
try
314305
{
315-
doc = theServer->getCapabilities();
306+
doc = theServer->getCapabilities( version );
316307
}
317308
catch ( QgsMapServiceException& ex )
318309
{
@@ -321,8 +312,8 @@ int main( int argc, char * argv[] )
321312
delete theServer;
322313
continue;
323314
}
324-
capabilitiesCache.insertCapabilitiesDocument( configFilePath, &doc );
325-
capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath );
315+
capabilitiesCache.insertCapabilitiesDocument( configFilePath, version, &doc );
316+
capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath, version );
326317
}
327318
else
328319
{
@@ -337,7 +328,7 @@ int main( int argc, char * argv[] )
337328
delete theServer;
338329
continue;
339330
}
340-
else if ( requestIt->second == "GetMap" )
331+
else if ( request == "GetMap" )
341332
{
342333
QImage* result = 0;
343334
try
@@ -369,12 +360,12 @@ int main( int argc, char * argv[] )
369360
delete theServer;
370361
continue;
371362
}
372-
else if ( requestIt->second == "GetFeatureInfo" )
363+
else if ( request == "GetFeatureInfo" )
373364
{
374365
QDomDocument featureInfoDoc;
375366
try
376367
{
377-
if ( theServer->getFeatureInfo( featureInfoDoc ) != 0 )
368+
if ( theServer->getFeatureInfo( featureInfoDoc, version ) != 0 )
378369
{
379370
delete theRequestHandler;
380371
delete theServer;
@@ -390,19 +381,12 @@ int main( int argc, char * argv[] )
390381
}
391382

392383
//info format for GetFeatureInfo
393-
QString infoFormat;
394-
std::map<QString, QString>::const_iterator p_it = parameterMap.find( "INFO_FORMAT" );
395-
if ( p_it != parameterMap.end() )
396-
{
397-
infoFormat = p_it->second;
398-
}
399-
400-
theRequestHandler->sendGetFeatureInfoResponse( featureInfoDoc, infoFormat );
384+
theRequestHandler->sendGetFeatureInfoResponse( featureInfoDoc, parameterMap.value( "INFO_FORMAT" ) );
401385
delete theRequestHandler;
402386
delete theServer;
403387
continue;
404388
}
405-
else if ( requestIt->second == "GetStyle" )
389+
else if ( request == "GetStyle" )
406390
{
407391
try
408392
{
@@ -418,7 +402,7 @@ int main( int argc, char * argv[] )
418402
delete theServer;
419403
continue;
420404
}
421-
else if ( requestIt->second == "GetLegendGraphics" )
405+
else if ( request == "GetLegendGraphics" )
422406
{
423407
QImage* result = 0;
424408
try
@@ -447,7 +431,7 @@ int main( int argc, char * argv[] )
447431
continue;
448432

449433
}
450-
else if ( requestIt->second == "GetPrint" )
434+
else if ( request == "GetPrint" )
451435
{
452436
QByteArray* printOutput = 0;
453437
try
@@ -470,7 +454,7 @@ int main( int argc, char * argv[] )
470454
}
471455
else//unknown request
472456
{
473-
QgsMapServiceException e( "OperationNotSupported", "Operation " + requestIt->second + " not supported" );
457+
QgsMapServiceException e( "OperationNotSupported", "Operation " + request + " not supported" );
474458
theRequestHandler->sendServiceException( e );
475459
delete theRequestHandler;
476460
delete theServer;

‎src/mapserver/qgscapabilitiescache.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,42 @@ QgsCapabilitiesCache::~QgsCapabilitiesCache()
2828
{
2929
}
3030

31-
const QDomDocument* QgsCapabilitiesCache::searchCapabilitiesDocument( const QString& configFilePath ) const
31+
const QDomDocument* QgsCapabilitiesCache::searchCapabilitiesDocument( QString configFilePath, QString version )
3232
{
3333
QCoreApplication::processEvents(); //get updates from file system watcher
34-
QHash< QString, QDomDocument >::const_iterator it = mCachedCapabilities.find( configFilePath );
35-
if ( it == mCachedCapabilities.constEnd() )
34+
35+
if ( mCachedCapabilities.contains( configFilePath ) && mCachedCapabilities[ configFilePath ].contains( version ) )
3636
{
37-
return 0;
37+
return &mCachedCapabilities[configFilePath][version];
3838
}
3939
else
4040
{
41-
return &( it.value() );
41+
return 0;
4242
}
4343
}
4444

45-
void QgsCapabilitiesCache::insertCapabilitiesDocument( const QString& configFilePath, const QDomDocument* doc )
45+
void QgsCapabilitiesCache::insertCapabilitiesDocument( QString configFilePath, QString version, const QDomDocument* doc )
4646
{
4747
if ( mCachedCapabilities.size() > 40 )
4848
{
4949
//remove another cache entry to avoid memory problems
50-
QHash<QString, QDomDocument>::iterator capIt = mCachedCapabilities.begin();
50+
QHash<QString, QHash<QString, QDomDocument> >::iterator capIt = mCachedCapabilities.begin();
5151
mFileSystemWatcher.removePath( capIt.key() );
5252
mCachedCapabilities.erase( capIt );
5353
}
54-
mCachedCapabilities.insert( configFilePath, doc->cloneNode().toDocument() );
55-
mFileSystemWatcher.addPath( configFilePath );
54+
55+
if ( !mCachedCapabilities.contains( configFilePath ) )
56+
{
57+
mFileSystemWatcher.addPath( configFilePath );
58+
mCachedCapabilities.insert( configFilePath, QHash<QString, QDomDocument>() );
59+
}
60+
61+
mCachedCapabilities[ configFilePath ].insert( version, doc->cloneNode().toDocument() );
5662
}
5763

5864
void QgsCapabilitiesCache::removeChangedEntry( const QString& path )
5965
{
6066
QgsDebugMsg( "Remove capabilities cache entry because file changed" );
61-
QHash< QString, QDomDocument >::iterator it = mCachedCapabilities.find( path );
62-
if ( it != mCachedCapabilities.end() )
63-
{
64-
mCachedCapabilities.erase( it );
65-
}
67+
mCachedCapabilities.remove( path );
6668
mFileSystemWatcher.removePath( path );
6769
}

‎src/mapserver/qgscapabilitiescache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ class QgsCapabilitiesCache: public QObject
3232
~QgsCapabilitiesCache();
3333

3434
/**Returns cached capabilities document (or 0 if document for configuration file not in cache)*/
35-
const QDomDocument* searchCapabilitiesDocument( const QString& configFilePath ) const;
35+
const QDomDocument* searchCapabilitiesDocument( QString configFilePath, QString version );
3636
/**Inserts new capabilities document (creates a copy of the document, does not take ownership)*/
37-
void insertCapabilitiesDocument( const QString& configFilePath, const QDomDocument* doc );
37+
void insertCapabilitiesDocument( QString configFilePath, QString version, const QDomDocument* doc );
3838

3939
private:
40-
QHash< QString, QDomDocument > mCachedCapabilities;
40+
QHash< QString, QHash< QString, QDomDocument > > mCachedCapabilities;
4141
QFileSystemWatcher mFileSystemWatcher;
4242

4343
private slots:
4444
/**Removes changed entry from this cache*/
45-
void removeChangedEntry( const QString& path );
45+
void removeChangedEntry( const QString &path );
4646
};
4747

4848
#endif // QGSCAPABILITIESCACHE_H

‎src/mapserver/qgsconfigcache.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,33 @@ QgsConfigCache::QgsConfigCache()
4040

4141
QgsConfigCache::~QgsConfigCache()
4242
{
43-
QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations.begin();
44-
for ( ; configIt != mCachedConfigurations.end(); ++configIt )
43+
foreach( QgsConfigParser *parser, mCachedConfigurations.values() )
4544
{
46-
delete configIt.value();
45+
delete parser;
4746
}
4847
}
4948

5049
QgsConfigParser* QgsConfigCache::searchConfiguration( const QString& filePath )
5150
{
5251
QCoreApplication::processEvents(); //check for updates from file system watcher
53-
QgsConfigParser* p = 0;
54-
QHash<QString, QgsConfigParser*>::const_iterator configIt = mCachedConfigurations.find( filePath );
55-
if ( configIt == mCachedConfigurations.constEnd() )
52+
QgsConfigParser* p = mCachedConfigurations.value( filePath, 0 );
53+
54+
if ( p )
5655
{
57-
QgsDebugMsg( "Create new configuration" );
58-
p = insertConfiguration( filePath );
56+
QgsDebugMsg( "Return configuration from cache" );
5957
}
6058
else
6159
{
62-
QgsDebugMsg( "Return configuration from cache" );
63-
p = configIt.value();
60+
QgsDebugMsg( "Create new configuration" );
61+
p = insertConfiguration( filePath );
6462
}
6563

6664
if ( p )
6765
{
6866
//there could be more layers in a project than allowed by the cache per default
6967
QgsMSLayerCache::instance()->setProjectMaxLayers( p->numberOfLayers() );
7068
}
69+
7170
return p;
7271
}
7372

0 commit comments

Comments
 (0)
Please sign in to comment.