QDBusMetaTypeId: don't cache the result of qMetaTypeId<>() in static ints
[profile/ivi/qtbase.git] / src / dbus / qdbusmetatype.cpp
index 7c8d8cf..d8ee0b3 100644 (file)
@@ -40,6 +40,7 @@
 ****************************************************************************/
 
 #include "qdbusmetatype.h"
+#include "qdbusmetatype_p.h"
 
 #include <string.h>
 #include "qdbus_symbols_p.h"
 #include <qreadwritelock.h>
 #include <qvector.h>
 
-#include "qdbusmessage.h"
-#include "qdbusunixfiledescriptor.h"
-#include "qdbusutil_p.h"
-#include "qdbusmetatype_p.h"
 #include "qdbusargument_p.h"
+#include "qdbusutil_p.h"
+#include "qdbusunixfiledescriptor.h"
+#ifndef QT_BOOTSTRAPPED
+#include "qdbusmessage.h"
+#endif
 
 #ifndef QT_NO_DBUS
 
 # 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
 {
 public:
-    QDBusCustomTypeInfo() : signature(0, '\0'), marshall(0), demarshall(0)
+    QDBusCustomTypeInfo() : signature(), marshall(0), demarshall(0)
     { }
 
     // Suggestion:
@@ -96,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;
@@ -111,14 +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) {
-        // register our types with QtCore
-        message = qRegisterMetaType<QDBusMessage>("QDBusMessage");
-        argument = qRegisterMetaType<QDBusArgument>("QDBusArgument");
-        variant = qRegisterMetaType<QDBusVariant>("QDBusVariant");
-        objectpath = qRegisterMetaType<QDBusObjectPath>("QDBusObjectPath");
-        signature = qRegisterMetaType<QDBusSignature>("QDBusSignature");
-        error = qRegisterMetaType<QDBusError>("QDBusError");
-        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
@@ -159,6 +144,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
 
 /*!
     \class QDBusMetaType
+    \inmodule QtDBus
     \brief Meta-type registration system for the QtDBus module.
     \internal
 
@@ -191,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
@@ -290,9 +276,14 @@ bool QDBusMetaType::demarshall(const QDBusArgument &arg, int id, void *data)
         } else
             df = info.demarshall;
     }
-
+#ifndef QT_BOOTSTRAPPED
     QDBusArgument copy = arg;
     df(copy, data);
+#else
+    Q_UNUSED(arg);
+    Q_UNUSED(data);
+    Q_UNUSED(df);
+#endif
     return true;
 }
 
@@ -347,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]) {
@@ -438,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