input: Make core be responsible for parsing instead of plugin 48/293748/9
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 1 Jun 2023 10:00:57 +0000 (19:00 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 8 Jun 2023 04:59:38 +0000 (13:59 +0900)
 Previously, The input core was just polling input event, and plugin
was responsible for parsing and handling that event. The 'parsing' here
means converting libinput data structure into that of the deviced. All
plugins had followed same parsing logic, which had been able to become
a part of the core module. Therefore, the input core now has changed to
parse input event as well as polling. To pass parsed event to plugin,
the input core provides two function, which can be utilized by plugin
for registering callbacks.
 - int input_register_event_callback()
 - int input_unregister_event_callback()

With this change, plugin can now only focus on event handling, putting
parsing aside.

Change-Id: I872b22ef5c33c23f9be8b804f4a0dc92848483c9
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
16 files changed:
plugins/iot-headed/display/core.c
plugins/iot-headed/display/key-filter.c
plugins/iot-headless/input/input-handler.c
plugins/mobile/display/core.c
plugins/mobile/display/key-filter.c
plugins/tv/display/core.c
plugins/tv/display/key-filter.c
plugins/wearable/display/core.c
plugins/wearable/display/key-filter.c
src/display/core.h
src/display/plugin-common/display-input.c [deleted file]
src/display/poll.h
src/input/input-dbus.c
src/input/input-interface.h [deleted file]
src/input/input.c
src/input/input.h

index 8634eb6..a0f1c85 100644 (file)
@@ -1641,10 +1641,6 @@ static void display_init(void *data)
 
                }
 
-               if (display_conf.input_support)
-                       if (CHECK_OPS(keyfilter_ops, init))
-                               keyfilter_ops->init();
-
                set_display_init_direction(display_conf.display_init_direction);
        }
 }
@@ -1661,9 +1657,6 @@ static void display_exit(void *data)
        /* timeout is not needed */
        display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
 
-       if (CHECK_OPS(keyfilter_ops, exit))
-               keyfilter_ops->exit();
-
        unregister_kernel_uevent_control(&lcd_uevent_ops);
 
        display_ops_exit(NULL);
index 27176ca..35a18b3 100644 (file)
@@ -47,6 +47,7 @@
 #include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "display-lock.h"
+#include "input/input.h"
 
 #ifndef KEY_SCREENLOCK
 #define KEY_SCREENLOCK         0x98
@@ -578,7 +579,7 @@ static void update_vital_state(struct input_event *pinput)
        }
 }
 
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
 {
        int ignore = true;
 
@@ -651,11 +652,16 @@ static int check_key(struct input_event *pinput, int fd)
        return ignore;
 }
 
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
 {
-       struct input_event *pinput = data;
+       struct input_event *pinput = &(struct input_event) {
+               .time = time,
+               .type = type,
+               .code = keycode,
+               .value = keyvalue
+       };
        int ignore = true;
-       static int old_fd, code, value;
+       static int code, value;
 
        assert(pinput);
 
@@ -673,8 +679,7 @@ static int check_key_filter(void *data, int fd)
                if (pinput->code == BTN_TOUCH && !current_state_in_on())
                        break;
                if (pinput->code == code && pinput->value == value) {
-                       _E("Same key(%d, %d) is polled [%d,%d]",
-                               code, value, old_fd, fd);
+                       _E("Same key(%d, %d) is polled", code, value);
                }
                gdbus_signal_emit(NULL,
                                 DEVICED_PATH_INPUT,
@@ -682,12 +687,11 @@ static int check_key_filter(void *data, int fd)
                                 "key",
                                 g_variant_new("(iiii)", pinput->code, pinput->value, pinput->time.tv_sec, pinput->time.tv_usec));
 
-               old_fd = fd;
                code = pinput->code;
                value = pinput->value;
 
                update_vital_state(pinput);
-               ignore = check_key(pinput, fd);
+               ignore = check_key(pinput);
                restore_custom_brightness();
 
                break;
@@ -699,6 +703,11 @@ static int check_key_filter(void *data, int fd)
                        ignore = false;
                break;
        case EV_ABS:
+               if (touch_event_blocked()
+                       && !g_display_plugin.config->touch_wakeup
+                       && pinput->value == KEY_BEING_PRESSED)
+                       return;
+
                update_vital_state(pinput);
                if (pinput->value == KEY_PRESSED) {
                        switch_on_lcd(LCD_ON_BY_TOUCH);
@@ -720,9 +729,10 @@ static int check_key_filter(void *data, int fd)
        }
 
        if (ignore)
-               return 1;
+               return;
 
-       return 0;
+       /* lcd on or update lcd timeout */
+       poll_callback(INPUT_POLL_EVENT, NULL);
 }
 
 static int delayed_init_done(void *data)
