#include "e_input_event_intern.h"
+#include "e_input_backend_intern.h"
+#include "e_input_log.h"
#include <stdio.h>
#include <stdlib.h>
g_source_unref(&source->gsource);
}
+static void
+_e_input_thread_event_handler_add(void *data)
+{
+ E_Input_Thread_Request_Input_Event_Data *ie_data = data;
+ E_Input_Event_Source *source = e_input_event_source_get();
+
+ EINA_SAFETY_ON_NULL_RETURN(ie_data);
+ EINA_SAFETY_ON_NULL_RETURN(source);
+
+ INF("[input thread|%s] eh(%p)\n", __func__, ie_data->eh);
+ source->ev_handler_list = g_list_append(source->ev_handler_list, ie_data->eh);
+}
+
E_API E_Input_Event_Handler *
e_input_event_handler_add(E_Input_Event_Source *source, int event, ev_handler_func func, void *user_data)
{
eh->func = func;
eh->user_data = user_data;
+ if (e_input_thread_id_get() != gettid())
+ {
+ E_Input_Thread_Request_Input_Event_Data ie_data;
+ memset(&ie_data, 0, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ ie_data.eh = eh;
+
+ INF("[%s] eh(%p)\n", __func__, eh);
+ e_input_backend_thread_safe_call(_e_input_thread_event_handler_add, &ie_data, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ return eh;
+ }
+
source->ev_handler_list = g_list_append(source->ev_handler_list, eh);
return eh;
}
+static void
+_e_input_thread_event_handler_prepend(void *data)
+{
+ E_Input_Thread_Request_Input_Event_Data *ie_data = data;
+ E_Input_Event_Source *source = e_input_event_source_get();
+
+ EINA_SAFETY_ON_NULL_RETURN(ie_data);
+ EINA_SAFETY_ON_NULL_RETURN(source);
+
+ INF("[input thread|%s] eh(%p)\n", __func__, ie_data->eh);
+ source->ev_handler_list = g_list_prepend(source->ev_handler_list, ie_data->eh);
+}
+
E_API E_Input_Event_Handler *
e_input_event_handler_prepend(E_Input_Event_Source *source, int event, ev_handler_func func, void *user_data)
{
eh->func = func;
eh->user_data = user_data;
+ if (e_input_thread_id_get() != gettid())
+ {
+ E_Input_Thread_Request_Input_Event_Data ie_data;
+ memset(&ie_data, 0, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ ie_data.eh = eh;
+
+ INF("[%s] eh(%p)\n", __func__, eh);
+ e_input_backend_thread_safe_call(_e_input_thread_event_handler_prepend, &ie_data, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ return eh;
+ }
+
source->ev_handler_list = g_list_prepend(source->ev_handler_list, eh);
return eh;
}
+static void
+_e_input_thread_event_handler_del(void *data)
+{
+ E_Input_Thread_Request_Input_Event_Data *ie_data = data;
+ E_Input_Event_Source *source = e_input_event_source_get();
+
+ EINA_SAFETY_ON_NULL_RETURN(ie_data);
+ EINA_SAFETY_ON_NULL_RETURN(source);
+
+ INF("[input thread|%s] eh(%p)\n", __func__, ie_data->eh);
+ source->ev_handler_list = g_list_remove(source->ev_handler_list, ie_data->eh);
+ free(ie_data->eh);
+}
+
E_API void
e_input_event_handler_del(E_Input_Event_Source *source, E_Input_Event_Handler *event_handler)
{
- if (!source) return;
+ if (!source)
+ {
+ ERR("source is NULL");
+ return;
+ }
+
+ if (e_input_thread_id_get() != gettid())
+ {
+ E_Input_Thread_Request_Input_Event_Data ie_data;
+ memset(&ie_data, 0, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ ie_data.eh = event_handler;
+
+ INF("[%s] eh(%p)\n", __func__, event_handler);
+ e_input_backend_thread_safe_call(_e_input_thread_event_handler_del, &ie_data, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ return;
+ }
source->ev_handler_list = g_list_remove(source->ev_handler_list, event_handler);
free(event_handler);
}
+static void
+_e_input_thread_event_filter_add(void *data)
+{
+ E_Input_Thread_Request_Input_Event_Data *ie_data = data;
+ E_Input_Event_Source *source = e_input_event_source_get();
+
+ EINA_SAFETY_ON_NULL_RETURN(ie_data);
+ EINA_SAFETY_ON_NULL_RETURN(source);
+
+ INF("[input thread|%s] ef(%p)\n", __func__, ie_data->ef);
+ source->ev_filter_list = g_list_append(source->ev_filter_list, ie_data->ef);
+}
+
E_API E_Input_Event_Filter *
e_input_event_filter_add(E_Input_Event_Source *source, int event, ev_handler_func func, void *user_data)
{
ef->func = func;
ef->user_data = user_data;
+ if (e_input_thread_id_get() != gettid())
+ {
+ E_Input_Thread_Request_Input_Event_Data ie_data;
+ memset(&ie_data, 0, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ ie_data.ef = ef;
+
+ INF("[%s] ef(%p)\n", __func__, ef);
+ e_input_backend_thread_safe_call(_e_input_thread_event_filter_add, &ie_data, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ return ef;
+ }
+
source->ev_filter_list = g_list_append(source->ev_filter_list, ef);
return ef;
}
+static void
+_e_input_thread_event_filter_del(void *data)
+{
+ E_Input_Thread_Request_Input_Event_Data *ie_data = data;
+ E_Input_Event_Source *source = e_input_event_source_get();
+
+ EINA_SAFETY_ON_NULL_RETURN(ie_data);
+ EINA_SAFETY_ON_NULL_RETURN(source);
+
+ INF("[input thread|%s] ef(%p)\n", __func__, ie_data->ef);
+ source->ev_filter_list = g_list_remove(source->ev_filter_list, ie_data->ef);
+ free(ie_data->ef);
+}
+
E_API void
e_input_event_filter_del(E_Input_Event_Source *source, E_Input_Event_Filter *event_filter)
{
- if (source)
- source->ev_filter_list = g_list_remove(source->ev_filter_list, event_filter);
+ if (!source)
+ {
+ ERR("source is NULL");
+ return;
+ }
+
+ if (e_input_thread_id_get() != gettid())
+ {
+ E_Input_Thread_Request_Input_Event_Data ie_data;
+ memset(&ie_data, 0, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ ie_data.ef = event_filter;
+
+ INF("[%s] ef(%p)\n", __func__, event_filter);
+ e_input_backend_thread_safe_call(_e_input_thread_event_filter_del, &ie_data, sizeof(E_Input_Thread_Request_Input_Event_Data));
+ return;
+ }
+
+ source->ev_filter_list = g_list_remove(source->ev_filter_list, event_filter);
free(event_filter);
}
g_source_set_ready_time((GSource *)source, 0);
}
+static void
+_e_input_thread_event_add(void *data)
+{
+ E_Input_Thread_Request_Input_Event_Data *ie_data = data;
+ E_Input_Event_Source *source = e_input_event_source_get();
+
+ EINA_SAFETY_ON_NULL_RETURN(ie_data);
+ EINA_SAFETY_ON_NULL_RETURN(source);
+
+ INF("[input thread|%s] ev(%p)\n", __func__, ie_data->ev);
+ _e_input_event_send(source, ie_data->ev);
+}
+
E_API void
e_input_event_add(E_Input_Event_Source *source, int event_type, void *ev_data, ev_free_func free_func, void *free_func_data)
{
ev->free_func = free_func;
ev->free_func_data = free_func_data;
+ if (e_input_thread_id_get() != gettid())
+ {
+ E_Input_Thread_Request_Input_Event_Data ie_data;
+ memset(&ie_data, 0, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ ie_data.ev = ev;
+
+ INF("[%s] ev(%p)\n", __func__, ev);
+ e_input_backend_thread_safe_call(_e_input_thread_event_add, &ie_data, sizeof(E_Input_Thread_Request_Input_Event_Data));
+
+ return;
+ }
+
_e_input_event_send(source, ev);
}