imDispch.c revision 61b2299d
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(Xim im)
67{
68    register XimProtoIntrRec *rec, *next;
69
70    for (rec = im->private.proto.intrproto; rec;) {
71	next = rec->next;
72	Xfree(rec);
73	rec = next;
74    }
75    im->private.proto.intrproto = NULL;
76    return;
77}
78
79Private Bool
80_XimTransportIntr(
81    Xim		 im,
82    INT16	 len,
83    XPointer	 data,
84    XPointer	 call_data)
85{
86    Xim			 call_im = (Xim)call_data;
87    XimProtoIntrRec	*rec = call_im->private.proto.intrproto;
88    CARD8		 major_opcode = *((CARD8 *)data);
89    CARD8		 minor_opcode = *((CARD8 *)data + 1);
90
91    for (; rec; rec = rec->next) {
92	if ((major_opcode == (CARD8)rec->major_code)
93	 && (minor_opcode == (CARD8)rec->minor_code))
94	    if ((*rec->func)(call_im, len, data, rec->call_data))
95		return True;
96    }
97    return False;
98}
99
100Public Bool
101_XimDispatchInit(Xim im)
102{
103    if (_XimRegisterDispatcher(im, _XimTransportIntr, (XPointer)im))
104	return True;
105    return False;
106}
107