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 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/tools/qdbusxml2cpp') 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; -- cgit v1.2.3