@@ -756,30 +766,21 @@ static struct display_actor_ops display_menukey_actor = {
        .caps   = DISPLAY_CAPA_LCDON,
 };
 
-static void keyfilter_init(void)
-{
-       display_add_actor(&display_powerkey_actor);
-       display_add_actor(&display_menukey_actor);
-
-       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
-       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
-       .init                   = keyfilter_init,
-       .check                  = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
 static void __CONSTRUCTOR__ initialize(void)
 {
        disp_plgn = get_var_display_plugin();
-       if (!disp_plgn) {
+       if (!disp_plgn)
                _E("Failed to get display plugin variable.");
-       }
 
        backlight_ops = get_var_backlight_ops();
        if (!backlight_ops)
                _E("Failed to get backlight operator variable.");
+
+       display_add_actor(&display_powerkey_actor);
+       display_add_actor(&display_menukey_actor);
+
+       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+       input_register_event_callback(check_key_filter, NULL, NULL, NULL);
 }
index 81f3978..2f02aa5 100644 (file)
 #include "shared/device-notifier.h"
 #include "shared/log.h"
 #include "shared/event.h"
-#include "input/input-interface.h"
 
 #include "input-config.h"
 #include "input-dbus.h"
+#include "input/input.h"
 
-#define KEYVALUE_PRESS       1
-#define KEYVALUE_RELEASE     0
+static int input_event_handler_id;
 
 static gboolean level_event_detected(gpointer data)
 {
@@ -128,66 +127,46 @@ static void stop_event_timer(struct input_config *ic)
        }
 }
 
-static void input_handler_process_key(int keycode, int keyvalue)
+static void input_handler_process_key(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
 {
        struct input_config *ic;
 
+       if (type != EV_KEY)
+               return;
+
        _D("Key input: code=%d, value=%d", keycode, keyvalue);
 
        /* acquire tmplock on pressing key */
-       if (keyvalue == KEYVALUE_PRESS)
+       if (keyvalue == KEY_PRESSED)
                device_notify(DEVICE_NOTIFIER_KEY_PRESS, (void *)(intptr_t) keycode);
 
        /* process all registered event to the keycode */
        ic = find_input_config(keycode);
-       if (ic && keyvalue == KEYVALUE_PRESS)
+       if (ic && keyvalue == KEY_PRESSED)
                start_event_timer(ic);
-       else if (ic && keyvalue == KEYVALUE_RELEASE)
+       else if (ic && keyvalue == KEY_RELEASED)
                stop_event_timer(ic);
 
        /* release tmplock on releasing key */
-       if (keyvalue == KEYVALUE_RELEASE)
+       if (keyvalue == KEY_RELEASED)
                device_notify(DEVICE_NOTIFIER_KEY_RELEASE, (void *)(intptr_t) keycode);
 }
 
-static int input_handler_execute(void *data)
+static void input_handler_init(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 0;
-
-       ek = libinput_event_get_keyboard_event(e);
-       keycode = libinput_event_keyboard_get_key(ek);
-       keyvalue = libinput_event_keyboard_get_key_state(ek);
-
-       input_handler_process_key(keycode, keyvalue);
-
-       return 0;
+       init_input_config();
+       input_register_event_callback(input_handler_process_key, NULL, NULL, &input_event_handler_id);
 }
 
-static struct input_ops input_handler_ops = {
-       .input_handler_process_key = input_handler_process_key,
-};
-
-static void input_handler_init(void *data)
+static void input_handler_exit(void *data)
 {
-       init_input_config();
-       *(struct input_ops**)data = &input_handler_ops;
+       input_unregister_event_callback(input_event_handler_id);
 }
 
 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, /* initialized by core input module */
+       .exit              = input_handler_exit,
 };
 
 DEVICE_OPS_REGISTER(&input_handler_device_ops)
