Skip to content

Commit

Permalink
Server refactoring: implements service modules registry
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 3a03c98 commit 1e0d830
Show file tree
Hide file tree
Showing 26 changed files with 1,746 additions and 0 deletions.
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
76 changes: 76 additions & 0 deletions python/server/qgsserverrequest.sip
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;

};

77 changes: 77 additions & 0 deletions python/server/qgsserverresponse.sip
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;

};

60 changes: 60 additions & 0 deletions python/server/qgsservice.sip
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;
};

50 changes: 50 additions & 0 deletions python/server/qgsservicemodule.sip
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;
};


83 changes: 83 additions & 0 deletions python/server/qgsserviceregistry.sip
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();
};


7 changes: 7 additions & 0 deletions python/server/server.sip
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@
%Include qgswfsprojectparser.sip
%Include qgsconfigcache.sip
%Include qgsserver.sip

%Include qgsserverrequest.sip
%Include qgsserverresponse.sip
%Include qgsservice.sip
%Include qgsservicemodule.sip
%Include qgsserviceregistry.sip

10 changes: 10 additions & 0 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ SET ( qgis_mapserv_SRCS
qgssldconfigparser.cpp
qgsconfigparserutils.cpp
qgsserver.cpp
#XXX https://github.com/qgis/QGIS-Enhancement-Proposals/issues/74
qgsservice.cpp
qgsservicemodule.cpp
qgsserviceloader.cpp
qgsservicenativeloader.cpp
qgsservicepythonloader.cpp
qgsserviceregistry.cpp
qgsserverrequest.cpp
qgsserverresponse.cpp
#----------------------------
)
IF("${Qt5Network_VERSION}" VERSION_LESS "5.0.0")
SET (qgis_mapserv_SRCS ${qgis_mapserv_SRCS}
Expand Down
Loading

0 comments on commit 1e0d830

Please sign in to comment.