From: jeon Date: Mon, 25 Mar 2019 09:55:15 +0000 (+0900) Subject: evdev: support device add/del APIs for runtime input device control X-Git-Tag: submit/tizen/20190530.092249~90 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62f6871050dadc69dab0802ea23697204a983d4c;p=platform%2Fcore%2Fuifw%2Fpepper.git evdev: support device add/del APIs for runtime input device control Change-Id: I7b116200428e550258d625fe76701a36cd06e2c2 --- diff --git a/src/lib/evdev/evdev-internal.h b/src/lib/evdev/evdev-internal.h index ca073bf..a5dddb1 100644 --- a/src/lib/evdev/evdev-internal.h +++ b/src/lib/evdev/evdev-internal.h @@ -27,6 +27,8 @@ #include #include +#define MAX_PATH_LEN 16 + struct pepper_evdev { pepper_compositor_t *compositor; @@ -41,6 +43,8 @@ struct evdev_device_info pepper_evdev_t *evdev; pepper_input_device_t *device; struct wl_event_source *event_source; + int fd; + char path[MAX_PATH_LEN]; pepper_list_t link; }; diff --git a/src/lib/evdev/evdev.c b/src/lib/evdev/evdev.c index 9121763..c0b77ff 100644 --- a/src/lib/evdev/evdev.c +++ b/src/lib/evdev/evdev.c @@ -213,8 +213,10 @@ _evdev_keyboard_device_open(pepper_evdev_t *evdev, const char *path) PEPPER_CHECK(device_info, goto error, "[%s] Failed to allocate memory for device info...\n", __FUNCTION__); event_mask = WL_EVENT_READABLE; + device_info->fd = fd; device_info->evdev = evdev; device_info->device = device; + strncpy(device_info->path, path, MAX_PATH_LEN - 1); device_info->event_source = wl_event_loop_add_fd(evdev->event_loop, fd, event_mask, _evdev_keyboard_event_fd_read, device_info); PEPPER_CHECK(device_info->event_source, goto error, "[%s] Failed to add fd as an event source...\n", __FUNCTION__); @@ -245,6 +247,61 @@ error: return 0; } +static void +_evdev_keyboard_device_close(pepper_evdev_t *evdev, const char *path) +{ + evdev_device_info_t *device_info = NULL; + + evdev_device_info_t *tmp = NULL; + + PEPPER_CHECK(path, return, "[%s] Given path is NULL.\n", __FUNCTION__); + + pepper_list_for_each_safe(device_info, tmp, &evdev->device_list, link) { + if (!strncmp(path, device_info->path, MAX_PATH_LEN)) { + pepper_input_device_destroy(device_info->device); + wl_event_source_remove(device_info->event_source); + close(device_info->fd); + + pepper_list_remove(&device_info->link); + free(device_info); + + break; + } + } +} + + +PEPPER_API pepper_bool_t +pepper_evdev_device_path_add(pepper_evdev_t *evdev, const char *path) +{ + int res = 0; + + PEPPER_CHECK(evdev, return PEPPER_FALSE, "Invalid evdev structure.\n"); + PEPPER_CHECK(path, return PEPPER_FALSE, "Invalid path.\n"); + + if (!strncmp(path, "event", 5)) { + res = _evdev_keyboard_device_open(evdev, path); + } else { + PEPPER_ERROR("Invalid path to open: %s\n", path); + } + + if (res) return PEPPER_TRUE; + return PEPPER_FALSE; +} + +PEPPER_API void +pepper_evdev_device_path_remove(pepper_evdev_t *evdev, const char *path) +{ + PEPPER_CHECK(evdev, return, "Invalid evdev structure.\n"); + PEPPER_CHECK(path, return, "Invalid path.\n"); + + if (!strncmp(path, "event", 5)) { + _evdev_keyboard_device_close(evdev, path); + } else { + PEPPER_ERROR("Invalid path to close: %s\n", path); + } +} + PEPPER_API uint32_t pepper_evdev_device_probe(pepper_evdev_t *evdev, uint32_t caps) { @@ -317,6 +374,8 @@ pepper_evdev_destroy(pepper_evdev_t *evdev) pepper_input_device_destroy(device_info->device); if (device_info->event_source) wl_event_source_remove(device_info->event_source); + if (device_info->fd) + close(device_info->fd); pepper_list_remove(&device_info->link); free(device_info); diff --git a/src/lib/evdev/pepper-evdev.h b/src/lib/evdev/pepper-evdev.h index cfb6f84..0a16e08 100644 --- a/src/lib/evdev/pepper-evdev.h +++ b/src/lib/evdev/pepper-evdev.h @@ -34,6 +34,12 @@ typedef struct pepper_evdev pepper_evdev_t; typedef struct evdev_device_info evdev_device_info_t; typedef struct evdev_key_event evdev_key_event_t; +PEPPER_API pepper_bool_t +pepper_evdev_device_path_add(pepper_evdev_t *evdev, const char *path); + +PEPPER_API void +pepper_evdev_device_path_remove(pepper_evdev_t *evdev, const char *path); + PEPPER_API uint32_t pepper_evdev_device_probe(pepper_evdev_t *evdev, uint32_t caps);