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
=== modified file 'libunity-2d-private/src/gnomesessionclient.cpp'
--- libunity-2d-private/src/gnomesessionclient.cpp 2011-02-07 21:55:11 +0000
+++ libunity-2d-private/src/gnomesessionclient.cpp 2011-03-22 15:46:34 +0000
@@ -31,12 +31,16 @@
31#include <QDBusInterface>31#include <QDBusInterface>
32#include <QDBusReply>32#include <QDBusReply>
33#include <QDBusPendingCallWatcher>33#include <QDBusPendingCallWatcher>
34#include <QTime>
3435
35static const char* SM_DBUS_SERVICE = "org.gnome.SessionManager";36static const char* SM_DBUS_SERVICE = "org.gnome.SessionManager";
36static const char* SM_DBUS_PATH = "/org/gnome/SessionManager";37static const char* SM_DBUS_PATH = "/org/gnome/SessionManager";
37static const char* SM_DBUS_INTERFACE = "org.gnome.SessionManager";38static const char* SM_DBUS_INTERFACE = "org.gnome.SessionManager";
38static const char* SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate";39static const char* SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate";
3940
41// Number of seconds to wait for gnome-session to call us back
42static const int MAX_END_SESSION_WAIT = 5;
43
40struct GnomeSessionClientPrivate44struct GnomeSessionClientPrivate
41{45{
42 GnomeSessionClientPrivate(const QString& applicationId)46 GnomeSessionClientPrivate(const QString& applicationId)
@@ -45,12 +49,32 @@
4549
46 QString m_applicationId;50 QString m_applicationId;
47 QString m_clientPath;51 QString m_clientPath;
52 bool m_waitingForEndSession;
53
54 bool sendEndSessionResponse()
55 {
56 UQ_DEBUG;
57 QDBusInterface iface(
58 SM_DBUS_SERVICE,
59 m_clientPath,
60 SM_CLIENT_DBUS_INTERFACE);
61 QDBusReply<void> reply = iface.call("EndSessionResponse", /* is_okay= */ true, /* reason= */ "");
62 if (reply.isValid()) {
63 return true;
64 } else {
65 UQ_WARNING << "EndSessionResponse failed:" << reply.error().message();
66 return false;
67 }
68 }
48};69};
4970
50GnomeSessionClient::GnomeSessionClient(const QString& applicationId, QObject* parent)71GnomeSessionClient::GnomeSessionClient(const QString& applicationId, QObject* parent)
51: QObject(parent)72: QObject(parent)
52, d(new GnomeSessionClientPrivate(applicationId))73, d(new GnomeSessionClientPrivate(applicationId))
53{74{
75 d->m_waitingForEndSession = false;
76 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
77 SLOT(waitForEndSession()));
54}78}
5579
56GnomeSessionClient::~GnomeSessionClient()80GnomeSessionClient::~GnomeSessionClient()
@@ -97,25 +121,43 @@
97121
98void GnomeSessionClient::stop()122void GnomeSessionClient::stop()
99{123{
124 UQ_DEBUG;
100 QCoreApplication::quit();125 QCoreApplication::quit();
101}126}
102127
103void GnomeSessionClient::queryEndSession()128void GnomeSessionClient::queryEndSession()
104{129{
105 QDBusInterface iface(130 UQ_DEBUG;
106 SM_DBUS_SERVICE,131 d->m_waitingForEndSession = true;
107 d->m_clientPath,132
108 SM_CLIENT_DBUS_INTERFACE);133 if (!d->sendEndSessionResponse()) {
109 QDBusReply<void> reply = iface.call("EndSessionResponse", /* is_okay= */ true, /* reason= */ "");134 d->m_waitingForEndSession = false;
110 if (!reply.isValid()) {
111 UQ_WARNING << "EndSessionResponse failed:" << reply.error().message();
112 }135 }
113}136}
114137
115void GnomeSessionClient::endSession()138void GnomeSessionClient::endSession()
116{139{
117 queryEndSession();140 UQ_DEBUG;
141 d->sendEndSessionResponse();
142 d->m_waitingForEndSession = false;
118 QCoreApplication::quit();143 QCoreApplication::quit();
119}144}
120145
146void GnomeSessionClient::waitForEndSession()
147{
148 if (!d->m_waitingForEndSession) {
149 return;
150 }
151
152 UQ_DEBUG << "Application is about to quit, waiting for gnome-session to call us back";
153 QTime watchDog;
154 watchDog.start();
155 while (d->m_waitingForEndSession && watchDog.elapsed() < MAX_END_SESSION_WAIT * 1000) {
156 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
157 }
158 if (d->m_waitingForEndSession) {
159 UQ_WARNING << "gnome-session did not call back after" << MAX_END_SESSION_WAIT << "seconds, leaving";
160 }
161}
162
121#include "gnomesessionclient.moc"163#include "gnomesessionclient.moc"
122164
=== modified file 'libunity-2d-private/src/gnomesessionclient.h'
--- libunity-2d-private/src/gnomesessionclient.h 2011-02-07 21:55:11 +0000
+++ libunity-2d-private/src/gnomesessionclient.h 2011-03-22 15:46:34 +0000
@@ -52,6 +52,7 @@
52 void stop();52 void stop();
53 void queryEndSession();53 void queryEndSession();
54 void endSession();54 void endSession();
55 void waitForEndSession();
5556
56private:57private:
57 GnomeSessionClientPrivate* const d;58 GnomeSessionClientPrivate* const d;

Subscribers

People subscribed via source and target branches