32 QString makeServiceKey(
const QString &name,
const QString &version )
34 return QString(
"%1_%2" ).arg( name, version );
44 bool isVersionGreater(
const QString &v1,
const QString &v2 )
46 QStringList l1 = v1.split(
'.' );
47 QStringList l2 = v2.split(
'.' );
48 QStringList::iterator it1 = l1.begin();
49 QStringList::iterator it2 = l2.begin();
51 while ( it1 != l1.end() && it2 != l2.end() )
56 int i1 = it1->toInt( &isint );
59 int i2 = it2->toInt( &isint );
60 if ( isint && i1 != i2 )
94 VersionTable::const_iterator v = mVersions.constFind( name );
95 if ( v != mVersions.constEnd() )
97 key = version.isEmpty() ? v->second : makeServiceKey( name, version );
98 ServiceTable::const_iterator it = mServices.constFind( key );
99 if ( it != mServices.constEnd() )
107 service = mServices[v->second].get();
119 QString name = service->
name();
120 QString version = service->
version();
123 QString key = makeServiceKey( name, version );
124 if ( mServices.constFind( key ) != mServices.constEnd() )
131 mServices.insert( key, std::shared_ptr<QgsService>( service ) );
138 VersionTable::const_iterator v = mVersions.constFind( name );
139 if ( v == mVersions.constEnd() )
142 mVersions.insert( name, VersionTable::mapped_type( version, key ) );
165 VersionTable::const_iterator v = mVersions.constFind( name );
166 if ( v != mVersions.constEnd() )
168 if ( version.isEmpty() )
171 ServiceTable::iterator it = mServices.begin();
172 while ( it != mServices.end() )
174 if ( ( *it )->name() == name )
177 it = mServices.erase( it );
186 mVersions.remove( name );
190 QString key = makeServiceKey( name, version );
191 ServiceTable::iterator found = mServices.find( key );
192 if ( found != mServices.end() )
195 mServices.erase( found );
202 std::function < void ( const ServiceTable::mapped_type & ) >
203 findGreaterVersion = [name, &maxVer](
const ServiceTable::mapped_type & service )
205 if ( service->name() == name &&
206 ( maxVer.isEmpty() || isVersionGreater( service->version(), maxVer ) ) )
207 maxVer = service->version();
210 mVersions.remove( name );
212 std::for_each( mServices.constBegin(), mServices.constEnd(), findGreaterVersion );
213 if ( !maxVer.isEmpty() )
216 QString key = makeServiceKey( name, maxVer );
217 mVersions.insert( name, VersionTable::mapped_type( version, key ) );
227 mNativeLoader.
loadModules( nativeModulePath, *
this, serverIface );
void cleanUp()
Clean up registered service and unregister modules.
virtual QString name() const =0
~QgsServiceRegistry()
Destructor.
void unloadModules()
Unload all modules.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void init(const QString &nativeModulepath, QgsServerInterface *serverIface=nullptr)
Initialize registry, load modules and auto register services.
void registerService(QgsService *service)
Register a service by its name and version.
QgsService Class defining interfaces for QGIS server services.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
QgsService * getService(const QString &name, const QString &version=QString())
Retrieve a service from its name.
int unregisterService(const QString &name, const QString &version=QString())
Unregister service from its name and version.
void loadModules(const QString &modulePath, QgsServiceRegistry ®istrar, QgsServerInterface *serverIface=nullptr)
Load all modules from path.
virtual QString version() const =0