Session Management

Qt 5.3
Session Management Qt 5.3.2 Reference Documentation
Contents
Shutting a Session Down
Protocols and Support on Different Platforms
Getting Session Management to Work with Qt
Testing and Debugging Session Management
Session Management
A session is a group of running applications, each of which has a particular state. The session is controlled by a service called the session manager. The applications participating in the session are called session clients.

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 session management.

In the common case, a session consists of all applications that a user runs on their desktop at a time. Under Unix/X11, however, a session may include applications running on different computers and may span multiple displays.

Shutting a Session Down

A session is shut down by the session manager, usually on behalf of the user when they want to log out. A system might also perform an automatic shutdown in an emergency situation, for example, if power is about to be lost. Clearly there is a significant difference between these types of shutdown. During the first, the user may want to interact with the application, specifying 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!

Protocols and Support on Different Platforms

On Mac OS X, and Microsoft Windows versions prior to Windows 2000, there is nothing like complete session management for applications yet, i.e. no restoring of previous sessions. (Windows 2000 and XP provide "hibernation" where the entire memory is saved to disk and restored when the machine is restarted.) They do support graceful logouts where applications have the opportunity to cancel the process after getting confirmation from the user. This is the functionality that corresponds to the QApplication::commitData() method.

X11 has supported complete session management since X11R6.

Getting Session Management to Work with Qt

Start by reimplementing QApplication::commitData() to enable your application to take part in the graceful logout process. If you are only targeting the Microsoft Windows platform, this is all you can and must provide. Ideally, your application should provide a shutdown dialog similar to the following:

A typical dialog on shutdown

Example code for this dialog can be found in the documentation of QSessionManager::allowsInteraction().

For complete session management (only supported on X11R6 at present), you must also take care of saving the application‘s state, and potentially of restoring the state in the next life cycle of the session. This saving is done by reimplementing QApplication::saveState(). All state data you are saving in this function, should be marked with the session identifier QApplication::sessionId(). This application specific identifier is globally unique, so no clashes will occur. (See QSessionManager for information on saving/restoring the state of a particular Qt application.)

Restoration is usually done in the application‘s main() function. Check if QApplication::isSessionRestored() is true. If that‘s the case, use the session identifier QApplication::sessionId() again to access your state data and restore the state of the application.

Important: In order to allow the window manager to restore window attributes such as stacking order or geometry information, you must identify your top level widgets with unique application-wide object names (see QObject::setObjectName()). When restoring the application, you must ensure that all restored top level widgets are given the same unique names they had before.

Testing and Debugging Session Management

Session management support on Mac OS X and Windows is fairly limited due to the lack of this functionality in the operating system itself. Simply shut the session down and verify that your application behaves as expected. It may be useful 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 is time consuming.

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 called xsm and is part of a standard X11R6 installation. As always with X11, a useful and informative manual page is provided. Using xsm is straightforward (apart from the clumsy Athena-based user interface). Here‘s a simple approach:

Run X11R6.
Create a dot file .xsmstartup in your home directory which contains the single line
xterm
This tells xsm that the default/failsafe session is just an xterm and nothing else. Otherwise xsm would try to invoke lots of clients including the windowmanager twm, which isn‘t very helpful.

Now launch xsm 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 SESSION_MANAGER environment variable points to the session manager you just started.
Launch your application from the new xterm window. It will connect itself automatically to the session manager. You can check with the ClientList push button whether the connect was successful.
Note: Never keep the ClientList open when you start or end session managed clients! Otherwise xsm is likely to crash.

Use the session manager‘s Checkpoint and Shutdown buttons with different settings and see how your application behaves. The save type local means that the clients should save their state. It corresponds to the QApplication::saveState() function. The global save type asks applications to save their unsaved changes in permanent, globally accessible storage. It invokes QApplication::commitData().
Whenever something crashes, blame xsm and not Qt. xsm 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.

时间: 2024-10-06 18:44:46

Session Management的相关文章

session management会话管理的原理

web请求与响应基于http,而http是无状态协议.所以我们为了跨越多个请求保留用户的状态,需要利用某种工具帮助我们记录与识别每一次请求及请求的其他信息.举个栗子,我们在淘宝购物的时候,首先添加了一本<C++ primer>进入购物车,然后我们又继续去搜索<thinking in java>,继续添加购物车,这时购物车应该有两本书.但如果我们不采取session management会话管理的话,基于http无状态协议,我们在第二次向购物车发出添加请求时,他是无法知道我们第一次添

