1 /******************************************************************************
4 Copyright 1993, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 Author: Ralph Mor, X Consortium
27 ******************************************************************************/
32 #include <X11/ICE/ICElib.h>
33 #include "ICElibint.h"
37 IceAddConnectionWatch (
38 IceWatchProc watchProc,
43 * watchProc will be called each time an ICE connection is
44 * created/destroyed by ICElib.
47 _IceWatchProc *ptr = _IceWatchProcs;
48 _IceWatchProc *newWatchProc;
51 if ((newWatchProc = (_IceWatchProc *) malloc (
52 sizeof (_IceWatchProc))) == NULL)
57 newWatchProc->watch_proc = watchProc;
58 newWatchProc->client_data = clientData;
59 newWatchProc->watched_connections = NULL;
60 newWatchProc->next = NULL;
62 while (ptr && ptr->next)
66 _IceWatchProcs = newWatchProc;
68 ptr->next = newWatchProc;
72 * Invoke the watch proc with any previously opened ICE connections.
75 for (i = 0; i < _IceConnectionCount; i++)
77 _IceWatchedConnection *newWatchedConn = (_IceWatchedConnection *)
78 malloc (sizeof (_IceWatchedConnection));
80 newWatchedConn->iceConn = _IceConnectionObjs[i];
81 newWatchedConn->next = NULL;
83 newWatchProc->watched_connections = newWatchedConn;
85 (*newWatchProc->watch_proc) (_IceConnectionObjs[i],
86 newWatchProc->client_data, True, &newWatchedConn->watch_data);
95 IceRemoveConnectionWatch (
96 IceWatchProc watchProc,
100 _IceWatchProc *currWatchProc = _IceWatchProcs;
101 _IceWatchProc *prevWatchProc = NULL;
103 while (currWatchProc && (currWatchProc->watch_proc != watchProc ||
104 currWatchProc->client_data != clientData))
106 prevWatchProc = currWatchProc;
107 currWatchProc = currWatchProc->next;
112 _IceWatchProc *nextWatchProc = currWatchProc->next;
113 _IceWatchedConnection *watchedConn;
115 watchedConn = currWatchProc->watched_connections;
118 _IceWatchedConnection *nextWatchedConn = watchedConn->next;
119 free ((char *) watchedConn);
120 watchedConn = nextWatchedConn;
123 if (prevWatchProc == NULL)
124 _IceWatchProcs = nextWatchProc;
126 prevWatchProc->next = nextWatchProc;
128 free ((char *) currWatchProc);
135 _IceConnectionOpened (
139 _IceWatchProc *watchProc = _IceWatchProcs;
143 _IceWatchedConnection *newWatchedConn = (_IceWatchedConnection *)
144 malloc (sizeof (_IceWatchedConnection));
145 _IceWatchedConnection *watchedConn;
147 watchedConn = watchProc->watched_connections;
148 while (watchedConn && watchedConn->next)
149 watchedConn = watchedConn->next;
151 newWatchedConn->iceConn = iceConn;
152 newWatchedConn->next = NULL;
154 if (watchedConn == NULL)
155 watchProc->watched_connections = newWatchedConn;
157 watchedConn->next = newWatchedConn;
159 (*watchProc->watch_proc) (iceConn,
160 watchProc->client_data, True, &newWatchedConn->watch_data);
162 watchProc = watchProc->next;
169 _IceConnectionClosed (
173 _IceWatchProc *watchProc = _IceWatchProcs;
177 _IceWatchedConnection *watchedConn = watchProc->watched_connections;
178 _IceWatchedConnection *prev = NULL;
180 while (watchedConn && watchedConn->iceConn != iceConn)
183 watchedConn = watchedConn->next;
188 (*watchProc->watch_proc) (iceConn,
189 watchProc->client_data, False, &watchedConn->watch_data);
192 watchProc->watched_connections = watchedConn->next;
194 prev->next = watchedConn->next;
196 free ((char *) watchedConn);
199 watchProc = watchProc->next;