summaryrefslogtreecommitdiff
path: root/doc/SMlib.xml
blob: 66fedd2bc8a572425bc03f26b5cbaeb115f9a9bb (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">


<!-- lifted from troff+ms+XMan by doclifter -->
<book id="smlibms">

<bookinfo>
   <title>X Session Management Library</title>
   <subtitle>X Consortium Standard</subtitle>
   <releaseinfo>X Version 11, Release 6.4</releaseinfo>
   <authorgroup>
      <author>
         <firstname>Ralph</firstname><surname>Mor</surname>
      </author>
   </authorgroup>
   <corpname>X Consortium Standard</corpname>
   <copyright><year>1993</year><holder>X Consortium</holder></copyright>
   <copyright><year>1994</year><holder>X Consortium</holder></copyright>
   <releaseinfo>Version 1.0</releaseinfo>
   <affiliation><orgname>X Consortium</orgname></affiliation>
   <productnumber>X Version 11, Release 7</productnumber>

<legalnotice>
<para>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &ldquo;Software&rdquo;), to deal in the Software without 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 following conditions:</para>

<para>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &ldquo;Software&rdquo;), to deal in the Software without 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 following conditions:</para>

<para>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</para>

<para>THE SOFTWARE IS PROVIDED &ldquo;AS IS&rdquo;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X CONSORTIUM 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.</para>

<para>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.</para>

<para>X Window System is a trademark of The Open Group.</para>
</legalnotice>

</bookinfo>

<chapter id="overview_of_session_management">
<title>Overview of Session Management</title>

<abstract>
<para>The purpose of the X Session Management Protocol (XSMP) is to provide a uniform mechanism for users to save and restore their sessions.  A <emphasis remap='I'>session</emphasis> is a group of clients, each of which has a particular state.  The session is controlled by a network service called the <emphasis remap='I'>session manager</emphasis>.  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.</para>

<para>For purposes of this protocol, a <emphasis remap='I'>client</emphasis> of the session manager is defined as a connection to the session manager.  A client is typically, though not necessarily, a process running an application program connected to an X display.  However, a client may be connected to more than one X display or not be connected to any X displays at all.</para>
</abstract>
</chapter>

<chapter id='the_session_management_library'>
<title>The Session Management Library</title>
<abstract>
<para>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.</para>
</abstract>

<para>SMlib has two parts to it:</para>
<itemizedlist mark='bullet'>
     <listitem><para>One set of functions for clients that want to be part of a session</para></listitem>
  <listitem><para>One set of functions for session managers to call</para></listitem>
</itemizedlist>

<para>Some applications will use both sets of functions and act as <emphasis remap='I'>nested session managers</emphasis>.  That is, they will be both a session 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.</para>

