[PATCH libevdev] Accept LIBEVDEDV_READ_FLAG_BLOCKING as valid flag
Benjamin Tissoires
benjamin.tissoires at gmail.com
Tue Apr 7 19:16:15 PDT 2015
On Mon, Apr 6, 2015 at 6:53 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> https://bugs.freedesktop.org/show_bug.cgi?id=89798
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> libevdev/libevdev.c | 6 +++++-
> test/test-libevdev-events.c | 33 +++++++++++++++++++++++++++++++++
> 2 files changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
> index 0cdbe22..8d7a250 100644
> --- a/libevdev/libevdev.c
> +++ b/libevdev/libevdev.c
> @@ -989,6 +989,10 @@ libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event
> {
> int rc = LIBEVDEV_READ_STATUS_SUCCESS;
> enum event_filter_status filter_status;
> + const int valid_flags = LIBEVDEV_READ_FLAG_NORMAL |
> + LIBEVDEV_READ_FLAG_SYNC |
> + LIBEVDEV_READ_FLAG_FORCE_SYNC |
> + LIBEVDEV_READ_FLAG_BLOCKING;
I guess this should be an unsigned int, not a signed one.
Other than that:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
Cheers,
Benjamin
>
> if (!dev->initialized) {
> log_bug(dev, "device not initialized. call libevdev_set_fd() first\n");
> @@ -996,7 +1000,7 @@ libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event
> } else if (dev->fd < 0)
> return -EBADF;
>
> - if (!(flags & (LIBEVDEV_READ_FLAG_NORMAL|LIBEVDEV_READ_FLAG_SYNC|LIBEVDEV_READ_FLAG_FORCE_SYNC))) {
> + if ((flags & valid_flags) == 0) {
> log_bug(dev, "invalid flags %#x.\n", flags);
> return -EINVAL;
> }
> diff --git a/test/test-libevdev-events.c b/test/test-libevdev-events.c
> index c950959..44447a0 100644
> --- a/test/test-libevdev-events.c
> +++ b/test/test-libevdev-events.c
> @@ -97,6 +97,38 @@ START_TEST(test_next_event_invalid_fd)
> }
> END_TEST
>
> +START_TEST(test_next_event_blocking)
> +{
> + struct uinput_device* uidev;
> + struct libevdev *dev;
> + int fd, flags;
> + int rc;
> + struct input_event ev;
> +
> + test_create_device(&uidev, &dev,
> + EV_REL, REL_X,
> + EV_REL, REL_Y,
> + EV_KEY, BTN_LEFT,
> + -1);
> +
> + fd = libevdev_get_fd(dev);
> + flags = fcntl(fd, F_GETFL) & ~O_NONBLOCK;
> + rc = fcntl(fd, F_SETFL, flags);
> + ck_assert_int_eq(rc, 0);
> +
> + uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1);
> + uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
> + rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_BLOCKING, &ev);
> + ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
> + ck_assert_int_eq(ev.type, EV_KEY);
> + ck_assert_int_eq(ev.code, BTN_LEFT);
> + ck_assert_int_eq(ev.value, 1);
> +
> + libevdev_free(dev);
> + uinput_device_free(uidev);
> +}
> +END_TEST
> +
> START_TEST(test_syn_dropped_event)
> {
> struct uinput_device* uidev;
> @@ -2116,6 +2148,7 @@ libevdev_events(void)
> TCase *tc = tcase_create("event polling");
> tcase_add_test(tc, test_next_event);
> tcase_add_test(tc, test_next_event_invalid_fd);
> + tcase_add_test(tc, test_next_event_blocking);
> tcase_add_test(tc, test_syn_dropped_event);
> tcase_add_test(tc, test_double_syn_dropped_event);
> tcase_add_test(tc, test_event_type_filtered);
> --
> 2.3.3
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools
More information about the Input-tools
mailing list