From 6f275a4beb9a42b9d5ac99682ce9939a66239778 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 31 May 2016 11:57:53 -0300 Subject: Make sure QDBusConnection::connect() returns false if already connected QDBusConnection::connect() behaves like QObject::connect with a connection type of Qt::UniqueConnection | Qt::QueuedConnection. So return false if it's already connected. [ChangeLog][QtDBus][QDBusConnection] Fixed a bug that would cause QDBusConnection::connect() to return true if a slot was already connected to the same D-Bus signal. QtDBus does not support multiple connections. Change-Id: I87e17314d8b24ae983b1fffd1453aef5a7c9ad0b Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/dbus/qdbusconnection_p.h | 4 ++-- src/dbus/qdbusintegrator.cpp | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index bd100639d1..0b7c731810 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -280,7 +280,7 @@ public slots: void socketWrite(int); void objectDestroyed(QObject *o); void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args); - void addSignalHook(const QString &key, const SignalHook &hook); + bool addSignalHook(const QString &key, const SignalHook &hook); bool removeSignalHook(const QString &key, const SignalHook &hook); private slots: @@ -293,7 +293,7 @@ signals: void dispatchStatusChanged(); void spyHooksFinished(const QDBusMessage &msg); void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout = -1); - void signalNeedsConnecting(const QString &key, const QDBusConnectionPrivate::SignalHook &hook); + bool signalNeedsConnecting(const QString &key, const QDBusConnectionPrivate::SignalHook &hook); bool signalNeedsDisconnecting(const QString &key, const QDBusConnectionPrivate::SignalHook &hook); void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 54418c213a..21bc3c8ac2 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -2187,20 +2187,16 @@ bool QDBusConnectionPrivate::connectSignal(const QString &service, // check the slot QDBusConnectionPrivate::SignalHook hook; QString key; - QString name2 = name; - if (name2.isNull()) - name2.detach(); hook.signature = signature; if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false)) return false; // don't connect Q_ASSERT(thread() != QThread::currentThread()); - emit signalNeedsConnecting(key, hook); - return true; + return emit signalNeedsConnecting(key, hook); } -void QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook &hook) +bool QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook &hook) { QDBusWriteLocker locker(ConnectAction, this); @@ -2216,7 +2212,7 @@ void QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook entry.midx == hook.midx && entry.argumentMatch == hook.argumentMatch) { // no need to compare the parameters if it's the same slot - return; // already there + return false; // already there } } @@ -2228,7 +2224,7 @@ void QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook if (mit != matchRefCounts.end()) { // Match already present mit.value() = mit.value() + 1; - return; + return true; } matchRefCounts.insert(hook.matchRule, 1); @@ -2255,6 +2251,7 @@ void QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook } } } + return true; } bool QDBusConnectionPrivate::disconnectSignal(const QString &service, -- cgit v1.2.3