Skip to content

Commit 4c6bf30

Browse files
committed
Add plugin files and define
1 parent 0f87533 commit 4c6bf30

9 files changed

+472
-0
lines changed

src/mapserver/qgis_map_serv.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include "qgsnetworkaccessmanager.h"
3838
#include "qgsmaplayerregistry.h"
3939
#include "qgsserverlogger.h"
40+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
41+
#include "qgsserverplugins.h"
42+
#include "qgsserverfilter.h"
43+
#include "qgsserverinterfaceimpl.h"
44+
#endif
4045

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

323+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
324+
// Create the interface
325+
QgsServerInterfaceImpl serverIface( &capabilitiesCache );
326+
// Init plugins
327+
if (! QgsServerPlugins::initPlugins( &serverIface ) )
328+
{
329+
QgsMessageLog::logMessage( "No server plugins are available", "Server", QgsMessageLog::INFO );
330+
}
331+
// Store plugin filters for faster access
332+
QMultiMap<int, QgsServerFilter*> pluginFilters = serverIface.filters();
333+
#endif
334+
318335
while ( fcgi_accept() >= 0 )
319336
{
320337
QgsMapLayerRegistry::instance()->removeAllMapLayers();
@@ -340,6 +357,17 @@ int main( int argc, char * argv[] )
340357
theRequestHandler->setServiceException( e );
341358
}
342359

360+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
361+
// Set the request handler into the interface for plugins to manipulate it
362+
serverIface.setRequestHandler( theRequestHandler.data() );
363+
// Iterate filters and call their requestReady() method
364+
QgsServerFiltersMap::const_iterator filtersIterator;
365+
for( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator)
366+
{
367+
filtersIterator.value()->requestReady();
368+
}
369+
#endif
370+
343371
// Copy the parameters map
344372
QMap<QString, QString> parameterMap( theRequestHandler->parameterMap() );
345373

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

429+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
430+
// Call responseReady plugin filters
431+
for(filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator)
432+
{
433+
filtersIterator.value()->responseReady();
434+
}
435+
#endif
436+
401437
theRequestHandler->sendResponse();
402438

403439
if ( logLevel < 1 )

src/mapserver/qgsserverfilter.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
qgsseerverfilter.cpp
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+
#include "qgsserverfilter.h"
21+
#include "qgslogger.h"
22+
23+
/**
24+
* QgsServerFilter
25+
* Class defining I/O filters for Qgis Mapserver and
26+
* implemented in plugins
27+
*
28+
*/
29+
30+
QgsServerFilter::QgsServerFilter(QgsServerInterface *serverInterface):
31+
mServerInterface( serverInterface )
32+
{
33+
}
34+
35+
QgsServerFilter::~QgsServerFilter()
36+
{
37+
}
38+
39+
40+
void QgsServerFilter::requestReady()
41+
{
42+
QgsDebugMsg( "QgsServerFilter plugin default requestReady called");
43+
}
44+
45+
void QgsServerFilter::responseReady()
46+
{
47+
QgsDebugMsg( "QgsServerFilter plugin default responseReady called");
48+
}
49+

src/mapserver/qgsserverfilter.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
#ifndef QGSSERVERFILTER_H
20+
#define QGSSERVERFILTER_H
21+
22+
#include <QMultiMap>
23+
24+
class QgsServerInterface;
25+
26+
/**
27+
* QgsServerFilter
28+
* Class defining I/O filters for Qgis Server and
29+
* implemented in plugins
30+
*
31+
*/
32+
33+
class QgsServerFilter
34+
{
35+
36+
public:
37+
38+
/** Constructor */
39+
QgsServerFilter( QgsServerInterface* serverInterface );
40+
/** Destructor */
41+
virtual ~QgsServerFilter();
42+
QgsServerInterface* serverInterface( ) { return mServerInterface; }
43+
virtual void requestReady();
44+
virtual void responseReady();
45+
46+
private:
47+
48+
QgsServerInterface* mServerInterface;
49+
50+
};
51+
52+
typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;
53+
54+
55+
#endif // QGSSERVERFILTER_H

