Skip to content

Commit 1e0d830

Browse files
committed
Server refactoring: implements service modules registry
Implementation for qgis/QGIS-Enhancement-Proposals#74
1 parent 3a03c98 commit 1e0d830

26 files changed

+1746
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

python/server/qgsserverrequest.sip

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/***************************************************************************
2+
qgsserverrequest.h
3+
4+
Define ruquest class for getting request contents
5+
-------------------
6+
begin : 2016-12-05
7+
copyright : (C) 2016 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+
/**
21+
* \ingroup server
22+
* QgsServerRequest
23+
* Class defining request intreface passed to services QgsService::executeRequest() method
24+
*
25+
* Note about design: this intreface must be passed along to python and thus signatures methods must be
26+
* compatible with pyQGS/pyQT api and rules.
27+
*/
28+
class QgsServerRequest
29+
{
30+
%TypeHeaderCode
31+
#include "qgsserverrequest.h"
32+
%End
33+
public:
34+
35+
enum Method {
36+
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod
37+
};
38+
39+
/**
40+
* Constructor
41+
*
42+
* @param url the lurl string
43+
* @param method the request method
44+
*/
45+
QgsServerRequest( const QString& url, Method method );
46+
47+
/**
48+
* Constructor
49+
*
50+
* @param url QUrl
51+
* @param method the rquest method
52+
*/
53+
QgsServerRequest( const QUrl& url, Method method );
54+
55+
//! destructor
56+
virtual ~QgsServerRequest();
57+
58+
/**
59+
* @return the request url
60+
*/
61+
virtual const QUrl& url() const;
62+
63+
/**
64+
* @return the rquest method
65+
*/
66+
virtual Method method() const;
67+
68+
/**
69+
* Return post/put data
70+
* The default implementation retfurn nullptr
71+
* @return a QByteArray pointer or nullptr
72+
*/
73+
virtual const QByteArray* data() const;
74+
75+
};
76+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
qgsserverresponse.h
3+
4+
Define response class for services
5+
-------------------
6+
begin : 2016-12-05
7+
copyright : (C) 2016 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+
/**
21+
* \ingroup server
22+
* QgsServerResponse
23+
* Class defining response interface passed to services QgsService::executeRequest() method
24+
*
25+
* Note:
26+
* This class is intended to be used from python code: method signatures and return types should be
27+
* compatible with pyQGIS/pyQT types and rules.
28+
*
29+
*/
30+
class QgsServerResponse
31+
{
32+
%TypeHeaderCode
33+
#include "qgsserverresponse.h"
34+
%End
35+
public:
36+
37+
//!constructor
38+
QgsServerResponse();
39+
40+
//! destructor
41+
virtual ~QgsServerResponse();
42+
43+
/** Set header entry
44+
* Add header entry to the response
45+
* Note that it is usually an error to set hedaer after writng data
46+
*/
47+
virtual void setHeader( const QString& key, const QString& value ) = 0;
48+
49+
/** Set the http return code
50+
*/
51+
virtual void setReturnCode( int code ) = 0;
52+
53+
/**
54+
* Send error
55+
*/
56+
virtual void sendError( int code, const QString& message ) = 0;
57+
58+
/**
59+
* Write string
60+
*/
61+
virtual void write(const QString& data );
62+
63+
/**
64+
* Write chunk af data
65+
* They are convenience method that will write directly to the
66+
* underlying I/O device
67+
*/
68+
virtual qint64 write(const QByteArray& byteArray );
69+
70+
71+
/**
72+
* Return the underlying QIODevice
73+
*/
74+
virtual QIODevice* io() = 0;
75+
76+
};
77+

python/server/qgsservice.sip

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/***************************************************************************
2+
qgsservice.h
3+
4+
Class defining the service interface for QGIS server services.
5+
-------------------
6+
begin : 2016-12-05
7+
copyright : (C) 2016 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+
/**
21+
* \ingroup server
22+
* QgsService
23+
* Class defining interfaces for QGIS server services
24+
*
25+
* This class provides methods for executing server requests
26+
* They are registered at runtime for a given service name.
27+
*
28+
*/
29+
class QgsService
30+
{
31+
%TypeHeaderCode
32+
#include "qgsservice.h"
33+
#include "qgsserverrequest.h"
34+
#include "qgsserverresponse.h"
35+
%End
36+
37+
public:
38+
39+
//! Constructor
40+
QgsService();
41+
42+
//! Destructor
43+
virtual ~QgsService();
44+
45+
/**
46+
* Return true if the given method is supported for that
47+
* service.
48+
* @param method QGSMethodType the
49+
* @return QString containing the configuration file path
50+
*/
51+
virtual bool allowMethod( QgsServerRequest::Method ) const = 0;
52+
53+
/**
54+
* Execute the requests and set result in QgsServerRequest
55+
* @param request a QgsServerRequest instance
56+
* @param response a QgsServerResponse instance
57+
*/
58+
virtual void executeRequest( const QgsServerRequest& request, QgsServerResponse& response ) = 0;
59+
};
60+