<para>Clients initialize by connecting to the session manager and obtaining a <emphasis remap='I'>client-ID</emphasis> 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 the client can be restarted (via an <function>SmRestartCommand</function>. 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 particular instantiation.  The client-ID should be saved as part of the <function>SmRestartCommand</function> so that the client will retain the same ID after it is restarted.</para>

<para>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.</para>
</chapter>

<chapter id='understanding_smlibs_dependence_on_ice'>
<title>Understanding SMlib's Dependence on ICE</title>

<para>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 connection.  As a result, working with SMlib requires a little knowledge of how the ICE library works.</para>

<para>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 <function>IceProcessMessages</function> function.  <function>IceProcessMessages</function> 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.</para>

<para>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 <function>select</function> call on the file descriptor for the ICE connection, but more typically, <function>XtAppAddInput</function> will be used to register a callback that will invoke <function>IceProcessMessages</function> each time there is data to read on the ICE connection.</para>

<para>To further complicate things, knowing which file descriptors to call <function>select</function> on requires an understanding of how ICE connections are created.  On the client side, a call must be made to <function>SmcOpenConnection</function> in order to open a connection with a session manager.  <function>SmcOpenConnection</function> will internally make a call into <function>IceOpenConnection</function> 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 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 <function>select</function> on.</para>

<para>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 <function>IceListenForConnections</function> in order to start listening for connections from clients.  Once a connection attempt is detected, <function>IceAcceptConnection</function> must be called, and the session manager can simply add the new ICE file descriptor to the list of descriptors to call <function>select</function> on.</para>

<para>For further information on the library functions related to ICE connections, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</chapter>

<chapter id='header_files_and_library_name'>
<title>Header Files and Library Name</title>

<para>Applications (both session managers and clients) should include the header file &lt;<symbol role='Pn'>X11/SM/SMlib.h</symbol>&gt;.  This header file defines all of the SMlib data structures and function prototypes.  <function>SMlib.h</function> includes the header file &lt;<symbol role='Pn'>X11/SM/SM.h</symbol>&gt;, which defines all of the SMlib constants.</para>

<para>Because SMlib is dependent on ICE, applications should link against SMlib and ICElib by using <function>-lSM</function> <function>-lICE</function></para>
</chapter>

<chapter id='session_management_client'>
<title>Session Management Client (Smc) Functions</title>


<para>This section discusses how Session Management clients:</para>
<itemizedlist mark='bullet'>
     <listitem><para>Connect to the Session Manager</para></listitem>
     <listitem><para>Close the connection</para></listitem>
     <listitem><para>Modify callbacks</para></listitem>
     <listitem><para>Set, delete, and retrieve Session Manager properties</para></listitem>
     <listitem><para>Interact with the user</para></listitem>
     <listitem><para>Request a &ldquo;Save Yourself&rdquo;</para></listitem>
     <listitem><para>Request a &ldquo;Save Yourself Phase 2&rdquo;</para></listitem>
     <listitem><para>Complete a &ldquo;Save Yourself&rdquo;</para></listitem>
     <listitem><para>Use Smc informational functions</para></listitem>
     <listitem><para>Handle Errors</para></listitem>
</itemizedlist>

<sect1 id='connecting_to_the_session_manager'>
<title>Connecting to the Session Manager</title>

<para>To open a connection with a session manager, use <function>SmcOpenConnection</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>SmcConn <function>SmcOpenConnection</function></funcdef>
      <paramdef>char *<parameter>network_ids_list</parameter></paramdef>
      <paramdef>SmPointer <parameter>context</parameter></paramdef>
      <paramdef>int <parameter>xsmp_major_rev</parameter></paramdef>
      <paramdef>int <parameter>xsmp_minor_rev</parameter></paramdef>
      <paramdef>unsigned long <parameter>mask</parameter></paramdef>
      <paramdef>SmcCallbacks *<parameter>callbacks</parameter></paramdef>
      <paramdef>char *<parameter>previous_id</parameter></paramdef>
      <paramdef>char **<parameter>client_id_ret</parameter></paramdef>
      <paramdef>int <parameter>error_length</parameter></paramdef>
      <paramdef>char *<parameter>error_string_ret</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para>Specifies the network ID(s) of the session manager.</para>

<variablelist remap='IP'>
  <varlistentry>
     <term><emphasis remap='I'>context</emphasis></term>
     <listitem><para>A pointer to an opaque object or NULL.  Used to determine if an ICE connection can be shared (see <link linkend='context_sharing'>below</link>).</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>xsmp_major_rev</emphasis></term>
     <listitem><para>The highest major version of the XSMP the application supports.</para></listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>xsmp_minor_rev</emphasis></term>
  <listitem><para>The highest minor version of the XSMP the application supports (for the specified xsmp_major_rev).</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>mask</emphasis></term>
     <listitem><para>A mask indicating which callbacks to register.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>callbacks</emphasis></term>
     <listitem><para>The callbacks to register.  These callbacks are used to respond to messages from the session manager.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>previous_id</emphasis></term>
     <listitem><para>The client ID from the previous session.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>client_id_ret</emphasis></term>
     <listitem><para>The client ID for the current session is returned.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>error_length</emphasis></term>
     <listitem><para>Length of the error_string_ret argument passed in.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>error_string_ret</emphasis></term>
     <listitem><para>Returns a null-terminated error message, if any.  The error_string_ret argument points to user supplied memory.  No more than error_length bytes are used.</para></listitem>
  </varlistentry>
</variablelist>


<para>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 <function>SESSION_MANAGER</function> environment variable will be used.  Each network ID has the following format:</para>

<informaltable pgwide='0' frame='none'>
  <tgroup cols='3' align='center'>
    <colspec colname='c1'/>
    <colspec colname='c2'/>
    <colspec colname='c3'/>
    <tbody>
      <row>
        <entry align='left'></entry>
        <entry align='left'>tcp/&lt;hostname&gt;:&lt;portnumber&gt;</entry>
        <entry align='left'>or</entry>
      </row>
      <row>
        <entry align='left'></entry>
        <entry align='left'>decnet/&lt;hostname&gt;::&lt;objname&gt;</entry>
        <entry align='left'>or</entry>
      </row>
      <row>
        <entry align='left'></entry>
        <entry align='left'>local/&lt;hostname&gt;:&lt;path&gt;</entry>
        <entry align='left'></entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>

<para>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.</para>

<para>After the connection is established, <function>SmcOpenConnection</function> registers 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.</para>

<para>If <function>SmcOpenConnection</function> succeeds, it returns an opaque connection pointer of type <function>SmcConn</function> 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 <function>free</function> when no longer needed.  On failure, <function>SmcOpenConnection</function> returns NULL, and the reason for failure is returned in error_string_ret.</para>

<para>Note that SMlib uses the ICE protocol to establish a connection 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.</para>

<para id='context_sharing'>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 connection.  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.</para>

<para>As previously discussed (<link linkend='understanding_smlibs_dependence_on_ice'>section 3, &ldquo;Understanding SMlib's Dependence on ICE&rdquo;</link>), the client will have to keep track of when ICE connections are created or destroyed (using <function>IceAddConnectionWatch</function> and <function>IceRemoveConnectionWatch</function> and will have to call <function>IceProcessMessages</function> each time a <function>select</function> shows that there is data to read on an ICE connection.  For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>

<para>The callbacks argument contains a set of callbacks used to respond to session manager events.  The mask argument specifies which callbacks are set.  All of the callbacks specified in this version of SMlib are mandatory.  The mask argument is necessary in order to maintain backwards compatibility in future versions of the library.</para>

<para>The following values may be ORed together to obtain a mask value:</para>

<synopsis>
<function>SmcSaveYourselfProcMask</function>
<function>SmcDieProcMask</function>
<function>SmcSaveCompleteProcMask</function>
<function>SmcShutdownCancelledProcMask</function>
</synopsis>

<para>For each callback, the client can register a pointer to client data.  When SMlib invokes the callback, it will pass the client data pointer.</para>

<!-- .ne 4  IGNORED -->

<synopsis>
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;
</synopsis>
<sect2 id='the_save_yourself_callback'>
<title>The Save Yourself Callback</title>

<para>The Save Yourself callback is of type <function>SmcSaveYourselfProc</function></para>

<funcsynopsis>
<funcprototype>
  <funcdef>typedef void (*<function>SaveYourselfProc</function>)</funcdef>
    <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
    <paramdef>SmcConn <parameter>client_data</parameter></paramdef>
    <paramdef>int <parameter>save_type</parameter></paramdef>
    <paramdef>Bool <parameter>shutdown</parameter></paramdef>
    <paramdef>int <parameter>interact_style</parameter></paramdef>
    <paramdef>Bool <parameter>fast</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>Client data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>save_type</emphasis></term>
    <listitem><para>Specifies the type of information that should be saved.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>shut_down</emphasis></term>
    <listitem><para>Specifies if a shutdown is taking place.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>interact_style</emphasis></term>
    <listitem><para>The type of interaction allowed with the user.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>fast</emphasis></term>
    <listitem><para>if <emphasis remap="B">True</emphasis>, then client should save its state as quickly as possible.</para></listitem>
  </varlistentry>
</variablelist>

<para>The session manager sends a &ldquo;Save Yourself&rdquo; 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 <function>SmcSetProperties</function> to update the properties indicating how to restart the client.  When all the properties have been set, the client calls <function>SmcSaveYourselfDone</function></para>

<para>If interact_style is <function>SmInteractStyleNone</function> the client must not interact with the user while saving state.  If interact_style is <function>SmInteractStyleErrors</function> the client may interact with the user only if an error condition arises.  If interact_style is <function>SmInteractStyleAny</function> then the client may interact with the user for any purpose.  Because only one client can interact with the user at a time, the client must call <function>SmcInteractRequest</function> and wait for an &ldquo;Interact&rdquo; message from the session manager.  When the client is done interacting with the user, it calls <function>SmcInteractDone</function> The client may only call <function>SmcInteractRequest</function> after it receives a &ldquo;Save Yourself&rdquo; message and before it calls <function>SmcSaveYourselfDone</function></para>

<para>If save_type is <function>SmSaveLocal</function> 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 <function>SmSaveGlobal</function> the user wants the client to commit all of its data to permanent, globally accessible storage.  If save_type is <function>SmSaveBoth</function> the client should do both of these (it should first commit the data to permanent storage before updating its properties).</para>

<para>Some examples are as follows:</para>

<itemizedlist mark='bullet'>
      <listitem><para>If a word processor were sent a &ldquo;Save Yourself&rdquo; with a type of <function>SmSaveLocal</function> it could create a temporary file that included the current contents of the file, the location of the cursor, and other aspects of the current editing session.  It would then update its SmRestartCommand property with enough information to find this temporary file.</para></listitem>
      <listitem><para>If a word processor were sent a &ldquo;Save Yourself&rdquo; with a type of <function>SmSaveGlobal</function> it would simply save the currently edited file.</para></listitem>
     <listitem><para>If a word processor were sent a &ldquo;Save Yourself&rdquo; with a type of <function>SmSaveBoth</function> 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.</para></listitem>
</itemizedlist>

<para>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 &ldquo;Save Complete&rdquo; message.  If shutting down, the client must save state and then prevent interaction until it receives either a &ldquo;Die&rdquo; or a &ldquo;Shutdown Cancelled.&rdquo;</para>

<para>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 <function>True</function></para>
</sect2>

<sect2 id='the_die_callback'>
<title>The Die Callback</title>

<para>The Die callback is of type <function>SmcDieProc</function></para>

<funcsynopsis>
<funcprototype>
  <funcdef>typedef void (*<function>SmcDieProc</function>)</funcdef>
    <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
    <paramdef>SmcConn <parameter>client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>Client data specified when the callback was registered.</para></listitem>
  </varlistentry>
</variablelist>


<para>The session manager sends a &ldquo;Die&rdquo; message to a client when it wants it to die.  The client should respond by calling <function>SmcCloseConnection</function> A session manager that behaves properly will send a &ldquo;Save Yourself&rdquo; message before the &ldquo;Die&rdquo; message.</para>
</sect2>

<sect2 id='the_save_complete_callback'>
<title>The Save Complete Callback</title>

<para>The Save Complete callback is of type <function>SmcSaveCompleteProc</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmcSaveCompleteProc</function>)</funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>Client data specified when the callback was registered.</para></listitem>
  </varlistentry>
</variablelist>
</sect2>


<sect2 id='the_shutdown_cancelled_callback'>
<title>The Shutdown Cancelled Callback</title>

<para>The Shutdown Cancelled callback is of type <function>SmcShutdownCancelledProc</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmcShutdownCancelledProc</function>)</funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>Client data specified when the callback was registered.</para></listitem>
  </varlistentry>
</variablelist>

<para>The session manager sends a &ldquo;Shutdown Cancelled&rdquo; message when the user cancelled the shutdown during an interaction (see <link linkend='interacting_with_the_user'>section 5.5, &ldquo;Interacting With the User&rdquo;</link>).  The client can now continue as if the shutdown had never happened.  If the client has not called <function>SmcSaveYourselfDone</function> yet, it can either abort the save and then call <function>SmcSaveYourselfDone</function> with the success argument set to <function>False</function> or it can continue with the save and then call <function>SmcSaveYourselfDone</function> with the success argument set to reflect the outcome of the save.</para>
</sect2>
</sect1>

