summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusxmlgenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/qdbusxmlgenerator.cpp')
-rw-r--r--src/dbus/qdbusxmlgenerator.cpp187
1 files changed, 53 insertions, 134 deletions
diff --git a/src/dbus/qdbusxmlgenerator.cpp b/src/dbus/qdbusxmlgenerator.cpp
index 97ce3dc910..412ac18095 100644
--- a/src/dbus/qdbusxmlgenerator.cpp
+++ b/src/dbus/qdbusxmlgenerator.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtCore/qmetaobject.h>
#include <QtCore/qstringlist.h>
@@ -52,6 +16,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
extern Q_DBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
const QMetaObject *base, int flags);
@@ -59,28 +25,28 @@ static inline QString typeNameToXml(const char *typeName)
{
// ### copied from qtextdocument.cpp
// ### move this into Qt Core at some point
- const QLatin1String plain(typeName);
+ const QLatin1StringView plain(typeName);
QString rich;
rich.reserve(int(plain.size() * 1.1));
for (int i = 0; i < plain.size(); ++i) {
- if (plain.at(i) == QLatin1Char('<'))
- rich += QLatin1String("&lt;");
- else if (plain.at(i) == QLatin1Char('>'))
- rich += QLatin1String("&gt;");
- else if (plain.at(i) == QLatin1Char('&'))
- rich += QLatin1String("&amp;");
+ if (plain.at(i) == u'<')
+ rich += "&lt;"_L1;
+ else if (plain.at(i) == u'>')
+ rich += "&gt;"_L1;
+ else if (plain.at(i) == u'&')
+ rich += "&amp;"_L1;
else
rich += plain.at(i);
}
return rich;
}
-static inline QLatin1String accessAsString(bool read, bool write)
+static inline QLatin1StringView accessAsString(bool read, bool write)
{
if (read)
- return write ? QLatin1String("readwrite") : QLatin1String("read") ;
+ return write ? "readwrite"_L1 : "read"_L1 ;
else
- return write ? QLatin1String("write") : QLatin1String("") ;
+ return write ? "write"_L1 : ""_L1 ;
}
// implement the D-Bus org.freedesktop.DBus.Introspectable interface
@@ -101,24 +67,24 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
(!mp.isScriptable() && (flags & QDBusConnection::ExportNonScriptableProperties))))
continue;
- int typeId = mp.userType();
- if (!typeId)
+ QMetaType type = mp.metaType();
+ if (!type.isValid())
continue;
- const char *signature = QDBusMetaType::typeToSignature(typeId);
+ const char *signature = QDBusMetaType::typeToSignature(type);
if (!signature)
continue;
- retval += QLatin1String(" <property name=\"%1\" type=\"%2\" access=\"%3\"")
- .arg(QLatin1String(mp.name()),
- QLatin1String(signature),
+ retval += " <property name=\"%1\" type=\"%2\" access=\"%3\""_L1
+ .arg(QLatin1StringView(mp.name()),
+ QLatin1StringView(signature),
accessAsString(mp.isReadable(), mp.isWritable()));
- if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) {
- const char *typeName = QMetaType::typeName(typeId);
- retval += QLatin1String(">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n")
+ if (!QDBusMetaType::signatureToMetaType(signature).isValid()) {
+ const char *typeName = type.name();
+ retval += ">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n"_L1
.arg(typeNameToXml(typeName));
} else {
- retval += QLatin1String("/>\n");
+ retval += "/>\n"_L1;
}
}
}
@@ -127,14 +93,17 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
for (int i = methodOffset; i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
- bool isSignal;
+ bool isSignal = false;
+ bool isSlot = false;
if (mm.methodType() == QMetaMethod::Signal)
// adding a signal
isSignal = true;
- else if (mm.access() == QMetaMethod::Public && (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method))
- isSignal = false;
+ else if (mm.access() == QMetaMethod::Public && mm.methodType() == QMetaMethod::Slot)
+ isSlot = true;
+ else if (mm.access() == QMetaMethod::Public && mm.methodType() == QMetaMethod::Method)
+ ; // invokable, neither signal nor slot
else
- continue; // neither signal nor public slot
+ continue; // neither signal nor public method/slot
if (isSignal && !(flags & (QDBusConnection::ExportScriptableSignals |
QDBusConnection::ExportNonScriptableSignals)))
@@ -153,36 +122,36 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
isSignal ? "signal" : "method", mm.name().constData());
// check the return type first
- int typeId = mm.returnType();
- if (typeId != QMetaType::UnknownType && typeId != QMetaType::Void) {
+ QMetaType typeId = mm.returnMetaType();
+ if (typeId.isValid() && typeId.id() != QMetaType::Void) {
const char *typeName = QDBusMetaType::typeToSignature(typeId);
if (typeName) {
- xml += QLatin1String(" <arg type=\"%1\" direction=\"out\"/>\n")
+ xml += " <arg type=\"%1\" direction=\"out\"/>\n"_L1
.arg(typeNameToXml(typeName));
// do we need to describe this argument?
- if (QDBusMetaType::signatureToType(typeName) == QMetaType::UnknownType)
- xml += QLatin1String(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
- .arg(typeNameToXml(QMetaType::typeName(typeId)));
+ if (!QDBusMetaType::signatureToMetaType(typeName).isValid())
+ xml += " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n"_L1
+ .arg(typeNameToXml(QMetaType(typeId).name()));
} else {
- qWarning() << "Unsupported return type" << typeId << QMetaType::typeName(typeId) << "in method" << mm.name();
+ qWarning() << "Unsupported return type" << typeId.id() << typeId.name() << "in method" << mm.name();
continue;
}
}
- else if (typeId == QMetaType::UnknownType) {
+ else if (!typeId.isValid()) {
qWarning() << "Invalid return type in method" << mm.name();
continue; // wasn't a valid type
}
QList<QByteArray> names = mm.parameterNames();
- QList<int> types;
+ QList<QMetaType> types;
QString errorMsg;
int inputCount = qDBusParametersForMethod(mm, types, errorMsg);
if (inputCount == -1) {
qWarning() << "Skipped method" << mm.name() << ":" << qPrintable(errorMsg);
continue; // invalid form
}
- if (isSignal && inputCount + 1 != types.count())
+ if (isSignal && inputCount + 1 != types.size())
continue; // signal with output arguments?
if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message())
continue; // signal with QDBusMessage argument?
@@ -190,7 +159,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
continue; // cloned signal?
int j;
- for (j = 1; j < types.count(); ++j) {
+ for (j = 1; j < types.size(); ++j) {
// input parameter for a slot or output for a signal
if (types.at(j) == QDBusMetaTypeId::message()) {
isScriptable = true;
@@ -199,7 +168,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
QString name;
if (!names.at(j - 1).isEmpty())
- name = QLatin1String("name=\"%1\" ").arg(QLatin1String(names.at(j - 1)));
+ name = "name=\"%1\" "_L1.arg(QLatin1StringView(names.at(j - 1)));
bool isOutput = isSignal || j > inputCount;
@@ -208,10 +177,10 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
qUtf16Printable(name), signature, isOutput ? "out" : "in");
// do we need to describe this argument?
- if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) {
- const char *typeName = QMetaType::typeName(types.at(j));
+ if (!QDBusMetaType::signatureToMetaType(signature).isValid()) {
+ const char *typeName = QMetaType(types.at(j)).name();
xml += QString::fromLatin1(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.%1%2\" value=\"%3\"/>\n")
- .arg(isOutput ? QLatin1String("Out") : QLatin1String("In"))
+ .arg(isOutput ? "Out"_L1 : "In"_L1)
.arg(isOutput && !isSignal ? j - inputCount : j - 1)
.arg(typeNameToXml(typeName));
}
@@ -220,21 +189,21 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
int wantedMask;
if (isScriptable)
wantedMask = isSignal ? QDBusConnection::ExportScriptableSignals
- : QDBusConnection::ExportScriptableSlots;
+ : isSlot ? QDBusConnection::ExportScriptableSlots
+ : QDBusConnection::ExportScriptableInvokables;
else
wantedMask = isSignal ? QDBusConnection::ExportNonScriptableSignals
- : QDBusConnection::ExportNonScriptableSlots;
+ : isSlot ? QDBusConnection::ExportNonScriptableSlots
+ : QDBusConnection::ExportNonScriptableInvokables;
if ((flags & wantedMask) != wantedMask)
continue;
if (qDBusCheckAsyncTag(mm.tag()))
// add the no-reply annotation
- xml += QLatin1String(" <annotation name=\"" ANNOTATION_NO_WAIT "\""
- " value=\"true\"/>\n");
+ xml += " <annotation name=\"" ANNOTATION_NO_WAIT "\" value=\"true\"/>\n"_L1;
retval += xml;
- retval += QLatin1String(" </%1>\n")
- .arg(isSignal ? QLatin1String("signal") : QLatin1String("method"));
+ retval += " </%1>\n"_L1.arg(isSignal ? "signal"_L1 : "method"_L1);
}
return retval;
@@ -256,60 +225,10 @@ QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
if (xml.isEmpty())
return QString(); // don't add an empty interface
- return QLatin1String(" <interface name=\"%1\">\n%2 </interface>\n")
- .arg(interface, xml);
-}
-#if 0
-QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo, const QMetaObject *base,
- int flags)
-{
- if (interface.isEmpty()) {
- // generate the interface name from the meta object
- int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
- if (idx >= mo->classInfoOffset()) {
- interface = QLatin1String(mo->classInfo(idx).value());
- } else {
- interface = QLatin1String(mo->className());
- interface.replace(QLatin1String("::"), QLatin1String("."));
-
- if (interface.startsWith(QLatin1String("QDBus"))) {
- interface.prepend(QLatin1String("org.qtproject.QtDBus."));
- } else if (interface.startsWith(QLatin1Char('Q')) &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
- // assume it's Qt
- interface.prepend(QLatin1String("org.qtproject.Qt."));
- } else if (!QCoreApplication::instance()||
- QCoreApplication::instance()->applicationName().isEmpty()) {
- interface.prepend(QLatin1String("local."));
- } else {
- interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
- QStringList domainName =
- QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
- Qt::SkipEmptyParts);
- if (domainName.isEmpty())
- interface.prepend(QLatin1String("local."));
- else
- for (int i = 0; i < domainName.count(); ++i)
- interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
- }
- }
- }
-
- QString xml;
- int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTROSPECTION);
- if (idx >= mo->classInfoOffset())
- return QString::fromUtf8(mo->classInfo(idx).value());
- else
- xml = generateInterfaceXml(mo, flags, base->methodCount(), base->propertyCount());
-
- if (xml.isEmpty())
- return QString(); // don't add an empty interface
- return QString::fromLatin1(" <interface name=\"%1\">\n%2 </interface>\n")
+ return " <interface name=\"%1\">\n%2 </interface>\n"_L1
.arg(interface, xml);
}
-#endif
-
QT_END_NAMESPACE
#endif // QT_NO_DBUS