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