tizen 2.4 release
[framework/uifw/elementary.git] / src / lib / elm_store.c
index c2bd8dd..cd7bb22 100644 (file)
@@ -1,5 +1,10 @@
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#endif
+
 #include <Elementary.h>
 #include <Elementary_Cursor.h>
+
 #include "elm_priv.h"
 
 typedef struct _Elm_Store_Filesystem           Elm_Store_Filesystem;
@@ -94,11 +99,7 @@ _store_cache_trim(Elm_Store *st)
         if (!sti->fetched)
           {
              eina_lock_release(&sti->lock);
-             if (sti->fetch_th)
-               {
-                  ecore_thread_cancel(sti->fetch_th);
-                  sti->fetch_th = NULL;
-               }
+             ELM_SAFE_FREE(sti->fetch_th, ecore_thread_cancel);
              eina_lock_take(&sti->lock);
           }
         sti->fetched = EINA_FALSE;
@@ -113,29 +114,17 @@ _store_cache_trim(Elm_Store *st)
 }
 
 static void
-_store_genlist_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+_store_genlist_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
 {
    Elm_Store *st = data;
    st->genlist = NULL;
-   if (st->list_th)
-     {
-        ecore_thread_cancel(st->list_th);
-        st->list_th = NULL;
-     }
+   ELM_SAFE_FREE(st->list_th, ecore_thread_cancel);
    st->realized = eina_list_free(st->realized);
    while (st->items)
      {
         Elm_Store_Item *sti = (Elm_Store_Item *)st->items;
-        if (sti->eval_job)
-          {
-             ecore_job_del(sti->eval_job);
-             sti->eval_job = NULL;
-          }
-        if (sti->fetch_th)
-          {
-             ecore_thread_cancel(sti->fetch_th);
-             sti->fetch_th = NULL;
-          }
+        ELM_SAFE_FREE(sti->eval_job, ecore_job_del);
+        ELM_SAFE_FREE(sti->fetch_th, ecore_thread_cancel);
         if (sti->store->item.free) sti->store->item.free(sti);
         eina_lock_take(&sti->lock);
         if (sti->data)
@@ -146,7 +135,7 @@ _store_genlist_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
           }
         eina_lock_release(&sti->lock);
         eina_lock_free(&sti->lock);
-        st->items = NULL;
+        st->items = eina_inlist_remove(st->items, EINA_INLIST_GET(sti));
         free(sti);
      }
    // FIXME: kill threads and more
@@ -155,9 +144,9 @@ _store_genlist_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
 ////// **** WARNING ***********************************************************
 ////   * This function runs inside a thread outside efl mainloop. Be careful! *
 //     ************************************************************************
-/* TODO: refactor lock part into core? this does not depend on filesystm part */
+/* TODO: refactor lock part into core? this does not depend on filesystem part */
 static void
-_store_filesystem_fetch_do(void *data, Ecore_Thread *th __UNUSED__)
+_store_filesystem_fetch_do(void *data, Ecore_Thread *th EINA_UNUSED)
 {
    Elm_Store_Item *sti = data;
    eina_lock_take(&sti->lock);
@@ -180,7 +169,7 @@ _store_filesystem_fetch_do(void *data, Ecore_Thread *th __UNUSED__)
 //     ************************************************************************
 ////   * End of separate thread function.                                     *
 ////// ************************************************************************
-/* TODO: refactor lock part into core? this does not depend on filesystm part */
+/* TODO: refactor lock part into core? this does not depend on filesystem part */
 static void
 _store_filesystem_fetch_end(void *data, Ecore_Thread *th)
 {
@@ -191,7 +180,7 @@ _store_filesystem_fetch_end(void *data, Ecore_Thread *th)
    if (th == sti->fetch_th) sti->fetch_th = NULL;
 }
 
-/* TODO: refactor lock part into core? this does not depend on filesystm part */
+/* TODO: refactor lock part into core? this does not depend on filesystem part */
 static void
 _store_filesystem_fetch_cancel(void *data, Ecore_Thread *th)
 {
@@ -229,17 +218,13 @@ _store_item_eval(void *data)
      }
    else
      {
-        if (sti->fetch_th)
-          {
-             ecore_thread_cancel(sti->fetch_th);
-             sti->fetch_th = NULL;
-          }
+        ELM_SAFE_FREE(sti->fetch_th, ecore_thread_cancel);
         _store_cache_trim(sti->store);
      }
 }
 
 static void
