[PATCH evemu 7/7] python: use evemu_event_type_get_max directly

Peter Hutterer peter.hutterer at who-t.net
Thu Aug 14 20:29:07 PDT 2014


On Thu, Aug 14, 2014 at 02:00:45PM -0400, Benjamin Tissoires wrote:
> Instead of using evemu.event_get_value("EV_ABS", "ABS_MAX"), we can rely
> on the internal libevdev API to use evemu.event_get_max("EV_ABS").
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
> ---
> 
> As mentioned in the cover letter, I am not sure about the benefits of
> this one.

yeah, I don't think this gives us any benefits. The libevdev one is merely
there to avoid the various switch statements when iterating over a bunch of
events and thus multiple event types. For evemu, I don't think this is
needed. The only benefit we get here is to know what the libevdev-built-in
max is, but even that probably won't give us much. Let's hold off on this
one please.

Cheers,
   Peter

> 
>  python/evemu/__init__.py          | 13 +++++++++++++
>  python/evemu/base.py              |  6 ++++++
>  python/evemu/tests/test_device.py | 14 +++++++-------
>  src/evemu.c                       |  5 +++++
>  src/evemu.h                       | 11 +++++++++++
>  src/libevemu.ver                  |  1 +
>  6 files changed, 43 insertions(+), 7 deletions(-)
> 
> diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
> index dea2be8..b66b5e5 100644
> --- a/python/evemu/__init__.py
> +++ b/python/evemu/__init__.py
> @@ -32,6 +32,7 @@ __all__ = ["Device",
>             "InputEvent",
>             "event_get_value",
>             "event_get_name",
> +           "event_get_max",
>             "input_prop_get_value",
>             "input_prop_get_name"]
>  
> @@ -99,6 +100,18 @@ def event_get_name(event_type, event_code = None):
>  
>      return ev_code_name
>  
> +def event_get_max(event_type):
> +    t = -1
> +    if type(event_type) == str:
> +        t = _libevemu.evemu_event_type_from_name(event_type)
> +    else:
> +        t = event_type
> +
> +    if t < 0:
> +        raise KeyError("Unable to find type " + repr(event_type))
> +
> +    return _libevemu.evemu_event_type_get_max(t)
> +
>  def input_prop_get_name(prop):
>      """
>      Return the name of the input property, or None if undefined.
> diff --git a/python/evemu/base.py b/python/evemu/base.py
> index 53758dd..5963a06 100644
> --- a/python/evemu/base.py
> +++ b/python/evemu/base.py
> @@ -405,6 +405,11 @@ class LibEvemu(LibraryWrapper):
>              "argtypes": (c_void_p,),
>              "restype": None
>              },
> +        #int evemu_event_type_get_max(unsigned int type);
> +        "evemu_event_type_get_max": {
> +            "argtypes": (c_uint,),
> +            "restype": c_int
> +            },
>          #const char *evemu_event_type_get_name(unsigned int type);
>          "evemu_event_type_get_name": {
>              "argtypes": (c_uint,),
> @@ -430,6 +435,7 @@ class LibEvemu(LibraryWrapper):
>              "argtypes": (c_uint,),
>              "restype": c_char_p
>              },
> +
>          }
>  
>  class InputEvent(ctypes.Structure):
> diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
> index ed8011d..5b97de0 100644
> --- a/python/evemu/tests/test_device.py
> +++ b/python/evemu/tests/test_device.py
> @@ -178,35 +178,35 @@ class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
>          self.assertEqual(self._device.id_version, 272)
>  
>      def test_get_abs_minimum(self):
> -        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
> +        absmax = evemu.event_get_max("EV_ABS")
>          keys = range(0, absmax + 1)
>          results = dict((x, self._device.get_abs_minimum(x)) for x in keys)
>  
>          self.assertEqual(results, self.get_expected_abs("min"))
>  
>      def test_get_abs_maximum(self):
> -        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
> +        absmax = evemu.event_get_max("EV_ABS")
>          keys = range(0, absmax + 1)
>          results = dict((x, self._device.get_abs_maximum(x)) for x in keys)
>  
>          self.assertEqual(results, self.get_expected_abs("max"))
>  
>      def test_get_abs_fuzz(self):
> -        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
> +        absmax = evemu.event_get_max("EV_ABS")
>          keys = range(0, absmax + 1)
>          results = dict((x, self._device.get_abs_fuzz(x)) for x in keys)
>  
>          self.assertEqual(results, self.get_expected_abs("fuzz"))
>  
>      def test_get_abs_flat(self):
> -        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
> +        absmax = evemu.event_get_max("EV_ABS")
>          keys = range(0, absmax + 1)
>          results = dict((x, self._device.get_abs_flat(x)) for x in keys)
>  
>          self.assertEqual(results, self.get_expected_abs("flat"))
>  
>      def test_get_abs_resolution(self):
> -        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
> +        absmax = evemu.event_get_max("EV_ABS")
>          keys = range(0, absmax + 1)
>          results = dict((x, self._device.get_abs_resolution(x)) for x in keys)
>  
> @@ -220,14 +220,14 @@ class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
>          self.assertEqual(results, self.get_expected_propbits())
>  
>      def test_has_event_ev_abs(self):
> -        absmax = evemu.event_get_value("EV_ABS", "ABS_MAX")
> +        absmax = evemu.event_get_max("EV_ABS")
>          keys = range(0, absmax + 1)
>          results = dict((x, self._device.has_event("EV_ABS", x)) for x in keys)
>  
>          self.assertEqual(results, self.get_expected_absbits())
>  
>      def test_has_event_ev_key(self):
> -        keymax = evemu.event_get_value("EV_KEY", "KEY_MAX")
> +        keymax = evemu.event_get_max("EV_KEY")
>          keys = range(0, keymax + 1)
>          results = dict((x, self._device.has_event("EV_KEY", x)) for x in keys)
>  
> diff --git a/src/evemu.c b/src/evemu.c
> index 1821f40..c4c9a09 100644
> --- a/src/evemu.c
> +++ b/src/evemu.c
> @@ -818,6 +818,11 @@ const char *evemu_property_get_name(unsigned int prop)
>  	return libevdev_property_get_name(prop);
>  }
>  
> +int evemu_event_type_get_max(unsigned int type)
> +{
> +	return libevdev_event_type_get_max(type);
> +}
> +
>  int evemu_event_type_from_name(const char *name)
>  {
>  	return libevdev_event_type_from_name(name);
> diff --git a/src/evemu.h b/src/evemu.h
> index c2af364..a072d9b 100644
> --- a/src/evemu.h
> +++ b/src/evemu.h
> @@ -196,6 +196,17 @@ const char *evemu_event_code_get_name(unsigned int type, unsigned int code);
>  const char *evemu_property_get_name(unsigned int prop);
>  
>  /**
> + * evemu_event_type_get_max() - get the max value for the given event type
> + *
> + * @type: The event type to return the maximum for (EV_ABS, EV_REL, etc.). No max is defined for
> + * EV_SYN.
> + *
> + * Returns the max value defined for the given event type, e.g. ABS_MAX for a type of EV_ABS, or -1
> + * for an invalid type.
> + */
> +int evemu_event_type_get_max(unsigned int type);
> +
> +/**
>   * 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
> diff --git a/src/libevemu.ver b/src/libevemu.ver
> index 3cfae96..a48a76a 100644
> --- a/src/libevemu.ver
> +++ b/src/libevemu.ver
> @@ -48,6 +48,7 @@ EVEMU_2.0 {
>  
>  EVEMU_2.1 {
>    global:
> +    evemu_event_type_get_max;
>      evemu_event_type_get_name;
>      evemu_event_type_from_name;
>      evemu_event_code_get_name;
> -- 
> 2.0.4
> 
> _______________________________________________
> 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