index e29de08..fda90ef 100644 (file)
@@ -1647,10 +1647,6 @@ static void display_init(void *data)
 
                }
 
-               if (display_conf.input_support)
-                       if (CHECK_OPS(keyfilter_ops, init))
-                               keyfilter_ops->init();
-
                set_display_init_direction(display_conf.display_init_direction);
        }
 }
@@ -1667,9 +1663,6 @@ static void display_exit(void *data)
        /* timeout is not needed */
        display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
 
-       if (CHECK_OPS(keyfilter_ops, exit))
-               keyfilter_ops->exit();
-
        unregister_kernel_uevent_control(&lcd_uevent_ops);
 
        display_ops_exit(NULL);
index bca2172..e05a94b 100644 (file)
@@ -47,6 +47,7 @@
 #include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "display-lock.h"
+#include "input/input.h"
 
 #ifndef KEY_SCREENLOCK
 #define KEY_SCREENLOCK         0x98
@@ -610,7 +611,7 @@ static void update_vital_state(struct input_event *pinput)
        }
 }
 
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
 {
        int ignore = true;
 
@@ -683,11 +684,16 @@ static int check_key(struct input_event *pinput, int fd)
        return ignore;
 }
 
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
 {
-       struct input_event *pinput = data;
+       struct input_event *pinput = &(struct input_event) {
+               .time = time,
+               .type = type,
+               .code = keycode,
+               .value = keyvalue
+       };
        int ignore = true;
-       static int old_fd, code, value;
+       static int code, value;
 
        assert(pinput);
 
@@ -705,15 +711,13 @@ static int check_key_filter(void *data, int fd)
                if (pinput->code == BTN_TOUCH && !current_state_in_on())
                        break;
                if (pinput->code == code && pinput->value == value) {
-                       _E("Same key(%d, %d) is polled [%d,%d]",
-                               code, value, old_fd, fd);
+                       _E("Same key(%d, %d) is polled", code, value);
                }
-               old_fd = fd;
                code = pinput->code;
                value = pinput->value;
 
                update_vital_state(pinput);
-               ignore = check_key(pinput, fd);
+               ignore = check_key(pinput);
                restore_custom_brightness();
 
                break;
@@ -725,6 +729,11 @@ static int check_key_filter(void *data, int fd)
                        ignore = false;
                break;
        case EV_ABS:
+               if (touch_event_blocked()
+                       && !g_display_plugin.config->touch_wakeup
+                       && pinput->value == KEY_BEING_PRESSED)
+                       return;
+
                update_vital_state(pinput);
                if (pinput->value == KEY_PRESSED) {
                        switch_on_lcd(LCD_ON_BY_TOUCH);
@@ -746,9 +755,10 @@ static int check_key_filter(void *data, int fd)
        }
 
        if (ignore)
-               return 1;
+               return;
 
-       return 0;
+       /* lcd on or update lcd timeout */
+       poll_callback(INPUT_POLL_EVENT, NULL);
 }
 
 static int delayed_init_done(void *data)
@@ -782,30 +792,21 @@ static struct display_actor_ops display_menukey_actor = {
        .caps   = DISPLAY_CAPA_LCDON,
 };
 
-static void keyfilter_init(void)
-{
-       display_add_actor(&display_powerkey_actor);
-       display_add_actor(&display_menukey_actor);
-
-       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
-       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
-       .init                   = keyfilter_init,
-       .check                  = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
 static void __CONSTRUCTOR__ initialize(void)
 {
        disp_plgn = get_var_display_plugin();
-       if (!disp_plgn) {
+       if (!disp_plgn)
                _E("Failed to get display plugin variable.");
-       }
 
        backlight_ops = get_var_backlight_ops();
        if (!backlight_ops)
                _E("Failed to get backlight operator variable.");
+
+       display_add_actor(&display_powerkey_actor);
+       display_add_actor(&display_menukey_actor);
+
+       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+       input_register_event_callback(check_key_filter, NULL, NULL, NULL);
 }
index 32a23c2..1d735d0 100644 (file)
@@ -1638,10 +1638,6 @@ static void display_init(void *data)
 
                }
 
-               if (display_conf.input_support)
-                       if (CHECK_OPS(keyfilter_ops, init))
-                               keyfilter_ops->init();
-
                set_display_init_direction(display_conf.display_init_direction);
        }
 }
