summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusintegrator.cpp
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2022-11-16 16:05:01 +0100
committerAleix Pol <aleixpol@kde.org>2022-11-26 01:45:43 +0100
commit479072791b0a91dae375bd136a5062e4e85d9e7a (patch)
tree4c873d0260bfc4d37cbcfbf3e2dd3359d885e88b /src/dbus/qdbusintegrator.cpp
parent4332cb313469de1525afe3cddd792d7bc7e08a14 (diff)
dbus: Include some debug messages when failing to connect
When using dbus, there's a number of cases where resolution happens at runtime. It's useful to see dbus complain when connects don't work, because otherwise the system doesn't work but we don't know what is happening. Added this to debug such an issue, already helped me address other cases that had gone unnoticed elsewhere, so this is something that benefits from being in QtDBus. Change-Id: I5eefb94fcf775182edf1ad0c24e8a6692f84b15f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/dbus/qdbusintegrator.cpp')
-rw-r--r--src/dbus/qdbusintegrator.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 8b190b8e5f..09f29f9556 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -6,7 +6,7 @@
#include <qcoreapplication.h>
#include <qelapsedtimer.h>
-#include <qdebug.h>
+#include <qloggingcategory.h>
#include <qmetaobject.h>
#include <qobject.h>
#include <qsocketnotifier.h>
@@ -50,6 +50,8 @@ QT_IMPL_METATYPE_EXTERN(QDBusSlotCache)
// used with dbus_server_allocate_data_slot
static dbus_int32_t server_slot = -1;
+Q_LOGGING_CATEGORY(dbusIntegration, "qt.dbus.integration", QtWarningMsg)
+
Q_CONSTINIT static QBasicAtomicInt isDebugging = Q_BASIC_ATOMIC_INITIALIZER(-1);
#define qDBusDebug if (::isDebugging.loadRelaxed() == 0); else qDebug
@@ -860,6 +862,9 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu
slotData.metaTypes.clear();
slotCache.hash.insert(cacheKey, slotData);
object->setProperty(cachePropertyName, QVariant::fromValue(slotCache));
+
+ qCWarning(dbusIntegration).nospace() << "Could not find slot " << mo->className()
+ << "::" << memberName.constData();
return false;
}
}
@@ -1288,16 +1293,16 @@ void QDBusConnectionPrivate::serviceOwnerChangedNoLock(const QString &name,
}
int QDBusConnectionPrivate::findSlot(QObject *obj, const QByteArray &normalizedName,
- QList<QMetaType> &params)
+ QList<QMetaType> &params, QString &errorMsg)
{
+ errorMsg.clear();
int midx = obj->metaObject()->indexOfMethod(normalizedName);
if (midx == -1)
return -1;
- QString errorMsg;
int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params, errorMsg);
- if ( inputCount == -1 || inputCount + 1 != params.size() )
- return -1; // failed to parse or invalid arguments or output arguments
+ if (inputCount == -1 || inputCount + 1 != params.size())
+ return -1;
return midx;
}
@@ -1310,10 +1315,11 @@ bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hoo
bool buildSignature)
{
QByteArray normalizedName = signal + 1;
- hook.midx = findSlot(receiver, signal + 1, hook.params);
+ QString errorMsg;
+ hook.midx = findSlot(receiver, signal + 1, hook.params, errorMsg);
if (hook.midx == -1) {
normalizedName = QMetaObject::normalizedSignature(signal + 1);
- hook.midx = findSlot(receiver, normalizedName, hook.params);
+ hook.midx = findSlot(receiver, normalizedName, hook.params, errorMsg);
}
if (hook.midx < minMIdx) {
return false;
@@ -2210,8 +2216,11 @@ bool QDBusConnectionPrivate::connectSignal(const QString &service,
QString key;
hook.signature = signature;
- if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false))
+ if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0,
+ false)) {
+ qCWarning(dbusIntegration) << "Could not connect" << interface << "to" << slot + 1;
return false; // don't connect
+ }
Q_ASSERT(thread() != QThread::currentThread());
return emit signalNeedsConnecting(key, hook);
@@ -2300,8 +2309,11 @@ bool QDBusConnectionPrivate::disconnectSignal(const QString &service,
name2.detach();
hook.signature = signature;
- if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false))
+ if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0,
+ false)) {
+ qCWarning(dbusIntegration) << "Could not disconnect" << interface << "to" << slot + 1;
return false; // don't disconnect
+ }
Q_ASSERT(thread() != QThread::currentThread());
return emit signalNeedsDisconnecting(key, hook);
@@ -2428,8 +2440,10 @@ void QDBusConnectionPrivate::connectRelay(const QString &service,
sig.append(QSIGNAL_CODE + '0');
sig.append(signal.methodSignature());
if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig,
- QDBusAbstractInterface::staticMetaObject.methodCount(), true))
+ QDBusAbstractInterface::staticMetaObject.methodCount(), true)) {
+ qCWarning(dbusIntegration) << "Could not connect" << interface << "to" << signal.name();
return; // don't connect
+ }
Q_ASSERT(thread() != QThread::currentThread());
emit signalNeedsConnecting(key, hook);
@@ -2449,8 +2463,11 @@ void QDBusConnectionPrivate::disconnectRelay(const QString &service,
sig.append(QSIGNAL_CODE + '0');
sig.append(signal.methodSignature());
if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig,
- QDBusAbstractInterface::staticMetaObject.methodCount(), true))
+ QDBusAbstractInterface::staticMetaObject.methodCount(), true)) {
+ qCWarning(dbusIntegration)
+ << "Could not disconnect" << interface << "to" << signal.methodSignature();
return; // don't disconnect
+ }
Q_ASSERT(thread() != QThread::currentThread());
emit signalNeedsDisconnecting(key, hook);