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() )
109 service = mServices[v->second].get();
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() )
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 )
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() )
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 )
239 if ( api->accept( request.
url() ) )
241 Q_ASSERT( !api->name().isEmpty() );
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() )
270 api = mApis[v->second].get();
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 )
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() )
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() )
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 ) );
@ Warning
Warning message.
@ Critical
Critical/error message.
@ Info
Information message.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Server generic API endpoint abstract base class.
virtual const QString version() const
Returns the version of the service.
virtual const QString name() const =0
Returns the API name.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
void unloadModules()
Unload all modules.
void loadModules(const QString &modulePath, QgsServiceRegistry ®istrar, QgsServerInterface *serverIface=nullptr)
Load all modules from path.
void cleanUp()
Clean up registered service and unregister modules.
bool registerApi(QgsServerApi *api)
Registers the QgsServerApi api.
int unregisterService(const QString &name, const QString &version=QString())
Unregister service from its name and version.
int unregisterApi(const QString &name, const QString &version=QString())
Unregisters API from its name and version.
QgsServerApi * apiForRequest(const QgsServerRequest &request) const
Searches the API register for an API matching the request and returns a (possibly NULL) pointer to it...
void init(const QString &nativeModulepath, QgsServerInterface *serverIface=nullptr)
Initialize registry, load modules and auto register services.
QgsService * getService(const QString &name, const QString &version=QString())
Retrieve a service from its name.
void registerService(QgsService *service)
Register a service by its name and version.
QgsServerApi * getApi(const QString &name, const QString &version=QString())
Retrieves an API from its name.
QgsService Class defining interfaces for QGIS server services.
virtual QString name() const =0
virtual QString version() const =0