Skip to content

Commit 689f3b1

Browse files
committed
Expose QgsServerInterface to service modules
* Instanciate QgsServerInterface even if HAVE_SERVER_PYTHON_PLUGINS is not defined * Pass QgsServerInterface in module registration methods. * Add QgsServer initialisation test #Please enter the commit message for your changes. Lines starting
1 parent 2adbaf0 commit 689f3b1

22 files changed

+84
-133
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ ELSE (WIN32)
521521
SET (QGIS_PLUGIN_SUBDIR_REV ../../MacOS)
522522
SET (DEFAULT_INCLUDE_SUBDIR include/qgis)
523523

524-
SET (DEFAULT_SERVER_MODULE_SUBDIR ../PlugIns/server)
524+
# Set server moodules path to DEFAULT_LIBEXEC_SUBDIR+'/server'
525+
SET (DEFAULT_SERVER_MODULE_SUBDIR ${DEFAULT_LIBEXEC_SUBDIR}/server)
525526

526527
# path for framework references when running from build directory
527528
# changed later to reference in-app resources upon install
@@ -547,7 +548,7 @@ ELSE (WIN32)
547548
SET (DEFAULT_PLUGIN_SUBDIR lib${LIB_SUFFIX}/qgis/plugins)
548549
SET (DEFAULT_INCLUDE_SUBDIR include/qgis)
549550

550-
SET (DEFAULT_SERVER_MODULE_SUBDIR lib${LIB_SUFFIX}/qgis/server)
551+
SET (DEFAULT_SERVER_MODULE_SUBDIR ${DEFAULT_LIBEXEC_SUBDIR}/qgis/server)
551552
ENDIF (APPLE)
552553

553554
ENDIF (WIN32)

cmake_templates/qgsconfig.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
2929
#define CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}"
3030

31+
#define QGIS_SERVER_MODULE_SUBDIR "${QGIS_SERVER_MODULE_SUBDIR}"
32+
3133
#define QSCINTILLA_VERSION_STR "${QSCINTILLA_VERSION_STR}"
3234

3335
#if defined( __APPLE__ )

mac/cmake/0vars.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SET (QGIS_PLUGIN_SUBDIR "@QGIS_PLUGIN_SUBDIR@")
3434
SET (QGIS_PLUGIN_SUBDIR_REV "@QGIS_PLUGIN_SUBDIR_REV@")
3535
SET (QGIS_DATA_SUBDIR "@QGIS_DATA_SUBDIR@")
3636
SET (QGIS_DATA_SUBDIR_REV "@QGIS_DATA_SUBDIR_REV@")
37+
SET (QGIS_SERVER_MODULE_SUBDIR "@QGIS_SERVER_MODULE_SUBDIR@")
3738

3839
# optional components
3940
SET (WITH_GLOBE "@WITH_GLOBE@")

python/server/qgsserver.sip

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ class QgsServer
193193
*/
194194

195195
/** Returns a pointer to the server interface */
196-
%If (HAVE_SERVER_PYTHON_PLUGINS)
197-
QgsServerInterface* serverInterface();
198-
%End
196+
QgsServerInterface* serverInterface();
199197

200198
private:
201199
QgsServer( const QgsServer& );

python/server/qgsserverinterface.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ class QgsServerInterface
124124
*/
125125
virtual void removeProjectLayers( const QString& path ) = 0;
126126

127+
/**
128+
* Return the service registry
129+
* @return QgsServiceResgistry
130+
*/
131+
virtual QgsServiceRegistry* serviceRegistry() = 0 /KeepReference/;
132+
127133
private:
128134
/** Constructor */
129135
QgsServerInterface();

python/server/qgsservicemodule.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class QgsServiceModule
4444
* Ask module to registe all provided services
4545
* @param registry QgsServiceRegistry
4646
*/
47-
virtual void registerSelf( QgsServiceRegistry& registry ) = 0;
47+
virtual void registerSelf( QgsServiceRegistry& registry,
48+
QgsServerInterface* serverIface = nullptr ) = 0;
4849
};
4950

5051

