watch.c revision 266e564d
1266e564dSmrg/* $Xorg: watch.c,v 1.4 2001/02/09 02:03:26 xorgcvs Exp $ */ 2266e564dSmrg/****************************************************************************** 3266e564dSmrg 4266e564dSmrg 5266e564dSmrgCopyright 1993, 1998 The Open Group 6266e564dSmrg 7266e564dSmrgPermission to use, copy, modify, distribute, and sell this software and its 8266e564dSmrgdocumentation for any purpose is hereby granted without fee, provided that 9266e564dSmrgthe above copyright notice appear in all copies and that both that 10266e564dSmrgcopyright notice and this permission notice appear in supporting 11266e564dSmrgdocumentation. 12266e564dSmrg 13266e564dSmrgThe above copyright notice and this permission notice shall be included in 14266e564dSmrgall copies or substantial portions of the Software. 15266e564dSmrg 16266e564dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17266e564dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18266e564dSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19266e564dSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20266e564dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21266e564dSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22266e564dSmrg 23266e564dSmrgExcept as contained in this notice, the name of The Open Group shall not be 24266e564dSmrgused in advertising or otherwise to promote the sale, use or other dealings 25266e564dSmrgin this Software without prior written authorization from The Open Group. 26266e564dSmrg 27266e564dSmrgAuthor: Ralph Mor, X Consortium 28266e564dSmrg******************************************************************************/ 29266e564dSmrg 30266e564dSmrg#ifdef HAVE_CONFIG_H 31266e564dSmrg#include <config.h> 32266e564dSmrg#endif 33266e564dSmrg#include <X11/ICE/ICElib.h> 34266e564dSmrg#include "ICElibint.h" 35266e564dSmrg 36266e564dSmrg 37266e564dSmrgStatus 38266e564dSmrgIceAddConnectionWatch (watchProc, clientData) 39266e564dSmrg 40266e564dSmrgIceWatchProc watchProc; 41266e564dSmrgIcePointer clientData; 42266e564dSmrg 43266e564dSmrg{ 44266e564dSmrg /* 45266e564dSmrg * watchProc will be called each time an ICE connection is 46266e564dSmrg * created/destroyed by ICElib. 47266e564dSmrg */ 48266e564dSmrg 49266e564dSmrg _IceWatchProc *ptr = _IceWatchProcs; 50266e564dSmrg _IceWatchProc *newWatchProc; 51266e564dSmrg int i; 52266e564dSmrg 53266e564dSmrg if ((newWatchProc = (_IceWatchProc *) malloc ( 54266e564dSmrg sizeof (_IceWatchProc))) == NULL) 55266e564dSmrg { 56266e564dSmrg return (0); 57266e564dSmrg } 58266e564dSmrg 59266e564dSmrg newWatchProc->watch_proc = watchProc; 60266e564dSmrg newWatchProc->client_data = clientData; 61266e564dSmrg newWatchProc->watched_connections = NULL; 62266e564dSmrg newWatchProc->next = NULL; 63266e564dSmrg 64266e564dSmrg while (ptr && ptr->next) 65266e564dSmrg ptr = ptr->next; 66266e564dSmrg 67266e564dSmrg if (ptr == NULL) 68266e564dSmrg _IceWatchProcs = newWatchProc; 69266e564dSmrg else 70266e564dSmrg ptr->next = newWatchProc; 71266e564dSmrg 72266e564dSmrg 73266e564dSmrg /* 74266e564dSmrg * Invoke the watch proc with any previously opened ICE connections. 75266e564dSmrg */ 76266e564dSmrg 77266e564dSmrg for (i = 0; i < _IceConnectionCount; i++) 78266e564dSmrg { 79266e564dSmrg _IceWatchedConnection *newWatchedConn = (_IceWatchedConnection *) 80266e564dSmrg malloc (sizeof (_IceWatchedConnection)); 81266e564dSmrg 82266e564dSmrg newWatchedConn->iceConn = _IceConnectionObjs[i]; 83266e564dSmrg newWatchedConn->next = NULL; 84266e564dSmrg 85266e564dSmrg newWatchProc->watched_connections = newWatchedConn; 86266e564dSmrg 87266e564dSmrg (*newWatchProc->watch_proc) (_IceConnectionObjs[i], 88266e564dSmrg newWatchProc->client_data, True, &newWatchedConn->watch_data); 89266e564dSmrg } 90266e564dSmrg 91266e564dSmrg return (1); 92266e564dSmrg} 93266e564dSmrg 94266e564dSmrg 95266e564dSmrg 96266e564dSmrgvoid 97266e564dSmrgIceRemoveConnectionWatch (watchProc, clientData) 98266e564dSmrg 99266e564dSmrgIceWatchProc watchProc; 100266e564dSmrgIcePointer clientData; 101266e564dSmrg 102266e564dSmrg{ 103266e564dSmrg _IceWatchProc *currWatchProc = _IceWatchProcs; 104266e564dSmrg _IceWatchProc *prevWatchProc = NULL; 105266e564dSmrg 106266e564dSmrg while (currWatchProc && (currWatchProc->watch_proc != watchProc || 107266e564dSmrg currWatchProc->client_data != clientData)) 108266e564dSmrg { 109266e564dSmrg prevWatchProc = currWatchProc; 110266e564dSmrg currWatchProc = currWatchProc->next; 111266e564dSmrg } 112266e564dSmrg 113266e564dSmrg if (currWatchProc) 114266e564dSmrg { 115266e564dSmrg _IceWatchProc *nextWatchProc = currWatchProc->next; 116266e564dSmrg _IceWatchedConnection *watchedConn; 117266e564dSmrg 118266e564dSmrg watchedConn = currWatchProc->watched_connections; 119266e564dSmrg while (watchedConn) 120266e564dSmrg { 121266e564dSmrg _IceWatchedConnection *nextWatchedConn = watchedConn->next; 122266e564dSmrg free ((char *) watchedConn); 123266e564dSmrg watchedConn = nextWatchedConn; 124266e564dSmrg } 125266e564dSmrg 126266e564dSmrg if (prevWatchProc == NULL) 127266e564dSmrg _IceWatchProcs = nextWatchProc; 128266e564dSmrg else 129266e564dSmrg prevWatchProc->next = nextWatchProc; 130266e564dSmrg 131266e564dSmrg free ((char *) currWatchProc); 132266e564dSmrg } 133266e564dSmrg} 134266e564dSmrg 135266e564dSmrg 136266e564dSmrg 137266e564dSmrgvoid 138266e564dSmrg_IceConnectionOpened (iceConn) 139266e564dSmrg 140266e564dSmrgIceConn iceConn; 141266e564dSmrg 142266e564dSmrg{ 143266e564dSmrg _IceWatchProc *watchProc = _IceWatchProcs; 144266e564dSmrg 145266e564dSmrg while (watchProc) 146266e564dSmrg { 147266e564dSmrg _IceWatchedConnection *newWatchedConn = (_IceWatchedConnection *) 148266e564dSmrg malloc (sizeof (_IceWatchedConnection)); 149266e564dSmrg _IceWatchedConnection *watchedConn; 150266e564dSmrg 151266e564dSmrg watchedConn = watchProc->watched_connections; 152266e564dSmrg while (watchedConn && watchedConn->next) 153266e564dSmrg watchedConn = watchedConn->next; 154266e564dSmrg 155266e564dSmrg newWatchedConn->iceConn = iceConn; 156266e564dSmrg newWatchedConn->next = NULL; 157266e564dSmrg 158266e564dSmrg if (watchedConn == NULL) 159266e564dSmrg watchProc->watched_connections = newWatchedConn; 160266e564dSmrg else 161266e564dSmrg watchedConn->next = newWatchedConn; 162266e564dSmrg 163266e564dSmrg (*watchProc->watch_proc) (iceConn, 164266e564dSmrg watchProc->client_data, True, &newWatchedConn->watch_data); 165266e564dSmrg 166266e564dSmrg watchProc = watchProc->next; 167266e564dSmrg } 168266e564dSmrg} 169266e564dSmrg 170266e564dSmrg 171266e564dSmrg 172266e564dSmrgvoid 173266e564dSmrg_IceConnectionClosed (iceConn) 174266e564dSmrg 175266e564dSmrgIceConn iceConn; 176266e564dSmrg 177266e564dSmrg{ 178266e564dSmrg _IceWatchProc *watchProc = _IceWatchProcs; 179266e564dSmrg 180266e564dSmrg while (watchProc) 181266e564dSmrg { 182266e564dSmrg _IceWatchedConnection *watchedConn = watchProc->watched_connections; 183266e564dSmrg _IceWatchedConnection *prev = NULL; 184266e564dSmrg 185266e564dSmrg while (watchedConn && watchedConn->iceConn != iceConn) 186266e564dSmrg { 187266e564dSmrg prev = watchedConn; 188266e564dSmrg watchedConn = watchedConn->next; 189266e564dSmrg } 190266e564dSmrg 191266e564dSmrg if (watchedConn) 192266e564dSmrg { 193266e564dSmrg (*watchProc->watch_proc) (iceConn, 194266e564dSmrg watchProc->client_data, False, &watchedConn->watch_data); 195266e564dSmrg 196266e564dSmrg if (prev == NULL) 197266e564dSmrg watchProc->watched_connections = watchedConn->next; 198266e564dSmrg else 199266e564dSmrg prev->next = watchedConn->next; 200266e564dSmrg 201266e564dSmrg free ((char *) watchedConn); 202266e564dSmrg } 203266e564dSmrg 204266e564dSmrg watchProc = watchProc->next; 205266e564dSmrg } 206266e564dSmrg} 207