Skip to content
Permalink
Browse files

Merge pull request #1701 from elpaso/serverpython2

[feature] Serverpython2
  • Loading branch information
mhugent committed Nov 27, 2014
2 parents 9491851 + a790f7f commit 35556de96f06d084e0575f0baa1fa6833519df33
@@ -46,6 +46,13 @@ IF(WITH_MAPSERVER)
SET (MAPSERVER_SKIP_ECW FALSE CACHE BOOL "Determines whether QGIS mapserver should disable ECW (ECW in server apps requires a special license)")
ENDIF(WITH_MAPSERVER)


SET (WITH_SERVER_PLUGINS TRUE CACHE BOOL "Determines whether QGIS mapserver support for python plugins should be built")
IF(WITH_SERVER_PLUGINS)
SET(MAPSERVER_HAVE_PYTHON_PLUGINS TRUE)
ENDIF(WITH_SERVER_PLUGINS)


# Custom widgets
SET (WITH_CUSTOM_WIDGETS FALSE CACHE BOOL "Determines whether QGIS custom widgets for Qt Designer should be built")

@@ -76,6 +83,7 @@ IF(WITH_ORACLE)
SET(HAVE_ORACLE TRUE)
ENDIF(WITH_ORACLE)


# try to configure and build python bindings by default
SET (WITH_BINDINGS TRUE CACHE BOOL "Determines whether python bindings should be built")
IF (WITH_BINDINGS)
@@ -56,5 +56,7 @@

#cmakedefine MAPSERVER_SKIP_ECW

#cmakedefine MAPSERVER_HAVE_PYTHON_PLUGINS

#endif

@@ -22,7 +22,7 @@ SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})
#
# NOTE: regular project 'make install' is unaffected

# Other target dependenciess will be added, per staged resource
# Other target dependencies will be added, per staged resource
ADD_CUSTOM_TARGET(staged-plugins)

# Plugins can also be staged with CMake option at build time
@@ -163,6 +163,27 @@ ENDIF(UNIX AND NOT SIP_VERSION_NUM LESS 265984)

ADD_SIP_PYTHON_MODULE(qgis._gui gui/gui.sip qgis_core qgis_gui)

SET(PY_MODULES core gui analysis networkanalysis)

# server module
IF (WITH_SERVER_PLUGINS)
INCLUDE_DIRECTORIES(
../src/mapserver
${CMAKE_BINARY_DIR}/src/mapserver
)

SET(PY_MODULES ${PY_MODULES} server)

