summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusservicewatcher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/qdbusservicewatcher.cpp')
-rw-r--r--src/dbus/qdbusservicewatcher.cpp117
1 files changed, 44 insertions, 73 deletions
diff --git a/src/dbus/qdbusservicewatcher.cpp b/src/dbus/qdbusservicewatcher.cpp
index 47cb4441c3..bf94f54f56 100644
--- a/src/dbus/qdbusservicewatcher.cpp
+++ b/src/dbus/qdbusservicewatcher.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusservicewatcher.h"
#include "qdbusconnection.h"
@@ -76,10 +40,11 @@ public:
&QDBusServiceWatcherPrivate::setWatchModeForwardToQ)
void _q_serviceOwnerChanged(const QString &, const QString &, const QString &);
- void setConnection(const QStringList &services, const QDBusConnection &c, QDBusServiceWatcher::WatchMode watchMode);
+ void setConnection(const QStringList &newServices, const QDBusConnection &newConnection,
+ QDBusServiceWatcher::WatchMode newMode);
- void addService(const QString &service);
- void removeService(const QString &service);
+ void addService(const QString &service, QDBusServiceWatcher::WatchMode mode);
+ void removeService(const QString &service, QDBusServiceWatcher::WatchMode mode);
};
void QDBusServiceWatcherPrivate::_q_serviceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)
@@ -92,39 +57,43 @@ void QDBusServiceWatcherPrivate::_q_serviceOwnerChanged(const QString &service,
emit q->serviceUnregistered(service);
}
-void QDBusServiceWatcherPrivate::setConnection(const QStringList &services,
- const QDBusConnection &c,
- QDBusServiceWatcher::WatchMode wm)
+void QDBusServiceWatcherPrivate::setConnection(const QStringList &newServices,
+ const QDBusConnection &newConnection,
+ QDBusServiceWatcher::WatchMode newMode)
{
+ const QStringList oldServices = watchedServicesData.valueBypassingBindings();
+ const QDBusServiceWatcher::WatchMode oldMode = watchMode.valueBypassingBindings();
if (connection.isConnected()) {
// remove older rules
- for (const QString &s : qAsConst(watchedServicesData.value()))
- removeService(s);
+ for (const QString &s : oldServices)
+ removeService(s, oldMode);
}
- connection = c;
- watchMode.setValueBypassingBindings(wm); // caller has to call notify()
- watchedServicesData.setValueBypassingBindings(services); // caller has to call notify()
+ connection = newConnection;
+ watchMode.setValueBypassingBindings(newMode); // caller has to call notify()
+ watchedServicesData.setValueBypassingBindings(newServices); // caller has to call notify()
if (connection.isConnected()) {
// add new rules
- for (const QString &s : qAsConst(watchedServicesData.value()))
- addService(s);
+ for (const QString &s : newServices)
+ addService(s, newMode);
}
}
-void QDBusServiceWatcherPrivate::addService(const QString &service)
+void QDBusServiceWatcherPrivate::addService(const QString &service,
+ QDBusServiceWatcher::WatchMode mode)
{
QDBusConnectionPrivate *d = QDBusConnectionPrivate::d(connection);
if (d && d->shouldWatchService(service))
- d->watchService(service, watchMode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+ d->watchService(service, mode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
}
-void QDBusServiceWatcherPrivate::removeService(const QString &service)
+void QDBusServiceWatcherPrivate::removeService(const QString &service,
+ QDBusServiceWatcher::WatchMode mode)
{
QDBusConnectionPrivate *d = QDBusConnectionPrivate::d(connection);
if (d && d->shouldWatchService(service))
- d->unwatchService(service, watchMode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+ d->unwatchService(service, mode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
}
/*!
@@ -296,8 +265,9 @@ void QDBusServiceWatcher::setWatchedServices(const QStringList &services)
{
Q_D(QDBusServiceWatcher);
d->watchedServicesData.removeBindingUnlessInWrapper();
- if (services == d->watchedServicesData)
+ if (services == d->watchedServicesData.valueBypassingBindings())
return;
+ // trigger watchMode re-evaluation, but only once for the setter
d->setConnection(services, d->connection, d->watchMode);
d->watchedServicesData.notify();
}
@@ -319,13 +289,14 @@ void QDBusServiceWatcher::addWatchedService(const QString &newService)
{
Q_D(QDBusServiceWatcher);
d->watchedServicesData.removeBindingUnlessInWrapper();
- if (d->watchedServicesData.value().contains(newService))
+ auto services = d->watchedServicesData.valueBypassingBindings();
+ if (services.contains(newService))
return;
- d->addService(newService);
+ // re-evaluate watch mode
+ d->addService(newService, d->watchMode);
- auto templist = d->watchedServicesData.valueBypassingBindings();
- templist << newService;
- d->watchedServicesData.setValueBypassingBindings(templist);
+ services << newService;
+ d->watchedServicesData.setValueBypassingBindings(services);
d->watchedServicesData.notify();
}
@@ -344,17 +315,16 @@ bool QDBusServiceWatcher::removeWatchedService(const QString &service)
{
Q_D(QDBusServiceWatcher);
d->watchedServicesData.removeBindingUnlessInWrapper();
- d->removeService(service);
- auto tempList = d->watchedServicesData.value();
- bool result = tempList.removeOne(service);
- if (result) {
- d->watchedServicesData.setValueBypassingBindings(tempList);
- d->watchedServicesData.notify();
- return true;
- } else {
- // nothing changed
- return false;
- }
+ auto tempList = d->watchedServicesData.valueBypassingBindings();
+ const bool result = tempList.removeOne(service);
+ if (!result)
+ return false; // nothing changed
+
+ // re-evaluate watch mode
+ d->removeService(service, d->watchMode);
+ d->watchedServicesData.setValueBypassingBindings(tempList);
+ d->watchedServicesData.notify();
+ return true;
}
QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode() const
@@ -371,8 +341,9 @@ void QDBusServiceWatcher::setWatchMode(WatchMode mode)
{
Q_D(QDBusServiceWatcher);
d->watchMode.removeBindingUnlessInWrapper();
- if (mode == d->watchMode.value())
+ if (mode == d->watchMode.valueBypassingBindings())
return;
+ // trigger watchedServicesData re-evaluation, but only once for the setter
d->setConnection(d->watchedServicesData, d->connection, mode);
d->watchMode.notify();
}