[PATCH libevdev 1/3] Enumerate libevdev_next_event() return codes

Peter Hutterer peter.hutterer at who-t.net
Tue Sep 10 19:12:47 PDT 2013


Improved readability in callers, changing magic numbers 0 and 1 to

rc = libevdev_next_event();
if (rc == LIBEVDEV_READ_STATUS_SUCCESS)
    do_something();
else if (rc == LIBEVDEV_READ_STATUS_SYNC)
    do_something_else()

No ABI changes, the enum values are the previously documented values,
this is just a readability improvement.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev.c         |  8 ++---
 libevdev/libevdev.h         | 49 ++++++++++++++++++-------
 test/test-libevdev-events.c | 88 ++++++++++++++++++++++-----------------------
 tools/libevdev-events.c     | 10 +++---
 4 files changed, 89 insertions(+), 66 deletions(-)

diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 70680d6..d863c8d 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -722,7 +722,7 @@ read_more_events(struct libevdev *dev)
 LIBEVDEV_EXPORT int
 libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev)
 {
-	int rc = 0;
+	int rc = LIBEVDEV_READ_STATUS_SUCCESS;
 
 	if (dev->fd < 0) {
 		log_bug("device not initialized. call libevdev_set_fd() first\n");
@@ -778,7 +778,7 @@ libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event
 
 		if (flags & LIBEVDEV_FORCE_SYNC) {
 			dev->sync_state = SYNC_NEEDED;
-			rc = 1;
+			rc = LIBEVDEV_READ_STATUS_SYNC;
 			goto out;
 		}
 
@@ -794,12 +794,12 @@ libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event
 	rc = 0;
 	if (ev->type == EV_SYN && ev->code == SYN_DROPPED) {
 		dev->sync_state = SYNC_NEEDED;
-		rc = 1;
+		rc = LIBEVDEV_READ_STATUS_SYNC;
 	}
 
 	if (flags & LIBEVDEV_READ_SYNC && dev->queue_nsync > 0) {
 		dev->queue_nsync--;
-		rc = 1;
+		rc = LIBEVDEV_READ_STATUS_SYNC;
 		if (dev->queue_nsync == 0)
 			dev->sync_state = SYNC_NONE;
 	}
diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
index 2e8af10..f08fc04 100644
--- a/libevdev/libevdev.h
+++ b/libevdev/libevdev.h
@@ -501,25 +501,48 @@ int libevdev_change_fd(struct libevdev* dev, int fd);
  */
 int libevdev_get_fd(const struct libevdev* dev);
 
+
+/**
+ * @ingroup events
+ */
+enum libevdev_read_status {
+	/**
+	 * libevdev_next_event() has finished without an error
+	 * and an event is available for processing.
+	 *
+	 * @see libevdev_next_event
+	 */
+	LIBEVDEV_READ_STATUS_SUCCESS = 0,
+	/**
+	 * Depending on the libevdev_next_event() read flag:
+	 * * libevdev received a SYN_DROPPED from the device, and the caller should
+	 * now resync the device, or,
+	 * * an event has been read in sync mode.
+	 *
+	 * @see libevdev_next_event
+	 */
+	LIBEVDEV_READ_STATUS_SYNC = 1,
+};
 /**
  * @ingroup events
  *
  * Get the next event from the device. This function operates in two different
  * modes: normal mode or sync mode.
  *
- * In normal mode, this function returns 0 and returns the event in the
- * parameter ev. If no events are available at this time, it returns -EAGAIN
- * and ev is undefined.
+ * In normal mode, this function returns LIBEVDEV_READ_STATUS_SUCCESS and
+ * returns the event in the parameter ev. If no events are available at this
+ * time, it returns -EAGAIN and ev is undefined.
  *
- * If a SYN_DROPPED is read from the device, this function returns 1. The
- * caller should now call this function with the LIBEVDEV_READ_SYNC flag set,
- * to get the set of events that make up the device state delta. This function
- * returns 1 for each event part of that delta, until it returns -EAGAIN once
- * all events have been synced.
+ * If a SYN_DROPPED is read from the device, this function returns
+ * LIBEVDEV_READ_STATUS_SYNC. The caller should now call this function with the
+ * LIBEVDEV_READ_SYNC flag set, to get the set of events that make up the
+ * device state delta. This function returns LIBEVDEV_READ_STATUS_SYNC for
+ * each event part of that delta, until it returns -EAGAIN once all events
+ * have been synced.
  *
  * If a device needs to be synced by the caller but the caller does not call
- * with the LIBEVDEV_READ_SYNC flag set, all events from the diff are dropped
- * and event processing continues as normal.
+ * with the LIBEVDEV_READ_STATUS_SYNC flag set, all events from the diff are
+ * dropped and event processing continues as normal.
  *
  * @param dev The evdev device, already initialized with libevdev_set_fd()
  * @param flags Set of flags to determine behaviour. If LIBEVDEV_READ_NORMAL
@@ -527,10 +550,10 @@ int libevdev_get_fd(const struct libevdev* dev);
  * set, the next event is read in sync mode.
  * @param ev On success, set to the current event.
  * @return On failure, a negative errno is returned.
- * @retval 0 One or more events where read of the device
+ * @retval LIBEVDEV_READ_STATUS_SUCCESS One or more events where read of the device
  * @retval -EAGAIN No events are currently available on the device
- * @retval 1 A SYN_DROPPED event was received, or a synced event was
- * returned.
+ * @retval LIBEVDEV_READ_STATUS_SYNC A SYN_DROPPED event was received, or a
+ * synced event was returned.
  *
  * @note This function is signal-safe.
  */
diff --git a/test/test-libevdev-events.c b/test/test-libevdev-events.c
index d82c577..b1c263d 100644
--- a/test/test-libevdev-events.c
+++ b/test/test-libevdev-events.c
@@ -48,7 +48,7 @@ START_TEST(test_next_event)
 	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_NORMAL, &ev);
-	ck_assert_int_eq(rc, 0);
+	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);
@@ -87,10 +87,9 @@ START_TEST(test_syn_event)
 	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_NORMAL, &ev);
