Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 2adbaf0 commit 689f3b1
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 133 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Expand Up @@ -521,7 +521,8 @@ ELSE (WIN32)
SET (QGIS_PLUGIN_SUBDIR_REV ../../MacOS)
SET (DEFAULT_INCLUDE_SUBDIR include/qgis)

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

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

SET (DEFAULT_SERVER_MODULE_SUBDIR lib${LIB_SUFFIX}/qgis/server)
SET (DEFAULT_SERVER_MODULE_SUBDIR ${DEFAULT_LIBEXEC_SUBDIR}/qgis/server)
ENDIF (APPLE)

ENDIF (WIN32)
Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -28,6 +28,8 @@
#define CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
#define CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}"

#define QGIS_SERVER_MODULE_SUBDIR "${QGIS_SERVER_MODULE_SUBDIR}"

#define QSCINTILLA_VERSION_STR "${QSCINTILLA_VERSION_STR}"

#if defined( __APPLE__ )
Expand Down
1 change: 1 addition & 0 deletions mac/cmake/0vars.cmake.in
Expand Up @@ -34,6 +34,7 @@ SET (QGIS_PLUGIN_SUBDIR "@QGIS_PLUGIN_SUBDIR@")
SET (QGIS_PLUGIN_SUBDIR_REV "@QGIS_PLUGIN_SUBDIR_REV@")
SET (QGIS_DATA_SUBDIR "@QGIS_DATA_SUBDIR@")
SET (QGIS_DATA_SUBDIR_REV "@QGIS_DATA_SUBDIR_REV@")
SET (QGIS_SERVER_MODULE_SUBDIR "@QGIS_SERVER_MODULE_SUBDIR@")

# optional components
SET (WITH_GLOBE "@WITH_GLOBE@")
Expand Down
4 changes: 1 addition & 3 deletions python/server/qgsserver.sip
Expand Up @@ -193,9 +193,7 @@ class QgsServer
*/

/** Returns a pointer to the server interface */
%If (HAVE_SERVER_PYTHON_PLUGINS)
QgsServerInterface* serverInterface();
%End
QgsServerInterface* serverInterface();

private:
QgsServer( const QgsServer& );
Expand Down
6 changes: 6 additions & 0 deletions python/server/qgsserverinterface.sip
Expand Up @@ -124,6 +124,12 @@ class QgsServerInterface
*/
virtual void removeProjectLayers( const QString& path ) = 0;

/**
* Return the service registry
* @return QgsServiceResgistry
*/
virtual QgsServiceRegistry* serviceRegistry() = 0 /KeepReference/;

private:
/** Constructor */
QgsServerInterface();
Expand Down
3 changes: 2 additions & 1 deletion python/server/qgsservicemodule.sip
Expand Up @@ -44,7 +44,8 @@ class QgsServiceModule
* Ask module to registe all provided services
* @param registry QgsServiceRegistry
*/
virtual void registerSelf( QgsServiceRegistry& registry ) = 0;
virtual void registerSelf( QgsServiceRegistry& registry,
QgsServerInterface* serverIface = nullptr ) = 0;
};


3 changes: 2 additions & 1 deletion python/server/qgsserviceregistry.sip
Expand Up @@ -78,7 +78,8 @@ class QgsServiceRegistry
* Initialize registry, load modules and auto register services
* @param nativeModulepath the native module path
*/
void init( const QString& nativeModulepath );
// XXX Do we want this exposed to python ?
void init( const QString& nativeModulepath, QgsServerInterface* serverIface = nullptr );

