Skip to content
Permalink
Browse files

Removed python loader: added unRegisterService() method

  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 4c8a5cb commit 705547e6171211bd820e5d9cdb779c2d52ca8575
@@ -62,15 +62,23 @@ class QgsServiceRegistry
*/
void registerService( QgsService* service /Transfer/ );

/**
* Unregister service from its name and version
*
* @param name the tame of the service
* @param version (optional) the specific version to unload
* @return the number of unregstered services
*
* If the version is not specified then all versions from the specified service
* are unloaded
*/
int unRegisterService( const QString& name, const QString& version = QString() );

/**
* 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() );
void init( const QString& nativeModulepath );

/**
* Clean up registered service and unregister modules
@@ -55,7 +55,6 @@ SET ( qgis_mapserv_SRCS
qgsservicemodule.cpp
qgsserviceloader.cpp
qgsservicenativeloader.cpp
qgsservicepythonloader.cpp
qgsserviceregistry.cpp
qgsserverrequest.cpp
qgsserverresponse.cpp
@@ -40,7 +40,7 @@ QgsServerRequest::~QgsServerRequest()

}

QString QgsServerRequest::getHeader( const QString& name ) const
QString QgsServerRequest::getHeader( const QString& /*name*/ ) const
{
return "";
}

This file was deleted.

This file was deleted.

@@ -22,6 +22,9 @@
#include "qgslogger.h"
#include "qgsmessagelog.h"

#include <algorithm>
#include <functional>

namespace
{

@@ -145,23 +148,81 @@ void QgsServiceRegistry::registerService( QgsService* service )
}
}

void QgsServiceRegistry::init( const QString& nativeModulePath, const QString& pythonModulePath )
int QgsServiceRegistry::unRegisterService( const QString& name, const QString& version )
{
// Check that we have a service of that name
int removed = 0;
VersionTable::const_iterator v = mVersions.constFind( name );
if ( v != mVersions.constEnd() )
{
if ( version.isEmpty() )
{
// No version specified, remove all versions
ServiceTable::iterator it = mServices.begin();
while ( it != mServices.end() )
{
if (( *it )->name() == name )
{
QgsMessageLog::logMessage( QString( "Unregistering service %1 %2" ).arg( name, ( *it )->version() ) );
it = mServices.erase( it );
++removed;
}
else
{
++it;
}
}
// Remove from version table
mVersions.remove( name );
}
else
{
QString key = makeServiceKey( name, version );
ServiceTable::iterator found = mServices.find( key );
if ( found != mServices.end() )
{
QgsMessageLog::logMessage( QString( "Unregistering service %1 %2" ).arg( name, version ) );
mServices.erase( found );
removed = 1;

// Find if we have other services of that name
// but with different version
//
QString maxVer;
std::function < void ( const ServiceTable::mapped_type& ) >
findGreaterVersion = [name,&maxVer]( const ServiceTable::mapped_type & service )
{
if ( service->name() == name &&
( maxVer.isEmpty() || isVersionGreater( service->version(), maxVer ) ) )
maxVer = service->version();
};

mVersions.remove( name );

std::for_each( mServices.constBegin(), mServices.constEnd(), findGreaterVersion );
if ( !maxVer.isEmpty() )
{
// Set the new default service
QString key = makeServiceKey( name, maxVer );
mVersions.insert( name, VersionTable::mapped_type( version, key ) );
}
}
}
}
return removed;
}

void QgsServiceRegistry::init( const QString& nativeModulePath )
{
mNativeLoader.loadModules( nativeModulePath, *this );
#ifdef HAVE_SERVER_PYTHON_SERVICES
mPythonLoader.loadModules( pythonModulePath, *this );
#endif
}

void QgsServiceRegistry::cleanUp()
{
// Release all services
mVersions.clear();
mServices.clear();

mNativeLoader.unloadModules();
#ifdef HAVE_SERVER_PYTHON_SERVICES
mPythonLoader.unloadModules();
#endif
}


@@ -25,7 +25,6 @@
#include <QString>

#include "qgsservicenativeloader.h"
#include "qgsservicepythonloader.h"
#include <memory>

class QgsService;
@@ -75,15 +74,23 @@ class SERVER_EXPORT QgsServiceRegistry
*/
void registerService( QgsService* service );

/**
* Unregister service from its name and version
*
* @param name the tame of the service
* @param version (optional) the specific version to unload
* @return the number of services unregistered
*
* If the version is not specified then all versions from the specified service
* are unloaded
*/
int unRegisterService( const QString& name, const QString& version = QString() );

/**
* 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() );
void init( const QString& nativeModulepath );

/**
* Clean up registered service and unregister modules
@@ -95,7 +102,6 @@ class SERVER_EXPORT QgsServiceRegistry
typedef QHash<QString, QPair<QString, QString> > VersionTable;

QgsServiceNativeLoader mNativeLoader;
QgsServicePythonLoader mPythonLoader;

ServiceTable mServices;
VersionTable mVersions;
@@ -31,7 +31,7 @@ class SampleService: public QgsService
return method == QgsServerRequest::GetMethod;
}

void executeRequest( const QgsServerRequest& request, QgsServerResponse& response )
void executeRequest( const QgsServerRequest& /*request*/, QgsServerResponse& response )
{
QgsDebugMsg( "SampleService::executeRequest called" );
response.write( QString( "Hello world from myService" ) );

0 comments on commit 705547e

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