-_store_genlist_item_realized(void *data, Evas_Object *obj __UNUSED__, void *event_info)
+_store_genlist_item_realized(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
 {
    Elm_Store *st = data;
    Elm_Object_Item *gli = event_info;
@@ -247,12 +232,12 @@ _store_genlist_item_realized(void *data, Evas_Object *obj __UNUSED__, void *even
    if (!sti) return;
    st->realized_count++;
    sti->live = EINA_TRUE;
-   if (sti->eval_job) ecore_job_del(sti->eval_job);
+   ecore_job_del(sti->eval_job);
    sti->eval_job = ecore_job_add(_store_item_eval, sti);
 }
 
 static void
-_store_genlist_item_unrealized(void *data, Evas_Object *obj __UNUSED__, void *event_info)
+_store_genlist_item_unrealized(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
 {
    Elm_Store *st = data;
    Elm_Object_Item *gli = event_info;
@@ -260,7 +245,7 @@ _store_genlist_item_unrealized(void *data, Evas_Object *obj __UNUSED__, void *ev
    if (!sti) return;
    st->realized_count--;
    sti->live = EINA_FALSE;
-   if (sti->eval_job) ecore_job_del(sti->eval_job);
+   ecore_job_del(sti->eval_job);
    sti->eval_job = ecore_job_add(_store_item_eval, sti);
 }
 
@@ -278,7 +263,7 @@ _store_item_mapping_find(Elm_Store_Item *sti, const char *part)
 }
 
 static char *
-_store_item_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
+_store_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
 {
    Elm_Store_Item *sti = data;
    const char *s = "";
@@ -365,7 +350,7 @@ _store_item_content_get(void *data, Evas_Object *obj, const char *part)
 }
 
 static void
-_store_item_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
+_store_item_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
 {
 }
 
@@ -381,7 +366,7 @@ _store_filesystem_sort_cb(void *d1, void *d2)
 }
 
 static void
-_store_filesystem_list_do(void *data, Ecore_Thread *th __UNUSED__)
+_store_filesystem_list_do(void *data, Ecore_Thread *th EINA_UNUSED)
 {
    Elm_Store_Filesystem *st = data;
    Eina_Iterator *it;
@@ -414,7 +399,7 @@ _store_filesystem_list_do(void *data, Ecore_Thread *th __UNUSED__)
           }
         else
           {
-             if (info->base.sort_id) free(info->base.sort_id);
+             free(info->base.sort_id);
              free(info);
           }
         if (ecore_thread_check(th)) break;
@@ -449,7 +434,7 @@ _store_filesystem_list_cancel(void *data, Ecore_Thread *th)
 }
 
 static void
-_store_filesystem_list_update(void *data, Ecore_Thread *th __UNUSED__, void *msg)
+_store_filesystem_list_update(void *data, Ecore_Thread *th EINA_UNUSED, void *msg)
 {
    Elm_Store *st = data;
    Elm_Store_Item_Filesystem *sti;
@@ -484,7 +469,7 @@ _store_filesystem_list_update(void *data, Ecore_Thread *th __UNUSED__, void *msg
                                             NULL/* func data */);
    st->items = eina_inlist_append(st->items, (Eina_Inlist *)sti);
 done:
-   if (info->base.sort_id) free(info->base.sort_id);
+   free(info->base.sort_id);
    free(info);
 }
 
@@ -546,26 +531,14 @@ elm_store_free(Elm_Store *st)
 {
    void (*item_free)(Elm_Store_Item *);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
-   if (st->list_th)
-     {
-        ecore_thread_cancel(st->list_th);
-        st->list_th = NULL;
-     }
+   ELM_SAFE_FREE(st->list_th, ecore_thread_cancel);
    st->realized = eina_list_free(st->realized);
    item_free = st->item.free;
    while (st->items)
      {
         Elm_Store_Item *sti = (Elm_Store_Item *)st->items;
-        if (sti->eval_job)
-          {
-             ecore_job_del(sti->eval_job);
-             sti->eval_job = NULL;
-          }
-        if (sti->fetch_th)
-          {
-             ecore_thread_cancel(sti->fetch_th);
-             sti->fetch_th = NULL;
-          }
+        ELM_SAFE_FREE(sti->eval_job, ecore_job_del);
+        ELM_SAFE_FREE(sti->fetch_th, ecore_thread_cancel);
         if (item_free) item_free(sti);
         eina_lock_take(&sti->lock);
         if (sti->data)
@@ -576,6 +549,7 @@ elm_store_free(Elm_Store *st)
           }
         eina_lock_release(&sti->lock);
         eina_lock_free(&sti->lock);
+        st->items = eina_inlist_remove(st->items, EINA_INLIST_GET(sti));
         free(sti);
      }
    if (st->genlist)
@@ -616,11 +590,7 @@ elm_store_filesystem_directory_set(Elm_Store *store, const char *dir)
    Elm_Store_Filesystem *st = (Elm_Store_Filesystem *)store;
    if (!EINA_MAGIC_CHECK(store, ELM_STORE_MAGIC)) return;
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_FILESYSTEM_MAGIC)) return;
-   if (store->list_th)
-     {
-        ecore_thread_cancel(store->list_th);
-        store->list_th = NULL;
-     }
+   ELM_SAFE_FREE(store->list_th, ecore_thread_cancel);
    if (!eina_stringshare_replace(&st->dir, dir)) return;
    store->list_th = ecore_thread_feedback_run(_store_filesystem_list_do,
                                               _store_filesystem_list_update,