Merge lp:~agateau/unity-2d/wait-for-end-session into lp:unity-2d/3.0

Proposed by Aurélien Gâteau
Status: Merged
Approved by: Aurélien Gâteau
Approved revision: 468
Merged at revision: 474
Proposed branch: lp:~agateau/unity-2d/wait-for-end-session
Merge into: lp:unity-2d/3.0
Diff against target: 117 lines (+51/-8)
2 files modified
libunity-2d-private/src/gnomesessionclient.cpp (+50/-8)
libunity-2d-private/src/gnomesessionclient.h (+1/-0)
To merge this branch: bzr merge lp:~agateau/unity-2d/wait-for-end-session
Reviewer Review Type Date Requested Status
Aurélien Gâteau (community) Approve
Bill Filler (community) Needs Fixing
Review via email: mp+54320@code.launchpad.net

Commit message

[session] Avoid long delays on logout

Make sure we wait for gnome-session to call us back before we leave the event-loop.

Description of the change

Avoid long delays on logout

Make sure we wait for gnome-session to call us back before we leave the event-loop.

To post a comment you must log in.
Revision history for this message
Bill Filler (bfiller) wrote :

tested and works great. I just made a couple of slight changes that you should consider:
See my branch here for diff
lp:~bfiller/unity-2d/wait-for-end-session

1) in queryEndSession() I set m_waitingForEndSession = true as the first thing and only set it to false if an error occurs sending the response.

2) in endSession() don't set the m_waitingForEndSession = false until after we send response

after merging these changes it's good to go unless you have comments

review: Needs Fixing
Revision history for this message
Bob The Builder (bobthebuilder-deactivatedaccount) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Aurélien Gâteau (agateau) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/gnomesessionclient.cpp'
2--- libunity-2d-private/src/gnomesessionclient.cpp 2011-02-07 21:55:11 +0000
3+++ libunity-2d-private/src/gnomesessionclient.cpp 2011-03-22 15:46:34 +0000
4@@ -31,12 +31,16 @@
5 #include <QDBusInterface>
6 #include <QDBusReply>
7 #include <QDBusPendingCallWatcher>
8+#include <QTime>
9
10 static const char* SM_DBUS_SERVICE = "org.gnome.SessionManager";
11 static const char* SM_DBUS_PATH = "/org/gnome/SessionManager";
12 static const char* SM_DBUS_INTERFACE = "org.gnome.SessionManager";
13 static const char* SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate";
14
15+// Number of seconds to wait for gnome-session to call us back
16+static const int MAX_END_SESSION_WAIT = 5;
17+
18 struct GnomeSessionClientPrivate
19 {
20 GnomeSessionClientPrivate(const QString& applicationId)
21@@ -45,12 +49,32 @@
22
23 QString m_applicationId;
24 QString m_clientPath;
25+ bool m_waitingForEndSession;
26+
27+ bool sendEndSessionResponse()
28+ {
29+ UQ_DEBUG;
30+ QDBusInterface iface(
31+ SM_DBUS_SERVICE,
32+ m_clientPath,
33+ SM_CLIENT_DBUS_INTERFACE);
34+ QDBusReply<void> reply = iface.call("EndSessionResponse", /* is_okay= */ true, /* reason= */ "");
35+ if (reply.isValid()) {
36+ return true;
37+ } else {
38+ UQ_WARNING << "EndSessionResponse failed:" << reply.error().message();
39+ return false;
40+ }
41+ }
42 };
43
44 GnomeSessionClient::GnomeSessionClient(const QString& applicationId, QObject* parent)
45 : QObject(parent)
46 , d(new GnomeSessionClientPrivate(applicationId))
47 {
48+ d->m_waitingForEndSession = false;
49+ connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
50+ SLOT(waitForEndSession()));
51 }
52
53 GnomeSessionClient::~GnomeSessionClient()
54@@ -97,25 +121,43 @@
55
56 void GnomeSessionClient::stop()
57 {
58+ UQ_DEBUG;
59 QCoreApplication::quit();
60 }
61
62 void GnomeSessionClient::queryEndSession()
63 {
64- QDBusInterface iface(
65- SM_DBUS_SERVICE,
66- d->m_clientPath,
67- SM_CLIENT_DBUS_INTERFACE);
68- QDBusReply<void> reply = iface.call("EndSessionResponse", /* is_okay= */ true, /* reason= */ "");
69- if (!reply.isValid()) {
70- UQ_WARNING << "EndSessionResponse failed:" << reply.error().message();
71+ UQ_DEBUG;
72+ d->m_waitingForEndSession = true;
73+
74+ if (!d->sendEndSessionResponse()) {
75+ d->m_waitingForEndSession = false;
76 }
77 }
78
79 void GnomeSessionClient::endSession()
80 {
81- queryEndSession();
82+ UQ_DEBUG;
83+ d->sendEndSessionResponse();
84+ d->m_waitingForEndSession = false;
85 QCoreApplication::quit();
86 }
87
88+void GnomeSessionClient::waitForEndSession()
89+{
90+ if (!d->m_waitingForEndSession) {
91+ return;
92+ }
93+
94+ UQ_DEBUG << "Application is about to quit, waiting for gnome-session to call us back";
95+ QTime watchDog;
96+ watchDog.start();
97+ while (d->m_waitingForEndSession && watchDog.elapsed() < MAX_END_SESSION_WAIT * 1000) {
98+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
99+ }
100+ if (d->m_waitingForEndSession) {
101+ UQ_WARNING << "gnome-session did not call back after" << MAX_END_SESSION_WAIT << "seconds, leaving";
102+ }
103+}
104+
105 #include "gnomesessionclient.moc"
106
107=== modified file 'libunity-2d-private/src/gnomesessionclient.h'
108--- libunity-2d-private/src/gnomesessionclient.h 2011-02-07 21:55:11 +0000
109+++ libunity-2d-private/src/gnomesessionclient.h 2011-03-22 15:46:34 +0000
110@@ -52,6 +52,7 @@
111 void stop();
112 void queryEndSession();
113 void endSession();
114+ void waitForEndSession();
115
116 private:
117 GnomeSessionClientPrivate* const d;

Subscribers

People subscribed via source and target branches