-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server refactoring: implements service modules registry
Implementation for qgis/QGIS-Enhancement-Proposals#74
- Loading branch information
Showing
26 changed files
with
1,746 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*************************************************************************** | ||
qgsserverrequest.h | ||
|
||
Define ruquest class for getting request contents | ||
------------------- | ||
begin : 2016-12-05 | ||
copyright : (C) 2016 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** | ||
* \ingroup server | ||
* QgsServerRequest | ||
* Class defining request intreface passed to services QgsService::executeRequest() method | ||
* | ||
* Note about design: this intreface must be passed along to python and thus signatures methods must be | ||
* compatible with pyQGS/pyQT api and rules. | ||
*/ | ||
class QgsServerRequest | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsserverrequest.h" | ||
%End | ||
public: | ||
|
||
enum Method { | ||
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod | ||
}; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param url the lurl string | ||
* @param method the request method | ||
*/ | ||
QgsServerRequest( const QString& url, Method method ); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param url QUrl | ||
* @param method the rquest method | ||
*/ | ||
QgsServerRequest( const QUrl& url, Method method ); | ||
|
||
//! destructor | ||
virtual ~QgsServerRequest(); | ||
|
||
/** | ||
* @return the request url | ||
*/ | ||
virtual const QUrl& url() const; | ||
|
||
/** | ||
* @return the rquest method | ||
*/ | ||
virtual Method method() const; | ||
|
||
/** | ||
* Return post/put data | ||
* The default implementation retfurn nullptr | ||
* @return a QByteArray pointer or nullptr | ||
*/ | ||
virtual const QByteArray* data() const; | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*************************************************************************** | ||
qgsserverresponse.h | ||
|
||
Define response class for services | ||
------------------- | ||
begin : 2016-12-05 | ||
copyright : (C) 2016 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** | ||
* \ingroup server | ||
* QgsServerResponse | ||
* Class defining response interface passed to services QgsService::executeRequest() method | ||
* | ||
* Note: | ||
* This class is intended to be used from python code: method signatures and return types should be | ||
* compatible with pyQGIS/pyQT types and rules. | ||
* | ||
*/ | ||
class QgsServerResponse | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsserverresponse.h" | ||
%End | ||
public: | ||
|
||
//!constructor | ||
QgsServerResponse(); | ||
|
||
//! destructor | ||
virtual ~QgsServerResponse(); | ||
|
||
/** Set header entry | ||
* Add header entry to the response | ||
* Note that it is usually an error to set hedaer after writng data | ||
*/ | ||
virtual void setHeader( const QString& key, const QString& value ) = 0; | ||
|
||
/** Set the http return code | ||
*/ | ||
virtual void setReturnCode( int code ) = 0; | ||
|
||
/** | ||
* Send error | ||
*/ | ||
virtual void sendError( int code, const QString& message ) = 0; | ||
|
||
/** | ||
* Write string | ||
*/ | ||
virtual void write(const QString& data ); | ||
|
||
/** | ||
* Write chunk af data | ||
* They are convenience method that will write directly to the | ||
* underlying I/O device | ||
*/ | ||
virtual qint64 write(const QByteArray& byteArray ); | ||
|
||
|
||
/** | ||
* Return the underlying QIODevice | ||
*/ | ||
virtual QIODevice* io() = 0; | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*************************************************************************** | ||
qgsservice.h | ||
|
||
Class defining the service interface for QGIS server services. | ||
------------------- | ||
begin : 2016-12-05 | ||
copyright : (C) 2016 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** | ||
* \ingroup server | ||
* QgsService | ||
* Class defining interfaces for QGIS server services | ||
* | ||
* This class provides methods for executing server requests | ||
* They are registered at runtime for a given service name. | ||
* | ||
*/ | ||
class QgsService | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsservice.h" | ||
#include "qgsserverrequest.h" | ||
#include "qgsserverresponse.h" | ||
%End | ||
|
||
public: | ||
|
||
//! Constructor | ||
QgsService(); | ||
|
||
//! Destructor | ||
virtual ~QgsService(); | ||
|
||
/** | ||
* Return true if the given method is supported for that | ||
* service. | ||
* @param method QGSMethodType the | ||
* @return QString containing the configuration file path | ||
*/ | ||
virtual bool allowMethod( QgsServerRequest::Method ) const = 0; | ||
|
||
/** | ||
* Execute the requests and set result in QgsServerRequest | ||
* @param request a QgsServerRequest instance | ||
* @param response a QgsServerResponse instance | ||
*/ | ||
virtual void executeRequest( const QgsServerRequest& request, QgsServerResponse& response ) = 0; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*************************************************************************** | ||
qgsservicemodule.h | ||
|
||
Class defining the service module interface for QGIS server services. | ||
------------------- | ||
begin : 2016-12-05 | ||
copyright : (C) 2016 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** | ||
* \ingroup server | ||
* QgsServiceModule | ||
* Class defining the service module interface for QGIS server services | ||
* | ||
* This class act as a service registrar for services. | ||
* | ||
* For dynamic modules, a QgsServiceModule instance is returned from the QGS_ServiceModule_Init() entry point | ||
*/ | ||
class QgsServiceModule | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsservicemodule.h" | ||
#include "qgsserviceregistry.h" | ||
%End | ||
public: | ||
|
||
//! Constructor | ||
QgsServiceModule(); | ||
|
||
//! Destructor | ||
virtual ~QgsServiceModule() = 0; | ||
|
||
/** | ||
* Ask module to registe all provided services | ||
* @param registry QgsServiceRegistry | ||
*/ | ||
virtual void registerSelf( QgsServiceRegistry& registry ) = 0; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*************************************************************************** | ||
qgsserviceregistry.h | ||
|
||
Class defining the service manager for QGIS server services. | ||
------------------- | ||
begin : 2016-12-05 | ||
copyright : (C) 2016 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** | ||
* \ingroup server | ||
* QgsServiceRegistry | ||
* Class defining the cegistry manager for QGIS server services | ||
* | ||
* This class provides methods for registering and retrieving | ||
* services. Note that the regstiry does not hord ownership of | ||
* registered service but vill call the 'release' method on cleanup) | ||
* | ||
*/ | ||
class QgsServiceRegistry | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsserviceregistry.h" | ||
#include "qgsservice.h" | ||
#include "qgsserverrequest.h" | ||
#include "qgsserverresponse.h" | ||
%End | ||
public: | ||
|
||
//! Constructor | ||
QgsServiceRegistry(); | ||
|
||
//! Destructor | ||
~QgsServiceRegistry(); | ||
|
||
/** | ||
* Retrieve a service from its name | ||
* @param name the name of the service | ||
* @param version the required version (optional) | ||
* @return QgsService | ||
*/ | ||
QgsService* getService( const QString& name, const QString& version = QString() ); | ||
|
||
/** | ||
* Register a service by its name | ||
* | ||
* This method is intended to be called by modules for registering | ||
* services. A module may register multiple services. | ||
* The registry gain ownership of services. | ||
* | ||
* @param name the name of the service | ||
* @param service a QgsServerResponse to be registered | ||
* @param version the service version | ||
*/ | ||
void registerService( const QString& name, QgsService* service /Transfer/, const QString& version ); | ||
|
||
/** | ||
* Initialize registry, load modules and auto register services | ||
* @param nativeModulepath the native module path | ||
* @param pythonModulePath the python module path | ||
* | ||
* If pythonModulePath is not specified the environnement variables QGIS_PYTHON_SERVICE_PATH | ||
* is examined. | ||
*/ | ||
void init( const QString& nativeModulepath, const QString& pythonModulePath = QString() ); | ||
|
||
/** | ||
* Clean up registered service and unregister modules | ||
*/ | ||
void cleanUp(); | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.