[PATCH evemu 4/4] py: Add and use wrapper for libevemu calls

Peter Hutterer peter.hutterer at who-t.net
Mon Jan 13 01:28:43 PST 2014


On Fri, Jan 10, 2014 at 07:32:27PM -0500, Benjamin Tissoires wrote:
> On Fri, Jan 10, 2014 at 3:30 AM, Daniel Martin <consume.noise at gmail.com> wrote:
> > Introduce a class LibEvemu in base.py, which wraps API calls to
> > libevemu, and replace _call()s by using it.
> > As this obsoletes the class EvEmuBase, it's removed as well.
> >
> > v2: Removed tests if functions can be found in the loaded library and
> >     added tests that the loaded library is static in the class.
> >
> > Signed-off-by: Daniel Martin <consume.noise at gmail.com>
> > ---
> >  python/evemu/__init__.py        |  93 ++++++---------
> >  python/evemu/base.py            | 254 +++++++++++++++++++++++++++++++++++++---
> >  python/evemu/const.py           |  33 ------
> >  python/evemu/tests/test_base.py |  29 ++++-
> >  4 files changed, 292 insertions(+), 117 deletions(-)
> >
> > diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
> > index f474036..8e725c7 100644
> > --- a/python/evemu/__init__.py
> > +++ b/python/evemu/__init__.py
> > @@ -53,36 +53,28 @@ class Device(object):
[...]
> > +            "errcheck": expect_eq_zero
> > +            },
> > +        #int evemu_play_one(int fd, const struct input_event *ev);
> > +        "evemu_play_one": {
> > +            "argtypes": (c_int, c_void_p),
> > +            "restype": c_int,
> > +            "errcheck": expect_eq_zero
> > +            },
> > +        #int evemu_play(FILE *fp, int fd);
> > +        "evemu_play": {
> > +            "argtypes": (c_void_p, c_int),
> > +            "restype": c_int,
> > +            "errcheck": expect_eq_zero
> > +            },
> > +        #int evemu_create(struct evemu_device *dev, int fd);
> > +        "evemu_create": {
> > +            "argtypes": (c_void_p, c_int),
> > +            "restype": c_int,
> > +            "errcheck": expect_eq_zero
> > +            },
> > +        #void evemu_destroy(struct evemu_device *dev);
> > +        "evemu_destroy": {
> > +            "argtypes": (c_void_p,),
> > +            "restype": None
> > +            },
> > +        }
> 
> Thanks for this job.
> I would rather prefer having some kind of script which would generate
> the dict for us. However, I don't think it is possible to generate
> this automatically without spending hours.

the easiest approach to that would be to declare the functions in xml and
create both C and python files from it. that would be easiest with a
supposedly simple xslt template. But I doubt the effort is worth it. evemu
has seen quite a few changes over the last months but I suspect that will
trickle to a stop now. The API itself hasn't changed that much and libevdev
will take care of any changes in the evdev api so I think evemu will be in
maintenance mode soon - changes like this only push that out for
little actual gain.

a simple script to compare libevemu.ver is probably the best choice here,
and a bit more vigilance from us when reviewing the patches.

Cheers,
   Peter

> How about adding a test during the build which would fail if
> "src/libevemu.ver" and _api_prototypes are not matching (at least for
> additions/removals). I am thinking of it because I just added 1
> function to the API, and I did not updated the python wrapper. I guess
> this will happen again in the future, and a failure during compile
> would force us to update it accordingly.
> 
> Any thoughts on that?
> I'll add this to my to-do list for next week I think.

> 
> Cheers,
> Benjamin
> 
> > diff --git a/python/evemu/const.py b/python/evemu/const.py
> > index 35f1878..19c507a 100644
> > --- a/python/evemu/const.py
> > +++ b/python/evemu/const.py
> > @@ -2,39 +2,6 @@ LIB = "libevemu.so"
> >  ENCODING="iso8859-1"
> >  UINPUT_NODE = "/dev/uinput"
> >
> > -# The following should be examined every release of evemu
> > -API = [
> > -    "evemu_new",
> > -    "evemu_delete",
> > -    "evemu_extract",
> > -    "evemu_write",
> > -    "evemu_read",
> > -    "evemu_write_event",
> > -    "evemu_record",
> > -    "evemu_read_event",
> > -    "evemu_play",
> > -    "evemu_create",
> > -    "evemu_destroy",
> > -    # Device settrs
> > -    "evemu_set_name",
> > -    # Device gettrs
> > -    "evemu_get_version",
> > -    "evemu_get_name",
> > -    "evemu_get_id_bustype",
> > -    "evemu_get_id_vendor",
> > -    "evemu_get_id_product",
> > -    "evemu_get_id_version",
> > -    "evemu_get_abs_minimum",
> > -    "evemu_get_abs_maximum",
> > -    "evemu_get_abs_fuzz",
> > -    "evemu_get_abs_flat",
> > -    "evemu_get_abs_resolution",
> > -    # Device hasers
> > -    "evemu_has_prop",
> > -    "evemu_has_event",
> > -    "evemu_has_bit",
> > -    ]
> > -
> >  event_types = {
> >      "EV_SYN": 0x00,
> >      "EV_KEY": 0x01,
> > diff --git a/python/evemu/tests/test_base.py b/python/evemu/tests/test_base.py
> > index 29bdb15..bc35c73 100644
> > --- a/python/evemu/tests/test_base.py
> > +++ b/python/evemu/tests/test_base.py
> > @@ -7,12 +7,6 @@ import evemu.testing.testcase
> >
> >  class EvEmuBaseTestCase(evemu.testing.testcase.BaseTestCase):
> >
> > -    def test_so_library_found(self):
> > -        wrapper = evemu.base.EvEmuBase()
> > -        # Make sure that the library loads
> > -        self.assertNotEqual(
> > -            wrapper._lib._name.find("libevemu"), -1)
> > -
> >      def test_libc_found(self):
> >          lib = evemu.base.LibC._load()
> >          self.assertNotEqual(lib, None)
> > @@ -36,5 +30,28 @@ class EvEmuBaseTestCase(evemu.testing.testcase.BaseTestCase):
> >
> >          self.assertEqual(first._loaded_lib, second._loaded_lib)
> >
> > +    def test_libevemu_found(self):
> > +        lib = evemu.base.LibEvemu._load()
> > +        self.assertNotEqual(lib, None)
> > +        self.assertTrue(lib._name.startswith("libevemu"))
> > +
> > +    def test_libevemu_static_from_load(self):
> > +        first = evemu.base.LibEvemu._load()
> > +        self.assertNotEqual(first, None)
> > +
> > +        second = evemu.base.LibEvemu._load()
> > +        self.assertNotEqual(second, None)
> > +
> > +        self.assertEqual(first, second)
> > +
> > +    def test_libevemu_static_in_object(self):
> > +        first = evemu.base.LibEvemu()
> > +        self.assertNotEqual(first, None)
> > +
> > +        second = evemu.base.LibEvemu()
> > +        self.assertNotEqual(second, None)
> > +
> > +        self.assertEqual(first._loaded_lib, second._loaded_lib)
> > +
> >  if __name__ == "__main__":
> >      unittest.main()
> > --
> > 1.8.5.2
> >
> > _______________________________________________
> > Input-tools mailing list
> > Input-tools at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/input-tools
> _______________________________________________
> 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