[RFC PATCH libevdev] Revamp the API once again

Peter Hutterer peter.hutterer at who-t.net
Thu Aug 29 18:13:56 PDT 2013


Another look at the current API showed some inconsistencies, rectified
in this commit:

libevdev_kernel_*: modify the underlying kernel device
libevdev_event_type_*: something with an event type
libevdev_event_code_*: something with an event code
libevdev_event_*: struct input_event-related functions (i.e. not device-related)
libevdev_property_*: something with a property
libevdev_*: anything applying to a device

Hopefully that's the last API change. Current symbols deprecated and aliased.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Bikeshedding appreciated here. I think I'm happy with this API, or at least
one that prefixes everything similarly. A couple of more comments:

libevdev_event_type obviously overlaps with libevdev_event but a simple 
libevdev_type_* seemed wrong to me. same for *_code_*.

there's no prefix to work on a device but libevdev_device_* seemed extreme
and operating on a device should be the default use-case anyway. so I think
that's fine.

I've got the follow-up patch to actually switch everything to use this new
API, but I'll leave it out for now until the bikeshedding completes.

if this API gets in, the plan is something like this:
* release 0.4 with all the new goodness
* fix things
* release 0.5 with deprecated symbols removed, a versioned and stable API
* switch everything to use libevdev
* fix things
* 1.0 release. buy a tropical island, live like a king for the rest of our
  days


 libevdev/libevdev-int.h |  1 +
 libevdev/libevdev.c     | 35 +++++++++++++++++++++++++++++++++++
 libevdev/libevdev.h     | 30 +++++++++++++++++++++++-------
 3 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/libevdev/libevdev-int.h b/libevdev/libevdev-int.h
index 61c2454..8454079 100644
--- a/libevdev/libevdev-int.h
+++ b/libevdev/libevdev-int.h
@@ -38,6 +38,7 @@
 #define ABS_MT_MAX ABS_MT_TOOL_Y
 #define ABS_MT_CNT (ABS_MT_MAX - ABS_MT_MIN + 1)
 #define LIBEVDEV_EXPORT __attribute__((visibility("default")))
+#define ALIAS(_to) __attribute__((alias(#_to)))
 
 #undef min
 #undef max
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 9b37f70..e04d48a 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -1164,14 +1164,24 @@ libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab)
 	return rc < 0 ? -errno : 0;
 }
 
+/* DEPRECATED */
 LIBEVDEV_EXPORT int
 libevdev_is_event_type(const struct input_event *ev, unsigned int type)
+ALIAS(libevdev_event_is_type);
+
+LIBEVDEV_EXPORT int
+libevdev_event_is_type(const struct input_event *ev, unsigned int type)
 {
 	return type < EV_CNT && ev->type == type;
 }
 
+/* DEPRECATED */
 LIBEVDEV_EXPORT int
 libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code)
+ALIAS(libevdev_event_is_code);
+
+LIBEVDEV_EXPORT int
+libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code)
 {
 	int max;
 
@@ -1182,8 +1192,13 @@ libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned
 	return (max > -1 && code <= (unsigned int)max && ev->code == code);
 }
 
+/* DEPRECATED */
 LIBEVDEV_EXPORT const char*
 libevdev_get_event_type_name(unsigned int type)
+ALIAS(libevdev_event_type_get_name);
+
+LIBEVDEV_EXPORT const char*
+libevdev_event_type_get_name(unsigned int type)
 {
 	if (type > EV_MAX)
 		return NULL;
@@ -1191,8 +1206,13 @@ libevdev_get_event_type_name(unsigned int type)
 	return ev_map[type];
 }
 
+/* DEPRECATED */
 LIBEVDEV_EXPORT const char*
 libevdev_get_event_code_name(unsigned int type, unsigned int code)
+ALIAS(libevdev_event_code_get_name);
+
+LIBEVDEV_EXPORT const char*
+libevdev_event_code_get_name(unsigned int type, unsigned int code)
 {
 	int max = libevdev_get_event_type_max(type);
 
@@ -1202,8 +1222,18 @@ libevdev_get_event_code_name(unsigned int type, unsigned int code)
 	return event_type_map[type][code];
 }
 
+/* DEPRECATED */
+LIBEVDEV_EXPORT const char*
+libevdev_get_input_prop_name(unsigned int prop)
+ALIAS(libevdev_property_get_name);
+
+/* DEPRECATED */
 LIBEVDEV_EXPORT const char*
 libevdev_get_property_name(unsigned int prop)
