1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 Copyright (c) 2009 Red Hat, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 <!-- use this file with xsltproc evtest-replace.xml <input.xml>
22 where <input.xml> is the xml file generated by evtest-capture.
25 <xsl:stylesheet version=
"1.0" xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform">
26 <xsl:output method=
"text" indent=
"yes" encoding=
"UTF-8"/>
29 <xsl:template match=
"/evtest-capture">
32 Copyright (c)
2009 Red Hat, Inc.
34 This program is free software; you can redistribute it and/or modify
35 it under the terms of the GNU General Public License as published by
36 the Free Software Foundation; either version
2 of the License, or
37 (at your option) any later version.
39 This program is distributed in the hope that it will be useful,
40 but WITHOUT ANY WARRANTY; without even the implied warranty of
41 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 GNU General Public License for more details.
44 You should have received a copy of the GNU General Public License
45 along with this program; if not, write to the Free Software
46 Foundation, Inc.,
59 Temple Place, Suite
330, Boston, MA
02111-
1307 USA
54 #include
<linux/input.h
>
55 #include
<linux/uinput.h
>
60 static void send_event(int fd, int type, int code, int value, int sec, int usec);
62 static int setup(struct uinput_user_dev *dev, int fd)
65 <xsl:apply-templates select=
"info/id"/>
66 <xsl:apply-templates select=
"info/event-type"/>
71 perror(
"ioctl failed.");
75 static int run(int fd)
78 <xsl:apply-templates select=
"events"/>
83 static int init_uinput()
85 struct uinput_user_dev dev;
87 fd = open(
"/dev/uinput", O_RDWR);
88 if (fd <
0 && errno == ENODEV)
89 fd = open(
"/dev/input/uinput", O_RDWR);
93 memset(&dev,
0, sizeof(dev));
96 if (write(fd, &dev, sizeof(dev)) < sizeof(dev))
98 if (ioctl(fd, UI_DEV_CREATE, NULL) == -
1) goto error;
103 fprintf(stderr,
"Error: %s\n", strerror(errno));
111 static void cleanup_uinput(void)
116 ioctl(fd, UI_DEV_DESTROY, NULL);
121 static void send_event(int fd, int type, int code, int value, int sec, int usec)
123 static int sec_offset = -
1;
124 static long last_time = -
1;
126 struct input_event event;
132 if (sec_offset == -
1)
136 newtime = sec *
1000000 + usec;
139 usleep(newtime - last_time);
141 if (write(fd, &event, sizeof(event)) < sizeof(event))
142 perror(
"Send event failed.");
147 int main (int argc, char **argv)
149 if (init_uinput() <
0) {
151 "Failed to initialize /dev/input/uinput. Exiting.\n");
155 printf(
"Device created. Press CTRL+C to terminate.\n");
165 <!-- Setup the required uinput bits to make the device look real
166 The funky comments at the start of the lines are just to improve
167 the output indenting.
169 <xsl:template match=
"event-type">
170 if (ioctl(fd, UI_SET_EVBIT,
<xsl:value-of select=
"@type"/>) == -
1) goto error;
171 <!-- --><xsl:for-each select=
"code">
173 <xsl:when test=
"../@type = 'EV_KEY'">
174 if (ioctl(fd, UI_SET_KEYBIT,
<xsl:value-of select=
"@value"/>) == -
1) goto error;
176 <xsl:when test=
"../@type = 'EV_REL'">
177 if (ioctl(fd, UI_SET_RELBIT,
<xsl:value-of select=
"@value"/>) == -
1) goto error;
179 <xsl:when test=
"../@type = 'EV_MSC'">
180 if (ioctl(fd, UI_SET_MSCBIT,
<xsl:value-of select=
"@value"/>) == -
1) goto error;
182 <xsl:when test=
"../@type = 'EV_ABS'">
183 if (ioctl(fd, UI_SET_ABSBIT,
<xsl:value-of select=
"@value"/>) == -
1) goto error;
185 int idx =
<xsl:value-of select=
"@value"/>;
186 dev-
>absmin[idx] =
<xsl:value-of select=
"@abs-min"/>;
187 dev-
>absmax[idx] =
<xsl:value-of select=
"@abs-max"/>;
188 dev-
>absfuzz[idx] =
<xsl:value-of select=
"@abs-fuzz"/>;
189 dev-
>absflat[idx] =
<xsl:value-of select=
"@abs-flat"/>;
191 if (dev-
>absmin[idx] == dev-
>absmax[idx])
199 <xsl:template match=
"id">
200 strcpy(dev-
>name,
"<xsl:value-of select=".
"/>");
201 dev-
>id.bustype =
<xsl:value-of select=
"@bus"/>;
202 dev-
>id.vendor =
<xsl:value-of select=
"@vendor"/>;
203 dev-
>id.product =
<xsl:value-of select=
"@product"/>;
204 dev-
>id.version =
<xsl:value-of select=
"@version"/>;
207 <!-- code replaying the events -->
208 <xsl:template match=
"events">
209 <xsl:for-each select=
"event">
210 send_event(fd,
<xsl:value-of select=
"@type"/>,
<xsl:value-of select=
"@code"/>,
<xsl:value-of select=
"@value"/>,
<xsl:value-of select=
"@sec"/>,
<xsl:value-of select=
"@usec"/>);
</xsl:for-each>