Debian Codegraph @

src/imports/serviceframework/qdeclarativeservice_p.h

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSystems module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ***************************************************************************/
39
40 #ifndef QDECLARATIVESERVICE_P_H
41 #define QDECLARATIVESERVICE_P_H
42
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53
54 #include <QtCore>
55 #include <qserviceinterfacedescriptor.h>
56 #include <qservicemanager.h>
57 #include <qqml.h>
58 #include <qqmllist.h>
59
60 QT_BEGIN_NAMESPACE
61
62 class QDeclarativeServiceDescriptor : public QObject, public QServiceInterfaceDescriptor {
63 Q_OBJECT
64 Q_PROPERTY(QString serviceName READ serviceName CONSTANT)
65 Q_PROPERTY(QString interfaceName READ interfaceName CONSTANT)
66 Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
67 Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
68 Q_PROPERTY(bool valid READ isValid CONSTANT)
69
70 public:
71 QDeclarativeServiceDescriptor(QObject* parent = 0) : QObject(parent) {}
72 QDeclarativeServiceDescriptor(const QDeclarativeServiceDescriptor& other)
73 : QObject(0), QServiceInterfaceDescriptor(other) {}
74 QDeclarativeServiceDescriptor(const QServiceInterfaceDescriptor& other)
75 : QObject(0), QServiceInterfaceDescriptor(other) {}
76 bool operator==(const QServiceInterfaceDescriptor& other) const
77 { return QServiceInterfaceDescriptor::operator==(other); }
78 QDeclarativeServiceDescriptor& operator=(const QServiceInterfaceDescriptor& other)
79 {
80 QServiceInterfaceDescriptor::operator=(other);
81 return *this;
82 }
83 QDeclarativeServiceDescriptor& operator=(const QDeclarativeServiceDescriptor& other)
84 {
85 QServiceInterfaceDescriptor::operator=(other);
86 return *this;
87 }
88 };
89
90 class QDeclarativeServiceLoader : public QObject, public QQmlParserStatus {
91 Q_OBJECT
92 Q_INTERFACES(QQmlParserStatus)
93 Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
94 // ### Rename descriptor?
95 Q_PROPERTY(QDeclarativeServiceDescriptor* serviceDescriptor READ serviceDescriptor WRITE setServiceDescriptor NOTIFY serviceDescriptorChanged RESET resetServiceDescriptor) //Takes precedence over interfaceName if set
96 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
97 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
98 // ### Rename object?
99 Q_PROPERTY(QObject* serviceObject READ serviceObject NOTIFY serviceObjectChanged)
100 Q_ENUMS(Status)
101
102 public:
103 enum Status {
104 Null = 0,
105 Ready,
106 Loading,
107 Error
108 };
109
110 QDeclarativeServiceLoader();
111 ~QDeclarativeServiceLoader();
112
113 Q_INVOKABLE QString errorString() const
114 {
115 if (m_status == Error)
116 return m_errorString;
117 else
118 return "";
119 }
120
121 QString interfaceName() const
122 {
123 return m_interfaceName;
124 }
125
126 QDeclarativeServiceDescriptor* serviceDescriptor() const
127 {
128 return m_serviceDescriptor;
129 }
130
131 void resetServiceDescriptor()
132 {
133 setServiceDescriptor(0);
134 }
135
136 Status status() const
137 {
138 return m_status;
139 }
140
141 bool asynchronous() const
142 {
143 return m_asynchronous;
144 }
145
146 QObject* serviceObject() const
147 {
148 return m_serviceObject;
149 }
150
151 public slots:
152 void setInterfaceName(QString arg)
153 {
154 if (m_interfaceName != arg) {
155 m_interfaceName = arg;
156 emit interfaceNameChanged(arg);
157 if (!m_serviceDescriptor && m_componentComplete)
158 startLoading();
159 }
160 }
161
162 void setServiceDescriptor(QDeclarativeServiceDescriptor* arg)
163 {
164 if (m_serviceDescriptor != arg) {
165 m_serviceDescriptor = arg;
166 emit serviceDescriptorChanged(arg);
167 if (m_componentComplete)
168 startLoading();
169 }
170 }
171
172 void setAsynchronous(bool arg)
173 {
174 if (m_asynchronous != arg) {
175 m_asynchronous = arg;
176 emit asynchronousChanged(arg);
177 }
178 }
179
180 private Q_SLOTS:
181 void setStatus(Status arg)
182 {
183 if (m_status != arg) {
184 m_status = arg;
185 emit statusChanged(arg);
186 }
187 }
188
189 protected:
190 virtual void classBegin() {}
191 virtual void componentComplete();
192
193 signals:
194 void interfaceNameChanged(QString arg);
195
196 void serviceDescriptorChanged(QServiceInterfaceDescriptor* arg);
197
198 void statusChanged(Status arg);
199
200 void asynchronousChanged(bool arg);
201
202 void serviceObjectChanged(QObject* arg);
203
204 private slots:
205 void startLoading();
206 void finishLoading();
207 void IPCFault(QService::UnrecoverableIPCError);
208
209 private:
210 QString m_interfaceName;
211 QDeclarativeServiceDescriptor* m_serviceDescriptor;
212 Status m_status;
213 bool m_asynchronous;
214 QObject* m_serviceObject;
215 QString m_errorString;
216
217 bool m_componentComplete;
218 QServiceManager* m_serviceManager;
219 QServiceReply* m_serviceReply;
220 };
221
222 class QDeclarativeServiceFilter : public QObject, public QQmlParserStatus {
223 Q_OBJECT
224 Q_INTERFACES(QQmlParserStatus)
225 Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
226 Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
227 Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged)
228 Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged)
229 Q_PROPERTY(bool exactVersionMatching READ exactVersionMatching WRITE setExactVersionMatching NOTIFY exactVersionMatchingChanged)
230 // ### Rename monitorRegistrations ?
231 Q_PROPERTY(bool monitorServiceRegistrations READ monitorServiceRegistrations WRITE setMonitorServiceRegistrations NOTIFY monitorServiceRegistrationsChanged)
232 // ### Rename services ?
233 Q_PROPERTY(QQmlListProperty<QDeclarativeServiceDescriptor> serviceDescriptions READ serviceDescriptions NOTIFY serviceDescriptionsChanged)
234 public:
235 QDeclarativeServiceFilter(QObject* parent = 0);
236 ~QDeclarativeServiceFilter();
237 QString serviceName() const
238 {
239 return m_serviceName;
240 }
241
242 QString interfaceName() const
243 {
244 return m_interfaceName;
245 }
246
247 int majorVersion() const
248 {
249 return m_majorVersion;
250 }
251
252 int minorVersion() const
253 {
254 return m_minorVersion;
255 }
256
257 bool exactVersionMatching() const
258 {
259 return m_exactVersionMatching;
260 }
261
262 bool monitorServiceRegistrations() const
263 {
264 return m_monitorServiceRegistrations;
265 }
266
267 QQmlListProperty<QDeclarativeServiceDescriptor> serviceDescriptions()
268 {
269 return QQmlListProperty<QDeclarativeServiceDescriptor> (this, 0, s_append, s_count, s_at, s_clear);
270 }
271
272 public slots:
273 void setServiceName(QString arg)
274 {
275 if (m_serviceName != arg) {
276 m_serviceName = arg;
277 emit serviceNameChanged(arg);
278 updateServiceList();
279 }
280 }
281
282 void setInterfaceName(QString arg)
283 {
284 if (m_interfaceName != arg) {
285 m_interfaceName = arg;
286 emit interfaceNameChanged(arg);
287 updateServiceList();
288 }
289 }
290
291 void setMajorVersion(int arg)
292 {
293 if (m_majorVersion != arg) {
294 m_majorVersion = arg;
295 emit majorVersionChanged(arg);
296 updateServiceList();
297 }
298 }
299
300 void setMinorVersion(int arg)
301 {
302 if (m_minorVersion != arg) {
303 m_minorVersion = arg;
304 emit minorVersionChanged(arg);
305 updateServiceList();
306 }
307 }
308
309 void setExactVersionMatching(bool arg)
310 {
311 if (m_exactVersionMatching != arg) {
312 m_exactVersionMatching = arg;
313 emit exactVersionMatchingChanged(arg);
314 updateServiceList();
315 }
316 }
317
318 void setMonitorServiceRegistrations(bool updates);
319
320 protected:
321 virtual void classBegin() {}
322 virtual void componentComplete();
323 signals:
324 void serviceNameChanged(QString arg);
325
326 void interfaceNameChanged(QString arg);
327
328 void majorVersionChanged(int arg);
329
330 void minorVersionChanged(int arg);
331
332 void exactVersionMatchingChanged(bool arg);
333
334 void monitorServiceRegistrationsChanged(bool arg);
335
336 void serviceDescriptionsChanged();
337
338 private slots:
339 void updateServiceList();
340 void servicesAddedRemoved();
341 private:
342 QString m_serviceName;
343 QString m_interfaceName;
344 int m_majorVersion;
345 int m_minorVersion;
346 bool m_exactVersionMatching;
347 bool m_monitorServiceRegistrations;
348 QQmlListProperty<QDeclarativeServiceDescriptor*> m_serviceDescriptions;
349 QList<QDeclarativeServiceDescriptor> m_services;
350
351 QServiceManager* m_serviceManager;
352 bool m_componentComplete;
353
354 static void s_append(QQmlListProperty<QDeclarativeServiceDescriptor> *prop, QDeclarativeServiceDescriptor *service);
355 static int s_count(QQmlListProperty<QDeclarativeServiceDescriptor> *prop);
356 static QDeclarativeServiceDescriptor* s_at(QQmlListProperty<QDeclarativeServiceDescriptor> *prop, int index);
357 static void s_clear(QQmlListProperty<QDeclarativeServiceDescriptor> *prop);
358 };
359
360 QT_END_NAMESPACE
361
362 QML_DECLARE_TYPE(QDeclarativeServiceLoader);
363 QML_DECLARE_TYPE(QDeclarativeServiceDescriptor);
364 QML_DECLARE_TYPE(QDeclarativeServiceFilter);
365
366
367 #endif // QDECLARATIVESERVICE_P_H