Skip to content
Permalink
Browse files

Server refactoring: implements service modules registry

  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 3a03c98 commit 1e0d830529c8cb05c69cda22403e5fd2d254e5f6
@@ -0,0 +1 @@
---
@@ -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;

};

@@ -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;

};

@@ -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;
};

@@ -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;
};


@@ -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();
};


@@ -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

@@ -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}

0 comments on commit 1e0d830

Please sign in to comment.
You can’t perform that action at this time.