Skip to content

Commit 705547e

Browse files
committed
Removed python loader: added unRegisterService() method
1 parent 4c8a5cb commit 705547e

File tree

9 files changed

+135
-181
lines changed

9 files changed

+135
-181
lines changed

python/server/qgsserviceregistry.sip

+13-5
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@ class QgsServiceRegistry
6262
*/
6363
void registerService( QgsService* service /Transfer/ );
6464

65+
/**
66+
* Unregister service from its name and version
67+
*
68+
* @param name the tame of the service
69+
* @param version (optional) the specific version to unload
70+
* @return the number of unregstered services
71+
*
72+
* If the version is not specified then all versions from the specified service
73+
* are unloaded
74+
*/
75+
int unRegisterService( const QString& name, const QString& version = QString() );
76+
6577
/**
6678
* Initialize registry, load modules and auto register services
6779
* @param nativeModulepath the native module path
68-
* @param pythonModulePath the python module path
69-
*
70-
* If pythonModulePath is not specified the environnement variables QGIS_PYTHON_SERVICE_PATH
71-
* is examined.
7280
*/
73-
void init( const QString& nativeModulepath, const QString& pythonModulePath = QString() );
81+
void init( const QString& nativeModulepath );
7482

7583
/**
7684
* Clean up registered service and unregister modules

src/server/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ SET ( qgis_mapserv_SRCS
5555
qgsservicemodule.cpp
5656
qgsserviceloader.cpp
5757
qgsservicenativeloader.cpp
58-
qgsservicepythonloader.cpp
5958
qgsserviceregistry.cpp
6059
qgsserverrequest.cpp
6160
qgsserverresponse.cpp

src/server/qgsserverrequest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QgsServerRequest::~QgsServerRequest()
4040

4141
}
4242

43-
QString QgsServerRequest::getHeader( const QString& name ) const
43+
QString QgsServerRequest::getHeader( const QString& /*name*/ ) const
4444
{
4545
return "";
4646
}

src/server/qgsservicepythonloader.cpp

-83
This file was deleted.

src/server/qgsservicepythonloader.h

-73
This file was deleted.

src/server/qgsserviceregistry.cpp

+69-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "qgslogger.h"
2323
#include "qgsmessagelog.h"
2424

25+
#include <algorithm>
26+
#include <functional>
27+
2528
namespace
2629
{
2730

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

148-
void QgsServiceRegistry::init( const QString& nativeModulePath, const QString& pythonModulePath )
151+
int QgsServiceRegistry::unRegisterService( const QString& name, const QString& version )
152+
{
153+
// Check that we have a service of that name
154+
int removed = 0;
155+
VersionTable::const_iterator v = mVersions.constFind( name );
156+
if ( v != mVersions.constEnd() )
157+
{
158+
if ( version.isEmpty() )
159+
{
160+
// No version specified, remove all versions
161+
ServiceTable::iterator it = mServices.begin();
162+
while ( it != mServices.end() )
163+
{
164+
if (( *it )->name() == name )
165+
{
166+
QgsMessageLog::logMessage( QString( "Unregistering service %1 %2" ).arg( name, ( *it )->version() ) );
167+
it = mServices.erase( it );
168+
++removed;
169+
}
170+
else
171+
{
172+
++it;
173+
}
174+
}
175+
// Remove from version table
176+
mVersions.remove( name );
177+
}
178+
else
179+
{
180+
QString key = makeServiceKey( name, version );
181+
ServiceTable::iterator found = mServices.find( key );
182+
if ( found != mServices.end() )
183+
{
184+
QgsMessageLog::logMessage( QString( "Unregistering service %1 %2" ).arg( name, version ) );
185+
mServices.erase( found );
186+
removed = 1;
187+
188+
// Find if we have other services of that name
189+
// but with different version
190+
//
191+
QString maxVer;
192+
std::function < void ( const ServiceTable::mapped_type& ) >
193+
findGreaterVersion = [name,&maxVer]( const ServiceTable::mapped_type & service )
194+
{
195+
if ( service->name() == name &&
196+
( maxVer.isEmpty() || isVersionGreater( service->version(), maxVer ) ) )
197+
maxVer = service->version();
198+
};
199+
200+
mVersions.remove( name );
201+
202+
std::for_each( mServices.constBegin(), mServices.constEnd(), findGreaterVersion );
203+
if ( !maxVer.isEmpty() )
204+
{
205+
// Set the new default service
206+
QString key = makeServiceKey( name, maxVer );
207+
mVersions.insert( name, VersionTable::mapped_type( version, key ) );
208+
}
209+
}
210+
}
211+
}
212+
return removed;
213+
}
214+
215+
void QgsServiceRegistry::init( const QString& nativeModulePath )
149216
{
150217
mNativeLoader.loadModules( nativeModulePath, *this );
151-
#ifdef HAVE_SERVER_PYTHON_SERVICES
152-
mPythonLoader.loadModules( pythonModulePath, *this );
153-
#endif
154218
}
155219

156220
void QgsServiceRegistry::cleanUp()
157221
{
158222
// Release all services
223+
mVersions.clear();
159224
mServices.clear();
160-
161225
mNativeLoader.unloadModules();
162-
#ifdef HAVE_SERVER_PYTHON_SERVICES
163-
mPythonLoader.unloadModules();
164-
#endif
165226
}
166227

167228

src/server/qgsserviceregistry.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <QString>
2626

2727
#include "qgsservicenativeloader.h"
28-
#include "qgsservicepythonloader.h"
2928
#include <memory>
3029

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

77+
/**
78+
* Unregister service from its name and version
79+
*
80+
* @param name the tame of the service
81+
* @param version (optional) the specific version to unload
82+
* @return the number of services unregistered
83+
*
84+
* If the version is not specified then all versions from the specified service
85+
* are unloaded
86+
*/
87+
int unRegisterService( const QString& name, const QString& version = QString() );
88+
7889
/**
7990
* Initialize registry, load modules and auto register services
8091
* @param nativeModulepath the native module path
81-
* @param pythonModulePath the python module path
82-
*
83-
* If pythonModulePath is not specified the environnement variables QGIS_PYTHON_SERVICE_PATH
84-
* is examined.
8592
*/
86-
void init( const QString& nativeModulepath, const QString& pythonModulePath = QString() );
93+
void init( const QString& nativeModulepath );
8794

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

97104
QgsServiceNativeLoader mNativeLoader;
98-
QgsServicePythonLoader mPythonLoader;
99105

100106
ServiceTable mServices;
101107
VersionTable mVersions;

src/server/services/DummyService/dummy.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SampleService: public QgsService
3131
return method == QgsServerRequest::GetMethod;
3232
}
3333

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

0 commit comments

Comments
 (0)