QDBusMetaTypeId: don't cache the result of qMetaTypeId<>() in static ints
[profile/ivi/qtbase.git] / src / dbus / qdbusmetatype.cpp
index 0359b4d..d8ee0b3 100644 (file)
@@ -40,6 +40,7 @@
 ****************************************************************************/
 
 #include "qdbusmetatype.h"
+#include "qdbusmetatype_p.h"
 
 #include <string.h>
 #include "qdbus_symbols_p.h"
@@ -49,7 +50,6 @@
 #include <qreadwritelock.h>
 #include <qvector.h>
 
-#include "qdbusmetatype_p.h"
 #include "qdbusargument_p.h"
 #include "qdbusutil_p.h"
 #include "qdbusunixfiledescriptor.h"
 # define DBUS_TYPE_UNIX_FD_AS_STRING "h"
 #endif
 
-Q_DECLARE_METATYPE(QList<bool>)
-Q_DECLARE_METATYPE(QList<short>)
-Q_DECLARE_METATYPE(QList<ushort>)
-Q_DECLARE_METATYPE(QList<int>)
-Q_DECLARE_METATYPE(QList<uint>)
-Q_DECLARE_METATYPE(QList<qlonglong>)
-Q_DECLARE_METATYPE(QList<qulonglong>)
-Q_DECLARE_METATYPE(QList<double>)
-
 QT_BEGIN_NAMESPACE
 
 class QDBusCustomTypeInfo
@@ -98,14 +89,6 @@ inline static void registerHelper(T * = 0)
         reinterpret_cast<QDBusMetaType::DemarshallFunction>(df));
 }
 
-int QDBusMetaTypeId::message;
-int QDBusMetaTypeId::argument;
-int QDBusMetaTypeId::variant;
-int QDBusMetaTypeId::objectpath;
-int QDBusMetaTypeId::signature;
-int QDBusMetaTypeId::error;
-int QDBusMetaTypeId::unixfd;
-
 void QDBusMetaTypeId::init()
 {
     static volatile bool initialized = false;
@@ -113,16 +96,14 @@ void QDBusMetaTypeId::init()
     // reentrancy is not a problem since everything else is locked on their own
     // set the guard variable at the end
     if (!initialized) {
-#ifndef QT_BOOTSTRAPPED
-        // register our types with QtCore
-        message = qRegisterMetaType<QDBusMessage>("QDBusMessage");
-        error = qRegisterMetaType<QDBusError>("QDBusError");
-#endif
-        argument = qRegisterMetaType<QDBusArgument>("QDBusArgument");
-        variant = qRegisterMetaType<QDBusVariant>("QDBusVariant");
-        objectpath = qRegisterMetaType<QDBusObjectPath>("QDBusObjectPath");
-        signature = qRegisterMetaType<QDBusSignature>("QDBusSignature");
-        unixfd = qRegisterMetaType<QDBusUnixFileDescriptor>("QDBusUnixFileDescriptor");
+        // register our types with QtCore (calling qMetaTypeId<T>() does this implicitly)
+        (void)message();
+        (void)argument();
+        (void)variant();
+        (void)objectpath();
+        (void)signature();
+        (void)error();
+        (void)unixfd();
 
 #ifndef QDBUS_NO_SPECIALTYPES
         // and register QtCore's with us
@@ -154,11 +135,6 @@ void QDBusMetaTypeId::init()
         qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >();
 #endif
 
-#if QT_BOOTSTRAPPED
-        const int lastId = qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >();
-        message = lastId + 1;
-        error = lastId + 2;
-#endif
         initialized = true;
     }
 }
@@ -168,6 +144,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
 
 /*!
     \class QDBusMetaType
+    \inmodule QtDBus
     \brief Meta-type registration system for the QtDBus module.
     \internal
 
@@ -200,7 +177,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
     Q_DECLARE_METATYPE() macro, and then registered as in the
     following example:
 
-    \snippet doc/src/snippets/code/src_qdbus_qdbusmetatype.cpp 0
+    \snippet code/src_qdbus_qdbusmetatype.cpp 0
 
     If \c{T} isn't a type derived from one of
     Qt's \l{container classes}, the \c{operator<<} and
@@ -361,16 +338,16 @@ int QDBusMetaType::signatureToType(const char *signature)
         return QVariant::String;
 
     case DBUS_TYPE_OBJECT_PATH:
-        return QDBusMetaTypeId::objectpath;
+        return QDBusMetaTypeId::objectpath();
 
     case DBUS_TYPE_SIGNATURE:
-        return QDBusMetaTypeId::signature;
+        return QDBusMetaTypeId::signature();
 
     case DBUS_TYPE_UNIX_FD:
-        return QDBusMetaTypeId::unixfd;
+        return QDBusMetaTypeId::unixfd();
 
     case DBUS_TYPE_VARIANT:
-        return QDBusMetaTypeId::variant;
+        return QDBusMetaTypeId::variant();
 
     case DBUS_TYPE_ARRAY:       // special case
         switch (signature[1]) {
@@ -452,13 +429,13 @@ const char *QDBusMetaType::typeToSignature(int type)
     }
 
     QDBusMetaTypeId::init();
-    if (type == QDBusMetaTypeId::variant)
+    if (type == QDBusMetaTypeId::variant())
         return DBUS_TYPE_VARIANT_AS_STRING;
-    else if (type == QDBusMetaTypeId::objectpath)
+    else if (type == QDBusMetaTypeId::objectpath())
         return DBUS_TYPE_OBJECT_PATH_AS_STRING;
-    else if (type == QDBusMetaTypeId::signature)
+    else if (type == QDBusMetaTypeId::signature())
         return DBUS_TYPE_SIGNATURE_AS_STRING;
-    else if (type == QDBusMetaTypeId::unixfd)
+    else if (type == QDBusMetaTypeId::unixfd())
         return DBUS_TYPE_UNIX_FD_AS_STRING;
 
     // try the database