From 51069126c5a65b8dd323fd2ab80d2bd1abb79753 Mon Sep 17 00:00:00 2001 From: junkyu han Date: Thu, 13 Apr 2017 09:31:01 +0900 Subject: [PATCH] Refactoring for TDD Change-Id: If26a9a162df8cd003c9f4d4138bb61fe4fcaf679 --- .cproject | 42 +++++++-------- src/animation.c | 156 +++++++++++++++++++++++++---------------------------- src/boot.c | 4 +- tizen-manifest.xml | 4 +- 4 files changed, 98 insertions(+), 108 deletions(-) diff --git a/.cproject b/.cproject index cddc9ba..4330f5c 100644 --- a/.cproject +++ b/.cproject @@ -22,16 +22,22 @@ - + - + - + - + @@ -327,6 +323,7 @@ + @@ -647,4 +644,5 @@ + diff --git a/src/animation.c b/src/animation.c index eeeeb9d..0542680 100644 --- a/src/animation.c +++ b/src/animation.c @@ -56,19 +56,19 @@ static void win_del(void *data, Evas_Object * obj, void *event_info) elm_exit(); } -static Eina_Bool _end_cb(void *data) +static Eina_Bool __end_cb(void *data) { int type = (int) data; - _D("_end_cb is invoked"); - if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) { - _E("Failed to set finished set"); - } if (type == TYPE_ON) { _D("EXIT on BOOTING"); + if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) { + _E("Failed to set finished set"); + } elm_exit(); } else { /* Delete Previous Layout */ + _D("EXIT on SHUTDOWN"); if (s_animation.layout) evas_object_del(s_animation.layout); Evas_Object *disp_block = NULL; @@ -80,45 +80,39 @@ static Eina_Bool _end_cb(void *data) return ECORE_CALLBACK_CANCEL; } -static void _edje_cb(void *d, Evas_Object * obj, const char *e, const char *s) +static void __set_poweroff_message(void) { - _D("edje callback is invoked"); + Evas_Coord w; + Evas_Coord h; + + evas_object_size_hint_weight_set(s_animation.txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_fill_set(s_animation.txt, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_resize(s_animation.txt, s_animation.w, s_animation.h); + evas_object_color_set(s_animation.txt, 255, 255, 255, 255); + evas_object_text_font_set(s_animation.txt, "SLP:style=medium", 30); + evas_object_geometry_get(s_animation.txt, NULL, NULL, &w, &h); + evas_object_move(s_animation.txt, (s_animation.w - w) >> 1, (s_animation.h - h) >> 1); + evas_object_show(s_animation.txt); +} +static void __edje_cb(void *d, Evas_Object * obj, const char *e, const char *s) +{ if (s_animation.state == TYPE_OFF || s_animation.state == TYPE_OFF_WITH_MSG) { _D("TYPE OFF"); - if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) + if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) { _E("Failed to set finished set"); + } if (s_animation.txt) { - Evas_Coord w; - Evas_Coord h; - - evas_object_size_hint_weight_set(s_animation.txt, - EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - evas_object_size_hint_fill_set(s_animation.txt, - EVAS_HINT_FILL, - EVAS_HINT_FILL); - evas_object_resize(s_animation.txt, s_animation.w, - s_animation.h); - evas_object_color_set(s_animation.txt, 255, 255, 255, - 255); - evas_object_text_font_set(s_animation.txt, - "SLP:style=medium", 30); - evas_object_geometry_get(s_animation.txt, NULL, NULL, - &w, &h); - evas_object_move(s_animation.txt, - (s_animation.w - w) >> 1, - (s_animation.h - h) >> 1); - evas_object_show(s_animation.txt); + __set_poweroff_message(); } - ecore_timer_add(1, _end_cb, (void *)TYPE_OFF); + ecore_timer_add(1, __end_cb, (void *)TYPE_OFF); } else { _D("TYPE_ON"); - _end_cb((void *)TYPE_ON); + __end_cb((void *)TYPE_ON); } } -static void layout_file_set(int state) +static Eina_Bool __layout_file_set(int state) { char file_name[1024]; char *on_off; @@ -136,40 +130,47 @@ static void layout_file_set(int state) ret = access(file_name, 0); if (ret == 0) { _D("This Resolution[%d]x[%d] is supported !!", s_animation.w, s_animation.h); - elm_layout_file_set(s_animation.layout, file_name, on_off); + if (!elm_layout_file_set(s_animation.layout, file_name, on_off)) return EINA_FALSE; } else { _E("This Resolution[%d]x[%d] is STRANGE !!, Set default image '720x1280'", s_animation.w, s_animation.h); if (state == TYPE_ON) { - elm_layout_file_set(s_animation.layout, DEFAULT_ON, on_off); + if (!elm_layout_file_set(s_animation.layout, DEFAULT_ON, on_off)) return EINA_FALSE; } else { - elm_layout_file_set(s_animation.layout, DEFAULT_OFF, on_off); + if (!elm_layout_file_set(s_animation.layout, DEFAULT_OFF, on_off)) return EINA_FALSE; } } + + return EINA_TRUE; } -static int init_layout(const char *msg) +static Evas_Object *__create_layout(const char *msg) { - s_animation.layout = elm_layout_add(s_animation.win); - if (!s_animation.layout) { + Eina_Bool ret; + Evas_Object *layout = elm_layout_add(s_animation.win); + if (!layout) { _E("Failed to create layout"); - return EXIT_FAILURE; + return NULL; } - layout_file_set(s_animation.state); + ret = __layout_file_set(s_animation.state); + if (ret != EINA_TRUE) { + _E("Failed to set layout file"); + evas_object_del(layout); + return NULL; + } - evas_object_size_hint_weight_set(s_animation.layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - _D("[Boot-ani] Start animation: %d mode", s_animation.state); - elm_win_resize_object_add(s_animation.win, s_animation.layout); - edje_object_signal_callback_add(elm_layout_edje_get(s_animation.layout), "end", "animation", _edje_cb, NULL); - evas_object_show(s_animation.layout); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(s_animation.win, layout); + edje_object_signal_callback_add(elm_layout_edje_get(layout), "end", "animation", __edje_cb, NULL); + evas_object_show(layout); if (msg) { if (!s_animation.txt) { - s_animation.txt = evas_object_text_add(s_animation.evas); + s_animation.txt = evas_object_text_add(evas_object_evas_get(s_animation.win)); if (!s_animation.txt) { _E("Failed to add text"); - evas_object_del(s_animation.layout); - return EXIT_FAILURE; + evas_object_del(layout); + return NULL; } } @@ -177,10 +178,10 @@ static int init_layout(const char *msg) evas_object_hide(s_animation.txt); } - return EXIT_SUCCESS; + return layout; } -static void fini_layout(void) +static void __fini_layout(void) { if (s_animation.layout) { evas_object_del(s_animation.layout); @@ -192,49 +193,37 @@ static void fini_layout(void) } } -static int create_window(void) +static Evas_Object *__create_window(void) { _D("Create Window"); printf("Create Window\n"); int x, y = 0; + Evas_Object *win; - s_animation.win = elm_win_add(NULL, "BOOT_ANIMATION", ELM_WIN_NOTIFICATION); - elm_win_aux_hint_add(s_animation.win, "wm.comp.win.always.selective.mode", "1"); + win = elm_win_add(NULL, "BOOT_ANIMATION", ELM_WIN_NOTIFICATION); + elm_win_aux_hint_add(win, "wm.comp.win.always.selective.mode", "1"); - elm_win_role_set(s_animation.win, "alert"); - if (!s_animation.win) { + elm_win_role_set(win, "alert"); + if (!win) { _E("Failed to create a new window"); printf("Failed to create a new window\n"); - return EXIT_FAILURE; + return NULL; } if (s_animation.state == TYPE_OFF || s_animation.state == TYPE_OFF_WITH_MSG) { _D("We are turning off the Tizen"); } - efl_util_set_notification_window_level(s_animation.win, EFL_UTIL_NOTIFICATION_LEVEL_HIGH); - evas_object_smart_callback_add(s_animation.win, "delete-request", win_del, NULL); + efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_HIGH); + evas_object_smart_callback_add(win, "delete-request", win_del, NULL); - s_animation.evas = evas_object_evas_get(s_animation.win); - if (!s_animation.evas) { - evas_object_del(s_animation.win); - _E("Failed to get the evas object"); - return EXIT_FAILURE; - } - elm_win_screen_size_get(s_animation.win, &x, &y, &s_animation.w, &s_animation.h); + elm_win_screen_size_get(win, &x, &y, &s_animation.w, &s_animation.h); _D("Window size is x: %d, y: %d, w: %d, h: %d", x, y, s_animation.w, s_animation.h); - elm_win_borderless_set(s_animation.win, 1); - elm_win_indicator_mode_set(s_animation.win, ELM_WIN_INDICATOR_HIDE); - evas_object_move(s_animation.win, 0, 0); - evas_object_show(s_animation.win); + elm_win_borderless_set(win, 1); + elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_HIDE); + evas_object_move(win, 0, 0); + evas_object_show(win); - s_animation.ee = ecore_evas_ecore_evas_get(s_animation.evas); - if (!s_animation.ee) { - evas_object_del(s_animation.win); - _E("Failed to get the ecore evas object"); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; + return win; } int init_animation(int state, const char *msg) @@ -244,18 +233,21 @@ int init_animation(int state, const char *msg) s_animation.state = state; - if (create_window() == EXIT_FAILURE) { + s_animation.win = __create_window(); + if (!s_animation.win) { _E("Failed to create a new window"); printf("Failed to create a new window\n"); return EXIT_FAILURE; } - if (init_layout(msg) == EXIT_FAILURE) { - _E("Failed to init the layout object"); - if (msg) { + s_animation.layout = __create_layout(msg); + if (!s_animation.layout) { + _E("Failed to create layout"); + if (s_animation.txt) { evas_object_del(s_animation.txt); } evas_object_del(s_animation.win); + return EXIT_FAILURE; } return EXIT_SUCCESS; @@ -263,7 +255,7 @@ int init_animation(int state, const char *msg) int fini_animation(void) { - fini_layout(); + __fini_layout(); evas_object_del(s_animation.win); fflush(stdout); close(1); diff --git a/src/boot.c b/src/boot.c index e4e6f79..e735eaa 100644 --- a/src/boot.c +++ b/src/boot.c @@ -86,7 +86,7 @@ static int get_wav_file(int state, char *wavpath) } #endif -static int xready_cb(keynode_t * node, void *user_data) +static int __prepare_animation(keynode_t * node, void *user_data) { int c; int argc; @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) _D("Failed to set finished value to 0\n"); printf("[%s/%s/%d] Failed to set finished value to 0\n", __FILE__, __func__, __LINE__); } - if (xready_cb(NULL, &args) != EXIT_SUCCESS) { + if (__prepare_animation(NULL, &args) != EXIT_SUCCESS) { vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1); return 1; } diff --git a/tizen-manifest.xml b/tizen-manifest.xml index 3242615..a810db4 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml @@ -1,7 +1,7 @@ - + - + boot-animation.png -- 2.7.4