Skip to content

Commit 5f44cc5

Browse files
committedNov 26, 2014
Added serve python plugins
1 parent f2608b3 commit 5f44cc5

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
lines changed
 

‎python/server/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from qgis._server import *
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
/**A cache for capabilities xml documents (by configuration file path)*/
3+
class QgsCapabilitiesCache: public QObject
4+
{
5+
%TypeHeaderCode
6+
#include <QDomDocument>
7+
#include <QFileSystemWatcher>
8+
#include <QHash>
9+
#include <QObject>
10+
#include "qgscapabilitiescache.h"
11+
%End
12+
public:
13+
14+
/**Returns cached capabilities document (or 0 if document for configuration file not in cache)*/
15+
const QDomDocument* searchCapabilitiesDocument( QString configFilePath, QString version );
16+
/**Inserts new capabilities document (creates a copy of the document, does not take ownership)*/
17+
void insertCapabilitiesDocument( QString configFilePath, QString version, const QDomDocument* doc );
18+
19+
};
20+
21+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
/**Exception class for WMS service exceptions. The most important codes are:
3+
"InvalidFormat"
4+
"Invalid CRS"
5+
"LayerNotDefined" / "StyleNotDefined"
6+
"OperationNotSupported"*/
7+
8+
class QgsMapServiceException
9+
{
10+
%TypeHeaderCode
11+
#include <qgsmapserviceexception.h>
12+
%End
13+
public:
14+
QgsMapServiceException( const QString& code, const QString& message );
15+
QString code() const;
16+
QString message() const;
17+
18+
};

‎python/server/qgsrequesthandler.sip

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**This class is an interface hiding the details of reading input and writing output from/to a wms request mechanism.
2+
Examples of possible mechanisms are cgi Get, cgi Post, SOAP or the usage as a standalone command line executable*/
3+
class QgsRequestHandler
4+
{
5+
%TypeHeaderCode
6+
#include "qgsmapserviceexception.h"
7+
#include "qgsrequesthandler.h"
8+
9+
%End
10+
11+
public:
12+
13+
virtual void parseInput() = 0;
14+
virtual void setGetMapResponse( const QString& service, QImage* img, int imageQuality ) = 0;
15+
virtual void setGetCapabilitiesResponse( const QDomDocument& doc ) = 0;
16+
virtual void setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) = 0;
17+
virtual void setServiceException( QgsMapServiceException ex ) = 0;
18+
virtual void setGetStyleResponse( const QDomDocument& doc ) = 0;
19+
virtual void setGetPrintResponse( QByteArray* ba ) = 0;
20+
virtual bool startGetFeatureResponse( QByteArray* ba, const QString& infoFormat ) = 0;
21+
virtual void setGetFeatureResponse( QByteArray* ba ) = 0;
22+
virtual void endGetFeatureResponse( QByteArray* ba ) = 0;
23+
virtual void setGetCoverageResponse( QByteArray* ba ) = 0;
24+
25+
/**Set an HTTP header*/
26+
virtual void setHeader( const QString &name, const QString &value ) = 0;
27+
/**Remove an HTTP header*/
28+
virtual int removeHeader( const QString &name ) = 0;
29+
/**Delete all HTTP headers*/
30+
virtual void clearHeaders( ) = 0;
31+
/**Append the bytestream to response body*/
32+
virtual void appendBody( const QByteArray &body) = 0;
33+
/**Clears the response body*/
34+
virtual void clearBody( ) = 0;
35+
virtual void setInfoFormat( const QString &format ) = 0;
36+
virtual void sendResponse( ) const = 0;
37+
virtual bool responseReady() const = 0;
38+
/**Pointer to last raised exception*/
39+
virtual bool exceptionRaised() const = 0;
40+
QMap<QString, QString> parameterMap( );
41+
/**Set a request parameter*/
42+
virtual void setParameter(const QString &key, const QString &value) = 0;
43+
/**Remove a request parameter*/
44+
virtual int removeParameter(const QString &key) = 0;
45+
/**Return a request parameter*/
46+
virtual QString parameter(const QString &key) const = 0;
47+
QString format() const;
48+
49+
protected:
50+
51+
virtual void sendHeaders( ) const = 0;
52+
virtual void sendBody( ) const = 0;
53+
54+
55+
};

