Skip to content
Permalink
Browse files

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 689f3b1ab208451c4beca62079d69de3fe47508f
@@ -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
@@ -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)
@@ -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__ )
@@ -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@")
@@ -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& );
@@ -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();
@@ -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;
};


@@ -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
@@ -53,7 +53,6 @@ SET ( qgis_mapserv_SRCS
qgsserver.cpp
qgsservice.cpp
qgsservicemodule.cpp
qgsserviceloader.cpp
qgsservicenativeloader.cpp
qgsserviceregistry.cpp
qgsserverrequest.cpp
@@ -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>
@@ -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 )
{
@@ -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 );
@@ -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.
@@ -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
@@ -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( );
@@ -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

@@ -27,6 +27,7 @@
#include "qgsaccesscontrolfilter.h"
#include "qgsaccesscontrol.h"
#include "qgis_server.h"
#include "qgsserviceregistry.h"

/**
* \ingroup server
@@ -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;
};
@@ -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();
@@ -89,5 +90,8 @@ void QgsServerInterfaceImpl::removeProjectLayers( const QString& path )
QgsMSLayerCache::instance()->removeProjectLayers( path );
}


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

@@ -37,7 +37,8 @@ class QgsServerInterfaceImpl : public QgsServerInterface
public:

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


~QgsServerInterfaceImpl();
@@ -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
@@ -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

This file was deleted.

This file was deleted.

@@ -22,6 +22,7 @@
#define QGSSERVICEMODULE_H

class QgsServiceRegistry;
class QgsServerInterface;

/**
* \ingroup server
@@ -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
@@ -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 );
@@ -74,7 +75,7 @@ void QgsServiceNativeLoader::loadModules( const QString& modulePath, QgsServiceR
if ( module )
{
// Register services
module->registerSelf( registrar );
module->registerSelf( registrar, serverIface );
}
}
}

0 comments on commit 689f3b1

Please sign in to comment.
You can’t perform that action at this time.