<sect1 id='closing_the_connection'><title>Closing the Connection</title>

<para>To close a connection with a session manager, use <function>SmcCloseConnection</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>SmcCloseStatus <function>SmcCloseConnection</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>int <parameter>count</parameter></paramdef>
      <paramdef>char **<parameter>reason_msgs</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>count</emphasis></term>
    <listitem><para>The number of reasons for closing the connection.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reason_msgs</emphasis></term>
    <listitem><para>The reasons for closing the connection.</para></listitem>
  </varlistentry>
</variablelist>


<para>The reason_msgs argument will most likely be NULL if resignation 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 display these reason messages to the user.</para>

<para>Note that SMlib used the ICE protocol to establish a connection with the session manager, and various protocols other than session management may be active on the ICE connection.  When <function>SmcCloseConnection</function> is called, the ICE connection will be closed only if all protocols have been shutdown on the connection.  Check the ICElib standard for <function>IceAddConnectionWatch</function> and <function>IceRemoveConnectionWatch</function> 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 <function>select</function> on (or calls <function>XtAppAddInput</function> or <function>XtRemoveInput</function></para>


<para><function>SmcCloseConnection</function> returns one of the following values:</para>
<itemizedlist mark='bullet'>
      <listitem><para><function>SmcClosedNow</function> - the ICE connection was closed at this time, the watch procedures were invoked, and the connection was freed.</para></listitem>
      <listitem><para><function>SmcClosedASAP</function> - an IO error had occurred on the connection, but <function>SmcCloseConnection</function> is being called within a nested <function>IceProcessMessages</function> 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 <function>IceProcessMessages</function> returns a status of <function>IceProcessMessagesConnectionClosed</function></para> </listitem>
      <listitem><para><function>SmcConnectionInUse</function> - the connection was not closed at this time, because it is being used by other active protocols.</para> </listitem>
</itemizedlist>
</sect1>


<sect1 id='modifying_callbacks'>
<title>Modifying Callbacks</title>

<para>To modify callbacks set up in <function>SmcOpenConnection</function> use <function>SmcModifyCallbacks</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmcModifyCallbacks</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>unsigned long <parameter>mask</parameter></paramdef>
      <paramdef>SmcCallbacks *<parameter>callbacks</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<para>The session management connection object.</para>
<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>mask</emphasis></term>
    <listitem><para>A mask indicating which callbacks to modify.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>callbacks</emphasis></term>
    <listitem><para>The new callbacks.</para></listitem>
  </varlistentry>
</variablelist>

<para>When specifying a value for the mask argument, the following values may be ORed together:</para>

<synopsis>
<function>SmcSaveYourselfProcMask</function>
<function>SmcDieProcMask</function>
<function>SmcSaveCompleteProcMask</function>
<function>SmcShutdownCancelledProcMask</function>
</synopsis>
</sect1>

<sect1 id='setting_deleting_and_retrieving_session_management_properties'>
<title>Setting, Deleting, and Retrieving Session Management Properties</title>

<para>To set session management properties for this client, use <function>SmcSetProperties</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmcSetProperties</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>int <parameter>num_props</parameter></paramdef>
      <paramdef>SmProp **<parameter>props</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>num_proprs</emphasis></term>
    <listitem><para>The number of properties.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>props</emphasis></term>
    <listitem><para>The list of properties to set.</para></listitem>
  </varlistentry>
</variablelist>


<para>The properties are specified as an array of property pointers.  Previously set property values may be over-written using the <function>SmcSetProperties</function> 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.</para>

<para>For a description of session management properties and the <function>SmProp</function> structure, see <link linkend='session_management_properties'>section 7, &ldquo;Session Management Properties.&rdquo;</link></para>


<para>To delete properties previously set by the client, use <function>SmcDeleteProperties</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmcDeleteProperties</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>int <parameter>num_props</parameter></paramdef>
      <paramdef>char **<parameter>prop_names</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>num_proprs</emphasis></term>
    <listitem><para>The number of properties.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>prop_names</emphasis></term>
    <listitem><para>The list of properties to set.</para></listitem>
  </varlistentry>
</variablelist>

<para>To get properties previously stored by the client, use <function>SmcGetProperties</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>Status <function>SmcGetProperties</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>SmcPropReplyProc <parameter>prop_reply_proc</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>prop_reply_proc</emphasis></term>
    <listitem><para>The callback to be invoked when the properties reply comes back.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>This pointer to client data will be passed to the <function>SmcPropReplyProc</function> callback.</para></listitem>
  </varlistentry>
</variablelist>

<para>The return value of <function>SmcGetProperties</function> is zero for failure and a positive value for success.</para>

<para>Note that the library does not block until the properties reply comes back.  Rather, a callback of type <function>SmcPropReplyProc</function> is invoked when the data is ready.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmcPropReplyProc</function>)</funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
      <paramdef>int <parameter>num_props</parameter></paramdef>
      <paramdef>SmProp **<parameter>props</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>This pointer to client data will be passed to the <function>SmcPropReplyProc</function> callback.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>num_props</emphasis></term>
    <listitem><para>The number of properties returned.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>props</emphasis></term>
    <listitem><para>The list of properties returned.</para></listitem>
  </varlistentry>
</variablelist>

<para>To free each property, use <function>SmFreeProperty</function> (see <link linkend='freeing_data'>section 8, &ldquo;Freeing Data&rdquo;</link>).  To free the actual array of pointers, use <function>free</function></para>
</sect1>

<sect1 id='interacting_with_the_user'>
<title>Interacting With the User</title>

<para>After receiving a &ldquo;Save Yourself&rdquo; message with an interact_style of <function>SmInteractStyleErrors</function> or <function>SmInteractStyleAny</function> 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 <function>SmcInteractRequest</function> and wait for an &ldquo;Interact&rdquo; message from the session manager.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>Status <function>SmcInteractRequest</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>int <parameter>dialog_type</parameter></paramdef>
      <paramdef>SmcInteractProc <parameter>interact_proc</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>dialog_type</emphasis></term>
    <listitem><para>The type of dialog the client wishes to present to the user.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>interact_proc</emphasis></term>
    <listitem><para>The callback to be invoked when the &ldquo;Interact&rdquo; message arrives from the session manager.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>This pointer to client data will be passed to the <function>SmcInteractProc</function> callback when the &ldquo;Interact&rdquo; message arrives.</para></listitem>
  </varlistentry>
</variablelist>

<para>The return value of <function>SmcInteractRequest</function> is zero for failure and a positive value for success.</para>

<para>The dialog_type argument specifies either <function>SmDialogError</function> indicating that the client wants to start an error dialog, or <function>SmDialogNormal</function> meaning that the client wishes to start a nonerror dialog.</para>

<para>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 &ldquo;Shutdown Cancelled&rdquo; message instead of the &ldquo;Interact&rdquo; message.</para>

<para>The <function>SmcInteractProc</function> callback will be invoked when the &ldquo;Interact&rdquo; message arrives from the session manager.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmcInteractProc</function>)</funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>Client data specified when the callback was registered.</para></listitem>
  </varlistentry>
</variablelist>

<para>After interacting with the user (in response to an &ldquo;Interact&rdquo; message), you should call <function>SmcInteractDone</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmcInteractDone</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>Bool <parameter>cancel_shutdown</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>cancel_shutdown</emphasis></term>
    <listitem><para>If <function>True</function>, indicates that the user requests that the entire shutdown be cancelled.</para></listitem>
  </varlistentry>
</variablelist>
<para>The cancel_shutdown argument may only be <function>True</function> if the corresponding &ldquo;Save Yourself&rdquo; specified <function>True</function> for shutdown and <function>SmInteractStyleErrors</function> or <function>SmInteractStyleAny</function> for the interact_style.</para>
</sect1>

