From b6fc94e23753ed3e4b5d16ece7bebfc06d71e292 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 1 Nov 2021 15:31:39 +0900 Subject: [PATCH] input: make input module initialize plugin input-handler Change-Id: Ia72cd8f207b782da369e4161e1bd9269045e19e6 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 2 +- plugins/iot-headed/display/core.c | 5 +-- plugins/iot-headless/input/input-handler.c | 55 +++++++++++------------------- plugins/mobile/display/core.c | 5 +-- plugins/tv/display/core.c | 5 +-- plugins/wearable/display/core.c | 5 +-- src/display/display-input.c | 35 ++++++++----------- src/display/poll.h | 3 -- src/input/input.c | 38 ++++++++++++--------- src/shared/common.c | 1 - src/shared/devices.c | 11 ++++++ src/shared/devices.h | 1 + src/shared/plugin.c | 2 -- src/tzip/tzip-utility.c | 1 - src/tzip/tzip.c | 1 - src/usbhost/usb-host.c | 2 -- 16 files changed, 74 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 926fcbc..15d8125 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,7 @@ FOREACH(flag ${REQUIRED_PKGS_CFLAGS}) ENDFOREACH(flag) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE -rdynamic") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -D_GNU_SOURCE") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-pie") diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index a91533b..c772d9e 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -2042,9 +2042,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2256,7 +2254,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index bb2bb43..ae25482 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -20,6 +20,7 @@ #include #include +#include "shared/common.h" #include "shared/devices.h" #include "shared/log.h" @@ -28,6 +29,7 @@ #define LONGPRESS_INTERVAL 10000 /* milisecond */ +static int longpress_interval = LONGPRESS_INTERVAL; static guint longpress_timer_id; static gboolean longpressed_cb(void *data) @@ -55,7 +57,7 @@ static void start_longpress_timer(void) longpress_timer_id = 0; } - longpress_timer_id = g_timeout_add(LONGPRESS_INTERVAL, longpressed_cb, NULL); + longpress_timer_id = g_timeout_add(longpress_interval, longpressed_cb, NULL); } static void stop_longpress_timer(void) @@ -66,14 +68,19 @@ static void stop_longpress_timer(void) } } -/* poweroff if power button is pressed longer than LONGPRESS_INTERVAL */ -static void input_event_handler(struct libinput_event *e) +static int input_handler_execute(void *data) { + struct libinput_event *e; struct libinput_event_keyboard *ek; int keycode, keyvalue; + if (!data) + return 0; + + e = (struct libinput_event *) data; + if (libinput_event_get_type(e) != LIBINPUT_EVENT_KEYBOARD_KEY) - return; + return 0; ek = libinput_event_get_keyboard_event(e); keycode = libinput_event_keyboard_get_key(ek); @@ -87,42 +94,20 @@ static void input_event_handler(struct libinput_event *e) else if (keyvalue == KEYVALUE_RELEASE) stop_longpress_timer(); } -} -static void input_event_handler_init(void *data) -{ - const struct device_ops *input_device; - - input_device = find_device("input"); - if (check_default(input_device)) { - _E("There is no input device"); - return; - } - - if (input_device->init) { - _D("[%s] Initialization.", input_device->name); - input_device->init(input_event_handler); - } + return 0; } -static void input_event_handler_exit(void *data) +static void input_handler_init(void *data) { - const struct device_ops *input_device; - - input_device = find_device("input"); - if (check_default(input_device)) { - _E("There is no input device"); - return; - } - - if (input_device->exit) - input_device->exit(NULL); + // TODO: parse system config, which set holding time of short/long key } -static const struct device_ops input_event_handler_device_ops = { - DECLARE_NAME_LEN("input-event-handler"), - .init = input_event_handler_init, - .exit = input_event_handler_exit, +static const struct device_ops input_handler_device_ops = { + DECLARE_NAME_LEN("input-handler"), + .init = input_handler_init, + .execute = input_handler_execute, + .disable_auto_init = true, }; -DEVICE_OPS_REGISTER(&input_event_handler_device_ops); +DEVICE_OPS_REGISTER(&input_handler_device_ops) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 3d11cbd..6b3aad8 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2048,9 +2048,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2262,7 +2260,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 86807aa..3f9357d 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2039,9 +2039,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2253,7 +2251,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 5acaa70..2ff8cf6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2331,9 +2331,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2584,7 +2582,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/src/display/display-input.c b/src/display/display-input.c index 0e1d4c6..05fcde6 100644 --- a/src/display/display-input.c +++ b/src/display/display-input.c @@ -30,7 +30,7 @@ #define SEAT_NAME "seat0" -static void process_event(struct libinput_event *ev) +static void process_input(struct libinput_event *ev) { static const struct device_ops *display_device_ops; struct input_event input; @@ -105,30 +105,25 @@ static void process_event(struct libinput_event *ev) poll_callback(INPUT_POLL_EVENT, NULL); } -gboolean display_input_init(gpointer data) +static int input_handler_execute(void *data) { - static const struct device_ops *input_device; - - input_device = find_device("input"); - if (check_default(input_device)) - return G_SOURCE_REMOVE; + if (!data) + return 0; - _D("[%s] Initialization.", input_device->name); - if (input_device->init) - input_device->init(process_event); + process_input(data); - return G_SOURCE_REMOVE; + return 0; } -int display_input_exit(void) +static void input_handler_init(void *data) { - static const struct device_ops *input_device; - - input_device = find_device("input"); - if (check_default(input_device)) - return 0; +} - input_device->exit(NULL); +static const struct device_ops input_handler_device_ops = { + DECLARE_NAME_LEN("input-handler"), + .init = input_handler_init, + .execute = input_handler_execute, + .disable_auto_init = true, +}; - return 0; -} +DEVICE_OPS_REGISTER(&input_handler_device_ops) diff --git a/src/display/poll.h b/src/display/poll.h index 096316d..aed0736 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -143,9 +143,6 @@ enum cond_flags_e { #define RESET_TIMER_STR "resettimer" #define KEEP_TIMER_STR "keeptimer" -gboolean display_input_init(gpointer data); -int display_input_exit(void); - /** * @} */ diff --git a/src/input/input.c b/src/input/input.c index 76c82b9..f39e7b8 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "shared/devices.h" #include "shared/log.h" @@ -38,21 +39,23 @@ static struct udev *udev; static struct libinput *li; static guint efd; -static void (*input_event_handler) (struct libinput_event *); +static const struct device_ops *input_handler; -static gboolean input_handler(gint fd, GIOCondition cond, void *data) +static gboolean input_callback(gint fd, GIOCondition cond, void *data) { struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; + struct libinput *input = (struct libinput *) data; - if (!input || !input_event_handler) + if (!input_handler) + return G_SOURCE_REMOVE; + + if (!input) return G_SOURCE_CONTINUE; libinput_dispatch(input); while ((ev = libinput_get_event(input))) { - input_event_handler(ev); - + input_handler->execute(ev); libinput_event_destroy(ev); libinput_dispatch(input); } @@ -93,13 +96,15 @@ static void input_init(void *data) int ret; int fd; - if (!data) { - _E("there is no handler for input event"); + /* load plugin input handler */ + input_handler = find_device("input-handler"); + if (check_default(input_handler) || input_handler->execute == NULL) { + input_handler = NULL; return; } - /* registering input event handler */ - input_event_handler = data; + if (input_handler->init) + input_handler->init(NULL); udev = udev_new(); if (!udev) { @@ -125,9 +130,9 @@ static void input_init(void *data) return; } - /* add to poll handler */ + /* add poll callback */ efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, + input_callback, (void *)((intptr_t)li)); if (!efd) { _E("fail to g_unix_fd_add"); @@ -150,16 +155,17 @@ static void input_exit(void *data) if (udev) udev_unref(udev); - input_event_handler = NULL; + if (input_handler && input_handler->exit) + input_handler->exit(NULL); + + input_handler = NULL; } -/* input module parse and transfer - * input event to input event handler */ static const struct device_ops input_device_ops = { DECLARE_NAME_LEN("input"), .init = input_init, .exit = input_exit, - .disable_auto_init = true, + .priority = -1, /* initialize at last */ }; DEVICE_OPS_REGISTER(&input_device_ops) diff --git a/src/shared/common.c b/src/shared/common.c index af6e980..c7f4bb0 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -16,7 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE #include #include #include diff --git a/src/shared/devices.c b/src/shared/devices.c index 950c1d7..f3884a1 100644 --- a/src/shared/devices.c +++ b/src/shared/devices.c @@ -39,6 +39,17 @@ void remove_device(const struct device_ops *dev) SYS_G_LIST_REMOVE(dev_head, dev); } +void remove_device_by_devname(const char *devname) +{ + const struct device_ops *dev = find_device(devname); + + if (check_default(dev)) + return; + + _D("remove device=%s", devname); + remove_device(dev); +} + const struct device_ops *find_device(const char *name) { GList *elem; diff --git a/src/shared/devices.h b/src/shared/devices.h index d42c490..b0feb6a 100644 --- a/src/shared/devices.h +++ b/src/shared/devices.h @@ -132,6 +132,7 @@ static void __DESTRUCTOR__ module_exit(void) \ extern GList *dev_head; void add_device(const struct device_ops *dev); void remove_device(const struct device_ops *dev); +void remove_device_by_devname(const char *devname); const struct device_ops *find_device(const char *name); int check_default(const struct device_ops *dev); diff --git a/src/shared/plugin.c b/src/shared/plugin.c index d74f981..db8725c 100644 --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -16,8 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE - #include #include #include diff --git a/src/tzip/tzip-utility.c b/src/tzip/tzip-utility.c index 8e749e3..671163e 100644 --- a/src/tzip/tzip-utility.c +++ b/src/tzip/tzip-utility.c @@ -16,7 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE #include #include #include diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 9ae85dd..d99ed56 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -18,7 +18,6 @@ #define FUSE_USE_VERSION 26 -#define _GNU_SOURCE #include #include #include diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 1af7c9c..9155fb5 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -15,8 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define _GNU_SOURCE - #include #include #include -- 2.7.4