summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2019-12-02 09:52:41 +0100
committerOlivier Goffart <ogoffart@woboq.com>2020-02-20 16:11:02 +0100
commit33cd680ddbaccf6139e215d851a39e657ae36394 (patch)
tree85f0fe036e840221ee3e3a91c2e9423bd61f8d43 /src/dbus
parent14f1ec186f87ce50037044ccb079463676518ec5 (diff)
New QMetaType representation
the QMetaType is represented as a pointer to a "vtable" in the form of a QtPrivate::QMetaTypeInterface* The recomanded use of QMetaType is to construct an object with QMetaType::fromType. This does not require any registration. There is still an id() function which will do some registration for compatibility with Qt5. Also the patch does not really touch the other extra things that can be registered (data stream operator, comparison operator, iteratable, ...) and this still uses the previous system. This is only the change in QMetaType, other changes to use it in QVariant and QMetaObject will follow Change-Id: Iffad20085cf33f33447f58a68236013a8b60fdbf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusmetaobject.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp
index dabd417a32..bfda2aa9b6 100644
--- a/src/dbus/qdbusmetaobject.cpp
+++ b/src/dbus/qdbusmetaobject.cpp
@@ -127,27 +127,31 @@ QDBusMetaObjectGenerator::QDBusMetaObjectGenerator(const QString &interfaceName,
}
}
-static int registerComplexDBusType(const char *typeName)
+static int registerComplexDBusType(const QByteArray &typeName)
{
- struct QDBusRawTypeHandler {
- static void destruct(void *)
- {
- qFatal("Cannot destruct placeholder type QDBusRawType");
- }
-
- static void *construct(void *, const void *)
- {
- qFatal("Cannot construct placeholder type QDBusRawType");
- return nullptr;
- }
+ struct QDBusRawTypeHandler : QtPrivate::QMetaTypeInterface
+ {
+ const QByteArray name;
+ QDBusRawTypeHandler(const QByteArray &name)
+ : QtPrivate::QMetaTypeInterface {
+ 0, sizeof(void *), sizeof(void *), QMetaType::MovableType, nullptr,
+ name.constData(), 0, QtPrivate::RefCount{0},
+ [](QtPrivate::QMetaTypeInterface *self) {
+ delete static_cast<QDBusRawTypeHandler *>(self);
+ },
+ nullptr, nullptr, nullptr, nullptr, nullptr
+ },
+ name(name)
+ {}
};
- return QMetaType::registerNormalizedType(typeName,
- QDBusRawTypeHandler::destruct,
- QDBusRawTypeHandler::construct,
- sizeof(void *),
- QMetaType::MovableType,
- nullptr);
+ static QBasicMutex mutex;
+ static QHash<QByteArray, QMetaType> hash;
+ QMutexLocker lock(&mutex);
+ QMetaType &metatype = hash[typeName];
+ if (!metatype.isValid())
+ metatype = QMetaType(new QDBusRawTypeHandler(typeName));
+ return metatype.id();
}
Q_DBUS_EXPORT bool qt_dbus_metaobject_skip_annotations = false;