-	ck_assert_int_eq(rc, 0);
+	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);
-
 	rc = pipe2(pipefd, O_NONBLOCK);
 	ck_assert_int_eq(rc, 0);
 
@@ -104,11 +103,11 @@ START_TEST(test_syn_event)
 
 	libevdev_change_fd(dev, uinput_device_get_fd(uidev));
 
-	ck_assert_int_eq(rc, 0);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	/* only check for the rc, nothing actually changed on the device */
 
@@ -144,7 +143,7 @@ START_TEST(test_event_type_filtered)
 	uinput_device_event(uidev, EV_KEY, REL_Y, 1);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
-	ck_assert_int_eq(rc, 0);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 
@@ -179,13 +178,13 @@ START_TEST(test_event_code_filtered)
 	uinput_device_event(uidev, EV_REL, REL_Y, 1);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
-	ck_assert_int_eq(rc, 0);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
 	ck_assert_int_eq(ev.type, EV_REL);
 	ck_assert_int_eq(ev.code, REL_Y);
 	ck_assert_int_eq(ev.value, 1);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
-	ck_assert_int_eq(rc, 0);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 
@@ -261,24 +260,25 @@ START_TEST(test_syn_delta_button)
 	uinput_device_event(uidev, EV_KEY, KEY_MAX, 1);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_KEY);
 	ck_assert_int_eq(ev.code, BTN_LEFT);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_KEY);
 	ck_assert_int_eq(ev.code, BTN_RIGHT);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_KEY);
 	ck_assert_int_eq(ev.code, KEY_MAX);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
@@ -327,25 +327,25 @@ START_TEST(test_syn_delta_abs)
 	uinput_device_event(uidev, EV_ABS, ABS_MAX, 700);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_X);
 	ck_assert_int_eq(ev.value, 100);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_Y);
 	ck_assert_int_eq(ev.value, 500);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MAX);
 	ck_assert_int_eq(ev.value, 700);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
@@ -403,61 +403,61 @@ START_TEST(test_syn_delta_mt)
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_X);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_Y);
 	ck_assert_int_eq(ev.value, 5);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_SLOT);
 	ck_assert_int_eq(ev.value, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_POSITION_X);
 	ck_assert_int_eq(ev.value, 100);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_POSITION_Y);
 	ck_assert_int_eq(ev.value, 500);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_TRACKING_ID);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_SLOT);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_POSITION_X);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_POSITION_Y);
 	ck_assert_int_eq(ev.value, 5);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_ABS);
 	ck_assert_int_eq(ev.code, ABS_MT_TRACKING_ID);
 	ck_assert_int_eq(ev.value, 2);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