@@ -1658,9 +1654,6 @@ static void display_exit(void *data)
        /* timeout is not needed */
        display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
 
-       if (CHECK_OPS(keyfilter_ops, exit))
-               keyfilter_ops->exit();
-
        unregister_kernel_uevent_control(&lcd_uevent_ops);
 
        display_ops_exit(NULL);
index dc1db6c..424e4a1 100644 (file)
@@ -47,6 +47,7 @@
 #include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "display-lock.h"
+#include "input/input.h"
 
 #ifndef KEY_SCREENLOCK
 #define KEY_SCREENLOCK         0x98
@@ -578,7 +579,7 @@ static void update_vital_state(struct input_event *pinput)
        }
 }
 
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
 {
        int ignore = true;
 
@@ -651,11 +652,16 @@ static int check_key(struct input_event *pinput, int fd)
        return ignore;
 }
 
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
 {
-       struct input_event *pinput = data;
+       struct input_event *pinput = &(struct input_event) {
+               .time = time,
+               .type = type,
+               .code = keycode,
+               .value = keyvalue
+       };
        int ignore = true;
-       static int old_fd, code, value;
+       static int code, value;
 
        assert(pinput);
 
@@ -673,15 +679,13 @@ static int check_key_filter(void *data, int fd)
                if (pinput->code == BTN_TOUCH && !current_state_in_on())
                        break;
                if (pinput->code == code && pinput->value == value) {
-                       _E("Same key(%d, %d) is polled [%d,%d]",
-                               code, value, old_fd, fd);
+                       _E("Same key(%d, %d) is polled", code, value);
                }
-               old_fd = fd;
                code = pinput->code;
                value = pinput->value;
 
                update_vital_state(pinput);
-               ignore = check_key(pinput, fd);
+               ignore = check_key(pinput);
                restore_custom_brightness();
 
                break;
@@ -693,6 +697,11 @@ static int check_key_filter(void *data, int fd)
                        ignore = false;
                break;
        case EV_ABS:
+               if (touch_event_blocked()
+                       && !g_display_plugin.config->touch_wakeup
+                       && pinput->value == KEY_BEING_PRESSED)
+                       return;
+
                update_vital_state(pinput);
                if (pinput->value == KEY_PRESSED) {
                        switch_on_lcd(LCD_ON_BY_TOUCH);
@@ -714,9 +723,10 @@ static int check_key_filter(void *data, int fd)
        }
 
        if (ignore)
-               return 1;
+               return;
 
-       return 0;
+       /* lcd on or update lcd timeout */
+       poll_callback(INPUT_POLL_EVENT, NULL);
 }
 
 static int delayed_init_done(void *data)
@@ -750,30 +760,21 @@ static struct display_actor_ops display_menukey_actor = {
        .caps   = DISPLAY_CAPA_LCDON,
 };
 
-static void keyfilter_init(void)
-{
-       display_add_actor(&display_powerkey_actor);
-       display_add_actor(&display_menukey_actor);
-
-       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
-       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
-       .init                   = keyfilter_init,
-       .check                  = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
 static void __CONSTRUCTOR__ initialize(void)
 {
        disp_plgn = get_var_display_plugin();
-       if (!disp_plgn) {
+       if (!disp_plgn)
                _E("Failed to get display plugin variable.");
-       }
 
        backlight_ops = get_var_backlight_ops();
        if (!backlight_ops)
                _E("Failed to get backlight operator variable.");
+
+       display_add_actor(&display_powerkey_actor);
+       display_add_actor(&display_menukey_actor);
+
+       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+       input_register_event_callback(check_key_filter, NULL, NULL, NULL);
 }
index e3bd04d..2c6d570 100644 (file)
@@ -2049,10 +2049,6 @@ static void display_init(void *data)
 
                }
 
-               if (display_conf.input_support)
-                       if (CHECK_OPS(keyfilter_ops, init))
-                               keyfilter_ops->init();
-
                set_display_init_direction(display_conf.display_init_direction);
        }
 }
@@ -2069,9 +2065,6 @@ static void display_exit(void *data)
        /* timeout is not needed */
        display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
 
-       if (CHECK_OPS(keyfilter_ops, exit))
-               keyfilter_ops->exit();
-
        unregister_kernel_uevent_control(&lcd_uevent_ops);
        unregister_kernel_uevent_control(&sec_dsim_uevent_ops);
 