<sect1 id='requesting_a_save_yourself'>
<title>Requesting a Save Yourself</title>

<para>To request a checkpoint from the session manager, use <function>SmcRequestSaveYourself</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmcRequestSaveYourself</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>int <parameter>save_type</parameter></paramdef>
      <paramdef>Bool <parameter>shutdown</parameter></paramdef>
      <paramdef>int <parameter>interact_style</parameter></paramdef>
      <paramdef>Bool <parameter>fast</parameter></paramdef>
      <paramdef>Bool <parameter>global</parameter></paramdef>
  </funcprototype>
</funcsynopsis>


<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>save_type</emphasis></term>
    <listitem><para>Specifies the type of information that should be saved.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>shutdown</emphasis></term>
    <listitem><para>Specifies if a shutdown is taking place.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>interact_style</emphasis></term>
    <listitem><para>The type of interaction allowed with the user.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>fast</emphasis></term>
    <listitem><para>If <function>True</function> the client should save its state as quickly as possible.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>global</emphasis></term>
    <listitem><para>Controls who gets the &ldquo;Save Yourself.&rdquo;</para></listitem>
  </varlistentry>
</variablelist>

<para>The save_type, shutdown, interact_style, and fast arguments are discussed in more detail in <link linkend='the_save_yourself_callback'>section 5.1.1, &ldquo;The Save Yourself Callback.&rdquo;</link></para>

<para>If global is set to <function>True</function> then the resulting &ldquo;Save Yourself&rdquo; 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.</para>

<para>If global is set to <function>False</function> then the &ldquo;Save Yourself&rdquo; should only be sent to the client that requested it.</para>
</sect1>

<sect1 id='requesting_a_save_yourself_phase_2'>
<title>Requesting a Save Yourself Phase 2</title>

<para>In response to a &ldquo;Save Yourself&rdquo;, 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 <function>SmcRequestSaveYourselfPhase2</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>Status <function>SmcRequestSaveYourselfPhase2</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>SmcSaveYourselfPhase2Proc <parameter>save_yourself_phase2_proc</parameter></paramdef>
      <paramdef>SmPointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>save_type_phase2_proc</emphasis></term>
    <listitem><para>The callback to be invoked when the &ldquo;Save Yourself Phase 2&rdquo; message arrives from the session manager.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>This pointer to client data will be passed to the <function>SmcSaveYourselfPhase2Proc</function> callback when the &ldquo;Save Yourself Phase 2&rdquo; message arrives.</para></listitem>
  </varlistentry>
</variablelist>

<para>The return value of <function>SmcRequestSaveYourselfPhase2</function> is zero for failure and a positive value for success.</para>

<para>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.</para>
</sect1>

<sect1 id='completing_a_save_yourself'>
<title>Completing a Save Yourself</title>

<para>After saving state in response to a &ldquo;Save Yourself&rdquo; message, you should call <function>SmcSaveYourselfDone</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmcSaveYourselfDone</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>Bool <parameter>success</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>success</emphasis></term>
    <listitem><para>If <function>True</function> the &ldquo;Save Yourself&rdquo; operation was completed successfully.</para></listitem>
  </varlistentry>
</variablelist>

<para>Before calling <function>SmcSaveYourselfDone</function> the client must have set each required property at least once since the client registered with the session manager.</para>
</sect1>

<sect1 id='using_smc_informational_functions'>
<title>Using Smc Informational Functions</title>

<funcsynopsis>
   <funcprototype>
      <funcdef>int <function>SmcProtocolVersion</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmcProtocolVersion</function> returns the major version of the session management protocol associated with this session.</para>


<funcsynopsis>
   <funcprototype>
      <funcdef>int <function>SmcProtocolRevision</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmcProtocolRevision</function> returns the minor version of the session management protocol associated with this session.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>char <function>*SmcVendor</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmcVendor</function> returns a string that provides some identification of the owner of the session manager.  The string should be freed with a call to <function>free</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>char <function>*SmcRelease</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmcRelease</function> returns a string that provides the release number of the session manager.  The string should be freed with a call to <function>free</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>char <function>*SmcClientID</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmcClientID</function> returns a null-terminated string for the client ID associated with this connection.  This information was also returned in <function>SmcOpenConnection</function> (it is provided here for convenience).  Call <function>free</function> on this pointer when the client ID is no longer needed.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>IceConn <function>SmcGetIceConnection</function></funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmcGetIceConnection</function> returns the ICE connection object associated 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 <function>IceConnectionNumber</function> <function>IceConnectionString</function> <function>IceLastSentSequenceNumber</function> <function>IceLastReceivedSequenceNumber</function> and <function>IcePing</function> For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</sect1>

<sect1 id='error_handling'>
<title>Error Handling</title>

<para>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 <function>stderr</function> and exits if the severity of the error is fatal.  The client can change this error handler by calling the <function>SmcSetErrorHandler</function> function.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>SmcErrorHandler <function>SmcSetErrorHandler</function></funcdef>
      <paramdef>SmcErrorHandler <parameter>handler</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<para>The error handler.  You should pass NULL to restore the default handler.</para>


<para><function>SmcSetErrorHandler</function> returns the previous error handler.</para>

<para>The <function>SmcErrorHandler</function> has the following type:</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmcErrorHandler</function>)</funcdef>
      <paramdef>SmcConn <parameter>smc_conn</parameter></paramdef>
      <paramdef>Bool <parameter>swap</parameter></paramdef>
      <paramdef>int <parameter>offending_minor_opcode</parameter></paramdef>
      <paramdef>unsigned long <parameter>offending_sequence_num</parameter></paramdef>
      <paramdef>int <parameter>error_class</parameter></paramdef>
      <paramdef>int <parameter>severity</parameter></paramdef>
      <paramdef>IcePointer <parameter>values</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>smc_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>swap</emphasis></term>
     <listitem><para>A flag that indicates if the specified values need byte swapping.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>offending_minor_opcode</emphasis></term>
     <listitem><para>The minor opcode of the offending message.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>offending_sequence_num</emphasis></term>
     <listitem><para>The sequence number of the offending message.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>error_class</emphasis></term>
     <listitem><para>The error class of the offending message.</para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>severity</emphasis></term>
     <listitem><para><function>IceCanContinue</function><function>IceFatalToProtocol</function> or <function>IceFatalToConnection</function></para></listitem>
  </varlistentry>
  <varlistentry>
     <term><emphasis remap='I'>values</emphasis></term>
     <listitem><para>Any additional error values specific to the minor opcode and class.</para></listitem>
  </varlistentry>
</variablelist>

<para>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 <function>IceSetIOErrorHandler</function> For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</sect1>
</chapter>

<chapter id='session_management_server'>
<title>Session Management Server (Sms) Functions</title>

<para>This section discusses how Session Management servers:</para>

<itemizedlist mark='bullet'>
    <listitem><para>Initialize the library</para></listitem>
    <listitem><para>Register the client</para></listitem>
    <listitem><para>Send a &ldquo;Save Yourself&rdquo; message</para></listitem>
    <listitem><para>Send a &ldquo;Save Yourself Phase 2&rdquo; message</para></listitem>
    <listitem><para>Send an &ldquo;Interact&rdquo; message</para></listitem>
    <listitem><para>Send a &ldquo;Save Complete&rdquo; message</para></listitem>
    <listitem><para>Send a &ldquo;Die&rdquo; message</para></listitem>
    <listitem><para>Cancel a shutdown</para></listitem>
    <listitem><para>Return properties</para></listitem>
    <listitem><para>Ping a client</para></listitem>
    <listitem><para>Clean up after a client disconnects</para></listitem>
    <listitem><para>Use Sms informational functions</para></listitem>
    <listitem><para>Handle errors</para></listitem>
</itemizedlist>

<sect1 id='initializing_the_library'>
<title>Initializing the Library</title>

