diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-02-18 22:14:36 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-29 12:50:14 +0100 |
commit | 019a5f2dd50404abfb06f26d31aa6292eb6344fc (patch) | |
tree | 9798b09da79f0807c0160b638e12a6b2a782295e /src/dbus/qdbusmetaobject.cpp | |
parent | 87438fd705b2b81006a18f1c35ebd112da1b3054 (diff) |
Port QDBusMetaObject to new meta-object string format
Bring QDBusMetaObject up-to-date with latest moc changes
(generating the string table as an array of QByteArrayData).
QDBusMetaObject now uses the same string table generator as
QMetaObjectBuilder.
The Q_CORE_EXPORT for rawStringData() will be removed once QtDBus
has been ported to the new meta-method data format (the method name
will be stored directly in the standard method descriptor, no need
for QtDBus to store it as a separate string).
Change-Id: I41165f48501b9b11c0288208cdc770926677a8aa
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/dbus/qdbusmetaobject.cpp')
-rw-r--r-- | src/dbus/qdbusmetaobject.cpp | 49 |
1 files changed, 7 insertions, 42 deletions
diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp index bd7b83bf65..eb2d3dffa8 100644 --- a/src/dbus/qdbusmetaobject.cpp +++ b/src/dbus/qdbusmetaobject.cpp @@ -54,6 +54,7 @@ #include "qdbusabstractinterface_p.h" #include <private/qmetaobject_p.h> +#include <private/qmetaobjectbuilder_p.h> #ifndef QT_NO_DBUS @@ -355,36 +356,6 @@ void QDBusMetaObjectGenerator::parseProperties() void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) { - class MetaStringTable - { - public: - typedef QHash<QByteArray, int> Entries; // string --> offset mapping - typedef Entries::const_iterator const_iterator; - Entries::const_iterator constBegin() const - { return m_entries.constBegin(); } - Entries::const_iterator constEnd() const - { return m_entries.constEnd(); } - - MetaStringTable() : m_offset(0) {} - - int enter(const QByteArray &value) - { - Entries::iterator it = m_entries.find(value); - if (it != m_entries.end()) - return it.value(); - int pos = m_offset; - m_entries.insert(value, pos); - m_offset += value.size() + 1; - return pos; - } - - int arraySize() const { return m_offset; } - - private: - Entries m_entries; - int m_offset; - }; - // this code here is mostly copied from qaxbase.cpp // with a few modifications to make it cleaner @@ -397,7 +368,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int)); QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(idata.data()); - Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 6, "QtDBus meta-object generator should generate the same version as moc"); + Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 7, "QtDBus meta-object generator should generate the same version as moc"); header->revision = QMetaObjectPrivate::OutputRevision; header->className = 0; header->classInfoCount = 0; @@ -425,7 +396,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count(); idata.resize(data_size + 1); - MetaStringTable strings; + QMetaStringTable strings; strings.enter(className.toLatin1()); int offset = header->methodData; @@ -484,14 +455,8 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) Q_ASSERT(offset == header->propertyDBusData); Q_ASSERT(signatureOffset == header->methodDBusData); - char *string_data = new char[strings.arraySize()]; - { - MetaStringTable::const_iterator it; - for (it = strings.constBegin(); it != strings.constEnd(); ++it) { - memcpy(string_data + it.value(), it.key().constData(), it.key().size()); - string_data[it.value() + it.key().size()] = '\0'; - } - } + char *string_data = new char[strings.blobSize()]; + strings.writeBlob(string_data); uint *uint_data = new uint[idata.size()]; memcpy(uint_data, idata.data(), idata.size() * sizeof(int)); @@ -499,7 +464,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) // put the metaobject together obj->d.data = uint_data; obj->d.extradata = 0; - obj->d.stringdata = string_data; + obj->d.stringdata = reinterpret_cast<const QByteArrayData *>(string_data); obj->d.superdata = &QDBusAbstractInterface::staticMetaObject; } @@ -618,7 +583,7 @@ const char *QDBusMetaObject::dbusNameForMethod(int id) const //id -= methodOffset(); if (id >= 0 && id < priv(d.data)->methodCount) { int handle = priv(d.data)->methodDBusData + id*intsPerMethod; - return d.stringdata + d.data[handle]; + return QMetaObjectPrivate::rawStringData(this, d.data[handle]); } return 0; } |