default_backend: modify return type of get_ani_info_from_ani_collection, fix the... 59/220659/1
authorSung-Jin Park <sj76.park@samsung.com>
Wed, 21 Aug 2019 07:07:17 +0000 (16:07 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 20 Dec 2019 07:14:21 +0000 (16:14 +0900)
Change-Id: I75ecec5305d33465cd1eb3a3ff7ee182f5ad97ab
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
backends/default_backend.c

index 70fb0f6..47a2281 100644 (file)
@@ -66,7 +66,7 @@ struct _default_led_info_t
 pui_backend_ani_data *g_ani_data = NULL;
 
 static pui_bool
-_frame_cb(void *data, int serial)
+_ani_backend_frame_cb(void *data, int serial)
 {
        pui_ani_t *ani = (pui_ani_t *)data;
 
@@ -76,24 +76,42 @@ _frame_cb(void *data, int serial)
        //pui_backend_ani_get_buffer();
        //pui_backend_ani_update();
 
+       pui_info("... serial=%d\n", serial);
+
        return (pui_bool)1;
 }
 
-pui_int_error
-get_ani_info_from_ani_collection(default_ani_info *info, pui_id id)
+default_ani_info *
+get_ani_info_from_ani_collection(pui_id id)
 {
-       pui_int_error e = PUI_INT_ERROR_NONE;
+       default_ani_info *ani_info = NULL;
 
        //TODO
        //ex> data->id = id;
        //ex> data->interval = 30;
 
-       return e;
+       if (!_animations_hash)
+               return NULL;
+
+       pui_info("... id: %s\n", id);
+
+       ani_info = eina_hash_find(_animations_hash, id);
+
+       if (!ani_info)
+       {
+               pui_err("ani_info has NOT been found ! (id:%s)\n", id);
+               return NULL;
+       }
+
+       pui_info("ani_info has been found ! (id:%s)\n", id);
+
+       return ani_info;
 }
 
 pui_error
 _ani_start(pui_ani_t *ani, int repeat)
 {
+       pui_bool ret = 0;
        pui_int_error e = PUI_INT_ERROR_NONE;
        pui_backend_ani_data *ani_data = NULL;
 
@@ -103,8 +121,16 @@ _ani_start(pui_ani_t *ani, int repeat)
        //TODO
        (void) info;
 
+       pui_info("... info->id: %s, repeat : %d\n", info->id, repeat);
+
        pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
-       pui_backend_ani_add_frame_cb(ani, _frame_cb, 0.1);
+       ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_frame_cb, 0.1);
+
+       if (!ret)
+       {
+               pui_err("Failed to add frame callback !\n");
+               e = PUI_INT_ERROR_INVALID_RESOURCES;
+       }
 
        return e;
 }
@@ -121,6 +147,8 @@ _ani_stop(pui_ani_t *ani)
        //TODO
        (void) info;
 
+       pui_info("... info->id: %s\n", info->id);
+
        pui_backend_ani_remove_frame_cb(ani);
        pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
 
@@ -296,7 +324,9 @@ _is_ani_supported(pui_id id)
                return e;
        }
        ani_info = eina_hash_find(_animations_hash, id);
-       if (!ani_info) e = PUI_INT_ERROR_ID_NOT_SUPPORTED;
+
+       if (!ani_info)
+               e = PUI_INT_ERROR_ID_NOT_SUPPORTED;
 
        return e;
 }
