33 QString makeServiceKey(
const QString &name,
const QString &version )
35 return QString(
"%1_%2" ).arg( name, version );
45 bool isVersionGreater(
const QString &v1,
const QString &v2 )
47 QStringList l1 = v1.split(
'.' );
48 QStringList l2 = v2.split(
'.' );
49 QStringList::iterator it1 = l1.begin();
50 QStringList::iterator it2 = l2.begin();
52 while ( it1 != l1.end() && it2 != l2.end() )
57 const int i1 = it1->toInt( &isint );
60 const int i2 = it2->toInt( &isint );
61 if ( isint && i1 != i2 )
95 const VersionTable::const_iterator v = mServiceVersions.constFind( name );
96 if ( v != mServiceVersions.constEnd() )
98 key = version.isEmpty() ? v->second : makeServiceKey( name, version );
99 const ServiceTable::const_iterator it = mServices.constFind( key );
100 if ( it != mServices.constEnd() )
108 QStringLiteral(
"Server" ), Qgis::MessageLevel::Warning );
109 service = mServices[v->second].get();
115 QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
122 const QString name = service->
name();
123 const QString version = service->
version();
126 const QString key = makeServiceKey( name, version );
127 if ( mServices.constFind( key ) != mServices.constEnd() )
130 QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
135 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
136 mServices.insert( key, std::shared_ptr<QgsService>( service ) );
143 const VersionTable::const_iterator v = mServiceVersions.constFind( name );
144 if ( v == mServiceVersions.constEnd() )
147 mServiceVersions.insert( name, VersionTable::mapped_type( version, key ) );
171 const VersionTable::const_iterator v = mApiVersions.constFind( name );
172 if ( v != mApiVersions.constEnd() )
174 if ( version.isEmpty() )
177 ApiTable::iterator it = mApis.begin();
178 while ( it != mApis.end() )
180 if ( ( *it )->name() == name )
183 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
184 it = mApis.erase( it );
193 mApiVersions.remove( name );
197 const QString key = makeServiceKey( name, version );
198 const ApiTable::iterator found = mApis.find( key );
199 if ( found != mApis.end() )
202 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
203 mApis.erase( found );
210 const std::function < void (
const ApiTable::mapped_type & ) >
211 findGreaterVersion = [name, &maxVer](
const ApiTable::mapped_type & api )
213 if ( api->name() == name &&
214 ( maxVer.isEmpty() || isVersionGreater( api->version(), maxVer ) ) )
215 maxVer = api->version();
218 mApiVersions.remove( name );
220 std::for_each( mApis.constBegin(), mApis.constEnd(), findGreaterVersion );
221 if ( !maxVer.isEmpty() )
224 const QString key = makeServiceKey( name, maxVer );
225 mApiVersions.insert( name, VersionTable::mapped_type( version, key ) );
235 for (
const auto &api : mApis )
238 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
239 if ( api->accept( request.
url() ) )
241 Q_ASSERT( !api->name().isEmpty() );
243 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
256 const VersionTable::const_iterator v = mApiVersions.constFind( name );
257 if ( v != mApiVersions.constEnd() )
259 key = version.isEmpty() ? v->second : makeServiceKey( name, version );
260 const ApiTable::const_iterator it = mApis.constFind( key );
261 if ( it != mApis.constEnd() )
269 QStringLiteral(
"Server" ), Qgis::MessageLevel::Warning );
270 api = mApis[v->second].get();
276 QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
285 const VersionTable::const_iterator v = mServiceVersions.constFind( name );
286 if ( v != mServiceVersions.constEnd() )
288 if ( version.isEmpty() )
291 ServiceTable::iterator it = mServices.begin();
292 while ( it != mServices.end() )
294 if ( ( *it )->name() == name )
297 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
298 it = mServices.erase( it );
307 mServiceVersions.remove( name );
311 const QString key = makeServiceKey( name, version );
312 const ServiceTable::iterator found = mServices.find( key );
313 if ( found != mServices.end() )
316 QStringLiteral(
"Server" ), Qgis::MessageLevel::Info );
317 mServices.erase( found );
324 const std::function < void (
const ServiceTable::mapped_type & ) >
325 findGreaterVersion = [name, &maxVer](
const ServiceTable::mapped_type & service )
327 if ( service->name() == name &&
328 ( maxVer.isEmpty() || isVersionGreater( service->version(), maxVer ) ) )
329 maxVer = service->version();
332 mServiceVersions.remove( name );
334 std::for_each( mServices.constBegin(), mServices.constEnd(), findGreaterVersion );
335 if ( !maxVer.isEmpty() )
338 const QString key = makeServiceKey( name, maxVer );
339 mServiceVersions.insert( name, VersionTable::mapped_type( version, key ) );
349 mNativeLoader.
loadModules( nativeModulePath, *
this, serverIface );
355 mServiceVersions.clear();
364 const QString name = api->
name();
365 const QString version = api->
version();
368 const QString key = makeServiceKey( name, version );
369 if ( mApis.constFind( key ) != mApis.constEnd() )
372 QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
376 QgsMessageLog::logMessage( QStringLiteral(
"Adding API %1 %2" ).arg( name, version ), QString(), Qgis::MessageLevel::Info );
377 mApis.insert( key, std::shared_ptr<QgsServerApi>( api ) );
384 const VersionTable::const_iterator v = mApiVersions.constFind( name );
385 if ( v == mApiVersions.constEnd() )
388 mApiVersions.insert( name, VersionTable::mapped_type( version, key ) );