index 8c4cb04..635dfba 100644 (file)
@@ -46,6 +46,7 @@
 #include "power/power-off.h"
 #include "power/power-suspend.h"
 #include "display-lock.h"
+#include "input/input.h"
 
 #ifndef KEY_SCREENLOCK
 #define KEY_SCREENLOCK         0x98
@@ -541,7 +542,7 @@ static void update_vital_state(struct input_event *pinput)
        }
 }
 
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
 {
        int ignore = true;
 
@@ -610,11 +611,16 @@ static int check_key(struct input_event *pinput, int fd)
        return ignore;
 }
 
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
 {
-       struct input_event *pinput = data;
+       struct input_event *pinput = &(struct input_event) {
+               .time = time,
+               .type = type,
+               .code = keycode,
+               .value = keyvalue
+       };
        int ignore = true;
-       static int old_fd, code, value;
+       static int code, value;
 
        assert(pinput);
 
@@ -632,15 +638,13 @@ static int check_key_filter(void *data, int fd)
                if (pinput->code == BTN_TOUCH && !current_state_in_on())
                        break;
                if (pinput->code == code && pinput->value == value) {
-                       _E("Same key(%d, %d) is polled [%d,%d]",
-                               code, value, old_fd, fd);
+                       _E("Same key(%d, %d) is polled", code, value);
                }
-               old_fd = fd;
                code = pinput->code;
                value = pinput->value;
 
                update_vital_state(pinput);
-               ignore = check_key(pinput, fd);
+               ignore = check_key(pinput);
                restore_custom_brightness();
 
                break;
@@ -652,6 +656,11 @@ static int check_key_filter(void *data, int fd)
                        ignore = false;
                break;
        case EV_ABS:
+               if (touch_event_blocked() && !ambient_get_state()
+                       && !g_display_plugin.config->touch_wakeup
+                       && pinput->value == KEY_BEING_PRESSED)
+                       return;
+
                update_vital_state(pinput);
                if (pinput->value == KEY_PRESSED) {
                        switch_on_lcd(LCD_ON_BY_TOUCH);
@@ -673,9 +682,10 @@ static int check_key_filter(void *data, int fd)
        }
 
        if (ignore)
-               return 1;
+               return;
 
-       return 0;
+       /* lcd on or update lcd timeout */
+       poll_callback(INPUT_POLL_EVENT, NULL);
 }
 
 static int delayed_init_done(void *data)
@@ -709,22 +719,6 @@ static struct display_actor_ops display_menukey_actor = {
        .caps   = DISPLAY_CAPA_LCDON,
 };
 
