Merge lp:~renatofilho/address-book-service/enable-debug into lp:address-book-service

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Bill Filler
Approved revision: 146
Merged at revision: 138
Proposed branch: lp:~renatofilho/address-book-service/enable-debug
Merge into: lp:address-book-service
Diff against target: 344 lines (+139/-10)
9 files modified
contacts/contacts-service.cpp (+1/-0)
lib/addressbook-adaptor.h (+2/-0)
lib/addressbook.cpp (+99/-4)
lib/addressbook.h (+11/-2)
lib/contacts-map.cpp (+5/-0)
lib/contacts-map.h (+2/-0)
lib/dirtycontact-notify.cpp (+6/-0)
lib/dirtycontact-notify.h (+1/-0)
upstart/address-book-service.conf (+12/-4)
To merge this branch: bzr merge lp:~renatofilho/address-book-service/enable-debug
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+233084@code.launchpad.net

Commit message

Enabled folks and service debug by default.
Reload contacts if EDS die.
WORKAROUND: Check for EDS status after start the service and if necessary reload folks.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
138. By Renato Araujo Oliveira Filho

Reload contacts if EDS die.
WORKAROUND: Check for EDS status after start the service and if necessary reload folks.

139. By Renato Araujo Oliveira Filho

Merge parent branch.

140. By Renato Araujo Oliveira Filho

Does not wait 10s to check for eds, check for it just after the service be ready.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
141. By Renato Araujo Oliveira Filho

Disable EDS tracker if FOLKS_BACKENDS_ALLOWED is set without eds.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
142. By Renato Araujo Oliveira Filho

Check if EDS was running already when the service started.
Created a new "reloaded" signal to notify when the service reload all contacts.

143. By Renato Araujo Oliveira Filho

Avoid infinite loop while looking for EDS.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
144. By Renato Araujo Oliveira Filho

Avoid crash during the addressbook service destructor.

Does not use the contacts map if it was already destroyed by previous call of function shutdown.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

It basically works but we should fix the restart logic a bit. Currently it tries 10 times in a row to restart EDS, without any delay. This happens very quickly, probably too quickly.

Instead, you should sleep between each retry with a timer or something. Like try immediately after first failure, then sleep 2 seconds and retry, then sleep 3 seconds and retry, then sleep 4 seconds and retry, etc.. until you've tried 10 times.

review: Needs Fixing
145. By Renato Araujo Oliveira Filho

Wait some ms before reload folks if EDS did not start.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
146. By Renato Araujo Oliveira Filho

Removed folks debug.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/<package-name>) on device or emulator?
yes

