Skip to content

Commit 4c6bf30

Browse files
committedNov 26, 2014
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

‎src/mapserver/qgsserverplugins.cpp

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/***************************************************************************
2+
QgsServerPlugins.cpp
3+
-------------------------
4+
begin : August 28, 2014
5+
copyright : (C) 2014 by Alessandro Pasotti - ItOpen
6+
email : apasotti at gmail dot com
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+
#include "qgsserverplugins.h"
19+
#include "qgsmapserviceexception.h"
20+
#include "qgsapplication.h"
21+
#include "qgslogger.h"
22+
#include "qgsserverlogger.h"
23+
#include "qgsmsutils.h"
24+
25+
#include <QLibrary>
26+
27+
QgsServerPlugins::QgsServerPlugins()
28+
{
29+
}
30+
31+
// Initialize static members
32+
QgsPythonUtils* QgsServerPlugins::mPythonUtils;
33+
// Initialize static members
34+
QStringList QgsServerPlugins::mServerPlugins;
35+
36+
// This code is mainly borrowed from QGIS desktop Python plugin initialization
37+
bool QgsServerPlugins::initPlugins(QgsServerInterface *interface)
38+
{
39+
40+
QString pythonlibName( "qgispython" );
41+
#if defined(Q_WS_MAC) || defined(Q_OS_LINUX)
42+
pythonlibName.prepend( QgsApplication::libraryPath() );
43+
#endif
44+
#ifdef __MINGW32__
45+
pythonlibName.prepend( "lib" );
46+
#endif
47+
QString version = QString( "%1.%2.%3" ).arg( QGis::QGIS_VERSION_INT / 10000 ).arg( QGis::QGIS_VERSION_INT / 100 % 100 ).arg( QGis::QGIS_VERSION_INT % 100 );
48+
QgsDebugMsg( QString( "load library %1 (%2)" ).arg( pythonlibName ).arg( version ) );
49+
QLibrary pythonlib( pythonlibName, version );
50+
// It's necessary to set these two load hints, otherwise Python library won't work correctly
51+
// see http://lists.kde.org/?l=pykde&m=117190116820758&w=2
52+
pythonlib.setLoadHints( QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint );
53+
if ( !pythonlib.load() )
54+
{
55+
pythonlib.setFileName( pythonlibName );
56+
if ( !pythonlib.load() )
57+
{
58+
QgsDebugMsg( QString( "Couldn't load Python support library: %1" ).arg( pythonlib.errorString() ) );
59+
return FALSE;
60+
}
61+
}
62+
63+
QgsDebugMsg("Python support library loaded successfully.");
64+
typedef QgsPythonUtils*( *inst )();
65+
inst pythonlib_inst = ( inst ) cast_to_fptr( pythonlib.resolve( "instance" ) );
66+
if ( !pythonlib_inst )
67+
{
68+
//using stderr on purpose because we want end users to see this [TS]
69+
QgsDebugMsg( QString( "Couldn't resolve python support library's instance() symbol." ) );
70+
return FALSE;
71+
}
72+
73+
QgsDebugMsg("Python support library's instance() symbol resolved.");
74+
mPythonUtils = pythonlib_inst();
75+
mPythonUtils->initServerPython( interface );
76+
77+
if ( mPythonUtils && mPythonUtils->isEnabled() )
78+
{
79+
QgsDebugMsg("Python support ENABLED :-)");
80+
}
81+
else
82+
{
83+
QgsDebugMsg("Python support FAILED :-(");
84+
return FALSE;
85+
}
86+
87+
//Init plugins: loads a list of installed plugins and filter them
88+
//for "server" metadata
89+
QListIterator<QString> plugins( mPythonUtils->pluginList() );
90+
bool atLeastOneEnabled = FALSE;
91+
while (plugins.hasNext())
92+
{
93+
QString pluginName = plugins.next();
94+
QString pluginService = mPythonUtils->getPluginMetadata(pluginName, "server" );
95+
if ( pluginService == "True" )
96+
{
97+
if ( mPythonUtils->loadPlugin( pluginName ) )
98+
{
99+
if ( mPythonUtils->startServerPlugin( pluginName ))
100+
{
101+
atLeastOneEnabled = TRUE;
102+
mServerPlugins.append( pluginName );
103+
QgsMessageLog::logMessage( QString("Server plugin %1 loaded!").arg( pluginName ), "Server", QgsMessageLog::CRITICAL );
104+
} else {
105+
QgsMessageLog::logMessage( QString("Error loading server plugin %1").arg( pluginName ), "Server", QgsMessageLog::CRITICAL );
106+
}
107+
} else {
108+
QgsMessageLog::logMessage( QString("Error starting server plugin %1").arg( pluginName ), "Server", QgsMessageLog::CRITICAL );
109+
}
110+
}
111+
}
112+
return mPythonUtils && mPythonUtils->isEnabled() && atLeastOneEnabled;
113+
}

‎src/mapserver/qgsserverplugins.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/***************************************************************************
2+
qgsserverplugins.h
3+
-------------------------
4+
begin : August 28, 2014
5+
copyright : (C) 2014 by Alessandro Pasotti - ItOpen
6+
email : apasotti at gmail dot com
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+
#ifndef QGSSERVERPLUGINS_H
19+
#define QGSSERVERPLUGINS_H
20+
21+
#include "qgsrequesthandler.h"
22+
#include "qgspythonutils.h"
23+
#include "qgsserverinterface.h"
24+
25+
class QgsServerPlugins
26+
{
27+
public:
28+
explicit QgsServerPlugins();
29+
static bool initPlugins(QgsServerInterface* interface);
30+
static QgsPythonUtils* mPythonUtils;
31+
static QStringList mServerPlugins;
32+
};
33+
34+
#endif // QGSSERVERPLUGINS_H

0 commit comments

Comments
 (0)
Please sign in to comment.