[PATCH evemu 1/2] tools: evemu-device: rely on libevdev to retrieve the device node

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Jan 9 15:26:47 PST 2014



On 09/01/14 18:21, Peter Hutterer wrote:
> I'd rather not make the evemu API explicitly dependent on a libevdev ABI
> decision. this needs to be either documented (e.g. evemu_create() for an fd
> < 0 opens it automatically) and handled in evemu_create directly or we add a
> new call for evemu_create_managed() that handles everything. I'd go for the
> latter.
> 

Right, I was not very happy of having to add the libevdev dependency either.

so, here is another attempt (I'm on fire!):

From: Benjamin Tissoires <benjamin.tissoires at gmail.com>
Date: Thu, 9 Jan 2014 18:22:56 -0500
Subject: [PATCH evemu] tools: device: rely on libevdev to open the uinput node

libevdev can take care of the uinput node, I am glad to remove this part.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
 src/evemu.c          |  6 ++++++
 src/evemu.h          | 12 ++++++++++++
 src/libevemu.ver     |  1 +
 tools/evemu-device.c | 11 +----------
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/evemu.c b/src/evemu.c
index 21adef1..b494c18 100644
--- a/src/evemu.c
+++ b/src/evemu.c
@@ -781,6 +781,12 @@ int evemu_create(struct evemu_device *dev, int fd)
 	return libevdev_uinput_create_from_device(dev->evdev, fd, &dev->uidev);
 }
 
+int evemu_create_managed(struct evemu_device *dev)
+{
+	return libevdev_uinput_create_from_device(dev->evdev,
+		LIBEVDEV_UINPUT_OPEN_MANAGED, &dev->uidev);
+}
+
 const char *evemu_get_devnode(struct evemu_device *dev)
 {
 	return libevdev_uinput_get_devnode(dev->uidev);
diff --git a/src/evemu.h b/src/evemu.h
index d25d707..ae3f7d3 100644
--- a/src/evemu.h
+++ b/src/evemu.h
@@ -423,6 +423,18 @@ int evemu_play(FILE *fp, int fd);
 int evemu_create(struct evemu_device *dev, int fd);
 
 /**
+ * evemu_create_managed() - create a kernel device from the evemu configuration
+ * @dev: the device in use
+ *
+ * Creates a new device with all the properties of the evemu device.
+ * Compared to evemu_create, evemu will take care of the handling of the uinput
+ * file descriptor.
+ *
+ * Returns zero if successful, negative error otherwise.
+ */
+int evemu_create_managed(struct evemu_device *dev);
+
+/**
  * evemu_get_devnode() - get device node
  * @dev: the device in use
  *
diff --git a/src/libevemu.ver b/src/libevemu.ver
index 8f216fd..3b13930 100644
--- a/src/libevemu.ver
+++ b/src/libevemu.ver
@@ -2,6 +2,7 @@ EVEMU_2.0 {
   global:
     evemu_create;
     evemu_create_event;
+    evemu_create_managed;
     evemu_delete;
     evemu_destroy;
     evemu_extract;
diff --git a/tools/evemu-device.c b/tools/evemu-device.c
index 46ffaeb..c0a7157 100644
--- a/tools/evemu-device.c
+++ b/tools/evemu-device.c
@@ -50,8 +50,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#define UINPUT_NODE "/dev/uinput"
-
 /*
  * Finds the newly created device node and holds it open.
  */
@@ -85,7 +83,6 @@ static int evemu_device(FILE *fp)
 {
 	struct evemu_device *dev;
 	int ret = -ENOMEM;
-	int fd;
 
 	dev = evemu_new(NULL);
 	if (!dev)
@@ -100,18 +97,12 @@ static int evemu_device(FILE *fp)
 		evemu_set_name(dev, name);
 	}
 
-	ret = fd = open(UINPUT_NODE, O_WRONLY);
+	ret = evemu_create_managed(dev);
 	if (ret < 0)
 		goto out;
-
-	ret = evemu_create(dev, fd);
-	if (ret < 0)
-		goto out_close;
 	hold_device(dev);
 	evemu_destroy(dev);
 
-out_close:
-	close(fd);
 out:
 	evemu_delete(dev);
 
-- 
1.8.3.1

The sad thing is that now the net line of code difference is positive :(

Cheers,
Benjamin


More information about the Input-tools mailing list