Use Spring transaction to simplify Hibernate session management

Spring对Hibernate有很好的支持    DataSource ->SessionFactory-> HibernateTranscationManagerHibernate中通过SessionFactory创建和维护Session.Spring对SessionFactory的配置进行了整合,无需再通过Hibernate.cfg.xml对SessionFactory进行设定.SessionFactory节点的mappingResources属性包含了映射文件的路径,list节点下可配

[Session Management] State Server 管理 Session

公司计划升级所有电脑的操作系统,在导入的前置准备阶段,进行系统测试时,居然发现-- 公司计划升级所有电脑的操作系统, 在导入的前置准备阶段,进行系统测试时, 居然发现-- 负责的线上系统,如果由IE6 升级 IE8 之后的版本, 会发现使用者打完账号与密码登入后,开始鬼打墙的情况, 一直出现登入首页的情况. 写了一些测试程序,发现,原来是Session的问题, 由于系统有采用Hardware NLB的设定, 而且登入后的网页,有再触发另开新一个窗口, 发现两个窗口的Physical Host I

《how tomcat work》 搬运工 Chapter 9: Session Management

Catalina版本的Tomcat通过manager板块来提供session管理,manager通常是和context联系在一起,就是context类里会有一个manager实例. Session interface public interface Session { public static final String SESSION_CREATED_EVENT = "createSession"; public static final String SESSION_DESTRO

认证 协议 JWT OAuth Session Cookie

本文翻译自Auth-Boss. 如果有翻译的不恰当或不对的地方, 欢迎指出. 成为一个认证老司机, 了解网络上不同的身份认证方法. 本文档的目的是记录和编目Web上的身份验证方法.认证指的是创建一个系统的过程,用户可以通过该系统"登录"在线服务,并授予对受保护资源的访问权限.以下引用可能更好地总结我想要解释的内容: 客户端认证涉及向Web上的服务器证明客户端(或用户)的身份.[1] How 我写作风格简洁,会用到一些技术词. 免责声明:本文档不作为包含所有认证方法的网络的目录;本文档也

转:通过Spring Session实现新一代的Session管理

长期以来,session管理就是企业级Java中的一部分,以致于我们潜意识就认为它是已经解决的问题,在最近的记忆中,我们没有看到这个领域有很大的革新. 但是,现代的趋势是微服务以及可水平扩展的原生云应用(cloud native application),它们会挑战过去20多年来我们设计和构建session管理器时的前提假设,并且暴露了现代化session管理器的不足. 本文将会阐述最近发布的Spring Session API如何帮助我们克服眼下session管理方式中的一些不足,在企业级Ja

HTTP验证大法(Basic Auth,Session, JWT, Oauth, Openid)

本文标签:   HTTP Auth OpenID HTTP验证大法 Session REST   服务器 成为一个"认证"老司机 本文翻译自 Auth-Boss . 如果有翻译的不恰当或不对的地方, 欢迎指出. 成为一个认证老司机, 了解网络上不同的身份认证方法. 本文档的目的是记录和编目Web上的身份验证方法. 认证指的是创建一个系统的过程,用户可以通过该系统"登录"在线服务,并授予对受保护资源的访问权限. 以下引用可能更好地总结我想要解释的内容: 客户端认证涉及

servlet和jsp学习指南(二)Session管理

Web语言HTTP是无状态的,默认情况下,Web服务器不知道一个HTTP请求是来自初次用户,还是来自之前已经访问过的用户.但正常应用程序需要记住用户身份的,换句说,它必须能够管理用户session. 用于保持状态的常用方法有4种:网址重写.隐藏域.cookie已经HttpSession. (一)网址重写 网址重写是一种Session追踪技术,需要将一个或多个token作为一个查询字符串添加到一个URL钟.注意URL和token之间要用一个问号(?)隔开,两个token之间则是用一个&符号隔开.

webpy使用笔记(二) session/sessionid的使用

webpy使用笔记(二) session的使用 webpy使用系列之session的使用,虽然工作中使用的是django,但是自己并不喜欢那种大而全的东西~什么都给你准备好了,自己好像一个机器人一样赶着重复的基本工作,从在学校时候就养成了追究原理的习惯,从而有了这篇session的使用和说明. PS:其实有些总结的东西挺好的,想分享给大家看,而不是枯燥的代码,这东西说实话对其他人用处不大,但都被移除首页了~~ webpy中的session 下面为官方的例子,用session来存储页面访问的次数,