@@ -489,25 +489,25 @@ START_TEST(test_syn_delta_led)
 	uinput_device_event(uidev, EV_LED, LED_MAX, 1);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_LED);
 	ck_assert_int_eq(ev.code, LED_NUML);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_LED);
 	ck_assert_int_eq(ev.code, LED_CAPSL);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_LED);
 	ck_assert_int_eq(ev.code, LED_MAX);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
@@ -543,25 +543,25 @@ START_TEST(test_syn_delta_sw)
 	uinput_device_event(uidev, EV_SW, SW_MAX, 1);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SW);
 	ck_assert_int_eq(ev.code, SW_LID);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SW);
 	ck_assert_int_eq(ev.code, SW_MICROPHONE_INSERT);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SW);
 	ck_assert_int_eq(ev.code, SW_MAX);
 	ck_assert_int_eq(ev.value, 1);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_SYN);
 	ck_assert_int_eq(ev.code, SYN_REPORT);
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
@@ -606,7 +606,7 @@ START_TEST(test_skipped_sync)
 	uinput_device_event(uidev, EV_ABS, ABS_Y, 500);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
 	ck_assert_int_eq(rc, -EAGAIN);
@@ -650,10 +650,10 @@ START_TEST(test_incomplete_sync)
 	uinput_device_event(uidev, EV_ABS, ABS_Y, 500);
 	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 	ck_assert_int_eq(ev.type, EV_KEY);
 	ck_assert_int_eq(ev.code, BTN_LEFT);
 	ck_assert_int_eq(ev.value, 1);
@@ -687,7 +687,7 @@ START_TEST(test_empty_sync)
 	ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
 
 	rc = libevdev_next_event(dev, LIBEVDEV_FORCE_SYNC, &ev);
-	ck_assert_int_eq(rc, 1);
+	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);
 
 	rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
 	ck_assert_int_eq(rc, -EAGAIN);
@@ -863,7 +863,7 @@ START_TEST(test_mt_event_values)
 
 	do {
 		rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
-	} while (rc == 0);
+	} while (rc == LIBEVDEV_READ_STATUS_SUCCESS);
 	ck_assert_int_eq(rc, -EAGAIN);
 
 	ck_assert_int_eq(libevdev_get_current_slot(dev), 1);
diff --git a/tools/libevdev-events.c b/tools/libevdev-events.c
index 1511227..fe7092c 100644
--- a/tools/libevdev-events.c
+++ b/tools/libevdev-events.c
@@ -171,18 +171,18 @@ main(int argc, char **argv)
 	do {
 		struct input_event ev;
 		rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL|LIBEVDEV_READ_BLOCKING, &ev);
-		if (rc == 1) {
+		if (rc == LIBEVDEV_READ_STATUS_SYNC) {
 			printf("::::::::::::::::::::: dropped ::::::::::::::::::::::\n");
-			while (rc == 1) {
+			while (rc == LIBEVDEV_READ_STATUS_SYNC) {
 				print_sync_event(&ev);
 				rc = libevdev_next_event(dev, LIBEVDEV_READ_SYNC, &ev);
 			}
 			printf("::::::::::::::::::::: re-synced ::::::::::::::::::::::\n");
-		} else if (rc == 0)
+		} else if (rc == LIBEVDEV_READ_STATUS_SUCCESS)
 			print_event(&ev);
-	} while (rc == 1 || rc == 0 || rc == -EAGAIN);
+	} while (rc == LIBEVDEV_READ_STATUS_SYNC || rc == LIBEVDEV_READ_STATUS_SUCCESS || rc == -EAGAIN);
 
-	if (rc != 0 && rc != -EAGAIN)
+	if (rc != LIBEVDEV_READ_STATUS_SUCCESS && rc != -EAGAIN)
 		fprintf(stderr, "Failed to handle events: %s\n", strerror(rc));
 
 	rc = 0;
-- 
1.8.3.1



More information about the Input-tools mailing list