input: make input module initialize plugin input-handler 69/265869/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 1 Nov 2021 06:31:39 +0000 (15:31 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 1 Nov 2021 06:31:39 +0000 (15:31 +0900)
Change-Id: Ia72cd8f207b782da369e4161e1bd9269045e19e6
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
16 files changed:
CMakeLists.txt
plugins/iot-headed/display/core.c
plugins/iot-headless/input/input-handler.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/display-input.c
src/display/poll.h
src/input/input.c
src/shared/common.c
src/shared/devices.c
src/shared/devices.h
src/shared/plugin.c
src/tzip/tzip-utility.c
src/tzip/tzip.c
src/usbhost/usb-host.c

index 926fcbc..15d8125 100644 (file)
@@ -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")
index a91533b..c772d9e 100644 (file)
@@ -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;
                }
        }
index bb2bb43..ae25482 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/input.h>
 #include <glib.h>
 
+#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)
index 3d11cbd..6b3aad8 100644 (file)
@@ -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;
                }
        }
index 86807aa..3f9357d 100644 (file)
@@ -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;
                }
        }
index 5acaa70..2ff8cf6 100644 (file)
@@ -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;
                }
        }
index 0e1d4c6..05fcde6 100644 (file)
@@ -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)
index 096316d..aed0736 100644 (file)
@@ -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);
-
 /**
  * @}
  */
index 76c82b9..f39e7b8 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 #include <linux/input.h>
 #include <libinput.h>
+#include <dlfcn.h>
 
 #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)
index af6e980..c7f4bb0 100644 (file)
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
index 950c1d7..f3884a1 100644 (file)
@@ -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;
index d42c490..b0feb6a 100644 (file)
@@ -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);
index d74f981..db8725c 100644 (file)
@@ -16,8 +16,6 @@
  * limitations under the License.
  */
 
-#define _GNU_SOURCE
-
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
index 8e749e3..671163e 100644 (file)
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-#define _GNU_SOURCE
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
index 9ae85dd..d99ed56 100644 (file)
@@ -18,7 +18,6 @@
 
 #define FUSE_USE_VERSION 26
 
-#define _GNU_SOURCE
 #include <semaphore.h>
 #include <fuse.h>
 #include <stdio.h>
index 1af7c9c..9155fb5 100644 (file)
@@ -15,8 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#define _GNU_SOURCE
-
 #include <stdio.h>
 #include <stdint.h>
 #include <limits.h>