Skip to content

Commit

Permalink
Merge pull request #3866 from dmarteau/master
Browse files Browse the repository at this point in the history
Implements service modules registry - Experimental
  • Loading branch information
rldhont committed Jan 10, 2017
2 parents 3a03c98 + ff3487d commit 9be984c
Show file tree
Hide file tree
Showing 91 changed files with 9,160 additions and 4,742 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Expand Up @@ -445,6 +445,8 @@ IF (WIN32)
SET (DEFAULT_PLUGIN_SUBDIR plugins)
SET (DEFAULT_INCLUDE_SUBDIR include)

SET (DEFAULT_SERVER_MODULE_SUBDIR server)

IF (MSVC)
SET (DEFAULT_BIN_SUBDIR bin)
SET (DEFAULT_CGIBIN_SUBDIR bin)
Expand Down Expand Up @@ -518,6 +520,10 @@ ELSE (WIN32)
SET (DEFAULT_PLUGIN_SUBDIR ../PlugIns/qgis)
SET (QGIS_PLUGIN_SUBDIR_REV ../../MacOS)
SET (DEFAULT_INCLUDE_SUBDIR include/qgis)

# 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
SET (CMAKE_INSTALL_NAME_DIR ${CMAKE_BINARY_DIR}/output/lib)
Expand All @@ -541,6 +547,8 @@ ELSE (WIN32)
SET (DEFAULT_LIBEXEC_SUBDIR lib${LIB_SUFFIX}/qgis)
SET (DEFAULT_PLUGIN_SUBDIR lib${LIB_SUFFIX}/qgis/plugins)
SET (DEFAULT_INCLUDE_SUBDIR include/qgis)

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