FILE(GLOB sip_files_server
server/*.sip
)
SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_server})
SET(SIP_EXTRA_OPTIONS ${PYQT4_SIP_FLAGS} -o -a ${CMAKE_BINARY_DIR}/python/qgis.server.api)
ADD_SIP_PYTHON_MODULE(qgis._server server/server.sip qgis_core qgis_server)

ENDIF (WITH_SERVER_PLUGINS)


# additional analysis includes
INCLUDE_DIRECTORIES(
../src/analysis/vector
@@ -234,7 +255,7 @@ ENDIF(WITH_CUSTOM_WIDGETS)
# Plugin utilities files to copy to staging or install
SET(PY_FILES
__init__.py
utils.py
utils.py
)

ADD_CUSTOM_TARGET(pyutils ALL)
@@ -251,7 +272,7 @@ FOREACH(pyfile ${PY_FILES})
PY_COMPILE(pyutils "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${pyfile}")
ENDFOREACH(pyfile)

FOREACH(module core gui analysis networkanalysis)
FOREACH(module ${PY_MODULES})
ADD_CUSTOM_TARGET(py${module} ALL)
ADD_DEPENDENCIES(py${module} python_module_qgis__${module})
FILE(GLOB_RECURSE PY_FILES "${module}/*.py")
@@ -0,0 +1 @@
from qgis._server import *
@@ -0,0 +1,38 @@
/***************************************************************************
qgscapabilitiescache.sip

A cache for capabilities xml documents (by configuration file path)
-------------------
begin : 2014-09-10
copyright : (C) 2014 by Alessandro Pasotti
email : a dot pasotti at itopen dot it
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \class QgsCapabilitiesCache
* \brief A cache for capabilities xml documents (by configuration file path)
*/
class QgsCapabilitiesCache: public QObject
{
%TypeHeaderCode
#include "qgscapabilitiescache.h"
%End
public:

/**Returns cached capabilities document (or 0 if document for configuration file not in cache)*/
const QDomDocument* searchCapabilitiesDocument( QString configFilePath, QString version );
/**Inserts new capabilities document (creates a copy of the document, does not take ownership)*/
void insertCapabilitiesDocument( QString configFilePath, QString version, const QDomDocument* doc );

};


@@ -0,0 +1,42 @@
/***************************************************************************
qgsmapserviceexception.sip

QGIS Server exception
-------------------
begin : 2014-09-10
copyright : (C) 2014 by Alessandro Pasotti
email : a dot pasotti at itopen dot it
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


/**
* \class QgsMapServiceException
* \brief Exception class for WMS service exceptions.
*
* The most important codes are:
* * "InvalidFormat"
* * "Invalid CRS"
* * "LayerNotDefined" / "StyleNotDefined"
* * "OperationNotSupported"
*/

class QgsMapServiceException
{
%TypeHeaderCode
#include <qgsmapserviceexception.h>
%End
public:
QgsMapServiceException( const QString& code, const QString& message );
QString code() const;
QString message() const;

};
@@ -0,0 +1,90 @@
/***************************************************************************
qgsrequesthandler.sip

This class is an interface hiding the details of reading input and
writing output from/to a wms request mechanism
-------------------
begin : 2014-09-10
copyright : (C) 2014 by Alessandro Pasotti
email : a dot pasotti at itopen dot it
***************************************************************************/


/**
* \class QgsRequestHandler
* \brief This class is an interface hiding the details of reading input and
* writing output from/to a wms request mechanism.
*
* Examples of possible mechanisms are cgi Get, cgi Post, SOAP or the usage
* as a standalone command line executable
*/

class QgsRequestHandler
{
%TypeHeaderCode
#include "qgsmapserviceexception.h"
#include "qgsrequesthandler.h"

%End

public:

/**Set an HTTP header*/
virtual void setHeader( const QString &name, const QString &value ) = 0;
/**Remove an HTTP header*/
virtual int removeHeader( const QString &name ) = 0;
/**Delete all HTTP headers*/
virtual void clearHeaders( ) = 0;
/**Returns the response body*/
virtual QByteArray body();
/**Append the bytestream to response body*/
virtual void appendBody( const QByteArray &body) = 0;
/**Clears the response body*/
virtual void clearBody( ) = 0;
/**Set the info format string such as "text/xml"*/
virtual void setInfoFormat( const QString &format ) = 0;
/**Check wether there is any header set or the body is not empty*/
virtual bool responseReady() const = 0;
/**Pointer to last raised exception*/
virtual bool exceptionRaised() const = 0;
/**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( );
/**Set a request parameter*/
virtual void setParameter(const QString &key, const QString &value) = 0;
/**Remove a request parameter*/
virtual int removeParameter(const QString &key) = 0;
/**Return a request parameter*/
virtual QString parameter(const QString &key) const = 0;
/**Return the image format*/
QString format() const;
/**Return the format string as requested by the client*/
QString infoFormat() const;
/**Allow plugins to return a QgsMapServiceException*/
virtual void setServiceException( QgsMapServiceException ex /Transfer/) = 0;

private:

/* Not yet part of the API */

virtual void sendHeaders( ) const = 0;
virtual void sendBody( ) const = 0;

/**Send out the response writing to FCGI stdout*/
virtual void sendResponse( ) const = 0;

virtual void parseInput() = 0;
virtual void setGetMapResponse( const QString& service, QImage* img, int imageQuality ) = 0;
virtual void setGetCapabilitiesResponse( const QDomDocument& doc ) = 0;
virtual void setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) = 0;
virtual void setGetStyleResponse( const QDomDocument& doc ) = 0;
virtual void setGetPrintResponse( QByteArray* ba ) = 0;
virtual bool startGetFeatureResponse( QByteArray* ba, const QString& infoFormat ) = 0;
virtual void setGetFeatureResponse( QByteArray* ba ) = 0;
virtual void endGetFeatureResponse( QByteArray* ba ) = 0;
virtual void setGetCoverageResponse( QByteArray* ba ) = 0;


};
@@ -0,0 +1,67 @@
/***************************************************************************
qgsseerverfilter.h

Server I/O filters class for Qgis Mapserver for use by plugins
-------------------
begin : 2014-09-10
copyright : (C) 2014 by Alessandro Pasotti
email : a dot pasotti at itopen dot it
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \class QgsServerFilter
* \brief Class defining I/O filters for Qgis Mapserver and
* implemented in plugins.
*
* Filters can define any (or none) of the following hooks:
* * requestReady() - called when request is ready
* * responseComplete() - called when the response is complete
* after core services have returned to main loop
* * sendResponse() - called just before sending output to FGCI
*/

