-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsserviceregistry.h
163 lines (137 loc) · 5.04 KB
/
qgsserviceregistry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/***************************************************************************
qgsserviceregistry.h
Class defining the service manager for QGIS server services.
-------------------
begin : 2016-12-05
copyright : (C) 2016 by David Marteau
email : david dot marteau at 3liz dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSSERVICEREGISTRY_H
#define QGSSERVICEREGISTRY_H
#include "qgsconfig.h"
#include "qgis.h"
#include <QHash>
#include <QString>
#include "qgsservicenativeloader.h"
#include <memory>
class QgsService;
class QgsServerRequest;
class QgsServerApi;
class QgsServerInterface;
/**
* \ingroup server
* \brief QgsServiceRegistry
* Class defining the registry manager for QGIS server services
*
* This class provides methods for registering and retrieving
* services.
*
* IMPORTANT: The registry hold ownership of registered services and
* will call 'delete' on cleanup
*
* \since QGIS 3.0
*/
class SERVER_EXPORT QgsServiceRegistry
{
public:
//! Constructor
QgsServiceRegistry() = default;
//! Destructor
~QgsServiceRegistry();
/**
* Retrieve a service from its name
* \param name the name of the service
* \param version the version string (optional)
* \returns QgsService
*
* If the version is not provided the higher version of the service is returned
*/
QgsService *getService( const QString &name, const QString &version = QString() );
/**
* Register a service by its name and version
*
* This method is intended to be called by modules for registering
* services. A module may register multiple services.
*
* The registry takes ownership of services and will call 'delete' on cleanup
*
* \param service a QgsService to be registered
*/
void registerService( QgsService *service SIP_TRANSFER );
/**
* Registers the QgsServerApi \a api
*
* The registry takes ownership of services and will call 'delete' on cleanup
* \since QGIS 3.10
*/
bool registerApi( QgsServerApi *api SIP_TRANSFER );
/**
* Unregisters API from its name and version
*
* \param name the name of the service
* \param version (optional) the specific version to unload
* \returns the number of APIs unregistered
*
* If the version is not specified then all versions from the specified API
* are unloaded
* \since QGIS 3.10
*/
int unregisterApi( const QString &name, const QString &version = QString() );
/**
* Searches the API register for an API matching the \a request and returns a (possibly NULL) pointer to it.
* \since QGIS 3.10
*/
QgsServerApi *apiForRequest( const QgsServerRequest &request ) const SIP_SKIP;
/**
* Retrieves an API from its name
*
* If the version is not provided the higher version of the service is returned
*
* \param name the name of the API
* \param version the version string (optional)
* \returns QgsServerApi
* \since QGIS 3.10
*/
QgsServerApi *getApi( const QString &name, const QString &version = QString() );
/**
* Unregister service from its name and version
*
* \param name the name of the service
* \param version (optional) the specific version to unload
* \returns 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 serverIface the server interface
* \param nativeModulepath the native module path
*/
void init( const QString &nativeModulepath, QgsServerInterface *serverIface = nullptr );
/**
* Clean up registered service and unregister modules
*/
void cleanUp();
private:
// XXX consider using QMap because of the few numbers of
// elements to handle
typedef QHash<QString, std::shared_ptr<QgsService> > ServiceTable;
typedef QHash<QString, std::shared_ptr<QgsServerApi> > ApiTable;
typedef QHash<QString, QPair<QString, QString> > VersionTable;
QgsServiceNativeLoader mNativeLoader;
ServiceTable mServices;
VersionTable mServiceVersions;
ApiTable mApis;
VersionTable mApiVersions;
};
#endif