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
60QT_BEGIN_NAMESPACE
61
62class QDBusMetaObjectGenerator
63{
64public:
65 QDBusMetaObjectGenerator(const QString &interface,
66 const QDBusIntrospection::Interface *parsedData);
67 void write(QDBusMetaObject *obj);
68 void writeWithoutXml(QDBusMetaObject *obj);
69
70private:
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
110static const int intsPerProperty = 2;
111static const int intsPerMethod = 2;
112
113struct QDBusMetaObjectPrivate : public QMetaObjectPrivate
114{
115 int propertyDBusData;
116 int methodDBusData;
117};
118
119QDBusMetaObjectGenerator::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
130static int registerComplexDBusType(const QByteArray &typeName)
131{
132 struct QDBusRawTypeHandler : QtPrivate::QMetaTypeInterface
133 {
134 const QByteArray name;
135 QDBusRawTypeHandler(const QByteArray &name)
136 : QtPrivate::QMetaTypeInterface {
137 0, sizeof(void *), sizeof(void *), QMetaType::RelocatableType, 0, nullptr,
138 name.constData(),
139 nullptr, nullptr, nullptr, nullptr,
140 nullptr, nullptr, nullptr,
141 nullptr, nullptr, nullptr
142 },
143 name(name)
144 {}
145 };
146
147 static QBasicMutex mutex;
148 static struct Hash : QHash<QByteArray, QMetaType>
149 {
150 ~Hash()
151 {
152 for (QMetaType entry : *this)
153 QMetaType::unregisterMetaType(std::move(entry));
154 }
155 } hash;
156 QMutexLocker lock(&mutex);
157 QMetaType &metatype = hash[typeName];
158 if (!metatype.isValid())
159 metatype = QMetaType(new QDBusRawTypeHandler(typeName));
160 return metatype.id();
161}
162
163Q_DBUS_EXPORT bool qt_dbus_metaobject_skip_annotations = false;
164
165QDBusMetaObjectGenerator::Type
166QDBusMetaObjectGenerator::findType(const QByteArray &signature,
167 const QDBusIntrospection::Annotations &annotations,
168 const char *direction, int id)
169{
170 Type result;
171 result.id = QMetaType::UnknownType;
172
173 int type = QDBusMetaType::signatureToMetaType(signature).id();
174 if (type == QMetaType::UnknownType && !qt_dbus_metaobject_skip_annotations) {
175 // it's not a type normally handled by our meta type system
176 // it must contain an annotation
177 QString annotationName = QString::fromLatin1("org.qtproject.QtDBus.QtTypeName");
178 if (id >= 0)
179 annotationName += QString::fromLatin1(".%1%2")
180 .arg(QLatin1String(direction))
181 .arg(id);
182
183 // extract from annotations:
184 QByteArray typeName = annotations.value(annotationName).toLatin1();
185
186 // verify that it's a valid one
187 if (typeName.isEmpty()) {
188 // try the old annotation from Qt 4
189 annotationName = QString::fromLatin1("com.trolltech.QtDBus.QtTypeName");
190 if (id >= 0)
191 annotationName += QString::fromLatin1(".%1%2")
192 .arg(QLatin1String(direction))
193 .arg(id);
194 typeName = annotations.value(annotationName).toLatin1();
195 }
196
197 if (!typeName.isEmpty()) {
198 // type name found
199 type = QMetaType::fromName(typeName).id();
200 }
201
202 if (type == QMetaType::UnknownType || signature != QDBusMetaType::typeToSignature(QMetaType(type))) {
203 // type is still unknown or doesn't match back to the signature that it
204 // was expected to, so synthesize a fake type
205 typeName = "QDBusRawType<0x" + signature.toHex() + ">*";
206 type = registerComplexDBusType(typeName);
207 }
208
209 result.name = typeName;
210 } else if (type == QMetaType::UnknownType) {
211 // this case is used only by the qdbus command-line tool
212 // invalid, let's create an impossible type that contains the signature
213
214 if (signature == "av") {
215 result.name = "QVariantList";
216 type = QMetaType::QVariantList;
217 } else if (signature == "a{sv}") {
218 result.name = "QVariantMap";
219 type = QMetaType::QVariantMap;
220 } else if (signature == "a{ss}") {
221 result.name = "QMap<QString,QString>";
222 type = qMetaTypeId<QMap<QString, QString> >();
223 } else {
224 result.name = "{D-Bus type \"" + signature + "\"}";
225 type = registerComplexDBusType(result.name);
226 }
227 } else {
228 result.name = QMetaType(type).name();
229 }
230
231 result.id = type;
232 return result; // success
233}
234
235void QDBusMetaObjectGenerator::parseMethods()
236{
237 //
238 // TODO:
239 // Add cloned methods when the remote object has return types
240 //
241
242 QDBusIntrospection::Methods::ConstIterator method_it = data->methods.constBegin();
243 QDBusIntrospection::Methods::ConstIterator method_end = data->methods.constEnd();
244 for ( ; method_it != method_end; ++method_it) {
245 const QDBusIntrospection::Method &m = *method_it;
246 Method mm;
247
248 mm.name = m.name.toLatin1();
249 QByteArray prototype = mm.name;
250 prototype += '(';
251
252 bool ok = true;
253
254 // build the input argument list
255 for (int i = 0; i < m.inputArgs.count(); ++i) {
256 const QDBusIntrospection::Argument &arg = m.inputArgs.at(i);
257
258 Type type = findType(arg.type.toLatin1(), m.annotations, "In", i);
259 if (type.id == QMetaType::UnknownType) {
260 ok = false;
261 break;
262 }
263
264 mm.inputTypes.append(type.id);
265
266 mm.parameterNames.append(arg.name.toLatin1());
267
268 prototype.append(type.name);
269 prototype.append(',');
270 }
271 if (!ok) continue;
272
273 // build the output argument list:
274 for (int i = 0; i < m.outputArgs.count(); ++i) {
275 const QDBusIntrospection::Argument &arg = m.outputArgs.at(i);
276
277 Type type = findType(arg.type.toLatin1(), m.annotations, "Out", i);
278 if (type.id == QMetaType::UnknownType) {
279 ok = false;
280 break;
281 }
282
283 mm.outputTypes.append(type.id);
284
285 if (i == 0 && type.id == -1) {
286 mm.rawReturnType = type.name;
287 }
288 if (i != 0) {
289 // non-const ref parameter
290 mm.parameterNames.append(arg.name.toLatin1());
291
292 prototype.append(type.name);
293 prototype.append("&,");
294 }
295 }
296 if (!ok) continue;
297
298 // convert the last commas:
299 if (!mm.parameterNames.isEmpty())
300 prototype[prototype.length() - 1] = ')';
301 else
302 prototype.append(')');
303
304 // check the async tag
305 if (m.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true"))
306 mm.tag = "Q_NOREPLY";
307
308 // meta method flags
309 mm.flags = AccessPublic | MethodSlot | MethodScriptable;
310
311 // add
312 methods.insert(QMetaObject::normalizedSignature(prototype), mm);
313 }
314}
315
316void QDBusMetaObjectGenerator::parseSignals()
317{
318 QDBusIntrospection::Signals::ConstIterator signal_it = data->signals_.constBegin();
319 QDBusIntrospection::Signals::ConstIterator signal_end = data->signals_.constEnd();
320 for ( ; signal_it != signal_end; ++signal_it) {
321 const QDBusIntrospection::Signal &s = *signal_it;
322 Method mm;
323
324 mm.name = s.name.toLatin1();
325 QByteArray prototype = mm.name;
326 prototype += '(';
327
328 bool ok = true;
329
330 // build the output argument list
331 for (int i = 0; i < s.outputArgs.count(); ++i) {
332 const QDBusIntrospection::Argument &arg = s.outputArgs.at(i);
333
334 Type type = findType(arg.type.toLatin1(), s.annotations, "Out", i);
335 if (type.id == QMetaType::UnknownType) {
336 ok = false;
337 break;
338 }
339
340 mm.inputTypes.append(type.id);
341
342 mm.parameterNames.append(arg.name.toLatin1());
343
344 prototype.append(type.name);
345 prototype.append(',');
346 }
347 if (!ok) continue;
348
349 // convert the last commas:
350 if (!mm.parameterNames.isEmpty())
351 prototype[prototype.length() - 1] = ')';
352 else
353 prototype.append(')');
354
355 // meta method flags
356 mm.flags = AccessPublic | MethodSignal | MethodScriptable;
357
358 // add
359 signals_.insert(QMetaObject::normalizedSignature(prototype), mm);
360 }
361}
362
363void QDBusMetaObjectGenerator::parseProperties()
364{
365 QDBusIntrospection::Properties::ConstIterator prop_it = data->properties.constBegin();
366 QDBusIntrospection::Properties::ConstIterator prop_end = data->properties.constEnd();
367 for ( ; prop_it != prop_end; ++prop_it) {
368 const QDBusIntrospection::Property &p = *prop_it;
369 Property mp;
370 Type type = findType(p.type.toLatin1(), p.annotations);
371 if (type.id == QMetaType::UnknownType)
372 continue;
373
374 QByteArray name = p.name.toLatin1();
375 mp.signature = p.type.toLatin1();
376 mp.type = type.id;
377 mp.typeName = type.name;
378
379 // build the flags:
380 mp.flags = StdCppSet | Scriptable | Stored | Designable;
381 if (p.access != QDBusIntrospection::Property::Write)
382 mp.flags |= Readable;
383 if (p.access != QDBusIntrospection::Property::Read)
384 mp.flags |= Writable;
385
386 // add the property:
387 properties.insert(name, mp);
388 }
389}
390
391// Returns the sum of all parameters (including return type) for the given
392// \a map of methods. This is needed for calculating the size of the methods'
393// parameter type/name meta-data.
394int QDBusMetaObjectGenerator::aggregateParameterCount(const QMap<QByteArray, Method> &map)
395{
396 int sum = 0;
397 QMap<QByteArray, Method>::const_iterator it;
398 for (it = map.constBegin(); it != map.constEnd(); ++it) {
399 const Method &m = it.value();
400 sum += m.inputTypes.size() + qMax(qsizetype(1), m.outputTypes.size());
401 }
402 return sum;
403}
404
405void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
406{
407 // this code here is mostly copied from qaxbase.cpp
408 // with a few modifications to make it cleaner
409
410 QString className = interface;
411 className.replace(QLatin1Char('.'), QLatin1String("::"));
412 if (className.isEmpty())
413 className = QLatin1String("QDBusInterface");
414
415 QVarLengthArray<int> idata;
416 idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int));
417
418 int methodParametersDataSize =
419 ((aggregateParameterCount(signals_)
420 + aggregateParameterCount(methods)) * 2) // types and parameter names
421 - signals_.count() // return "parameters" don't have names
422 - methods.count(); // ditto
423
424 QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(idata.data());
425 static_assert(QMetaObjectPrivate::OutputRevision == 10, "QtDBus meta-object generator should generate the same version as moc");
426 header->revision = QMetaObjectPrivate::OutputRevision;
427 header->className = 0;
428 header->classInfoCount = 0;
429 header->classInfoData = 0;
430 header->methodCount = signals_.count() + methods.count();
431 header->methodData = idata.size();
432 header->propertyCount = properties.count();
433 header->propertyData = header->methodData + header->methodCount * QMetaObjectPrivate::IntsPerMethod + methodParametersDataSize;
434 header->enumeratorCount = 0;
435 header->enumeratorData = 0;
436 header->constructorCount = 0;
437 header->constructorData = 0;
438 header->flags = RequiresVariantMetaObject;
439 header->signalCount = signals_.count();
440 // These are specific to QDBusMetaObject:
441 header->propertyDBusData = header->propertyData + header->propertyCount * QMetaObjectPrivate::IntsPerProperty;
442 header->methodDBusData = header->propertyDBusData + header->propertyCount * intsPerProperty;
443
444 int data_size = idata.size() +
445 (header->methodCount * (QMetaObjectPrivate::IntsPerMethod+intsPerMethod)) + methodParametersDataSize +
446 (header->propertyCount * (QMetaObjectPrivate::IntsPerProperty+intsPerProperty));
447 for (const Method &mm : qAsConst(signals_))
448 data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count();
449 for (const Method &mm : qAsConst(methods))
450 data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count();
451 idata.resize(data_size + 1);
452
453 QMetaStringTable strings(className.toLatin1());
454
455 int offset = header->methodData;
456 int parametersOffset = offset + header->methodCount * QMetaObjectPrivate::IntsPerMethod;
457 int signatureOffset = header->methodDBusData;
458 int typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod;
459 idata[typeidOffset++] = 0; // eod
460
461 int totalMetaTypeCount = properties.count();
462 ++totalMetaTypeCount; // + 1 for metatype of dynamic metaobject
463 for (const auto& methodContainer: {signals_, methods}) {
464 for (const auto& method: methodContainer) {
465 int argc = method.inputTypes.size() + qMax(qsizetype(0), method.outputTypes.size() - 1);
466 totalMetaTypeCount += argc + 1;
467 }
468 }
469 QMetaType *metaTypes = new QMetaType[totalMetaTypeCount];
470 int propertyId = 0;
471
472 // add each method:
473 int currentMethodMetaTypeOffset = properties.count() + 1;
474 for (int x = 0; x < 2; ++x) {
475 // Signals must be added before other methods, to match moc.
476 QMap<QByteArray, Method> &map = (x == 0) ? signals_ : methods;
477 for (QMap<QByteArray, Method>::ConstIterator it = map.constBegin();
478 it != map.constEnd(); ++it) {
479 const Method &mm = it.value();
480
481 int argc = mm.inputTypes.size() + qMax(qsizetype(0), mm.outputTypes.size() - 1);
482
483 idata[offset++] = strings.enter(mm.name);
484 idata[offset++] = argc;
485 idata[offset++] = parametersOffset;
486 idata[offset++] = strings.enter(mm.tag);
487 idata[offset++] = mm.flags;
488 idata[offset++] = currentMethodMetaTypeOffset;
489
490 // Parameter types
491 for (int i = -1; i < argc; ++i) {
492 int type;
493 QByteArray typeName;
494 if (i < 0) { // Return type
495 if (!mm.outputTypes.isEmpty()) {
496 type = mm.outputTypes.first();
497 if (type == -1) {
498 type = IsUnresolvedType | strings.enter(mm.rawReturnType);
499 }
500 } else {
501 type = QMetaType::Void;
502 }
503 } else if (i < mm.inputTypes.size()) {
504 type = mm.inputTypes.at(i);
505 } else {
506 Q_ASSERT(mm.outputTypes.size() > 1);
507 type = mm.outputTypes.at(i - mm.inputTypes.size() + 1);
508 // Output parameters are references; type id not available
509 typeName = QMetaType(type).name();
510 typeName.append('&');
511 }
512 Q_ASSERT(type != QMetaType::UnknownType);
513 int typeInfo;
514 if (!typeName.isEmpty())
515 typeInfo = IsUnresolvedType | strings.enter(typeName);
516 else
517 typeInfo = type;
518 metaTypes[currentMethodMetaTypeOffset++] = QMetaType (type);
519 idata[parametersOffset++] = typeInfo;
520 }
521 // Parameter names
522 for (int i = 0; i < argc; ++i)
523 idata[parametersOffset++] = strings.enter(mm.parameterNames.at(i));
524
525 idata[signatureOffset++] = typeidOffset;
526 idata[typeidOffset++] = mm.inputTypes.count();
527 memcpy(idata.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.count() * sizeof(int));
528 typeidOffset += mm.inputTypes.count();
529
530 idata[signatureOffset++] = typeidOffset;
531 idata[typeidOffset++] = mm.outputTypes.count();
532 memcpy(idata.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.count() * sizeof(int));
533 typeidOffset += mm.outputTypes.count();
534 }
535 }
536
537 Q_ASSERT(offset == header->methodData + header->methodCount * QMetaObjectPrivate::IntsPerMethod);
538 Q_ASSERT(parametersOffset == header->propertyData);
539 Q_ASSERT(signatureOffset == header->methodDBusData + header->methodCount * intsPerMethod);
540 Q_ASSERT(typeidOffset == idata.size());
541 offset += methodParametersDataSize;
542 Q_ASSERT(offset == header->propertyData);
543
544 // add each property
545 signatureOffset = header->propertyDBusData;
546 for (QMap<QByteArray, Property>::ConstIterator it = properties.constBegin();
547 it != properties.constEnd(); ++it) {
548 const Property &mp = it.value();
549
550 // form is name, typeinfo, flags
551 idata[offset++] = strings.enter(it.key()); // name
552 Q_ASSERT(mp.type != QMetaType::UnknownType);
553 idata[offset++] = mp.type;
554 idata[offset++] = mp.flags;
555 idata[offset++] = -1; // notify index
556 idata[offset++] = 0; // revision
557
558 idata[signatureOffset++] = strings.enter(mp.signature);
559 idata[signatureOffset++] = mp.type;
560
561 metaTypes[propertyId++] = QMetaType(mp.type);
562 }
563 metaTypes[propertyId] = QMetaType(); // we can't know our own metatype
564
565 Q_ASSERT(offset == header->propertyDBusData);
566 Q_ASSERT(signatureOffset == header->methodDBusData);
567
568 char *string_data = new char[strings.blobSize()];
569 strings.writeBlob(string_data);
570
571 uint *uint_data = new uint[idata.size()];
572 memcpy(uint_data, idata.data(), idata.size() * sizeof(int));
573
574 // put the metaobject together
575 obj->d.data = uint_data;
576 obj->d.relatedMetaObjects = nullptr;
577 obj->d.static_metacall = nullptr;
578 obj->d.extradata = nullptr;
579 obj->d.stringdata = reinterpret_cast<const uint *>(string_data);
580 obj->d.superdata = &QDBusAbstractInterface::staticMetaObject;
581 obj->d.metaTypes = reinterpret_cast<QtPrivate::QMetaTypeInterface *const *>(metaTypes);
582}
583
584#if 0
585void QDBusMetaObjectGenerator::writeWithoutXml(const QString &interface)
586{
587 // no XML definition
588 QString tmp(interface);
589 tmp.replace(QLatin1Char('.'), QLatin1String("::"));
590 QByteArray name(tmp.toLatin1());
591
592 QDBusMetaObjectPrivate *header = new QDBusMetaObjectPrivate;
593 memset(header, 0, sizeof *header);
594 header->revision = 1;
595 // leave the rest with 0
596
597 char *stringdata = new char[name.length() + 1];
598 stringdata[name.length()] = '\0';
599
600 d.data = reinterpret_cast<uint*>(header);
601 d.relatedMetaObjects = 0;
602 d.static_metacall = 0;
603 d.extradata = 0;
604 d.stringdata = stringdata;
605 d.superdata = &QDBusAbstractInterface::staticMetaObject;
606 cached = false;
607}
608#endif
609
610/////////
611// class QDBusMetaObject
612
613QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, const QString &xml,
614 QHash<QString, QDBusMetaObject *> &cache,
615 QDBusError &error)
616{
617 error = QDBusError();
618 QDBusIntrospection::Interfaces parsed = QDBusIntrospection::parseInterfaces(xml);
619
620 QDBusMetaObject *we = nullptr;
621 QDBusIntrospection::Interfaces::ConstIterator it = parsed.constBegin();
622 QDBusIntrospection::Interfaces::ConstIterator end = parsed.constEnd();
623 for ( ; it != end; ++it) {
624 // check if it's in the cache
625 bool us = it.key() == interface;
626
627 QDBusMetaObject *obj = cache.value(it.key(), 0);
628 if ( !obj && ( us || !interface.startsWith( QLatin1String("local.") ) ) ) {
629 // not in cache; create
630 obj = new QDBusMetaObject;
631 QDBusMetaObjectGenerator generator(it.key(), it.value().constData());
632 generator.write(obj);
633
634 if ( (obj->cached = !it.key().startsWith( QLatin1String("local.") )) )
635 // cache it
636 cache.insert(it.key(), obj);
637 else if (!us)
638 delete obj;
639
640 }
641
642 if (us)
643 // it's us
644 we = obj;
645 }
646
647 if (we)
648 return we;
649 // still nothing?
650
651 if (parsed.isEmpty()) {
652 // object didn't return introspection
653 we = new QDBusMetaObject;
654 QDBusMetaObjectGenerator generator(interface, nullptr);
655 generator.write(we);
656 we->cached = false;
657 return we;
658 } else if (interface.isEmpty()) {
659 // merge all interfaces
660 it = parsed.constBegin();
661 QDBusIntrospection::Interface merged = *it.value().constData();
662
663 for (++it; it != end; ++it) {
664 merged.annotations.insert(it.value()->annotations);
665 merged.methods.unite(it.value()->methods);
666 merged.signals_.unite(it.value()->signals_);
667 merged.properties.insert(it.value()->properties);
668 }
669
670 merged.name = QLatin1String("local.Merged");
671 merged.introspection.clear();
672
673 we = new QDBusMetaObject;
674 QDBusMetaObjectGenerator generator(merged.name, &merged);
675 generator.write(we);
676 we->cached = false;
677 return we;
678 }
679
680 // mark as an error
681 error = QDBusError(QDBusError::UnknownInterface,
682 QLatin1String("Interface '%1' was not found")
683 .arg(interface));
684 return nullptr;
685}
686
687QDBusMetaObject::QDBusMetaObject()
688{
689}
690
691static inline const QDBusMetaObjectPrivate *priv(const uint* data)
692{
693 return reinterpret_cast<const QDBusMetaObjectPrivate *>(data);
694}
695
696const int *QDBusMetaObject::inputTypesForMethod(int id) const
697{
698 //id -= methodOffset();
699 if (id >= 0 && id < priv(d.data)->methodCount) {
700 int handle = priv(d.data)->methodDBusData + id*intsPerMethod;
701 return reinterpret_cast<const int*>(d.data + d.data[handle]);
702 }
703 return nullptr;
704}
705
706const int *QDBusMetaObject::outputTypesForMethod(int id) const
707{
708 //id -= methodOffset();
709 if (id >= 0 && id < priv(d.data)->methodCount) {
710 int handle = priv(d.data)->methodDBusData + id*intsPerMethod;
711 return reinterpret_cast<const int*>(d.data + d.data[handle + 1]);
712 }
713 return nullptr;
714}
715
716int QDBusMetaObject::propertyMetaType(int id) const
717{
718 //id -= propertyOffset();
719 if (id >= 0 && id < priv(d.data)->propertyCount) {
720 int handle = priv(d.data)->propertyDBusData + id*intsPerProperty;
721 return d.data[handle + 1];
722 }
723 return 0;
724}
725
726QT_END_NAMESPACE
727
728#endif // QT_NO_DBUS
729