Skip to content

Commit

Permalink
Added serve python plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 26, 2014
1 parent f2608b3 commit 5f44cc5
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/server/__init__.py
@@ -0,0 +1 @@
from qgis._server import *
21 changes: 21 additions & 0 deletions python/server/qgscapabilitiescache.sip
@@ -0,0 +1,21 @@

/**A cache for capabilities xml documents (by configuration file path)*/
class QgsCapabilitiesCache: public QObject
{
%TypeHeaderCode
#include <QDomDocument>
#include <QFileSystemWatcher>
#include <QHash>
#include <QObject>
#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 );

};


18 changes: 18 additions & 0 deletions python/server/qgsmapserviceexception.sip
@@ -0,0 +1,18 @@

/**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;

};
55 changes: 55 additions & 0 deletions python/server/qgsrequesthandler.sip
@@ -0,0 +1,55 @@
/**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:

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 setServiceException( QgsMapServiceException ex ) = 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;

/**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;
/**Append the bytestream to response body*/
virtual void appendBody( const QByteArray &body) = 0;
/**Clears the response body*/
virtual void clearBody( ) = 0;
virtual void setInfoFormat( const QString &format ) = 0;
virtual void sendResponse( ) const = 0;
virtual bool responseReady() const = 0;
/**Pointer to last raised exception*/
virtual bool exceptionRaised() const = 0;
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;
QString format() const;

protected:

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


};
43 changes: 43 additions & 0 deletions python/server/qgsserverfilter.sip
@@ -0,0 +1,43 @@
/***************************************************************************
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. *
* *
***************************************************************************/

/**
* QgsServerFilter
* Class defining I/O filters for Qgis Mapserver and
* implemented in plugins
*
*/

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

public:

/** Constructor */
QgsServerFilter( QgsServerInterface* serverInterface /Transfer/);
/** Destructor */
virtual ~QgsServerFilter();
QgsServerInterface* serverInterface( );
virtual void requestReady();
virtual void responseReady();

};
32 changes: 32 additions & 0 deletions python/server/qgsserverinterface.sip
@@ -0,0 +1,32 @@
/**
* \class QgsServerInterface
* \brief Class defining interfaces
* made available to server plugins.
*
* Only functionality exposed by QgisServerInterface can be used in server plugins.
*/


typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;

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

public:
//virtual void setRequestHandler( QgsRequestHandler* requestHandler) = 0;
virtual QgsCapabilitiesCache* capabiblitiesCache() = 0 /KeepReference/;
virtual QgsRequestHandler* requestHandler( ) = 0 /KeepReference/;
// Tansfer ownership to avoid garbage collector to call dtor
virtual void registerFilter( QgsServerFilter* filter /Transfer/, int priority = 0 ) = 0;
// Commented because of problem with typedef QgsServerFiltersMap
// virtual QgsServerFiltersMap filters( ) = 0;

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

};

34 changes: 34 additions & 0 deletions python/server/qgsserverlogger.sip
@@ -0,0 +1,34 @@
/***************************************************************************
qgsserverlogger.h
-----------------
begin : May 5, 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/


/**Writes message log into server logfile*/
class QgsServerLogger: public QObject
{
%TypeHeaderCode
#include "qgsserverlogger.h"
%End

public:
static QgsServerLogger* instance();

int logLevel();

public slots:
void logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level );

};
17 changes: 17 additions & 0 deletions python/server/server.sip
@@ -0,0 +1,17 @@
%Module(name=qgis._server,
version=0,
keyword_arguments="Optional")


%Import QtCore/QtCoremod.sip
%Import QtGui/QtGuimod.sip
%Import QtXml/QtXmlmod.sip

%Import core/core.sip

%Include qgsserverfilter.sip
%Include qgsserverlogger.sip
%Include qgsmapserviceexception.sip
%Include qgscapabilitiescache.sip
%Include qgsrequesthandler.sip
%Include qgsserverinterface.sip

0 comments on commit 5f44cc5

Please sign in to comment.