XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy VVeerrssiioonn 11..00 XX CCoonnssoorrttiiuumm SSttaannddaarrdd XX VVeerrssiioonn 1111,, RReelleeaassee 77 lliibbSSMM 11..11..11 Ralph Mor X Consortium Copyright © 1993, 1994 X Consortium Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documenta‐ tion files (the ‘‘Software’’), to deal in the Software with‐ out restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the fol‐ lowing conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ‘‘AS IS’’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PUR‐ POSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSOR‐ TIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium. X Window System is a trademark of The Open Group. _1_. _O_v_e_r_v_i_e_w _o_f _S_e_s_s_i_o_n _M_a_n_a_g_e_m_e_n_t The purpose of the X Session Management Protocol (XSMP) is to provide a uniform mechanism for users to save and restore their sessions. A _s_e_s_s_i_o_n is a group of clients, each of which has a particular state. The session is controlled by a network service called the _s_e_s_s_i_o_n _m_a_n_a_g_e_r. The session manager issues commands to its clients on behalf of the user. These commands may cause clients to save their state or to terminate. It is expected that the client will save its state in such a way that the client can be restarted at a later time and resume its operation as if it had never been terminated. A client’s state might include information about the file currently being edited, the current position of the insertion point within the file, or the start of an uncommitted transaction. The means by which clients are restarted is unspecified by this protocol. For purposes of this protocol, a _c_l_i_e_n_t of the session man‐ ager is defined as a connection to the session manager. A client is typically, though not necessarily, a process run‐ ning an application program connected to an X display. How‐ ever, a client may be connected to more than one X display or not be connected to any X displays at all. _2_. _T_h_e _S_e_s_s_i_o_n _M_a_n_a_g_e_m_e_n_t _L_i_b_r_a_r_y The Session Management Library (SMlib) is a low‐level "C" language interface to XSMP. It is expected that higher level toolkits, such as Xt, will hide many of the details of session management from clients. Higher level toolkits might also be developed for session managers to use, but no such effort is currently under way. SMlib has two parts to it: · One set of functions for clients that want to be part of a session · One set of functions for session managers to call Some applications will use both sets of functions and act as _n_e_s_t_e_d _s_e_s_s_i_o_n _m_a_n_a_g_e_r_s. That is, they will be both a ses‐ sion manager and a client of another session. An example is a mail program that could start a text editor for editing the text of a mail message. The mail program is part of a regular session and, at the same time, is also acting as a session manager to the editor. Clients initialize by connecting to the session manager and obtaining a _c_l_i_e_n_t_‐_I_D that uniquely identifies them in the session. The session manager maintains a list of properties for each client in the session. These properties describe the client’s environment and, most importantly, describe how − 1 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 the client can be restarted (via an _S_m_R_e_s_t_a_r_t_C_o_m_m_a_n_d). Clients are expected to save their state in such a way as to allow multiple instantiations of themselves to be managed independently. For example, clients may use their client‐ID as part of a filename in which to store the state for a par‐ ticular instantiation. The client‐ID should be saved as part of the _S_m_R_e_s_t_a_r_t_C_o_m_m_a_n_d so that the client will retain the same ID after it is restarted. Once the client initializes itself with the session manager, it must be ready to respond to messages from the session manager. For example, it might be asked to save its state or to terminate. In the case of a shutdown, the session manager might give each client a chance to interact with the user and cancel the shutdown. _3_. _U_n_d_e_r_s_t_a_n_d_i_n_g _S_M_l_i_b_’_s _D_e_p_e_n_d_e_n_c_e _o_n _I_C_E The X Session Management Protocol is layered on top of the Inter‐Client Exchange (ICE) Protocol. The ICE protocol is designed to multiplex several protocols over a single con‐ nection. As a result, working with SMlib requires a little knowledge of how the ICE library works. The ICE library utilizes callbacks to process messages. When a client detects that there is data to read on an ICE connection, it should call the _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s function. _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s will read the message header and look at the major opcode in order to determine which protocol the message was intended for. The appropriate protocol library will then be triggered to unpack the message and hand it off to the client via a callback. The main point to be aware of is that an application using SMlib must have some code that detects when there is data to read on an ICE connection. This can be done via a _s_e_l_e_c_t call on the file descriptor for the ICE connection, but more typically, _X_t_A_p_p_A_d_d_I_n_p_u_t will be used to register a callback that will invoke _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s each time there is data to read on the ICE connection. To further complicate things, knowing which file descriptors to call _s_e_l_e_c_t on requires an understanding of how ICE con‐ nections are created. On the client side, a call must be made to _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n in order to open a connection with a session manager. _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n will internally make a call into _I_c_e_O_p_e_n_C_o_n_n_e_c_t_i_o_n, which will, in turn, determine if an ICE connection already exists between the client and session manager. Most likely, a connection will not already exist and a new ICE connection will be created. The main point to be aware of is that, on the client side, it is not obvious when ICE connections get created or destroyed, because connections are shared when possible. To deal with this, the ICE library lets the application register watch − 2 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 procedures that will be invoked each time an ICE connection is opened or closed. These watch procedures could be used to add or remove ICE file descriptors from the list of descriptors to call _s_e_l_e_c_t on. On the session manager side, things work a bit differently. The session manager has complete control over the creation of ICE connections. The session manager has to first call _I_c_e_L_i_s_t_e_n_F_o_r_C_o_n_n_e_c_t_i_o_n_s in order to start listening for con‐ nections from clients. Once a connection attempt is detected, _I_c_e_A_c_c_e_p_t_C_o_n_n_e_c_t_i_o_n must be called, and the ses‐ sion manager can simply add the new ICE file descriptor to the list of descriptors to call _s_e_l_e_c_t on. For further information on the library functions related to ICE connections, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y stan‐ dard. _4_. _H_e_a_d_e_r _F_i_l_e_s _a_n_d _L_i_b_r_a_r_y _N_a_m_e Applications (both session managers and clients) should include the header file <_X_1_1_/_S_M_/_S_M_l_i_b_._h>. This header file defines all of the SMlib data structures and function proto‐ types. _S_M_l_i_b_._h includes the header file <_X_1_1_/_S_M_/_S_M_._h>, which defines all of the SMlib constants. Because SMlib is dependent on ICE, applications should link against SMlib and ICElib by using _‐_l_S_M _‐_l_I_C_E. _5_. _S_e_s_s_i_o_n _M_a_n_a_g_e_m_e_n_t _C_l_i_e_n_t _(_S_m_c_) _F_u_n_c_t_i_o_n_s This section discusses how Session Management clients: · Connect to the Session Manager · Close the connection · Modify callbacks · Set, delete, and retrieve Session Manager properties · Interact with the user · Request a ‘‘Save Yourself’’ · Request a ‘‘Save Yourself Phase 2’’ · Complete a ‘‘Save Yourself’’ · Use Smc informational functions · Handle Errors − 3 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _5_._1_. _C_o_n_n_e_c_t_i_n_g _t_o _t_h_e _S_e_s_s_i_o_n _M_a_n_a_g_e_r To open a connection with a session manager, use _S_m_c_O_p_e_n_C_o_n_‐ _n_e_c_t_i_o_n. __ ││ SmcConn SmcOpenConnection(_n_e_t_w_o_r_k___i_d_s___l_i_s_t, _c_o_n_t_e_x_t, _x_s_m_p___m_a_j_o_r___r_e_v, _x_s_m_p___m_i_n_o_r___r_e_v, _m_a_s_k, _c_a_l_l_b_a_c_k_s, _p_r_e_v_i_o_u_s___i_d, _c_l_i_e_n_t___i_d___r_e_t, _e_r_r_o_r___l_e_n_g_t_h, _e_r_r_o_r___s_t_r_i_n_g___r_e_t) char *_n_e_t_w_o_r_k___i_d_s___l_i_s_t; SmPointer _c_o_n_t_e_x_t; int _x_s_m_p___m_a_j_o_r___r_e_v; int _x_s_m_p___m_i_n_o_r___r_e_v; unsigned long _m_a_s_k; SmcCallbacks *_c_a_l_l_b_a_c_k_s; char *_p_r_e_v_i_o_u_s___i_d; char **_c_l_i_e_n_t___i_d___r_e_t; int _e_r_r_o_r___l_e_n_g_t_h; char *_e_r_r_o_r___s_t_r_i_n_g___r_e_t; _n_e_t_w_o_r_k___i_d_s___l_i_s_t Specifies the network ID(s) of the session man‐ ager. _c_o_n_t_e_x_t A pointer to an opaque object or NULL. Used to determine if an ICE connection can be shared (see below). _x_s_m_p___m_a_j_o_r___r_e_v The highest major version of the XSMP the applica‐ tion supports. _x_s_m_p___m_i_n_o_r___r_e_v The highest minor version of the XSMP the applica‐ tion supports (for the specified xsmp_major_rev). _m_a_s_k A mask indicating which callbacks to register. _c_a_l_l_b_a_c_k_s The callbacks to register. These callbacks are used to respond to messages from the session man‐ ager. _p_r_e_v_i_o_u_s___i_dThe client ID from the previous session. _c_l_i_e_n_t___i_d___r_e_t The client ID for the current session is returned. _e_r_r_o_r___l_e_n_g_t_h Length of the error_string_ret argument passed in. _e_r_r_o_r___s_t_r_i_n_g___r_e_t Returns a null‐terminated error message, if any. The error_string_ret argument points to user sup‐ plied memory. No more than error_length bytes are − 4 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 used. ││__ The network_ids_list argument is a null‐terminated string containing a list of network IDs for the session manager, separated by commas. If network_ids_list is NULL, the value of the _S_E_S_S_I_O_N___M_A_N_A_G_E_R environment variable will be used. Each network ID has the following format: tcp/: or decnet/:: or local/: An attempt will be made to use the first network ID. If that fails, an attempt will be made using the second network ID, and so on. After the connection is established, _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n reg‐ isters the client with the session manager. If the client is being restarted from a previous session, previous_id should contain a null terminated string representing the client ID from the previous session. If the client is first joining the session, previous_id should be set to NULL. If previous_id is specified but is determined to be invalid by the session manager, SMlib will re‐register the client with previous_id set to NULL. If _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n succeeds, it returns an opaque connec‐ tion pointer of type _S_m_c_C_o_n_n and the client_id_ret argument contains the client ID to be used for this session. The client_id_ret should be freed with a call to _f_r_e_e when no longer needed. On failure, _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n returns NULL, and the reason for failure is returned in error_string_ret. Note that SMlib uses the ICE protocol to establish a connec‐ tion with the session manager. If an ICE connection already exists between the client and session manager, it might be possible for the same ICE connection to be used for session management. The context argument indicates how willing the client is to share the ICE connection with other protocols. If context is NULL, then the caller is always willing to share the con‐ nection. If context is not NULL, then the caller is not willing to use a previously opened ICE connection that has a different non‐NULL context associated with it. As previously discussed (section 3, ‘‘Understanding SMlib’s Dependence on ICE’’), the client will have to keep track of when ICE connections are created or destroyed (using _I_c_e_A_d_d_‐ _C_o_n_n_e_c_t_i_o_n_W_a_t_c_h and _I_c_e_R_e_m_o_v_e_C_o_n_n_e_c_t_i_o_n_W_a_t_c_h), and will have to call _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s each time a _s_e_l_e_c_t shows that there is data to read on an ICE connection. For further − 5 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 information, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. The callbacks argument contains a set of callbacks used to respond to session manager events. The mask argument speci‐ fies which callbacks are set. All of the callbacks speci‐ fied in this version of SMlib are mandatory. The mask argu‐ ment is necessary in order to maintain backwards compatibil‐ ity in future versions of the library. The following values may be ORed together to obtain a mask value: _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_P_r_o_c_M_a_s_k _S_m_c_D_i_e_P_r_o_c_M_a_s_k _S_m_c_S_a_v_e_C_o_m_p_l_e_t_e_P_r_o_c_M_a_s_k _S_m_c_S_h_u_t_d_o_w_n_C_a_n_c_e_l_l_e_d_P_r_o_c_M_a_s_k For each callback, the client can register a pointer to client data. When SMlib invokes the callback, it will pass the client data pointer. __ ││ typedef struct { struct { SmcSaveYourselfProc callback; SmPointer client_data; } save_yourself; struct { SmcDieProc callback; SmPointer client_data; } die; struct { SmcSaveCompleteProc callback; SmPointer client_data; } save_complete; struct { SmcShutdownCancelledProc callback; SmPointer client_data; } shutdown_cancelled; } SmcCallbacks; ││__ − 6 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _5_._1_._1_. _T_h_e _S_a_v_e _Y_o_u_r_s_e_l_f _C_a_l_l_b_a_c_k The Save Yourself callback is of type _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_P_r_o_c. __ ││ typedef void (*SmcSaveYourselfProc)(); void SaveYourselfProc(_s_m_c___c_o_n_n, _c_l_i_e_n_t___d_a_t_a, _s_a_v_e___t_y_p_e, _s_h_u_t_d_o_w_n, _i_n_t_e_r_a_c_t___s_t_y_l_e, _f_a_s_t) SmcConn _s_m_c___c_o_n_n; SmPointer _c_l_i_e_n_t___d_a_t_a; int _s_a_v_e___t_y_p_e; Bool _s_h_u_t_d_o_w_n; int _i_n_t_e_r_a_c_t___s_t_y_l_e; Bool _f_a_s_t; _s_m_c___c_o_n_n The session management connection object. _c_l_i_e_n_t___d_a_t_aClient data specified when the callback was reg‐ istered. _s_a_v_e___t_y_p_e Specifies the type of information that should be saved. _s_h_u_t_d_o_w_n Specifies if a shutdown is taking place. _i_n_t_e_r_a_c_t___s_t_y_l_e The type of interaction allowed with the user. _f_a_s_t If _T_r_u_e, the client should save its state as quickly as possible. ││__ The session manager sends a ‘‘Save Yourself’’ message to a client either to checkpoint it or just before termination so that it can save its state. The client responds with zero or more calls to _S_m_c_S_e_t_P_r_o_p_e_r_t_i_e_s to update the properties indicating how to restart the client. When all the proper‐ ties have been set, the client calls _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e. If interact_style is _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_N_o_n_e, the client must not interact with the user while saving state. If inter‐ act_style is _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_E_r_r_o_r_s, the client may interact with the user only if an error condition arises. If inter‐ act_style is _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_A_n_y, then the client may inter‐ act with the user for any purpose. Because only one client can interact with the user at a time, the client must call _S_m_c_I_n_t_e_r_a_c_t_R_e_q_u_e_s_t and wait for an ‘‘Interact’’ message from the session manager. When the client is done interacting with the user, it calls _S_m_c_I_n_t_e_r_a_c_t_D_o_n_e. The client may only call _S_m_c_I_n_t_e_r_a_c_t_R_e_q_u_e_s_t after it receives a ‘‘Save Yourself’’ message and before it calls _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e. If save_type is _S_m_S_a_v_e_L_o_c_a_l, the client must update the − 7 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 properties to reflect its current state. Specifically, it should save enough information to restore the state as seen by the user of this client. It should not affect the state as seen by other users. If save_type is _S_m_S_a_v_e_G_l_o_b_a_l, the user wants the client to commit all of its data to perma‐ nent, globally accessible storage. If save_type is _S_m_S_a_v_e_‐ _B_o_t_h, the client should do both of these (it should first commit the data to permanent storage before updating its properties). Some examples are as follows: · If a word processor were sent a ‘‘Save Yourself’’ with a type of _S_m_S_a_v_e_L_o_c_a_l, it could create a temporary file that included the current contents of the file, the location of the cursor, and other aspects of the cur‐ rent editing session. It would then update its SmRestartCommand property with enough information to find this temporary file. · If a word processor were sent a ‘‘Save Yourself’’ with a type of _S_m_S_a_v_e_G_l_o_b_a_l, it would simply save the cur‐ rently edited file. · If a word processor were sent a ‘‘Save Yourself’’ with a type of _S_m_S_a_v_e_B_o_t_h, it would first save the currently edited file. It would then create a temporary file with information such as the current position of the cursor and what file is being edited. Finally, it would update its SmRestartCommand property with enough information to find the temporary file. The shutdown argument specifies whether the system is being shut down. The interaction is different depending on whether or not shutdown is set. If not shutting down, the client should save its state and wait for a ‘‘Save Com‐ plete’’ message. If shutting down, the client must save state and then prevent interaction until it receives either a ‘‘Die’’ or a ‘‘Shutdown Cancelled.’’ The fast argument specifies that the client should save its state as quickly as possible. For example, if the session manager knows that power is about to fail, it would set fast to _T_r_u_e. _5_._1_._2_. _T_h_e _D_i_e _C_a_l_l_b_a_c_k The Die callback is of type _S_m_c_D_i_e_P_r_o_c. __ ││ − 8 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 typedef void (*SmcDieProc)(); void DieProc(_s_m_c___c_o_n_n, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; SmPointer _c_l_i_e_n_t___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _c_l_i_e_n_t___d_a_t_aClient data specified when the callback was reg‐ istered. ││__ The session manager sends a ‘‘Die’’ message to a client when it wants it to die. The client should respond by calling _S_m_c_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n. A session manager that behaves properly will send a ‘‘Save Yourself’’ message before the ‘‘Die’’ message. _5_._1_._3_. _T_h_e _S_a_v_e _C_o_m_p_l_e_t_e _C_a_l_l_b_a_c_k The Save Complete callback is of type _S_m_c_S_a_v_e_C_o_m_p_l_e_t_e_P_r_o_c. __ ││ typedef void (*SmcSaveCompleteProc)(); void SaveCompleteProc(_s_m_c___c_o_n_n, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; SmPointer _c_l_i_e_n_t___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _c_l_i_e_n_t___d_a_t_aClient data specified when the callback was reg‐ istered. ││__ When the session manager is done with a checkpoint, it will send each of the clients a ‘‘Save Complete’’ message. The client is then free to change its state. _5_._1_._4_. _T_h_e _S_h_u_t_d_o_w_n _C_a_n_c_e_l_l_e_d _C_a_l_l_b_a_c_k The Shutdown Cancelled callback is of type _S_m_c_S_h_u_t_d_o_w_n_C_a_n_‐ _c_e_l_l_e_d_P_r_o_c. __ ││ typedef void (*SmcShutdownCancelledProc)(); void ShutdownCancelledProc(_s_m_c___c_o_n_n, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; SmPointer _c_l_i_e_n_t___d_a_t_a; − 9 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _s_m_c___c_o_n_n The session management connection object. _c_l_i_e_n_t___d_a_t_aClient data specified when the callback was reg‐ istered. ││__ The session manager sends a ‘‘Shutdown Cancelled’’ message when the user cancelled the shutdown during an interaction (see section 5.5, ‘‘Interacting With the User’’). The client can now continue as if the shutdown had never hap‐ pened. If the client has not called _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e yet, it can either abort the save and then call _S_m_c_S_a_v_e_Y_o_u_r_‐ _s_e_l_f_D_o_n_e with the success argument set to _F_a_l_s_e, or it can continue with the save and then call _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e with the success argument set to reflect the outcome of the save. _5_._2_. _C_l_o_s_i_n_g _t_h_e _C_o_n_n_e_c_t_i_o_n To close a connection with a session manager, use _S_m_c_C_l_o_s_e_C_‐ _o_n_n_e_c_t_i_o_n. __ ││ SmcCloseStatus SmcCloseConnection(_s_m_c___c_o_n_n, _c_o_u_n_t, _r_e_a_s_o_n___m_s_g_s) SmcConn _s_m_c___c_o_n_n; int _c_o_u_n_t; char **_r_e_a_s_o_n___m_s_g_s; _s_m_c___c_o_n_n The session management connection object. _c_o_u_n_t The number of reason messages. _r_e_a_s_o_n___m_s_g_sThe reasons for closing the connection. ││__ The reason_msgs argument will most likely be NULL if resig‐ nation is expected by the client. Otherwise, it contains a list of null‐terminated Compound Text strings representing the reason for termination. The session manager should dis‐ play these reason messages to the user. Note that SMlib used the ICE protocol to establish a connec‐ tion with the session manager, and various protocols other than session management may be active on the ICE connection. When _S_m_c_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n is called, the ICE connection will be closed only if all protocols have been shutdown on the connection. Check the ICElib standard for _I_c_e_A_d_d_C_o_n_n_e_c_t_i_o_n_‐ _W_a_t_c_h and _I_c_e_R_e_m_o_v_e_C_o_n_n_e_c_t_i_o_n_W_a_t_c_h to learn how to set up a callback to be invoked each time an ICE connection is opened or closed. Typically this callback adds/removes the ICE file descriptor from the list of active descriptors to call _s_e_l_e_c_t on (or calls _X_t_A_p_p_A_d_d_I_n_p_u_t or _X_t_R_e_m_o_v_e_I_n_p_u_t). − 10 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _S_m_c_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n returns one of the following values: · _S_m_c_C_l_o_s_e_d_N_o_w − the ICE connection was closed at this time, the watch procedures were invoked, and the con‐ nection was freed. · _S_m_c_C_l_o_s_e_d_A_S_A_P − an IO error had occurred on the connec‐ tion, but _S_m_c_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n is being called within a nested _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s. The watch procedures have been invoked at this time, but the connection will be freed as soon as possible (when the nesting level reaches zero and _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s returns a status of _I_c_e_P_r_o_c_e_s_s_M_e_s_s_a_g_e_s_C_o_n_n_e_c_t_i_o_n_C_l_o_s_e_d). · _S_m_c_C_o_n_n_e_c_t_i_o_n_I_n_U_s_e − the connection was not closed at this time, because it is being used by other active protocols. _5_._3_. _M_o_d_i_f_y_i_n_g _C_a_l_l_b_a_c_k_s To modify callbacks set up in _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n, use _S_m_c_M_o_d_‐ _i_f_y_C_a_l_l_b_a_c_k_s. __ ││ void SmcModifyCallbacks(_s_m_c___c_o_n_n, _m_a_s_k, _c_a_l_l_b_a_c_k_s) SmcConn _s_m_c___c_o_n_n; unsigned long _m_a_s_k; SmcCallbacks *_c_a_l_l_b_a_c_k_s; _s_m_c___c_o_n_n The session management connection object. _m_a_s_k A mask indicating which callbacks to modify. _c_a_l_l_b_a_c_k_s The new callbacks. ││__ When specifying a value for the mask argument, the following values may be ORed together: _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_P_r_o_c_M_a_s_k _S_m_c_D_i_e_P_r_o_c_M_a_s_k _S_m_c_S_a_v_e_C_o_m_p_l_e_t_e_P_r_o_c_M_a_s_k _S_m_c_S_h_u_t_d_o_w_n_C_a_n_c_e_l_l_e_d_P_r_o_c_M_a_s_k _5_._4_. _S_e_t_t_i_n_g_, _D_e_l_e_t_i_n_g_, _a_n_d _R_e_t_r_i_e_v_i_n_g _S_e_s_s_i_o_n _M_a_n_a_g_e_m_e_n_t _P_r_o_p_e_r_t_i_e_s To set session management properties for this client, use − 11 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _S_m_c_S_e_t_P_r_o_p_e_r_t_i_e_s. __ ││ void SmcSetProperties(_s_m_c___c_o_n_n, _n_u_m___p_r_o_p_s, _p_r_o_p_s) SmcConn _s_m_c___c_o_n_n; int _n_u_m___p_r_o_p_s; SmProp **_p_r_o_p_s; _s_m_c___c_o_n_n The session management connection object. _n_u_m___p_r_o_p_s The number of properties. _p_r_o_p_s The list of properties to set. ││__ The properties are specified as an array of property point‐ ers. Previously set property values may be over‐written using the _S_m_c_S_e_t_P_r_o_p_e_r_t_i_e_s function. Note that the session manager is not expected to restore property values when the session is restarted. Because of this, clients should not try to use the session manager as a database for storing application specific state. For a description of session management properties and the _S_m_P_r_o_p structure, see section 7, ‘‘Session Management Prop‐ erties.’’ To delete properties previously set by the client, use _S_m_c_D_e_l_e_t_e_P_r_o_p_e_r_t_i_e_s. __ ││ void SmcDeleteProperties(_s_m_c___c_o_n_n, _n_u_m___p_r_o_p_s, _p_r_o_p___n_a_m_e_s) SmcConn _s_m_c___c_o_n_n; int _n_u_m___p_r_o_p_s; char **_p_r_o_p___n_a_m_e_s; _s_m_c___c_o_n_n The session management connection object. _n_u_m___p_r_o_p_s The number of properties. _p_r_o_p___n_a_m_e_sThe list of properties to delete. ││__ To get properties previously stored by the client, use _S_m_c_G_e_t_P_r_o_p_e_r_t_i_e_s. __ ││ − 12 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 Status SmcGetProperties(_s_m_c___c_o_n_n, _p_r_o_p___r_e_p_l_y___p_r_o_c, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; SmcPropReplyProc _p_r_o_p___r_e_p_l_y___p_r_o_c; SmPointer _c_l_i_e_n_t___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _p_r_o_p___r_e_p_l_y___p_r_o_c The callback to be invoked when the properties reply comes back. _c_l_i_e_n_t___d_a_t_aThis pointer to client data will be passed to the _S_m_c_P_r_o_p_R_e_p_l_y_P_r_o_c callback. ││__ The return value of _S_m_c_G_e_t_P_r_o_p_e_r_t_i_e_s is zero for failure and a positive value for success. Note that the library does not block until the properties reply comes back. Rather, a callback of type _S_m_c_P_r_o_p_R_e_‐ _p_l_y_P_r_o_c is invoked when the data is ready. __ ││ typedef void (*SmcPropReplyProc)(); void PropReplyProc(_s_m_c___c_o_n_n, _c_l_i_e_n_t___d_a_t_a, _n_u_m___p_r_o_p_s, _p_r_o_p_s) SmcConn _s_m_c___c_o_n_n; SmPointer _c_l_i_e_n_t___d_a_t_a; int _n_u_m___p_r_o_p_s; SmProp **_p_r_o_p_s; _s_m_c___c_o_n_n The session management connection object. _c_l_i_e_n_t___d_a_t_aClient data specified when the callback was reg‐ istered. _n_u_m___p_r_o_p_s The number of properties returned. _p_r_o_p_s The list of properties returned. ││__ To free each property, use _S_m_F_r_e_e_P_r_o_p_e_r_t_y (see section 8, ‘‘Freeing Data’’). To free the actual array of pointers, use _f_r_e_e. _5_._5_. _I_n_t_e_r_a_c_t_i_n_g _W_i_t_h _t_h_e _U_s_e_r After receiving a ‘‘Save Yourself’’ message with an inter‐ act_style of _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_E_r_r_o_r_s or _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_A_n_y, the client may choose to interact with the user. Because only one client can interact with the user at a time, the client must call _S_m_c_I_n_t_e_r_a_c_t_R_e_q_u_e_s_t and wait for an − 13 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ‘‘Interact’’ message from the session manager. __ ││ Status SmcInteractRequest(_s_m_c___c_o_n_n, _d_i_a_l_o_g___t_y_p_e, _i_n_t_e_r_a_c_t___p_r_o_c, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; int _d_i_a_l_o_g___t_y_p_e; SmcInteractProc _i_n_t_e_r_a_c_t___p_r_o_c; SmPointer _c_l_i_e_n_t___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _d_i_a_l_o_g___t_y_p_eThe type of dialog the client wishes to present to the user. _i_n_t_e_r_a_c_t___p_r_o_c The callback to be invoked when the ‘‘Interact’’ message arrives from the session manager. _c_l_i_e_n_t___d_a_t_aThis pointer to client data will be passed to the _S_m_c_I_n_t_e_r_a_c_t_P_r_o_c callback when the ‘‘Interact’’ message arrives. ││__ The return value of _S_m_c_I_n_t_e_r_a_c_t_R_e_q_u_e_s_t is zero for failure and a positive value for success. The dialog_type argument specifies either _S_m_D_i_a_l_o_g_E_r_r_o_r, indicating that the client wants to start an error dialog, or _S_m_D_i_a_l_o_g_N_o_r_m_a_l, meaning that the client wishes to start a nonerror dialog. Note that if a shutdown is in progress, the user may have the option of cancelling the shutdown. If the shutdown is cancelled, the clients that have not interacted yet with the user will receive a ‘‘Shutdown Cancelled’’ message instead of the ‘‘Interact’’ message. The _S_m_c_I_n_t_e_r_a_c_t_P_r_o_c callback will be invoked when the ‘‘Interact’’ message arrives from the session manager. __ ││ typedef void (*SmcInteractProc)(); void InteractProc(_s_m_c___c_o_n_n, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; SmPointer _c_l_i_e_n_t___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _c_l_i_e_n_t___d_a_t_aClient data specified when the callback was reg‐ istered. − 14 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ││__ After interacting with the user (in response to an ‘‘Inter‐ act’’ message), you should call _S_m_c_I_n_t_e_r_a_c_t_D_o_n_e. __ ││ void SmcInteractDone(_s_m_c___c_o_n_n, _c_a_n_c_e_l___s_h_u_t_d_o_w_n) SmcConn _s_m_c___c_o_n_n; Bool _c_a_n_c_e_l___s_h_u_t_d_o_w_n; _s_m_c___c_o_n_n The session management connection object. _c_a_n_c_e_l___s_h_u_t_d_o_w_n If _T_r_u_e, indicates that the user requests that the entire shutdown be cancelled. ││__ The cancel_shutdown argument may only be _T_r_u_e if the corre‐ sponding ‘‘Save Yourself’’ specified _T_r_u_e for shutdown and _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_E_r_r_o_r_s or _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_A_n_y for the inter‐ act_style. _5_._6_. _R_e_q_u_e_s_t_i_n_g _a _S_a_v_e _Y_o_u_r_s_e_l_f To request a checkpoint from the session manager, use _S_m_c_R_e_‐ _q_u_e_s_t_S_a_v_e_Y_o_u_r_s_e_l_f. __ ││ void SmcRequestSaveYourself(_s_m_c___c_o_n_n, _s_a_v_e___t_y_p_e, _s_h_u_t_d_o_w_n, _i_n_t_e_r_a_c_t___s_t_y_l_e, _f_a_s_t, _g_l_o_b_a_l) SmcConn _s_m_c___c_o_n_n; int _s_a_v_e___t_y_p_e; Bool _s_h_u_t_d_o_w_n; int _i_n_t_e_r_a_c_t___s_t_y_l_e; Bool _f_a_s_t; Bool _g_l_o_b_a_l; _s_m_c___c_o_n_n The session management connection object. _s_a_v_e___t_y_p_e Specifies the type of information that should be saved. _s_h_u_t_d_o_w_n Specifies if a shutdown is taking place. _i_n_t_e_r_a_c_t___s_t_y_l_e The type of interaction allowed with the user. _f_a_s_t If _T_r_u_e, the client should save its state as quickly as possible. _g_l_o_b_a_l Controls who gets the ‘‘Save Yourself.’’ − 15 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ││__ The save_type, shutdown, interact_style, and fast arguments are discussed in more detail in section 5.1.1, ‘‘The Save Yourself Callback.’’ If global is set to _T_r_u_e, then the resulting ‘‘Save Your‐ self’’ should be sent to all clients in the session. For example, a vendor of a Uninterruptible Power Supply (UPS) might include a Session Management client that would monitor the status of the UPS and generate a fast shutdown if the power is about to be lost. If global is set to _F_a_l_s_e, then the ‘‘Save Yourself’’ should only be sent to the client that requested it. _5_._7_. _R_e_q_u_e_s_t_i_n_g _a _S_a_v_e _Y_o_u_r_s_e_l_f _P_h_a_s_e _2 In response to a ‘‘Save Yourself, the client may request to be informed when all the other clients are quiescent so that it can save their state. To do so, use _S_m_c_R_e_q_u_e_s_t_S_a_v_e_Y_o_u_r_‐ _s_e_l_f_P_h_a_s_e_2. __ ││ Status SmcRequestSaveYourselfPhase2(_s_m_c___c_o_n_n, _s_a_v_e___y_o_u_r_s_e_l_f___p_h_a_s_e_2___p_r_o_c, _c_l_i_e_n_t___d_a_t_a) SmcConn _s_m_c___c_o_n_n; SmcSaveYourselfPhase2Proc _s_a_v_e___y_o_u_r_s_e_l_f___p_h_a_s_e_2___p_r_o_c; SmPointer _c_l_i_e_n_t___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _s_a_v_e___y_o_u_r_s_e_l_f___p_h_a_s_e_2___p_r_o_c The callback to be invoked when the ‘‘Save Your‐ self Phase 2’’ message arrives from the session manager. _c_l_i_e_n_t___d_a_t_aThis pointer to client data will be passed to the _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_P_h_a_s_e_2_P_r_o_c callback when the ‘‘Save Yourself Phase 2’’ message arrives. ││__ The return value of _S_m_c_R_e_q_u_e_s_t_S_a_v_e_Y_o_u_r_s_e_l_f_P_h_a_s_e_2 is zero for failure and a positive value for success. This request is needed by clients that manage other clients (for example, window managers, workspace managers, and so on). The manager must make sure that all of the clients that are being managed are in an idle state so that their state can be saved. _5_._8_. _C_o_m_p_l_e_t_i_n_g _a _S_a_v_e _Y_o_u_r_s_e_l_f After saving state in response to a ‘‘Save Yourself’’ − 16 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 message, you should call _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e. __ ││ void SmcSaveYourselfDone(_s_m_c___c_o_n_n, _s_u_c_c_e_s_s) SmcConn _s_m_c___c_o_n_n; Bool _s_u_c_c_e_s_s; _s_m_c___c_o_n_n The session management connection object. _s_u_c_c_e_s_s If _T_r_u_e, the ‘‘Save Yourself’’ operation was com‐ pleted successfully. ││__ Before calling _S_m_c_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e, the client must have set each required property at least once since the client regis‐ tered with the session manager. _5_._9_. _U_s_i_n_g _S_m_c _I_n_f_o_r_m_a_t_i_o_n_a_l _F_u_n_c_t_i_o_n_s __ ││ int SmcProtocolVersion(_s_m_c___c_o_n_n) SmcConn _s_m_c___c_o_n_n; ││__ _S_m_c_P_r_o_t_o_c_o_l_V_e_r_s_i_o_n returns the major version of the session management protocol associated with this session. __ ││ int SmcProtocolRevision(_s_m_c___c_o_n_n) SmcConn _s_m_c___c_o_n_n; ││__ _S_m_c_P_r_o_t_o_c_o_l_R_e_v_i_s_i_o_n returns the minor version of the session management protocol associated with this session. __ ││ char *SmcVendor(_s_m_c___c_o_n_n) SmcConn _s_m_c___c_o_n_n; ││__ _S_m_c_V_e_n_d_o_r returns a string that provides some identification of the owner of the session manager. The string should be freed with a call to _f_r_e_e. − 17 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 __ ││ char *SmcRelease(_s_m_c___c_o_n_n) SmcConn _s_m_c___c_o_n_n; ││__ _S_m_c_R_e_l_e_a_s_e returns a string that provides the release number of the session manager. The string should be freed with a call to _f_r_e_e. __ ││ char *SmcClientID(_s_m_c___c_o_n_n) SmcConn _s_m_c___c_o_n_n; ││__ _S_m_c_C_l_i_e_n_t_I_D returns a null‐terminated string for the client ID associated with this connection. This information was also returned in _S_m_c_O_p_e_n_C_o_n_n_e_c_t_i_o_n (it is provided here for convenience). Call _f_r_e_e on this pointer when the client ID is no longer needed. __ ││ IceConn SmcGetIceConnection(_s_m_c___c_o_n_n) SmcConn _s_m_c___c_o_n_n; ││__ _S_m_c_G_e_t_I_c_e_C_o_n_n_e_c_t_i_o_n returns the ICE connection object asso‐ ciated with this session management connection object. The ICE connection object can be used to get some additional information about the connection. Some of the more useful functions which can be used on the IceConn are _I_c_e_C_o_n_n_e_c_‐ _t_i_o_n_N_u_m_b_e_r, _I_c_e_C_o_n_n_e_c_t_i_o_n_S_t_r_i_n_g, _I_c_e_L_a_s_t_S_e_n_t_S_e_q_u_e_n_c_e_N_u_m_b_e_r, _I_c_e_L_a_s_t_R_e_c_e_i_v_e_d_S_e_q_u_e_n_c_e_N_u_m_b_e_r, and _I_c_e_P_i_n_g. For further information, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. _5_._1_0_. _E_r_r_o_r _H_a_n_d_l_i_n_g If the client receives an unexpected protocol error from the session manager, an error handler is invoked by SMlib. A default error handler exists that simply prints the error message to _s_t_d_e_r_r and exits if the severity of the error is fatal. The client can change this error handler by calling the _S_m_c_S_e_t_E_r_r_o_r_H_a_n_d_l_e_r function. __ ││ SmcErrorHandler SmcSetErrorHandler(_h_a_n_d_l_e_r) SmcErrorHandler _h_a_n_d_l_e_r; _h_a_n_d_l_e_r The error handler. You should pass NULL to restore the default handler. − 18 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ││__ _S_m_c_S_e_t_E_r_r_o_r_H_a_n_d_l_e_r returns the previous error handler. The _S_m_c_E_r_r_o_r_H_a_n_d_l_e_r has the following type: __ ││ typedef void (*SmcErrorHandler)(); void ErrorHandler(_s_m_c___c_o_n_n, _s_w_a_p, _o_f_f_e_n_d_i_n_g___m_i_n_o_r___o_p_c_o_d_e, _o_f_f_e_n_d_i_n_g___s_e_q_u_e_n_c_e___n_u_m, _e_r_r_o_r___c_l_a_s_s, _s_e_v_e_r_i_t_y, _v_a_l_u_e_s) SmcConn _s_m_c___c_o_n_n; Bool _s_w_a_p; int _o_f_f_e_n_d_i_n_g___m_i_n_o_r___o_p_c_o_d_e; unsigned long _o_f_f_e_n_d_i_n_g___s_e_q_u_e_n_c_e___n_u_m; int _e_r_r_o_r___c_l_a_s_s; int _s_e_v_e_r_i_t_y; IcePointer _v_a_l_u_e_s; _s_m_c___c_o_n_n The session management connection object. _s_w_a_p A flag that indicates if the specified values need byte swapping. _o_f_f_e_n_d_i_n_g___m_i_n_o_r___o_p_c_o_d_e The minor opcode of the offending message. _o_f_f_e_n_d_i_n_g___s_e_q_u_e_n_c_e___n_u_m The sequence number of the offending message. _e_r_r_o_r___c_l_a_s_sThe error class of the offending message. _s_e_v_e_r_i_t_y _I_c_e_C_a_n_C_o_n_t_i_n_u_e, _I_c_e_F_a_t_a_l_T_o_P_r_o_t_o_c_o_l, or _I_c_e_F_a_t_a_l_T_o_‐ _C_o_n_n_e_c_t_i_o_n. _v_a_l_u_e_s Any additional error values specific to the minor opcode and class. ││__ Note that this error handler is invoked for protocol related errors. To install an error handler to be invoked when an IO error occurs, use _I_c_e_S_e_t_I_O_E_r_r_o_r_H_a_n_d_l_e_r. For further information, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. _6_. _S_e_s_s_i_o_n _M_a_n_a_g_e_m_e_n_t _S_e_r_v_e_r _(_S_m_s_) _F_u_n_c_t_i_o_n_s This section discusses how Session Management servers: · Initialize the library · Register the client · Send a ‘‘Save Yourself’’ message − 19 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 · Send a ‘‘Save Yourself Phase 2’’ message · Send an ‘‘Interact’’ message · Send a ‘‘Save Complete’’ message · Send a ‘‘Die’’ message · Cancel a shutdown · Return properties · Ping a client · Clean up after a client disconnects · Use Sms informational functions · Handle errors _6_._1_. _I_n_i_t_i_a_l_i_z_i_n_g _t_h_e _L_i_b_r_a_r_y _S_m_s_I_n_i_t_i_a_l_i_z_e is the first SMlib function that should be called by a session manager. It provides information about the session manager and registers a callback that will be invoked each time a new client connects to the session man‐ ager. __ ││ Status SmsInitialize(_v_e_n_d_o_r, _r_e_l_e_a_s_e, _n_e_w___c_l_i_e_n_t___p_r_o_c, _m_a_n_a_g_e_r___d_a_t_a, _h_o_s_t___b_a_s_e_d___a_u_t_h___p_r_o_c, _e_r_r_o_r___l_e_n_g_t_h, _e_r_r_o_r___s_t_r_i_n_g___r_e_t) char *_v_e_n_d_o_r; char *_r_e_l_e_a_s_e; SmsNewClientProc _n_e_w___c_l_i_e_n_t___p_r_o_c; SmPointer _m_a_n_a_g_e_r___d_a_t_a; IceHostBasedAuthProc _h_o_s_t___b_a_s_e_d___a_u_t_h___p_r_o_c; int _e_r_r_o_r___l_e_n_g_t_h; char *_e_r_r_o_r___s_t_r_i_n_g___r_e_t; _v_e_n_d_o_r A string specifying the session manager vendor. _r_e_l_e_a_s_e A string specifying the session manager release number. _n_e_w___c_l_i_e_n_t___p_r_o_c Callback to be invoked each time a new client con‐ nects to the session manager. _m_a_n_a_g_e_r___d_a_t_a When the _S_m_s_N_e_w_C_l_i_e_n_t_P_r_o_c callback is invoked, this pointer to manager data will be passed. _h_o_s_t___b_a_s_e_d___a_u_t_h___p_r_o_c − 20 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 Host based authentication callback. _e_r_r_o_r___l_e_n_g_t_h Length of the error_string_ret argument passed in. _e_r_r_o_r___s_t_r_i_n_g___r_e_t Returns a null‐terminated error message, if any. The error_string_ret points to user supplied mem‐ ory. No more than error_length bytes are used. ││__ After the _S_m_s_I_n_i_t_i_a_l_i_z_e function is called, the session man‐ ager should call the _I_c_e_L_i_s_t_e_n_F_o_r_C_o_n_n_e_c_t_i_o_n_s function to listen for new connections. Afterwards, each time a client connects, the session manager should call _I_c_e_A_c_c_e_p_t_C_o_n_n_e_c_‐ _t_i_o_n. See section 9, ‘‘Authentication of Clients,’’ for more details on authentication (including host based authentica‐ tion). Also see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard for further details on listening for and accepting ICE con‐ nections. Each time a new client connects to the session manager, the _S_m_s_N_e_w_C_l_i_e_n_t_P_r_o_c callback is invoked. The session manager obtains a new opaque connection object that it should use for all future interaction with the client. At this time, the session manager must also register a set of callbacks to respond to the different messages that the client might send. __ ││ typedef Status (*SmsNewClientProc)(); Status NewClientProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _m_a_s_k___r_e_t, _c_a_l_l_b_a_c_k_s___r_e_t, _f_a_i_l_u_r_e___r_e_a_s_o_n___r_e_t) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; unsigned long *_m_a_s_k___r_e_t; SmsCallbacks *_c_a_l_l_b_a_c_k_s___r_e_t; char **_f_a_i_l_u_r_e___r_e_a_s_o_n___r_e_t; _s_m_s___c_o_n_n A new opaque connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _m_a_s_k___r_e_t On return, indicates which callbacks were set by the session manager. _c_a_l_l_b_a_c_k_s___r_e_t On return, contains the callbacks registered by the session manager. − 21 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _f_a_i_l_u_r_e___r_e_a_s_o_n___r_e_t Failure reason returned. ││__ If a failure occurs, the _S_m_s_N_e_w_C_l_i_e_n_t_P_r_o_c should return a zero status as well as allocate and return a failure reason string in failure_reason_ret. SMlib will be responsible for freeing this memory. The session manager must register a set of callbacks to respond to client events. The mask_ret argument specifies which callbacks are set. All of the callbacks specified in this version of SMlib are mandatory. The mask_ret argument is necessary in order to maintain backwards compatibility in future versions of the library. The following values may be ORed together to obtain a mask value: _S_m_s_R_e_g_i_s_t_e_r_C_l_i_e_n_t_P_r_o_c_M_a_s_k _S_m_s_I_n_t_e_r_a_c_t_R_e_q_u_e_s_t_P_r_o_c_M_a_s_k _S_m_s_I_n_t_e_r_a_c_t_D_o_n_e_P_r_o_c_M_a_s_k _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_R_e_q_u_e_s_t_P_r_o_c_M_a_s_k _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_P_2_R_e_q_u_e_s_t_P_r_o_c_M_a_s_k _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e_P_r_o_c_M_a_s_k _S_m_s_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n_P_r_o_c_M_a_s_k _S_m_s_S_e_t_P_r_o_p_e_r_t_i_e_s_P_r_o_c_M_a_s_k _S_m_s_D_e_l_e_t_e_P_r_o_p_e_r_t_i_e_s_P_r_o_c_M_a_s_k _S_m_s_G_e_t_P_r_o_p_e_r_t_i_e_s_P_r_o_c_M_a_s_k For each callback, the session manager can register a pointer to manager data specific to that callback. This pointer will be passed to the callback when it is invoked by SMlib. __ ││ typedef struct { struct { SmsRegisterClientProc callback; SmPointer manager_data; } register_client; struct { SmsInteractRequestProc callback; SmPointer manager_data; } interact_request; struct { SmsInteractDoneProc callback; SmPointer manager_data; } interact_done; − 22 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 struct { SmsSaveYourselfRequestProc callback; SmPointer manager_data; } save_yourself_request; struct { SmsSaveYourselfPhase2RequestProc callback; SmPointer manager_data; } save_yourself_phase2_request; struct { SmsSaveYourselfDoneProc callback; SmPointer manager_data; } save_yourself_done; struct { SmsCloseConnectionProc callback; SmPointer manager_data; } close_connection; struct { SmsSetPropertiesProc callback; SmPointer manager_data; } set_properties; struct { SmsDeletePropertiesProc callback; SmPointer manager_data; } delete_properties; struct { SmsGetPropertiesProc callback; SmPointer manager_data; } get_properties; } SmsCallbacks; ││__ _6_._1_._1_. _T_h_e _R_e_g_i_s_t_e_r _C_l_i_e_n_t _C_a_l_l_b_a_c_k The Register Client callback is the first callback that will be invoked after the client connects to the session manager. Its type is _S_m_s_R_e_g_i_s_t_e_r_C_l_i_e_n_t_P_r_o_c. __ ││ typedef Status (*SmsRegisterClientProc(); Status RegisterClientProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _p_r_e_v_i_o_u_s___i_d) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; char *_p_r_e_v_i_o_u_s___i_d; − 23 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _p_r_e_v_i_o_u_s___i_dThe client ID from the previous session. ││__ Before any further interaction takes place with the client, the client must be registered with the session manager. If the client is being restarted from a previous session, previous_id will contain a null‐terminated string represent‐ ing the client ID from the previous session. Call _f_r_e_e on the previous_id pointer when it is no longer needed. If the client is first joining the session, previous_id will be NULL. If previous_id is invalid, the session manager should not register the client at this time. This callback should return a status of zero, which will cause an error message to be sent to the client. The client should re‐register with previous_id set to NULL. Otherwise, the session manager should register the client with a unique client ID by calling the _S_m_s_R_e_g_i_s_t_e_r_C_l_i_e_n_t_R_e_‐ _p_l_y function (to be discussed shortly), and the _S_m_s_R_e_g_i_s_t_e_r_‐ _C_l_i_e_n_t_P_r_o_c callback should return a status of one. _6_._1_._2_. _T_h_e _I_n_t_e_r_a_c_t _R_e_q_u_e_s_t _C_a_l_l_b_a_c_k The Interact Request callback is of type _S_m_s_I_n_t_e_r_a_c_t_R_e_q_u_e_s_t_‐ _P_r_o_c. __ ││ typedef void (*SmsInteractRequestProc)(); void InteractRequestProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _d_i_a_l_o_g___t_y_p_e) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; int _d_i_a_l_o_g___t_y_p_e; _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _d_i_a_l_o_g___t_y_p_eThe type of dialog the client wishes to present to the user. ││__ − 24 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 When a client receives a ‘‘Save Yourself’’ message with an interact_style of _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_E_r_r_o_r_s or _S_m_I_n_t_e_r_a_c_t_‐ _S_t_y_l_e_A_n_y, the client may choose to interact with the user. Because only one client can interact with the user at a time, the client must request to interact with the user. The session manager should keep a queue of all clients wish‐ ing to interact. It should send an ‘‘Interact’’ message to one client at a time and wait for an ‘‘Interact Done’’ mes‐ sage before continuing with the next client. The dialog_type argument specifies either _S_m_D_i_a_l_o_g_E_r_r_o_r, indicating that the client wants to start an error dialog, or _S_m_D_i_a_l_o_g_N_o_r_m_a_l, meaning that the client wishes to start a nonerror dialog. If a shutdown is in progress, the user may have the option of cancelling the shutdown. If the shutdown is cancelled (specified in the ‘‘Interact Done’’ message), the session manager should send a ‘‘Shutdown Cancelled’’ message to each client that requested to interact. _6_._1_._3_. _T_h_e _I_n_t_e_r_a_c_t _D_o_n_e _C_a_l_l_b_a_c_k When the client is done interacting with the user, the _S_m_s_I_n_t_e_r_a_c_t_D_o_n_e_P_r_o_c callback will be invoked. __ ││ typedef void (*SmsInteractDoneProc)(); void InteractDoneProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _c_a_n_c_e_l___s_h_u_t_d_o_w_n) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; Bool _c_a_n_c_e_l___s_h_u_t_d_o_w_n; _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _c_a_n_c_e_l___s_h_u_t_d_o_w_n Specifies if the user requests that the entire shutdown be cancelled. ││__ Note that the shutdown can be cancelled only if the corre‐ sponding ‘‘Save Yourself’’ specified _T_r_u_e for shutdown and _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_E_r_r_o_r_s or _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_A_n_y for the inter‐ act_style. _6_._1_._4_. _T_h_e _S_a_v_e _Y_o_u_r_s_e_l_f _R_e_q_u_e_s_t _C_a_l_l_b_a_c_k The Save Yourself Request callback is of type − 25 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_R_e_q_u_e_s_t_P_r_o_c. __ ││ typedef void (*SmsSaveYourselfRequestProc)(); void SaveYourselfRequestProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _s_a_v_e___t_y_p_e, _s_h_u_t_d_o_w_n, _i_n_t_e_r_a_c_t___s_t_y_l_e, _f_a_s_t, _g_l_o_b_a_l) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; int _s_a_v_e___t_y_p_e; Bool _s_h_u_t_d_o_w_n; int _i_n_t_e_r_a_c_t___s_t_y_l_e; Bool _f_a_s_t; Bool _g_l_o_b_a_l; _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _s_a_v_e___t_y_p_e Specifies the type of information that should be saved. _s_h_u_t_d_o_w_n Specifies if a shutdown is taking place. _i_n_t_e_r_a_c_t___s_t_y_l_e The type of interaction allowed with the user. _f_a_s_t If _T_r_u_e, the client should save its state as quickly as possible. _g_l_o_b_a_l Controls who gets the ‘‘Save Yourself.’’ ││__ The Save Yourself Request prompts the session manager to initiate a checkpoint or shutdown. For information on the save_type, shutdown, interact_style, and fast arguments, see section 6.3, ‘‘Sending a Save Yourself Message.’’ If global is set to _T_r_u_e, then the resulting ‘‘Save Your‐ self’’ should be sent to all applications. If global is set to _F_a_l_s_e, then the ‘‘Save Yourself’’ should only be sent to the client that requested it. _6_._1_._5_. _T_h_e _S_a_v_e _Y_o_u_r_s_e_l_f _P_h_a_s_e _2 _R_e_q_u_e_s_t _C_a_l_l_b_a_c_k The Save Yourself Phase 2 Request callback is of type _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_P_h_a_s_e_2_R_e_q_u_e_s_t_P_r_o_c. __ ││ − 26 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 typedef void (*SmsSaveYourselfPhase2RequestProc)(); void SmsSaveYourselfPhase2RequestProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. ││__ This request is sent by clients that manage other clients (for example, window managers, workspace managers, and so on). Such managers must make sure that all of the clients that are being managed are in an idle state so that their state can be saved. _6_._1_._6_. _T_h_e _S_a_v_e _Y_o_u_r_s_e_l_f _D_o_n_e _C_a_l_l_b_a_c_k When the client is done saving its state in response to a ‘‘Save Yourself’’ message, the _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_D_o_n_e_P_r_o_c will be invoked. __ ││ typedef void (*SmsSaveYourselfDoneProc)(); void SaveYourselfDoneProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _s_u_c_c_e_s_s) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; Bool _s_u_c_c_e_s_s; _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _s_u_c_c_e_s_s If _T_r_u_e, the Save Yourself operation was completed successfully. ││__ Before the ‘‘Save Yourself Done’’ was sent, the client must have set each required property at least once since it reg‐ istered with the session manager. _6_._1_._7_. _T_h_e _C_o_n_n_e_c_t_i_o_n _C_l_o_s_e_d _C_a_l_l_b_a_c_k If the client properly terminates (that is, it calls _S_m_c_‐ _C_l_o_s_e_C_o_n_n_e_c_t_i_o_n), the _S_m_s_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n_P_r_o_c callback is − 27 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 invoked. __ ││ typedef void (*SmsCloseConnectionProc)(); void CloseConnectionProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _c_o_u_n_t, _r_e_a_s_o_n___m_s_g_s) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; int _c_o_u_n_t; char **_r_e_a_s_o_n___m_s_g_s; _s_m_s___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _c_o_u_n_t The number of reason messages. _r_e_a_s_o_n___m_s_g_sThe reasons for closing the connection. ││__ The reason_msgs argument will most likely be NULL and the count argument zero (0) if resignation is expected by the user. Otherwise, it contains a list of null‐terminated Com‐ pound Text strings representing the reason for termination. The session manager should display these reason messages to the user. Call _S_m_F_r_e_e_R_e_a_s_o_n_s to free the reason messages. For further information, see section 8, ‘‘Freeing Data.’’ _6_._1_._8_. _T_h_e _S_e_t _P_r_o_p_e_r_t_i_e_s _C_a_l_l_b_a_c_k When the client sets session management properties, the _S_m_s_‐ _S_e_t_P_r_o_p_e_r_t_i_e_s_P_r_o_c callback will be invoked. __ ││ typedef void (*SmsSetPropertiesProc)(); void SetPropertiesProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _n_u_m___p_r_o_p_s, _p_r_o_p_s) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; int _n_u_m___p_r_o_p_s; SmProp **_p_r_o_p_s; _s_m_c___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. − 28 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _n_u_m___p_r_o_p_s The number of properties. _p_r_o_p_s The list of properties to set. ││__ The properties are specified as an array of property point‐ ers. For a description of session management properties and the _S_m_P_r_o_p structure, see section 7, ‘‘Session Management Properties.’’ Previously set property values may be over‐written. Some properties have predefined semantics. The session manager is required to store nonpredefined properties. To free each property, use _S_m_F_r_e_e_P_r_o_p_e_r_t_y. For further information, see section 8, ‘‘Freeing Data.’’ You should free the actual array of pointers with a call to _f_r_e_e. _6_._1_._9_. _T_h_e _D_e_l_e_t_e _P_r_o_p_e_r_t_i_e_s _C_a_l_l_b_a_c_k When the client deletes session management properties, the _S_m_s_D_e_l_e_t_e_P_r_o_p_e_r_t_i_e_s_P_r_o_c callback will be invoked. __ ││ typedef void (*SmsDeletePropertiesProc)(); void DeletePropertiesProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a, _n_u_m___p_r_o_p_s, _p_r_o_p___n_a_m_e_s) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; int _n_u_m___p_r_o_p_s; char **_p_r_o_p___n_a_m_e_s; _s_m_c___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. _n_u_m___p_r_o_p_s The number of properties. _p_r_o_p___n_a_m_e_sThe list of properties to delete. ││__ The properties are specified as an array of strings. For a description of session management properties and the _S_m_P_r_o_p structure, see section 7, ‘‘Session Management Properties.’’ _6_._1_._1_0_. _T_h_e _G_e_t _P_r_o_p_e_r_t_i_e_s _C_a_l_l_b_a_c_k The _S_m_s_G_e_t_P_r_o_p_e_r_t_i_e_s_P_r_o_c callback is invoked when the client − 29 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 wants to retrieve properties it set. __ ││ typedef void (*SmsGetPropertiesProc)(); void GetPropertiesProc(_s_m_s___c_o_n_n, _m_a_n_a_g_e_r___d_a_t_a) SmsConn _s_m_s___c_o_n_n; SmPointer _m_a_n_a_g_e_r___d_a_t_a; _s_m_c___c_o_n_n The session management connection object. _m_a_n_a_g_e_r___d_a_t_a Manager data specified when the callback was reg‐ istered. ││__ The session manager should respond by calling _S_m_s_R_e_t_u_r_n_P_r_o_p_‐ _e_r_t_i_e_s. All of the properties set for this client should be returned. _6_._2_. _R_e_g_i_s_t_e_r_i_n_g _t_h_e _C_l_i_e_n_t To register a client (in response to a _S_m_s_R_e_g_i_s_t_e_r_C_l_i_e_n_t_P_r_o_c callback), use _S_m_s_R_e_g_i_s_t_e_r_C_l_i_e_n_t_R_e_p_l_y. __ ││ Status SmsRegisterClientReply(_s_m_s___c_o_n_n, _c_l_i_e_n_t___i_d) SmsConn _s_m_s___c_o_n_n; char *_c_l_i_e_n_t___i_d; _s_m_s___c_o_n_n The session management connection object. _c_l_i_e_n_t___i_d A null‐terminated string representing a unique client ID. ││__ The return value of _S_m_s_R_e_g_i_s_t_e_r_C_l_i_e_n_t_R_e_p_l_y is zero for fail‐ ure and a positive value for success. Failure will occur if SMlib can not allocate memory to hold a copy of the client ID for it’s own internal needs. If a non‐NULL previous_id was specified when the client reg‐ istered itself, client_id should be identical to previ‐ ous_id. Otherwise, client_id should be a unique ID freshly generated by the session manager. In addition, the session manager should send a ‘‘Save Yourself’’ message with type = Local, shutdown = False, interact‐style = None, and fast = False immediately after registering the client. Note that once a client ID has been assigned to the client, − 30 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 the client keeps this ID indefinitely. If the client is terminated and restarted, it will be reassigned the same ID. It is desirable to be able to pass client IDs around from machine to machine, from user to user, and from session man‐ ager to session manager, while retaining the identity of the client. This, combined with the indefinite persistence of client IDs, means that client IDs need to be globally unique. You should call the _S_m_s_G_e_n_e_r_a_t_e_C_l_i_e_n_t_I_D function to generate a globally unique client ID. __ ││ char *SmsGenerateClientID(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; _s_m_s___c_o_n_n The session management connection object. ││__ NULL will be returned if the ID could not be generated. Otherwise, the return value of the function is the client ID. It should be freed with a call to _f_r_e_e when no longer needed. _6_._3_. _S_e_n_d_i_n_g _a _S_a_v_e _Y_o_u_r_s_e_l_f _M_e_s_s_a_g_e To send a ‘‘Save Yourself’’ to a client, use _S_m_s_S_a_v_e_Y_o_u_r_‐ _s_e_l_f. __ ││ void SmsSaveYourself(_s_m_s___c_o_n_n, _s_a_v_e___t_y_p_e, _s_h_u_t_d_o_w_n, _i_n_t_e_r_a_c_t___s_t_y_l_e, _f_a_s_t) SmsConn _s_m_s___c_o_n_n; int _s_a_v_e___t_y_p_e; Bool _s_h_u_t_d_o_w_n; int _i_n_t_e_r_a_c_t___s_t_y_l_e; Bool _f_a_s_t; _s_m_s___c_o_n_n The session management connection object. _s_a_v_e___t_y_p_e Specifies the type of information that should be saved. _s_h_u_t_d_o_w_n Specifies if a shutdown is taking place. _i_n_t_e_r_a_c_t___s_t_y_l_e The type of interaction allowed with the user. _f_a_s_t If _T_r_u_e, the client should save its state as quickly as possible. ││__ The session manager sends a ‘‘Save Yourself’’ message to a − 31 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 client either to checkpoint it or just before termination so that it can save its state. The client responds with zero or more ‘‘Set Properties’’ messages to update the properties indicating how to restart the client. When all the proper‐ ties have been set, the client sends a ‘‘Save Yourself Done’’ message. If interact_style is _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_N_o_n_e, the client must not interact with the user while saving state. If inter‐ act_style is _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_E_r_r_o_r_s, the client may interact with the user only if an error condition arises. If inter‐ act_style is _S_m_I_n_t_e_r_a_c_t_S_t_y_l_e_A_n_y, then the client may inter‐ act with the user for any purpose. The client must send an ‘‘Interact Request’’ message and wait for an ‘‘Interact’’ message from the session manager before it can interact with the user. When the client is done interacting with the user, it should send an ‘‘Interact Done’’ message. The ‘‘Interact Request’’ message can be sent any time after a ‘‘Save Yourself’’ and before a ‘‘Save Yourself Done.’’ If save_type is _S_m_S_a_v_e_L_o_c_a_l, the client must update the properties to reflect its current state. Specifically, it should save enough information to restore the state as seen by the user of this client. It should not affect the state as seen by other users. If save_type is _S_m_S_a_v_e_G_l_o_b_a_l the user wants the client to commit all of its data to perma‐ nent, globally accessible storage. If save_type is _S_m_S_a_v_e_‐ _B_o_t_h, the client should do both of these (it should first commit the data to permanent storage before updating its properties). The shutdown argument specifies whether the session is being shut down. The interaction is different depending on whether or not shutdown is set. If not shutting down, then the client can save and resume normal operation. If shut‐ ting down, the client must save and then must prevent inter‐ action until it receives either a ‘‘Die’’ or a ‘‘Shutdown Cancelled,’’ because anything the user does after the save will be lost. The fast argument specifies that the client should save its state as quickly as possible. For example, if the session manager knows that power is about to fail, it should set fast to _T_r_u_e. _6_._4_. _S_e_n_d_i_n_g _a _S_a_v_e _Y_o_u_r_s_e_l_f _P_h_a_s_e _2 _M_e_s_s_a_g_e In order to send a ‘‘Save Yourself Phase 2’’ message to a client, use _S_m_s_S_a_v_e_Y_o_u_r_s_e_l_f_P_h_a_s_e_2. __ ││ void SmsSaveYourselfPhase2(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; − 32 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _s_m_s___c_o_n_n The session management connection object. ││__ The session manager sends this message to a client that has previously sent a ‘‘Save Yourself Phase 2 Request’’ message. This message informs the client that all other clients are in a fixed state and this client can save state that is associated with other clients. _6_._5_. _S_e_n_d_i_n_g _a_n _I_n_t_e_r_a_c_t _M_e_s_s_a_g_e To send an ‘‘Interact’’ message to a client, use _S_m_s_I_n_t_e_r_‐ _a_c_t. __ ││ void SmsInteract(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; _s_m_s___c_o_n_n The session management connection object. ││__ The ‘‘Interact’’ message grants the client the privilege of interacting with the user. When the client is done inter‐ acting with the user, it must send an ‘‘Interact Done’’ mes‐ sage to the session manager. _6_._6_. _S_e_n_d_i_n_g _a _S_a_v_e _C_o_m_p_l_e_t_e _M_e_s_s_a_g_e To send a ‘‘Save Complete’’ message to a client, use _S_m_s_S_a_v_e_C_o_m_p_l_e_t_e. __ ││ void SmsSaveComplete(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; _s_m_s___c_o_n_n The session management connection object. ││__ The session manager sends this message when it is done with a checkpoint. The client is then free to change its state. _6_._7_. _S_e_n_d_i_n_g _a _D_i_e _M_e_s_s_a_g_e To send a ‘‘Die’’ message to a client, use _S_m_s_D_i_e. __ ││ void SmsDie(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; _s_m_s___c_o_n_n The session management connection object. − 33 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ││__ Before the session manager terminates, it should wait for a ‘‘Connection Closed’’ message from each client that it sent a ‘‘Die’’ message to, timing out appropriately. _6_._8_. _C_a_n_c_e_l_l_i_n_g _a _S_h_u_t_d_o_w_n To cancel a shutdown, use _S_m_s_S_h_u_t_d_o_w_n_C_a_n_c_e_l_l_e_d. __ ││ void SmsShutdownCancelled(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; _s_m_s___c_o_n_n The session management connection object. ││__ The client can now continue as if the shutdown had never happened. If the client has not sent a ‘‘Save Yourself Done’’ message yet, it can either abort the save and send a ‘‘Save Yourself Done’’ with the success argument set to _F_a_l_s_e, or it can continue with the save and send a ‘‘Save Yourself Done’’ with the success argument set to reflect the outcome of the save. _6_._9_. _R_e_t_u_r_n_i_n_g _P_r_o_p_e_r_t_i_e_s In response to a ‘‘Get Properties’’ message, the session manager should call _S_m_s_R_e_t_u_r_n_P_r_o_p_e_r_t_i_e_s. __ ││ void SmsReturnProperties(_s_m_s___c_o_n_n, _n_u_m___p_r_o_p_s, _p_r_o_p_s) SmsConn _s_m_s___c_o_n_n; int _n_u_m___p_r_o_p_s; SmProp **_p_r_o_p_s; _s_m_s___c_o_n_n The session management connection object. _n_u_m___p_r_o_p_s The number of properties. _p_r_o_p_s The list of properties to return to the client. ││__ The properties are returned as an array of property point‐ ers. For a description of session management properties and the _S_m_P_r_o_p structure, see section 7, ‘‘Session Management Properties.’’ _6_._1_0_. _P_i_n_g_i_n_g _a _C_l_i_e_n_t To check that a client is still alive, you should use the _I_c_e_P_i_n_g function provided by the ICE library. To do so, the − 34 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ICE connection must be obtained using the _S_m_s_G_e_t_I_c_e_C_o_n_n_e_c_‐ _t_i_o_n (see section 6.12, ‘‘Using Sms Informational Func‐ tions’’). __ ││ void IcePing(_i_c_e___c_o_n_n, _p_i_n_g___r_e_p_l_y___p_r_o_c, _c_l_i_e_n_t___d_a_t_a) IceConn _i_c_e___c_o_n_n; IcePingReplyProc _p_i_n_g___r_e_p_l_y___p_r_o_c; IcePointer _c_l_i_e_n_t___d_a_t_a; _i_c_e___c_o_n_n A valid ICE connection object. _p_i_n_g___r_e_p_l_y___p_r_o_c The callback to invoke when the Ping reply arrives. _c_l_i_e_n_t___d_a_t_aThis pointer will be passed to the _I_c_e_P_i_n_g_R_e_‐ _p_l_y_P_r_o_c callback. ││__ When the Ping reply is ready (if ever), the _I_c_e_P_i_n_g_R_e_p_l_y_P_r_o_c callback will be invoked. A session manager should have some sort of timeout period, after which it assumes the client has unexpectedly died. __ ││ typedef void (*IcePingReplyProc)(); void PingReplyProc(_i_c_e___c_o_n_n, _c_l_i_e_n_t___d_a_t_a) IceConn _i_c_e___c_o_n_n; IcePointer _c_l_i_e_n_t___d_a_t_a; _i_c_e___c_o_n_n The ICE connection object. _c_l_i_e_n_t___d_a_t_aThe client data specified in the call to _I_c_e_P_i_n_g. ││__ _6_._1_1_. _C_l_e_a_n_i_n_g _U_p _A_f_t_e_r _a _C_l_i_e_n_t _D_i_s_c_o_n_n_e_c_t_s When the session manager receives a ‘‘Connection Closed’’ message or otherwise detects that the client aborted the connection, it should call the _S_m_s_C_l_e_a_n_U_p function in order to free up the connection object. __ ││ void SmsCleanUp(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; − 35 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _s_m_s___c_o_n_n The session management connection object. ││__ _6_._1_2_. _U_s_i_n_g _S_m_s _I_n_f_o_r_m_a_t_i_o_n_a_l _F_u_n_c_t_i_o_n_s __ ││ int SmsProtocolVersion(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; ││__ _S_m_s_P_r_o_t_o_c_o_l_V_e_r_s_i_o_n returns the major version of the session management protocol associated with this session. __ ││ int SmsProtocolRevision(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; ││__ _S_m_s_P_r_o_t_o_c_o_l_R_e_v_i_s_i_o_n returns the minor version of the session management protocol associated with this session. __ ││ char *SmsClientID(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; ││__ _S_m_s_C_l_i_e_n_t_I_D returns a null‐terminated string for the client ID associated with this connection. You should call _f_r_e_e on this pointer when the client ID is no longer needed. To obtain the host name of a client, use _S_m_s_C_l_i_e_n_t_H_o_s_t_N_a_m_e. This host name will be needed to restart the client. __ ││ char *SmsClientHostName(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; ││__ The string returned is of the form _p_r_o_t_o_c_o_l/_h_o_s_t_n_a_m_e, where _p_r_o_t_o_c_o_l is one of {tcp, decnet, local}. You should call _f_r_e_e on the string returned when it is no longer needed. − 36 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 __ ││ IceConn SmsGetIceConnection(_s_m_s___c_o_n_n) SmsConn _s_m_s___c_o_n_n; ││__ _S_m_s_G_e_t_I_c_e_C_o_n_n_e_c_t_i_o_n returns the ICE connection object asso‐ ciated with this session management connection object. The ICE connection object can be used to get some additional information about the connection. Some of the more useful functions which can be used on the IceConn are _I_c_e_C_o_n_n_e_c_‐ _t_i_o_n_N_u_m_b_e_r, and _I_c_e_L_a_s_t_S_e_q_u_e_n_c_e_N_u_m_b_e_r. For further informa‐ tion, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. _6_._1_3_. _E_r_r_o_r _H_a_n_d_l_i_n_g If the session manager receives an unexpected protocol error from a client, an error handler is invoked by SMlib. A default error handler exists which simply prints the error message (it does not exit). The session manager can change this error handler by calling _S_m_s_S_e_t_E_r_r_o_r_H_a_n_d_l_e_r. __ ││ SmsErrorHandler SmsSetErrorHandler(_h_a_n_d_l_e_r) SmsErrorHandler _h_a_n_d_l_e_r; _h_a_n_d_l_e_r The error handler. You should pass NULL to restore the default handler. ││__ _S_m_s_S_e_t_E_r_r_o_r_H_a_n_d_l_e_r returns the previous error handler. The _S_m_s_E_r_r_o_r_H_a_n_d_l_e_r has the following type: __ ││ typedef void (*SmsErrorHandler)(); void ErrorHandler(_s_m_s___c_o_n_n, _s_w_a_p, _o_f_f_e_n_d_i_n_g___m_i_n_o_r___o_p_c_o_d_e, _o_f_f_e_n_d_i_n_g___s_e_q_u_e_n_c_e___n_u_m, _e_r_r_o_r___c_l_a_s_s, _s_e_v_e_r_i_t_y, _v_a_l_u_e_s) SmsConn _s_m_s___c_o_n_n; Bool _s_w_a_p; int _o_f_f_e_n_d_i_n_g___m_i_n_o_r___o_p_c_o_d_e; unsigned long _o_f_f_e_n_d_i_n_g___s_e_q_u_e_n_c_e___n_u_m; int _e_r_r_o_r___c_l_a_s_s; int _s_e_v_e_r_i_t_y; IcePointer _v_a_l_u_e_s; _s_m_s___c_o_n_n The session management connection object. _s_w_a_p A flag which indicates if the specified values need byte swapping. _o_f_f_e_n_d_i_n_g___m_i_n_o_r___o_p_c_o_d_e The minor opcode of the offending message. − 37 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 _o_f_f_e_n_d_i_n_g___s_e_q_u_e_n_c_e___n_u_m The sequence number of the offending message. _e_r_r_o_r___c_l_a_s_sThe error class of the offending message. _s_e_v_e_r_i_t_y _I_c_e_C_a_n_C_o_n_t_i_n_u_e, _I_c_e_F_a_t_a_l_T_o_P_r_o_t_o_c_o_l, or _I_c_e_F_a_t_a_l_T_o_‐ _C_o_n_n_e_c_t_i_o_n. _v_a_l_u_e_s Any additional error values specific to the minor opcode and class. ││__ Note that this error handler is invoked for protocol related errors. To install an error handler to be invoked when an IO error occurs, use _I_c_e_S_e_t_I_O_E_r_r_o_r_H_a_n_d_l_e_r. For further information, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. _7_. _S_e_s_s_i_o_n _M_a_n_a_g_e_m_e_n_t _P_r_o_p_e_r_t_i_e_s Each property is defined by the _S_m_P_r_o_c structure: typedef struct { char *name; /* name of property */ char *type; /* type of property */ int num_vals; /* number of values */ SmPropValue *vals; /* the list of values */ } SmProp; typedef struct { int length; /* the length of the value */ SmPointer value; /* the value */ } SmPropValue; The X Session Management Protocol defines a list of prede‐ fined properties, several of which are required to be set by the client. The following table specifies the predefined properties and indicates which ones are required. Each property has a type associated with it. A type of SmCARD8 indicates that there is a single 1‐byte value. A type of SmARRAY8 indicates that there is a single array of bytes. A type of SmLISTofARRAY8 indicates that there is a list of array of bytes. ───────────────────────────────────────────────────────────── _N_a_m_e _T_y_p_e _P_O_S_I_X _T_y_p_e _R_e_q_u_i_r_e_d ───────────────────────────────────────────────────────────── SmCloneCommand OS‐specific SmLISTofARRAY8 Yes SmCurrentDirectory OS‐specific SmARRAY8 No SmDiscardCommand OS‐specific SmLISTofARRAY8 No* − 38 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 ───────────────────────────────────────────────────────────── _N_a_m_e _T_y_p_e _P_O_S_I_X _T_y_p_e _R_e_q_u_i_r_e_d ───────────────────────────────────────────────────────────── SmEnvironment OS‐specific SmLISTofARRAY8 No SmProcessID OS‐specific SmARRAY8 No SmProgram OS‐specific SmARRAY8 Yes SmRestartCommand OS‐specific SmLISTofARRAY8 Yes SmResignCommand OS‐specific SmLISTofARRAY8 No SmRestartStyleHint SmCARD8 SmCARD8 No SmShutdownCommand OS‐specific SmLISTofARRAY8 No SmUserID SmARRAY8 SmARRAY8 Yes ───────────────────────────────────────────────────────────── * Required if any state is stored in an external repository (for example, state file). · SmCloneCommand This is like the SmRestartCommand, except it restarts a copy of the application. The only difference is that the application does not supply its client ID at regis‐ ter time. On POSIX systems, this should be of type SmLISTofARRAY8. · SmCurrentDirectory On POSIX‐based systems, this specifies the value of the current directory that needs to be set up prior to starting the SmProgram and should of type SmARRAY8. · SmDiscardCommand The discard command contains a command that when deliv‐ ered to the host that the client is running on (deter‐ mined from the connection), will cause it to discard any information about the current state. If this com‐ mand is not specified, the Session Manager will assume that all of the client’s state is encoded in the SmRestartCommand. On POSIX systems, the type should be SmLISTofARRAY8. · SmEnvironment On POSIX based systems, this will be of type SmLISTo‐ fARRAY8, where the ARRAY8s alternate between environ‐ ment variable name and environment variable value. · SmProcessID This specifies an OS‐specific identifier for the process. On POSIX systems, this should contain the return value of _g_e_t_p_i_d turned into a Latin‐1 (decimal) string. − 39 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 · SmProgram This is the name of the program that is running. On POSIX systems, this should be first parameter passed to _e_x_e_c_v_e and should be of type SmARRAY8. · SmRestartCommand The restart command contains a command that, when delivered to the host that the client is running on (determined from the connection), will cause the client to restart in its current state. On POSIX‐based sys‐ tems, this is of type SmLISTofARRAY8, and each of the elements in the array represents an element in the _a_r_g_v array. This restart command should ensure that the client restarts with the specified client‐ID. · SmResignCommand A client that sets the SmRestartStyleHint to SmRestar‐ tAnway uses this property to specify a command that undoes the effect of the client and removes any saved state. As an example, consider a user that runs _x_m_o_d_m_a_p, which registers with the Session Manager, sets SmRestartStyleHint to SmRestartAnyway, and then termi‐ nates. To allow the Session Manager (at the user’s request) to undo this, _x_m_o_d_m_a_p would register a SmRe‐ signCommand that undoes the effects of the _x_m_o_d_m_a_p. · SmRestartStyleHint If the RestartStyleHint property is present, it will contain the style of restarting the client prefers. If this style is not specified, SmRestartIfRunning is assumed. The possible values are as follows: ───────────────────────────── _N_a_m_e _V_a_l_u_e ───────────────────────────── SmRestartIfRunning 0 SmRestartAnyway 1 SmRestartImmediately 2 SmRestartNever 3 ───────────────────────────── The SmRestartIfRunning style is used in the usual case. The client should be restarted in the next session if it was running at the end of the current session. The SmRestartAnyway style is used to tell the Session Manager that the application should be restarted in the next session even if it exits before the current ses‐ sion is terminated. It should be noted that this is − 40 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 only a hint and the Session Manager will follow the policies specified by its users in determining what applications to restart. A client that uses SmRestartAnyway should also set the SmResignCommand and SmShutdownCommand properties to commands that undo the state of the client after it exits. The SmRestartImmediately style is like SmRestartAnyway, but, in addition, the client is meant to run continu‐ ously. If the client exits, the Session Manager should try to restart it in the current session. SmRestartNever style specifies that the client does not wish to be restarted in the next session. · SmShutdownCommand This command is executed at shutdown time to clean up after a client that is no longer running but retained its state by setting SmRestartStyleHint to SmRestar‐ tAnyway. The client must not remove any saved state as the client is still part of the session. As an exam‐ ple, consider a client that turns on a camera at start up time. This client then exits. At session shutdown, the user wants the camera turned off. This client would set the SmRestartStyleHint to SmRestartAnyway and would register a SmShutdownCommand that would turn off the camera. · SmUserID Specifies the user ID. On POSIX‐based systems, this will contain the user’s name (the pw_name member of struct _p_a_s_s_w_d). _8_. _F_r_e_e_i_n_g _D_a_t_a To free an individual property, use _S_m_F_r_e_e_P_r_o_p_e_r_t_y. __ ││ void SmFreeProperty(_p_r_o_p) SmProp *_p_r_o_p; _p_r_o_p The property to free. ││__ To free the reason strings from the _S_m_s_C_l_o_s_e_C_o_n_n_e_c_t_i_o_n_P_r_o_c − 41 − XX SSeessssiioonn MMaannaaggeemmeenntt LLiibbrraarryy lliibbSSMM 11..11..11 callback, use _S_m_F_r_e_e_R_e_a_s_o_n_s. __ ││ void SmFreeReasons(_c_o_u_n_t, _r_e_a_s_o_n_s) int _c_o_u_n_t; char **_r_e_a_s_o_n_s; _c_o_u_n_t The number of reason strings. _r_e_a_s_o_n_s The list of reason strings to free. ││__ _9_. _A_u_t_h_e_n_t_i_c_a_t_i_o_n _o_f _C_l_i_e_n_t_s As stated earlier, the session management protocol is lay‐ ered on top of ICE. Authentication occurs at two levels in the ICE protocol: · The first is when an ICE connection is opened. · The second is when a Protocol Setup occurs on an ICE connection. The authentication methods that are available are implemen‐ tation‐dependent (that is., dependent on the ICElib and SMlib implementations in use). For further information, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. _1_0_. _W_o_r_k_i_n_g _i_n _a _M_u_l_t_i_‐_T_h_r_e_a_d_e_d _E_n_v_i_r_o_n_m_e_n_t To declare that multiple threads in an application will be using SMlib (or any other library layered on top of ICElib), you should call _I_c_e_I_n_i_t_T_h_r_e_a_d_s. For further information, see the _I_n_t_e_r_‐_C_l_i_e_n_t _E_x_c_h_a_n_g_e _L_i_b_r_a_r_y standard. _1_1_. _A_c_k_n_o_w_l_e_d_g_e_m_e_n_t_s Thanks to the following people for their participation in the X Session Management design: Jordan Brown, Ellis Cohen, Donna Converse, Stephen Gildea, Vania Joloboff, Stuart Marks, Bob Scheifler, Ralph Swick, and Mike Wexler. − 42 − TTaabbllee ooff CCoonntteennttss 1. Overview of Session Management ..................... 1 2. The Session Management Library ..................... 1 3. Understanding SMlib’s Dependence on ICE ............ 2 4. Header Files and Library Name ...................... 3 5. Session Management Client (Smc) Functions .......... 3 5.1. Connecting to the Session Manager ................ 4 5.1.1. The Save Yourself Callback ..................... 7 5.1.2. The Die Callback ............................... 8 5.1.3. The Save Complete Callback ..................... 9 5.1.4. The Shutdown Cancelled Callback ................ 9 5.2. Closing the Connection ........................... 10 5.3. Modifying Callbacks .............................. 11 5.4. Setting, Deleting, and Retrieving Session Man‐ agement Properties .................................... 11 5.5. Interacting With the User ........................ 13 5.6. Requesting a Save Yourself ....................... 15 5.7. Requesting a Save Yourself Phase 2 ............... 16 5.8. Completing a Save Yourself ....................... 16 5.9. Using Smc Informational Functions ................ 17 5.10. Error Handling .................................. 18 6. Session Management Server (Sms) Functions .......... 19 6.1. Initializing the Library ......................... 20 6.1.1. The Register Client Callback ................... 23 6.1.2. The Interact Request Callback .................. 24 6.1.3. The Interact Done Callback ..................... 25 6.1.4. The Save Yourself Request Callback ............. 25 6.1.5. The Save Yourself Phase 2 Request Callback ..... 26 6.1.6. The Save Yourself Done Callback ................ 27 6.1.7. The Connection Closed Callback ................. 27 6.1.8. The Set Properties Callback .................... 28 6.1.9. The Delete Properties Callback ................. 29 6.1.10. The Get Properties Callback ................... 29 6.2. Registering the Client ........................... 30 6.3. Sending a Save Yourself Message .................. 31 6.4. Sending a Save Yourself Phase 2 Message .......... 32 6.5. Sending an Interact Message ...................... 33 6.6. Sending a Save Complete Message ................. 33 6.7. Sending a Die Message ............................ 33 6.8. Cancelling a Shutdown ............................ 34 6.9. Returning Properties ............................. 34 6.10. Pinging a Client ................................ 34 6.11. Cleaning Up After a Client Disconnects .......... 35 6.12. Using Sms Informational Functions ............... 36 6.13. Error Handling .................................. 37 7. Session Management Properties ...................... 38 8. Freeing Data ....................................... 41 9. Authentication of Clients .......................... 42 iii 10. Working in a Multi‐Threaded Environment ........... 42 11. Acknowledgements .................................. 42 iv