1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - Session Management</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style></head><body bgcolor="#ffffff">
<p>
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center> Session Management</h1><br clear="all">
<h2> Definitions </h2>
<p>
A <em>session</em> is a group of applications running, each of which has a
particular state. The session is controlled by a service called the <em>session</em> <em>manager.</em> The applications participating in the session are
called <em>session</em> <em>clients.</em>
<p>
The session manager issues commands to its clients on behalf of the
user. These commands may cause clients to commit unsaved changes (for
example by saving open files), to preserve their state for future
sessions or to terminate gracefully. The set of these operations is
called <em>session</em> <em>management.</em>
<p>
In the common case, a session consists of all applications that a
user runs on his desktop at a time. Under Unix/X11, however, a
session may as well run on different computers, span multiple displays
or just consists of a few applications.
<p>
<h2> Shutting a session down </h2>
<p>
A session is shut down by the session manager, usually on behalf of
the user when she wants to log out. A system might, however, also
perform an automatic shutdown in an emergency case, when for example
the power is about to be lost. Clearly there is one big difference
between both shutdowns. During the first, the user may want to
interact with the application, telling exactly which files should be
saved and which should be discarded. In the latter case, there's no
time for interaction. There may not even be a user sitting in front of
the machine!
<p>
<h2> Protocols and support on different platforms</h2>
<p>
On MS-Windows, there is nothing like complete session management for
applications yet, i.e. no restoring of previous sessions. Windows does,
however, support graceful logouts where applications have the chance
to cancel the process after getting confirmation from the user. This
is the functionality that corresponds to the
<a href="qapplication.html#6163c1">QApplication::commitData()</a> method.
<p>
X11 on the other hand supports complete session management since
X11R6. Within the life-time of Qt-2.0, virtually all popular Unix/X11
desktops will very likely support the XConsortium standard.
<p>
<h2> Getting session management to work with Qt </h2>
<p>
In any case you should reimplement <a href="qapplication.html#6163c1">QApplication::commitData()</a> to
enable your application to take part in the graceful logout process. If
you target the MS-Windows platform only, this is all you can and have
to provide. Ideally, your application should provide a shutdown dialog
similar to the following one:
<p>
<center><img src="session.png" alt="A typical dialog on
shutdown"></center>
<p>
Example code to this dialog can be found in the documentation of <a href="qsessionmanager.html#25f903">QSessionManager::allowsInteraction()</a>.
<p>
For complete session management yet only supported on X11R6, you also
have to take care of saving the state of the application and
potentially restore the state in the next life cycle of the session.
This saving is done by reimplementing <a href="qapplication.html#437e1b">QApplication::saveState()</a>. All state data you are saving in this
function, shall be marked with the session identifier <a href="qapplication.html#a6fd61">QApplication::sessionId()</a>. This application specific identifier is
globally unique, so no clashes will happen.
<p>
Restauration is usually done in the application's main()
function. Check if <a href="qapplication.html#aa8893">QApplication::isSessionRestored()</a> is <code>TRUE.</code> If
that's the case, use the session identifier <a href="qapplication.html#a6fd61">QApplication::sessionId()</a> again to access your state date and restore
the state of the application.
<p>
<strong>Important:</strong> In order to allow the window manager to
restore window attributes such as stacking order or geometry
information, you have to identify your toplevel widgets with an
application-wide unique object name (see <a href="qobject.html#ceac81">QObject::setName()</a> ). When
restoring the application, you'll have to ensure that all restored
toplevel widgets end up with their prior object name again.
<p>
<h2> Testing and debugging session management </h2>
<p>
As mentioned earlier, session management support on Windows is fairly
limited due to the lack of this functionality in the Windows operating
system itself. Simply shut the session down and verify that your
application behaves as wanted. It may be a good idea to launch another
application, usually the integrated development environment, before
starting your application. This other application will get the
shutdown message afterwards, thus permitting you to cancel the
shutdown. Otherwise you would have to log in again after each test
run, which is not a problem per se but time consuming.
<p>
On Unix you can either use a desktop environment that supports
standard X11R6 session management or, the recommended method, use the
session manager reference implementation provided by the X Consortium.
This sample manager is dubbed <code>xsm</code> and is part of a standard X11R6
installation. As always with X11, a useful and informative manual page
is provided. Using <code>xsm</code> is straightforward (apart from the clumsy
Athena-based user interface). Here's a simple approach:
<p>
<ul>
<li> Run X11R6.
<li> Create a dot file <code>.xsmstartup</code> in your home directory which
contains the single line
<p>
<pre>xterm
</pre>
<p>
This tells <code>xsm</code> that the default/failsafe session is just an xterm
and nothing else. Otherwise <code>xsm</code> would try to invoke lots of
clients including the windowmanager <code>twm,</code> which isn't very helpful.
<li> Now launch <code>xsm</code> from another terminal window. Both a session
manager window and the xterm will appear. The xterm has a nice
property that sets it apart from all the other shells you are
currently running: Within its shell, the <code>SESSION_MANAGER</code>
environment variable points to the session manager you just started.
<li> Launch your application from the new xterm window. It will
connect itself automatically to the session manager. You can check
with the <em>ClientList</em> push button whether the connect was successful.<br>
<strong>Note:</strong> Never keep the <em>ClientList</em> open when you
start or end session managed clients! Otherwise <code>xsm</code> is likely to
crash.
<li> Use the session manager's <em>Checkpoint</em> and <em>Shutdown</em> buttons
with different settings and see how your application behaves. The save
type <em>local</em> means that the clients should save their state. It
corresponds to the <a href="qapplication.html#437e1b">QApplication::saveState()</a> function. The <em>global</em> save type asks application to save their unsaved changes in the
permanent, globally accessible storage. It invokes <a href="qapplication.html#6163c1">QApplication::commitData()</a>, respectively.
<li> Whenever something crashes, blame <code>xsm</code> and not Qt. <code>xsm</code> is far
from being a usable session manager on a user's desktop. It is,
however, stable and useful enough to serve as testing environment.
</ul>
<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|