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
=== modified file 'contacts/contacts-service.cpp'
--- contacts/contacts-service.cpp 2014-06-26 22:10:02 +0000
+++ contacts/contacts-service.cpp 2014-09-11 18:57:11 +0000
@@ -185,6 +185,7 @@
185 if (!m_iface->lastError().isValid()) {185 if (!m_iface->lastError().isValid()) {
186 m_serviceIsReady = m_iface.data()->property("isReady").toBool();186 m_serviceIsReady = m_iface.data()->property("isReady").toBool();
187 connect(m_iface.data(), SIGNAL(ready()), this, SLOT(onServiceReady()));187 connect(m_iface.data(), SIGNAL(ready()), this, SLOT(onServiceReady()));
188 connect(m_iface.data(), SIGNAL(reloaded()), this, SIGNAL(serviceChanged()));
188 connect(m_iface.data(), SIGNAL(contactsAdded(QStringList)), this, SLOT(onContactsAdded(QStringList)));189 connect(m_iface.data(), SIGNAL(contactsAdded(QStringList)), this, SLOT(onContactsAdded(QStringList)));
189 connect(m_iface.data(), SIGNAL(contactsRemoved(QStringList)), this, SLOT(onContactsRemoved(QStringList)));190 connect(m_iface.data(), SIGNAL(contactsRemoved(QStringList)), this, SLOT(onContactsRemoved(QStringList)));
190 connect(m_iface.data(), SIGNAL(contactsUpdated(QStringList)), this, SLOT(onContactsUpdated(QStringList)));191 connect(m_iface.data(), SIGNAL(contactsUpdated(QStringList)), this, SLOT(onContactsUpdated(QStringList)));
191192
=== modified file 'lib/addressbook-adaptor.h'
--- lib/addressbook-adaptor.h 2014-04-09 19:45:40 +0000
+++ lib/addressbook-adaptor.h 2014-09-11 18:57:11 +0000
@@ -51,6 +51,7 @@
51" <arg direction=\"out\" type=\"a(ss)\" name=\"errorMap\"/>\n"51" <arg direction=\"out\" type=\"a(ss)\" name=\"errorMap\"/>\n"
52" </signal>\n"52" </signal>\n"
53" <signal name=\"ready\"/>\n"53" <signal name=\"ready\"/>\n"
54" <signal name=\"reloaded\"/>\n"
54" <method name=\"ping\">\n"55" <method name=\"ping\">\n"
55" <arg direction=\"out\" type=\"b\"/>\n"56" <arg direction=\"out\" type=\"b\"/>\n"
56" </method>\n"57" </method>\n"
@@ -131,6 +132,7 @@
131 void contactsUpdated(const QStringList &ids);132 void contactsUpdated(const QStringList &ids);
132 void asyncOperationResult(QMap<QString, QString> errors);133 void asyncOperationResult(QMap<QString, QString> errors);
133 void ready();134 void ready();
135 void reloaded();
134136
135private:137private:
136 AddressBook *m_addressBook;138 AddressBook *m_addressBook;
137139
=== modified file 'lib/addressbook.cpp'
--- lib/addressbook.cpp 2014-08-11 21:20:38 +0000
+++ lib/addressbook.cpp 2014-09-11 18:57:11 +0000
@@ -91,9 +91,10 @@
91AddressBook::AddressBook(QObject *parent)91AddressBook::AddressBook(QObject *parent)
92 : QObject(parent),92 : QObject(parent),
93 m_individualAggregator(0),93 m_individualAggregator(0),
94 m_contacts(new ContactsMap),94 m_contacts(0),
95 m_adaptor(0),95 m_adaptor(0),
96 m_notifyContactUpdate(0),96 m_notifyContactUpdate(0),
97 m_edsIsLive(false),
97 m_ready(false),98 m_ready(false),
98 m_individualsChangedDetailedId(0),99 m_individualsChangedDetailedId(0),
99 m_notifyIsQuiescentHandlerId(0),100 m_notifyIsQuiescentHandlerId(0),
@@ -106,6 +107,7 @@
106 m_serviceName = CPIM_SERVICE_NAME;107 m_serviceName = CPIM_SERVICE_NAME;
107 }108 }
108 prepareUnixSignals();109 prepareUnixSignals();
110 connectWithEDS();
109}111}
110112
111AddressBook::~AddressBook()113AddressBook::~AddressBook()
@@ -159,6 +161,7 @@
159 prepareFolks();161 prepareFolks();
160 return true;162 return true;
161 }163 }
164
162 return false;165 return false;
163}166}
164167
@@ -167,8 +170,18 @@
167 return start(QDBusConnection::sessionBus());170 return start(QDBusConnection::sessionBus());
168}171}
169172
170void AddressBook::shutdown()173void AddressBook::unprepareFolks()
171{174{
175 // remove all contacts
176 // flusing any pending notification
177 m_notifyContactUpdate->flush();
178
179 // notify about contacts removal
180 if (m_contacts) {
181 m_notifyContactUpdate->insertRemovedContacts(m_contacts->keys().toSet());
182 m_notifyContactUpdate->flush();
183 }
184
172 m_ready = false;185 m_ready = false;
173186
174 Q_FOREACH(View* view, m_views) {187 Q_FOREACH(View* view, m_views) {
@@ -189,6 +202,11 @@
189 m_individualsChangedDetailedId = m_notifyIsQuiescentHandlerId = 0;202 m_individualsChangedDetailedId = m_notifyIsQuiescentHandlerId = 0;
190 g_clear_object(&m_individualAggregator);203 g_clear_object(&m_individualAggregator);
191 }204 }
205}
206
207void AddressBook::shutdown()
208{
209 unprepareFolks();
192210
193 if (m_adaptor) {211 if (m_adaptor) {
194 if (m_connection.interface() &&212 if (m_connection.interface() &&
@@ -208,6 +226,7 @@
208226
209void AddressBook::prepareFolks()227void AddressBook::prepareFolks()
210{228{
229 m_contacts = new ContactsMap;
211 m_individualAggregator = folks_individual_aggregator_dup();230 m_individualAggregator = folks_individual_aggregator_dup();
212 g_object_get(G_OBJECT(m_individualAggregator), "is-quiescent", &m_ready, NULL);231 g_object_get(G_OBJECT(m_individualAggregator), "is-quiescent", &m_ready, NULL);
213 if (m_ready) {232 if (m_ready) {
@@ -215,7 +234,7 @@
215 }234 }
216 m_notifyIsQuiescentHandlerId = g_signal_connect(m_individualAggregator,235 m_notifyIsQuiescentHandlerId = g_signal_connect(m_individualAggregator,
217 "notify::is-quiescent",236 "notify::is-quiescent",
218 (GCallback)AddressBook::isQuiescentChanged,237 (GCallback) AddressBook::isQuiescentChanged,
219 this);238 this);
220239
221 m_individualsChangedDetailedId = g_signal_connect(m_individualAggregator,240 m_individualsChangedDetailedId = g_signal_connect(m_individualAggregator,
@@ -223,12 +242,45 @@
223 (GCallback) AddressBook::individualsChangedCb,242 (GCallback) AddressBook::individualsChangedCb,
224 this);243 this);
225244
226
227 folks_individual_aggregator_prepare(m_individualAggregator,245 folks_individual_aggregator_prepare(m_individualAggregator,
228 (GAsyncReadyCallback) AddressBook::prepareFolksDone,246 (GAsyncReadyCallback) AddressBook::prepareFolksDone,
229 this);247 this);
230}248}
231249
250void AddressBook::connectWithEDS()
251{
252 // we need to keep it update with the EDS dbus service name
253 static const QString evolutionServiceName("org.gnome.evolution.dataserver.AddressBook6");
254
255 // Check if eds was disabled manually
256 // If eds was disabled we should skip the check
257 if (qEnvironmentVariableIsSet("FOLKS_BACKENDS_ALLOWED")) {
258 QString allowedBackends = qgetenv("FOLKS_BACKENDS_ALLOWED");
259 if (!allowedBackends.contains("eds")) {
260 return;
261 }
262 }
263
264 // check if service is already registered
265 // We will try register a EDS service if its fails this mean that the service is already registered
266 m_edsIsLive = !QDBusConnection::sessionBus().registerService(evolutionServiceName);
267 if (!m_edsIsLive) {
268 // if we succeed we need to unregister it
269 QDBusConnection::sessionBus().unregisterService(evolutionServiceName);
270 }
271
272 m_edsWatcher = new QDBusServiceWatcher(evolutionServiceName,
273 QDBusConnection::sessionBus(),
274 QDBusServiceWatcher::WatchForOwnerChange,
275 this);
276 connect(m_edsWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
277 this, SLOT(onEdsServiceOwnerChanged(QString,QString,QString)));
278
279
280 // WORKAROUND: Will ceck for EDS after the service get ready
281 connect(this, SIGNAL(ready()), SLOT(checkForEds()));
282}
283
232SourceList AddressBook::availableSources(const QDBusMessage &message)284SourceList AddressBook::availableSources(const QDBusMessage &message)
233{285{
234 getSource(message, false);286 getSource(message, false);
@@ -606,6 +658,22 @@
606 m_notifyContactUpdate->insertChangedContacts(QSet<QString>() << individual->id());658 m_notifyContactUpdate->insertChangedContacts(QSet<QString>() << individual->id());
607}659}
608660
661void AddressBook::onEdsServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
662{
663 qDebug() << name << oldOwner << newOwner;
664 if (newOwner.isEmpty()) {
665 m_edsIsLive = false;
666 qWarning() << "EDS died: restarting service" << m_individualsChangedDetailedId;
667 // reset folks objects
668 unprepareFolks();
669 prepareFolks();
670
671 Q_EMIT m_adaptor->reloaded();
672 } else {
673 m_edsIsLive = true;
674 }
675}
676
609int AddressBook::removeContacts(const QStringList &contactIds, const QDBusMessage &message)677int AddressBook::removeContacts(const QStringList &contactIds, const QDBusMessage &message)
610{678{
611 RemoveContactsData *data = new RemoveContactsData;679 RemoveContactsData *data = new RemoveContactsData;
@@ -920,4 +988,31 @@
920 m_snQuit->setEnabled(true);988 m_snQuit->setEnabled(true);
921}989}
922990
991// WORKAROUND: For some strange reason sometimes EDS does not start with the service request
992// we will try to reload folks if this happen
993void AddressBook::checkForEds()
994{
995 // Use maxRetry value to avoid infinite loop
996 static const int maxRerty = 10;
997 static int retryCount = 0;
998 if (retryCount >= maxRerty) {
999 return;
1000 }
1001 retryCount++;
1002
1003 if (!m_edsIsLive) {
1004 // wait some ms to restart folks, this ms increase 500ms for each retryCount
1005 QTimer::singleShot(500 * retryCount, this, SLOT(reloadFolks()));
1006 qWarning() << "EDS did not start, trying to reload folks;";
1007 } else {
1008 retryCount = 0;
1009 }
1010}
1011
1012void AddressBook::reloadFolks()
1013{
1014 unprepareFolks();
1015 prepareFolks();
1016}
1017
923} //namespace1018} //namespace
9241019
=== modified file 'lib/addressbook.h'
--- lib/addressbook.h 2014-04-09 19:45:40 +0000
+++ lib/addressbook.h 2014-09-11 18:57:11 +0000
@@ -80,10 +80,15 @@
80private Q_SLOTS:80private Q_SLOTS:
81 void viewClosed();81 void viewClosed();
82 void individualChanged(QIndividual *individual);82 void individualChanged(QIndividual *individual);
83 void onEdsServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
8384
84 // Unix signal handlers.85 // Unix signal handlers.
85 void handleSigQuit();86 void handleSigQuit();
8687
88 // WORKAROUND: Check if EDS was running when the service started
89 void checkForEds();
90 void reloadFolks();
91
87private:92private:
88 FolksIndividualAggregator *m_individualAggregator;93 FolksIndividualAggregator *m_individualAggregator;
89 ContactsMap *m_contacts;94 ContactsMap *m_contacts;
@@ -91,10 +96,12 @@
91 AddressBookAdaptor *m_adaptor;96 AddressBookAdaptor *m_adaptor;
92 // timer to avoid send several updates at the same time97 // timer to avoid send several updates at the same time
93 DirtyContactsNotify *m_notifyContactUpdate;98 DirtyContactsNotify *m_notifyContactUpdate;
99 QDBusServiceWatcher *m_edsWatcher;
94100
101 bool m_edsIsLive;
95 bool m_ready;102 bool m_ready;
96 int m_individualsChangedDetailedId;103 gulong m_individualsChangedDetailedId;
97 int m_notifyIsQuiescentHandlerId;104 gulong m_notifyIsQuiescentHandlerId;
98 QDBusConnection m_connection;105 QDBusConnection m_connection;
99106
100 // Update command107 // Update command
@@ -123,6 +130,8 @@
123 static void quitSignalHandler(int unused);130 static void quitSignalHandler(int unused);
124131
125 void prepareFolks();132 void prepareFolks();
133 void unprepareFolks();
134 void connectWithEDS();
126 bool registerObject(QDBusConnection &connection);135 bool registerObject(QDBusConnection &connection);
127 QString removeContact(FolksIndividual *individual);136 QString removeContact(FolksIndividual *individual);
128 QString addContact(FolksIndividual *individual);137 QString addContact(FolksIndividual *individual);
129138
=== modified file 'lib/contacts-map.cpp'
--- lib/contacts-map.cpp 2014-08-11 21:20:38 +0000
+++ lib/contacts-map.cpp 2014-09-11 18:57:11 +0000
@@ -158,6 +158,11 @@
158 return m_contacts;158 return m_contacts;
159}159}
160160
161QStringList ContactsMap::keys() const
162{
163 return m_idToEntry.keys();
164}
165
161void ContactsMap::sertSort(const SortClause &clause)166void ContactsMap::sertSort(const SortClause &clause)
162{167{
163 if (clause.toContactSortOrder() != m_sortClause.toContactSortOrder()) {168 if (clause.toContactSortOrder() != m_sortClause.toContactSortOrder()) {
164169
=== modified file 'lib/contacts-map.h'
--- lib/contacts-map.h 2014-08-11 21:20:38 +0000
+++ lib/contacts-map.h 2014-09-11 18:57:11 +0000
@@ -75,6 +75,8 @@
75 void lock();75 void lock();
76 void unlock();76 void unlock();
77 QList<ContactEntry*> values() const;77 QList<ContactEntry*> values() const;
78 QStringList keys() const;
79
78 void sertSort(const SortClause &clause);80 void sertSort(const SortClause &clause);
79 SortClause sort() const;81 SortClause sort() const;
8082
8183
=== modified file 'lib/dirtycontact-notify.cpp'
--- lib/dirtycontact-notify.cpp 2014-06-30 23:30:11 +0000
+++ lib/dirtycontact-notify.cpp 2014-09-11 18:57:11 +0000
@@ -54,6 +54,12 @@
54 m_timer.start();54 m_timer.start();
55}55}
5656
57void DirtyContactsNotify::flush()
58{
59 m_timer.stop();
60 emitSignals();
61}
62
57void DirtyContactsNotify::insertRemovedContacts(QSet<QString> ids)63void DirtyContactsNotify::insertRemovedContacts(QSet<QString> ids)
58{64{
59 if (!m_adaptor->isReady()) {65 if (!m_adaptor->isReady()) {
6066
=== modified file 'lib/dirtycontact-notify.h'
--- lib/dirtycontact-notify.h 2014-03-27 16:47:09 +0000
+++ lib/dirtycontact-notify.h 2014-09-11 18:57:11 +0000
@@ -41,6 +41,7 @@
41 void insertChangedContacts(QSet<QString> ids);41 void insertChangedContacts(QSet<QString> ids);
42 void insertRemovedContacts(QSet<QString> ids);42 void insertRemovedContacts(QSet<QString> ids);
43 void insertAddedContacts(QSet<QString> ids);43 void insertAddedContacts(QSet<QString> ids);
44 void flush();
4445
45private Q_SLOTS:46private Q_SLOTS:
46 void emitSignals();47 void emitSignals();
4748
=== modified file 'upstart/address-book-service.conf'
--- upstart/address-book-service.conf 2014-08-19 13:03:47 +0000
+++ upstart/address-book-service.conf 2014-09-11 18:57:11 +0000
@@ -1,11 +1,19 @@
1description "address-book-service"1description "address-book-service"
2author "Bill Filler <bill.filler@canonical.com>"2author "Bill Filler <bill.filler@canonical.com>"
33
4start on started unity84start on started dbus and xsession SESSION=ubuntu-touch
5stop on desktop-end5stop on runlevel [06]
66
7respawn7respawn
8respawn limit unlimited
9
10pre-start script
11 echo "START `date`"
12 initctl set-env ADDRESS_BOOK_SERVICE_DEBUG="On"
13end script
14
15post-stop script
16 echo "STOP `date`"
17end script
818
9exec /usr/lib/arm-linux-gnueabihf/address-book-service/address-book-service19exec /usr/lib/arm-linux-gnueabihf/address-book-service/address-book-service
10
11pre-start exec /usr/lib/evolution/evolution-addressbook-factory

Subscribers

People subscribed via source and target branches