-static void keyfilter_init(void)
-{
-       display_add_actor(&display_powerkey_actor);
-       display_add_actor(&display_menukey_actor);
-
-       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
-       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
-       .init                   = keyfilter_init,
-       .check                  = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
 static void __CONSTRUCTOR__ initialize(void)
 {
        disp_plgn = get_var_display_plugin();
@@ -734,4 +728,12 @@ static void __CONSTRUCTOR__ initialize(void)
        backlight_ops = get_var_backlight_ops();
        if (!backlight_ops)
                _E("Failed to get backlight operator variable.");
+
+       display_add_actor(&display_powerkey_actor);
+       display_add_actor(&display_menukey_actor);
+
+       register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+       register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+       input_register_event_callback(check_key_filter, NULL, NULL, NULL);
 }
index 62125e3..ae7ea33 100644 (file)
@@ -97,14 +97,6 @@ struct display_function_info {
 
 extern struct display_function_info display_info;
 
-struct display_keyfilter_ops {
-       void (*init)(void);
-       void (*exit)(void);
-       int (*check)(void *, int);
-};
-
-extern const struct display_keyfilter_ops *keyfilter_ops;
-
 typedef struct {
        pid_t pid;
        unsigned int cond;
diff --git a/src/display/plugin-common/display-input.c b/src/display/plugin-common/display-input.c
deleted file mode 100644 (file)
index 3b608a3..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <linux/input.h>
-#include <libinput.h>
-
-#include "util.h"
-#include "core.h"
-#include "poll.h"
-#include "ambient-mode.h"
-#include "display-plugin.h"
-
-#define SEAT_NAME   "seat0"
-
-static void process_input(struct libinput_event *ev)
-{
-       static const struct device_ops *display_device_ops;
-       struct input_event input;
-       struct libinput *li;
-       struct libinput_event_keyboard *k;
-       unsigned int time;
-       int fd = 0;
-       if(!g_display_plugin.config) {
-               _E("Failed to get display configuration variable.");
-               return;
-       }
-
-       if (!display_device_ops) {
-               display_device_ops = find_device("display");
-               if (check_default(display_device_ops))
-                       return;
-       }
-
-       /* do not operate when display stops */
-       if (device_get_status(display_device_ops)
-                       != DEVICE_OPS_STATUS_START) {
-               _E("display status is stop");
-               return;
-       }
-
-       switch (libinput_event_get_type(ev)) {
-       case LIBINPUT_EVENT_KEYBOARD_KEY:
-               k = libinput_event_get_keyboard_event(ev);
-               time = libinput_event_keyboard_get_time(k);
-               li = libinput_event_get_context(ev);
-
-               input.time.tv_sec = MSEC_TO_SEC(time);
-               input.time.tv_usec = MSEC_TO_USEC(time % 1000);
-               input.type = EV_KEY;
-               input.code = libinput_event_keyboard_get_key(k);
-               input.value = libinput_event_keyboard_get_key_state(k);
-
-               fd = libinput_get_fd(li);
-               _D("time %ld.%06ld type %d code %d value %d fd %d",
-                               input.time.tv_sec, input.time.tv_usec, input.type,
-                               input.code, input.value, fd);
-               break;
-       case LIBINPUT_EVENT_POINTER_MOTION:
-       case LIBINPUT_EVENT_POINTER_BUTTON:
-               input.type = EV_REL;
-               break;
-       case LIBINPUT_EVENT_TOUCH_DOWN:
-               input.type = EV_ABS;
-               input.value = KEY_PRESSED;
-               break;
-       case LIBINPUT_EVENT_TOUCH_UP:
-               input.type = EV_ABS;
-               input.value = KEY_RELEASED;
-               break;
-       case LIBINPUT_EVENT_TOUCH_MOTION:
-       case LIBINPUT_EVENT_TOUCH_FRAME:
-               if (touch_event_blocked() && !ambient_get_state() && !g_display_plugin.config->touch_wakeup)
-                       return;
-               input.type = EV_ABS;
-               input.value = KEY_BEING_PRESSED;
-               break;
-       default:
-               return;
-       }
-
-       if (CHECK_OPS(keyfilter_ops, check) &&
-           keyfilter_ops->check(&input, fd) != 0)
-               return;
-
-       /* lcd on or update lcd timeout */
-       poll_callback(INPUT_POLL_EVENT, NULL);
-}
-
-static int input_handler_execute(void *data)
-{
-       if (!data)
-               return 0;
-
-       process_input(data);
-
-       return 0;
-}
-
-static void input_handler_init(void *data)
-{
-}
-
-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_handler_device_ops)
index 2b9bda2..bd79b92 100644 (file)
@@ -66,10 +66,6 @@ enum {
        INTERNAL_LOCK_OVERCOOL,
 };
 
-#define KEY_RELEASED           0
-#define KEY_PRESSED                    1
-#define KEY_BEING_PRESSED      2
-
 #define SIGNAL_NAME_LCD_CONTROL                "lcdcontol"
 
 #define LCD_NORMAL  0x01       /**< NORMAL state */
index 750ec76..0c75bbd 100644 (file)
@@ -33,7 +33,6 @@
 #include "shared/common.h"
 #include "input.h"
 #include "input-dbus.h"
-#include "input-interface.h"
 #include "input-device-manager.h"
 
 /* FIXME: input.keyboard feature check should be added and return DEVICE_ERROR_NOT_SUPPORTED */
@@ -90,7 +89,8 @@ static GVariant *dbus_emulate_key(GDBusConnection *conn,
 
        g_variant_get(param, "(ii)", &keycode, &keyvalue);
 
-       input_handler_process_key(keycode, keyvalue);
+       // temporarily disabled
+       //input_handler_process_key(keycode, keyvalue);
 
        return gdbus_new_g_variant_tuple();
 }
@@ -185,4 +185,4 @@ int input_dbus_init(void)
                return ret;
        }
        return 0;
-}
\ No newline at end of file
+}
diff --git a/src/input/input-interface.h b/src/input/input-interface.h
deleted file mode 100644 (file)
index 62bbf1e..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file       input-interface.h
- * @brief      input interface module header
- */
-#ifndef __INPUT_INTERFACE_H__
-#define __INPUT_INTERFACE_H__
-
-struct input_ops {
-       void (*input_handler_process_key)(int keycode, int keyvalue);
-};
-
-#endif /* __INPUT_INTERFACE_H__ */
\ No newline at end of file
index 23563f0..f596414 100644 (file)
@@ -18,6 +18,7 @@
 
 
 #include <stdio.h>
