Home | History | Annotate | Line # | Download | only in src
      1 /******************************************************************************
      2 
      3 
      4 Copyright 1993, 1998  The Open Group
      5 
      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
     10 documentation.
     11 
     12 The above copyright notice and this permission notice shall be included in
     13 all copies or substantial portions of the Software.
     14 
     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.
     21 
     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.
     25 
     26 Author: Ralph Mor, X Consortium
     27 ******************************************************************************/
     28 
     29 #ifdef HAVE_CONFIG_H
     30 #include <config.h>
     31 #endif
     32 #include <X11/ICE/ICElib.h>
     33 #include "ICElibint.h"
     34 
     35 
     36 void
     37 _IceAddReplyWait (
     38 	IceConn			iceConn,
     39 	IceReplyWaitInfo	*replyWait
     40 )
     41 {
     42     /*
     43      * Add this replyWait to the end of the list (only if the
     44      * replyWait is not already in the list).
     45      */
     46 
     47     _IceSavedReplyWait	*savedReplyWait;
     48     _IceSavedReplyWait	*prev, *last;
     49 
     50     prev = NULL;
     51     last = iceConn->saved_reply_waits;
     52 
     53     while (last)
     54     {
     55 	if (last->reply_wait == replyWait)
     56 	    return;
     57 
     58 	prev = last;
     59 	last = last->next;
     60     }
     61 
     62     savedReplyWait = malloc (sizeof (_IceSavedReplyWait));
     63     if (!savedReplyWait)
     64       return;
     65 
     66     savedReplyWait->reply_wait = replyWait;
     67     savedReplyWait->reply_ready = False;
     68     savedReplyWait->next = NULL;
     69 
     70     if (prev == NULL)
     71 	iceConn->saved_reply_waits = savedReplyWait;
     72     else
     73 	prev->next = savedReplyWait;
     74 }
     75 
     76 
     77 
     78 IceReplyWaitInfo *
     79 _IceSearchReplyWaits (
     80 	IceConn	iceConn,
     81 	int	majorOpcode
     82 )
     83 {
     84     /*
     85      * Return the first replyWait in the list with the given majorOpcode
     86      */
     87 
     88     _IceSavedReplyWait	*savedReplyWait = iceConn->saved_reply_waits;
     89 
     90     while (savedReplyWait && !savedReplyWait->reply_ready &&
     91 	savedReplyWait->reply_wait->major_opcode_of_request != majorOpcode)
     92     {
     93 	savedReplyWait = savedReplyWait->next;
     94     }
     95 
     96     return (savedReplyWait ? savedReplyWait->reply_wait : NULL);
     97 }
     98 
     99 
    100 
    101 void
    102 _IceSetReplyReady (
    103 	IceConn			iceConn,
    104 	IceReplyWaitInfo	*replyWait
    105 )
    106 {
    107     /*
    108      * The replyWait specified has a reply ready.
    109      */
    110 
    111     _IceSavedReplyWait	*savedReplyWait = iceConn->saved_reply_waits;
    112 
    113     while (savedReplyWait && savedReplyWait->reply_wait != replyWait)
    114 	savedReplyWait = savedReplyWait->next;
    115 
    116     if (savedReplyWait)
    117 	savedReplyWait->reply_ready = True;
    118 }
    119 
    120 
    121 
    122 Bool
    123 _IceCheckReplyReady (
    124 	IceConn			iceConn,
    125 	IceReplyWaitInfo	*replyWait
    126 )
    127 {
    128     _IceSavedReplyWait	*savedReplyWait = iceConn->saved_reply_waits;
    129     _IceSavedReplyWait	*prev = NULL;
    130     Bool		found = False;
    131     Bool		ready;
    132 
    133     while (savedReplyWait && !found)
    134     {
    135 	if (savedReplyWait->reply_wait == replyWait)
    136 	    found = True;
    137 	else
    138 	{
    139 	    prev = savedReplyWait;
    140 	    savedReplyWait = savedReplyWait->next;
    141 	}
    142     }
    143 
    144     ready = found && savedReplyWait->reply_ready;
    145 
    146     if (ready)
    147     {
    148 	if (prev == NULL)
    149 	    iceConn->saved_reply_waits = savedReplyWait->next;
    150 	else
    151 	    prev->next = savedReplyWait->next;
    152 
    153 	free (savedReplyWait);
    154     }
    155 
    156     return (ready);
    157 }
    158