Did CI run pass? If not, please explain why.
yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
yes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contacts/contacts-service.cpp'
2--- contacts/contacts-service.cpp 2014-06-26 22:10:02 +0000
3+++ contacts/contacts-service.cpp 2014-09-11 18:57:11 +0000
4@@ -185,6 +185,7 @@
5 if (!m_iface->lastError().isValid()) {
6 m_serviceIsReady = m_iface.data()->property("isReady").toBool();
7 connect(m_iface.data(), SIGNAL(ready()), this, SLOT(onServiceReady()));
8+ connect(m_iface.data(), SIGNAL(reloaded()), this, SIGNAL(serviceChanged()));
9 connect(m_iface.data(), SIGNAL(contactsAdded(QStringList)), this, SLOT(onContactsAdded(QStringList)));
10 connect(m_iface.data(), SIGNAL(contactsRemoved(QStringList)), this, SLOT(onContactsRemoved(QStringList)));
11 connect(m_iface.data(), SIGNAL(contactsUpdated(QStringList)), this, SLOT(onContactsUpdated(QStringList)));
12
13=== modified file 'lib/addressbook-adaptor.h'
14--- lib/addressbook-adaptor.h 2014-04-09 19:45:40 +0000
15+++ lib/addressbook-adaptor.h 2014-09-11 18:57:11 +0000
16@@ -51,6 +51,7 @@
17 " <arg direction=\"out\" type=\"a(ss)\" name=\"errorMap\"/>\n"
18 " </signal>\n"
19 " <signal name=\"ready\"/>\n"
20+" <signal name=\"reloaded\"/>\n"
21 " <method name=\"ping\">\n"
22 " <arg direction=\"out\" type=\"b\"/>\n"
23 " </method>\n"
24@@ -131,6 +132,7 @@
25 void contactsUpdated(const QStringList &ids);
26 void asyncOperationResult(QMap<QString, QString> errors);
27 void ready();
28+ void reloaded();
29
30 private:
31 AddressBook *m_addressBook;
32
33=== modified file 'lib/addressbook.cpp'
34--- lib/addressbook.cpp 2014-08-11 21:20:38 +0000
35+++ lib/addressbook.cpp 2014-09-11 18:57:11 +0000
36@@ -91,9 +91,10 @@
37 AddressBook::AddressBook(QObject *parent)
38 : QObject(parent),
39 m_individualAggregator(0),
40- m_contacts(new ContactsMap),
41+ m_contacts(0),
42 m_adaptor(0),
43 m_notifyContactUpdate(0),
44+ m_edsIsLive(false),
45 m_ready(false),
46 m_individualsChangedDetailedId(0),
47 m_notifyIsQuiescentHandlerId(0),
48@@ -106,6 +107,7 @@
49 m_serviceName = CPIM_SERVICE_NAME;
50 }
51 prepareUnixSignals();
52+ connectWithEDS();
53 }
54
55 AddressBook::~AddressBook()
56@@ -159,6 +161,7 @@
57 prepareFolks();
58 return true;
59 }
60+
61 return false;
62 }
63
64@@ -167,8 +170,18 @@
65 return start(QDBusConnection::sessionBus());
66 }
67
68-void AddressBook::shutdown()
69+void AddressBook::unprepareFolks()
70 {
71+ // remove all contacts
72+ // flusing any pending notification
73+ m_notifyContactUpdate->flush();
74+
75+ // notify about contacts removal
76+ if (m_contacts) {
77+ m_notifyContactUpdate->insertRemovedContacts(m_contacts->keys().toSet());
78+ m_notifyContactUpdate->flush();
79+ }
80+
81 m_ready = false;
82
83 Q_FOREACH(View* view, m_views) {
84@@ -189,6 +202,11 @@
85 m_individualsChangedDetailedId = m_notifyIsQuiescentHandlerId = 0;
86 g_clear_object(&m_individualAggregator);
87 }
88+}
89+
90+void AddressBook::shutdown()
91+{
92+ unprepareFolks();
93
94 if (m_adaptor) {
95 if (m_connection.interface() &&
96@@ -208,6 +226,7 @@
97
98 void AddressBook::prepareFolks()
99 {
100+ m_contacts = new ContactsMap;
101 m_individualAggregator = folks_individual_aggregator_dup();
102 g_object_get(G_OBJECT(m_individualAggregator), "is-quiescent", &m_ready, NULL);
103 if (m_ready) {
104@@ -215,7 +234,7 @@
105 }
106 m_notifyIsQuiescentHandlerId = g_signal_connect(m_individualAggregator,
107 "notify::is-quiescent",
108- (GCallback)AddressBook::isQuiescentChanged,
109+ (GCallback) AddressBook::isQuiescentChanged,
110 this);
111
112 m_individualsChangedDetailedId = g_signal_connect(m_individualAggregator,
113@@ -223,12 +242,45 @@
114 (GCallback) AddressBook::individualsChangedCb,
115 this);
116
117-
118 folks_individual_aggregator_prepare(m_individualAggregator,
119 (GAsyncReadyCallback) AddressBook::prepareFolksDone,
120 this);
121 }
122
123+void AddressBook::connectWithEDS()
124+{
125+ // we need to keep it update with the EDS dbus service name
126+ static const QString evolutionServiceName("org.gnome.evolution.dataserver.AddressBook6");
127+
128+ // Check if eds was disabled manually
129+ // If eds was disabled we should skip the check
130+ if (qEnvironmentVariableIsSet("FOLKS_BACKENDS_ALLOWED")) {
131+ QString allowedBackends = qgetenv("FOLKS_BACKENDS_ALLOWED");
132+ if (!allowedBackends.contains("eds")) {
133+ return;
134+ }
135+ }
136+
137+ // check if service is already registered
138+ // We will try register a EDS service if its fails this mean that the service is already registered
139+ m_edsIsLive = !QDBusConnection::sessionBus().registerService(evolutionServiceName);
140+ if (!m_edsIsLive) {
141+ // if we succeed we need to unregister it
142+ QDBusConnection::sessionBus().unregisterService(evolutionServiceName);
143+ }
144+
145+ m_edsWatcher = new QDBusServiceWatcher(evolutionServiceName,
146+ QDBusConnection::sessionBus(),
147+ QDBusServiceWatcher::WatchForOwnerChange,
148+ this);
149+ connect(m_edsWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
150+ this, SLOT(onEdsServiceOwnerChanged(QString,QString,QString)));
151+
152+
153+ // WORKAROUND: Will ceck for EDS after the service get ready
154+ connect(this, SIGNAL(ready()), SLOT(checkForEds()));
155+}
156+
157 SourceList AddressBook::availableSources(const QDBusMessage &message)
158 {
159 getSource(message, false);
160@@ -606,6 +658,22 @@
161 m_notifyContactUpdate->insertChangedContacts(QSet<QString>() << individual->id());
162 }
163
164+void AddressBook::onEdsServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
165+{
166+ qDebug() << name << oldOwner << newOwner;
167+ if (newOwner.isEmpty()) {
168+ m_edsIsLive = false;
169+ qWarning() << "EDS died: restarting service" << m_individualsChangedDetailedId;
170+ // reset folks objects
171+ unprepareFolks();
172+ prepareFolks();
173+
174+ Q_EMIT m_adaptor->reloaded();
175+ } else {
176+ m_edsIsLive = true;
177+ }
178+}
179+
180 int AddressBook::removeContacts(const QStringList &contactIds, const QDBusMessage &message)
181 {
182 RemoveContactsData *data = new RemoveContactsData;
183@@ -920,4 +988,31 @@
184 m_snQuit->setEnabled(true);
185 }
186
187+// WORKAROUND: For some strange reason sometimes EDS does not start with the service request
188+// we will try to reload folks if this happen
189+void AddressBook::checkForEds()
190+{
191+ // Use maxRetry value to avoid infinite loop
192+ static const int maxRerty = 10;
193+ static int retryCount = 0;
194+ if (retryCount >= maxRerty) {
195+ return;
196+ }
197+ retryCount++;
198+
199+ if (!m_edsIsLive) {
200+ // wait some ms to restart folks, this ms increase 500ms for each retryCount
201+ QTimer::singleShot(500 * retryCount, this, SLOT(reloadFolks()));
202+ qWarning() << "EDS did not start, trying to reload folks;";
203+ } else {
204+ retryCount = 0;
205+ }
206+}
207+
208+void AddressBook::reloadFolks()
209+{
210+ unprepareFolks();
211+ prepareFolks();
212+}
213+
214 } //namespace
215
216=== modified file 'lib/addressbook.h'
217--- lib/addressbook.h 2014-04-09 19:45:40 +0000
218+++ lib/addressbook.h 2014-09-11 18:57:11 +0000
219@@ -80,10 +80,15 @@
220 private Q_SLOTS:
221 void viewClosed();
222 void individualChanged(QIndividual *individual);
223+ void onEdsServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
224
225 // Unix signal handlers.
226 void handleSigQuit();
227
228+ // WORKAROUND: Check if EDS was running when the service started
229+ void checkForEds();
230+ void reloadFolks();
231+
232 private:
233 FolksIndividualAggregator *m_individualAggregator;
234 ContactsMap *m_contacts;
235@@ -91,10 +96,12 @@
236 AddressBookAdaptor *m_adaptor;
237 // timer to avoid send several updates at the same time
238 DirtyContactsNotify *m_notifyContactUpdate;
239+ QDBusServiceWatcher *m_edsWatcher;
240
241+ bool m_edsIsLive;
242 bool m_ready;
243- int m_individualsChangedDetailedId;
244- int m_notifyIsQuiescentHandlerId;
245+ gulong m_individualsChangedDetailedId;
246+ gulong m_notifyIsQuiescentHandlerId;
247 QDBusConnection m_connection;
248
249 // Update command
250@@ -123,6 +130,8 @@
251 static void quitSignalHandler(int unused);
252
253 void prepareFolks();
254+ void unprepareFolks();
255+ void connectWithEDS();
256 bool registerObject(QDBusConnection &connection);
257 QString removeContact(FolksIndividual *individual);
258 QString addContact(FolksIndividual *individual);
259
260=== modified file 'lib/contacts-map.cpp'
261--- lib/contacts-map.cpp 2014-08-11 21:20:38 +0000
262+++ lib/contacts-map.cpp 2014-09-11 18:57:11 +0000
263@@ -158,6 +158,11 @@
264 return m_contacts;
265 }
266
267+QStringList ContactsMap::keys() const
268+{
269+ return m_idToEntry.keys();
270+}
271+
272 void ContactsMap::sertSort(const SortClause &clause)
273 {
274 if (clause.toContactSortOrder() != m_sortClause.toContactSortOrder()) {
275
276=== modified file 'lib/contacts-map.h'
277--- lib/contacts-map.h 2014-08-11 21:20:38 +0000
278+++ lib/contacts-map.h 2014-09-11 18:57:11 +0000
279@@ -75,6 +75,8 @@
280 void lock();
281 void unlock();
282 QList<ContactEntry*> values() const;
283+ QStringList keys() const;
284+
285 void sertSort(const SortClause &clause);
286 SortClause sort() const;
287
288
289=== modified file 'lib/dirtycontact-notify.cpp'
290--- lib/dirtycontact-notify.cpp 2014-06-30 23:30:11 +0000
291+++ lib/dirtycontact-notify.cpp 2014-09-11 18:57:11 +0000
292@@ -54,6 +54,12 @@
293 m_timer.start();
294 }
295
296+void DirtyContactsNotify::flush()
297+{
298+ m_timer.stop();
299+ emitSignals();
300+}
301+
302 void DirtyContactsNotify::insertRemovedContacts(QSet<QString> ids)
303 {
304 if (!m_adaptor->isReady()) {
305
306=== modified file 'lib/dirtycontact-notify.h'
307--- lib/dirtycontact-notify.h 2014-03-27 16:47:09 +0000
308+++ lib/dirtycontact-notify.h 2014-09-11 18:57:11 +0000
309@@ -41,6 +41,7 @@
310 void insertChangedContacts(QSet<QString> ids);
311 void insertRemovedContacts(QSet<QString> ids);
312 void insertAddedContacts(QSet<QString> ids);
313+ void flush();
314
315 private Q_SLOTS:
316 void emitSignals();
317
318=== modified file 'upstart/address-book-service.conf'
319--- upstart/address-book-service.conf 2014-08-19 13:03:47 +0000
320+++ upstart/address-book-service.conf 2014-09-11 18:57:11 +0000
321@@ -1,11 +1,19 @@
322 description "address-book-service"
323 author "Bill Filler <bill.filler@canonical.com>"
324
325-start on started unity8
326-stop on desktop-end
327+start on started dbus and xsession SESSION=ubuntu-touch
328+stop on runlevel [06]
329
330 respawn
331+respawn limit unlimited
332+
333+pre-start script
334+ echo "START `date`"
335+ initctl set-env ADDRESS_BOOK_SERVICE_DEBUG="On"
336+end script
337+
338+post-stop script
339+ echo "STOP `date`"
340+end script
341
342 exec /usr/lib/arm-linux-gnueabihf/address-book-service/address-book-service
343-
344-pre-start exec /usr/lib/evolution/evolution-addressbook-factory

Subscribers

People subscribed via source and target branches