python/server/qgsservicemodule.sip

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/***************************************************************************
2+
qgsservicemodule.h
3+
4+
Class defining the service module interface for QGIS server services.
5+
-------------------
6+
begin : 2016-12-05
7+
copyright : (C) 2016 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+
/**
21+
* \ingroup server
22+
* QgsServiceModule
23+
* Class defining the service module interface for QGIS server services
24+
*
25+
* This class act as a service registrar for services.
26+
*
27+
* For dynamic modules, a QgsServiceModule instance is returned from the QGS_ServiceModule_Init() entry point
28+
*/
29+
class QgsServiceModule
30+
{
31+
%TypeHeaderCode
32+
#include "qgsservicemodule.h"
33+
#include "qgsserviceregistry.h"
34+
%End
35+
public:
36+
37+
//! Constructor
38+
QgsServiceModule();
39+
40+
//! Destructor
41+
virtual ~QgsServiceModule() = 0;
42+
43+
/**
44+
* Ask module to registe all provided services
45+
* @param registry QgsServiceRegistry
46+
*/
47+
virtual void registerSelf( QgsServiceRegistry& registry ) = 0;
48+
};
49+
50+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/***************************************************************************
2+
qgsserviceregistry.h
3+
4+
Class defining the service manager for QGIS server services.
5+
-------------------
6+
begin : 2016-12-05
7+
copyright : (C) 2016 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+
/**
21+
* \ingroup server
22+
* QgsServiceRegistry
23+
* Class defining the cegistry manager for QGIS server services
24+
*
25+
* This class provides methods for registering and retrieving
26+
* services. Note that the regstiry does not hord ownership of
27+
* registered service but vill call the 'release' method on cleanup)
28+
*
29+
*/
30+
class QgsServiceRegistry
31+
{
32+
%TypeHeaderCode
33+
#include "qgsserviceregistry.h"
34+
#include "qgsservice.h"
35+
#include "qgsserverrequest.h"
36+
#include "qgsserverresponse.h"
37+
%End
38+
public:
39+
40+
//! Constructor
41+
QgsServiceRegistry();
42+
43+
//! Destructor
44+
~QgsServiceRegistry();
45+
46+
/**
47+
* Retrieve a service from its name
48+
* @param name the name of the service
49+
* @param version the required version (optional)
50+
* @return QgsService
51+
*/
52+
QgsService* getService( const QString& name, const QString& version = QString() );
53+
54+
/**
55+
* Register a service by its name
56+
*
57+
* This method is intended to be called by modules for registering
58+
* services. A module may register multiple services.
59+
* The registry gain ownership of services.
60+
*
61+
* @param name the name of the service
62+
* @param service a QgsServerResponse to be registered
63+
* @param version the service version
64+
*/
65+
void registerService( const QString& name, QgsService* service /Transfer/, const QString& version );
66+
67+
/**
68+
* Initialize registry, load modules and auto register services
69+
* @param nativeModulepath the native module path
70+
* @param pythonModulePath the python module path
71+
*
72+
* If pythonModulePath is not specified the environnement variables QGIS_PYTHON_SERVICE_PATH
73+
* is examined.
74+
*/
75+
void init( const QString& nativeModulepath, const QString& pythonModulePath = QString() );
76+
77+
/**
78+
* Clean up registered service and unregister modules
79+
*/
80+
void cleanUp();
81+
};
82+
83+

python/server/server.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@
2828
%Include qgswfsprojectparser.sip
2929
%Include qgsconfigcache.sip
3030
%Include qgsserver.sip
31+
32+
%Include qgsserverrequest.sip
33+
%Include qgsserverresponse.sip
34+
%Include qgsservice.sip
35+
%Include qgsservicemodule.sip
36+
%Include qgsserviceregistry.sip
37+

src/server/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ SET ( qgis_mapserv_SRCS
4949
qgssldconfigparser.cpp
5050
qgsconfigparserutils.cpp
5151
qgsserver.cpp
52+
#XXX https://github.com/qgis/QGIS-Enhancement-Proposals/issues/74
53+
qgsservice.cpp
54+
qgsservicemodule.cpp
55+
qgsserviceloader.cpp
56+
qgsservicenativeloader.cpp
57+
qgsservicepythonloader.cpp
58+
qgsserviceregistry.cpp
59+
qgsserverrequest.cpp
60+
qgsserverresponse.cpp
61+
#----------------------------
5262
)
5363
IF("${Qt5Network_VERSION}" VERSION_LESS "5.0.0")
5464
SET (qgis_mapserv_SRCS ${qgis_mapserv_SRCS}

0 commit comments

Comments
 (0)