on xenial help sign in
Replace QDBusInterface with a non-blocking simplification which does not introspect the service on creation
5a7139eGerry Boland
src/libunity8-private/abstractdbusservicemonitor.cpp+17−3
@@ -25,6 +25,20 @@
25#include <QDBusConnectionInterface>
25#include <QDBusConnectionInterface>
26#include <QDBusReply>
26#include <QDBusReply>
27
27
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+
28AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(const QString &service, const QString &path,
42AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(const QString &service, const QString &path,
29 const QString &interface, const Bus bus,
43 const QString &interface, const Bus bus,
30 QObject *parent)
44 QObject *parent)
@@ -61,8 +75,8 @@ void AbstractDBusServiceMonitor::createInterface(const QString &)
61 m_dbusInterface = nullptr;
75 m_dbusInterface = nullptr;
62 }
76 }
63
77
64− m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
78+ m_dbusInterface = new AsyncDBusInterface(m_service, m_path, m_interface,
65− QDBusConnection::sessionBus());
79+ QDBusConnection::sessionBus());
66 Q_EMIT serviceAvailableChanged(true);
80 Q_EMIT serviceAvailableChanged(true);
67}
81}
68
82
@@ -76,7 +90,7 @@ void AbstractDBusServiceMonitor::destroyInterface(const QString &)
76 Q_EMIT serviceAvailableChanged(false);
90 Q_EMIT serviceAvailableChanged(false);
77}
91}
78
92
79−QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const
93+QDBusAbstractInterface* AbstractDBusServiceMonitor::dbusInterface() const
80{
94{
81 return m_dbusInterface;
95 return m_dbusInterface;
82}
96}
src/libunity8-private/abstractdbusservicemonitor.h+3−3
@@ -24,7 +24,7 @@
24#include <QString>
24#include <QString>
25#include <QDBusConnection>
25#include <QDBusConnection>
26
26
27−class QDBusInterface;
27+class QDBusAbstractInterface;
28class QDBusServiceWatcher;
28class QDBusServiceWatcher;
29
29
30class Q_DECL_EXPORT AbstractDBusServiceMonitor : public QObject
30class Q_DECL_EXPORT AbstractDBusServiceMonitor : public QObject
@@ -44,7 +44,7 @@ public:
44 QObject *parent = 0);
44 QObject *parent = 0);
45 ~AbstractDBusServiceMonitor();
45 ~AbstractDBusServiceMonitor();
46
46
47− QDBusInterface* dbusInterface() const;
47+ QDBusAbstractInterface* dbusInterface() const;
48
48
49 bool serviceAvailable() const;
49 bool serviceAvailable() const;
50
50
@@ -60,7 +60,7 @@ protected:
60 const QString m_path;
60 const QString m_path;
61 const QString m_interface;
61 const QString m_interface;
62 QDBusServiceWatcher* m_watcher;
62 QDBusServiceWatcher* m_watcher;
63− QDBusInterface* m_dbusInterface;
63+ QDBusAbstractInterface* m_dbusInterface;
64};
64};
65
65
66#endif // ABSTRACTDBUSSERVICEMONITOR_H
66#endif // ABSTRACTDBUSSERVICEMONITOR_H