Merge lp:~peter-hutterer/evemu/evemu-event-v3 into lp:evemu

Proposed by Peter Hutterer
Status: Merged
Merged at revision: 55
Proposed branch: lp:~peter-hutterer/evemu/evemu-event-v3
Merge into: lp:evemu
Diff against target: 309 lines (+201/-3)
7 files modified
.bzrignore (+2/-0)
include/evemu.h (+17/-0)
src/evemu.c (+17/-0)
src/libutouch-evemu.ver (+2/-0)
tools/Makefile.am (+2/-1)
tools/evemu-device.txt (+7/-2)
tools/evemu-event.c (+154/-0)
To merge this branch: bzr merge lp:~peter-hutterer/evemu/evemu-event-v3
Reviewer Review Type Date Requested Status
Chase Douglas (community) Approve
Review via email: mp+109248@code.launchpad.net

Description of the change

version 3 of the evemu-event patches. sorry, couldn't push to v2 for some reason but there's only two patches on top of the last one. Changes to v2:
- check for device path to exist and only exist once
- error out for unknown options

To post a comment you must log in.
Revision history for this message
Chase Douglas (chasedouglas) wrote :

Looks good to me :).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-11-24 03:24:15 +0000
3+++ .bzrignore 2012-06-07 22:25:25 +0000
4@@ -19,6 +19,8 @@
5 tools/evemu-device
6 tools/evemu-device.1
7 tools/evemu-echo
8+tools/evemu-event
9+tools/evemu-event.1
10 tools/evemu-play
11 tools/evemu-play.1
12 tools/evemu-record
13
14=== modified file 'include/evemu.h'
15--- include/evemu.h 2012-06-05 16:09:52 +0000
16+++ include/evemu.h 2012-06-07 22:25:25 +0000
17@@ -328,6 +328,15 @@
18 int evemu_write_event(FILE *fp, const struct input_event *ev);
19
20 /**
21+ * evemu_create_event() - Create a single event
22+ * @ev: pointer to the kernel event to be filled
23+ * @type: the event type to set
24+ * @code: the event code to set
25+ * @value: the event value to set
26+ */
27+int evemu_create_event(struct input_event *ev, int type, int code, int value);
28+
29+/**
30 * evemu_read_event() - read kernel event from file
31 * @fp: file pointer to read the event from
32 * @ev: pointer to the kernel event to be filled
33@@ -370,6 +379,14 @@
34 */
35 int evemu_record(FILE *fp, int fd, int ms);
36
37+
38+/**
39+ * evemu_play_one() - play one event to kernel device
40+ * @fd: file descriptor of kernel device to write to
41+ * @ev: pointer to the kernel event to be played
42+ */
43+int evemu_play_one(int fd, const struct input_event *ev);
44+
45 /**
46 * evemu_play() - replay events from file to kernel device in realtime
47 * @fp: file pointer to read the events from
48
49=== modified file 'src/evemu.c'
50--- src/evemu.c 2012-06-05 16:13:31 +0000
51+++ src/evemu.c 2012-06-07 22:25:25 +0000
52@@ -425,6 +425,16 @@
53 return ret;
54 }
55
56+int evemu_create_event(struct input_event *ev, int type, int code, int value)
57+{
58+ ev->time.tv_sec = 0;
59+ ev->time.tv_usec = 0;
60+ ev->type = type;
61+ ev->code = code;
62+ ev->value = value;
63+ return 0;
64+}
65+
66 int evemu_read_event_realtime(FILE *fp, struct input_event *ev,
67 struct timeval *evtime)
68 {
69@@ -449,6 +459,13 @@
70 return ret;
71 }
72
73+int evemu_play_one(int fd, const struct input_event *ev)
74+{
75+ int ret;
76+ SYSCALL(ret = write(fd, ev, sizeof(*ev)));
77+ return (ret < sizeof(*ev));
78+}
79+
80 int evemu_play(FILE *fp, int fd)
81 {
82 struct input_event ev;
83
84=== modified file 'src/libutouch-evemu.ver'
85--- src/libutouch-evemu.ver 2012-06-05 16:09:52 +0000
86+++ src/libutouch-evemu.ver 2012-06-07 22:25:25 +0000
87@@ -1,6 +1,7 @@
88 UTOUCH_EVEMU_1.0 {
89 global:
90 evemu_create;
91+ evemu_create_event;
92 evemu_delete;
93 evemu_destroy;
94 evemu_extract;
95@@ -19,6 +20,7 @@
96 evemu_has_prop;
97 evemu_new;
98 evemu_play;
99+ evemu_play_one;
100 evemu_read;
101 evemu_read_event;
102 evemu_read_event_realtime;
103
104=== modified file 'tools/Makefile.am'
105--- tools/Makefile.am 2011-01-05 10:19:44 +0000
106+++ tools/Makefile.am 2012-06-07 22:25:25 +0000
107@@ -5,7 +5,8 @@
108 evemu-describe \
109 evemu-device \
110 evemu-record \
111- evemu-play
112+ evemu-play \
113+ evemu-event
114
115 INCLUDES=-I$(top_srcdir)/include/
116
117
118=== modified file 'tools/evemu-device.txt'
119--- tools/evemu-device.txt 2011-01-05 10:19:44 +0000
120+++ tools/evemu-device.txt 2012-06-07 22:25:25 +0000
121@@ -4,8 +4,8 @@
122 NAME
123 ----
124
125- evemu-device, evemu-play - create a virtual input device and replay an
126- event sequence
127+ evemu-device, evemu-play, evemu-event - create a virtual input device
128+ and replay an event sequence
129
130 SYNOPSIS
131 --------
132@@ -13,6 +13,8 @@
133
134 evemu-play /dev/input/eventX < event-sequence
135
136+ evemu-event /dev/input/eventX [--sync] --type <type> --code <code> --value <value>
137+
138 DESCRIPTION
139 -----------
140 evemu-device creates a virtual input device based on the description-file.
141@@ -24,6 +26,9 @@
142 evemu-play replays the event sequence given on stdin through the input
143 device. The event sequence must be in the form created by evemu-record(1).
144
145+evemu-event plays exactly one event with the current time. If *--sync* is
146+given, evemu-event generates an *EV_SYN* event after the event.
147+
148 evemu-device must be able to write to the uinput device node, and evemu-play
149 must be able to write to the device node specified; in most cases this means
150 it must be run as root.
151
152=== added file 'tools/evemu-event.c'
153--- tools/evemu-event.c 1970-01-01 00:00:00 +0000
154+++ tools/evemu-event.c 2012-06-07 22:25:25 +0000
155@@ -0,0 +1,154 @@
156+/*****************************************************************************
157+ *
158+ * evemu - Kernel device emulation
159+ *
160+ * Copyright (C) 2011 Red Hat, Inc.
161+ *
162+ * This program is free software: you can redistribute it and/or modify it
163+ * under the terms of the GNU General Public License as published by the
164+ * Free Software Foundation, either version 3 of the License, or (at your
165+ * option) any later version.
166+ *
167+ * This program is distributed in the hope that it will be useful, but
168+ * WITHOUT ANY WARRANTY; without even the implied warranty of
169+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
170+ * General Public License for more details.
171+ *
172+ * You should have received a copy of the GNU General Public License along
173+ * with this program. If not, see <http://www.gnu.org/licenses/>.
174+ *
175+ ****************************************************************************/
176+#include "evemu.h"
177+#include <getopt.h>
178+#include <limits.h>
179+#include <stdio.h>
180+#include <fcntl.h>
181+#include <string.h>
182+#include <unistd.h>
183+#include <stdlib.h>
184+#include <linux/input.h>
185+
186+static struct option opts[] = {
187+ { "type", required_argument, 0, 't'},
188+ { "code", required_argument, 0, 'c'},
189+ { "value", required_argument, 0, 'v'},
190+ { "sync", no_argument, 0, 's'},
191+ { "device", required_argument, 0, 'd'}
192+};
193+
194+int parse_arg(const char *arg, long int *value)
195+{
196+ char *endp;
197+
198+ *value = strtol(arg, &endp, 0);
199+ if (*arg == '\0' || *endp != '\0')
200+ return 1;
201+ return 0;
202+}
203+
204+void usage(void)
205+{
206+ fprintf(stderr, "Usage: %s [--sync] <device> --type <type> --code <code> --value <value>\n", program_invocation_short_name);
207+}
208+
209+int main(int argc, char *argv[])
210+{
211+ int rc = -1;
212+ int fd = -1;
213+ long int type, code, value;
214+ struct input_event ev;
215+ int sync = 0;
216+ const char *path = NULL;
217+
218+ if (argc < 5) {
219+ usage();
220+ goto out;
221+ }
222+
223+ while(1) {
224+ int option_index = 0;
225+ int c;
226+
227+ c = getopt_long(argc, argv, "", opts, &option_index);
228+ if (c == -1) /* we only do long options */
229+ break;
230+
231+ switch(c) {
232+ case 't': /* type */
233+ if (parse_arg(optarg, &type) || type < 0 || type > EV_MAX) {
234+ fprintf(stderr, "error: invalid type argument '%s'\n", optarg);
235+ goto out;
236+ }
237+ break;
238+ case 'c': /* code */
239+ if (parse_arg(optarg, &code) || code < 0 || code > USHRT_MAX) {
240+ fprintf(stderr, "error: invalid code argument '%s'\n", optarg);
241+ goto out;
242+ }
243+ break;
244+ case 'v': /* value */
245+ if (parse_arg(optarg, &value) || value < INT_MIN || value > INT_MAX) {
246+ fprintf(stderr, "error: invalid value argument '%s'\n", optarg);
247+ goto out;
248+ }
249+ break;
250+ case 'd': /* device */
251+ path = optarg;
252+ break;
253+ case 's': /* sync */
254+ sync = 1;
255+ break;
256+ default:
257+ usage();
258+ goto out;
259+ }
260+ }
261+
262+ /* if device wasn't specified as option, take the remaining arg */
263+ if (optind < argc) {
264+ if (argc - optind != 1 || path) {
265+ usage();
266+ goto out;
267+ }
268+ path = argv[optind];
269+ }
270+
271+ if (!path) {
272+ fprintf(stderr, "error: missing device path\n");
273+ usage();
274+ goto out;
275+ }
276+
277+ fd = open(path, O_WRONLY);
278+ if (fd < 0) {
279+ fprintf(stderr, "error: could not open device\n");
280+ goto out;
281+ }
282+
283+ if (evemu_create_event(&ev, type, code, value)) {
284+ fprintf(stderr, "error: failed to create event\n");
285+ goto out;
286+ }
287+
288+ if (evemu_play_one(fd, &ev)) {
289+ fprintf(stderr, "error: could not play event\n");
290+ goto out;
291+ }
292+
293+ if (sync) {
294+ if (evemu_create_event(&ev, EV_SYN, SYN_REPORT, 0)) {
295+ fprintf(stderr, "error: could not create SYN event\n");
296+ goto out;
297+ }
298+ if (evemu_play_one(fd, &ev)) {
299+ fprintf(stderr, "error: could not play SYN event\n");
300+ goto out;
301+ }
302+ }
303+
304+ rc = 0;
305+out:
306+ if (fd > -1)
307+ close(fd);
308+ return rc;
309+}

Subscribers

People subscribed via source and target branches