Improve tag related function 01/229001/4 accepted/tizen/unified/20200331.031015 submit/tizen/20200330.065305
authorMinje Ahn <minje.ahn@samsung.com>
Fri, 27 Mar 2020 04:13:33 +0000 (13:13 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 30 Mar 2020 04:30:58 +0000 (13:30 +0900)
Change-Id: I180531f6794ffb37214688cf6dc0bfba37b5495c
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/media_playlist.c
src/media_tag.c

index e397544..96e8126 100755 (executable)
@@ -417,13 +417,14 @@ int media_playlist_get_play_order(media_playlist_h playlist, int playlist_member
 int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name)
 {
        media_playlist_s *_playlist = (media_playlist_s *)playlist;
+       media_playlist_item_s *item = NULL;
 
        content_retip_if_fail(playlist);
        content_retip_if_fail(STRING_VALID(playlist_name));
 
        SAFE_FREE(_playlist->name);
 
-       media_playlist_item_s *item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
+       item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
        content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        item->playlist_name = g_strdup(playlist_name);
@@ -438,13 +439,14 @@ int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name
 int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *path)
 {
        media_playlist_s *_playlist = (media_playlist_s *)playlist;
+       media_playlist_item_s *item = NULL;
 
        content_retip_if_fail(playlist);
        content_retip_if_fail(STRING_VALID(path));
 
        SAFE_FREE(_playlist->thumbnail_path);
 
-       media_playlist_item_s *item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
+       item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
        content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        item->thumbnail_path = g_strdup(path);
@@ -459,12 +461,13 @@ int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *pat
 int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member_id, int play_order)
 {
        media_playlist_s *_playlist = (media_playlist_s *)playlist;
+       media_playlist_item_s *item = NULL;
 
        content_retip_if_fail(playlist);
        content_retipm_if_fail(playlist_member_id > 0, "%d", playlist_member_id);
        content_retipm_if_fail(play_order >= 0, "%d", play_order);
 
-       media_playlist_item_s *item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
+       item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
        content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        item->playlist_member_id = playlist_member_id;
@@ -479,11 +482,12 @@ int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member
 int media_playlist_add_media(media_playlist_h playlist, const char *media_id)
 {
        media_playlist_s *_playlist = (media_playlist_s *)playlist;
+       media_playlist_item_s *item = NULL;
 
        content_retip_if_fail(playlist);
        content_retip_if_fail(STRING_VALID(media_id));
 
-       media_playlist_item_s *item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
+       item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
        content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        item->media_id = g_strdup(media_id);
@@ -497,11 +501,12 @@ int media_playlist_add_media(media_playlist_h playlist, const char *media_id)
 int media_playlist_remove_media(media_playlist_h playlist, int playlist_member_id)
 {
        media_playlist_s *_playlist = (media_playlist_s *)playlist;
+       media_playlist_item_s *item = NULL;
 
        content_retip_if_fail(playlist);
        content_retipm_if_fail(playlist_member_id > 0, "%d", playlist_member_id);
 
-       media_playlist_item_s *item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
+       item = (media_playlist_item_s *)calloc(1, sizeof(media_playlist_item_s));
        content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        item->playlist_member_id = playlist_member_id;
index adc6106..e572f51 100755 (executable)
 
 #include <media_info_private.h>
 
-static void __media_tag_item_add(media_tag_s *tag_s, media_tag_item_s *item_s);
-static void __media_tag_item_release(media_tag_s *tag_s);
-static int __media_tag_insert_item_to_tag(int tag_id, const char *media_id);
-static int __media_tag_remove_item_from_tag(int tag_id, const char *media_id);
-static int __media_tag_update_tag_name(int tag_id, const char *tag_name);
-static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag);
-
-static void __media_tag_item_add(media_tag_s *tag_s, media_tag_item_s *item_s)
+static void __media_tag_item_free(gpointer item)
 {
-       tag_s->item_list = g_list_append(tag_s->item_list, item_s);
+       media_tag_item_s *_item = (media_tag_item_s *)item;
+       SAFE_FREE(_item->media_id);
+       SAFE_FREE(_item->tag_name);
+       SAFE_FREE(_item);
 }
 
-static void __media_tag_item_release(media_tag_s *tag_s)
+static void __media_tag_item_release(media_tag_s *tag)
 {
-       int idx = 0;
-       int list_cnt = 0;
-       media_tag_item_s *item = NULL;
-
-       list_cnt = g_list_length(tag_s->item_list);
-
-       content_debug("list_cnt : [%d]", list_cnt);
-
-       for (idx = 0; idx < list_cnt; idx++) {
-               item = (media_tag_item_s*)g_list_nth_data(tag_s->item_list, idx);
-               if (item != NULL) {
-                       SAFE_FREE(item->media_id);
-                       SAFE_FREE(item->tag_name);
-                       SAFE_FREE(item);
-               }
-       }
-
-       g_list_free(tag_s->item_list);
-       tag_s->item_list = NULL;
+       if (!tag || !tag->item_list)
+               return;
 
+       g_list_free_full(tag->item_list, __media_tag_item_free);
+       tag->item_list = NULL;
 }
 
 static int __media_tag_insert_item_to_tag(int tag_id, const char *media_id)
@@ -91,9 +72,9 @@ static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag)
        int ret = MEDIA_CONTENT_ERROR_NONE;
        sqlite3_stmt *stmt = NULL;
        char *select_query = NULL;
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
 
-       content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag");
+       content_retip_if_fail(tag);
 
        select_query = sqlite3_mprintf(SELECT_TAG_BY_NAME, name);
 
@@ -102,7 +83,7 @@ static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag)
        content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
        if (sqlite3_step(stmt) == SQLITE_ROW) {
-               _tag->tag_id = (int)sqlite3_column_int(stmt, 0);
+               _tag->tag_id = sqlite3_column_int(stmt, 0);
                _tag->name = g_strdup(name);
        } else {
                content_error("Nonexistent tag name[%s]", name);
@@ -119,17 +100,15 @@ int media_tag_insert_to_db(const char *tag_name, media_tag_h *tag)
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char *query_str = NULL;
 
-       if (!STRING_VALID(tag_name)) {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(STRING_VALID(tag_name));
+       content_retip_if_fail(tag);
 
        query_str = sqlite3_mprintf(INSERT_TAG_TO_TAG, tag_name);
        ret = _content_query_sql(query_str);
        SQLITE3_SAFE_FREE(query_str);
 
        if (ret == MEDIA_CONTENT_ERROR_NONE) {
-               media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
+               media_tag_s *_tag = (media_tag_s *)calloc(1, sizeof(media_tag_s));
                content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
                ret = __media_tag_get_tag_info_from_db(tag_name, (media_tag_h)_tag);
@@ -144,13 +123,9 @@ int media_tag_delete_from_db(int tag_id)
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char *query_str = NULL;
 
-       if (tag_id < 0) {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retipm_if_fail(tag_id > 0, "%d", tag_id);
 
        query_str = sqlite3_mprintf(DELETE_TAG_FROM_TAG, tag_id);
-
        ret = _content_query_sql(query_str);
 
        SQLITE3_SAFE_FREE(query_str);
@@ -160,165 +135,102 @@ int media_tag_delete_from_db(int tag_id)
 
 int media_tag_get_tag_count_from_db(filter_h filter, int *tag_count)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       if (tag_count != NULL) {
-               ret = _media_db_get_group_count(filter, MEDIA_GROUP_TAG, tag_count);
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(tag_count);
 
-       return ret;
+       return _media_db_get_group_count(filter, MEDIA_GROUP_TAG, tag_count);
 }
 
 int media_tag_foreach_tag_from_db(filter_h filter, media_tag_cb callback, void *user_data)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
+       content_retip_if_fail(callback);
 
-       if (callback == NULL) {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _media_db_get_tag(NULL, filter, callback, user_data);
-
-       return ret;
+       return _media_db_get_tag(NULL, filter, callback, user_data);
 }
 
 int media_tag_get_media_count_from_db(int tag_id, filter_h filter, int *media_count)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       if ((tag_id > 0) && (media_count != NULL)) {
-               ret = _media_db_get_group_item_count_by_id(tag_id, filter, MEDIA_GROUP_TAG, media_count);
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retipm_if_fail(tag_id > 0, "%d", tag_id);
+       content_retip_if_fail(media_count);
 
-       return ret;
+       return _media_db_get_group_item_count_by_id(tag_id, filter, MEDIA_GROUP_TAG, media_count);
 }
 
 int media_tag_foreach_media_from_db(int tag_id, filter_h filter, media_info_cb callback, void *user_data)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       if (callback == NULL) {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _media_db_get_group_item_by_id(tag_id, filter, callback, user_data, MEDIA_GROUP_TAG);
+       content_retip_if_fail(callback);
 
-       return ret;
+       return _media_db_get_group_item_by_id(tag_id, filter, callback, user_data, MEDIA_GROUP_TAG);
 }
 
 int media_tag_destroy(media_tag_h tag)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
-       if (_tag) {
-               SAFE_FREE(_tag->name);
-               SAFE_FREE(_tag);
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       media_tag_s *_tag = (media_tag_s *)tag;
+       content_retip_if_fail(tag);
 
-       return ret;
+       SAFE_FREE(_tag->name);
+       SAFE_FREE(_tag);
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_tag_clone(media_tag_h *dst, media_tag_h src)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_src = (media_tag_s*)src;
+       media_tag_s *_src = (media_tag_s *)src;
        media_tag_s *_dst = NULL;
 
-       if ((_src != NULL)) {
-               _dst = (media_tag_s*)calloc(1, sizeof(media_tag_s));
-               content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       content_retip_if_fail(src);
+       content_retip_if_fail(dst);
 
-               _dst->tag_id = _src->tag_id;
+       _dst = (media_tag_s *)calloc(1, sizeof(media_tag_s));
+       content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-               if (STRING_VALID(_src->name)) {
-                       _dst->name = strdup(_src->name);
-                       if (_dst->name == NULL) {
-                               SAFE_FREE(_dst);
-                               content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                               return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-                       }
-               }
-               *dst = (media_tag_h)_dst;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       _dst->tag_id = _src->tag_id;
+       _dst->name = g_strdup(_src->name);
 
-       return ret;
+       *dst = (media_tag_h)_dst;
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_tag_get_tag_id(media_tag_h tag, int *tag_id)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
+       content_retip_if_fail(tag);
+       content_retip_if_fail(tag_id);
 
-       if ((_tag != NULL) && (tag_id != NULL)) {
-               *tag_id = _tag->tag_id;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       *tag_id = _tag->tag_id;
 
-       return ret;
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_tag_get_name(media_tag_h tag, char **name)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
-       if (_tag) {
-               if (STRING_VALID(_tag->name)) {
-                       *name = strdup(_tag->name);
-                       content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-               } else {
-                       *name = NULL;
-               }
-               ret = MEDIA_CONTENT_ERROR_NONE;
+       media_tag_s *_tag = (media_tag_s *)tag;
+       content_retip_if_fail(tag);
+       content_retip_if_fail(name);
 
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       *name = g_strdup(_tag->name);
 
-       return ret;
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_tag_get_tag_from_db(int tag_id, media_tag_h *tag)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
        sqlite3_stmt *stmt = NULL;
-       char select_query[DEFAULT_QUERY_SIZE] = {0, };
-
-       if (tag_id <= 0) {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
-
-       memset(select_query, 0x00, sizeof(select_query));
+       char *query = NULL;
+       media_tag_s *_tag = NULL;
 
-       snprintf(select_query, sizeof(select_query), SELECT_TAG_FROM_TAG, tag_id);
+       content_retipm_if_fail(tag_id > 0, "%d", tag_id);
+       content_retip_if_fail(tag);
 
-       ret = _content_get_result(select_query, &stmt);
+       query = sqlite3_mprintf(SELECT_TAG_FROM_TAG, tag_id);
+       ret = _content_get_result(query, &stmt);
+       SQLITE3_SAFE_FREE(query);
        content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       media_tag_s *_tag = NULL;
-
        if (sqlite3_step(stmt) == SQLITE_ROW) {
-               _tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
+               _tag = (media_tag_s *)calloc(1, sizeof(media_tag_s));
                if (_tag == NULL) {
                        SQLITE3_FINALIZE(stmt);
                        content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
@@ -342,26 +254,19 @@ int media_tag_get_tag_from_db(int tag_id, media_tag_h *tag)
 int media_tag_add_media(media_tag_h tag, const char *media_id)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
+       media_tag_item_s *_item = NULL;
 
-       if ((_tag != NULL) && STRING_VALID(media_id)) {
-               media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s));
-               content_retvm_if(_item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       content_retip_if_fail(tag);
+       content_retip_if_fail(STRING_VALID(media_id));
 
-               _item->media_id = strdup(media_id);
-               _item->function = MEDIA_TAG_ADD;
+       _item = (media_tag_item_s *)calloc(1, sizeof(media_tag_item_s));
+       content_retvm_if(_item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-               if (_item->media_id == NULL) {
-                       SAFE_FREE(_item);
-                       content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
+       _item->media_id = g_strdup(media_id);
+       _item->function = MEDIA_TAG_ADD;
 
-               __media_tag_item_add(_tag, _item);
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       _tag->item_list = g_list_append(_tag->item_list, _item);
 
        return ret;
 }
@@ -369,26 +274,19 @@ int media_tag_add_media(media_tag_h tag, const char *media_id)
 int media_tag_remove_media(media_tag_h tag, const char *media_id)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
+       media_tag_item_s *_item = NULL;
 
-       if (_tag != NULL && STRING_VALID(media_id)) {
-               media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s));
-               content_retvm_if(_item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       content_retip_if_fail(tag);
+       content_retip_if_fail(STRING_VALID(media_id));
 
-               _item->media_id = strdup(media_id);
-               _item->function = MEDIA_TAG_REMOVE;
+       _item = (media_tag_item_s *)calloc(1, sizeof(media_tag_item_s));
+       content_retvm_if(_item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-               if (_item->media_id == NULL) {
-                       SAFE_FREE(_item);
-                       content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
+       _item->media_id = g_strdup(media_id);
+       _item->function = MEDIA_TAG_REMOVE;
 
-               __media_tag_item_add(_tag, _item);
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       _tag->item_list = g_list_append(_tag->item_list, _item);
 
        return ret;
 }
@@ -396,91 +294,67 @@ int media_tag_remove_media(media_tag_h tag, const char *media_id)
 int media_tag_set_name(media_tag_h tag, const char *tag_name)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
+       media_tag_item_s *_item = NULL;
 
-       if (_tag != NULL && STRING_VALID(tag_name)) {
-               SAFE_FREE(_tag->name);
+       content_retip_if_fail(tag);
+       content_retip_if_fail(STRING_VALID(tag_name));
 
-               media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s));
-               content_retvm_if(_item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       SAFE_FREE(_tag->name);
 
-               _item->tag_name = strdup(tag_name);
-               _item->function = MEDIA_TAG_UPDATE_TAG_NAME;
+       _item = (media_tag_item_s *)calloc(1, sizeof(media_tag_item_s));
+       content_retvm_if(_item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-               if (_item->tag_name == NULL) {
-                       SAFE_FREE(_item);
-                       content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
+       _item->tag_name = g_strdup(tag_name);
+       _item->function = MEDIA_TAG_UPDATE_TAG_NAME;
 
-               _tag->name = strdup(tag_name);
-               if (_tag->name == NULL) {
-                       SAFE_FREE(_item->tag_name);
-                       SAFE_FREE(_item);
-                       content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
+       _tag->name = g_strdup(tag_name);
 
-               __media_tag_item_add(_tag, _item);
-       } else {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       _tag->item_list = g_list_append(_tag->item_list, _item);
 
        return ret;
 }
 
-int media_tag_update_to_db(media_tag_h tag)
+void __media_tag_foreach_request(gpointer data, gpointer user_data)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
-       int idx = 0;
-       int length = 0;
-       media_tag_item_s *_tag_item = NULL;
-
-       if (_tag == NULL) {
-               content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       media_tag_item_s *_tag_item = (media_tag_item_s *)data;
+       int tag_id = GPOINTER_TO_INT(user_data);
 
-       if (_tag->item_list != NULL) {
-               length = g_list_length(_tag->item_list);
-       } else {
-               content_debug("operation list length is 0");
-               return MEDIA_CONTENT_ERROR_NONE;
-       }
+       if (!_tag_item)
+               return;
 
-       for (idx = 0; idx < length; idx++) {
-               _tag_item = (media_tag_item_s*)g_list_nth_data(_tag->item_list, idx);
-               if (_tag_item != NULL) {
-                       switch (_tag_item->function) {
-                       case MEDIA_TAG_ADD:
-                       {
-                               ret = __media_tag_insert_item_to_tag(_tag->tag_id, _tag_item->media_id);
-                       }
-                       break;
-
-                       case MEDIA_TAG_REMOVE:
-                       {
-                               ret = __media_tag_remove_item_from_tag(_tag->tag_id, _tag_item->media_id);
-                       }
-                       break;
-
-                       case MEDIA_TAG_UPDATE_TAG_NAME:
-                       {
-                               ret = __media_tag_update_tag_name(_tag->tag_id, _tag_item->tag_name);
-                       }
-                       break;
-
-                       default:
-                       break;
-                       }
-
-                       if (ret != MEDIA_CONTENT_ERROR_NONE)
-                               content_error("Failed some operation[%d]", _tag_item->function);
-               }
+       switch (_tag_item->function) {
+       case MEDIA_TAG_ADD:
+               ret = __media_tag_insert_item_to_tag(tag_id, _tag_item->media_id);
+               break;
+
+       case MEDIA_TAG_REMOVE:
+               ret = __media_tag_remove_item_from_tag(tag_id, _tag_item->media_id);
+               break;
+
+       case MEDIA_TAG_UPDATE_TAG_NAME:
+               ret = __media_tag_update_tag_name(tag_id, _tag_item->tag_name);
+               break;
+
+       default:
+               break;
        }
 
+       if (ret != MEDIA_CONTENT_ERROR_NONE)
+               content_error("Failed some operation[%d]", _tag_item->function);
+}
+
+int media_tag_update_to_db(media_tag_h tag)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       media_tag_s *_tag = (media_tag_s *)tag;
+
+       content_retip_if_fail(tag);
+       content_retvm_if(_tag->item_list == NULL, MEDIA_CONTENT_ERROR_NONE, "operation list length is 0");
+
+       g_list_foreach(_tag->item_list, __media_tag_foreach_request, GINT_TO_POINTER(_tag->tag_id));
+
        ret = media_svc_send_query(_content_get_uid());
 
        __media_tag_item_release(_tag);
@@ -490,11 +364,9 @@ int media_tag_update_to_db(media_tag_h tag)
 
 int media_tag_create(media_tag_h *tag)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       content_retvm_if(tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag");
+       content_retip_if_fail(tag);
 
-       media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
+       media_tag_s *_tag = (media_tag_s *)calloc(1, sizeof(media_tag_s));
        content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        _tag->tag_id = -1;
@@ -503,19 +375,19 @@ int media_tag_create(media_tag_h *tag)
 
        *tag = (media_tag_h)_tag;
 
-       return ret;
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_tag_insert_to_db_v2(media_tag_h tag)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
        media_tag_h tag_1;
        int tag_id = -1;
 
-       content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag");
-       content_retvm_if(!STRING_VALID(_tag->name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag name");
-       content_retvm_if(_tag->tag_id != -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag insert");
+       content_retip_if_fail(tag);
+       content_retip_if_fail(STRING_VALID(_tag->name));
+       content_retip_if_fail(_tag->tag_id == -1);
 
        ret = media_tag_insert_to_db(_tag->name, &tag_1);
        if (ret != MEDIA_CONTENT_ERROR_NONE) {
@@ -542,10 +414,10 @@ ERROR:
 
 int media_tag_update_to_db_v2(int tag_id, media_tag_h tag)
 {
-       media_tag_s *_tag = (media_tag_s*)tag;
+       media_tag_s *_tag = (media_tag_s *)tag;
 
-       content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag");
-       content_retvm_if(tag_id == -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag update");
+       content_retip_if_fail(tag);
+       content_retip_if_fail(tag_id > 0);
 
        _tag->tag_id = tag_id;