| diff --git a/include/evemu.h b/include/evemu.h |
| index 1f55d5c..e4ce667 100644 |
| --- a/include/evemu.h |
| +++ b/include/evemu.h |
| @@ -285,6 +285,7 @@ int evemu_record(FILE *fp, int fd, int ms); |
| * evemu_play() - replay events from file to kernel device in realtime |
| * @fp: file pointer to read the events from |
| * @fd: file descriptor of kernel device to write to |
| + * @fp_time: file descriptor for keeping playback timing information |
| * |
| * Contiuously reads events from the file and writes them to the |
| * kernel device, in realtime. The function terminates when end of |
| @@ -292,7 +293,7 @@ int evemu_record(FILE *fp, int fd, int ms); |
| * |
| * Returns zero if successful, negative error otherwise. |
| */ |
| -int evemu_play(FILE *fp, int fd); |
| +int evemu_play(FILE *fp, int fd, FILE *fp_time); |
| |
| /** |
| * evemu_create() - create a kernel device from the evemu configuration |
| diff --git a/src/Makefile.in b/src/Makefile.in |
| index 8468f02..6378196 100644 |
| --- a/src/Makefile.in |
| +++ b/src/Makefile.in |
| @@ -70,7 +70,7 @@ am__base_list = \ |
| am__installdirs = "$(DESTDIR)$(libdir)" \ |
| "$(DESTDIR)$(libutouch_evemuincludedir)" |
| LTLIBRARIES = $(lib_LTLIBRARIES) |
| -libutouch_evemu_la_LIBADD = |
| +libutouch_evemu_la_LIBADD = -lrt |
| am_libutouch_evemu_la_OBJECTS = evemu.lo |
| libutouch_evemu_la_OBJECTS = $(am_libutouch_evemu_la_OBJECTS) |
| libutouch_evemu_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ |
| diff --git a/src/evemu.c b/src/evemu.c |
| index df6b250..02377f1 100644 |
| --- a/src/evemu.c |
| +++ b/src/evemu.c |
| @@ -49,6 +49,8 @@ |
| #include <poll.h> |
| #include <ctype.h> |
| #include <unistd.h> |
| +#include <sys/time.h> |
| +#include <time.h> |
| |
| #ifndef UI_SET_PROPBIT |
| #define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int) |
| @@ -376,15 +378,25 @@ int evemu_read_event_realtime(FILE *fp, struct input_event *ev, |
| return ret; |
| } |
| |
| -int evemu_play(FILE *fp, int fd) |
| +int evemu_play(FILE *fp, int fd, FILE *fp_time) |
| { |
| struct input_event ev; |
| struct timeval evtime; |
| + struct timespec curr_tp; |
| int ret; |
| + char *time_format = "E: %lu.%06u %04x %04x %-4d -- playback %lu.%09u\n"; |
| |
| memset(&evtime, 0, sizeof(evtime)); |
| - while (evemu_read_event_realtime(fp, &ev, &evtime) > 0) |
| + while (evemu_read_event_realtime(fp, &ev, &evtime) > 0) { |
| + if (fp_time != NULL) { |
| + clock_gettime(CLOCK_MONOTONIC, &curr_tp); |
| + fprintf(fp_time, time_format, |
| + ev.time.tv_sec, ev.time.tv_usec, |
| + ev.type, ev.code, ev.value, |
| + curr_tp.tv_sec, curr_tp.tv_nsec); |
| + } |
| SYSCALL(ret = write(fd, &ev, sizeof(ev))); |
| + } |
| |
| return 0; |
| } |
| diff --git a/tools/evemu-play.c b/tools/evemu-play.c |
| index 7b9b777..f66275e 100644 |
| --- a/tools/evemu-play.c |
| +++ b/tools/evemu-play.c |
| @@ -49,8 +49,9 @@ |
| int main(int argc, char *argv[]) |
| { |
| int fd; |
| - if (argc != 2) { |
| - fprintf(stderr, "Usage: %s <device>\n", argv[0]); |
| + FILE *fp_time = NULL; |
| + if (argc < 2 || argc > 3) { |
| + fprintf(stderr, "Usage: %s <device> [output_file]\n", argv[0]); |
| fprintf(stderr, "\n"); |
| fprintf(stderr, "Event data is read from standard input.\n"); |
| return -1; |
| @@ -60,9 +61,20 @@ int main(int argc, char *argv[]) |
| fprintf(stderr, "error: could not open device\n"); |
| return -1; |
| } |
| - if (evemu_play(stdin, fd)) { |
| + if (argc == 3) { |
| + fp_time = fopen(argv[2], "w"); |
| + if (fp_time == NULL) { |
| + fprintf(stderr, "error: could not open output file %s.\n", |
| + argv[2]); |
| + return -1; |
| + } |
| + } |
| + if (evemu_play(stdin, fd, fp_time)) { |
| fprintf(stderr, "error: could not describe device\n"); |
| } |
| + if (fp_time != NULL) { |
| + close(fp_time); |
| + } |
| close(fd); |
| return 0; |
| } |