e_input: process input event asynchronously 49/296549/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 31 Jul 2023 08:40:33 +0000 (17:40 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Tue, 1 Aug 2023 02:17:12 +0000 (11:17 +0900)
Change-Id: I2a0c3864bb4158a35d3993e523b16e3694adc535
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/e_input_event.c
src/bin/e_input_event.h

index 612347d..17e2532 100755 (executable)
@@ -41,10 +41,38 @@ static GSourceFuncs _event_source_funcs = {
    .finalize = NULL,
 };
 
+static gboolean
+_input_event_handler(GIOChannel *source, GIOCondition condition, gpointer user_data)
+{
+    uint64_t value;
+    E_Input_Event_Source *src = user_data;
+
+    if (condition == G_IO_IN)
+      {
+         int ret = read(src->fd, &value, sizeof(uint64_t));
+         e_input_event_process(src);
+      }
+
+    return TRUE;
+}
+
 EINTERN E_Input_Event_Source *
 e_input_event_source_create()
 {
+   int fd = eventfd(0, EFD_CLOEXEC);
+   if (fd == -1)
+     {
+        ERR("Failed to create event fd\n");
+        return NULL;
+     }
+
    E_Input_Event_Source *source = (E_Input_Event_Source *)g_source_new(&_event_source_funcs, sizeof(E_Input_Event_Source));
+   source->fd = fd;
+   source->data = NULL;
+   GIOChannel *ch = g_io_channel_unix_new(source->fd);
+
+   g_io_add_watch(ch, G_IO_IN, _input_event_handler, (gpointer)source);
+
    source->ev_queue = g_queue_new();
 
    return source;
@@ -66,6 +94,8 @@ e_input_event_source_destroy(E_Input_Event_Source *source)
 
    g_list_free(source->ev_handler_list);
 
+   close(source->fd);
+
    /* should be flushed all events in ev_queue before free ev_queue */
    g_queue_free(source->ev_queue);
    g_source_destroy(&source->gsource);
@@ -208,6 +238,11 @@ _e_input_event_send(E_Input_Event_Source *source, E_Input_Event *ev)
    if (!source) return;
 
    g_queue_push_tail(source->ev_queue, ev);
+
+   uint64_t value = 1;
+   int ret = write(source->fd, &value, sizeof(uint64_t));
+   if (ret == -1)
+     ERR("failed to send event. (%p)\n", source);
 }
 
 E_API void
@@ -222,6 +257,4 @@ e_input_event_add(E_Input_Event_Source *source, int event_type, void *ev_data, e
    ev->free_func_data = free_func_data;
 
    _e_input_event_send(source, ev);
-
-   e_input_event_process(source);
 }
index a869c00..1da6fca 100755 (executable)
@@ -26,6 +26,7 @@ struct _e_input_event_filter {
 
 struct _e_input_event_source {
     GSource gsource;
+    int fd;
 
     void *data;
     GList *ev_handler_list;