revise the object life-cycle management
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 10 Dec 2013 23:17:41 +0000 (08:17 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 10 Dec 2013 23:17:41 +0000 (08:17 +0900)
Depends on EFL parent-children relationship

Change-Id: I0e25675993f61478c0bc693e047a0f2967925d84

packaging/liblivebox-edje.spec
src/script_port.c

index 9880706..94c521f 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-edje
 Summary: EDJE Script loader for the data provider master
-Version: 0.5.29
+Version: 0.5.30
 Release: 1
 Group: HomeTF/Livebox
 License: Flora
index 97b8be9..fb35bbf 100644 (file)
@@ -45,8 +45,6 @@
 
 #define PUBLIC __attribute__((visibility("default")))
 
-void _elm_access_object_hilight(Evas_Object *obj);
-
 struct image_option {
        int orient;
        int aspect;
@@ -81,7 +79,6 @@ struct info {
        Evas_Object *parent;
 
        Eina_List *obj_list;
-       Eina_List *access_chain;
 };
 
 struct child {
@@ -93,6 +90,7 @@ struct obj_info {
        char *id;
        Eina_List *children;
        Evas_Object *parent;
+       int delete_me;
 };
 
 static struct {
@@ -178,8 +176,6 @@ PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *par
 
 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
 {
-       Evas_Object *ao;
-       Evas_Object *edje;
        Evas *e;
        int x;
        int y;
@@ -187,16 +183,6 @@ static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item
        int h;
        double timestamp;
 
-       ao = evas_object_data_get(part_obj, "ao");
-       if (!ao) {
-               return;
-       }
-
-       edje = evas_object_data_get(ao, "edje");
-       if (!edje) {
-               return;
-       }
-
        e = evas_object_evas_get(part_obj);
        evas_object_geometry_get(part_obj, &x, &y, &w, &h);
        x += w / 2;
@@ -221,24 +207,6 @@ static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item
        evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
 }
 
-static void access_del_cb(void *_info, Evas *e, Evas_Object *ao, void *event_info)
-{
-       struct info *handle = _info;
-       Evas_Object *edje_part;
-
-       edje_part = evas_object_data_del(ao, "edje,part");
-
-       /*!
-        * \note
-        * (void)evas_object_data_del(ao, "edje");
-        * edje_part will delete the "ao" tag when it is deleted.
-        * (void)evas_object_data_del(edje_part, "ao");
-        */
-
-       handle->access_chain = eina_list_remove(handle->access_chain, edje_part);
-       DbgPrint("AO(%p) is removed from local access chain\n", ao);
-}
-
 static void update_focus_chain(struct info *handle, Evas_Object *ao)
 {
        const Eina_List *list;
@@ -284,17 +252,9 @@ PUBLIC int script_update_text(void *h, Evas *e, const char *id, const char *part
                                goto out;
                        }
 
-                       if (!handle->access_chain && s_info.access_on) {
-                               _elm_access_object_hilight(edje);
-                       }
-
-                       handle->access_chain = eina_list_append(handle->access_chain, edje_part);
                        evas_object_data_set(edje_part, "ao", ao);
-                       evas_object_data_set(ao, "edje", edje);
-                       evas_object_data_set(ao, "edje,part", edje_part);
                        elm_access_activate_cb_set(ao, activate_cb, NULL);
                        elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
-                       evas_object_event_callback_add(ao, EVAS_CALLBACK_DEL, access_del_cb, handle);
 
                        DbgPrint("[%s] Register access info: (%s) to, %p\n", part, text, handle->parent);
                }
@@ -602,17 +562,9 @@ PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *p
                        } else {
                                elm_access_info_set(ao, ELM_ACCESS_INFO, text);
 
-                               if (!handle->access_chain && s_info.access_on) {
-                                       _elm_access_object_hilight(edje);
-                               }
-
-                               handle->access_chain = eina_list_append(handle->access_chain, edje_part);
                                evas_object_data_set(edje_part, "ao", ao);
-                               evas_object_data_set(ao, "edje", edje);
-                               evas_object_data_set(ao, "edje,part", edje_part);
                                elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
                                elm_access_activate_cb_set(ao, activate_cb, NULL);
-                               evas_object_event_callback_add(ao, EVAS_CALLBACK_DEL, access_del_cb, handle);
                                DbgPrint("[%s] Register access info: (%s) to, %p (%p)\n", part, text, handle->parent, ao);
                        }
                }
@@ -734,7 +686,6 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
        Evas_Object *img;
        Evas_Coord w, h;
        struct obj_info *obj_info;
-       struct child *child;
        struct image_option img_opt = {
                .aspect = 0,
                .orient = 0,
@@ -760,20 +711,6 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
 
        img = elm_object_part_content_unset(edje, part);
        if (img) {
-               Eina_List *l;
-               Eina_List *n;
-
-               EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
-                       if (child->obj != img) {
-                               continue;
-                       }
-
-                       obj_info->children = eina_list_remove(obj_info->children, child);
-                       free(child->part);
-                       free(child);
-                       break;
-               }
-
                DbgPrint("delete object %s %p\n", part, img);
                evas_object_del(img);
        }
@@ -783,24 +720,9 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                return LB_STATUS_SUCCESS;
        }
 
-       child = malloc(sizeof(*child));
-       if (!child) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       child->part = strdup(part);
-       if (!child->part) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               free(child);
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
        img = evas_object_image_add(e);
        if (!img) {
                ErrPrint("Failed to add an image object\n");
-               free(child->part);
-               free(child);
                return LB_STATUS_ERROR_FAULT;
        }
 
@@ -813,8 +735,6 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
        if (err != EVAS_LOAD_ERROR_NONE) {
                ErrPrint("Load error: %s\n", evas_load_error_str(err));
                evas_object_del(img);
-               free(child->part);
-               free(child);
                return LB_STATUS_ERROR_IO;
        }
 
@@ -854,8 +774,6 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
 
                        if (!part_w || !part_h || !w || !h) {
                                evas_object_del(img);
-                               free(child->part);
-                               free(child);
                                return LB_STATUS_ERROR_INVALID;
                        }
 
@@ -877,8 +795,6 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                                if (!ee) {
                                        ErrPrint("Failed to create a EE\n");
                                        evas_object_del(img);
-                                       free(child->part);
-                                       free(child);
                                        return LB_STATUS_ERROR_FAULT;
                                }
 
@@ -888,10 +804,7 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                                if (!e) {
                                        ErrPrint("Unable to get Evas\n");
                                        ecore_evas_free(ee);
-
                                        evas_object_del(img);
-                                       free(child->part);
-                                       free(child);
                                        return LB_STATUS_ERROR_FAULT;
                                }
 
@@ -899,10 +812,7 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                                if (!src_img) {
                                        ErrPrint("Unable to add an image\n");
                                        ecore_evas_free(ee);
-
                                        evas_object_del(img);
-                                       free(child->part);
-                                       free(child);
                                        return LB_STATUS_ERROR_FAULT;
                                }
 
@@ -916,10 +826,7 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                                        ErrPrint("Load error: %s\n", evas_load_error_str(err));
                                        evas_object_del(src_img);
                                        ecore_evas_free(ee);
-
                                        evas_object_del(img);
-                                       free(child->part);
-                                       free(child);
                                        return LB_STATUS_ERROR_IO;
                                }
                                evas_object_image_size_get(src_img, &rw, &rh);
