imDispch.c revision 1ab64890
1/* $Xorg: imDispch.c,v 1.3 2000/08/17 19:45:12 cpqbld Exp $ */
2/******************************************************************
3
4                Copyright 1993, 1994 by FUJITSU LIMITED
5
6Permission to use, copy, modify, distribute, and sell this software
7and its documentation for any purpose is hereby granted without fee,
8provided that the above copyright notice appear in all copies and
9that both that copyright notice and this permission notice appear
10in supporting documentation, and that the name of FUJITSU LIMITED
11not be used in advertising or publicity pertaining to distribution
12of the software without specific, written prior permission.
13FUJITSU LIMITED makes no representations about the suitability of
14this software for any purpose.
15It is provided "as is" without express or implied warranty.
16
17FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
21USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23PERFORMANCE OF THIS SOFTWARE.
24
25  Author: Takashi Fujiwara     FUJITSU LIMITED
26                               fujiwara@a80.tech.yk.fujitsu.co.jp
27
28******************************************************************/
29/* $XFree86: xc/lib/X11/imDispch.c,v 1.4 2003/04/13 19:22:20 dawes Exp $ */
30
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34#include <X11/Xlib.h>
35#include "Xlibint.h"
36#include "Xutil.h"
37#include "Xlcint.h"
38#include "Ximint.h"
39
40
41Public Bool
42_XimRegProtoIntrCallback(
43    Xim		 im,
44    CARD16	 major_code,
45    CARD16	 minor_code,
46    Bool	(*proc)(
47                        Xim, INT16, XPointer, XPointer
48			),
49
50    XPointer	 call_data)
51{
52    XimProtoIntrRec    *rec;
53
54    if (!(rec = (XimProtoIntrRec *)Xmalloc(sizeof(XimProtoIntrRec))))
55        return False;
56    rec->func       = proc;
57    rec->major_code = major_code;
58    rec->minor_code = minor_code;
59    rec->call_data  = call_data;
60    rec->next       = im->private.proto.intrproto;
61    im->private.proto.intrproto = rec;
62    return True;
63}
64
65Public void
66_XimFreeProtoIntrCallback(im)
67    Xim		im;
68{
69    register XimProtoIntrRec *rec, *next;
70
71    for (rec = im->private.proto.intrproto; rec;) {
72	next = rec->next;
73	Xfree(rec);
74	rec = next;
75    }
76    im->private.proto.intrproto = NULL;
77    return;
78}
79
80Private Bool
81_XimTransportIntr(
82    Xim		 im,
83    INT16	 len,
84    XPointer	 data,
85    XPointer	 call_data)
86{
87    Xim			 call_im = (Xim)call_data;
88    XimProtoIntrRec	*rec = call_im->private.proto.intrproto;
89    CARD8		 major_opcode = *((CARD8 *)data);
90    CARD8		 minor_opcode = *((CARD8 *)data + 1);
91
92    for (; rec; rec = rec->next) {
93	if ((major_opcode == (CARD8)rec->major_code)
94	 && (minor_opcode == (CARD8)rec->minor_code))
95	    if ((*rec->func)(call_im, len, data, rec->call_data))
96		return True;
97    }
98    return False;
99}
100
101Public Bool
102_XimDispatchInit(im)
103    Xim		 im;
104{
105    if (_XimRegisterDispatcher(im, _XimTransportIntr, (XPointer)im))
106	return True;
107    return False;
108}
109