Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add plugin files and define
  • Loading branch information
elpaso committed Nov 26, 2014
1 parent 0f87533 commit 4c6bf30
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/mapserver/qgis_map_serv.cpp
Expand Up @@ -37,6 +37,11 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsmaplayerregistry.h"
#include "qgsserverlogger.h"
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
#include "qgsserverplugins.h"
#include "qgsserverfilter.h"
#include "qgsserverinterfaceimpl.h"
#endif

#include <QDomDocument>
#include <QNetworkDiskCache>
Expand Down Expand Up @@ -315,6 +320,18 @@ int main( int argc, char * argv[] )
int logLevel = QgsServerLogger::instance()->logLevel();
QTime time; //used for measuring request time if loglevel < 1

#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
// Create the interface
QgsServerInterfaceImpl serverIface( &capabilitiesCache );
// Init plugins
if (! QgsServerPlugins::initPlugins( &serverIface ) )
{
QgsMessageLog::logMessage( "No server plugins are available", "Server", QgsMessageLog::INFO );
}
// Store plugin filters for faster access
QMultiMap<int, QgsServerFilter*> pluginFilters = serverIface.filters();
#endif

while ( fcgi_accept() >= 0 )
{
QgsMapLayerRegistry::instance()->removeAllMapLayers();
Expand All @@ -340,6 +357,17 @@ int main( int argc, char * argv[] )
theRequestHandler->setServiceException( e );
}

#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
// Set the request handler into the interface for plugins to manipulate it
serverIface.setRequestHandler( theRequestHandler.data() );
// Iterate filters and call their requestReady() method
QgsServerFiltersMap::const_iterator filtersIterator;
for( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator)
{
filtersIterator.value()->requestReady();
}
#endif

// Copy the parameters map
QMap<QString, QString> parameterMap( theRequestHandler->parameterMap() );

Expand Down Expand Up @@ -398,6 +426,14 @@ int main( int argc, char * argv[] )
} // end switch
} // end if not exception raised

#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
// Call responseReady plugin filters
for(filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator)
{
filtersIterator.value()->responseReady();
}
#endif

theRequestHandler->sendResponse();

if ( logLevel < 1 )
Expand Down
49 changes: 49 additions & 0 deletions src/mapserver/qgsserverfilter.cpp
@@ -0,0 +1,49 @@
/***************************************************************************
qgsseerverfilter.cpp
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. *
* *
***************************************************************************/


#include "qgsserverfilter.h"
#include "qgslogger.h"

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

QgsServerFilter::QgsServerFilter(QgsServerInterface *serverInterface):
mServerInterface( serverInterface )
{
}

QgsServerFilter::~QgsServerFilter()
{
}


void QgsServerFilter::requestReady()
{
QgsDebugMsg( "QgsServerFilter plugin default requestReady called");
}

void QgsServerFilter::responseReady()
{
QgsDebugMsg( "QgsServerFilter plugin default responseReady called");
}

55 changes: 55 additions & 0 deletions src/mapserver/qgsserverfilter.h
@@ -0,0 +1,55 @@
/***************************************************************************
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. *
* *
***************************************************************************/

#ifndef QGSSERVERFILTER_H
#define QGSSERVERFILTER_H

#include <QMultiMap>

class QgsServerInterface;

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

class QgsServerFilter
{

public:

/** Constructor */
QgsServerFilter( QgsServerInterface* serverInterface );
/** Destructor */
virtual ~QgsServerFilter();
QgsServerInterface* serverInterface( ) { return mServerInterface; }
virtual void requestReady();
virtual void responseReady();

private:

QgsServerInterface* mServerInterface;

};

typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;