src/mapserver/qgsserverinterface.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/***************************************************************************
2+
* qgsserverinterface.cpp
3+
* Abstract base class for interfaces to functions in QgsServer
4+
* -------------------
5+
* begin : 2014-29-09
6+
* copyright : (C) 2014 by Alessandro Pasotti
7+
* email : a dot pasotti at itopen dot com
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+
#include "qgsserverinterface.h"
20+
21+
QgsServerInterface::QgsServerInterface()
22+
{
23+
24+
25+
}
26+
27+
QgsServerInterface::~QgsServerInterface()
28+
{
29+
}

src/mapserver/qgsserverinterface.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************
2+
qgsseerversinterface.h
3+
Interface class for exposing functions in Qgis Server 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+
#ifndef QGSSERVERINTERFACE_H
20+
#define QGSSERVERINTERFACE_H
21+
22+
#include "qgscapabilitiescache.h"
23+
#include "qgsrequesthandler.h"
24+
#include "qgsserverfilter.h"
25+
26+
/**
27+
* QgsServerInterface
28+
* Class defining interfaces exposed by Qgis Mapserver and
29+
* made available to plugins.
30+
*
31+
*/
32+
33+
class QgsServerInterface
34+
{
35+
36+
public:
37+
38+
/** Constructor */
39+
QgsServerInterface( );
40+
41+
/** Destructor */
42+
virtual ~QgsServerInterface() = 0;
43+
44+
virtual void setRequestHandler( QgsRequestHandler* requestHandler ) = 0;
45+
virtual QgsCapabilitiesCache* capabiblitiesCache() = 0;
46+
virtual QgsRequestHandler* requestHandler( ) = 0;
47+
virtual void registerFilter( QgsServerFilter* filter, int priority = 0 ) = 0;
48+
virtual QgsServerFiltersMap filters( ) = 0;
49+
50+
};
51+
52+
#endif // QGSSERVERINTERFACE_H
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/***************************************************************************
2+
qgsseerversinterface.h
3+
Interface class for exposing functions in 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+
#include "qgsserverinterfaceimpl.h"
21+
22+
23+
QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache* capCache ) :
24+
mCapabilitiesCache( capCache )
25+
{
26+
mRequestHandler = NULL;
27+
}
28+
29+
30+
/** Destructor */
31+
QgsServerInterfaceImpl::~QgsServerInterfaceImpl()
32+
{
33+
}
34+
35+
void QgsServerInterfaceImpl::setRequestHandler( QgsRequestHandler * requestHandler)
36+
{
37+
mRequestHandler = requestHandler;
38+
}
39+
40+
void QgsServerInterfaceImpl::registerFilter( QgsServerFilter *filter, int priority )
41+
{
42+
mFilters.insert(priority, filter);
43+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/***************************************************************************
2+
qgsseerversinterface.h
3+
Interface class for exposing functions in 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+
#ifndef QGSSERVERINTERFACEIMPL_H
20+
#define QGSSERVERINTERFACEIMPL_H
21+
22+
#include "qgsserverinterface.h"
23+
#include "qgscapabilitiescache.h"
24+
#include "qgsgetrequesthandler.h"
25+
#include "qgspostrequesthandler.h"
26+
#include "qgssoaprequesthandler.h"
27+
#include "qgsmaprenderer.h"
28+
29+
/**
30+
* QgsServerInterface
31+
* Class defining interfaces exposed by Qgis Mapserver and
32+
* made available to plugins.
33+
*
34+
*/
35+
36+
class QgsServerInterfaceImpl : public QgsServerInterface
37+
{
38+
39+
public:
40+
41+
/** Constructor */
42+
QgsServerInterfaceImpl( QgsCapabilitiesCache *capCache );
43+
44+
/** Destructor */
45+
~QgsServerInterfaceImpl();
46+
47+
void setRequestHandler( QgsRequestHandler* requestHandler );
48+
QgsCapabilitiesCache* capabiblitiesCache() { return mCapabilitiesCache; }
49+
QgsRequestHandler* requestHandler( ) { return mRequestHandler; }
50+
void registerFilter( QgsServerFilter *filter, int priority = 0 );
51+
QgsServerFiltersMap filters( ) { return mFilters; }
52+
53+
private:
54+
55+
QgsServerFiltersMap mFilters;
56+
QgsCapabilitiesCache* mCapabilitiesCache;
57+
QgsRequestHandler* mRequestHandler;
58+
59+
};
60+
61+
#endif // QGSSERVERINTERFACEIMPL_H

0 commit comments

Comments
 (0)