/**
* Clean up registered service and unregister modules
Expand Down
1 change: 0 additions & 1 deletion src/server/CMakeLists.txt
Expand Up @@ -53,7 +53,6 @@ SET ( qgis_mapserv_SRCS
qgsserver.cpp
qgsservice.cpp
qgsservicemodule.cpp
qgsserviceloader.cpp
qgsservicenativeloader.cpp
qgsserviceregistry.cpp
qgsserverrequest.cpp
Expand Down
15 changes: 6 additions & 9 deletions src/server/qgsserver.cpp
Expand Up @@ -39,9 +39,7 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsserverlogger.h"
#include "qgseditorwidgetregistry.h"
#ifdef HAVE_SERVER_PYTHON_PLUGINS
#include "qgsaccesscontrolfilter.h"
#endif

#include <QDomDocument>
#include <QNetworkDiskCache>
Expand All @@ -61,14 +59,12 @@

QString* QgsServer::sConfigFilePath = nullptr;
QgsCapabilitiesCache* QgsServer::sCapabilitiesCache = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsServerInterfaceImpl*QgsServer::sServerInterface = nullptr;
#endif
QgsServerInterfaceImpl* QgsServer::sServerInterface = nullptr;
// Initialization must run once for all servers
bool QgsServer::sInitialised = false;
bool QgsServer::sCaptureOutput = true;


QgsServiceRegistry QgsServer::sServiceRegistry;

QgsServer::QgsServer( bool captureOutput )
{
Expand Down Expand Up @@ -348,9 +344,10 @@ bool QgsServer::init( )

QgsEditorWidgetRegistry::initEditors();

#ifdef HAVE_SERVER_PYTHON_PLUGINS
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache );
#endif
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, &sServiceRegistry );

// Load service modules
sServiceRegistry.init( QgsApplication::libexecPath() + "/server", sServerInterface );

sInitialised = true;
QgsMessageLog::logMessage( QStringLiteral( "Server initialized" ), QStringLiteral( "Server" ), QgsMessageLog::INFO );
Expand Down
11 changes: 8 additions & 3 deletions src/server/qgsserver.h
Expand Up @@ -34,14 +34,15 @@
#include "qgscapabilitiescache.h"
#include "qgsmapsettings.h"
#include "qgsmessagelog.h"
#include "qgsserviceregistry.h"

#ifdef HAVE_SERVER_PYTHON_PLUGINS
#include "qgsserverplugins.h"
#include "qgsserverfilter.h"
#include "qgsserverinterfaceimpl.h"
#include "qgis_server.h"
#endif

#include "qgsserverinterfaceimpl.h"

/** \ingroup server
* The QgsServer class provides OGC web services.
Expand All @@ -59,7 +60,7 @@ class SERVER_EXPORT QgsServer
* @param var environment variable name
* @param val value
* @note added in 2.14
*/
/ */
void putenv( const QString &var, const QString &val );

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

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

#ifdef HAVE_SERVER_PYTHON_PLUGINS
//! Intialize python
//! Note: not in python bindings
void initPython( );
Expand Down Expand Up @@ -125,6 +126,10 @@ class SERVER_EXPORT QgsServer
//! Initialization must run once for all servers
static bool sInitialised;
static bool sCaptureOutput;

//! service registry
static QgsServiceRegistry sServiceRegistry;

};
#endif // QGSSERVER_H

7 changes: 7 additions & 0 deletions src/server/qgsserverinterface.h
Expand Up @@ -27,6 +27,7 @@
#include "qgsaccesscontrolfilter.h"
#include "qgsaccesscontrol.h"
#include "qgis_server.h"
#include "qgsserviceregistry.h"

/**
* \ingroup server
Expand Down Expand Up @@ -132,6 +133,12 @@ class SERVER_EXPORT QgsServerInterface
*/
virtual void removeProjectLayers( const QString& path ) = 0;

/**
* Return the service registry
* @return QgsServiceResgistry
*/
virtual QgsServiceRegistry* serviceRegistry() = 0;

private:
QString mConfigFilePath;
};
Expand Down
8 changes: 6 additions & 2 deletions src/server/qgsserverinterfaceimpl.cpp
Expand Up @@ -22,8 +22,9 @@
#include "qgsmslayercache.h"

