Skip to content

Commit

Permalink
Server refactoring: Added sample native service module; fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent af5eed1 commit 89859ef
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 21 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/server/qgsserverrequest.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 5 additions & 5 deletions python/server/qgsserverresponse.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*/
Expand All @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion python/server/qgsservicemodule.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion python/server/qgsserviceregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ IF (ENABLE_TESTS)
ADD_DEFINITIONS(-DENABLE_MS_TESTS=1)
ENDIF (ENABLE_TESTS)

ADD_SUBDIRECTORY(services)

########################################################
# Files

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsserverrequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 );
Expand Down
14 changes: 7 additions & 7 deletions src/server/qgsserverresponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*/
Expand All @@ -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 );

Expand All @@ -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);

Expand All @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsservicemodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsserviceregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() );

Expand Down
10 changes: 10 additions & 0 deletions src/server/services/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions src/server/services/DummyService/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 66 additions & 0 deletions src/server/services/DummyService/dummy.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions src/server/services/qgsmodule.h
Original file line number Diff line number Diff line change
@@ -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"


0 comments on commit 89859ef

Please sign in to comment.