+#include <assert.h>
 #include <fcntl.h>
 #include <stdbool.h>
 #include <errno.h>
@@ -35,7 +36,6 @@
 #include "input.h"
 #include "input-dbus.h"
 #include "input-parser.h"
-#include "input-interface.h"
 #include "input-device-manager.h"
 
 #define SEAT_NAME   "seat0"
@@ -45,25 +45,109 @@ static struct libinput *li;
 static struct input_ops *input_plugin_ops;
 static guint efd;
 
-static const struct device_ops *input_handler;
+struct input_event_handler {
+       int id;
+       input_event_callback cb;
+       input_destroy_callback destroy_cb;
+       void *udata;
+};
+
+static GList *input_event_handler_list;
+
+static void invoke_input_event_callback(gpointer data, gpointer udata)
+{
+       struct input_event_handler *h = (struct input_event_handler *) data;
+       struct input_event *event = (struct input_event *) udata;
+
+       assert(h);
+       assert(h->cb);
+       assert(event);
+
+       /**
+        * TODO: At this point, system maybe just woken up for a while due to input interrupt.
+        *       How can we guarantee all those callbacks are totally executed without system
+        *       falling into suspend again? Autosleep may make system go suspend right after
+        *       the key interrupt, that is, in the middle of the below callback execution.
+        */
+       h->cb(event->time, event->type, event->code, event->value);
+}
+
+static int convert_libinput_to_event(struct libinput_event *li_event, struct input_event *event)
+{
+       if (!li_event || !event)
+               return -EINVAL;
+
+       switch (libinput_event_get_type(li_event)) {
+       case LIBINPUT_EVENT_KEYBOARD_KEY:
+       {
+               struct libinput *li = libinput_event_get_context(li_event);
+               struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(li_event);
+               unsigned int time;
+               int fd;
+
+               assert(li);
+               assert(k);
+
+               time = libinput_event_keyboard_get_time(k);
+
+               event->time.tv_sec = (time / 1000);
+               event->time.tv_usec = MSEC_TO_USEC(time % 1000);
+               event->type = EV_KEY;
+               event->code = libinput_event_keyboard_get_key(k);
+               event->value = libinput_event_keyboard_get_key_state(k);
+
+               fd = libinput_get_fd(li);
+               _D("time %ld.%06ld type %d code %d value %d fd %d",
+                               event->time.tv_sec, event->time.tv_usec, event->type,
+                               event->code, event->value, fd);
+               return 0;
+       }
+       case LIBINPUT_EVENT_POINTER_MOTION:
+       case LIBINPUT_EVENT_POINTER_BUTTON:
+               event->type = EV_REL;
+               return 0;
+       case LIBINPUT_EVENT_TOUCH_DOWN:
+               event->type = EV_ABS;
+               event->value = KEY_PRESSED;
+               return 0;
+       case LIBINPUT_EVENT_TOUCH_UP:
+               event->type = EV_ABS;
+               event->value = KEY_RELEASED;
+               return 0;
+       case LIBINPUT_EVENT_TOUCH_MOTION:
+       case LIBINPUT_EVENT_TOUCH_FRAME:
+               event->type = EV_ABS;
+               event->value = KEY_BEING_PRESSED;
+               return 0;
+       default:
+               return -EINVAL;
+       }
+
+       // unreachable
+       return -EINVAL;
+}
 
 static gboolean input_callback(gint fd, GIOCondition cond, void *data)
 {
-       struct libinput_event *ev;
-       struct libinput *input = (struct libinput *) data;
+       struct libinput *li = (struct libinput *) data;
+       struct libinput_event *li_event = NULL;
 
-       if (!input_handler)
-               return G_SOURCE_REMOVE;
+       if (!input_event_handler_list)
+               return G_SOURCE_CONTINUE;
 
-       if (!input)
+       if (!li)
                return G_SOURCE_CONTINUE;
 
-       libinput_dispatch(input);
+       libinput_dispatch(li);
 
-       while ((ev = libinput_get_event(input))) {
-               input_handler->execute(ev);
-               libinput_event_destroy(ev);
-               libinput_dispatch(input);
+       while ((li_event = libinput_get_event(li))) {
+               struct input_event event = { 0 , };
+
+               if (convert_libinput_to_event(li_event, &event) == 0)
+                       g_list_foreach(input_event_handler_list, invoke_input_event_callback, &event);
+
+               libinput_event_destroy(li_event);
+               libinput_dispatch(li);
        }
 
        return G_SOURCE_CONTINUE;
@@ -97,26 +181,73 @@ static const struct libinput_interface interface = {
        .close_restricted = close_restricted,
 };
 
-void input_handler_process_key(int keycode, int keyvalue)
+static int alloc_unique_id(void)
 {
-       if (input_plugin_ops && input_plugin_ops->input_handler_process_key)
-               input_plugin_ops->input_handler_process_key(keycode, keyvalue);
+       static int id = 0;
+
+       return ++id;
 }
 
-static void input_init(void *data)
+int input_register_event_callback(input_event_callback cb, input_destroy_callback destroy_cb, void *udata, int *cb_id)
 {
-       int ret;
-       int fd;
+       struct input_event_handler *h = NULL;
+
+       if (!cb)
+               return -EINVAL;
+
+       h = calloc(1, sizeof(struct input_event_handler));
+       if (!h)
+               return -ENOMEM;
 
-       /* load plugin input handler */
-       input_handler = find_device("input-handler");
-       if (check_default(input_handler) || input_handler->execute == NULL) {
-               input_handler = NULL;
+       *h = (struct input_event_handler) {
+               .id = alloc_unique_id(),
+               .cb = cb,
+               .destroy_cb = destroy_cb,
+               .udata = udata,
+       };
+
+       input_event_handler_list = g_list_append(input_event_handler_list, h);
+
+       if (cb_id)
+               *cb_id = h->id;
+
+       return 0;
+}
+
+static int find_handler_by_id(gconstpointer data, gconstpointer udata)
+{
+       struct input_event_handler *h = (struct input_event_handler *) data;
+       int id = *(int *) udata;
+
+       if (h->id == id)
+               return 0;
+
+       return -1;
+}
+
+void input_unregister_event_callback(int cb_id)
+{
+       struct input_event_handler *h = NULL;
+       GList *l = NULL;
+
+       l = g_list_find_custom(input_event_handler_list, &cb_id, find_handler_by_id);
+       if (!l || !l->data)
                return;
-       }
 
-       if (input_handler->init)
-               input_handler->init(&input_plugin_ops);
+       input_event_handler_list = g_list_remove_link(input_event_handler_list, l);
+       h = l->data;
+
+       if (h->destroy_cb)
+               h->destroy_cb(h->udata);
+
+       free(h);
+       g_list_free(l);
+}
+
+static void input_init(void *data)
+{
+       int ret;
+       int fd;
 
        if (input_plugin_ops == NULL)
                _E("Failed to init input_ops");
@@ -186,11 +317,6 @@ static void input_exit(void *data)
        if (udev)
                udev_unref(udev);
 
-       if (input_handler && input_handler->exit)
-               input_handler->exit(NULL);
-
-       input_handler = NULL;
-
        input_devman_exit();
 }
 
index 287ad30..05749fb 100644 (file)
 #ifndef __INPUT_H__
 #define __INPUT_H__
 
-void input_handler_process_key(int keycode, int keyvalue);
+#include <time.h>
 
-#endif /* __INPUT_H__ */
\ No newline at end of file
+#define KEY_RELEASED           0
+#define KEY_PRESSED            1
+#define KEY_BEING_PRESSED      2
+
+typedef void (*input_event_callback) (struct timeval, unsigned short type, unsigned short code, unsigned int value);
+typedef void (*input_destroy_callback) (void *udata);
+int input_register_event_callback(input_event_callback cb, input_destroy_callback destroy_cb, void *udata, int *cb_id);
+void input_unregister_event_callback(int cb_id);
+
+#endif /* __INPUT_H__ */