@@ -306,25 +336,26 @@ _ani_info_cleanup(default_ani_info *ani_info)
 {
        int i;
 
-       if (!ani_info) return;
+       if (!ani_info)
+               return;
 
-       eina_hash_del(_animations_hash, ani_info->id, ani_info);
-       if (ani_info->frames) {
-               for (i = 0; i < ani_info->num_key_frames; i++) {
+       if (ani_info->frames)
+       {
+               for (i = 0; i < ani_info->num_key_frames; i++)
+               {
                        if (ani_info->frames[i].leds)
                                free(ani_info->frames[i].leds);
                }
+
                free(ani_info->frames);
        }
+
        free(ani_info->id);
-       free(ani_info);
 }
 
 pui_backend_ani_data *
 _ani_create(pui_id id)
 {
-       pui_int_error e = PUI_INT_ERROR_NONE;
-
        pui_backend_ani_data *ani_data = NULL;
        pui_backend_ani_func *ani_func = NULL;
 
@@ -332,6 +363,11 @@ _ani_create(pui_id id)
        default_ani_info *ani_info = NULL;
 
        //TODO : return NULL if the animation correspond to the given id dones't exist.
+       if (PUI_INT_ERROR_NONE != _is_ani_supported(id))
+       {
+               pui_err("The animation(%s) doesn't supported !\n", id);
+               return NULL;
+       }
 
        /* allocation of the structure of function pointers that will be called from pui_ani_control() */
        ani_func = pui_backend_ani_alloc_ani_func();
@@ -346,30 +382,10 @@ _ani_create(pui_id id)
        ani_func->ani_start = _ani_start;
        ani_func->ani_stop = _ani_stop;
 
-       ani_func->reserved1 = NULL;
-       ani_func->reserved2 = NULL;
-       ani_func->reserved3 = NULL;
-       ani_func->reserved4 = NULL;
-       ani_func->reserved5 = NULL;
-       ani_func->reserved6 = NULL;
-       ani_func->reserved7 = NULL;
-       ani_func->reserved8 = NULL;
-       ani_func->reserved9 = NULL;
-       ani_func->reserved10 = NULL;
-
-       /* backend's animation specific info */
-       ani_info = (default_ani_info *)calloc(1, sizeof(default_ani_info));
-
-       if (!ani_info)
-       {
-               pui_err("Failed to allocate memory ! (backend's ani specific info)\n");
-               goto err;
-       }
-
-       /* fill animation info associate with the given id from animation collection */
-       e = get_ani_info_from_ani_collection(ani_info, id);
+       /* get animation info associate with the given id from animation collection */
+       ani_info = get_ani_info_from_ani_collection(id);
        
-       if (PUI_INT_ERROR_NONE != e)
+       if (!ani_info)
        {
                pui_err("Failed to get ani info from animation collection !\n");
                goto err;
@@ -398,11 +414,6 @@ err:
                ani_func = NULL;
        }
 
-       if (ani_info)
-       {
-               _ani_info_cleanup(ani_info);
-       }
-
        return NULL;
 }
 
@@ -412,17 +423,13 @@ _ani_destroy(pui_backend_ani_data *ani_data)
        if (!ani_data)
                return;
 
-       pui_backend_ani_free_ani_func(ani_data->ani_func);
-
-       //TODO : free if anything needs to be done with ani_info
-       free(ani_data->ani_info);
-
-       ani_data->ani_func = NULL;
-       if (ani_data->ani_info) {
-               _ani_info_cleanup(ani_data->ani_info);
-               ani_data->ani_info = NULL;
+       if (ani_data->ani_func)
+       {
+               pui_backend_ani_free_ani_func(ani_data->ani_func);
+               ani_data->ani_func = NULL;
        }
 
+       ani_data->ani_info = NULL;
        g_ani_data = NULL;
 }
 
@@ -453,7 +460,7 @@ pui_default_backend_init(void)
 
        /* Allocate backend specific data if needed. Now it will be empty. */
        backend_data->data = NULL;
-       _animations_hash = eina_hash_string_superfast_new(_animation_data_free_cb);
+       _animations_hash = eina_hash_string_superfast_new(NULL);
 
        return backend_data;
 }
@@ -461,6 +468,9 @@ pui_default_backend_init(void)
 static void
 pui_default_backend_deinit(pui_backend_module_data *backend_data)
 {
+       Eina_Iterator *it;
+       default_ani_info *ani_info = NULL;
+
        if (!backend_data)
                return;
 
@@ -479,11 +489,23 @@ pui_default_backend_deinit(pui_backend_module_data *backend_data)
                        g_ani_data->ani_func = NULL;
                }
 
-               if (g_ani_data->ani_info)
+               g_ani_data->ani_info = NULL;
+       }
+
+       if (_animations_hash)
+       {
+               it = eina_hash_iterator_data_new(_animations_hash);
+
+               EINA_ITERATOR_FOREACH(it, ani_info)
                {
-                       _ani_info_cleanup(g_ani_data->ani_info);
-                       g_ani_data->ani_info = NULL;
+                       _animation_data_free_cb(ani_info);
+                       free(ani_info);
                }
+
+               eina_iterator_free(it);
+
+               eina_hash_free(_animations_hash);
+               _animations_hash = NULL;
        }
 
        backend_data->create_ani_collection = NULL;