+ALIAS(libevdev_property_get_name);
+
+LIBEVDEV_EXPORT const char*
+libevdev_property_get_name(unsigned int prop)
 {
 	if (prop > INPUT_PROP_MAX)
 		return NULL;
@@ -1211,8 +1241,13 @@ libevdev_get_property_name(unsigned int prop)
 	return input_prop_map[prop];
 }
 
+/* DEPRECATED */
 LIBEVDEV_EXPORT int
 libevdev_get_event_type_max(unsigned int type)
+ALIAS(libevdev_event_type_get_max);
+
+LIBEVDEV_EXPORT int
+libevdev_event_type_get_max(unsigned int type)
 {
 	if (type > EV_MAX)
 		return -1;
diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
index ff423b9..3c0a478 100644
--- a/libevdev/libevdev.h
+++ b/libevdev/libevdev.h
@@ -1225,7 +1225,7 @@ int libevdev_kernel_set_led_values(struct libevdev *dev, ...);
  * @return 1 if the event type matches the given type, 0 otherwise (or if
  * type is invalid)
  */
-int libevdev_is_event_type(const struct input_event *ev, unsigned int type);
+int libevdev_event_is_type(const struct input_event *ev, unsigned int type);
 
 /**
  * @ingroup misc
@@ -1250,7 +1250,7 @@ int libevdev_is_event_type(const struct input_event *ev, unsigned int type);
  * @return 1 if the event type matches the given type and code, 0 otherwise
  * (or if type/code are invalid)
  */
-int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code);
+int libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code);
 
 /**
  * @ingroup misc
@@ -1263,7 +1263,7 @@ int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsi
  * @note The list of names is compiled into libevdev. If the kernel adds new
  * defines for new properties libevdev will not automatically pick these up.
  */
-const char * libevdev_get_event_type_name(unsigned int type);
+const char * libevdev_event_type_get_name(unsigned int type);
 /**
  * @ingroup misc
  *
@@ -1276,7 +1276,7 @@ const char * libevdev_get_event_type_name(unsigned int type);
  * @note The list of names is compiled into libevdev. If the kernel adds new
  * defines for new properties libevdev will not automatically pick these up.
  */
-const char * libevdev_get_event_code_name(unsigned int type, unsigned int code);
+const char * libevdev_event_code_get_name(unsigned int type, unsigned int code);
 
 /**
  * @ingroup misc
@@ -1289,9 +1289,9 @@ const char * libevdev_get_event_code_name(unsigned int type, unsigned int code);
  * @note The list of names is compiled into libevdev. If the kernel adds new
  * defines for new properties libevdev will not automatically pick these up.
  * @note On older kernels input properties may not be defined and
- * libevdev_get_input_prop_name() will always return NULL
+ * libevdev_property_get_name() will always return NULL
  */
-const char* libevdev_get_property_name(unsigned int prop);
+const char* libevdev_property_get_name(unsigned int prop);
 
 /**
  * @ingroup misc
@@ -1305,7 +1305,7 @@ const char* libevdev_get_property_name(unsigned int prop);
  * @note The max value is compiled into libevdev. If the kernel changes the
  * max value, libevdev will not automatically pick these up.
  */
-int libevdev_get_event_type_max(unsigned int type);
+int libevdev_event_type_get_max(unsigned int type);
 
 /**
  * @ingroup bits
@@ -1333,6 +1333,22 @@ int libevdev_get_repeat(struct libevdev *dev, int *delay, int *period);
 /* replacement: libevdev_kernel_set_abs_info */
 int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs) LIBEVDEV_DEPRECATED;
 
+/** replacement: libevdev_event_type_get_max */
+int libevdev_get_event_type_max(unsigned int type) LIBEVDEV_DEPRECATED;
+
+/** replacement: libevdev_property_get_name */
+const char* libevdev_get_property_name(unsigned int prop);
+
+/** replacement: libevdev_event_type_get_name */
+const char * libevdev_get_event_type_name(unsigned int type) LIBEVDEV_DEPRECATED;
+/** replacement: libevdev_event_code_get_name */
+const char * libevdev_get_event_code_name(unsigned int type, unsigned int code) LIBEVDEV_DEPRECATED;
+
+/** replacement: libevdev_event_is_type */
+int libevdev_is_event_type(const struct input_event *ev, unsigned int type);
+
+/** replacement: libevdev_event_is_code */
+int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code);
 /**************************************/
 
 #ifdef __cplusplus
-- 
1.8.2.1



More information about the Input-tools mailing list