summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-07-20 22:33:46 +0200
committerDavid Härdeman <david@hardeman.nu>2015-07-20 22:33:46 +0200
commitf685878d4eb057d29c2b8087a1c55eb027bb7dda (patch)
tree9fedb3a66619e41f0185fefd412cce67f746a111
parentdc6bb0926504150b010b9313ef66216fa4cb9e3a (diff)
server: determine the evdev that corresponds to a given rcdev
-rw-r--r--rcm-server-main.c41
-rw-r--r--rcm-server-main.h1
2 files changed, 42 insertions, 0 deletions
diff --git a/rcm-server-main.c b/rcm-server-main.c
index cde13a0..5d9cb20 100644
--- a/rcm-server-main.c
+++ b/rcm-server-main.c
@@ -699,6 +699,9 @@ add_device(struct manager *mgr, struct udev_device *udev)
const char *str;
char *path;
struct device *device;
+ struct udev_enumerate *enumerate;
+ struct udev_list_entry *devices, *dev_list_entry;
+ struct udev_device *evdev;
name = udev_device_get_sysname(udev);
if (asprintf(&path, "/org/gnome/RemoteControlManager/%s", name) < 0) {
@@ -716,12 +719,49 @@ add_device(struct manager *mgr, struct udev_device *udev)
list_init(&device->keymaps);
device->path = path;
device->name = device->path + strlen("/org/gnome/RemoteControlManager/");
+ device->devnode = NULL;
if (keymaps_load(device) < 0) {
fprintf(stderr, "failed to load keymaps: %m\n");
free(path);
free(device);
+ return;
+ }
+
+ enumerate = udev_enumerate_new(mgr->udev);
+ udev_enumerate_add_match_parent(enumerate, udev);
+ udev_enumerate_add_match_sysname(enumerate, "event*");
+ udev_enumerate_scan_devices(enumerate);
+ devices = udev_enumerate_get_list_entry(enumerate);
+
+ udev_list_entry_foreach(dev_list_entry, devices) {
+ const char *path;
+ const char *devnode;
+
+ path = udev_list_entry_get_name(dev_list_entry);
+ if (!path) {
+ printf("Failed to get udev name\n");
+ continue;
+ }
+
+ evdev = udev_device_new_from_syspath(mgr->udev, path);
+ if (!evdev) {
+ printf("Failed to create udev device\n");
+ continue;
+ }
+
+ devnode = udev_device_get_devnode(evdev);
+ if (devnode && !device->devnode) {
+ device->devnode = strdup(devnode);
+ if (!device->devnode)
+ printf("Failed to strdup devnode\n");
+ else
+ printf("Devnode is %s\n", device->devnode);
+ }
+
+ udev_device_unref(evdev);
}
+ udev_enumerate_unref(enumerate);
str = udev_device_get_sysattr_value(udev, "uevent");
if (str) {
@@ -748,6 +788,7 @@ add_device(struct manager *mgr, struct udev_device *udev)
printf("\tAction : %s\n", udev_device_get_action(udev));
printf("\tDriver : %s\n", device->driver_name);
printf("\tKernel map: %s\n", device->keymap_name);
+ printf("\tDevnode : %s\n", device->devnode);
printf("\tProtocols : %s\n",
udev_device_get_sysattr_value(udev, "protocols"));
diff --git a/rcm-server-main.h b/rcm-server-main.h
index 188ffab..60b2968 100644
--- a/rcm-server-main.h
+++ b/rcm-server-main.h
@@ -6,6 +6,7 @@ struct device {
char *path;
char *driver_name;
char *keymap_name;
+ char *devnode;
struct list_head list;
struct list_head keymaps;
};