#endif // QGSSERVERFILTER_H
29 changes: 29 additions & 0 deletions src/mapserver/qgsserverinterface.cpp
@@ -0,0 +1,29 @@
/***************************************************************************
* qgsserverinterface.cpp
* Abstract base class for interfaces to functions in QgsServer
* -------------------
* begin : 2014-29-09
* copyright : (C) 2014 by Alessandro Pasotti
* email : a dot pasotti at itopen 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 "qgsserverinterface.h"

QgsServerInterface::QgsServerInterface()
{


}

QgsServerInterface::~QgsServerInterface()
{
}
52 changes: 52 additions & 0 deletions src/mapserver/qgsserverinterface.h
@@ -0,0 +1,52 @@
/***************************************************************************
qgsseerversinterface.h
Interface class for exposing functions in Qgis Server 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. *
* *
***************************************************************************/

#ifndef QGSSERVERINTERFACE_H
#define QGSSERVERINTERFACE_H

#include "qgscapabilitiescache.h"
#include "qgsrequesthandler.h"
#include "qgsserverfilter.h"

/**
* QgsServerInterface
* Class defining interfaces exposed by Qgis Mapserver and
* made available to plugins.
*
*/

class QgsServerInterface
{

public:

/** Constructor */
QgsServerInterface( );

/** Destructor */
virtual ~QgsServerInterface() = 0;

virtual void setRequestHandler( QgsRequestHandler* requestHandler ) = 0;
virtual QgsCapabilitiesCache* capabiblitiesCache() = 0;
virtual QgsRequestHandler* requestHandler( ) = 0;
virtual void registerFilter( QgsServerFilter* filter, int priority = 0 ) = 0;
virtual QgsServerFiltersMap filters( ) = 0;

};

#endif // QGSSERVERINTERFACE_H
43 changes: 43 additions & 0 deletions src/mapserver/qgsserverinterfaceimpl.cpp
@@ -0,0 +1,43 @@
/***************************************************************************
qgsseerversinterface.h
Interface class for exposing functions in 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. *
* *
***************************************************************************/


#include "qgsserverinterfaceimpl.h"


QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache* capCache ) :
mCapabilitiesCache( capCache )
{
mRequestHandler = NULL;
}


/** Destructor */
QgsServerInterfaceImpl::~QgsServerInterfaceImpl()
{
}

void QgsServerInterfaceImpl::setRequestHandler( QgsRequestHandler * requestHandler)
{
mRequestHandler = requestHandler;
}

void QgsServerInterfaceImpl::registerFilter( QgsServerFilter *filter, int priority )
{
mFilters.insert(priority, filter);
}
61 changes: 61 additions & 0 deletions src/mapserver/qgsserverinterfaceimpl.h
@@ -0,0 +1,61 @@
/***************************************************************************
qgsseerversinterface.h
Interface class for exposing functions in 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. *
* *
***************************************************************************/

#ifndef QGSSERVERINTERFACEIMPL_H
#define QGSSERVERINTERFACEIMPL_H

#include "qgsserverinterface.h"
#include "qgscapabilitiescache.h"
#include "qgsgetrequesthandler.h"
#include "qgspostrequesthandler.h"
#include "qgssoaprequesthandler.h"
#include "qgsmaprenderer.h"

/**
* QgsServerInterface
* Class defining interfaces exposed by Qgis Mapserver and
* made available to plugins.
*
*/

class QgsServerInterfaceImpl : public QgsServerInterface
{

public:

/** Constructor */
QgsServerInterfaceImpl( QgsCapabilitiesCache *capCache );

/** Destructor */
~QgsServerInterfaceImpl();

void setRequestHandler( QgsRequestHandler* requestHandler );
QgsCapabilitiesCache* capabiblitiesCache() { return mCapabilitiesCache; }
QgsRequestHandler* requestHandler( ) { return mRequestHandler; }
void registerFilter( QgsServerFilter *filter, int priority = 0 );
QgsServerFiltersMap filters( ) { return mFilters; }

private:

QgsServerFiltersMap mFilters;
QgsCapabilitiesCache* mCapabilitiesCache;
QgsRequestHandler* mRequestHandler;

};

#endif // QGSSERVERINTERFACEIMPL_H

0 comments on commit 4c6bf30

Please sign in to comment.