54
54
#include < stdlib.h>
55
55
56
56
57
- // Static initialisers, default values for fcgi server
58
- QgsApplication* QgsServer::mQgsApplication = nullptr ;
59
- bool QgsServer::mInitialised = false ;
60
- QString QgsServer::mServerName ( " qgis_server" );
61
- bool QgsServer::mCaptureOutput = false ;
62
- char * QgsServer::mArgv [1 ];
63
- int QgsServer::mArgc = 1 ;
64
- QString QgsServer::mConfigFilePath ;
65
- QgsMapRenderer* QgsServer::mMapRenderer = nullptr ;
66
- QgsCapabilitiesCache* QgsServer::mCapabilitiesCache ;
67
57
58
+ // Server status static initialisers.
59
+ // Default values are for C++, SIP bindings will override their
60
+ // options in in init()
61
+
62
+ QString QgsServer::sConfigFilePath = QString();
63
+ QgsCapabilitiesCache* QgsServer::sCapabilitiesCache = nullptr ;
64
+ QgsMapRenderer* QgsServer::sMapRenderer = nullptr ;
68
65
#ifdef HAVE_SERVER_PYTHON_PLUGINS
69
- bool QgsServer::mInitPython = true ;
70
- QgsServerInterfaceImpl* QgsServer::mServerInterface = nullptr ;
66
+ QgsServerInterfaceImpl* QgsServer::sServerInterface = nullptr ;
67
+ bool QgsServer::sInitPython = true ;
71
68
#endif
69
+ // Initialization must run once for all servers
70
+ bool QgsServer::sInitialised = false ;
71
+ char * QgsServer::sArgv [1 ];
72
+ int QgsServer::sArgc ;
73
+ QgsApplication* QgsServer::sQgsApplication = nullptr ;
74
+ bool QgsServer::sCaptureOutput = false ;
75
+
76
+
77
+
78
+ QgsServer::QgsServer ( int &argc, char **argv )
79
+ {
80
+ init ( argc, argv );
81
+ }
72
82
73
83
74
84
QgsServer::QgsServer ()
75
85
{
86
+ init ();
76
87
}
77
88
78
89
@@ -81,6 +92,13 @@ QgsServer::~QgsServer()
81
92
}
82
93
83
94
95
+ QString& QgsServer::serverName ()
96
+ {
97
+ static QString* name = new QString ( " qgis_server" );
98
+ return *name;
99
+ }
100
+
101
+
84
102
QFileInfo QgsServer::defaultAdminSLD ()
85
103
{
86
104
return QFileInfo ( " admin.sld" );
@@ -292,17 +310,18 @@ QString QgsServer::configPath( const QString& defaultConfigPath, const QMap<QStr
292
310
*/
293
311
bool QgsServer::init ()
294
312
{
295
- if ( mInitialised )
313
+ if ( sInitialised )
296
314
{
297
315
return false ;
298
316
}
299
- mArgv [0 ] = mServerName .toUtf8 ().data ();
300
- mArgc = 1 ;
301
- mCaptureOutput = true ;
317
+
318
+ sArgv [0 ] = serverName ().toUtf8 ().data ();
319
+ sArgc = 1 ;
320
+ sCaptureOutput = true ;
302
321
#ifdef HAVE_SERVER_PYTHON_PLUGINS
303
- mInitPython = false ;
322
+ sInitPython = false ;
304
323
#endif
305
- return init ( mArgc , mArgv );
324
+ return init ( sArgc , sArgv );
306
325
}
307
326
308
327
@@ -311,7 +330,7 @@ bool QgsServer::init()
311
330
*/
312
331
bool QgsServer::init ( int & argc, char ** argv )
313
332
{
314
- if ( mInitialised )
333
+ if ( sInitialised )
315
334
{
316
335
return false ;
317
336
}
@@ -330,7 +349,7 @@ bool QgsServer::init( int & argc, char ** argv )
330
349
QSettings::setPath ( QSettings::IniFormat, QSettings::UserScope, optionsPath );
331
350
}
332
351
333
- mQgsApplication = new QgsApplication ( argc, argv, getenv ( " DISPLAY" ), QString (), " server" );
352
+ sQgsApplication = new QgsApplication ( argc, argv, getenv ( " DISPLAY" ), QString (), " server" );
334
353
335
354
QCoreApplication::setOrganizationName ( QgsApplication::QGIS_ORGANIZATION_NAME );
336
355
QCoreApplication::setOrganizationDomain ( QgsApplication::QGIS_ORGANIZATION_DOMAIN );
@@ -386,24 +405,24 @@ bool QgsServer::init( int & argc, char ** argv )
386
405
}
387
406
if ( !defaultConfigFilePath.isEmpty () )
388
407
{
389
- mConfigFilePath = defaultConfigFilePath;
408
+ sConfigFilePath = defaultConfigFilePath;
390
409
}
391
410
392
411
// create cache for capabilities XML
393
- mCapabilitiesCache = new QgsCapabilitiesCache ();
394
- mMapRenderer = new QgsMapRenderer;
395
- mMapRenderer ->setLabelingEngine ( new QgsPalLabeling () );
412
+ sCapabilitiesCache = new QgsCapabilitiesCache ();
413
+ sMapRenderer = new QgsMapRenderer;
414
+ sMapRenderer ->setLabelingEngine ( new QgsPalLabeling () );
396
415
397
416
#ifdef ENABLE_MS_TESTS
398
417
QgsFontUtils::loadStandardTestFonts ( QStringList () << " Roman" << " Bold" );
399
418
#endif
400
419
401
420
#ifdef HAVE_SERVER_PYTHON_PLUGINS
402
- mServerInterface = new QgsServerInterfaceImpl ( mCapabilitiesCache );
403
- if ( mInitPython )
421
+ sServerInterface = new QgsServerInterfaceImpl ( sCapabilitiesCache );
422
+ if ( sInitPython )
404
423
{
405
424
// Init plugins
406
- if ( ! QgsServerPlugins::initPlugins ( mServerInterface ) )
425
+ if ( ! QgsServerPlugins::initPlugins ( sServerInterface ) )
407
426
{
408
427
QgsMessageLog::logMessage ( " No server python plugins are available" , " Server" , QgsMessageLog::INFO );
409
428
}
@@ -415,7 +434,7 @@ bool QgsServer::init( int & argc, char ** argv )
415
434
#endif
416
435
417
436
QgsEditorWidgetRegistry::initEditors ();
418
- mInitialised = true ;
437
+ sInitialised = true ;
419
438
QgsMessageLog::logMessage ( " Server initialized" , " Server" , QgsMessageLog::INFO );
420
439
return true ;
421
440
}
@@ -436,12 +455,6 @@ void QgsServer::putenv( const QString &var, const QString &val )
436
455
*/
437
456
QPair<QByteArray, QByteArray> QgsServer::handleRequest ( const QString& queryString )
438
457
{
439
- // Run init if handleRequest was called without previously initialising
440
- // the server
441
- if ( ! mInitialised )
442
- {
443
- init ();
444
- }
445
458
446
459
/*
447
460
* This is mainly for python bindings, passing QUERY_STRING
@@ -453,15 +466,15 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
453
466
int logLevel = QgsServerLogger::instance ()->logLevel ();
454
467
QTime time ; // used for measuring request time if loglevel < 1
455
468
QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
456
- mQgsApplication ->processEvents ();
469
+ sQgsApplication ->processEvents ();
457
470
if ( logLevel < 1 )
458
471
{
459
472
time .start ();
460
473
printRequestInfos ();
461
474
}
462
475
463
476
// Request handler
464
- QScopedPointer<QgsRequestHandler> theRequestHandler ( createRequestHandler ( mCaptureOutput ) );
477
+ QScopedPointer<QgsRequestHandler> theRequestHandler ( createRequestHandler ( sCaptureOutput ) );
465
478
466
479
try
467
480
{
@@ -476,10 +489,10 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
476
489
477
490
#ifdef HAVE_SERVER_PYTHON_PLUGINS
478
491
// Set the request handler into the interface for plugins to manipulate it
479
- mServerInterface ->setRequestHandler ( theRequestHandler.data () );
492
+ sServerInterface ->setRequestHandler ( theRequestHandler.data () );
480
493
// Iterate filters and call their requestReady() method
481
494
QgsServerFiltersMap::const_iterator filtersIterator;
482
- QgsServerFiltersMap filters = mServerInterface ->filters ();
495
+ QgsServerFiltersMap filters = sServerInterface ->filters ();
483
496
for ( filtersIterator = filters.constBegin (); filtersIterator != filters.constEnd (); ++filtersIterator )
484
497
{
485
498
filtersIterator.value ()->requestReady ();
@@ -488,22 +501,22 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
488
501
// Pass the filters to the requestHandler, this is needed for the following reasons:
489
502
// 1. allow core services to access plugin filters and implement thir own plugin hooks
490
503
// 2. allow requestHandler to call sendResponse plugin hook
491
- theRequestHandler->setPluginFilters ( mServerInterface ->filters () );
504
+ theRequestHandler->setPluginFilters ( sServerInterface ->filters () );
492
505
#endif
493
506
494
507
// Copy the parameters map
495
508
QMap<QString, QString> parameterMap ( theRequestHandler->parameterMap () );
496
509
#ifdef HAVE_SERVER_PYTHON_PLUGINS
497
510
const QgsAccessControl* accessControl = nullptr ;
498
- accessControl = mServerInterface ->accessControls ();
511
+ accessControl = sServerInterface ->accessControls ();
499
512
#endif
500
513
501
514
printRequestParameters ( parameterMap, logLevel );
502
515
QMap<QString, QString>::const_iterator paramIt;
503
516
// Config file path
504
- QString configFilePath = configPath ( mConfigFilePath , parameterMap );
517
+ QString configFilePath = configPath ( sConfigFilePath , parameterMap );
505
518
#ifdef HAVE_SERVER_PYTHON_PLUGINS
506
- mServerInterface ->setConfigFilePath ( configFilePath );
519
+ sServerInterface ->setConfigFilePath ( configFilePath );
507
520
#endif
508
521
// Service parameter
509
522
QString serviceString = theRequestHandler->parameter ( " SERVICE" );
@@ -600,8 +613,8 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
600
613
, parameterMap
601
614
, p
602
615
, theRequestHandler.data ()
603
- , mMapRenderer
604
- , mCapabilitiesCache
616
+ , sMapRenderer
617
+ , sCapabilitiesCache
605
618
#ifdef HAVE_SERVER_PYTHON_PLUGINS
606
619
, accessControl
607
620
#endif
@@ -617,14 +630,14 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
617
630
618
631
#ifdef HAVE_SERVER_PYTHON_PLUGINS
619
632
// Iterate filters and call their responseComplete() method
620
- filters = mServerInterface ->filters ();
633
+ filters = sServerInterface ->filters ();
621
634
for ( filtersIterator = filters.constBegin (); filtersIterator != filters.constEnd (); ++filtersIterator )
622
635
{
623
636
filtersIterator.value ()->responseComplete ();
624
637
}
625
638
// We are done using theRequestHandler in plugins, make sure we don't access
626
639
// to a deleted request handler from Python bindings
627
- mServerInterface ->clearRequestHandler ();
640
+ sServerInterface ->clearRequestHandler ();
628
641
#endif
629
642
630
643
theRequestHandler->sendResponse ();
0 commit comments