ENDIF (WIN32)
Expand Down Expand Up @@ -587,6 +595,8 @@ SET (QGIS_DATA_SUBDIR ${DEFAULT_DATA_SUBDIR} CACHE STRING "Subdirectory wh
SET (QGIS_PLUGIN_SUBDIR ${DEFAULT_PLUGIN_SUBDIR} CACHE STRING "Subdirectory where plugins will be installed")
SET (QGIS_INCLUDE_SUBDIR ${DEFAULT_INCLUDE_SUBDIR} CACHE STRING "Subdirectory where header files will be installed")

SET (QGIS_SERVER_MODULE_SUBDIR ${DEFAULT_SERVER_MODULE_SUBDIR} CACHE STRING "Subdirectory where server modules will be installed")

# mark *_SUBDIR variables as advanced as this is not something
# that an average user would use
MARK_AS_ADVANCED (QGIS_BIN_SUBDIR QGIS_CGIBIN_SUBDIR QGIS_LIB_SUBDIR QGIS_LIBEXEC_SUBDIR QGIS_DATA_SUBDIR QGIS_PLUGIN_SUBDIR QGIS_INCLUDE_SUBDIR)
Expand All @@ -600,6 +610,8 @@ SET (QGIS_DATA_DIR ${QGIS_DATA_SUBDIR})
SET (QGIS_PLUGIN_DIR ${QGIS_PLUGIN_SUBDIR})
SET (QGIS_INCLUDE_DIR ${QGIS_INCLUDE_SUBDIR})

SET (QGIS_SERVER_MODULE_DIR ${QGIS_SERVER_MODULE_SUBDIR})

# set the default locations where the targets (executables, libraries) will land when compiled
# this is to allow running qgis from the source tree without having to actually do a "make install"
SET (QGIS_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
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
53 changes: 24 additions & 29 deletions python/server/qgsrequesthandler.sip
Expand Up @@ -17,7 +17,7 @@
* Examples of possible mechanisms are cgi Get, cgi Post, SOAP or the usage
* as a standalone command line executable
*/
class QgsRequestHandler
class QgsRequestHandler /Abstract/
{
%TypeHeaderCode
#include "qgsmapserviceexception.h"
Expand All @@ -43,7 +43,7 @@ class QgsRequestHandler
// virtual void setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) = 0;

/** Allow plugins to return a QgsMapServiceException*/
virtual void setServiceException( const QgsMapServiceException& ex /Transfer/ ) = 0;
void setServiceException( const QgsMapServiceException& ex /Transfer/ );

//! @note not available in Python bindings
// virtual void setXmlResponse( const QDomDocument& doc ) = 0;
Expand All @@ -61,57 +61,52 @@ class QgsRequestHandler
// virtual void setGetFeatureResponse( QByteArray* ba ) = 0;

//! @note not available in Python bindings
virtual void endGetFeatureResponse( QByteArray* ba ) = 0;
void endGetFeatureResponse( QByteArray* ba );

//! @note not available in Python bindings
virtual void setGetCoverageResponse( QByteArray* ba ) = 0;

virtual void setDefaultHeaders();
void setGetCoverageResponse( QByteArray* ba );

/** Set an HTTP header*/
virtual void setHeader( const QString &name, const QString &value ) = 0;
void setHeader( const QString &name, const QString &value );

/** Remove an HTTP header*/
virtual int removeHeader( const QString &name ) = 0;
//! Retrieve header value
QString getHeader( const QString& name ) const;

/** Delete all HTTP headers*/
virtual void clearHeaders() = 0;
//! Return the list of all header keys
QList<QString> headerKeys() const;

/** Append the bytestream to response body*/
virtual void appendBody( const QByteArray &body ) = 0;
/** Remove an HTTP header*/
void removeHeader( const QString &name );

/** Clears the response body*/
virtual void clearBody() = 0;
/** Delete all HTTP headers*/
void clear();

/** Return the response body*/
virtual QByteArray body();
/** Append the bytestream to response body*/
void appendBody( const QByteArray &body );

/** Set the info format string such as "text/xml"*/
virtual void setInfoFormat( const QString &format ) = 0;

/** Check whether there is any header set or the body is not empty*/
virtual bool responseReady() const = 0;
void setInfoFormat( const QString &format );

/** Send out HTTP headers and flush output buffer*/
virtual void sendResponse() = 0;
void sendResponse();

/** Pointer to last raised exception*/
virtual bool exceptionRaised() const = 0;
bool exceptionRaised() const;

/** Return a copy of the parsed parameters as a key-value pair, to modify
* a parameter setParameter( const QString &key, const QString &value)
* and removeParameter(const QString &key) must be used
*/
QMap<QString, QString> parameterMap();
QMap<QString, QString> parameterMap() const;

/** Set a request parameter*/
virtual void setParameter( const QString &key, const QString &value ) = 0;
void setParameter( const QString &key, const QString &value );

/** Remove a request parameter*/
virtual int removeParameter( const QString &key ) = 0;
void removeParameter( const QString &key );

/** Return a request parameter*/
virtual QString parameter( const QString &key ) const = 0;
QString parameter( const QString &key ) const;

/** Return the requested format string*/
QString format() const;
Expand All @@ -120,13 +115,13 @@ class QgsRequestHandler
QString infoFormat() const;

/** Return true if the HTTP headers were already sent to the client*/
bool headersSent();
bool headersSent() const;


//! @note not available in Python bindings
// virtual QPair<QByteArray, QByteArray> getResponse() = 0;

private:
/** Parses the input and creates a request neutral Parameter/Value map*/
virtual void parseInput() = 0;
void parseInput();
};
32 changes: 17 additions & 15 deletions python/server/qgsserver.sip
Expand Up @@ -165,7 +165,7 @@ class QgsServer
/** Creates the server instance
* @param captureOutput set to false for stdout output (FCGI)
*/
QgsServer( bool captureOutput = true );
QgsServer();
~QgsServer();

/** Set environment variable
Expand All @@ -175,29 +175,31 @@ class QgsServer
*/
void putenv( const QString &var, const QString &val );

/** Handles the request. The output is normally printed trough FCGI printf
* by the request handler or, in case the server has been invoked from python
* bindings, a flag is set that captures all the output headers and body, instead
* of printing it returns the output as a QPair of QByteArray.
/** Handles the request.
* The query string is normally read from environment
* but can be also passed in args and in this case overrides the environment
* variable
*
* @param queryString optional QString containing the query string
* @return the response headers and body QPair of QByteArray if called from python bindings, empty otherwise
* @param request a QgsServerRequest holding request parameters
* @param response a QgsServerResponse for handling response I/O)
*/
QPair<QByteArray, QByteArray> handleRequest( const QString& queryString = QString() );
/*
// The following code was used to test type conversion in python bindings
QPair<QByteArray, QByteArray> testQPair( QPair<QByteArray, QByteArray> pair );
*/
void handleRequest( QgsServerRequest& request, QgsServerResponse& response );

/** Handles the request from query strinf
* The query string is normally read from environment
* but can be also passed in args and in this case overrides the environment
* variable.
*
* @param queryString QString containing the query string
* @return the response headers and body QPair of QByteArray
*/
QPair<QByteArray, QByteArray> handleRequest( const QString& queryString );

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

private:
QgsServer( const QgsServer& );
QgsServer & operator=( const QgsServer& );
};

22 changes: 14 additions & 8 deletions python/server/qgsserverinterface.sip
Expand Up @@ -39,7 +39,7 @@ typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;
class QgsServerInterface
{
%TypeHeaderCode
#include "qgsserverinterface.h"
#include "qgsserverinterface.h"
%End

public:
Expand All @@ -61,26 +61,26 @@ class QgsServerInterface
* Get pointer to the capabiblities cache
* @return QgsCapabilitiesCache
*/
virtual QgsCapabilitiesCache* capabilitiesCache() = 0 /KeepReference/;
virtual QgsCapabilitiesCache* capabilitiesCache() = 0 / KeepReference /;

/**
* Get pointer to the request handler
* @return QgsRequestHandler
*/
virtual QgsRequestHandler* requestHandler() = 0 /KeepReference/;
virtual QgsRequestHandler* requestHandler() = 0 / KeepReference /;

/**
* Register a QgsServerFilter
* @param filter the QgsServerFilter to add
* @param priority an optional priority for the filter order
*/
virtual void registerFilter( QgsServerFilter* filter /Transfer/, int priority = 0 ) = 0;
virtual void registerFilter( QgsServerFilter* filter / Transfer / , int priority = 0 ) = 0;

/**
* Set the filters map
* @param filters the QgsServerFiltersMap
*/
virtual void setFilters( QgsServerFiltersMap* filters /Transfer/) = 0;
virtual void setFilters( QgsServerFiltersMap* filters / Transfer / ) = 0;

/**
* Return the list of current QgsServerFilter
Expand All @@ -92,13 +92,13 @@ class QgsServerInterface
* @param accessControl the access control to register
* @param priority the priority used to order them
*/
virtual void registerAccessControl( QgsAccessControlFilter* accessControl /Transfer/, int priority = 0 ) = 0;
virtual void registerAccessControl( QgsAccessControlFilter* accessControl / Transfer / , int priority = 0 ) = 0;

/** Gets the registred access control filters */
virtual const QgsAccessControl* accessControls() const = 0;

//! Return an enrironment variable, used to pass environment variables to python
virtual QString getEnv(const QString& name ) const = 0;
virtual QString getEnv( const QString& name ) const = 0;

/**
* Return the configuration file path
Expand All @@ -110,7 +110,7 @@ class QgsServerInterface
* Set the configuration file path
* @param configFilePath QString with the configuration file path
*/
virtual void setConfigFilePath( const QString& configFilePath) = 0;
virtual void setConfigFilePath( const QString& configFilePath ) = 0;

/**
* Remove entry from config cache
Expand All @@ -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

0 comments on commit 9be984c

Please sign in to comment.