‎python/server/qgsserverfilter.sip

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/***************************************************************************
2+
qgsseerverfilter.h
3+
Server I/O filters class for Qgis Mapserver for use by plugins
4+
-------------------
5+
begin : 2014-09-10
6+
copyright : (C) 2014 by Alessandro Pasotti
7+
email : a dot pasotti at itopen dot it
8+
***************************************************************************/
9+
10+
/***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************/
18+
19+
/**
20+
* QgsServerFilter
21+
* Class defining I/O filters for Qgis Mapserver and
22+
* implemented in plugins
23+
*
24+
*/
25+
26+
class QgsServerFilter
27+
{
28+
%TypeHeaderCode
29+
#include "qgsserverfilter.h"
30+
#include "qgsserverinterface.h"
31+
%End
32+
33+
public:
34+
35+
/** Constructor */
36+
QgsServerFilter( QgsServerInterface* serverInterface /Transfer/);
37+
/** Destructor */
38+
virtual ~QgsServerFilter();
39+
QgsServerInterface* serverInterface( );
40+
virtual void requestReady();
41+
virtual void responseReady();
42+
43+
};

‎python/server/qgsserverinterface.sip

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* \class QgsServerInterface
3+
* \brief Class defining interfaces
4+
* made available to server plugins.
5+
*
6+
* Only functionality exposed by QgisServerInterface can be used in server plugins.
7+
*/
8+
9+
10+
typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;
11+
12+
class QgsServerInterface
13+
{
14+
%TypeHeaderCode
15+
#include "qgsserverinterface.h"
16+
%End
17+
18+
public:
19+
//virtual void setRequestHandler( QgsRequestHandler* requestHandler) = 0;
20+
virtual QgsCapabilitiesCache* capabiblitiesCache() = 0 /KeepReference/;
21+
virtual QgsRequestHandler* requestHandler( ) = 0 /KeepReference/;
22+
// Tansfer ownership to avoid garbage collector to call dtor
23+
virtual void registerFilter( QgsServerFilter* filter /Transfer/, int priority = 0 ) = 0;
24+
// Commented because of problem with typedef QgsServerFiltersMap
25+
// virtual QgsServerFiltersMap filters( ) = 0;
26+
27+
private:
28+
/** Constructor */
29+
QgsServerInterface( );
30+
31+
};
32+

‎python/server/qgsserverlogger.sip

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/***************************************************************************
2+
qgsserverlogger.h
3+
-----------------
4+
begin : May 5, 2014
5+
copyright : (C) 2014 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
19+
/**Writes message log into server logfile*/
20+
class QgsServerLogger: public QObject
21+
{
22+
%TypeHeaderCode
23+
#include "qgsserverlogger.h"
24+
%End
25+
26+
public:
27+
static QgsServerLogger* instance();
28+
29+
int logLevel();
30+
31+
public slots:
32+
void logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level );
33+
34+
};

‎python/server/server.sip

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%Module(name=qgis._server,
2+
version=0,
3+
keyword_arguments="Optional")
4+
5+
6+
%Import QtCore/QtCoremod.sip
7+
%Import QtGui/QtGuimod.sip
8+
%Import QtXml/QtXmlmod.sip
9+
10+
%Import core/core.sip
11+
12+
%Include qgsserverfilter.sip
13+
%Include qgsserverlogger.sip
14+
%Include qgsmapserviceexception.sip
15+
%Include qgscapabilitiescache.sip
16+
%Include qgsrequesthandler.sip
17+
%Include qgsserverinterface.sip

0 commit comments

Comments
 (0)
Please sign in to comment.