Add a flag for forcing a SYN_DROPPED event
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 28 Jun 2013 00:18:35 +0000 (10:18 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 28 Jun 2013 01:21:44 +0000 (11:21 +1000)
uinput doesn't route a SYN_DROPPED, so we neeed to handle fds in
a rather complicated manner. For tests, avoid this and instead force
the library to sync if a specific flag is given.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
libevdev/libevdev.c
libevdev/libevdev.h

index 3e2c98a..5dd6bdb 100644 (file)
@@ -530,7 +530,7 @@ int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_e
        if (dev->fd < 0)
                return -ENODEV;
 
-       if (!(flags & (LIBEVDEV_READ_NORMAL|LIBEVDEV_READ_SYNC)))
+       if (!(flags & (LIBEVDEV_READ_NORMAL|LIBEVDEV_READ_SYNC|LIBEVDEV_FORCE_SYNC)))
                return -EINVAL;
 
        if (flags & LIBEVDEV_READ_SYNC) {
@@ -558,6 +558,13 @@ int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_e
        if (rc < 0 && rc != -EAGAIN)
                goto out;
 
+       if (flags & LIBEVDEV_FORCE_SYNC) {
+               dev->need_sync = 1;
+               rc = 1;
+               goto out;
+       }
+
+
        if (queue_shift(dev, ev) != 0)
                return -EAGAIN;
 
index 0cf6295..d9f1daa 100644 (file)
@@ -189,6 +189,9 @@ struct libevdev;
 enum EvdevReadFlags {
        LIBEVDEV_READ_SYNC              = 1, /**< Process data in sync mode */
        LIBEVDEV_READ_NORMAL            = 2, /**< Process data in normal mode */
+       LIBEVDEV_FORCE_SYNC             = 4, /**< Pretend the next event is a SYN_DROPPED. There is
+                                                 no reason to ever use this except for
+                                                 automated tests, so don't. */
 };
 
 /**