summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@gmail.com>2014-01-09 17:11:59 -0500
committerBenjamin Tissoires <benjamin.tissoires@gmail.com>2014-01-09 18:09:29 -0500
commit80fa883e0e486d2ed1da7478f5a92de13bbb3de1 (patch)
tree520dbc85935b46e3e891d08ff3246d0a25e31053 /tools
parentd14caab0ce3ab3039c6d6a9320e398cf85d7d4e6 (diff)
tools: evemu-device: rely on libevdev to retrieve the device node
Cleanup a little evemu-device now that we rely on libevdev for the internal stuffs. Needs to export a new function evemu_get_devnode, but we already have broken the ABI. Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/evemu-device.c121
1 files changed, 2 insertions, 119 deletions
diff --git a/tools/evemu-device.c b/tools/evemu-device.c
index ae82578..064d116 100644
--- a/tools/evemu-device.c
+++ b/tools/evemu-device.c
@@ -51,133 +51,17 @@
#include <unistd.h>
#define UINPUT_NODE "/dev/uinput"
-#define MAX_EVENT_NODE 32
-#define SYS_INPUT_DIR "/sys/class/input"
-
-
-/*
- * Extracts the device number from the event file name.
- */
-static int _device_number_from_event_file_name(const char *event_file_name)
-{
- int device_number = -1;
- sscanf(event_file_name, "event%d", &device_number);
- return device_number;
-}
-
-
-/*
- * A filter that passes only input event file names.
- */
-static int _filter_event_files(const struct dirent *d)
-{
- return 0 == strncmp("event", d->d_name, sizeof("event")-1);
-}
-
-
-/*
- * A strict weak ordering function to compare two event file names.
- */
-static int _sort_event_files(const struct dirent **lhs, const struct dirent **rhs)
-{
- int d1 = _device_number_from_event_file_name((*lhs)->d_name);
- int d2 = _device_number_from_event_file_name((*rhs)->d_name);
- return (d1 > d2) ? -1 : (d1 == d2) ? 0 : 1;
-}
-
-
-/*
- * Finds the device node that has a matching device name and the most recent
- * creation time.
- */
-static char * _find_newest_device_node_with_name(const char *device_name)
-{
- struct dirent **event_file_list;
- time_t newest_node_time = 0;
- char *newest_node_name = NULL;
- int i;
-
- int event_file_count = scandir(SYS_INPUT_DIR,
- &event_file_list,
- _filter_event_files,
- _sort_event_files);
- if (event_file_count < 0)
- {
- fprintf(stderr, "error %d opening %s: %s\n",
- errno, SYS_INPUT_DIR, strerror(errno));
- return NULL;
- }
-
- for (i = 0; i < event_file_count; ++i)
- {
- int device_number = _device_number_from_event_file_name(event_file_list[i]->d_name);
-
- char name_file_name[48];
- FILE *name_file;
- char name[128];
- size_t name_length;
-
- /* get the name of the device */
- sprintf(name_file_name, SYS_INPUT_DIR "/event%d/device/name", device_number);
- name_file = fopen(name_file_name, "r");
- if (!name_file)
- {
- fprintf(stderr, "error %d opening %s: %s\n",
- errno, name_file_name, strerror(errno));
- goto next_file;
- }
- name_length = fread(name, sizeof(char), sizeof(name)-1, name_file);
- fclose(name_file);
-
- if (name_length <= 1)
- goto next_file;
-
- /* trim the trailing newline */
- name[name_length-1] = 0;
-
- /* if the device name matches, compare the creation times */
- if (0 == strcmp(name, device_name))
- {
- char input_name[32];
- struct stat sbuf;
- int sstat;
-
- sprintf(input_name, "/dev/input/event%d", device_number);
- sstat = stat(input_name, &sbuf);
- if (sstat < 0)
- {
- fprintf(stderr, "error %d stating %s: %s\n",
- errno, name_file_name, strerror(errno));
- goto next_file;
- }
-
- if (sbuf.st_ctime > newest_node_time)
- {
- newest_node_time = sbuf.st_ctime;
- free(newest_node_name);
- newest_node_name = strdup(input_name);
- }
- }
-
-next_file:
- free(event_file_list[i]);
- }
- free(event_file_list);
-
- return newest_node_name;
-}
-
/*
* Finds the newly created device node and holds it open.
*/
-static void hold_device(const struct evemu_device *dev)
+static void hold_device(struct evemu_device *dev)
{
char data[256];
int ret;
int fd;
- char *device_node = _find_newest_device_node_with_name(evemu_get_name(dev));
+ const char *device_node = evemu_get_devnode(dev);
if (!device_node)
{
fprintf(stderr, "can not determine device node\n");
@@ -195,7 +79,6 @@ static void hold_device(const struct evemu_device *dev)
fflush(stdout);
while ((ret = read(fd, data, sizeof(data))) > 0);
close(fd);
- free(device_node);
}
static int evemu_device(FILE *fp)