mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
Server refactoring: Added sample native service module; fixed typo
This commit is contained in:
parent
af5eed1a4b
commit
89859ef1b6
@ -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)
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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() );
|
||||
|
||||
|
10
src/server/services/CMakeLists.txt
Normal file
10
src/server/services/CMakeLists.txt
Normal file
@ -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)
|
||||
|
36
src/server/services/DummyService/CMakeLists.txt
Normal file
36
src/server/services/DummyService/CMakeLists.txt
Normal file
@ -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}
|
||||
)
|
||||
|
66
src/server/services/DummyService/dummy.cpp
Normal file
66
src/server/services/DummyService/dummy.cpp
Normal file
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
27
src/server/services/qgsmodule.h
Normal file
27
src/server/services/qgsmodule.h
Normal file
@ -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"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user