[PATCH evemu 1/7] Add wrappers around some libevdev utility functions

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Aug 14 11:00:39 PDT 2014


Mostly for the python binding so we can get rid of the generated mapping
tables.

We export here accessors around type/code/property.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
 python/evemu/base.py | 25 ++++++++++++++++++++
 src/evemu.c          | 25 ++++++++++++++++++++
 src/evemu.h          | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/libevemu.ver     |  9 +++++++
 4 files changed, 125 insertions(+)

diff --git a/python/evemu/base.py b/python/evemu/base.py
index 8d8b3de..53758dd 100644
--- a/python/evemu/base.py
+++ b/python/evemu/base.py
@@ -405,6 +405,31 @@ class LibEvemu(LibraryWrapper):
             "argtypes": (c_void_p,),
             "restype": None
             },
+        #const char *evemu_event_type_get_name(unsigned int type);
+        "evemu_event_type_get_name": {
+            "argtypes": (c_uint,),
+            "restype": c_char_p
+            },
+        #int evemu_event_type_from_name(const char *name);
+        "evemu_event_type_from_name": {
+            "argtypes": (c_char_p,),
+            "restype": c_int
+            },
+        #const char *evemu_event_code_get_name(unsigned int type, unsigned int code);
+        "evemu_event_code_get_name": {
+            "argtypes": (c_uint, c_uint,),
+            "restype": c_char_p
+            },
+        #int evemu_event_code_from_name(unsigned int type, const char *name);
+        "evemu_event_code_from_name": {
+            "argtypes": (c_uint, c_char_p,),
+            "restype": c_int
+            },
+        #const char *evemu_property_get_name(unsigned int prop);
+        "evemu_property_get_name": {
+            "argtypes": (c_uint,),
+            "restype": c_char_p
+            },
         }
 
 class InputEvent(ctypes.Structure):
diff --git a/src/evemu.c b/src/evemu.c
index aae1913..1821f40 100644
--- a/src/evemu.c
+++ b/src/evemu.c
@@ -802,3 +802,28 @@ void evemu_destroy(struct evemu_device *dev)
 		dev->uidev = NULL;
 	}
 }
+
+const char *evemu_event_type_get_name(unsigned int type)
+{
+	return libevdev_event_type_get_name(type);
+}
+
+const char *evemu_event_code_get_name(unsigned int type, unsigned int code)
+{
+	return libevdev_event_code_get_name(type, code);
+}
+
+const char *evemu_property_get_name(unsigned int prop)
+{
+	return libevdev_property_get_name(prop);
+}
+
+int evemu_event_type_from_name(const char *name)
+{
+	return libevdev_event_type_from_name(name);
+}
+
+int evemu_event_code_from_name(unsigned int type, const char *name)
+{
+	return libevdev_event_code_from_name(type, name);
+}
diff --git a/src/evemu.h b/src/evemu.h
index ae3f7d3..c2af364 100644
--- a/src/evemu.h
+++ b/src/evemu.h
@@ -165,6 +165,72 @@ unsigned int evemu_get_id_version(const struct evemu_device *dev);
 void evemu_set_id_version(struct evemu_device *dev, unsigned int version);
 
 /**
+ * evemu_event_type_get_name() - get the name of an event type
+ *
+ * @type: The event type to return the name for.
+ *
+ * Returns he name of the given event type (e.g. EV_ABS) or NULL for an
+ * invalid type
+ */
+const char *evemu_event_type_get_name(unsigned int type);
+
+/**
+ * evemu_event_code_get_name() - get the name of an event code
+ *
+ * @type: The event type for the code to query (EV_SYN, EV_REL, etc.)
+ * @code: The event code to return the name for (e.g. ABS_X)
+ *
+ * Returns the name of the given event code (e.g. ABS_X) or NULL for an
+ * invalid type or code
+ */
+const char *evemu_event_code_get_name(unsigned int type, unsigned int code);
+
+/**
+ * evemu_property_get_name() - get the name of an input property
+ *
+ * @prop: The input prop to return the name for (e.g. INPUT_PROP_BUTTONPAD)
+ *
+ * Returns the name of the given input prop (e.g. INPUT_PROP_BUTTONPAD) or NULL for an
+ * invalid property
+ */
+const char *evemu_property_get_name(unsigned int prop);
+
+/**
+ * evemu_event_type_from_name() - get the code of a given event type name
+ *
+ * Look up an event-type by its name. Event-types start with "EV_" followed by
+ * the name (eg., "EV_ABS"). The "EV_" prefix must be included in the name. It
+ * returns the constant assigned to the event-type or -1 if not found.
+ *
+ * @name: A non-NULL string describing an input-event type ("EV_KEY",
+ * "EV_ABS", ...), zero-terminated.
+ *
+ * Returns the given type constant for the passed name or -1 if not found.
+ */
+int evemu_event_type_from_name(const char *name);
+
+/**
+ * evemu_event_code_from_name() - get the numerical code of a given event code name
+ *
+ * Look up an event code by its type and name. Event codes start with a fixed
+ * prefix followed by their name (eg., "ABS_X"). The prefix must be included in
+ * the name. It returns the constant assigned to the event code or -1 if not
+ * found.
+ *
+ * You have to pass the event type where to look for the name. For instance, to
+ * resolve "ABS_X" you need to pass EV_ABS as type and "ABS_X" as string.
+ * Supported event codes are codes starting with SYN_, KEY_, BTN_, REL_, ABS_,
+ * MSC_, SND_, SW_, LED_, REP_, FF_.
+ *
+ * @type: The event type (EV_* constant) where to look for the name.
+ * @name: A non-NULL string describing an input-event code ("KEY_A",
+ * "ABS_X", "BTN_Y", ...), zero-terminated.
+ *
+ * Returns the given code constant for the passed name or -1 if not found.
+ */
+int evemu_event_code_from_name(unsigned int type, const char *name);
+
+/**
  * evemu_get_abs_minimum() - get kernel minimum value of event type
  * @dev: the device in use
  * @code: the event type code to query
diff --git a/src/libevemu.ver b/src/libevemu.ver
index d5f914f..3cfae96 100644
--- a/src/libevemu.ver
+++ b/src/libevemu.ver
@@ -45,3 +45,12 @@ EVEMU_2.0 {
   local:
     *;
 };
+
+EVEMU_2.1 {
+  global:
+    evemu_event_type_get_name;
+    evemu_event_type_from_name;
+    evemu_event_code_get_name;
+    evemu_event_code_from_name;
+    evemu_property_get_name;
+} EVEMU_2.0;
-- 
2.0.4



More information about the Input-tools mailing list