python/server/qgsserviceregistry.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class QgsServiceRegistry
7878
* Initialize registry, load modules and auto register services
7979
* @param nativeModulepath the native module path
8080
*/
81-
void init( const QString& nativeModulepath );
81+
// XXX Do we want this exposed to python ?
82+
void init( const QString& nativeModulepath, QgsServerInterface* serverIface = nullptr );
8283

8384
/**
8485
* Clean up registered service and unregister modules

src/server/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ SET ( qgis_mapserv_SRCS
5353
qgsserver.cpp
5454
qgsservice.cpp
5555
qgsservicemodule.cpp
56-
qgsserviceloader.cpp
5756
qgsservicenativeloader.cpp
5857
qgsserviceregistry.cpp
5958
qgsserverrequest.cpp

src/server/qgsserver.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
#include "qgsnetworkaccessmanager.h"
4040
#include "qgsserverlogger.h"
4141
#include "qgseditorwidgetregistry.h"
42-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
4342
#include "qgsaccesscontrolfilter.h"
44-
#endif
4543

4644
#include <QDomDocument>
4745
#include <QNetworkDiskCache>
@@ -61,14 +59,12 @@
6159

6260
QString* QgsServer::sConfigFilePath = nullptr;
6361
QgsCapabilitiesCache* QgsServer::sCapabilitiesCache = nullptr;
64-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
65-
QgsServerInterfaceImpl*QgsServer::sServerInterface = nullptr;
66-
#endif
62+
QgsServerInterfaceImpl* QgsServer::sServerInterface = nullptr;
6763
// Initialization must run once for all servers
6864
bool QgsServer::sInitialised = false;
6965
bool QgsServer::sCaptureOutput = true;
7066

71-
67+
QgsServiceRegistry QgsServer::sServiceRegistry;
7268

7369
QgsServer::QgsServer( bool captureOutput )
7470
{
@@ -348,9 +344,10 @@ bool QgsServer::init( )
348344

349345
QgsEditorWidgetRegistry::initEditors();
350346

351-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
352-
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache );
353-
#endif
347+
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, &sServiceRegistry );
348+
349+
// Load service modules
350+
sServiceRegistry.init( QgsApplication::libexecPath() + "/server", sServerInterface );
354351

355352
sInitialised = true;
356353
QgsMessageLog::logMessage( QStringLiteral( "Server initialized" ), QStringLiteral( "Server" ), QgsMessageLog::INFO );

src/server/qgsserver.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434
#include "qgscapabilitiescache.h"
3535
#include "qgsmapsettings.h"
3636
#include "qgsmessagelog.h"
37+
#include "qgsserviceregistry.h"
3738

3839
#ifdef HAVE_SERVER_PYTHON_PLUGINS
3940
#include "qgsserverplugins.h"
4041
#include "qgsserverfilter.h"
41-
#include "qgsserverinterfaceimpl.h"
4242
#include "qgis_server.h"
4343
#endif
4444

45+
#include "qgsserverinterfaceimpl.h"
4546

4647
/** \ingroup server
4748
* The QgsServer class provides OGC web services.
@@ -59,7 +60,7 @@ class SERVER_EXPORT QgsServer
5960
* @param var environment variable name
6061
* @param val value
6162
* @note added in 2.14
62-
*/
63+
/ */
6364
void putenv( const QString &var, const QString &val );
6465

6566
/** Handles the request. The output is normally printed trough FCGI printf
@@ -75,10 +76,10 @@ class SERVER_EXPORT QgsServer
7576
*/
7677
QPair<QByteArray, QByteArray> handleRequest( const QString& queryString = QString() );
7778

78-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
7979
//! Returns a pointer to the server interface
8080
QgsServerInterfaceImpl* serverInterface() { return sServerInterface; }
8181

82+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
8283
//! Intialize python
8384
//! Note: not in python bindings
8485
void initPython( );
@@ -125,6 +126,10 @@ class SERVER_EXPORT QgsServer
125126
//! Initialization must run once for all servers
126127
static bool sInitialised;
127128
static bool sCaptureOutput;
129+
130+
//! service registry
131+
static QgsServiceRegistry sServiceRegistry;
132+
128133
};
129134
#endif // QGSSERVER_H
130135

0 commit comments

Comments
 (0)