<para><function>SmsInitialize</function> 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 manager.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>Status <function>SmsInitialize</function></funcdef>
      <paramdef>char *<parameter>vendor</parameter></paramdef>
      <paramdef>char *<parameter>release</parameter></paramdef>
      <paramdef>SmsNewClientProc <parameter>new_client_proc</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>IceHostBasedAuthProc <parameter>host_based_auth_proc</parameter></paramdef>
      <paramdef>int <parameter>error_length</parameter></paramdef>
      <paramdef>char *<parameter>error_string_ret</parameter></paramdef>
  </funcprototype>
</funcsynopsis>



<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>vendor</emphasis></term>
    <listitem><para>A string specifying the session manager vendor.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>release</emphasis></term>
    <listitem><para>A string specifying the session manager release number.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>new_client_proc</emphasis></term>
    <listitem><para>Callback to be invoked each time a new client connects to the session manager.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>When the <function>SmsNewClientProc</function> callback is invoked, this pointer to manager data will be passed.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>host_based_auth_proc</emphasis></term>
    <listitem><para>Host based authentication callback.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_length</emphasis></term>
    <listitem><para>Length of the error_string_ret argument passed in.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_string_ret</emphasis></term>
    <listitem><para>Returns a null-terminated error message, if any.  The error_string_ret points to user supplied memory.  No more than error_length bytes are used.</para></listitem>
  </varlistentry>
</variablelist>

<para>After the <function>SmsInitialize</function> function is called, the session manager should call the <function>IceListenForConnections</function> function to listen for new connections.  Afterwards, each time a client connects, the session manager should call <function>IceAcceptConnection</function></para>

<para>See <link linkend='authentication_of_clients'>section 9, &ldquo;Authentication of Clients,&rdquo;</link> for more details on authentication (including host based authentication).  Also see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard for further details on listening for and accepting ICE connections.</para>

