Fix typo in license headers
[oweals/cde.git] / cde / programs / dtsession / SmWatch.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * (c) Copyright 1995 Digital Equipment Corporation.
25  * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
26  * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
27  * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
28  * (c) Copyright 1993, 1994, 1995 Novell, Inc. 
29  * (c) Copyright 1995 FUJITSU LIMITED.
30  * (c) Copyright 1995 Hitachi.
31  *
32  * $TOG: SmWatch.c /main/4 1997/03/19 12:21:06 barstow $
33  */
34 /******************************************************************************
35
36 Copyright (c) 1993  X Consortium
37
38 Permission is hereby granted, free of charge, to any person obtaining a copy
39 of this software and associated documentation files (the "Software"), to deal
40 in the Software without restriction, including without limitation the rights
41 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
42 copies of the Software, and to permit persons to whom the Software is
43 furnished to do so, subject to the following conditions:
44
45 The above copyright notice and this permission notice shall be included in
46 all copies or substantial portions of the Software.
47
48 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
51 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
52 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54
55 Except as contained in this notice, the name of the X Consortium shall not be
56 used in advertising or otherwise to promote the sale, use or other dealings
57 in this Software without prior written authorization from the X Consortium.
58 ******************************************************************************/
59
60 #include <X11/Intrinsic.h>
61 #include <X11/ICE/ICElib.h>
62 #include "SmXSMP.h"
63
64 /*
65  * Forward declarations
66  */
67 void _XtIceWatchProc ();
68 void _XtProcessIceMsgProc ();
69
70 Status
71 InitWatchProcs (
72         XtAppContext            appContext)
73 {
74 #ifdef DEBUG
75     printf ("InitWatchProcs\n");
76 #endif /* DEBUG */
77
78     return (IceAddConnectionWatch (_XtIceWatchProc, (IcePointer) appContext));
79 }
80
81
82 void
83 _XtIceWatchProc (
84         IceConn                 ice_conn,
85         IcePointer              client_data,
86         Bool                    opening,
87         IcePointer              *watch_data)
88 {
89 #ifdef DEBUG
90     printf ("_XtIceWatchProc\n");
91 #endif /* DEBUG */
92
93     if (opening)
94     {
95         XtAppContext appContext = (XtAppContext) client_data;
96
97         *watch_data = (IcePointer) XtAppAddInput (
98             appContext,
99             IceConnectionNumber (ice_conn),
100             (XtPointer) XtInputReadMask,
101             _XtProcessIceMsgProc,
102             (XtPointer) ice_conn);
103     }
104     else
105     {
106         XtRemoveInput ((XtInputId) *watch_data);
107     }
108 }
109
110
111 void
112 _XtProcessIceMsgProc (
113         XtPointer               client_data,
114         int                     *source,
115         XtInputId               *id)
116 {
117     IceConn                     ice_conn = (IceConn) client_data;
118     IceProcessMessagesStatus    status;
119
120 #ifdef DEBUG
121     printf ("_XtProcessIceMsgProc\n");
122 #endif /* DEBUG */
123
124     status = IceProcessMessages (ice_conn, NULL, NULL);
125
126     if (status == IceProcessMessagesIOError)
127     {
128         ClientRecPtr            pClientRec;
129         int                     found = 0;
130
131 #ifdef DEBUG
132         printf ("IO error on connection (fd = %d)\n", 
133                 IceConnectionNumber (ice_conn));
134 #endif /* DEBUG */
135
136         for (pClientRec = connectedList; pClientRec != NULL; 
137                 pClientRec = pClientRec->next) 
138         {
139             if (pClientRec->iceConn == ice_conn) 
140             {
141                 CloseDownClient (pClientRec);
142                 found = 1;
143                 break;
144             }
145         }
146
147         if (!found) {
148             IceSetShutdownNegotiation (ice_conn, False);
149             IceCloseConnection (ice_conn);
150         }
151     }
152 }