Merge lp:~morphis/ubuntu-system-settings/bt-always-do-async-calls into lp:ubuntu-system-settings

Proposed by Simon Fels on 2015-07-29
Status: Merged
Approved by: Sebastien Bacher on 2015-08-03
Approved revision: 1482
Merged at revision: 1492
Proposed branch: lp:~morphis/ubuntu-system-settings/bt-always-do-async-calls
Merge into: lp:ubuntu-system-settings
Diff against target: 94 lines (+31/-20)
2 files modified
plugins/bluetooth/device.cpp (+29/-19)
plugins/bluetooth/device.h (+2/-1)
To merge this branch: bzr merge lp:~morphis/ubuntu-system-settings/bt-always-do-async-calls
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve on 2015-08-03
Mathieu Trudel-Lapierre 2015-07-29 Approve on 2015-08-03
Review via email: mp+266201@code.launchpad.net

Commit Message

Convert Bluetooth connect/disconnect operations to async ones to not block the UI when the backend takes a little bit longer to perform those.

Description of the Change

Convert Bluetooth connect/disconnect operations to async ones to not block the UI when the backend takes a little bit longer to perform those.

To post a comment you must log in.
Mathieu Trudel-Lapierre (cyphermox) wrote :

This is straightforward and obvious. Provided it has been tested and does not show regression, I see no issues.

review: Approve
Charles Kerr (charlesk) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/bluetooth/device.cpp'
2--- plugins/bluetooth/device.cpp 2015-03-16 13:51:36 +0000
3+++ plugins/bluetooth/device.cpp 2015-07-29 09:54:12 +0000
4@@ -163,24 +163,16 @@
5 }
6 }
7
8-void Device::callInterface(const QSharedPointer<QDBusInterface> &interface, const QString &method)
9+void Device::slotDisconnectDone(QDBusPendingCallWatcher *watcher)
10 {
11- QDBusReply<void> reply;
12- constexpr int maxTries = 4;
13- int retryCount = 0;
14-
15- while (retryCount < maxTries) {
16- reply = interface->call(method);
17- if (reply.isValid())
18- break;
19- QThread::msleep(500);
20- retryCount++;
21- }
22-
23- if (retryCount >= maxTries && !reply.isValid()) {
24- qWarning() << "Could not" << method << "the interface" << interface->interface()
25- << ":" << reply.error().message();
26- }
27+ QDBusPendingReply<void> reply = *watcher;
28+
29+ if (reply.isError()) {
30+ qWarning() << "Could not disconnect device:"
31+ << reply.error().message();
32+ }
33+
34+ watcher->deleteLater();
35 }
36
37 void Device::disconnect(ConnectionMode mode)
38@@ -198,7 +190,22 @@
39 return;
40 }
41
42- callInterface(interface, "Disconnect");
43+ QDBusPendingCall call = interface->asyncCall("Disconnect");
44+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
45+ QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
46+ this, SLOT(slotDisconnectDone(QDBusPendingCallWatcher*)));
47+}
48+
49+void Device::slotConnectDone(QDBusPendingCallWatcher *watcher)
50+{
51+ QDBusPendingReply<void> reply = *watcher;
52+
53+ if (reply.isError()) {
54+ qWarning() << "Could not connect device:"
55+ << reply.error().message();
56+ }
57+
58+ watcher->deleteLater();
59 }
60
61 void Device::connect(ConnectionMode mode)
62@@ -216,7 +223,10 @@
63 return;
64 }
65
66- callInterface(interface, "Connect");
67+ QDBusPendingCall call = interface->asyncCall("Connect");
68+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
69+ QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
70+ this, SLOT(slotConnectDone(QDBusPendingCallWatcher*)));
71 }
72
73 void Device::slotMakeTrustedDone(QDBusPendingCallWatcher *call)
74
75=== modified file 'plugins/bluetooth/device.h'
76--- plugins/bluetooth/device.h 2014-12-05 12:06:33 +0000
77+++ plugins/bluetooth/device.h 2015-07-29 09:54:12 +0000
78@@ -147,7 +147,6 @@
79 Device(const QMap<QString,QVariant> &properties);
80 void initDevice(const QString &path, QDBusConnection &bus);
81 bool isValid() const { return getType() != Type::Other; }
82- void callInterface(const QSharedPointer<QDBusInterface> &interface, const QString &method);
83 void connect(ConnectionMode);
84 void connectPending();
85 void makeTrusted(bool trusted);
86@@ -162,6 +161,8 @@
87 void slotPropertyChanged(const QString &key, const QDBusVariant &value);
88 void slotServiceDiscoveryDone(QDBusPendingCallWatcher *call);
89 void slotMakeTrustedDone(QDBusPendingCallWatcher *call);
90+ void slotConnectDone(QDBusPendingCallWatcher *watcher);
91+ void slotDisconnectDone(QDBusPendingCallWatcher *watcher);
92
93 private:
94 void updateProperties(QSharedPointer<QDBusInterface>);

Subscribers

People subscribed via source and target branches