[UI Sample] Ecore Thread 4 Sample Overview
The Ecore Thread 4 sample demonstrates how to move a button using EFL thread feedback functions. If EFL APIs are called in the Ecore_Thread, use the ecore_thread_feedback_run() function instead of ecore_thread_run().
The following figure illustrates the Evas thread feedback in the Ecore Thread 4 screen.
Figure: Ecore Thread 4 screen
Implementation
The create_base_gui() function utilizes the ecore_thread_feedback_run() function to allow the thread_run_cb() function to call the thread_feedback_cb function.
#include <Elementary.h> typedef struct user_data { Evas_Object *obj; Evas_Coord x, y; } user_data; static void create_base_gui(appdata_s *ad) { // Window ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); elm_win_autodel_set(ad->win, EINA_TRUE); evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL); eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad); Evas_Object *btn; Ecore_Thread *thread; // Create a button btn = elm_button_add(ad->win); elm_object_text_set(btn, "Ecore</br>Thread</br>Main</br>Loop"); evas_object_resize(btn, 200, 200); evas_object_show(btn); // Create a thread thread = ecore_thread_feedback_run(thread_run_cb, thread_feedback_cb, thread_end_cb, thread_cancel_cb, btn, EINA_FALSE); // Show the window after the base GUI is set up evas_object_show(ad->win); }
The ecore_thread_feedback() function allows the thread_run_cb() callback to call the thread_feedback_cb callback.
static void thread_run_cb(void *data, Ecore_Thread *thread) { double t = 0.0; Evas_Coord x, y; Evas_Object *btn = data; while (1) { x = 150 + (150 * sin(t)); y = 150 + (150 * cos(t)); user_data *ud = malloc(sizeof(user_data)); ud->obj = btn; ud->x = x; ud->y = y; // After recording the time point, pass it as feedback back to the // mainloop and free data when done ecore_thread_feedback(thread, ud); usleep(1000); t += 0.001; // In case thread must be canceled, cancel this // loop co-operatively (canceling is co-operative) if (ecore_thread_check(thread)) break; } } static void thread_feedback_cb(void *data, Ecore_Thread *thread, void *msg) { // This function is in critical section user_data *ud = msg; evas_object_move(ud->obj, ud->x, ud->y); free(ud); } static void thread_end_cb(void *data, Ecore_Thread *thread) { printf("thread end!\n"); } static void thread_cancel_cb(void *data, Ecore_Thread *thread) { printf("thread cancel!\n"); } static void win_del_cb(void *data, Evas_Object *obj, void *event_info) { Ecore_Thread *thread = data; elm_exit(); }