QDBus: improve error handling, to give the developer feedback.
For instance, exporting an object with a slot like QString complexMethod(const MyVariantMap& vars); (even with a simple typedef QVariantMap MyVariantMap) used to silently skip that method in the introspection. Now it outputs: generateInterfaceXml: Skipped method "complexMethod" : Invalid type in parameter list: MyVariantMap Change-Id: I7964cfb63e973257ce1abe47b9625e361b2ad23f Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
170469ef84
commit
b2f9839457
@ -298,15 +298,18 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
|
||||
|
||||
// break down the parameter list
|
||||
QVector<int> types;
|
||||
int inputCount = qDBusParametersForMethod(mm, types);
|
||||
if (inputCount == -1)
|
||||
QString errorMsg;
|
||||
int inputCount = qDBusParametersForMethod(mm, types, errorMsg);
|
||||
if (inputCount == -1) {
|
||||
// invalid signal signature
|
||||
// qDBusParametersForMethod has already complained
|
||||
qWarning("QDBusAbstractAdaptor: Cannot relay signal %s::%s: %s",
|
||||
senderMetaObject->className(), mm.methodSignature().constData(),
|
||||
qPrintable(errorMsg));
|
||||
return;
|
||||
}
|
||||
if (inputCount + 1 != types.count() ||
|
||||
types.at(inputCount) == QDBusMetaTypeId::message()) {
|
||||
// invalid signal signature
|
||||
// qDBusParametersForMethod has not yet complained about this one
|
||||
qWarning("QDBusAbstractAdaptor: Cannot relay signal %s::%s",
|
||||
senderMetaObject->className(), mm.methodSignature().constData());
|
||||
return;
|
||||
|
@ -342,9 +342,9 @@ public:
|
||||
};
|
||||
|
||||
// in qdbusmisc.cpp
|
||||
extern int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes);
|
||||
extern int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes, QString &errorMsg);
|
||||
#endif // QT_BOOTSTRAPPED
|
||||
extern Q_DBUS_EXPORT int qDBusParametersForMethod(const QList<QByteArray> ¶meters, QVector<int>& metaTypes);
|
||||
extern Q_DBUS_EXPORT int qDBusParametersForMethod(const QList<QByteArray> ¶meters, QVector<int>& metaTypes, QString &errorMsg);
|
||||
extern Q_DBUS_EXPORT bool qDBusCheckAsyncTag(const char *tag);
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
extern bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name);
|
||||
|
@ -721,7 +721,8 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
|
||||
if (isAsync && returnType != QMetaType::Void)
|
||||
continue;
|
||||
|
||||
int inputCount = qDBusParametersForMethod(mm, metaTypes);
|
||||
QString errorMsg;
|
||||
int inputCount = qDBusParametersForMethod(mm, metaTypes, errorMsg);
|
||||
if (inputCount == -1)
|
||||
continue; // problem parsing
|
||||
|
||||
@ -1312,7 +1313,8 @@ int QDBusConnectionPrivate::findSlot(QObject* obj, const QByteArray &normalizedN
|
||||
if (midx == -1)
|
||||
return -1;
|
||||
|
||||
int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params);
|
||||
QString errorMsg;
|
||||
int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params, errorMsg);
|
||||
if ( inputCount == -1 || inputCount + 1 != params.count() )
|
||||
return -1; // failed to parse or invalid arguments or output arguments
|
||||
|
||||
|
@ -131,14 +131,14 @@ bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
|
||||
// metaTypes.count() >= retval + 1 in all cases
|
||||
//
|
||||
// sig must be the normalised signature for the method
|
||||
int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes)
|
||||
int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes, QString &errorMsg)
|
||||
{
|
||||
return qDBusParametersForMethod(mm.parameterTypes(), metaTypes);
|
||||
return qDBusParametersForMethod(mm.parameterTypes(), metaTypes, errorMsg);
|
||||
}
|
||||
|
||||
#endif // QT_BOOTSTRAPPED
|
||||
|
||||
int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QVector<int>& metaTypes)
|
||||
int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QVector<int>& metaTypes, QString &errorMsg)
|
||||
{
|
||||
QDBusMetaTypeId::init();
|
||||
metaTypes.clear();
|
||||
@ -151,8 +151,7 @@ int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QVector<in
|
||||
for ( ; it != end; ++it) {
|
||||
const QByteArray &type = *it;
|
||||
if (type.endsWith('*')) {
|
||||
//qWarning("Could not parse the method '%s'", mm.methodSignature().constData());
|
||||
// pointer?
|
||||
errorMsg = QLatin1String("Pointers are not supported: ") + QLatin1String(type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -162,8 +161,7 @@ int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QVector<in
|
||||
|
||||
int id = QMetaType::type(basictype);
|
||||
if (id == 0) {
|
||||
//qWarning("Could not parse the method '%s'", mm.methodSignature().constData());
|
||||
// invalid type in method parameter list
|
||||
errorMsg = QLatin1String("Unregistered output type in parameter list: ") + QLatin1String(type);
|
||||
return -1;
|
||||
} else if (QDBusMetaType::typeToSignature(id) == 0)
|
||||
return -1;
|
||||
@ -174,22 +172,22 @@ int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QVector<in
|
||||
}
|
||||
|
||||
if (seenMessage) { // && !type.endsWith('&')
|
||||
//qWarning("Could not parse the method '%s'", mm.methodSignature().constData());
|
||||
// non-output parameters after message or after output params
|
||||
errorMsg = QLatin1String("Invalid method, non-output parameters after message or after output parameters: ") + QLatin1String(type);
|
||||
return -1; // not allowed
|
||||
}
|
||||
|
||||
int id = QMetaType::type(type);
|
||||
if (id == QMetaType::UnknownType) {
|
||||
//qWarning("Could not parse the method '%s'", mm.methodSignature().constData());
|
||||
// invalid type in method parameter list
|
||||
errorMsg = QLatin1String("Unregistered input type in parameter list: ") + QLatin1String(type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (id == QDBusMetaTypeId::message())
|
||||
seenMessage = true;
|
||||
else if (QDBusMetaType::typeToSignature(id) == 0)
|
||||
else if (QDBusMetaType::typeToSignature(id) == 0) {
|
||||
errorMsg = QLatin1String("Type not registered with QtDBus in parameter list: ") + QLatin1String(type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
metaTypes.append(id);
|
||||
++inputCount;
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <QtCore/qmetaobject.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
#include "qdbusinterface_p.h" // for ANNOTATION_NO_WAIT
|
||||
#include "qdbusabstractadaptor_p.h" // for QCLASSINFO_DBUS_*
|
||||
@ -159,17 +160,24 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
|
||||
if (QDBusMetaType::signatureToType(typeName) == QVariant::Invalid)
|
||||
xml += QString::fromLatin1(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
|
||||
.arg(typeNameToXml(QMetaType::typeName(typeId)));
|
||||
} else
|
||||
} else {
|
||||
qWarning() << "Unsupported return type" << typeId << QMetaType::typeName(typeId) << "in method" << mm.name();
|
||||
continue;
|
||||
}
|
||||
else if (typeId == QMetaType::UnknownType)
|
||||
}
|
||||
else if (typeId == QMetaType::UnknownType) {
|
||||
qWarning() << "Invalid return type in method" << mm.name();
|
||||
continue; // wasn't a valid type
|
||||
}
|
||||
|
||||
QList<QByteArray> names = mm.parameterNames();
|
||||
QVector<int> types;
|
||||
int inputCount = qDBusParametersForMethod(mm, types);
|
||||
if (inputCount == -1)
|
||||
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())
|
||||
continue; // signal with output arguments?
|
||||
if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message())
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <qbuffer.h>
|
||||
#include <qregexp.h>
|
||||
#include <qvector.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -95,14 +96,14 @@ static const char help[] =
|
||||
"\n";
|
||||
|
||||
|
||||
int qDBusParametersForMethod(const FunctionDef &mm, QVector<int>& metaTypes)
|
||||
int qDBusParametersForMethod(const FunctionDef &mm, QVector<int>& metaTypes, QString &errorMsg)
|
||||
{
|
||||
QList<QByteArray> parameterTypes;
|
||||
|
||||
foreach (const ArgumentDef &arg, mm.arguments)
|
||||
parameterTypes.append(arg.normalizedType);
|
||||
|
||||
return qDBusParametersForMethod(parameterTypes, metaTypes);
|
||||
return qDBusParametersForMethod(parameterTypes, metaTypes, errorMsg);
|
||||
}
|
||||
|
||||
|
||||
@ -140,9 +141,12 @@ static QString addFunction(const FunctionDef &mm, bool isSignal = false) {
|
||||
}
|
||||
QList<ArgumentDef> names = mm.arguments;
|
||||
QVector<int> types;
|
||||
int inputCount = qDBusParametersForMethod(mm, types);
|
||||
if (inputCount == -1)
|
||||
QString errorMsg;
|
||||
int inputCount = qDBusParametersForMethod(mm, types, errorMsg);
|
||||
if (inputCount == -1) {
|
||||
qWarning() << qPrintable(errorMsg);
|
||||
return QString(); // invalid form
|
||||
}
|
||||
if (isSignal && inputCount + 1 != types.count())
|
||||
return QString(); // signal with output arguments?
|
||||
if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message())
|
||||
|
Loading…
Reference in New Issue
Block a user