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>
This commit is contained in:
parent
4332cb3134
commit
479072791b
@ -316,7 +316,8 @@ public:
|
||||
|
||||
public:
|
||||
// static methods
|
||||
static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> ¶ms);
|
||||
static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> ¶ms,
|
||||
QString &errorMsg);
|
||||
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
|
||||
const QString &service,
|
||||
const QString &path, const QString &interface, const QString &name,
|
||||
|
@ -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> ¶ms)
|
||||
QList<QMetaType> ¶ms, 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);
|
||||
|
@ -123,16 +123,18 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb
|
||||
return false;
|
||||
}
|
||||
|
||||
methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes);
|
||||
QString errorMsg;
|
||||
methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes, errorMsg);
|
||||
if (methodIdx == -1) {
|
||||
QByteArray normalizedName = QMetaObject::normalizedSignature(member + 1);
|
||||
methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes);
|
||||
methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes, errorMsg);
|
||||
}
|
||||
if (methodIdx == -1) {
|
||||
// would not be able to deliver a reply
|
||||
qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)",
|
||||
target->metaObject()->className(),
|
||||
member + 1, qPrintable(target->objectName()));
|
||||
qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s) "
|
||||
"because %s",
|
||||
target->metaObject()->className(), member + 1, qPrintable(target->objectName()),
|
||||
qPrintable(errorMsg));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user