QDBusConnection: Print error from prepareHook

When the operation fails we print a warning, but that warning does not
include the error message that prepareHook internally collects but
ignores.

Printing the error is useful for debugging.

Change-Id: I946c4781942115a17ffd43a79bff7676b6674be1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit b2e5f7049047f6311b96506621ac75ec2fcb0c2e)
This commit is contained in:
Nicolas Fella 2023-09-07 21:36:20 +02:00
parent f4bcf9f5af
commit 770d4ad14f
2 changed files with 25 additions and 20 deletions

View File

@ -321,11 +321,10 @@ public:
static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> &params, static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> &params,
QString &errorMsg); QString &errorMsg);
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
const QString &service, const QString &service, const QString &path, const QString &interface,
const QString &path, const QString &interface, const QString &name, const QString &name, const ArgMatchRules &argMatch, QObject *receiver,
const ArgMatchRules &argMatch, const char *signal, int minMIdx, bool buildSignature,
QObject *receiver, const char *signal, int minMIdx, QString &errorMsg);
bool buildSignature);
static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *); static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *);
static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object, static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object,
int idx, const QList<QMetaType> &metaTypes, int idx, const QList<QMetaType> &metaTypes,

View File

@ -1287,14 +1287,13 @@ int QDBusConnectionPrivate::findSlot(QObject *obj, const QByteArray &normalizedN
} }
bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
const QString &service, const QString &service, const QString &path,
const QString &path, const QString &interface, const QString &name, const QString &interface, const QString &name,
const ArgMatchRules &argMatch, const ArgMatchRules &argMatch, QObject *receiver,
QObject *receiver, const char *signal, int minMIdx, const char *signal, int minMIdx, bool buildSignature,
bool buildSignature) QString &errorMsg)
{ {
QByteArray normalizedName = signal + 1; QByteArray normalizedName = signal + 1;
QString errorMsg;
hook.midx = findSlot(receiver, signal + 1, hook.params, errorMsg); hook.midx = findSlot(receiver, signal + 1, hook.params, errorMsg);
if (hook.midx == -1) { if (hook.midx == -1) {
normalizedName = QMetaObject::normalizedSignature(signal + 1); normalizedName = QMetaObject::normalizedSignature(signal + 1);
@ -2210,9 +2209,11 @@ bool QDBusConnectionPrivate::connectSignal(const QString &service,
QString key; QString key;
hook.signature = signature; hook.signature = signature;
QString errorMsg;
if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0,
false)) { false, errorMsg)) {
qCWarning(dbusIntegration) << "Could not connect" << interface << "to" << slot + 1; qCWarning(dbusIntegration)
<< "Could not connect" << interface << "to" << slot + 1 << ":" << qPrintable(errorMsg);
return false; // don't connect return false; // don't connect
} }
@ -2303,9 +2304,11 @@ bool QDBusConnectionPrivate::disconnectSignal(const QString &service,
name2.detach(); name2.detach();
hook.signature = signature; hook.signature = signature;
QString errorMsg;
if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0,
false)) { false, errorMsg)) {
qCWarning(dbusIntegration) << "Could not disconnect" << interface << "to" << slot + 1; qCWarning(dbusIntegration)
<< "Could not disconnect" << interface << "to" << slot + 1 << ":" << qPrintable(errorMsg);
return false; // don't disconnect return false; // don't disconnect
} }
@ -2435,9 +2438,11 @@ void QDBusConnectionPrivate::connectRelay(const QString &service,
QByteArray sig; QByteArray sig;
sig.append(QSIGNAL_CODE + '0'); sig.append(QSIGNAL_CODE + '0');
sig.append(signal.methodSignature()); sig.append(signal.methodSignature());
QString errorMsg;
if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig, if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig,
QDBusAbstractInterface::staticMetaObject.methodCount(), true)) { QDBusAbstractInterface::staticMetaObject.methodCount(), true, errorMsg)) {
qCWarning(dbusIntegration) << "Could not connect" << interface << "to" << signal.name(); qCWarning(dbusIntegration)
<< "Could not connect" << interface << "to" << signal.name() << ":" << qPrintable(errorMsg);
return; // don't connect return; // don't connect
} }
@ -2458,10 +2463,11 @@ void QDBusConnectionPrivate::disconnectRelay(const QString &service,
QByteArray sig; QByteArray sig;
sig.append(QSIGNAL_CODE + '0'); sig.append(QSIGNAL_CODE + '0');
sig.append(signal.methodSignature()); sig.append(signal.methodSignature());
QString errorMsg;
if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig, if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig,
QDBusAbstractInterface::staticMetaObject.methodCount(), true)) { QDBusAbstractInterface::staticMetaObject.methodCount(), true, errorMsg)) {
qCWarning(dbusIntegration) qCWarning(dbusIntegration) << "Could not disconnect" << interface << "to"
<< "Could not disconnect" << interface << "to" << signal.methodSignature(); << signal.methodSignature() << ":" << qPrintable(errorMsg);
return; // don't disconnect return; // don't disconnect
} }