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 <thiago.macieira@intel.com>bb10
parent
aeceb5e383
commit
54079de9f9
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -160,6 +160,16 @@ void tst_qdbusxml2cpp::process_data()
|
|||
.arg(basicTypeList[i].cppType), QRegularExpression::DotMatchesEverythingOption);
|
||||
}
|
||||
|
||||
QTest::newRow("method-name")
|
||||
<< "<method name=\"Method\">"
|
||||
"<arg type=\"s\" direction=\"in\"/>"
|
||||
"<annotation name=\"org.qtproject.QtDBus.MethodName\" value=\"MethodRenamed\" />"
|
||||
"</method>"
|
||||
<< QRegularExpression("Q_SLOTS:.*QDBusPendingReply<> MethodRenamed\\(const QString &\\w*",
|
||||
QRegularExpression::DotMatchesEverythingOption)
|
||||
<< QRegularExpression("Q_SLOTS:.*void MethodRenamed\\(const QString &\\w*",
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QTest::newRow("method-complex")
|
||||
<< "<method name=\"Method\">"
|
||||
"<arg type=\"(dd)\" direction=\"in\"/>"
|
||||
|
|
|
|||
Loading…
Reference in New Issue