diff options
Diffstat (limited to 'rcm-server-udev.c')
-rw-r--r-- | rcm-server-udev.c | 84 |
1 files changed, 22 insertions, 62 deletions
diff --git a/rcm-server-udev.c b/rcm-server-udev.c index fec809d..82a33a8 100644 --- a/rcm-server-udev.c +++ b/rcm-server-udev.c @@ -13,34 +13,9 @@ #include "rcm-server-keymap.h" #include "rcm-server-evdev.h" #include "rcm-server-lirc.h" +#include "rcm-server-rcdev.h" #include "rcm-server-udev.h" -void -rc_device_free(struct rc_device *rcdev) -{ - if (!rcdev) - return; - - list_del(&rcdev->list); - lirc_close(rcdev); - evdev_close(rcdev); - - free(rcdev->path); - free(rcdev->input_name); - free(rcdev->driver_name); - free(rcdev->keymap_name); - free(rcdev->dev_name); - - while (!list_empty(&rcdev->keymaps)) { - struct keymap *keymap = list_first_entry(&rcdev->keymaps, typeof(*keymap), list); - list_del(&keymap->list); - free(keymap->name); - free(keymap); - } - - free(rcdev); -} - static void udev_device_remove(struct manager *mgr, struct udev_device *udev) { @@ -54,7 +29,7 @@ udev_device_remove(struct manager *mgr, struct udev_device *udev) if (strcmp(rcdev->name, name)) continue; sd_bus_emit_object_removed(mgr->bus, rcdev->path); - rc_device_free(rcdev); + rcdev_free(rcdev); mgr->num_rc_devs--; break; } @@ -64,43 +39,19 @@ static void udev_device_add(struct manager *mgr, struct udev_device *udev) { const char *name; - const char *str; - char *path; + const char *tmpstr; struct rc_device *rcdev; struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; int r; name = udev_device_get_sysname(udev); - if (asprintf(&path, "/org/gnome/RemoteControlManager/%s", name) < 0) { - fprintf(stderr, "asprintf failed: %m\n"); + if (!name) return; - } - rcdev = malloc(sizeof(*rcdev)); - if (!rcdev) { - fprintf(stderr, "malloc failed: %m\n"); - free(path); - return; - } - - list_init(&rcdev->keymaps); - rcdev->mgr = mgr; - rcdev->path = path; - rcdev->name = rcdev->path + strlen("/org/gnome/RemoteControlManager/"); - rcdev->evdev_fd = -1; - rcdev->lirc_fd = -1; - rcdev->error = NULL; - rcdev->input_name = NULL; - rcdev->driver_name = NULL; - rcdev->keymap_name = NULL; - rcdev->dev_name = NULL; - - if (keymaps_load(rcdev) < 0) { - fprintf(stderr, "failed to load keymaps: %m\n"); - rc_device_free(rcdev); + rcdev = rcdev_create(mgr, name); + if (!rcdev) return; - } enumerate = udev_enumerate_new(mgr->udev); udev_enumerate_add_match_parent(enumerate, udev); @@ -165,12 +116,21 @@ next: } udev_enumerate_unref(enumerate); - str = udev_device_get_sysattr_value(udev, "uevent"); - if (str) { - char tmp[strlen(str) + 1]; + tmpstr = udev_device_get_devnode(udev); + if (tmpstr) { + r = rcdev_setup(rcdev, tmpstr); + if (r < 0) { + printf("Failed to setup rcdev: %s\n", tmpstr); + rcdev->error = "Error: Failed to setup rcdev"; + } + } + + tmpstr = udev_device_get_sysattr_value(udev, "uevent"); + if (tmpstr) { + char tmp[strlen(tmpstr) + 1]; char *token; - strcpy(tmp, str); + strcpy(tmp, tmpstr); for (token = strtok(tmp, "\n"); token; token = strtok(NULL, "\n")) { if (!strncmp(token, "DRV_NAME=", strlen("DRV_NAME="))) @@ -178,7 +138,7 @@ next: else if (!strncmp(token, "NAME=", strlen("NAME="))) rcdev->keymap_name = strdup(token + strlen("NAME=")); else if (!strncmp(token, "DEVNAME=", strlen("DEVNAME="))) - rcdev->dev_name = strdup(token + strlen("DEVNAME=")); + continue; else if (!strncmp(token, "MAJOR=", strlen("MAJOR="))) continue; else if (!strncmp(token, "MINOR=", strlen("MINOR="))) @@ -198,7 +158,7 @@ next: printf("\tInput name: %s\n", rcdev->input_name); printf("\tDriver : %s\n", rcdev->driver_name); printf("\tKernel map: %s\n", rcdev->keymap_name); - printf("\tDev name : %s\n", rcdev->dev_name); + printf("\trcdev fd : %i\n", rcdev->rcdev_fd); printf("\tevdev fd : %i\n", rcdev->evdev_fd); printf("\tLIRC fd : %i\n", rcdev->lirc_fd); printf("\tDBUS path : %s\n", rcdev->path); @@ -208,7 +168,7 @@ next: list_add(&rcdev->list, &mgr->rc_devs); mgr->num_rc_devs++; - sd_bus_emit_object_added(mgr->bus, path); + sd_bus_emit_object_added(mgr->bus, rcdev->path); } static int |