//! Constructor
QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache* capCache )
QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache* capCache, QgsServiceRegistry* srvRegistry )
: mCapabilitiesCache( capCache )
, mServiceRegistry(srvRegistry)
{
mRequestHandler = nullptr;
mAccessControls = new QgsAccessControl();
Expand Down Expand Up @@ -89,5 +90,8 @@ void QgsServerInterfaceImpl::removeProjectLayers( const QString& path )
QgsMSLayerCache::instance()->removeProjectLayers( path );
}


QgsServiceRegistry* QgsServerInterfaceImpl::serviceRegistry()
{
return mServiceRegistry;
}

8 changes: 6 additions & 2 deletions src/server/qgsserverinterfaceimpl.h
Expand Up @@ -37,7 +37,8 @@ class QgsServerInterfaceImpl : public QgsServerInterface
public:

//! Constructor
explicit QgsServerInterfaceImpl( QgsCapabilitiesCache *capCache );
explicit QgsServerInterfaceImpl( QgsCapabilitiesCache *capCache,
QgsServiceRegistry* srvRegistry );


~QgsServerInterfaceImpl();
Expand All @@ -50,6 +51,7 @@ class QgsServerInterfaceImpl : public QgsServerInterface
void registerFilter( QgsServerFilter *filter, int priority = 0 ) override;
QgsServerFiltersMap filters() override { return mFilters; }
//! Register an access control filter
//
void registerAccessControl( QgsAccessControlFilter *accessControl, int priority = 0 ) override;

/** Gets the helper over all the registered access control filters
Expand All @@ -63,14 +65,16 @@ class QgsServerInterfaceImpl : public QgsServerInterface
void removeConfigCacheEntry( const QString& path ) override;
void removeProjectLayers( const QString& path ) override;

QgsServiceRegistry* serviceRegistry() override;

private:

QString mConfigFilePath;
QgsServerFiltersMap mFilters;
QgsAccessControl* mAccessControls;
QgsCapabilitiesCache* mCapabilitiesCache;
QgsRequestHandler* mRequestHandler;

QgsServiceRegistry* mServiceRegistry;
};

#endif // QGSSERVERINTERFACEIMPL_H
34 changes: 0 additions & 34 deletions src/server/qgsserviceloader.cpp

This file was deleted.

58 changes: 0 additions & 58 deletions src/server/qgsserviceloader.h

This file was deleted.

4 changes: 3 additions & 1 deletion src/server/qgsservicemodule.h
Expand Up @@ -22,6 +22,7 @@
#define QGSSERVICEMODULE_H

class QgsServiceRegistry;
class QgsServerInterface;

/**
* \ingroup server
Expand All @@ -47,7 +48,8 @@ class SERVER_EXPORT QgsServiceModule
* Ask module to register all provided services
* @param registry QgsServiceRegistry
*/
virtual void registerSelf( QgsServiceRegistry& registry ) = 0;
virtual void registerSelf( QgsServiceRegistry& registry,
QgsServerInterface* serverIface = nullptr ) = 0;
};

#endif
Expand Down
5 changes: 3 additions & 2 deletions src/server/qgsservicenativeloader.cpp
Expand Up @@ -54,7 +54,8 @@ QgsServiceNativeLoader::~QgsServiceNativeLoader()

}

void QgsServiceNativeLoader::loadModules( const QString& modulePath, QgsServiceRegistry& registrar )
void QgsServiceNativeLoader::loadModules( const QString& modulePath, QgsServiceRegistry& registrar,
QgsServerInterface* serverIface )
{
QDir moduleDir( modulePath );
moduleDir.setSorting( QDir::Name | QDir::IgnoreCase );
Expand All @@ -74,7 +75,7 @@ void QgsServiceNativeLoader::loadModules( const QString& modulePath, QgsServiceR
if ( module )
{
// Register services
module->registerSelf( registrar );
module->registerSelf( registrar, serverIface );
}
}
}
Expand Down

0 comments on commit 689f3b1

Please sign in to comment.