Merge lp:~ralsina/ubuntu-push-qml/async-rtm into lp:ubuntu-push-qml/rtm

Proposed by Roberto Alsina
Status: Merged
Approved by: Roberto Alsina
Approved revision: 13
Merged at revision: 12
Proposed branch: lp:~ralsina/ubuntu-push-qml/async-rtm
Merge into: lp:ubuntu-push-qml/rtm
Diff against target: 170 lines (+72/-28)
2 files modified
src/Ubuntu/PushNotifications/pushclient.cpp (+64/-28)
src/Ubuntu/PushNotifications/pushclient.h (+8/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntu-push-qml/async-rtm
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Review via email: mp+244591@code.launchpad.net

Commit message

Make registration async

Description of the change

Make registration async

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve
13. By Roberto Alsina

link bug

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Ubuntu/PushNotifications/pushclient.cpp'
--- src/Ubuntu/PushNotifications/pushclient.cpp 2014-10-23 19:15:41 +0000
+++ src/Ubuntu/PushNotifications/pushclient.cpp 2014-12-12 14:29:37 +0000
@@ -18,6 +18,8 @@
18#include "pushclient.h"18#include "pushclient.h"
19#include <QtDBus/QDBusConnection>19#include <QtDBus/QDBusConnection>
20#include <QtDBus/QDBusMessage>20#include <QtDBus/QDBusMessage>
21#include <QtDBus/QDBusPendingCall>
22#include <QtDBus/QDBusPendingReply>
21#include <QTimer>23#include <QTimer>
2224
23#define PUSH_SERVICE "com.ubuntu.PushNotifications"25#define PUSH_SERVICE "com.ubuntu.PushNotifications"
@@ -50,24 +52,31 @@
50 // Register to the push client52 // Register to the push client
51 QDBusMessage message = QDBusMessage::createMethodCall(PUSH_SERVICE, register_path , PUSH_IFACE, "Register");53 QDBusMessage message = QDBusMessage::createMethodCall(PUSH_SERVICE, register_path , PUSH_IFACE, "Register");
52 message << appId;54 message << appId;
53 QDBusMessage token = bus.call(message);55 QDBusPendingCall pcall = bus.asyncCall(message);
54 if (token.type() == QDBusMessage::ErrorMessage) {56 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
55 status = token.errorMessage();57 QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
56 emit statusChanged(status);58 this, SLOT(registerFinished(QDBusPendingCallWatcher*)));
57 // This has to be delayed because the error signal is not connected yet
58 QTimer::singleShot(200, this, SLOT(emitError()));
59 return;
60 }
61 this->token = token.arguments()[0].toStringList()[0];
6259
63 // Connect to the notification signal60 // Connect to the notification signal
64 QString postal_path(POSTAL_PATH);61 QString postal_path(POSTAL_PATH);
65 postal_path += "/" + pkgname;62 postal_path += "/" + pkgname;
66 bus.connect(POSTAL_SERVICE, postal_path, POSTAL_IFACE, "Post", "s", this, SLOT(notified(QString)));63 bus.connect(POSTAL_SERVICE, postal_path, POSTAL_IFACE, "Post", "s", this, SLOT(notified(QString)));
64}
6765
68 // Do an initial fetch66void PushClient::registerFinished(QDBusPendingCallWatcher *watcher) {
69 QTimer::singleShot(200, this, SLOT(getNotifications()));67 QDBusPendingReply<QString> reply = *watcher;
70 emit tokenChanged(this->token);68 if (reply.isError()) {
69 status = reply.error().message();
70 emit statusChanged(status);
71 // This has to be delayed because the error signal is not connected yet
72 QTimer::singleShot(200, this, SLOT(emitError()));
73 }
74 else {
75 this->token = reply.value();
76 // Do an initial fetch
77 QTimer::singleShot(200, this, SLOT(getNotifications()));
78 emit tokenChanged(this->token);
79 }
71}80}
7281
73QString PushClient::getAppId() {82QString PushClient::getAppId() {
@@ -90,20 +99,28 @@
9099
91void PushClient::getNotifications() {100void PushClient::getNotifications() {
92 QDBusConnection bus = QDBusConnection::sessionBus();101 QDBusConnection bus = QDBusConnection::sessionBus();
93
94 // FIXME: make async using http://qt-project.org/doc/qt-4.8/qdbusconnection.html#asyncCall
95 QString path(POSTAL_PATH);102 QString path(POSTAL_PATH);
96 path += "/" + pkgname;103 path += "/" + pkgname;
97 QDBusMessage message = QDBusMessage::createMethodCall(POSTAL_SERVICE, path, POSTAL_IFACE, "PopAll");104 QDBusMessage message = QDBusMessage::createMethodCall(POSTAL_SERVICE, path, POSTAL_IFACE, "PopAll");
98 message << this->appId;105 message << this->appId;
99 QDBusMessage reply = bus.call(message);106 QDBusPendingCall pcall = bus.asyncCall(message);
100 if (reply.type() == QDBusMessage::ErrorMessage) {107 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
101 emit error(reply.errorMessage());108 QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
102 }109 this, SLOT(popAllFinished(QDBusPendingCallWatcher*)));
103 emit notificationsChanged(reply.arguments()[0].toStringList());110}
111
112void PushClient::popAllFinished(QDBusPendingCallWatcher *watcher) {
113 QDBusPendingReply<QStringList> reply = *watcher;
114 if (reply.isError()) {
115 emit error(reply.error().message());
116 }
117 else {
118 emit notificationsChanged(reply.value());
119 }
104}120}
105121
106QStringList PushClient::getPersistent() {122QStringList PushClient::getPersistent() {
123 // FIXME: this is blocking, but making it async would change the API
107 QDBusConnection bus = QDBusConnection::sessionBus();124 QDBusConnection bus = QDBusConnection::sessionBus();
108 QString path(POSTAL_PATH);125 QString path(POSTAL_PATH);
109 path += "/" + pkgname;126 path += "/" + pkgname;
@@ -125,11 +142,21 @@
125 for (int i = 0; i < tags.size(); ++i) {142 for (int i = 0; i < tags.size(); ++i) {
126 message << tags.at(i);143 message << tags.at(i);
127 }144 }
128 QDBusMessage reply = bus.call(message);145 QDBusPendingCall pcall = bus.asyncCall(message);
129 if (reply.type() == QDBusMessage::ErrorMessage) {146 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
130 emit error(reply.errorMessage());147 QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
148 this, SLOT(clearPersistentFinished(QDBusPendingCallWatcher*)));
149}
150
151void PushClient::clearPersistentFinished(QDBusPendingCallWatcher *watcher) {
152 QDBusPendingReply<void> reply = *watcher;
153
154 if (reply.isError()) {
155 emit error(reply.error().message());
156 } else {
157 // FIXME: this is blocking
158 emit persistentChanged(getPersistent());
131 }159 }
132 emit persistentChanged(getPersistent());
133}160}
134161
135void PushClient::setCount(int count) {162void PushClient::setCount(int count) {
@@ -140,11 +167,20 @@
140 path += "/" + pkgname;167 path += "/" + pkgname;
141 QDBusMessage message = QDBusMessage::createMethodCall(POSTAL_SERVICE, path, POSTAL_IFACE, "setCounter");168 QDBusMessage message = QDBusMessage::createMethodCall(POSTAL_SERVICE, path, POSTAL_IFACE, "setCounter");
142 message << this->appId << count << visible;169 message << this->appId << count << visible;
143 QDBusMessage reply = bus.call(message);170 QDBusPendingCall pcall = bus.asyncCall(message);
144 if (reply.type() == QDBusMessage::ErrorMessage) {171 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
145 emit error(reply.errorMessage());172 QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
146 }173 this, SLOT(setCounterFinished(QDBusPendingCallWatcher*)));
147 emit countChanged(counter);174}
175
176void PushClient::setCounterFinished(QDBusPendingCallWatcher *watcher) {
177 QDBusPendingReply<void> reply = *watcher;
178 if (reply.isError()) {
179 emit error(reply.error().message());
180 }
181 else {
182 emit countChanged(counter);
183 }
148}184}
149185
150int PushClient::getCount() {186int PushClient::getCount() {
151187
=== modified file 'src/Ubuntu/PushNotifications/pushclient.h'
--- src/Ubuntu/PushNotifications/pushclient.h 2014-09-05 12:33:24 +0000
+++ src/Ubuntu/PushNotifications/pushclient.h 2014-12-12 14:29:37 +0000
@@ -22,6 +22,8 @@
22#include <QString>22#include <QString>
23#include <QStringList>23#include <QStringList>
2424
25class QDBusPendingCallWatcher;
26
25class PushClient : public QObject27class PushClient : public QObject
26{28{
27 Q_OBJECT29 Q_OBJECT
@@ -57,6 +59,12 @@
57 void emitError();59 void emitError();
58 void clearPersistent(QStringList tags);60 void clearPersistent(QStringList tags);
5961
62private slots:
63 void registerFinished(QDBusPendingCallWatcher *watcher);
64 void popAllFinished(QDBusPendingCallWatcher *watcher);
65 void setCounterFinished(QDBusPendingCallWatcher *watcher);
66 void clearPersistentFinished(QDBusPendingCallWatcher *watcher);
67
60private:68private:
61 QString appId;69 QString appId;
62 QString pkgname;70 QString pkgname;

Subscribers

People subscribed via source and target branches