Skip to content

Commit d8a05cc

Browse files
committed
Add plugin hook support decorator
- Add plugin hook support decorator for use in service modules - Remove handling of plugin hook with request handler (not needed anymore) - Reduce usage of HAVE_SERVER_PYTHON_PLUGINS by using forward opaque declaration.
1 parent 485ea82 commit d8a05cc

15 files changed

+345
-287
lines changed

src/server/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ SET ( qgis_mapserv_SRCS
5656
qgsserverresponse.cpp
5757
qgsfcgiserverresponse.cpp
5858
qgsbufferserverresponse.cpp
59+
qgsfilterresponsedecorator.cpp
5960
#----------------------------
6061
)
6162
IF("${Qt5Network_VERSION}" VERSION_LESS "5.0.0")
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/***************************************************************************
2+
qgsfilterresponsedecorator.cpp
3+
4+
Define response wrapper for fcgi response
5+
-------------------
6+
begin : 2017-01-03
7+
copyright : (C) 2017 by David Marteau
8+
email : david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
20+
#include "qgsconfig.h"
21+
#include "qgsfilterresponsedecorator.h"
22+
23+
QgsFilterResponseDecorator::QgsFilterResponseDecorator( QgsServerFiltersMap filters, QgsServerResponse& response )
24+
: mFilters(filters)
25+
, mResponse(response)
26+
{
27+
}
28+
29+
QgsFilterResponseDecorator::~QgsFilterResponseDecorator()
30+
{
31+
32+
}
33+
34+
void QgsFilterResponseDecorator::start()
35+
{
36+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
37+
QgsServerFiltersMap::const_iterator filtersIterator;
38+
for ( filtersIterator = mFilters.constBegin(); filtersIterator != mFilters.constEnd(); ++filtersIterator )
39+
{
40+
filtersIterator.value()->requestReady();
41+
}
42+
#endif
43+
}
44+
45+
void QgsFilterResponseDecorator::finish()
46+
{
47+
48+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
49+
QgsServerFiltersMap::const_iterator filtersIterator;
50+
for ( filtersIterator = mFilters.constBegin(); filtersIterator != mFilters.constEnd(); ++filtersIterator )
51+
{
52+
filtersIterator.value()->responseComplete();
53+
}
54+
#endif
55+
// Will call 'flush'
56+
mResponse.finish();
57+
}
58+
59+
void QgsFilterResponseDecorator::flush()
60+
{
61+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
62+
QgsServerFiltersMap::const_iterator filtersIterator;
63+
for ( filtersIterator = mFilters.constBegin(); filtersIterator != mFilters.constEnd(); ++filtersIterator )
64+
{
65+
filtersIterator.value()->sendResponse();
66+
}
67+
#endif
68+
mResponse.flush();
69+
}
70+
71+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/***************************************************************************
2+
qgsfilterresponsedecorator.h
3+
4+
Define response adapter for handling filter's hooks
5+
-------------------
6+
begin : 2017-01-05
7+
copyright : (C) 2017 by David Marteau
8+
email : david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#ifndef QGSFILTERRESPONSEDECORATOR_H
20+
#define QGSFILTERRESPONSEDECORATOR_H
21+
22+
#include "qgsserverresponse.h"
23+
#include "qgsserverfilter.h"
24+
25+
/**
26+
* \ingroup server
27+
* QgsFilterResponseDecorator
28+
* Class defining decorator for calling filter's hooks
29+
*/
30+
class QgsFilterResponseDecorator: public QgsServerResponse
31+
{
32+
public:
33+
34+
QgsFilterResponseDecorator( QgsServerFiltersMap filters, QgsServerResponse& response );
35+
~QgsFilterResponseDecorator();
36+
37+
/**
38+
* Call flter's requestReady() method
39+
*/
40+
void start();
41+
42+
// QgsServerResponse overrides
43+
44+
void setHeader( const QString& key, const QString& value ) override { mResponse.setHeader(key, value); }
45+
46+
void clearHeader( const QString& key ) override { mResponse.clearHeader( key ); }
47+
48+
QString getHeader( const QString& key ) const override { return mResponse.getHeader( key ); }
49+
50+
QList<QString> headerKeys() const override { return mResponse.headerKeys(); }
51+
52+
bool headersWritten() const override { return mResponse.headersWritten(); }
53+
54+
void setReturnCode( int code ) override { mResponse.setReturnCode( code ); }
55+
56+
void sendError( int code, const QString& message ) override { mResponse.sendError( code, message ); }
57+
58+
QIODevice* io() override { return mResponse.io(); }
59+
60+
void finish() override;
61+
62+
void flush() override;
63+
64+
void clear() override { mResponse.clear(); }
65+
66+
67+
68+
private:
69+
QgsServerFiltersMap mFilters;
70+
QgsServerResponse& mResponse;
71+
};
72+
73+
#endif
74+
75+
76+
77+
78+