<para>Each time a new client connects to the session manager, the <function>SmsNewClientProc</function> 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.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef Status (*<function>SmsNewClientProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>unsigned long *<parameter>mask_ret</parameter></paramdef>
      <paramdef>SmsCallbacks *<parameter>callbacks_ret</parameter></paramdef>
      <paramdef>char **<parameter>failure_reason_ret</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>A new opaque connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>mask_ret</emphasis></term>
    <listitem><para>On return, indicates which callbacks were set by the session manager.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>callbacks_ret</emphasis></term>
    <listitem><para>On return, contains the callbacks registered by the session manager.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>failure_reason_ret</emphasis></term>
    <listitem><para>Failure reason returned.</para></listitem>
  </varlistentry>
</variablelist>

<para>If a failure occurs, the <function>SmsNewClientProc</function> 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.</para>

<para>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.</para>

<para>The following values may be ORed together to obtain a mask value:</para>

<synopsis>
<function>SmsRegisterClientProcMask</function>
<function>SmsInteractRequestProcMask</function>
<function>SmsInteractDoneProcMask</function>
<function>SmsSaveYourselfRequestProcMask</function>
<function>SmsSaveYourselfP2RequestProcMask</function>
<function>SmsSaveYourselfDoneProcMask</function>
<function>SmsCloseConnectionProcMask</function>
<function>SmsSetPropertiesProcMask</function>
<function>SmsDeletePropertiesProcMask</function>
<function>SmsGetPropertiesProcMask</function>
</synopsis>

<para>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.</para>

<synopsis>
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;

	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;
</synopsis>

<sect2 id='the_register_client_callback'>
<title>The Register Client Callback</title>

<para>The Register Client callback is the first callback that will be invoked after the client connects to the session manager.  Its type is <function>SmsRegisterClientProc</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef Status (*<function>SmsRegisterClientProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>char *<parameter>previous_id</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>previous_id</emphasis></term>
    <listitem><para>The client ID from the previous session.</para></listitem>
  </varlistentry>
</variablelist>

<para>Before any further interaction takes place with the client, the client must be registered with the session manager.</para>

<para>If the client is being restarted from a previous session, previous_id will contain a null-terminated string representing the client ID from the previous session.  Call <function>free</function> on the previous_id pointer when it is no longer needed.
If the client is first joining the session, previous_id will be NULL.</para>

<para>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.</para>

<para>Otherwise, the session manager should register the client with a unique client ID by calling the <function>SmsRegisterClientReply</function> function (to be discussed shortly), and the <function>SmsRegisterClientProc</function> callback should return a status of one.</para>
</sect2>

<sect2 id='the_interact_request_callback'>
<title>The Interact Request Callback</title>

<para>The Interact Request callback is of type <function>SmsInteractRequestProc</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsInteractRequestProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>int <parameter>dialog_type</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>dialog_type</emphasis></term>
    <listitem><para>The type of dialog the client wishes to present to the user.</para></listitem>
  </varlistentry>
</variablelist>

<para>When a client receives a &ldquo;Save Yourself&rdquo; message with an interact_style of <function>SmInteractStyleErrors</function> or <function>SmInteractStyleAny</function> 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 wishing to interact.  It should send an &ldquo;Interact&rdquo; message to one client at a time and wait for an &ldquo;Interact Done&rdquo; message before continuing with the next client.</para>

<para>The dialog_type argument specifies either <function>SmDialogError</function> indicating that the client wants to start an error dialog, or <function>SmDialogNormal</function> meaning that the client wishes to start a nonerror dialog.</para>

<para>If a shutdown is in progress, the user may have the option of cancelling the shutdown.  If the shutdown is cancelled (specified in the &ldquo;Interact Done&rdquo; message), the session manager should send a &ldquo;Shutdown Cancelled&rdquo; message to each client that requested to interact.</para>
</sect2>

<sect2 id='the_interact_done_callback'>
<title>The Interact Done Callback</title>

<para>When the client is done interacting with the user, the <function>SmsInteractDoneProc</function> callback will be invoked.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsInteractDoneProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>Bool <parameter>cancel_shutdown</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>cancel_shutdown</emphasis></term>
    <listitem><para>Specifies if the user requests that the entire shutdown be cancelled.</para></listitem>
  </varlistentry>
</variablelist>

<para>Note that the shutdown can be cancelled only if the corresponding &ldquo;Save Yourself&rdquo; specified <function>True</function> for shutdown and <function>SmInteractStyleErrors</function> or <function>SmInteractStyleAny</function> for the interact_style.</para>
</sect2>




<sect2 id='the_save_yourself_request_callback'>
<title>The Save Yourself Request Callback</title>

<para>The Save Yourself Request callback is of type <function>SmsSaveYourselfRequestProc</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SaveYourselfRequestProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>int <parameter>save_type</parameter></paramdef>
      <paramdef>Bool <parameter>shutdown</parameter></paramdef>
      <paramdef>int <parameter>interact_style</parameter></paramdef>
      <paramdef>Bool <parameter>fast</parameter></paramdef>
      <paramdef>Bool <parameter>global</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>save_type</emphasis></term>
    <listitem><para>Specifies the type of information that should be saved.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>shutdown</emphasis></term>
    <listitem><para>Specifies if a shutdown is taking place.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>interact_style</emphasis></term>
    <listitem><para>The type of interaction allowed with the user.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>fast</emphasis></term>
    <listitem><para>If <function>True</function> the client should save its state as quickly as possible.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>global</emphasis></term>
    <listitem><para>Controls who gets the &ldquo;Save Yourself.&rdquo;</para></listitem>
  </varlistentry>
</variablelist>

<para>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 <link linkend='sending_a_save_yourself_message'>section 6.3, &ldquo;Sending a Save Yourself Message.&rdquo;</link></para>

<para>If global is set to <function>True</function> then the resulting &ldquo;Save Yourself&rdquo; should be sent to all applications.  If global is set to <function>False</function> then the &ldquo;Save Yourself&rdquo; should only be sent to the client that requested it.</para>
</sect2>

<sect2 id='the_save_yourself_phase_2_request_callback'>
<title>The Save Yourself Phase 2 Request Callback</title>

<para>The Save Yourself Phase 2 Request callback is of type <function>SmsSaveYourselfPhase2RequestProc</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsSaveYourselfPhase2RequestProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
</variablelist>

<para>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.</para>
</sect2>

<sect2 id='the_save_yourself_done_callback'>
<title>The Save Yourself Done Callback</title>

<para>When the client is done saving its state in response to a &ldquo;Save Yourself&rdquo; message, the <function>SmsSaveYourselfDoneProc</function> will be invoked.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SaveYourselfDoneProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>Bool <parameter>success</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>success</emphasis></term>
    <listitem><para>If <function>True</function> the Save Yourself operation was completed successfully.</para></listitem>
  </varlistentry>
</variablelist>

<para>Before the &ldquo;Save Yourself Done&rdquo; was sent, the client must have set each required property at least once since it registered with the session manager.</para>
</sect2>

<sect2 id='the_connection_closed_callback'>
<title>The Connection Closed Callback</title>

<para>If the client properly terminates (that is, it calls <function>SmcCloseConnection</function> the <function>SmsCloseConnectionProc</function> callback is invoked.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsCloseConnectionProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>int <parameter>count</parameter></paramdef>
      <paramdef>char **<parameter>reason_msgs</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
<varlistentry>
  <term><emphasis remap='I'>manager_data</emphasis></term>
  <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>count</emphasis></term>
    <listitem><para>The number of reason messages.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reason_msgs</emphasis></term>
    <listitem><para>The reasons for closing the connection.</para></listitem>
  </varlistentry>
</variablelist>

<para>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 Compound Text strings representing the reason for termination.  The session manager should display these reason messages to the user.</para>

<para>Call <function>SmFreeReasons</function> to free the reason messages.  For further information, see <link linkend='freeing_data'>section 8, &ldquo;Freeing Data&rdquo;</link></para>
</sect2>

<sect2 id='the_set_properties_callback'>
<title>The Set Properties Callback</title>

<para>When the client sets session management properties, the <function>SmsSetPropertiesProc</function> callback will be invoked.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsSetPropertiesProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>int <parameter>num_props</parameter></paramdef>
      <paramdef>SmProp **<parameter>props</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>num_props</emphasis></term>
    <listitem><para>The number of properties.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>props</emphasis></term>
    <listitem><para>The list of properties to set.</para></listitem>
  </varlistentry>
</variablelist>

<para>The properties are specified as an array of property pointers.  For a description of session management properties and the <function>SmProp</function> structure, see <link linkend='session_management_properties'>section 7, &ldquo;Session Management Properties.&rdquo;</link></para>

<para>Previously set property values may be over-written.  Some properties have predefined semantics.  The session manager is required to store nonpredefined properties.</para>

<para>To free each property, use <function>SmFreeProperty</function> For further information, see <link linkend='freeing_data'>section 8, &ldquo;Freeing Data&rdquo;</link> You should free the actual array of pointers with a call to <function>free</function></para>
</sect2>

<sect2 id='the_delete_properties_callback'>
<title>The Delete Properties Callback</title>

<para>When the client deletes session management properties, the <function>SmsDeletePropertiesProc</function> callback will be invoked.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsDeletePropertiesProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
      <paramdef>int <parameter>num_props</parameter></paramdef>
      <paramdef>char **<parameter>prop_names</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>num_props</emphasis></term>
    <listitem><para>The number of properties.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>prop_names</emphasis></term>
    <listitem><para>The list of properties to delete.</para></listitem>
  </varlistentry>
</variablelist>

<para>The properties are specified as an array of strings.  For a description of session management properties and the <function>SmProp</function> structure, see <link linkend='session_management_properties'>section 7, &ldquo;Session Management Properties.&rdquo;</link></para>
</sect2>

<sect2 id='the_get_properties_callback'>
<title>The Get Properties Callback</title>

<para>The <function>SmsGetPropertiesProc</function> callback is invoked when the client wants to retrieve properties it set.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsGetPropertiesProc</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>SmPointer <parameter>manager_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>manager_data</emphasis></term>
    <listitem><para>Manager data specified when the callback was registered.</para></listitem>
  </varlistentry>
</variablelist>

<para>The session manager should respond by calling <function>SmsReturnProperties</function> All of the properties set for this client should be returned.</para>
</sect2>
</sect1>
<sect1 id='registering_the_client'>
<title>Registering the Client</title>

<para>To register a client (in response to a <function>SmsRegisterClientProc</function> callback), use <function>SmsRegisterClientReply</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>Status <function>SmsRegisterClientReply</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>char *<parameter>client_id</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_id</emphasis></term>
    <listitem><para>A null-terminated string representing a unique client ID.</para></listitem>
  </varlistentry>
</variablelist>

<para>The return value of <function>SmsRegisterClientReply</function> is zero for failure 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.</para>

<para>If a non-NULL previous_id was specified when the client registered itself, client_id should be identical to previous_id.</para>

<para>Otherwise, client_id should be a unique ID freshly generated by the session manager.  In addition, the session manager should send a &ldquo;Save Yourself&rdquo; message with type = Local, shutdown = False, interact-style = None, and fast = False immediately after registering the client.</para>

<para>Note that once a client ID has been assigned to the client, 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 manager 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.</para>

<para>You should call the <function>SmsGenerateClientID</function> function to generate a globally unique client ID.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>char <function>*SmsGenerateClientID</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>


<para>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 <function>free</function> when no longer needed.</para>
</sect1>

<sect1 id='sending_a_save_yourself_message'>
<title>Sending a Save Yourself Message</title>

<para>To send a &ldquo;Save Yourself&rdquo; to a client, use <function>SmsSaveYourself</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsSaveYourself</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>int <parameter>save_type</parameter></paramdef>
      <paramdef>Bool <parameter>shutdown</parameter></paramdef>
      <paramdef>int <parameter>interact_style</parameter></paramdef>
      <paramdef>Bool <parameter>fast</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>save_type</emphasis></term>
    <listitem><para>Specifies the type of information that should be saved.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>shutdown</emphasis></term>
    <listitem><para>Specifies if a shutdown is taking place.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>interact_style</emphasis></term>
    <listitem><para>The type of interaction allowed with the user.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>fast</emphasis></term>
    <listitem><para>If <function>True</function> the client should save its state as quickly as possible.</para></listitem>
  </varlistentry>
</variablelist>


<para>The session manager sends a &ldquo;Save Yourself&rdquo; 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 &ldquo;Set Properties&rdquo; messages to update the properties indicating how to restart the client.  When all the properties have been set, the client sends a &ldquo;Save Yourself Done&rdquo; message.</para>

<para>If interact_style is <function>SmInteractStyleNone</function> the client must not interact with the user while saving state.  If interact_style is <function>SmInteractStyleErrors</function> the client may interact with the user only if an error condition arises.  If interact_style is <function>SmInteractStyleAny</function> then the client may interact with the user for any purpose.  The client must send an &ldquo;Interact Request&rdquo; message and wait for an &ldquo;Interact&rdquo; 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 &ldquo;Interact Done&rdquo; message.  The &ldquo;Interact Request&rdquo; message can be sent any time after a &ldquo;Save Yourself&rdquo; and before a &ldquo;Save Yourself Done.&rdquo;</para>

<para>If save_type is <function>SmSaveLocal</function> 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 <function>SmSaveGlobal</function> the user wants the client to commit all of its data to permanent, globally accessible storage.  If save_type is <function>SmSaveBoth</function> the client should do both of these (it should first commit the data to permanent storage before updating its properties).</para>

<para>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 shutting down, the client must save and then must prevent interaction until it receives either a &ldquo;Die&rdquo; or a &ldquo;Shutdown Cancelled,&rdquo; because anything the user does after the save will be lost.</para>

<para>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 <function>True</function></para>
</sect1>

<sect1 id='sending_a_save_yourself_phase_2_message'>
<title>Sending a Save Yourself Phase 2 Message</title>

<para>In order to send a &ldquo;Save Yourself Phase 2&rdquo; message to a client, use <function>SmsSaveYourselfPhase2</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsSaveYourselfPhase2</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>The session manager sends this message to a client that has previously sent a &ldquo;Save Yourself Phase 2 Request&rdquo; 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.</para>
</sect1>

<sect1 id='sending_an_interact_message'>
<title>Sending an Interact Message</title>

<para>To send an &ldquo;Interact&rdquo; message to a client, use <function>SmsInteract</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsInteract</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>The &ldquo;Interact&rdquo; message grants the client the privilege of interacting with the user.  When the client is done interacting with the user, it must send an &ldquo;Interact Done&rdquo; message to the session manager.</para>
</sect1>



<sect1 id='sending_a_save_complete_message'>
<title>Sending a Save Complete Message</title>

<para>To send a &ldquo;Save Complete&rdquo; message to a client, use <function>SmsSaveComplete</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsSaveComplete</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>The session manager sends this message when it is done with a checkpoint.  The client is then free to change its state.</para>
</sect1>

<sect1 id='sending_a_die_message'>
<title>Sending a Die Message</title>

<para>To send a &ldquo;Die&rdquo; message to a client, use <function>SmsDie</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsDie</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>Before the session manager terminates, it should wait for a &ldquo;Connection Closed&rdquo; message from each client that it sent a &ldquo;Die&rdquo; message to, timing out appropriately.</para>
</sect1>

<sect1 id='cancelling_a_shutdown'>
<title>Cancelling a Shutdown</title>

<para>To cancel a shutdown, use <function>SmsShutdownCancelled</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsShutdownCancelled</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>The client can now continue as if the shutdown had never happened.  If the client has not sent a &ldquo;Save Yourself Done&rdquo; message yet, it can either abort the save and send a &ldquo;Save Yourself Done&rdquo; with the success argument set to <function>False</function> or it can continue with the save and send a &ldquo;Save Yourself Done&rdquo; with the success argument set to reflect the outcome of the save.</para>
</sect1>
<!-- aaaaaaaaaaaaaaaaa -->

<sect1 id='returning_properties'>
<title>Returning Properties</title>

<para>In response to a &ldquo;Get Properties&rdquo; message, the session manager should call <function>SmsReturnProperties</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsReturnProperties</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>int <parameter>num_props</parameter></paramdef>
      <paramdef>SmProp **<parameter>props</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>num_props</emphasis></term>
    <listitem><para>The number of properties.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>props</emphasis></term>
    <listitem><para>The list of properties to return to the client.</para></listitem>
  </varlistentry>
</variablelist>

<para>The properties are returned as an array of property pointers.  For a description of session management properties and the <function>SmProp</function> structure, see <link linkend='session_management_properties'>section 7, &ldquo;Session Management Properties.&rdquo;</link></para>
</sect1>

<sect1 id='pinging_a_client'>
<title>Pinging a Client</title>

<para>To check that a client is still alive, you should use the <function>IcePing</function> function provided by the ICE library.  To do so, the ICE connection must be obtained using the <function>SmsGetIceConnection</function> (see <link linkend='using_sms_informational_functions'>section 6.12, &ldquo;Using Sms Informational Functions&rdquo;</link>).</para>


<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>IcePing</function></funcdef>
      <paramdef>IceConn <parameter>ice_conn</parameter></paramdef>
      <paramdef>IcePingReplyProc <parameter>ping_reply_proc</parameter></paramdef>
      <paramdef>IcePointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>A valid ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>ping_reply_proc</emphasis></term>
    <listitem><para>The callback to invoke when the Ping reply arrives.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>This pointer will be passed to the <function>IcePingReplyProc</function> callback.</para></listitem>
  </varlistentry>
</variablelist>


<para>When the Ping reply is ready (if ever), the <function>IcePingReplyProc</function> callback will be invoked.  A session manager should have some sort of timeout period, after which it assumes the client has unexpectedly died.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>IcePingReplyProc</function>)</funcdef>
      <paramdef>IceConn <parameter>ice_conn</parameter></paramdef>
      <paramdef>IcePointer <parameter>client_data</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>A valid ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem><para>The client data specified in the call to <function>IcePing</function></para></listitem>
  </varlistentry>
</variablelist>
</sect1>

<sect1 id='cleaning_up_after_a_client_disconnects'>
<title>Cleaning Up After a Client Disconnects</title>

<para>When the session manager receives a &ldquo;Connection Closed&rdquo; message or otherwise detects that the client aborted the connection, it should call the <function>SmsCleanUp</function> function in order to free up the connection object.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmsCleanUp</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
</variablelist>

</sect1>

<sect1 id='using_sms_informational_functions'>
<title>Using Sms Informational Functions</title>

<funcsynopsis>
   <funcprototype>
      <funcdef>int <function>SmsProtocolVersion</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmsProtocolVersion</function> returns the major version of the session management protocol associated with this session.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>int <function>SmsProtocolRevision</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmsProtocolRevision</function> returns the minor version of the session management protocol associated with this session.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>char <function>*SmsClientID</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmsClientID</function> returns a null-terminated string for the client ID associated with this connection.  You should call <function>free</function> on this pointer when the client ID is no longer needed.</para>


<para>To obtain the host name of a client, use <function>SmsClientHostName</function> This host name will be needed to restart the client.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>char <function>*SmsClientHostName</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para>The string returned is of the form <emphasis remap='I'>protocol</emphasis>/<emphasis remap='I'>hostname</emphasis>, where <emphasis remap='I'>protocol</emphasis> is one of {tcp, decnet, local}.  You should call <function>free</function> on the string returned when it is no longer needed.</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>IceConn <function>SmsGetIceConnection</function></funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<para><function>SmsGetIceConnection</function> returns the ICE connection object associated 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 <function>IceConnectionNumber</function> and <function>IceLastSequenceNumber</function> For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</sect1>

<sect1 id='error_handling2'>
<title>Error Handling</title>

<para>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 <function>SmsSetErrorHandler</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>SmsErrorHandler <function>SmsSetErrorHandler</function></funcdef>
      <paramdef>SmsErrorHandler <parameter>handler</parameter></paramdef>
  </funcprototype>
</funcsynopsis>
<para>The error handler.  You should pass NULL to restore the default handler.</para>

<para><function>SmsSetErrorHandler</function> returns the previous error handler.  The <function>SmsErrorHandler</function> has the following type:</para>

<funcsynopsis>
   <funcprototype>
      <funcdef>typedef void (*<function>SmsErrorHandler</function>)</funcdef>
      <paramdef>SmsConn <parameter>sms_conn</parameter></paramdef>
      <paramdef>Bool <parameter>swap</parameter></paramdef>
      <paramdef>int <parameter>offending_minor_opcode</parameter></paramdef>
      <paramdef>unsigned long <parameter>offending_sequence_num</parameter></paramdef>
      <paramdef>int <parameter>error_class</parameter></paramdef>
      <paramdef>int <parameter>severity</parameter></paramdef>
      <paramdef>IcePointer <parameter>values</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>sms_conn</emphasis></term>
    <listitem><para>The session management connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>swap</emphasis></term>
    <listitem><para>A flag which indicates if the specified values need byte swapping.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_minor_opcode</emphasis></term>
    <listitem><para>The minor opcode of the offending message.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_sequence_num</emphasis></term>
    <listitem><para>The sequence number of the offending message.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_class</emphasis></term>
    <listitem><para>The error class of the offending message.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>severity</emphasis></term>
    <listitem><para><function>IceCanContinue</function><function>IceFatalToProtocol</function> or <function>IceFatalToConnection</function></para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>values</emphasis></term>
    <listitem><para>Any additional error values specific to the minor opcode and class.</para></listitem>
  </varlistentry>
</variablelist>

<para>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 <function>IceSetIOErrorHandler</function> For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</sect1>
</chapter>

<chapter id='session_management_properties'>
<title>Session Management Properties</title>

<para>Each property is defined by the <function>SmProp</function> structure:</para>

<synopsis>
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;
</synopsis>

<para>The X Session Management Protocol defines a list of predefined 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.</para>

<para>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.</para>

<informaltable pgwide='0' frame='none'>
  <tgroup cols='4' align='center'>
    <colspec colname='c1'/>
    <colspec colname='c2'/>
    <colspec colname='c3'/>
    <colspec colname='c4'/>
    <thead>
      <row>
        <entry align='left'>Name</entry>
        <entry align='left'>Type</entry>
        <entry align='left'>POSIX Type</entry>
        <entry align='center'>Required</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry align='left'>SmCloneCommand</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmLISTofARRAY8</entry>
        <entry align='center'>Yes</entry>
      </row>
      <row>
        <entry align='left'>SmCurrentDirectory</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmARRAY8</entry>
        <entry align='center'>No</entry>
      </row>
      <row>
        <entry align='left'>SmDiscardCommand</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmLISTofARRAY8</entry>
        <entry align='center'>No*</entry>
      </row>
      <row>
        <entry align='left'>SmEnvironment</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmLISTofARRAY8</entry>
        <entry align='center'>No</entry>
      </row>
      <row>
        <entry align='left'>SmProcessID</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmARRAY8</entry>
        <entry align='center'>No</entry>
      </row>
      <row>
        <entry align='left'>SmProgram</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmARRAY8</entry>
        <entry align='center'>Yes</entry>
      </row>
      <row>
        <entry align='left'>SmRestartCommand</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmLISTofARRAY8</entry>
        <entry align='center'>Yes</entry>
      </row>
      <row>
        <entry align='left'>SmResignCommand</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmLISTofARRAY8</entry>
        <entry align='center'>No</entry>
      </row>
      <row>
        <entry align='left'>SmRestartStyleHint</entry>
        <entry align='left'>SmCARD8</entry>
        <entry align='left'>SmCARD8</entry>
        <entry align='center'>No</entry>
      </row>
      <row>
        <entry align='left'>SmShutdownCommand</entry>
        <entry align='left'>OS-specific</entry>
        <entry align='left'>SmLISTofARRAY8</entry>
        <entry align='center'>No</entry>
      </row>
      <row>
        <entry align='left'>SmUserID</entry>
        <entry align='left'>SmARRAY8</entry>
        <entry align='left'>SmARRAY8</entry>
        <entry align='center'>Yes</entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>

<para>* Required if any state is stored in an external repository (for example, state file).</para>

<itemizedlist mark='bullet'>
    <listitem><para>SmCloneCommand</para><para>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 register time.  On POSIX systems, this should be of type SmLISTofARRAY8.</para></listitem>
    <listitem><para>SmCurrentDirectory</para><para>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.</para></listitem>
    <listitem><para>SmDiscardCommand</para><para>The discard command contains a command that when delivered to the host that the client is running on (determined from the connection), will cause it to discard any information about the current state.  If this command 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.</para></listitem>
    <listitem><para>SmEnvironment</para> <para>On POSIX based systems, this will be of type SmLISTofARRAY8, where the ARRAY8s alternate between environment variable name and environment variable value.</para></listitem>
    <listitem><para>SmProcessID</para><para>This specifies an OS-specific identifier for the process.  On POSIX systems, this should contain the return value of <function>getpid</function> turned into a Latin-1 (decimal) string.</para></listitem>
    <listitem><para>SmProgram</para><para>This is the name of the program that is running.  On POSIX systems, this should be first parameter passed to <function>execve</function> and should be of type SmARRAY8.</para></listitem>
    <listitem><para>SmRestartCommand</para><para>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 systems, this is of type SmLISTofARRAY8, and each of the elements in the array represents an element in the <function>argv</function> array.  This restart command should ensure that the client restarts with the specified client-ID.</para></listitem>
    <listitem><para>SmResignCommand</para><para>A client that sets the SmRestartStyleHint to SmRestartAnway 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 <function>xmodmap</function> which registers with the Session Manager, sets SmRestartStyleHint to SmRestartAnyway, and then terminates.  To allow the Session Manager (at the user's request) to undo this, <function>xmodmap</function> would register a SmResignCommand that undoes the effects of the <function>xmodmap</function></para></listitem>
    <listitem><para>SmRestartStyleHint</para><para>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:</para>

<informaltable pgwide='0' frame='none'>
  <tgroup cols='2' align='center'>
    <colspec colname='c1'/>
    <colspec colname='c2'/>
    <thead>
      <row>
        <entry align='left'>Name</entry>
        <entry align='right'>Value</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry align='left'>SmRestartIfRunning</entry>
        <entry align='right'>0</entry>
      </row>
      <row>
        <entry align='left'>SmRestartAnyway</entry>
        <entry align='right'>1</entry>
      </row>
      <row>
        <entry align='left'>SmRestartImmediately</entry>
        <entry align='right'>2</entry>
      </row>
      <row>
        <entry align='left'>SmRestartNever</entry>
        <entry align='right'>3</entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>

<para>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.</para>

<para>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 session is terminated.  It should be noted that this is only a hint and the Session Manager will follow the policies specified by its users in determining what applications to restart.</para>

<para>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.</para>

<para>The SmRestartImmediately style is like SmRestartAnyway, but, in addition, the client is meant to run continuously.  If the client exits, the Session Manager should try to restart it in the current session.</para>

<para>SmRestartNever style specifies that the client does not wish to be restarted in the next session.</para>
  </listitem>
    <listitem><para>SmShutdownCommand</para><para>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 SmRestartAnyway.  The client must not remove any saved state as the client is still part of the session.  As an example, 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.</para></listitem>
    <listitem><para>SmUserID</para><para>Specifies the user ID.  On POSIX-based systems, this will contain the user's name (the pw_name member of struct <function>passwd</function></para></listitem>
</itemizedlist>
</chapter>

<chapter id='freeing_data'>
<title>Freeing Data</title>

<para>To free an individual property, use <function>SmFreeProperty</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmFreeProperty</function></funcdef>
      <paramdef>SmProp *<parameter>prop</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>prop</emphasis></term>
    <listitem><para>The property to free.</para></listitem>
  </varlistentry>
</variablelist>

<para>To free the reason strings from the <function>SmsCloseConnectionProc</function> callback, use <function>SmFreeReasons</function></para>

<funcsynopsis>
   <funcprototype>
      <funcdef>void <function>SmFreeReasons</function></funcdef>
      <paramdef>int <parameter>count</parameter></paramdef>
      <paramdef>char **<parameter>reasons</parameter></paramdef>
  </funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>count</emphasis></term>
    <listitem><para>The number of reason strings.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reasons</emphasis></term>
    <listitem><para>The list of reason strings to free.</para></listitem>
  </varlistentry>
</variablelist>
</chapter>

<chapter id='authentication_of_clients'>
<title>Authentication of Clients</title>

<para>As stated earlier, the session management protocol is layered on top of ICE.  Authentication occurs at two levels in the ICE protocol:</para>

<itemizedlist mark='bullet'>
    <listitem><para>The first is when an ICE connection is opened.</para></listitem>
    <listitem><para>The second is when a Protocol Setup occurs on an ICE connection.</para></listitem>
</itemizedlist>

<para>The authentication methods that are available are implementation-dependent
(that is., dependent on the ICElib and SMlib implementations in use).  For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</chapter>

<chapter id='working_in_a_multithreaded_environment'>
<title>Working in a Multi-Threaded Environment</title>

<para>To declare that multiple threads in an application will be using SMlib (or any other library layered on top of ICElib), you should call <function>IceInitThreads</function> For further information, see the <emphasis remap='I'>Inter-Client Exchange Library</emphasis> standard.</para>
</chapter>

<chapter id='acknowledgements'>
<title>Acknowledgements</title>

<para>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.</para>

</chapter>
</book>