on xenial help sign in
Replace QDBusInterface with a non-blocking simplification which does not introspect the service on creation
commit5a7139ef60d3be37d8839563f3a8be251f240fb8 authorGerry Boland <gerry.boland@canonical.com> dateTue 16 Dec 2014, 17:47 (12 years ago) parent621ea5f
2 files changed+20−6
src/libunity8-private/abstractdbusservicemonitor.cpp+17−3 src/libunity8-private/abstractdbusservicemonitor.h+3−3
src/libunity8-private/abstractdbusservicemonitor.cpp+17−3
@@ -25,6 +25,20 @@
2525#include <QDBusConnectionInterface>
2626#include <QDBusReply>
2727
28+// On construction QDBusInterface synchronously introspects the service, which will block the GUI
29+// thread if the service is busy. QDBusAbstractInterface does not perform this introspection, so
30+// let's subclass that and avoid the blocking scenario.
31+class AsyncDBusInterface : public QDBusAbstractInterface
32+{
33+public:
34+ AsyncDBusInterface(const QString &service, const QString &path,
35+ const QString &interface, const QDBusConnection &connection,
36+ QObject *parent = 0)
37+ : QDBusAbstractInterface(service, path, interface.toLatin1().data(), connection, parent)
38+ {}
39+ ~AsyncDBusInterface() = default;
40+};
41+
2842AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(const QString &service, const QString &path,
2943 const QString &interface, const Bus bus,
3044 QObject *parent)
@@ -61,8 +75,8 @@ void AbstractDBusServiceMonitor::createInterface(const QString &)
6175 m_dbusInterface = nullptr;
6276 }
6377
64− m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
65− QDBusConnection::sessionBus());
78+ m_dbusInterface = new AsyncDBusInterface(m_service, m_path, m_interface,
79+ QDBusConnection::sessionBus());
6680 Q_EMIT serviceAvailableChanged(true);
6781}
6882
@@ -76,7 +90,7 @@ void AbstractDBusServiceMonitor::destroyInterface(const QString &)
7690 Q_EMIT serviceAvailableChanged(false);
7791}
7892
79−QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const
93+QDBusAbstractInterface* AbstractDBusServiceMonitor::dbusInterface() const
8094{
8195 return m_dbusInterface;
8296}
src/libunity8-private/abstractdbusservicemonitor.h+3−3
@@ -24,7 +24,7 @@
2424#include <QString>
2525#include <QDBusConnection>
2626
27−class QDBusInterface;
27+class QDBusAbstractInterface;
2828class QDBusServiceWatcher;
2929
3030class Q_DECL_EXPORT AbstractDBusServiceMonitor : public QObject
@@ -44,7 +44,7 @@ public:
4444 QObject *parent = 0);
4545 ~AbstractDBusServiceMonitor();
4646
47− QDBusInterface* dbusInterface() const;
47+ QDBusAbstractInterface* dbusInterface() const;
4848
4949 bool serviceAvailable() const;
5050
@@ -60,7 +60,7 @@ protected:
6060 const QString m_path;
6161 const QString m_interface;
6262 QDBusServiceWatcher* m_watcher;
63− QDBusInterface* m_dbusInterface;
63+ QDBusAbstractInterface* m_dbusInterface;
6464};
6565
6666#endif // ABSTRACTDBUSSERVICEMONITOR_H