Skip to content
Permalink
Browse files

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.
  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 485ea82 commit d8a05ccef46ab40253a0d80c33b819c74c87bb63
@@ -56,6 +56,7 @@ SET ( qgis_mapserv_SRCS
qgsserverresponse.cpp
qgsfcgiserverresponse.cpp
qgsbufferserverresponse.cpp
qgsfilterresponsedecorator.cpp
#----------------------------
)
IF("${Qt5Network_VERSION}" VERSION_LESS "5.0.0")
@@ -0,0 +1,71 @@
/***************************************************************************
qgsfilterresponsedecorator.cpp
Define response wrapper for fcgi response
-------------------
begin : 2017-01-03
copyright : (C) 2017 by David Marteau
email : david dot marteau at 3liz dot com
***************************************************************************/

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

#include "qgsconfig.h"
#include "qgsfilterresponsedecorator.h"

QgsFilterResponseDecorator::QgsFilterResponseDecorator( QgsServerFiltersMap filters, QgsServerResponse& response )
: mFilters(filters)
, mResponse(response)
{
}

QgsFilterResponseDecorator::~QgsFilterResponseDecorator()
{

}

void QgsFilterResponseDecorator::start()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsServerFiltersMap::const_iterator filtersIterator;
for ( filtersIterator = mFilters.constBegin(); filtersIterator != mFilters.constEnd(); ++filtersIterator )
{
filtersIterator.value()->requestReady();
}
#endif
}

void QgsFilterResponseDecorator::finish()
{

#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsServerFiltersMap::const_iterator filtersIterator;
for ( filtersIterator = mFilters.constBegin(); filtersIterator != mFilters.constEnd(); ++filtersIterator )
{
filtersIterator.value()->responseComplete();
}
#endif
// Will call 'flush'
mResponse.finish();
}

void QgsFilterResponseDecorator::flush()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsServerFiltersMap::const_iterator filtersIterator;
for ( filtersIterator = mFilters.constBegin(); filtersIterator != mFilters.constEnd(); ++filtersIterator )
{
filtersIterator.value()->sendResponse();
}
#endif
mResponse.flush();
}


@@ -0,0 +1,78 @@
/***************************************************************************
qgsfilterresponsedecorator.h
Define response adapter for handling filter's hooks
-------------------
begin : 2017-01-05
copyright : (C) 2017 by David Marteau
email : david dot marteau at 3liz dot com
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef QGSFILTERRESPONSEDECORATOR_H
#define QGSFILTERRESPONSEDECORATOR_H

#include "qgsserverresponse.h"
#include "qgsserverfilter.h"

/**
* \ingroup server
* QgsFilterResponseDecorator
* Class defining decorator for calling filter's hooks
*/
class QgsFilterResponseDecorator: public QgsServerResponse
{
public:

QgsFilterResponseDecorator( QgsServerFiltersMap filters, QgsServerResponse& response );
~QgsFilterResponseDecorator();

/**
* Call flter's requestReady() method
*/
void start();

// QgsServerResponse overrides

void setHeader( const QString& key, const QString& value ) override { mResponse.setHeader(key, value); }

void clearHeader( const QString& key ) override { mResponse.clearHeader( key ); }

QString getHeader( const QString& key ) const override { return mResponse.getHeader( key ); }

QList<QString> headerKeys() const override { return mResponse.headerKeys(); }

bool headersWritten() const override { return mResponse.headersWritten(); }

void setReturnCode( int code ) override { mResponse.setReturnCode( code ); }

void sendError( int code, const QString& message ) override { mResponse.sendError( code, message ); }

QIODevice* io() override { return mResponse.io(); }

void finish() override;

void flush() override;

void clear() override { mResponse.clear(); }



private:
QgsServerFiltersMap mFilters;
QgsServerResponse& mResponse;
};

#endif





@@ -18,9 +18,12 @@
#ifndef QGSOWSSERVER_H
#define QGSOWSSERVER_H

#include "qgsconfig.h"
#include "qgsrequesthandler.h"
#ifdef HAVE_SERVER_PYTHON_PLUGINS
#include "qgsaccesscontrol.h"
#else
class QgsAccessControl;
#endif

#include <QHash>
@@ -34,16 +37,12 @@ class QgsOWSServer
const QString& configFilePath
, const QMap<QString, QString>& parameters
, QgsRequestHandler* rh
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* ac
#endif
)
: mParameters( parameters )
, mRequestHandler( rh )
, mConfigFilePath( configFilePath )
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, mAccessControl( ac )
#endif
{}
virtual ~QgsOWSServer() = default;

@@ -61,10 +60,11 @@ class QgsOWSServer
QMap<QString, QString> mParameters;
QgsRequestHandler* mRequestHandler;
QString mConfigFilePath;
#ifdef HAVE_SERVER_PYTHON_PLUGINS

//! The access control helper
const QgsAccessControl* mAccessControl;

#ifdef HAVE_SERVER_PYTHON_PLUGINS
/** Apply filter strings from the access control to the layers.
* @param layer the concerned layer
* @param originalLayerFilters the original layer filter
@@ -123,26 +123,8 @@ void QgsRequestHandler::setInfoFormat( const QString &format )

}


#ifdef HAVE_SERVER_PYTHON_PLUGINS
void QgsRequestHandler::setPluginFilters( const QgsServerFiltersMap& pluginFilters )
{
mPluginFilters = pluginFilters;
}
#endif

void QgsRequestHandler::sendResponse()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
// Plugin hook
// Iterate filters and call their sendResponse() method
QgsServerFiltersMap::const_iterator filtersIterator;
for ( filtersIterator = mPluginFilters.constBegin(); filtersIterator != mPluginFilters.constEnd(); ++filtersIterator )
{
filtersIterator.value()->sendResponse();
}
#endif

// Send data to output
mResponse.flush();
}
@@ -20,12 +20,6 @@
#ifndef QGSREQUESTHANDLER_H
#define QGSREQUESTHANDLER_H

//Needed for HAVE_SERVER_PYTHON_PLUGINS
#include "qgsconfig.h"
#ifdef HAVE_SERVER_PYTHON_PLUGINS
#include "qgsserverfilter.h"
#endif

#include <QMap>
#include <QString>
#include <QStringList>
@@ -138,13 +132,6 @@ class SERVER_EXPORT QgsRequestHandler
//! Remove a request parameter
void removeParameter( const QString &key );

#ifdef HAVE_SERVER_PYTHON_PLUGINS
/** Allow core services to call plugin hooks through sendResponse()
* @note not available in Python bindings
*/
void setPluginFilters( const QgsServerFiltersMap &pluginFilters );
#endif

/** Parses the input and creates a request neutral Parameter/Value map
* @note not available in Python bindings
*/
@@ -183,9 +170,6 @@ class SERVER_EXPORT QgsRequestHandler
static QRgb boxColor( const QgsColorBox& box, int boxPixels );
// TODO: if HAVE_SERVER_PYTHON

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

0 comments on commit d8a05cc

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