Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusmetaobject.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
6 | ** | - | ||||||
7 | ** This file is part of the QtDBus module of the Qt Toolkit. | - | ||||||
8 | ** | - | ||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
10 | ** Commercial License Usage | - | ||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
17 | ** | - | ||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
25 | ** | - | ||||||
26 | ** GNU General Public License Usage | - | ||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
36 | ** | - | ||||||
37 | ** $QT_END_LICENSE$ | - | ||||||
38 | ** | - | ||||||
39 | ****************************************************************************/ | - | ||||||
40 | - | |||||||
41 | #include "qdbusmetaobject_p.h" | - | ||||||
42 | - | |||||||
43 | #include <QtCore/qbytearray.h> | - | ||||||
44 | #include <QtCore/qhash.h> | - | ||||||
45 | #include <QtCore/qstring.h> | - | ||||||
46 | #include <QtCore/qvarlengtharray.h> | - | ||||||
47 | - | |||||||
48 | #include "qdbusutil_p.h" | - | ||||||
49 | #include "qdbuserror.h" | - | ||||||
50 | #include "qdbusmetatype.h" | - | ||||||
51 | #include "qdbusargument.h" | - | ||||||
52 | #include "qdbusintrospection_p.h" | - | ||||||
53 | #include "qdbusabstractinterface_p.h" | - | ||||||
54 | - | |||||||
55 | #include <private/qmetaobject_p.h> | - | ||||||
56 | #include <private/qmetaobjectbuilder_p.h> | - | ||||||
57 | - | |||||||
58 | #ifndef QT_NO_DBUS | - | ||||||
59 | - | |||||||
60 | QT_BEGIN_NAMESPACE | - | ||||||
61 | - | |||||||
62 | class QDBusMetaObjectGenerator | - | ||||||
63 | { | - | ||||||
64 | public: | - | ||||||
65 | QDBusMetaObjectGenerator(const QString &interface, | - | ||||||
66 | const QDBusIntrospection::Interface *parsedData); | - | ||||||
67 | void write(QDBusMetaObject *obj); | - | ||||||
68 | void writeWithoutXml(QDBusMetaObject *obj); | - | ||||||
69 | - | |||||||
70 | private: | - | ||||||
71 | struct Method { | - | ||||||
72 | QList<QByteArray> parameterNames; | - | ||||||
73 | QByteArray tag; | - | ||||||
74 | QByteArray name; | - | ||||||
75 | QVarLengthArray<int, 4> inputTypes; | - | ||||||
76 | QVarLengthArray<int, 4> outputTypes; | - | ||||||
77 | QByteArray rawReturnType; | - | ||||||
78 | int flags; | - | ||||||
79 | }; | - | ||||||
80 | - | |||||||
81 | struct Property { | - | ||||||
82 | QByteArray typeName; | - | ||||||
83 | QByteArray signature; | - | ||||||
84 | int type; | - | ||||||
85 | int flags; | - | ||||||
86 | }; | - | ||||||
87 | struct Type { | - | ||||||
88 | int id; | - | ||||||
89 | QByteArray name; | - | ||||||
90 | }; | - | ||||||
91 | - | |||||||
92 | QMap<QByteArray, Method> signals_; | - | ||||||
93 | QMap<QByteArray, Method> methods; | - | ||||||
94 | QMap<QByteArray, Property> properties; | - | ||||||
95 | - | |||||||
96 | const QDBusIntrospection::Interface *data; | - | ||||||
97 | QString interface; | - | ||||||
98 | - | |||||||
99 | Type findType(const QByteArray &signature, | - | ||||||
100 | const QDBusIntrospection::Annotations &annotations, | - | ||||||
101 | const char *direction = "Out", int id = -1); | - | ||||||
102 | - | |||||||
103 | void parseMethods(); | - | ||||||
104 | void parseSignals(); | - | ||||||
105 | void parseProperties(); | - | ||||||
106 | - | |||||||
107 | static int aggregateParameterCount(const QMap<QByteArray, Method> &map); | - | ||||||
108 | }; | - | ||||||
109 | - | |||||||
110 | static const int intsPerProperty = 2; | - | ||||||
111 | static const int intsPerMethod = 2; | - | ||||||
112 | - | |||||||
113 | struct QDBusMetaObjectPrivate : public QMetaObjectPrivate | - | ||||||
114 | { | - | ||||||
115 | int propertyDBusData; | - | ||||||
116 | int methodDBusData; | - | ||||||
117 | }; | - | ||||||
118 | - | |||||||
119 | QDBusMetaObjectGenerator::QDBusMetaObjectGenerator(const QString &interfaceName, | - | ||||||
120 | const QDBusIntrospection::Interface *parsedData) | - | ||||||
121 | : data(parsedData), interface(interfaceName) | - | ||||||
122 | { | - | ||||||
123 | if (data) { | - | ||||||
124 | parseProperties(); | - | ||||||
125 | parseSignals(); // call parseSignals first so that slots override signals | - | ||||||
126 | parseMethods(); | - | ||||||
127 | } | - | ||||||
128 | } | - | ||||||
129 | - | |||||||
130 | static int registerComplexDBusType(const char *typeName) | - | ||||||
131 | { | - | ||||||
132 | struct QDBusRawTypeHandler { | - | ||||||
133 | static void destruct(void *) | - | ||||||
134 | { | - | ||||||
135 | qFatal("Cannot destruct placeholder type QDBusRawType"); | - | ||||||
136 | } | - | ||||||
137 | - | |||||||
138 | static void *construct(void *, const void *) | - | ||||||
139 | { | - | ||||||
140 | qFatal("Cannot construct placeholder type QDBusRawType"); | - | ||||||
141 | return 0; | - | ||||||
142 | } | - | ||||||
143 | }; | - | ||||||
144 | - | |||||||
145 | return QMetaType::registerNormalizedType(typeName, | - | ||||||
146 | QDBusRawTypeHandler::destruct, | - | ||||||
147 | QDBusRawTypeHandler::construct, | - | ||||||
148 | sizeof(void *), | - | ||||||
149 | QMetaType::MovableType, | - | ||||||
150 | 0); | - | ||||||
151 | } | - | ||||||
152 | - | |||||||
153 | Q_DBUS_EXPORT bool qt_dbus_metaobject_skip_annotations = false; | - | ||||||
154 | - | |||||||
155 | QDBusMetaObjectGenerator::Type | - | ||||||
156 | QDBusMetaObjectGenerator::findType(const QByteArray &signature, | - | ||||||
157 | const QDBusIntrospection::Annotations &annotations, | - | ||||||
158 | const char *direction, int id) | - | ||||||
159 | { | - | ||||||
160 | Type result; | - | ||||||
161 | result.id = QVariant::Invalid; | - | ||||||
162 | - | |||||||
163 | int type = QDBusMetaType::signatureToType(signature); | - | ||||||
164 | if (type == QVariant::Invalid && !qt_dbus_metaobject_skip_annotations) { | - | ||||||
165 | // it's not a type normally handled by our meta type system | - | ||||||
166 | // it must contain an annotation | - | ||||||
167 | QString annotationName = QString::fromLatin1("org.qtproject.QtDBus.QtTypeName"); | - | ||||||
168 | if (id >= 0) | - | ||||||
169 | annotationName += QString::fromLatin1(".%1%2") | - | ||||||
170 | .arg(QLatin1String(direction)) | - | ||||||
171 | .arg(id); | - | ||||||
172 | - | |||||||
173 | // extract from annotations: | - | ||||||
174 | QByteArray typeName = annotations.value(annotationName).toLatin1(); | - | ||||||
175 | - | |||||||
176 | // verify that it's a valid one | - | ||||||
177 | if (typeName.isEmpty()) { | - | ||||||
178 | // try the old annotation from Qt 4 | - | ||||||
179 | annotationName = QString::fromLatin1("com.trolltech.QtDBus.QtTypeName"); | - | ||||||
180 | if (id >= 0) | - | ||||||
181 | annotationName += QString::fromLatin1(".%1%2") | - | ||||||
182 | .arg(QLatin1String(direction)) | - | ||||||
183 | .arg(id); | - | ||||||
184 | typeName = annotations.value(annotationName).toLatin1(); | - | ||||||
185 | } | - | ||||||
186 | - | |||||||
187 | if (!typeName.isEmpty()) { | - | ||||||
188 | // type name found | - | ||||||
189 | type = QMetaType::type(typeName); | - | ||||||
190 | } | - | ||||||
191 | - | |||||||
192 | if (type == QVariant::Invalid || signature != QDBusMetaType::typeToSignature(type)) { | - | ||||||
193 | // type is still unknown or doesn't match back to the signature that it | - | ||||||
194 | // was expected to, so synthesize a fake type | - | ||||||
195 | typeName = "QDBusRawType<0x" + signature.toHex() + ">*"; | - | ||||||
196 | type = registerComplexDBusType(typeName); | - | ||||||
197 | } | - | ||||||
198 | - | |||||||
199 | result.name = typeName; | - | ||||||
200 | } else if (type == QVariant::Invalid) { | - | ||||||
201 | // this case is used only by the qdbus command-line tool | - | ||||||
202 | // invalid, let's create an impossible type that contains the signature | - | ||||||
203 | - | |||||||
204 | if (signature == "av") { | - | ||||||
205 | result.name = "QVariantList"; | - | ||||||
206 | type = QVariant::List; | - | ||||||
207 | } else if (signature == "a{sv}") { | - | ||||||
208 | result.name = "QVariantMap"; | - | ||||||
209 | type = QVariant::Map; | - | ||||||
210 | } else if (signature == "a{ss}") { | - | ||||||
211 | result.name = "QMap<QString,QString>"; | - | ||||||
212 | type = qMetaTypeId<QMap<QString, QString> >(); | - | ||||||
213 | } else { | - | ||||||
214 | result.name = "{D-Bus type \"" + signature + "\"}"; | - | ||||||
215 | type = registerComplexDBusType(result.name); | - | ||||||
216 | } | - | ||||||
217 | } else { | - | ||||||
218 | result.name = QMetaType::typeName(type); | - | ||||||
219 | } | - | ||||||
220 | - | |||||||
221 | result.id = type; | - | ||||||
222 | return result; // success | - | ||||||
223 | } | - | ||||||
224 | - | |||||||
225 | void QDBusMetaObjectGenerator::parseMethods() | - | ||||||
226 | { | - | ||||||
227 | // | - | ||||||
228 | // TODO: | - | ||||||
229 | // Add cloned methods when the remote object has return types | - | ||||||
230 | // | - | ||||||
231 | - | |||||||
232 | QDBusIntrospection::Methods::ConstIterator method_it = data->methods.constBegin(); | - | ||||||
233 | QDBusIntrospection::Methods::ConstIterator method_end = data->methods.constEnd(); | - | ||||||
234 | for ( ; method_it != method_end; ++method_it) { | - | ||||||
235 | const QDBusIntrospection::Method &m = *method_it; | - | ||||||
236 | Method mm; | - | ||||||
237 | - | |||||||
238 | mm.name = m.name.toLatin1(); | - | ||||||
239 | QByteArray prototype = mm.name; | - | ||||||
240 | prototype += '('; | - | ||||||
241 | - | |||||||
242 | bool ok = true; | - | ||||||
243 | - | |||||||
244 | // build the input argument list | - | ||||||
245 | for (int i = 0; i < m.inputArgs.count(); ++i) { | - | ||||||
246 | const QDBusIntrospection::Argument &arg = m.inputArgs.at(i); | - | ||||||
247 | - | |||||||
248 | Type type = findType(arg.type.toLatin1(), m.annotations, "In", i); | - | ||||||
249 | if (type.id == QVariant::Invalid) { | - | ||||||
250 | ok = false; | - | ||||||
251 | break; | - | ||||||
252 | } | - | ||||||
253 | - | |||||||
254 | mm.inputTypes.append(type.id); | - | ||||||
255 | - | |||||||
256 | mm.parameterNames.append(arg.name.toLatin1()); | - | ||||||
257 | - | |||||||
258 | prototype.append(type.name); | - | ||||||
259 | prototype.append(','); | - | ||||||
260 | } | - | ||||||
261 | if (!ok) continue; | - | ||||||
262 | - | |||||||
263 | // build the output argument list: | - | ||||||
264 | for (int i = 0; i < m.outputArgs.count(); ++i) { | - | ||||||
265 | const QDBusIntrospection::Argument &arg = m.outputArgs.at(i); | - | ||||||
266 | - | |||||||
267 | Type type = findType(arg.type.toLatin1(), m.annotations, "Out", i); | - | ||||||
268 | if (type.id == QVariant::Invalid) { | - | ||||||
269 | ok = false; | - | ||||||
270 | break; | - | ||||||
271 | } | - | ||||||
272 | - | |||||||
273 | mm.outputTypes.append(type.id); | - | ||||||
274 | - | |||||||
275 | if (i == 0 && type.id == -1) { | - | ||||||
276 | mm.rawReturnType = type.name; | - | ||||||
277 | } | - | ||||||
278 | if (i != 0) { | - | ||||||
279 | // non-const ref parameter | - | ||||||
280 | mm.parameterNames.append(arg.name.toLatin1()); | - | ||||||
281 | - | |||||||
282 | prototype.append(type.name); | - | ||||||
283 | prototype.append("&,"); | - | ||||||
284 | } | - | ||||||
285 | } | - | ||||||
286 | if (!ok) continue; | - | ||||||
287 | - | |||||||
288 | // convert the last commas: | - | ||||||
289 | if (!mm.parameterNames.isEmpty()) | - | ||||||
290 | prototype[prototype.length() - 1] = ')'; | - | ||||||
291 | else | - | ||||||
292 | prototype.append(')'); | - | ||||||
293 | - | |||||||
294 | // check the async tag | - | ||||||
295 | if (m.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true")) | - | ||||||
296 | mm.tag = "Q_NOREPLY"; | - | ||||||
297 | - | |||||||
298 | // meta method flags | - | ||||||
299 | mm.flags = AccessPublic | MethodSlot | MethodScriptable; | - | ||||||
300 | - | |||||||
301 | // add | - | ||||||
302 | methods.insert(QMetaObject::normalizedSignature(prototype), mm); | - | ||||||
303 | } | - | ||||||
304 | } | - | ||||||
305 | - | |||||||
306 | void QDBusMetaObjectGenerator::parseSignals() | - | ||||||
307 | { | - | ||||||
308 | QDBusIntrospection::Signals::ConstIterator signal_it = data->signals_.constBegin(); | - | ||||||
309 | QDBusIntrospection::Signals::ConstIterator signal_end = data->signals_.constEnd(); | - | ||||||
310 | for ( ; signal_it != signal_end; ++signal_it) { | - | ||||||
311 | const QDBusIntrospection::Signal &s = *signal_it; | - | ||||||
312 | Method mm; | - | ||||||
313 | - | |||||||
314 | mm.name = s.name.toLatin1(); | - | ||||||
315 | QByteArray prototype = mm.name; | - | ||||||
316 | prototype += '('; | - | ||||||
317 | - | |||||||
318 | bool ok = true; | - | ||||||
319 | - | |||||||
320 | // build the output argument list | - | ||||||
321 | for (int i = 0; i < s.outputArgs.count(); ++i) { | - | ||||||
322 | const QDBusIntrospection::Argument &arg = s.outputArgs.at(i); | - | ||||||
323 | - | |||||||
324 | Type type = findType(arg.type.toLatin1(), s.annotations, "Out", i); | - | ||||||
325 | if (type.id == QVariant::Invalid) { | - | ||||||
326 | ok = false; | - | ||||||
327 | break; | - | ||||||
328 | } | - | ||||||
329 | - | |||||||
330 | mm.inputTypes.append(type.id); | - | ||||||
331 | - | |||||||
332 | mm.parameterNames.append(arg.name.toLatin1()); | - | ||||||
333 | - | |||||||
334 | prototype.append(type.name); | - | ||||||
335 | prototype.append(','); | - | ||||||
336 | } | - | ||||||
337 | if (!ok) continue; | - | ||||||
338 | - | |||||||
339 | // convert the last commas: | - | ||||||
340 | if (!mm.parameterNames.isEmpty()) | - | ||||||
341 | prototype[prototype.length() - 1] = ')'; | - | ||||||
342 | else | - | ||||||
343 | prototype.append(')'); | - | ||||||
344 | - | |||||||
345 | // meta method flags | - | ||||||
346 | mm.flags = AccessPublic | MethodSignal | MethodScriptable; | - | ||||||
347 | - | |||||||
348 | // add | - | ||||||
349 | signals_.insert(QMetaObject::normalizedSignature(prototype), mm); | - | ||||||
350 | } | - | ||||||
351 | } | - | ||||||
352 | - | |||||||
353 | void QDBusMetaObjectGenerator::parseProperties() | - | ||||||
354 | { | - | ||||||
355 | QDBusIntrospection::Properties::ConstIterator prop_it = data->properties.constBegin(); | - | ||||||
356 | QDBusIntrospection::Properties::ConstIterator prop_end = data->properties.constEnd(); | - | ||||||
357 | for ( ; prop_it != prop_end; ++prop_it) { | - | ||||||
358 | const QDBusIntrospection::Property &p = *prop_it; | - | ||||||
359 | Property mp; | - | ||||||
360 | Type type = findType(p.type.toLatin1(), p.annotations); | - | ||||||
361 | if (type.id == QVariant::Invalid) | - | ||||||
362 | continue; | - | ||||||
363 | - | |||||||
364 | QByteArray name = p.name.toLatin1(); | - | ||||||
365 | mp.signature = p.type.toLatin1(); | - | ||||||
366 | mp.type = type.id; | - | ||||||
367 | mp.typeName = type.name; | - | ||||||
368 | - | |||||||
369 | // build the flags: | - | ||||||
370 | mp.flags = StdCppSet | Scriptable | Stored | Designable; | - | ||||||
371 | if (p.access != QDBusIntrospection::Property::Write) | - | ||||||
372 | mp.flags |= Readable; | - | ||||||
373 | if (p.access != QDBusIntrospection::Property::Read) | - | ||||||
374 | mp.flags |= Writable; | - | ||||||
375 | - | |||||||
376 | // add the property: | - | ||||||
377 | properties.insert(name, mp); | - | ||||||
378 | } | - | ||||||
379 | } | - | ||||||
380 | - | |||||||
381 | // Returns the sum of all parameters (including return type) for the given | - | ||||||
382 | // \a map of methods. This is needed for calculating the size of the methods' | - | ||||||
383 | // parameter type/name meta-data. | - | ||||||
384 | int QDBusMetaObjectGenerator::aggregateParameterCount(const QMap<QByteArray, Method> &map) | - | ||||||
385 | { | - | ||||||
386 | int sum = 0; | - | ||||||
387 | QMap<QByteArray, Method>::const_iterator it; | - | ||||||
388 | for (it = map.constBegin(); it != map.constEnd(); ++it) { | - | ||||||
389 | const Method &m = it.value(); | - | ||||||
390 | sum += m.inputTypes.size() + qMax(1, m.outputTypes.size()); | - | ||||||
391 | } | - | ||||||
392 | return sum; | - | ||||||
393 | } | - | ||||||
394 | - | |||||||
395 | void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) | - | ||||||
396 | { | - | ||||||
397 | // this code here is mostly copied from qaxbase.cpp | - | ||||||
398 | // with a few modifications to make it cleaner | - | ||||||
399 | - | |||||||
400 | QString className = interface; | - | ||||||
401 | className.replace(QLatin1Char('.'), QLatin1String("::")); | - | ||||||
402 | if (className.isEmpty())
| 0-152 | ||||||
403 | className = QLatin1String("QDBusInterface"); never executed: className = QLatin1String("QDBusInterface"); | 0 | ||||||
404 | - | |||||||
405 | QVarLengthArray<int> idata; | - | ||||||
406 | idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int)); | - | ||||||
407 | - | |||||||
408 | int methodParametersDataSize = | - | ||||||
409 | ((aggregateParameterCount(signals_) | - | ||||||
410 | + aggregateParameterCount(methods)) * 2) // types and parameter names | - | ||||||
411 | - signals_.count() // return "parameters" don't have names | - | ||||||
412 | - methods.count(); // ditto | - | ||||||
413 | - | |||||||
414 | QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(idata.data()); | - | ||||||
415 | Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 7, "QtDBus meta-object generator should generate the same version as moc"); | - | ||||||
416 | header->revision = QMetaObjectPrivate::OutputRevision; | - | ||||||
417 | header->className = 0; | - | ||||||
418 | header->classInfoCount = 0; | - | ||||||
419 | header->classInfoData = 0; | - | ||||||
420 | header->methodCount = signals_.count() + methods.count(); | - | ||||||
421 | header->methodData = idata.size(); | - | ||||||
422 | header->propertyCount = properties.count(); | - | ||||||
423 | header->propertyData = header->methodData + header->methodCount * 5 + methodParametersDataSize; | - | ||||||
424 | header->enumeratorCount = 0; | - | ||||||
425 | header->enumeratorData = 0; | - | ||||||
426 | header->constructorCount = 0; | - | ||||||
427 | header->constructorData = 0; | - | ||||||
428 | header->flags = RequiresVariantMetaObject; | - | ||||||
429 | header->signalCount = signals_.count(); | - | ||||||
430 | // These are specific to QDBusMetaObject: | - | ||||||
431 | header->propertyDBusData = header->propertyData + header->propertyCount * 3; | - | ||||||
432 | header->methodDBusData = header->propertyDBusData + header->propertyCount * intsPerProperty; | - | ||||||
433 | - | |||||||
434 | int data_size = idata.size() + | - | ||||||
435 | (header->methodCount * (5+intsPerMethod)) + methodParametersDataSize + | - | ||||||
436 | (header->propertyCount * (3+intsPerProperty)); | - | ||||||
437 | foreachfor (const Method &mm ,: qAsConst(signals_))) | - | ||||||
438 | data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count(); executed 98 times by 12 tests: data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count(); Executed by:
| 98 | ||||||
439 | foreachfor (const Method &mm ,: qAsConst(methods))) | - | ||||||
440 | data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count(); executed 990 times by 12 tests: data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count(); Executed by:
| 990 | ||||||
441 | idata.resize(data_size + 1); | - | ||||||
442 | - | |||||||
443 | QMetaStringTable strings(className.toLatin1()); | - | ||||||
444 | - | |||||||
445 | int offset = header->methodData; | - | ||||||
446 | int parametersOffset = offset + header->methodCount * 5; | - | ||||||
447 | int signatureOffset = header->methodDBusData; | - | ||||||
448 | int typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod; | - | ||||||
449 | idata[typeidOffset++] = 0; // eod | - | ||||||
450 | - | |||||||
451 | // add each method: | - | ||||||
452 | for (int x = 0; x < 2; ++x) {
| 152-304 | ||||||
453 | // Signals must be added before other methods, to match moc. | - | ||||||
454 | QMap<QByteArray, Method> &map = (x == 0) ? signals_ : methods;
| 152 | ||||||
455 | for (QMap<QByteArray, Method>::ConstIterator it = map.constBegin(); | - | ||||||
456 | it != map.constEnd(); ++it) {
| 304-1088 | ||||||
457 | const Method &mm = it.value(); | - | ||||||
458 | - | |||||||
459 | int argc = mm.inputTypes.size() + qMax(0, mm.outputTypes.size() - 1); | - | ||||||
460 | - | |||||||
461 | idata[offset++] = strings.enter(mm.name); | - | ||||||
462 | idata[offset++] = argc; | - | ||||||
463 | idata[offset++] = parametersOffset; | - | ||||||
464 | idata[offset++] = strings.enter(mm.tag); | - | ||||||
465 | idata[offset++] = mm.flags; | - | ||||||
466 | - | |||||||
467 | // Parameter types | - | ||||||
468 | for (int i = -1; i < argc; ++i) {
| 1088-1756 | ||||||
469 | int type; | - | ||||||
470 | QByteArray typeName; | - | ||||||
471 | if (i < 0) { // Return type
| 668-1088 | ||||||
472 | if (!mm.outputTypes.isEmpty()) {
| 514-574 | ||||||
473 | type = mm.outputTypes.first(); | - | ||||||
474 | if (type == -1) {
| 0-514 | ||||||
475 | type = IsUnresolvedType | strings.enter(mm.rawReturnType); | - | ||||||
476 | } never executed: end of block | 0 | ||||||
477 | } else { executed 514 times by 11 tests: end of block Executed by:
| 514 | ||||||
478 | type = QMetaType::Void; | - | ||||||
479 | } executed 574 times by 12 tests: end of block Executed by:
| 574 | ||||||
480 | } else if (i < mm.inputTypes.size()) {
| 19-649 | ||||||
481 | type = mm.inputTypes.at(i); | - | ||||||
482 | } else { executed 649 times by 11 tests: end of block Executed by:
| 649 | ||||||
483 | Q_ASSERT(mm.outputTypes.size() > 1); | - | ||||||
484 | type = mm.outputTypes.at(i - mm.inputTypes.size() + 1); | - | ||||||
485 | // Output parameters are references; type id not available | - | ||||||
486 | typeName = QMetaType::typeName(type); | - | ||||||
487 | typeName.append('&'); | - | ||||||
488 | } executed 19 times by 5 tests: end of block Executed by:
| 19 | ||||||
489 | Q_ASSERT(type != QMetaType::UnknownType); | - | ||||||
490 | int typeInfo; | - | ||||||
491 | if (!typeName.isEmpty())
| 19-1737 | ||||||
492 | typeInfo = IsUnresolvedType | strings.enter(typeName); executed 19 times by 5 tests: typeInfo = IsUnresolvedType | strings.enter(typeName); Executed by:
| 19 | ||||||
493 | else | - | ||||||
494 | typeInfo = type; executed 1737 times by 12 tests: typeInfo = type; Executed by:
| 1737 | ||||||
495 | idata[parametersOffset++] = typeInfo; | - | ||||||
496 | } executed 1756 times by 12 tests: end of block Executed by:
| 1756 | ||||||
497 | // Parameter names | - | ||||||
498 | for (int i = 0; i < argc; ++i)
| 668-1088 | ||||||
499 | idata[parametersOffset++] = strings.enter(mm.parameterNames.at(i)); executed 668 times by 11 tests: idata[parametersOffset++] = strings.enter(mm.parameterNames.at(i)); Executed by:
| 668 | ||||||
500 | - | |||||||
501 | idata[signatureOffset++] = typeidOffset; | - | ||||||
502 | idata[typeidOffset++] = mm.inputTypes.count(); | - | ||||||
503 | memcpy(idata.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.count() * sizeof(int)); | - | ||||||
504 | typeidOffset += mm.inputTypes.count(); | - | ||||||
505 | - | |||||||
506 | idata[signatureOffset++] = typeidOffset; | - | ||||||
507 | idata[typeidOffset++] = mm.outputTypes.count(); | - | ||||||
508 | memcpy(idata.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.count() * sizeof(int)); | - | ||||||
509 | typeidOffset += mm.outputTypes.count(); | - | ||||||
510 | } executed 1088 times by 12 tests: end of block Executed by:
| 1088 | ||||||
511 | } executed 304 times by 12 tests: end of block Executed by:
| 304 | ||||||
512 | - | |||||||
513 | Q_ASSERT(offset == header->methodData + header->methodCount * 5); | - | ||||||
514 | Q_ASSERT(parametersOffset == header->propertyData); | - | ||||||
515 | Q_ASSERT(signatureOffset == header->methodDBusData + header->methodCount * intsPerMethod); | - | ||||||
516 | Q_ASSERT(typeidOffset == idata.size()); | - | ||||||
517 | offset += methodParametersDataSize; | - | ||||||
518 | Q_ASSERT(offset == header->propertyData); | - | ||||||
519 | - | |||||||
520 | // add each property | - | ||||||
521 | signatureOffset = header->propertyDBusData; | - | ||||||
522 | for (QMap<QByteArray, Property>::ConstIterator it = properties.constBegin(); | - | ||||||
523 | it != properties.constEnd(); ++it) {
| 88-152 | ||||||
524 | const Property &mp = it.value(); | - | ||||||
525 | - | |||||||
526 | // form is name, typeinfo, flags | - | ||||||
527 | idata[offset++] = strings.enter(it.key()); // name | - | ||||||
528 | Q_ASSERT(mp.type != QMetaType::UnknownType); | - | ||||||
529 | idata[offset++] = mp.type; | - | ||||||
530 | idata[offset++] = mp.flags; | - | ||||||
531 | - | |||||||
532 | idata[signatureOffset++] = strings.enter(mp.signature); | - | ||||||
533 | idata[signatureOffset++] = mp.type; | - | ||||||
534 | } executed 88 times by 4 tests: end of block Executed by:
| 88 | ||||||
535 | - | |||||||
536 | Q_ASSERT(offset == header->propertyDBusData); | - | ||||||
537 | Q_ASSERT(signatureOffset == header->methodDBusData); | - | ||||||
538 | - | |||||||
539 | char *string_data = new char[strings.blobSize()]; | - | ||||||
540 | strings.writeBlob(string_data); | - | ||||||
541 | - | |||||||
542 | uint *uint_data = new uint[idata.size()]; | - | ||||||
543 | memcpy(uint_data, idata.data(), idata.size() * sizeof(int)); | - | ||||||
544 | - | |||||||
545 | // put the metaobject together | - | ||||||
546 | obj->d.data = uint_data; | - | ||||||
547 | obj->d.relatedMetaObjects = 0; | - | ||||||
548 | obj->d.static_metacall = 0; | - | ||||||
549 | obj->d.extradata = 0; | - | ||||||
550 | obj->d.stringdata = reinterpret_cast<const QByteArrayData *>(string_data); | - | ||||||
551 | obj->d.superdata = &QDBusAbstractInterface::staticMetaObject; | - | ||||||
552 | } executed 152 times by 12 tests: end of block Executed by:
| 152 | ||||||
553 | - | |||||||
554 | #if 0 | - | ||||||
555 | void QDBusMetaObjectGenerator::writeWithoutXml(const QString &interface) | - | ||||||
556 | { | - | ||||||
557 | // no XML definition | - | ||||||
558 | QString tmp(interface); | - | ||||||
559 | tmp.replace(QLatin1Char('.'), QLatin1String("::")); | - | ||||||
560 | QByteArray name(tmp.toLatin1()); | - | ||||||
561 | - | |||||||
562 | QDBusMetaObjectPrivate *header = new QDBusMetaObjectPrivate; | - | ||||||
563 | memset(header, 0, sizeof *header); | - | ||||||
564 | header->revision = 1; | - | ||||||
565 | // leave the rest with 0 | - | ||||||
566 | - | |||||||
567 | char *stringdata = new char[name.length() + 1]; | - | ||||||
568 | stringdata[name.length()] = '\0'; | - | ||||||
569 | - | |||||||
570 | d.data = reinterpret_cast<uint*>(header); | - | ||||||
571 | d.relatedMetaObjects = 0; | - | ||||||
572 | d.static_metacall = 0; | - | ||||||
573 | d.extradata = 0; | - | ||||||
574 | d.stringdata = stringdata; | - | ||||||
575 | d.superdata = &QDBusAbstractInterface::staticMetaObject; | - | ||||||
576 | cached = false; | - | ||||||
577 | } | - | ||||||
578 | #endif | - | ||||||
579 | - | |||||||
580 | ///////// | - | ||||||
581 | // class QDBusMetaObject | - | ||||||
582 | - | |||||||
583 | QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, const QString &xml, | - | ||||||
584 | QHash<QString, QDBusMetaObject *> &cache, | - | ||||||
585 | QDBusError &error) | - | ||||||
586 | { | - | ||||||
587 | error = QDBusError(); | - | ||||||
588 | QDBusIntrospection::Interfaces parsed = QDBusIntrospection::parseInterfaces(xml); | - | ||||||
589 | - | |||||||
590 | QDBusMetaObject *we = 0; | - | ||||||
591 | QDBusIntrospection::Interfaces::ConstIterator it = parsed.constBegin(); | - | ||||||
592 | QDBusIntrospection::Interfaces::ConstIterator end = parsed.constEnd(); | - | ||||||
593 | for ( ; it != end; ++it) { | - | ||||||
594 | // check if it's in the cache | - | ||||||
595 | bool us = it.key() == interface; | - | ||||||
596 | - | |||||||
597 | QDBusMetaObject *obj = cache.value(it.key(), 0); | - | ||||||
598 | if ( !obj && ( us || !interface.startsWith( QLatin1String("local.") ) ) ) { | - | ||||||
599 | // not in cache; create | - | ||||||
600 | obj = new QDBusMetaObject; | - | ||||||
601 | QDBusMetaObjectGenerator generator(it.key(), it.value().constData()); | - | ||||||
602 | generator.write(obj); | - | ||||||
603 | - | |||||||
604 | if ( (obj->cached = !it.key().startsWith( QLatin1String("local.") )) ) | - | ||||||
605 | // cache it | - | ||||||
606 | cache.insert(it.key(), obj); | - | ||||||
607 | else if (!us) | - | ||||||
608 | delete obj; | - | ||||||
609 | - | |||||||
610 | } | - | ||||||
611 | - | |||||||
612 | if (us) | - | ||||||
613 | // it's us | - | ||||||
614 | we = obj; | - | ||||||
615 | } | - | ||||||
616 | - | |||||||
617 | if (we) | - | ||||||
618 | return we; | - | ||||||
619 | // still nothing? | - | ||||||
620 | - | |||||||
621 | if (parsed.isEmpty()) { | - | ||||||
622 | // object didn't return introspection | - | ||||||
623 | we = new QDBusMetaObject; | - | ||||||
624 | QDBusMetaObjectGenerator generator(interface, 0); | - | ||||||
625 | generator.write(we); | - | ||||||
626 | we->cached = false; | - | ||||||
627 | return we; | - | ||||||
628 | } else if (interface.isEmpty()) { | - | ||||||
629 | // merge all interfaces | - | ||||||
630 | it = parsed.constBegin(); | - | ||||||
631 | QDBusIntrospection::Interface merged = *it.value().constData(); | - | ||||||
632 | - | |||||||
633 | for (++it; it != end; ++it) { | - | ||||||
634 | merged.annotations.unite(it.value()->annotations); | - | ||||||
635 | merged.methods.unite(it.value()->methods); | - | ||||||
636 | merged.signals_.unite(it.value()->signals_); | - | ||||||
637 | merged.properties.unite(it.value()->properties); | - | ||||||
638 | } | - | ||||||
639 | - | |||||||
640 | merged.name = QLatin1String("local.Merged"); | - | ||||||
641 | merged.introspection.clear(); | - | ||||||
642 | - | |||||||
643 | we = new QDBusMetaObject; | - | ||||||
644 | QDBusMetaObjectGenerator generator(merged.name, &merged); | - | ||||||
645 | generator.write(we); | - | ||||||
646 | we->cached = false; | - | ||||||
647 | return we; | - | ||||||
648 | } | - | ||||||
649 | - | |||||||
650 | // mark as an error | - | ||||||
651 | error = QDBusError(QDBusError::UnknownInterface, | - | ||||||
652 | QString::fromLatin1("Interface '%1' was not found") | - | ||||||
653 | .arg(interface)); | - | ||||||
654 | return 0; | - | ||||||
655 | } | - | ||||||
656 | - | |||||||
657 | QDBusMetaObject::QDBusMetaObject() | - | ||||||
658 | { | - | ||||||
659 | } | - | ||||||
660 | - | |||||||
661 | static inline const QDBusMetaObjectPrivate *priv(const uint* data) | - | ||||||
662 | { | - | ||||||
663 | return reinterpret_cast<const QDBusMetaObjectPrivate *>(data); | - | ||||||
664 | } | - | ||||||
665 | - | |||||||
666 | const int *QDBusMetaObject::inputTypesForMethod(int id) const | - | ||||||
667 | { | - | ||||||
668 | //id -= methodOffset(); | - | ||||||
669 | if (id >= 0 && id < priv(d.data)->methodCount) { | - | ||||||
670 | int handle = priv(d.data)->methodDBusData + id*intsPerMethod; | - | ||||||
671 | return reinterpret_cast<const int*>(d.data + d.data[handle]); | - | ||||||
672 | } | - | ||||||
673 | return 0; | - | ||||||
674 | } | - | ||||||
675 | - | |||||||
676 | const int *QDBusMetaObject::outputTypesForMethod(int id) const | - | ||||||
677 | { | - | ||||||
678 | //id -= methodOffset(); | - | ||||||
679 | if (id >= 0 && id < priv(d.data)->methodCount) { | - | ||||||
680 | int handle = priv(d.data)->methodDBusData + id*intsPerMethod; | - | ||||||
681 | return reinterpret_cast<const int*>(d.data + d.data[handle + 1]); | - | ||||||
682 | } | - | ||||||
683 | return 0; | - | ||||||
684 | } | - | ||||||
685 | - | |||||||
686 | int QDBusMetaObject::propertyMetaType(int id) const | - | ||||||
687 | { | - | ||||||
688 | //id -= propertyOffset(); | - | ||||||
689 | if (id >= 0 && id < priv(d.data)->propertyCount) { | - | ||||||
690 | int handle = priv(d.data)->propertyDBusData + id*intsPerProperty; | - | ||||||
691 | return d.data[handle + 1]; | - | ||||||
692 | } | - | ||||||
693 | return 0; | - | ||||||
694 | } | - | ||||||
695 | - | |||||||
696 | QT_END_NAMESPACE | - | ||||||
697 | - | |||||||
698 | #endif // QT_NO_DBUS | - | ||||||
Source code | Switch to Preprocessed file |