class QgsServerFilter
{
%TypeHeaderCode
#include "qgsserverfilter.h"
#include "qgsserverinterface.h"
%End

public:

/** Constructor
* QgsServerInterface passed to plugins constructors
* and must be passed to QgsServerFilter instances.
*/
QgsServerFilter( QgsServerInterface* serverInterface);
/** Destructor */
virtual ~QgsServerFilter();
/** Return the QgsServerInterface instance*/
QgsServerInterface* serverInterface( );
/** Method called when the QgsRequestHandler is ready and populated with
* parameters, just before entering the main switch for core services.*/
virtual void requestReady();
/** Method called when the QgsRequestHandler processing has done and
* the response is ready, just after the main switch for core services
* and before final sending response to FCGI stdout.
*/
virtual void responseComplete();
/** Method called when the QgsRequestHandler sends its data to FCGI stdout.
* This normally occours at the end of core services processing just after
* the responseComplete() plugin hook. For streaming services (like WFS on
* getFeature requests, sendResponse() might have been called several times
* before the response is complete: in this particular case, sendResponse()
* is called once for each feature before hitting responseComplete()
*/
virtual void sendResponse();

};
@@ -0,0 +1,60 @@
/***************************************************************************
qgsserverinterface.sip

Class defining the interface made available to server plugins.
-------------------
begin : 2014-09-10
copyright : (C) 2014 by Alessandro Pasotti
email : a dot pasotti at itopen dot it
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \class QgsServerInterface
* \brief Class defining the interface made available to server plugins.
*
* This class provides methods to access the request handler and
* the capabilties cache. A method to read the environment
* variables set in the main FCGI loop is also available.
* Plugins can add listeners (instances of QgsServerFilter) with
* a certain priority through the registerFilter( QgsServerFilter* , int) method.
*/


typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;

class QgsServerInterface
{
%TypeHeaderCode
#include "qgsserverinterface.h"
%End

public:
/**Returns the current request handler*/
virtual QgsRequestHandler* requestHandler( ) = 0 /KeepReference/;
/**Returns the capabilities cache*/
virtual QgsCapabilitiesCache* capabiblitiesCache() = 0 /KeepReference/;
// Tansfer ownership to avoid garbage collector to call dtor
/** Register a filter with the given priority. The filter's requestReady()
* and responseReady() methods will be called from the loop*/
virtual void registerFilter( QgsServerFilter* filter /Transfer/, int priority = 0 ) = 0;
/**Return an environment variable set by FCGI*/
virtual QString getEnv(const QString& name ) const = 0;
// Commented because of problems with typedef QgsServerFiltersMap, provided
// methods to alter the filters map into QgsRequestHandler API
// virtual QgsServerFiltersMap filters( ) = 0;

private:
/** Constructor */
QgsServerInterface( );

};

0 comments on commit 35556de

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