@@ -933,10 +840,7 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                                        ErrPrint("Unable to get pixels\n");
                                        evas_object_del(src_img);
                                        ecore_evas_free(ee);
-
                                        evas_object_del(img);
-                                       free(child->part);
-                                       free(child);
                                        return LB_STATUS_ERROR_IO;
                                }
 
@@ -946,9 +850,6 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
                                if (!img) {
                                        evas_object_del(src_img);
                                        ecore_evas_free(ee);
-
-                                       free(child->part);
-                                       free(child);
                                        return LB_STATUS_ERROR_MEMORY;
                                }
 
@@ -1024,9 +925,7 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa
         * object will be shown by below statement automatically
         */
        DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
-       child->obj = img;
        elm_object_part_content_set(edje, part, img);
-       obj_info->children = eina_list_append(obj_info->children, child);
 
        /*!
         * \note
@@ -1077,52 +976,61 @@ static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info
 
        handle->obj_list = eina_list_remove(handle->obj_list, obj);
 
-       obj_info = evas_object_data_del(obj, "obj_info");
+       obj_info = evas_object_data_get(obj, "obj_info");
        if (!obj_info) {
                ErrPrint("Object info is not valid\n");
                return;
        }
 
+       elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
+
        DbgPrint("delete object %s %p\n", obj_info->id, obj);
-       parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
-       if (parent_obj_info) {
+       if (obj_info->parent == obj) {
+               DbgPrint("Parent EDJE\n");
+       } else if (obj_info->parent) {
                Eina_List *l;
                Eina_List *n;
 
-               EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
-                       if (child->obj != obj) {
-                               continue;
+               parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
+               if (parent_obj_info) {
+                       EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
+                               if (child->obj != obj) {
+                                       continue;
+                               }
+
+                               /*!
+                                * \note
+                                * If this code is executed,
+                                * The parent is not deleted by desc, this object is deleted by itself.
+                                * It is not possible, but we care it.
+                                */
+                               DbgPrint("Children is updated: %s (%s)\n", child->part, parent_obj_info->id);
+                               parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
+                               free(child->part);
+                               free(child);
+                               break;
                        }
 
