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
=== modified file '.bzrignore'
--- .bzrignore 2011-11-24 03:24:15 +0000
+++ .bzrignore 2012-06-07 22:25:25 +0000
@@ -19,6 +19,8 @@
19tools/evemu-device19tools/evemu-device
20tools/evemu-device.120tools/evemu-device.1
21tools/evemu-echo21tools/evemu-echo
22tools/evemu-event
23tools/evemu-event.1
22tools/evemu-play24tools/evemu-play
23tools/evemu-play.125tools/evemu-play.1
24tools/evemu-record26tools/evemu-record
2527
=== modified file 'include/evemu.h'
--- include/evemu.h 2012-06-05 16:09:52 +0000
+++ include/evemu.h 2012-06-07 22:25:25 +0000
@@ -328,6 +328,15 @@
328int evemu_write_event(FILE *fp, const struct input_event *ev);328int evemu_write_event(FILE *fp, const struct input_event *ev);
329329
330/**330/**
331 * evemu_create_event() - Create a single event
332 * @ev: pointer to the kernel event to be filled
333 * @type: the event type to set
334 * @code: the event code to set
335 * @value: the event value to set
336 */
337int evemu_create_event(struct input_event *ev, int type, int code, int value);
338
339/**
331 * evemu_read_event() - read kernel event from file340 * evemu_read_event() - read kernel event from file
332 * @fp: file pointer to read the event from341 * @fp: file pointer to read the event from
333 * @ev: pointer to the kernel event to be filled342 * @ev: pointer to the kernel event to be filled
@@ -370,6 +379,14 @@
370 */379 */
371int evemu_record(FILE *fp, int fd, int ms);380int evemu_record(FILE *fp, int fd, int ms);
372381
382
383/**
384 * evemu_play_one() - play one event to kernel device
385 * @fd: file descriptor of kernel device to write to
386 * @ev: pointer to the kernel event to be played
387 */
388int evemu_play_one(int fd, const struct input_event *ev);
389
373/**390/**
374 * evemu_play() - replay events from file to kernel device in realtime391 * evemu_play() - replay events from file to kernel device in realtime
375 * @fp: file pointer to read the events from392 * @fp: file pointer to read the events from
376393
=== modified file 'src/evemu.c'
--- src/evemu.c 2012-06-05 16:13:31 +0000
+++ src/evemu.c 2012-06-07 22:25:25 +0000
@@ -425,6 +425,16 @@
425 return ret;425 return ret;
426}426}
427427
428int evemu_create_event(struct input_event *ev, int type, int code, int value)
429{
430 ev->time.tv_sec = 0;
431 ev->time.tv_usec = 0;
432 ev->type = type;
433 ev->code = code;
434 ev->value = value;
435 return 0;
436}
437
428int evemu_read_event_realtime(FILE *fp, struct input_event *ev,438int evemu_read_event_realtime(FILE *fp, struct input_event *ev,
429 struct timeval *evtime)439 struct timeval *evtime)
430{440{
@@ -449,6 +459,13 @@
449 return ret;459 return ret;
450}460}
451461
462int evemu_play_one(int fd, const struct input_event *ev)
463{
464 int ret;
465 SYSCALL(ret = write(fd, ev, sizeof(*ev)));
466 return (ret < sizeof(*ev));
467}
468
452int evemu_play(FILE *fp, int fd)469int evemu_play(FILE *fp, int fd)
453{470{
454 struct input_event ev;471 struct input_event ev;
455472
=== modified file 'src/libutouch-evemu.ver'
--- src/libutouch-evemu.ver 2012-06-05 16:09:52 +0000
+++ src/libutouch-evemu.ver 2012-06-07 22:25:25 +0000
@@ -1,6 +1,7 @@
1UTOUCH_EVEMU_1.0 {1UTOUCH_EVEMU_1.0 {
2 global:2 global:
3 evemu_create;3 evemu_create;
4 evemu_create_event;
4 evemu_delete;5 evemu_delete;
5 evemu_destroy;6 evemu_destroy;
6 evemu_extract;7 evemu_extract;
@@ -19,6 +20,7 @@
19 evemu_has_prop;20 evemu_has_prop;
20 evemu_new;21 evemu_new;
21 evemu_play;22 evemu_play;
23 evemu_play_one;
22 evemu_read;24 evemu_read;
23 evemu_read_event;25 evemu_read_event;
24 evemu_read_event_realtime;26 evemu_read_event_realtime;
2527
=== modified file 'tools/Makefile.am'
--- tools/Makefile.am 2011-01-05 10:19:44 +0000
+++ tools/Makefile.am 2012-06-07 22:25:25 +0000
@@ -5,7 +5,8 @@
5 evemu-describe \5 evemu-describe \
6 evemu-device \6 evemu-device \
7 evemu-record \7 evemu-record \
8 evemu-play8 evemu-play \
9 evemu-event
910
10INCLUDES=-I$(top_srcdir)/include/11INCLUDES=-I$(top_srcdir)/include/
1112
1213
=== modified file 'tools/evemu-device.txt'
--- tools/evemu-device.txt 2011-01-05 10:19:44 +0000
+++ tools/evemu-device.txt 2012-06-07 22:25:25 +0000
@@ -4,8 +4,8 @@
4NAME4NAME
5----5----
66
7 evemu-device, evemu-play - create a virtual input device and replay an7 evemu-device, evemu-play, evemu-event - create a virtual input device
8 event sequence8 and replay an event sequence
99
10SYNOPSIS10SYNOPSIS
11--------11--------
@@ -13,6 +13,8 @@
1313
14 evemu-play /dev/input/eventX < event-sequence14 evemu-play /dev/input/eventX < event-sequence
1515
16 evemu-event /dev/input/eventX [--sync] --type <type> --code <code> --value <value>
17
16DESCRIPTION18DESCRIPTION
17-----------19-----------
18evemu-device creates a virtual input device based on the description-file.20evemu-device creates a virtual input device based on the description-file.
@@ -24,6 +26,9 @@
24evemu-play replays the event sequence given on stdin through the input26evemu-play replays the event sequence given on stdin through the input
25device. The event sequence must be in the form created by evemu-record(1).27device. The event sequence must be in the form created by evemu-record(1).
2628
29evemu-event plays exactly one event with the current time. If *--sync* is
30given, evemu-event generates an *EV_SYN* event after the event.
31
27evemu-device must be able to write to the uinput device node, and evemu-play32evemu-device must be able to write to the uinput device node, and evemu-play
28must be able to write to the device node specified; in most cases this means33must be able to write to the device node specified; in most cases this means
29it must be run as root.34it must be run as root.
3035
=== added file 'tools/evemu-event.c'
--- tools/evemu-event.c 1970-01-01 00:00:00 +0000
+++ tools/evemu-event.c 2012-06-07 22:25:25 +0000
@@ -0,0 +1,154 @@
1/*****************************************************************************
2 *
3 * evemu - Kernel device emulation
4 *
5 * Copyright (C) 2011 Red Hat, Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21#include "evemu.h"
22#include <getopt.h>
23#include <limits.h>
24#include <stdio.h>
25#include <fcntl.h>
26#include <string.h>
27#include <unistd.h>
28#include <stdlib.h>
29#include <linux/input.h>
30
31static struct option opts[] = {
32 { "type", required_argument, 0, 't'},
33 { "code", required_argument, 0, 'c'},
34 { "value", required_argument, 0, 'v'},
35 { "sync", no_argument, 0, 's'},
36 { "device", required_argument, 0, 'd'}
37};
38
39int parse_arg(const char *arg, long int *value)
40{
41 char *endp;
42
43 *value = strtol(arg, &endp, 0);
44 if (*arg == '\0' || *endp != '\0')
45 return 1;
46 return 0;
47}
48
49void usage(void)
50{
51 fprintf(stderr, "Usage: %s [--sync] <device> --type <type> --code <code> --value <value>\n", program_invocation_short_name);
52}
53
54int main(int argc, char *argv[])
55{
56 int rc = -1;
57 int fd = -1;
58 long int type, code, value;
59 struct input_event ev;
60 int sync = 0;
61 const char *path = NULL;
62
63 if (argc < 5) {
64 usage();
65 goto out;
66 }
67
68 while(1) {
69 int option_index = 0;
70 int c;
71
72 c = getopt_long(argc, argv, "", opts, &option_index);
73 if (c == -1) /* we only do long options */
74 break;
75
76 switch(c) {
77 case 't': /* type */
78 if (parse_arg(optarg, &type) || type < 0 || type > EV_MAX) {
79 fprintf(stderr, "error: invalid type argument '%s'\n", optarg);
80 goto out;
81 }
82 break;
83 case 'c': /* code */
84 if (parse_arg(optarg, &code) || code < 0 || code > USHRT_MAX) {
85 fprintf(stderr, "error: invalid code argument '%s'\n", optarg);
86 goto out;
87 }
88 break;
89 case 'v': /* value */
90 if (parse_arg(optarg, &value) || value < INT_MIN || value > INT_MAX) {
91 fprintf(stderr, "error: invalid value argument '%s'\n", optarg);
92 goto out;
93 }
94 break;
95 case 'd': /* device */
96 path = optarg;
97 break;
98 case 's': /* sync */
99 sync = 1;
100 break;
101 default:
102 usage();
103 goto out;
104 }
105 }
106
107 /* if device wasn't specified as option, take the remaining arg */
108 if (optind < argc) {
109 if (argc - optind != 1 || path) {
110 usage();
111 goto out;
112 }
113 path = argv[optind];
114 }
115
116 if (!path) {
117 fprintf(stderr, "error: missing device path\n");
118 usage();
119 goto out;
120 }
121
122 fd = open(path, O_WRONLY);
123 if (fd < 0) {
124 fprintf(stderr, "error: could not open device\n");
125 goto out;
126 }
127
128 if (evemu_create_event(&ev, type, code, value)) {
129 fprintf(stderr, "error: failed to create event\n");
130 goto out;
131 }
132
133 if (evemu_play_one(fd, &ev)) {
134 fprintf(stderr, "error: could not play event\n");
135 goto out;
136 }
137
138 if (sync) {
139 if (evemu_create_event(&ev, EV_SYN, SYN_REPORT, 0)) {
140 fprintf(stderr, "error: could not create SYN event\n");
141 goto out;
142 }
143 if (evemu_play_one(fd, &ev)) {
144 fprintf(stderr, "error: could not play SYN event\n");
145 goto out;
146 }
147 }
148
149 rc = 0;
150out:
151 if (fd > -1)
152 close(fd);
153 return rc;
154}

Subscribers

People subscribed via source and target branches