From 54079de9f9968513a741eeceb2a24c2fd2ddbb96 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 21 Nov 2014 14:54:33 +0100 Subject: Add annotation to rename methods created by qdbusxml2cpp Under DBus it is possible to have methods and signals with the same name or have methods which are reserved c++ keywords. For example the logind session interface has a signal and method both called Lock. This patch allows generated methods to use a different method name specified in the annotation that the original DBus name in the DBus interface in a similar manner to how one can rename accessors. [ChangeLog][QtDBus] Add annotation org.qtproject.QtDBus.MethodName to allow autogenerating C++ methods with different names to the original DBus method Change-Id: I08bbe77554fbdd348e93f82d45bab0d75d360c27 Reviewed-by: Thiago Macieira --- src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 15 ++++++++++++--- tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp index a85dd44f65..871175a822 100644 --- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp +++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp @@ -488,6 +488,15 @@ static QString propertySetter(const QDBusIntrospection::Property &property) return setter; } +static QString methodName(const QDBusIntrospection::Method &method) +{ + QString name = method.annotations.value(QStringLiteral("org.qtproject.QtDBus.MethodName")); + if (!name.isEmpty()) + return name; + + return method.name; +} + static QString stringify(const QString &data) { QString retval; @@ -679,7 +688,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf hs << "> "; } - hs << method.name << "("; + hs << methodName(method) << "("; QStringList argNames = makeArgNames(method.inputArgs); writeArgList(hs, argNames, method.annotations, method.inputArgs); @@ -1012,7 +1021,7 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte cs << returnType << " "; } - QString name = method.name; + QString name = methodName(method); hs << name << "("; cs << className << "::" << name << "("; @@ -1023,7 +1032,7 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte hs << ");" << endl; // finished for header cs << ")" << endl << "{" << endl - << " // handle method call " << interface->name << "." << method.name << endl; + << " // handle method call " << interface->name << "." << methodName(method) << endl; // make the call bool usingInvokeMethod = false; diff --git a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp index eac61a38b8..f6e4e3bdd9 100644 --- a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp +++ b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp @@ -160,6 +160,16 @@ void tst_qdbusxml2cpp::process_data() .arg(basicTypeList[i].cppType), QRegularExpression::DotMatchesEverythingOption); } + QTest::newRow("method-name") + << "" + "" + "" + "" + << QRegularExpression("Q_SLOTS:.*QDBusPendingReply<> MethodRenamed\\(const QString &\\w*", + QRegularExpression::DotMatchesEverythingOption) + << QRegularExpression("Q_SLOTS:.*void MethodRenamed\\(const QString &\\w*", + QRegularExpression::DotMatchesEverythingOption); + QTest::newRow("method-complex") << "" "" -- cgit v1.2.3