-                       /*!
-                        * \note
-                        * If this code is executed,
-                        * The parent is not deleted by desc, this object is deleted by itself.
-                        * It is not possible, but we care it.
-                        */
-                       DbgPrint("Parent's children is updated: %s\n", child->part);
-                       parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
-                       free(child->part);
-                       free(child);
-                       break;
+                       if (!parent_obj_info->children && parent_obj_info->delete_me == 1) {
+                               DbgPrint("Children is cleared: %s (by a child)\n", parent_obj_info->id);
+                               evas_object_data_del(obj_info->parent, "obj_info");
+                               free(parent_obj_info->id);
+                               free(parent_obj_info);
+                       }
                }
        } else {
-               DbgPrint("Parent EDJE\n");
+               DbgPrint("obj_info->parent is NULL (skipped)\n");
        }
 
-       elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
-
-       EINA_LIST_FREE(obj_info->children, child) {
-               DbgPrint("delete object %s %p\n", child->part, child->obj);
-               if (child->obj) {
-                       evas_object_del(child->obj);
-               }
-               free(child->part);
-               free(child);
+       if (!obj_info->children) {
+               DbgPrint("Children is cleared: %s\n", obj_info->id);
+               evas_object_data_del(obj, "obj_info");
+               free(obj_info->id);
+               free(obj_info);
+       } else {
+               DbgPrint("Children is remained: %s\n", obj_info->id);
+               obj_info->delete_me = 1;
        }
-
-       free(obj_info->id);
-       free(obj_info);
 }
 
 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
@@ -1380,21 +1288,6 @@ PUBLIC int script_update_script(void *h, Evas *e, const char *src_id, const char
 
        obj = elm_object_part_content_unset(edje, part);
        if (obj) {
-               Eina_List *l;
-               Eina_List *n;
-
-               EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
-                       if (child->obj != obj) {
-                               continue;
-                       }
-
-                       obj_info->children = eina_list_remove(obj_info->children, child);
-
-                       free(child->part);
-                       free(child);
-                       break;
-               }
-
                DbgPrint("delete object %s %p\n", part, obj);
                /*!
                 * \note
@@ -1626,6 +1519,7 @@ PUBLIC int script_destroy(void *_handle)
                evas_object_del(edje);
        }
 
+       DbgPrint("Release handle\n");
        free(handle->category);
        free(handle->file);
        free(handle->group);
@@ -1695,25 +1589,16 @@ PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
 PUBLIC int script_unload(void *_handle, Evas *e)
 {
        struct info *handle;
-       Evas_Object *edje;
-       Evas_Object *parent = NULL;
 
        handle = _handle;
 
-       edje = eina_list_nth(handle->obj_list, 0);
-       if (edje) {
-               struct obj_info *obj_info;
-
-               obj_info = evas_object_data_get(edje, "obj_info");
-               if (obj_info) {
-                       parent = obj_info->parent;
-               }
-               evas_object_del(edje);
+       if (handle->e != e) {
+               DbgPrint("Ooops, handle->e(%p) is not matched with e(%p)\n", handle->e, e);
        }
 
-       if (parent) {
+       if (handle->parent) {
                DbgPrint("Delete parent box\n");
-               evas_object_del(parent);
+               evas_object_del(handle->parent);
        }
 
        handle->e = NULL;