src/server/qgsowsserver.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
#ifndef QGSOWSSERVER_H
1919
#define QGSOWSSERVER_H
2020

21+
#include "qgsconfig.h"
2122
#include "qgsrequesthandler.h"
2223
#ifdef HAVE_SERVER_PYTHON_PLUGINS
2324
#include "qgsaccesscontrol.h"
25+
#else
26+
class QgsAccessControl;
2427
#endif
2528

2629
#include <QHash>
@@ -34,16 +37,12 @@ class QgsOWSServer
3437
const QString& configFilePath
3538
, const QMap<QString, QString>& parameters
3639
, QgsRequestHandler* rh
37-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
3840
, const QgsAccessControl* ac
39-
#endif
4041
)
4142
: mParameters( parameters )
4243
, mRequestHandler( rh )
4344
, mConfigFilePath( configFilePath )
44-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
4545
, mAccessControl( ac )
46-
#endif
4746
{}
4847
virtual ~QgsOWSServer() = default;
4948

@@ -61,10 +60,11 @@ class QgsOWSServer
6160
QMap<QString, QString> mParameters;
6261
QgsRequestHandler* mRequestHandler;
6362
QString mConfigFilePath;
64-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
63+
6564
//! The access control helper
6665
const QgsAccessControl* mAccessControl;
6766

67+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
6868
/** Apply filter strings from the access control to the layers.
6969
* @param layer the concerned layer
7070
* @param originalLayerFilters the original layer filter

src/server/qgsrequesthandler.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,8 @@ void QgsRequestHandler::setInfoFormat( const QString &format )
123123

124124
}
125125

126-
127-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
128-
void QgsRequestHandler::setPluginFilters( const QgsServerFiltersMap& pluginFilters )
129-
{
130-
mPluginFilters = pluginFilters;
131-
}
132-
#endif
133-
134126
void QgsRequestHandler::sendResponse()
135127
{
136-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
137-
// Plugin hook
138-
// Iterate filters and call their sendResponse() method
139-
QgsServerFiltersMap::const_iterator filtersIterator;
140-
for ( filtersIterator = mPluginFilters.constBegin(); filtersIterator != mPluginFilters.constEnd(); ++filtersIterator )
141-
{
142-
filtersIterator.value()->sendResponse();
143-
}
144-
#endif
145-
146128
// Send data to output
147129
mResponse.flush();
148130
}

src/server/qgsrequesthandler.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#ifndef QGSREQUESTHANDLER_H
2121
#define QGSREQUESTHANDLER_H
2222

23-
//Needed for HAVE_SERVER_PYTHON_PLUGINS
24-
#include "qgsconfig.h"
25-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
26-
#include "qgsserverfilter.h"
27-
#endif
28-
2923
#include <QMap>
3024
#include <QString>
3125
#include <QStringList>
@@ -138,13 +132,6 @@ class SERVER_EXPORT QgsRequestHandler
138132
//! Remove a request parameter
139133
void removeParameter( const QString &key );
140134

141-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
142-
/** Allow core services to call plugin hooks through sendResponse()
143-
* @note not available in Python bindings
144-
*/
145-
void setPluginFilters( const QgsServerFiltersMap &pluginFilters );
146-
#endif
147-
148135
/** Parses the input and creates a request neutral Parameter/Value map
149136
* @note not available in Python bindings
150137
*/
@@ -183,9 +170,6 @@ class SERVER_EXPORT QgsRequestHandler
183170
static QRgb boxColor( const QgsColorBox& box, int boxPixels );
184171
// TODO: if HAVE_SERVER_PYTHON
185172

186-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
187-
QgsServerFiltersMap mPluginFilters;
188-
#endif
189173
//! This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')
190174
QString mFormat;
191175
QString mFormatString; //format string as it is passed in the request (with base)

0 commit comments

Comments
 (0)