diff options
author | David Härdeman <david@hardeman.nu> | 2017-04-18 22:54:54 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2017-04-18 22:54:54 +0200 |
commit | 927f0751fc8be8a71c2d8b255522259d01a7fcef (patch) | |
tree | a4f59932b9a4df5ecdcb26014fc30e74aae05866 /rcm-server-evdev.c | |
parent | 0c5c949451f6f8f71e4489db19390ba6f931e2af (diff) |
Rename struct device to struct rc_device
Diffstat (limited to 'rcm-server-evdev.c')
-rw-r--r-- | rcm-server-evdev.c | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/rcm-server-evdev.c b/rcm-server-evdev.c index e39ef3d..a49e3aa 100644 --- a/rcm-server-evdev.c +++ b/rcm-server-evdev.c @@ -47,12 +47,15 @@ evdev_get_protocol_name(__u16 protocol) } static const char * -evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode) +evdev_guess_protocol(struct rc_device *rcdev, uint64_t scancode, uint32_t keycode) { struct rc_keymap_entry rke; unsigned i; - if (!device || device->evdev_fd < 0) + if (!rcdev) + return NULL; + + if (rcdev->evdev_fd < 0) return NULL; for (i = 0; ; i++) { @@ -60,7 +63,7 @@ evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode) rke.len = RKE_SIZE; rke.index = i; rke.flags = INPUT_KEYMAP_BY_INDEX; - if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke)) + if (ioctl(rcdev->evdev_fd, EVIOCGKEYCODE_V2, &rke)) break; if (rke.rc.scancode != scancode) @@ -76,7 +79,7 @@ evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode) } int -evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol, +evdev_get_mapping(struct rc_device *rcdev, unsigned index, unsigned *ret_protocol, uint64_t *ret_scancode, struct linux_input_keycode **ret_lik) { struct rc_keymap_entry rke; @@ -87,7 +90,7 @@ evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol, rke.index = index; rke.flags = INPUT_KEYMAP_BY_INDEX; - if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke)) + if (ioctl(rcdev->evdev_fd, EVIOCGKEYCODE_V2, &rke)) return 0; lik = get_linux_keycode_by_value(rke.keycode); @@ -103,7 +106,7 @@ evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol, } int -evdev_set_mapping(struct device *device, unsigned protocol, uint64_t scancode, +evdev_set_mapping(struct rc_device *rcdev, unsigned protocol, uint64_t scancode, struct linux_input_keycode *lik) { struct rc_keymap_entry rke; @@ -119,7 +122,7 @@ evdev_set_mapping(struct device *device, unsigned protocol, uint64_t scancode, else rke.keycode = KEY_RESERVED; - if (ioctl(device->evdev_fd, EVIOCSKEYCODE_V2, &rke)) { + if (ioctl(rcdev->evdev_fd, EVIOCSKEYCODE_V2, &rke)) { r = -errno; printf("EVIOCSKEYCODE_V2 failed (%s)\n", strerror(errno)); } @@ -128,7 +131,7 @@ evdev_set_mapping(struct device *device, unsigned protocol, uint64_t scancode, } static int -evdev_clear_keymap(struct device *device) +evdev_clear_keymap(struct rc_device *rcdev) { struct rc_keymap_entry rke; unsigned count = 0; @@ -140,7 +143,7 @@ evdev_clear_keymap(struct device *device) rke.len = RKE_SIZE; rke.index = 0; rke.flags = INPUT_KEYMAP_BY_INDEX; - if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke)) { + if (ioctl(rcdev->evdev_fd, EVIOCGKEYCODE_V2, &rke)) { printf("done (%u entries removed)\n", count); break; } @@ -151,7 +154,7 @@ evdev_clear_keymap(struct device *device) */ rke.keycode = KEY_RESERVED; - if (ioctl(device->evdev_fd, EVIOCSKEYCODE_V2, &rke)) { + if (ioctl(rcdev->evdev_fd, EVIOCSKEYCODE_V2, &rke)) { r = -errno; printf("failed (%s)\n", strerror(errno)); break; @@ -163,7 +166,7 @@ evdev_clear_keymap(struct device *device) } static void -set_keycode_new(struct device *device, __u16 protocol, __u64 scancode, __u32 keycode) +set_keycode_new(struct rc_device *rcdev, __u16 protocol, __u64 scancode, __u32 keycode) { struct rc_keymap_entry rke; @@ -176,21 +179,21 @@ set_keycode_new(struct device *device, __u16 protocol, __u64 scancode, __u32 key printf("Setting keycode (new ioctl) 0x%08llX (0x%02X) to 0x%02X\n", rke.rc.scancode, rke.rc.protocol, rke.keycode); - if (ioctl(device->evdev_fd, EVIOCSKEYCODE_V2, &rke)) { + if (ioctl(rcdev->evdev_fd, EVIOCSKEYCODE_V2, &rke)) { printf("Unable to call SETKEYCODE2 ioctl\n"); exit(EXIT_FAILURE); } } static int -evdev_set_keymap(struct device *device, struct keymap *keymap) +evdev_set_keymap(struct rc_device *rcdev, struct keymap *keymap) { unsigned i; printf("\tSetting up keymap: %s\n", keymap->name); for (i = 0; i < keymap->keycode_count; i++) - set_keycode_new(device, + set_keycode_new(rcdev, keymap->keycodes[i].protocol, keymap->keycodes[i].scancode, keymap->keycodes[i].lik->value); @@ -202,7 +205,7 @@ evdev_set_keymap(struct device *device, struct keymap *keymap) static int evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - struct device *device = userdata; + struct rc_device *rcdev = userdata; struct input_event ev; static struct linux_input_keycode *keycode = NULL; static bool pressed = false; @@ -212,13 +215,12 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) static bool protocol_recv = false; int r; - if (fd != device->evdev_fd) - fprintf(stderr, "evdev fd mismatch: %i != %i\n", device->evdev_fd, fd); + if (fd != rcdev->evdev_fd) + fprintf(stderr, "evdev fd mismatch: %i != %i\n", rcdev->evdev_fd, fd); if (revents & EPOLLHUP) { fprintf(stderr, "evdev connection closed!\n"); - close(fd); - device->evdev_fd = -1; + evdev_close(rcdev); return 0; } @@ -230,7 +232,7 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) do { char buf[100]; - r = libevdev_next_event(device->evdev_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); + r = libevdev_next_event(rcdev->evdev_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); if (r != LIBEVDEV_READ_STATUS_SUCCESS) continue; @@ -239,8 +241,8 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) libevdev_event_code_get_name(ev.type, ev.code), ev.value, ev.value); - sd_bus_emit_signal(device->mgr->bus, - device->path, + sd_bus_emit_signal(rcdev->mgr->bus, + rcdev->path, "org.gnome.RemoteControlManager.Device", "Event", "s", buf); @@ -286,7 +288,7 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) /* FIXME: protocol reporting will change */ if (scancode_recv) { if (!protocol_recv) { - protocol_name = evdev_guess_protocol(device, scancode, keycode ? keycode->value : KEY_RESERVED); + protocol_name = evdev_guess_protocol(rcdev, scancode, keycode ? keycode->value : KEY_RESERVED); printf(" protocol %s (guessed)", protocol_name); } else { protocol_name = evdev_get_protocol_name(protocol); @@ -304,16 +306,16 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) printf("\n"); if (scancode_recv && protocol_name) - sd_bus_emit_signal(device->mgr->bus, - device->path, + sd_bus_emit_signal(rcdev->mgr->bus, + rcdev->path, "org.gnome.RemoteControlManager.Device", "KeyPressed", "sts", protocol_name, scancode, keycode ? keycode->name : "KEY_RESERVED"); else if (keycode && !pressed) - sd_bus_emit_signal(device->mgr->bus, - device->path, + sd_bus_emit_signal(rcdev->mgr->bus, + rcdev->path, "org.gnome.RemoteControlManager.Device", "KeyReleased", "s", keycode->name); @@ -335,45 +337,45 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) } int -evdev_setup(struct device *device, const char *path) +evdev_setup(struct rc_device *rcdev, const char *path) { int r; struct keymap *keymap; /* FIXME: Fixup error handling */ - if (!device) + if (!rcdev) return -EINVAL; - if (device->evdev_fd >= 0) { + if (rcdev->evdev_fd >= 0) { printf("Multiple evdev devices!?\n"); return 0; } - device->evdev_fd = open(path, O_RDONLY | O_NONBLOCK); - r = libevdev_new_from_fd(device->evdev_fd, &device->evdev_dev); + rcdev->evdev_fd = open(path, O_RDONLY | O_NONBLOCK); + r = libevdev_new_from_fd(rcdev->evdev_fd, &rcdev->evdev_dev); if (r < 0) { printf("Failed to open evdev device %s: %s\n", path, strerror(-r)); - close(device->evdev_fd); + evdev_close(rcdev); return r; } - device->input_name = strdup(libevdev_get_name(device->evdev_dev)); + rcdev->input_name = strdup(libevdev_get_name(rcdev->evdev_dev)); printf("Performing evdev setup for device %s (%s)\n", - device->path, libevdev_get_name(device->evdev_dev)); - r = evdev_clear_keymap(device); + rcdev->path, libevdev_get_name(rcdev->evdev_dev)); + r = evdev_clear_keymap(rcdev); if (r < 0) return r; - list_for_each_entry(keymap, &device->keymaps, list) - r = evdev_set_keymap(device, keymap); + list_for_each_entry(keymap, &rcdev->keymaps, list) + r = evdev_set_keymap(rcdev, keymap); - if (sd_event_add_io(device->mgr->event, &device->evdev_ev, - device->evdev_fd, EPOLLIN, evdev_read, device) < 0) { + if (sd_event_add_io(rcdev->mgr->event, &rcdev->evdev_ev, + rcdev->evdev_fd, EPOLLIN, evdev_read, rcdev) < 0) { printf("Failed to add event source for evdev device %s: %s\n", path, strerror(errno)); r = -errno; - evdev_close(device); + evdev_close(rcdev); return r; } @@ -381,15 +383,15 @@ evdev_setup(struct device *device, const char *path) } void -evdev_close(struct device *device) +evdev_close(struct rc_device *rcdev) { - if (!device) + if (!rcdev) return; - if (device->evdev_fd < 0) + if (rcdev->evdev_fd < 0) return; - close(device->evdev_fd); - device->evdev_fd = -1; + close(rcdev->evdev_fd); + rcdev->evdev_fd = -1; } |