From 850d850c5af8ff77a4b9d53457ec6b1ba6c20cb3 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 9 Sep 2020 13:42:35 +0200 Subject: [PATCH] Use QMetaType instead of integer based type ids Change the implementation of Qt DBus to use QMetaType directly instead of integer based type ids. Change-Id: I999023b58fa50dcc3504386467faf09874f7d2cf Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/dbus/qdbusabstractadaptor.cpp | 2 +- src/dbus/qdbusabstractinterface.cpp | 14 +++--- src/dbus/qdbusargument.cpp | 8 ++-- src/dbus/qdbusargument.h | 29 ++++++------ src/dbus/qdbusargument_p.h | 4 +- src/dbus/qdbusconnection_p.h | 13 +++--- src/dbus/qdbusintegrator.cpp | 38 +++++++-------- src/dbus/qdbusintegrator_p.h | 6 +-- src/dbus/qdbusinterface.cpp | 12 ++--- src/dbus/qdbusinternalfilters.cpp | 16 +++---- src/dbus/qdbusmarshaller.cpp | 46 +++++++++---------- src/dbus/qdbusmessage.cpp | 6 +-- src/dbus/qdbusmessage.h | 3 +- src/dbus/qdbusmetaobject.cpp | 4 +- src/dbus/qdbusmetatype.cpp | 4 +- src/dbus/qdbusmetatype.h | 4 -- src/dbus/qdbusmetatype_p.h | 42 ++++++++--------- src/dbus/qdbusmisc.cpp | 16 +++---- src/dbus/qdbuspendingcall.cpp | 8 ++-- src/dbus/qdbuspendingcall_p.h | 4 +- src/dbus/qdbuspendingreply.cpp | 2 +- src/dbus/qdbuspendingreply.h | 4 +- src/dbus/qdbusreply.cpp | 10 ++-- src/dbus/qdbusutil.cpp | 12 ++--- src/dbus/qdbusxmlgenerator.cpp | 24 +++++----- src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp | 16 +++---- src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 2 +- tests/auto/dbus/qdbusmarshall/common.h | 4 +- .../dbus/qdbusmetatype/tst_qdbusmetatype.cpp | 2 +- tests/auto/tools/qmakelib/tst_qmakelib.cpp | 1 + 30 files changed, 173 insertions(+), 183 deletions(-) diff --git a/src/dbus/qdbusabstractadaptor.cpp b/src/dbus/qdbusabstractadaptor.cpp index 0d59efe145..4f749b0f9d 100644 --- a/src/dbus/qdbusabstractadaptor.cpp +++ b/src/dbus/qdbusabstractadaptor.cpp @@ -305,7 +305,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void ** realObject = realObject->parent(); // break down the parameter list - QList types; + QList types; QString errorMsg; int inputCount = qDBusParametersForMethod(mm, types, errorMsg); if (inputCount == -1) { diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index 4c580ed676..0a873ad5ad 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -154,10 +154,10 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu if (!isValid || !canMakeCalls()) // can't make calls return false; - const int type = mp.userType(); + QMetaType type = mp.metaType(); // is this metatype registered? const char *expectedSignature = ""; - if (int(mp.userType()) != QMetaType::QVariant) { + if (type.id() != QMetaType::QVariant) { expectedSignature = QDBusMetaType::typeToSignature(type); if (expectedSignature == nullptr) { qWarning("QDBusAbstractInterface: type %s must be registered with Qt D-Bus before it can be " @@ -193,10 +193,10 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu const char *foundType = nullptr; QVariant value = qvariant_cast(reply.arguments().at(0)).variant(); - if (value.userType() == type || type == QMetaType::QVariant + if (value.metaType() == type || type.id() == QMetaType::QVariant || (expectedSignature[0] == 'v' && expectedSignature[1] == '\0')) { // simple match - if (type == QMetaType::QVariant) { + if (type.id() == QMetaType::QVariant) { *reinterpret_cast(returnValuePtr) = value; } else { QMetaType(type).destruct(returnValuePtr); @@ -205,7 +205,7 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu return true; } - if (value.userType() == qMetaTypeId()) { + if (value.metaType() == QMetaType::fromType()) { QDBusArgument arg = qvariant_cast(value); foundType = "user type"; @@ -216,7 +216,7 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu } } else { foundType = value.typeName(); - foundSignature = QDBusMetaType::typeToSignature(value.userType()); + foundSignature = QDBusMetaType::typeToSignature(value.metaType()); } // there was an error... @@ -281,7 +281,7 @@ int QDBusAbstractInterfaceBase::qt_metacall(QMetaObject::Call _c, int _id, void if (_c == QMetaObject::WriteProperty) { QVariant value; - if (mp.userType() == qMetaTypeId()) + if (mp.metaType() == QMetaType::fromType()) value = reinterpret_cast(_a[0])->variant(); else value = QVariant(mp.metaType(), _a[0]); diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp index 840a6d9673..10baa5d907 100644 --- a/src/dbus/qdbusargument.cpp +++ b/src/dbus/qdbusargument.cpp @@ -96,7 +96,7 @@ QByteArray QDBusArgumentPrivate::createSignature(int id) "(Did you forget to call beginStructure() ?)", QMetaType(id).name(), signature.constData(), - QMetaType(QDBusMetaType::signatureToType(signature)).name()); + QDBusMetaType::signatureToMetaType(signature).name()); return ""; } return signature; @@ -879,7 +879,7 @@ void QDBusArgument::endStructure() \sa endArray(), beginStructure(), beginMap() */ -void QDBusArgument::beginArray(int id) +void QDBusArgument::beginArray(QMetaType id) { if (QDBusArgumentPrivate::checkWrite(d)) d = d->marshaller()->beginArray(id); @@ -916,10 +916,10 @@ void QDBusArgument::endArray() \sa endMap(), beginStructure(), beginArray(), beginMapEntry() */ -void QDBusArgument::beginMap(int kid, int vid) +void QDBusArgument::beginMap(QMetaType keyMetaType, QMetaType valueMetaType) { if (QDBusArgumentPrivate::checkWrite(d)) - d = d->marshaller()->beginMap(kid, vid); + d = d->marshaller()->beginMap(keyMetaType, valueMetaType); } /*! diff --git a/src/dbus/qdbusargument.h b/src/dbus/qdbusargument.h index 721ac41b3c..cf09543912 100644 --- a/src/dbus/qdbusargument.h +++ b/src/dbus/qdbusargument.h @@ -103,9 +103,13 @@ public: void beginStructure(); void endStructure(); - void beginArray(int elementMetaTypeId); + void beginArray(int elementMetaTypeId) + { beginArray(QMetaType(elementMetaTypeId)); } + void beginArray(QMetaType elementMetaType); void endArray(); - void beginMap(int keyMetaTypeId, int valueMetaTypeId); + void beginMap(int keyMetaTypeId, int valueMetaTypeId) + { beginMap(QMetaType(keyMetaTypeId), QMetaType(valueMetaTypeId)); } + void beginMap(QMetaType keyMetaType, QMetaType valueMetaType); void endMap(); void beginMapEntry(); void endMapEntry(); @@ -165,8 +169,7 @@ template inline T qdbus_cast(const QDBusArgument &arg) template inline T qdbus_cast(const QVariant &v) { - int id = v.userType(); - if (id == qMetaTypeId()) + if (v.metaType() == QMetaType::fromType()) return qdbus_cast(qvariant_cast(v)); else return qvariant_cast(v); @@ -227,8 +230,7 @@ template