From 89859ef1b63d37c189a6a37601c292fa06b94094 Mon Sep 17 00:00:00 2001 From: David Marteau Date: Wed, 14 Dec 2016 19:17:57 +0100 Subject: [PATCH] Server refactoring: Added sample native service module; fixed typo --- CMakeLists.txt | 11 ++++ python/server/qgsserverrequest.sip | 2 +- python/server/qgsserverresponse.sip | 10 +-- python/server/qgsservicemodule.sip | 2 +- python/server/qgsserviceregistry.sip | 2 +- src/server/CMakeLists.txt | 3 +- src/server/qgsserverrequest.h | 4 +- src/server/qgsserverresponse.h | 14 ++-- src/server/qgsservicemodule.h | 2 +- src/server/qgsserviceregistry.h | 4 +- src/server/services/CMakeLists.txt | 10 +++ .../services/DummyService/CMakeLists.txt | 36 ++++++++++ src/server/services/DummyService/dummy.cpp | 66 +++++++++++++++++++ src/server/services/qgsmodule.h | 27 ++++++++ 14 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 src/server/services/CMakeLists.txt create mode 100644 src/server/services/DummyService/CMakeLists.txt create mode 100644 src/server/services/DummyService/dummy.cpp create mode 100644 src/server/services/qgsmodule.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3899cb3dc41..9d245f40491 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -445,6 +445,8 @@ IF (WIN32) SET (DEFAULT_PLUGIN_SUBDIR plugins) SET (DEFAULT_INCLUDE_SUBDIR include) + SET (DEFAULT_SERVER_MODULE_SUBDIR server) + IF (MSVC) SET (DEFAULT_BIN_SUBDIR bin) SET (DEFAULT_CGIBIN_SUBDIR bin) @@ -518,6 +520,9 @@ ELSE (WIN32) SET (DEFAULT_PLUGIN_SUBDIR ../PlugIns/qgis) SET (QGIS_PLUGIN_SUBDIR_REV ../../MacOS) SET (DEFAULT_INCLUDE_SUBDIR include/qgis) + + SET (DEFAULT_SERVER_MODULE_SUBDIR ../PlugIns/server) + # path for framework references when running from build directory # changed later to reference in-app resources upon install SET (CMAKE_INSTALL_NAME_DIR ${CMAKE_BINARY_DIR}/output/lib) @@ -541,6 +546,8 @@ ELSE (WIN32) SET (DEFAULT_LIBEXEC_SUBDIR lib${LIB_SUFFIX}/qgis) SET (DEFAULT_PLUGIN_SUBDIR lib${LIB_SUFFIX}/qgis/plugins) SET (DEFAULT_INCLUDE_SUBDIR include/qgis) + + SET (DEFAULT_SERVER_MODULE_SUBDIR lib${LIB_SUFFIX}/qgis/server) ENDIF (APPLE) ENDIF (WIN32) @@ -587,6 +594,8 @@ SET (QGIS_DATA_SUBDIR ${DEFAULT_DATA_SUBDIR} CACHE STRING "Subdirectory wh SET (QGIS_PLUGIN_SUBDIR ${DEFAULT_PLUGIN_SUBDIR} CACHE STRING "Subdirectory where plugins will be installed") SET (QGIS_INCLUDE_SUBDIR ${DEFAULT_INCLUDE_SUBDIR} CACHE STRING "Subdirectory where header files will be installed") +SET (QGIS_SERVER_MODULE_SUBDIR ${DEFAULT_SERVER_MODULE_SUBDIR} CACHE STRING "Subdirectory where server modules will be installed") + # mark *_SUBDIR variables as advanced as this is not something # that an average user would use MARK_AS_ADVANCED (QGIS_BIN_SUBDIR QGIS_CGIBIN_SUBDIR QGIS_LIB_SUBDIR QGIS_LIBEXEC_SUBDIR QGIS_DATA_SUBDIR QGIS_PLUGIN_SUBDIR QGIS_INCLUDE_SUBDIR) @@ -600,6 +609,8 @@ SET (QGIS_DATA_DIR ${QGIS_DATA_SUBDIR}) SET (QGIS_PLUGIN_DIR ${QGIS_PLUGIN_SUBDIR}) SET (QGIS_INCLUDE_DIR ${QGIS_INCLUDE_SUBDIR}) +SET (QGIS_SERVER_MODULE_DIR ${QGIS_SERVER_MODULE_SUBDIR}) + # set the default locations where the targets (executables, libraries) will land when compiled # this is to allow running qgis from the source tree without having to actually do a "make install" SET (QGIS_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output) diff --git a/python/server/qgsserverrequest.sip b/python/server/qgsserverrequest.sip index 8b56703a13b..580903375a5 100644 --- a/python/server/qgsserverrequest.sip +++ b/python/server/qgsserverrequest.sip @@ -37,7 +37,7 @@ class QgsServerRequest /** * Constructor * - * @param url the lurl string + * @param url the url string * @param method the request method */ QgsServerRequest( const QString& url, Method method ); diff --git a/python/server/qgsserverresponse.sip b/python/server/qgsserverresponse.sip index 607c1db93e6..14dbf871cfe 100644 --- a/python/server/qgsserverresponse.sip +++ b/python/server/qgsserverresponse.sip @@ -38,7 +38,7 @@ class QgsServerResponse /** Set Header entry * Add Header entry to the response - * Note that it is usually an error to set Header after writng data + * Note that it is usually an error to set Header after writing data */ virtual void setHeader( const QString& key, const QString& value ) = 0; @@ -49,8 +49,8 @@ class QgsServerResponse /** * Send error - * This method delegate error handling at the server level. This is different - * from calling setReturnCodei() along with and a specific response body. + * This method delegates error handling at the server level. This is different + * from calling setReturnCode() along with and a specific response body. * @param code HHTP return code value * @param message An informative error message */ @@ -65,9 +65,9 @@ class QgsServerResponse /** * Write chunk of data - * They is a convenient method that will write directly to the + * This is a convenient method that will write directly to the * underlying I/O device - * @return the number of bytes that were actually writtene + * @return the number of bytes that were actually written */ virtual qint64 write(const QByteArray& byteArray ); diff --git a/python/server/qgsservicemodule.sip b/python/server/qgsservicemodule.sip index 781629db9b5..014a6b750fd 100644 --- a/python/server/qgsservicemodule.sip +++ b/python/server/qgsservicemodule.sip @@ -22,7 +22,7 @@ * QgsServiceModule * Class defining the service module interface for QGIS server services * - * This class act as a service registrar for services. + * This class acts as a service registrar for services. * * For dynamic modules, a QgsServiceModule instance is returned from the QGS_ServiceModule_Init() entry point */ diff --git a/python/server/qgsserviceregistry.sip b/python/server/qgsserviceregistry.sip index 8f58d95bfcb..6511e8e63cb 100644 --- a/python/server/qgsserviceregistry.sip +++ b/python/server/qgsserviceregistry.sip @@ -20,7 +20,7 @@ /** * \ingroup server * QgsServiceRegistry - * Class defining the cegistry manager for QGIS server services + * Class defining the registry manager for QGIS server services * * This class provides methods for registering and retrieving * services. diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index a3379c8d032..4f0bb50dd56 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -14,6 +14,8 @@ IF (ENABLE_TESTS) ADD_DEFINITIONS(-DENABLE_MS_TESTS=1) ENDIF (ENABLE_TESTS) +ADD_SUBDIRECTORY(services) + ######################################################## # Files @@ -49,7 +51,6 @@ 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 diff --git a/src/server/qgsserverrequest.h b/src/server/qgsserverrequest.h index 1a425bf0e57..6040f012545 100644 --- a/src/server/qgsserverrequest.h +++ b/src/server/qgsserverrequest.h @@ -28,7 +28,7 @@ */ // Note about design: this intreface must be passed along to python and thus signatures methods must be -// compatible with pyQGS/pyQT api and rules. +// compatible with pyQGIS/pyQT api and rules. class SERVER_EXPORT QgsServerRequest { @@ -41,7 +41,7 @@ class SERVER_EXPORT QgsServerRequest /** * Constructor * - * @param url the lurl string + * @param url the url string * @param method the request method */ QgsServerRequest( const QString& url, Method method ); diff --git a/src/server/qgsserverresponse.h b/src/server/qgsserverresponse.h index 427c45fbf74..eaf9f2c1695 100644 --- a/src/server/qgsserverresponse.h +++ b/src/server/qgsserverresponse.h @@ -44,7 +44,7 @@ class SERVER_EXPORT QgsServerResponse /** Set Header entry * Add Header entry to the response - * Note that it is usually an error to set Header after writng data + * Note that it is usually an error to set Header after writing data */ virtual void setHeader( const QString& key, const QString& value ) = 0; @@ -55,8 +55,8 @@ class SERVER_EXPORT QgsServerResponse /** * Send error - * This method delegate error handling at the server level. This is different - * from calling setReturnCodei() along with and a specific response body. + * This method delegates error handling at the server level. This is different + * from calling setReturnCode() along with and a specific response body. * @param code HHTP return code value * @param message An informative error message */ @@ -70,10 +70,10 @@ class SERVER_EXPORT QgsServerResponse virtual void write( const QString& data ); /** - * Write chunk af data + * Write chunk of data * This is a convenient method that will write directly * to the underlying I/O device - * @creturn the number of bytes that were actually written + * @return the number of bytes that were actually written */ virtual qint64 write( const QByteArray &byteArray ); @@ -84,7 +84,7 @@ class SERVER_EXPORT QgsServerResponse * to the underlying I/O device * @return the number of bytes written * - * @note not available in pything bindings + * @note not available in python bindings */ virtual qint64 write( const char* data, qint64 maxsize); @@ -95,7 +95,7 @@ class SERVER_EXPORT QgsServerResponse * to the underlying I/O device * @return the number of bytes written * - * @note not available in pything bindings + * @note not available in python bindings */ virtual qint64 write( const char* data ); diff --git a/src/server/qgsservicemodule.h b/src/server/qgsservicemodule.h index f5f7fd0a247..ae5dc822d54 100644 --- a/src/server/qgsservicemodule.h +++ b/src/server/qgsservicemodule.h @@ -28,7 +28,7 @@ class QgsServiceRegistry; * QgsServiceModule * Class defining the service module interface for QGIS server services * - * This class act as a service registrar for services. + * This class acts as a service registrar for services. * * For dynamic modules, a QgsServiceModule instance is returned from the QGS_ServiceModule_Init() entry point */ diff --git a/src/server/qgsserviceregistry.h b/src/server/qgsserviceregistry.h index 6d9a206a0cc..3ced1fe83fa 100644 --- a/src/server/qgsserviceregistry.h +++ b/src/server/qgsserviceregistry.h @@ -33,7 +33,7 @@ class QgsService; /** * \ingroup server * QgsServiceRegistry - * Class defining the cegistry manager for QGIS server services + * Class defining the registry manager for QGIS server services * * This class provides methods for registering and retrieving * services. @@ -59,7 +59,7 @@ class SERVER_EXPORT QgsServiceRegistry * @param version the version string (optional) * @return QgsService * - * If the version is not provided the higher version of the service is rerturnod + * If the version is not provided the higher version of the service is returned */ QgsService* getService( const QString& name, const QString& version = QString() ); diff --git a/src/server/services/CMakeLists.txt b/src/server/services/CMakeLists.txt new file mode 100644 index 00000000000..bc648f4c8c1 --- /dev/null +++ b/src/server/services/CMakeLists.txt @@ -0,0 +1,10 @@ +IF (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + SET(CMAKE_CXX_FLAGS_OLD "${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") +ENDIF() +# override default path where built files are put to allow running qgis without installing +SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODULE_SUBDIR}) +SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODULE_SUBDIR}) + +ADD_SUBDIRECTORY(DummyService) + diff --git a/src/server/services/DummyService/CMakeLists.txt b/src/server/services/DummyService/CMakeLists.txt new file mode 100644 index 00000000000..41ce2c2b23e --- /dev/null +++ b/src/server/services/DummyService/CMakeLists.txt @@ -0,0 +1,36 @@ + +######################################################## +# Files + +SET (dummy_SRCS + dummy.cpp +) + +######################################################## +# Build + +ADD_LIBRARY (dummy MODULE ${dummy_SRCS}) + + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ../../../core ../../../core/geometry ../../../core/raster + ../.. + .. + . +) + +TARGET_LINK_LIBRARIES(dummy + qgis_core + qgis_server +) + + +######################################################## +# Install + +INSTALL(TARGETS dummy + RUNTIME DESTINATION ${QGIS_SERVER_MODULE_DIR} + LIBRARY DESTINATION ${QGIS_SERVER_MODULE_DIR} +) + diff --git a/src/server/services/DummyService/dummy.cpp b/src/server/services/DummyService/dummy.cpp new file mode 100644 index 00000000000..01fe65dffbf --- /dev/null +++ b/src/server/services/DummyService/dummy.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + dummy.cpp + + Sample service implementation + ----------------------------- + begin : 2016-12-13 + 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. * + * * + ***************************************************************************/ + +#include "qgsmodule.h" + +// Service +class SampleService: public QgsService +{ + public: + QString name() const { return "SampleService"; } + QString version() const { return "1.0"; } + + bool allowMethod( QgsServerRequest::Method method ) const + { + return method == QgsServerRequest::GetMethod; + } + + void executeRequest( const QgsServerRequest& request, QgsServerResponse& response ) + { + QgsDebugMsg( "SampleService::executeRequest called" ); + response.write( QString("Hello world from myService") ); + } +}; + +// Module +class QgsSampleModule: public QgsServiceModule +{ + public: + void registerSelf( QgsServiceRegistry& registry ) + { + QgsDebugMsg( "SampleModule::registerSelf called" ); + registry.registerService( new SampleService() ); + } +}; + +// Entry points +QGISEXTERN QgsServiceModule* QGS_ServiceModule_Init() +{ + static QgsSampleModule module; + return &module; +} +QGISEXTERN void QGS_ServiceModule_Exit( QgsServiceModule* ) +{ + // Nothing to do +} + + + + + diff --git a/src/server/services/qgsmodule.h b/src/server/services/qgsmodule.h new file mode 100644 index 00000000000..82083f5c52e --- /dev/null +++ b/src/server/services/qgsmodule.h @@ -0,0 +1,27 @@ +/*************************************************************************** + qgsmodule.h + + Define some boilerplate code for implementing modules + ----------------------------- + begin : 2016-12-13 + 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. * + * * + ***************************************************************************/ + +#include "qgis.h" +#include "qgsservicemodule.h" +#include "qgsserviceregistry.h" +#include "qgsservice.h" +#include "qgslogger.h" +#include "qgsmessagelog.h" + +