#include <media_filter.h>
#include <media_info.h>
#include <media_info_private.h>
-#include <media_playlist.h>
-
-#define PLAYLIST_ARRAY_SIZE 20
-#define PLAYLIST_ARRAY_EXPAND 10
-#define MAX_TMP_STR 2048
-
-static __thread GList *g_playlist_item_list = NULL;
-
-static void __media_playlist_item_add(media_playlist_item_s *item_s);
-static void __media_playlist_item_release(void);
-static int __media_playlist_insert_playlist_record(const char *playlist_name, int *playlist_id);
-static int __media_playlist_insert_item_to_playlist(int playlist_id, const char *media_id);
-static int __media_playlist_remove_item_from_playlist(int playlist_id, int playlist_member_id);
-static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name);
-static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path);
-static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order);
-static int __media_playlist_reset_file(const char* playlist_path);
-static int __media_playlist_append_to_file(const char* playlist_path, const char* path);
-static int __media_playlist_import_item_from_file(const char* playlist_path, char*** const item_list, int* item_count);
-static int __media_playlist_destroy_import_item(char** item_list, int item_count);
-static void __media_playlist_destroy_export_item(gpointer data);
-
-static void __media_playlist_item_add(media_playlist_item_s *item_s)
-{
- g_playlist_item_list = g_list_append(g_playlist_item_list, item_s);
-}
+#include <media_util_private.h>
-static void __media_playlist_item_release(void)
+// LCOV_EXCL_START
+static void __media_playlist_item_free(gpointer item)
{
- int idx = 0;
- int list_cnt = 0;
- media_playlist_item_s *item = NULL;
-
- list_cnt = g_list_length(g_playlist_item_list);
-
- media_content_debug("list_cnt : [%d]", list_cnt);
+ media_playlist_item_s *_item = (media_playlist_item_s *)item;
- for(idx = 0; idx < list_cnt; idx++)
- {
- item = (media_playlist_item_s*)g_list_nth_data(g_playlist_item_list, idx);
- if(item != NULL)
- {
- SAFE_FREE(item->media_id);
- SAFE_FREE(item->playlist_name);
- SAFE_FREE(item->thumbnail_path);
- SAFE_FREE(item);
- }
- }
+ g_free(_item->media_id);
+ g_free(_item->playlist_name);
+ g_free(_item->thumbnail_path);
+ g_free(_item);
+}
- g_list_free(g_playlist_item_list);
- g_playlist_item_list = NULL;
+static void __media_playlist_item_release(media_playlist_s *playlist)
+{
+ if (!playlist || !playlist->item_list)
+ return;
+ g_list_free_full(playlist->item_list, __media_playlist_item_free);
+ playlist->item_list = NULL;
}
static int __media_playlist_insert_playlist_record(const char *playlist_name, int *playlist_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- char *query_str = NULL;
- char *select_query = NULL;
+ char *query = NULL;
sqlite3_stmt *stmt = NULL;
- query_str = sqlite3_mprintf(INSERT_PLAYLIST_TO_PLAYLIST, playlist_name);
+ query = sqlite3_mprintf(INSERT_PLAYLIST_TO_PLAYLIST, playlist_name);
- ret = _content_query_sql(query_str);
- sqlite3_free(query_str);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ ret = _content_query_sql(query);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- select_query = sqlite3_mprintf(SELECT_PLAYLIST_ID_FROM_PLAYLIST, playlist_name);
+ query = sqlite3_mprintf(SELECT_PLAYLIST_ID_FROM_PLAYLIST, playlist_name);
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- sqlite3_free(select_query);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while(sqlite3_step(stmt) == SQLITE_ROW)
- {
- *playlist_id = (int)sqlite3_column_int(stmt,0);
- }
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *playlist_id = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
{
int ret = MEDIA_CONTENT_ERROR_NONE;
sqlite3_stmt *stmt = NULL;
- char select_query[DEFAULT_QUERY_SIZE];
- char *query_str = NULL;
+ char *query = NULL;
int play_order = 0;
- memset(select_query, 0x00, sizeof(select_query));
-
- snprintf(select_query, sizeof(select_query), SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id);
+ query = sqlite3_mprintf(SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id);
/* get the max play_order */
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while(sqlite3_step(stmt) == SQLITE_ROW)
- {
- play_order = (int)sqlite3_column_int(stmt, 0);
- }
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ play_order = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
- ++play_order;
+ query = sqlite3_mprintf(INSERT_PLAYLIST_ITEM_TO_PLAYLIST_MAP, playlist_id, media_id, ++play_order);
+ ret = media_svc_append_query(query, _content_get_uid());
- query_str = sqlite3_mprintf("INSERT INTO %q (playlist_id, media_uuid, play_order) values (%d, '%q', %d)",
- DB_TABLE_PLAYLIST_MAP, playlist_id, media_id, play_order);
- ret = _content_query_sql(query_str);
- sqlite3_free(query_str);
-
- return ret;
+ return _content_error_capi(ret);
}
static int __media_playlist_remove_item_from_playlist(int playlist_id, int playlist_member_id)
char *query_str = NULL;
query_str = sqlite3_mprintf(REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP, playlist_id, playlist_member_id);
+ ret = media_svc_append_query(query_str, _content_get_uid());
- ret = _content_query_sql(query_str);
- sqlite3_free(query_str);
-
- return ret;
+ return _content_error_capi(ret);
}
static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name)
char *query_str = NULL;
query_str = sqlite3_mprintf(UPDATE_PLAYLIST_NAME_FROM_PLAYLIST, playlist_name, playlist_id);
+ ret = media_svc_append_query(query_str, _content_get_uid());
- ret = _content_query_sql(query_str);
- sqlite3_free(query_str);
-
- return ret;
+ return _content_error_capi(ret);
}
static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path)
char *query_str = NULL;
query_str = sqlite3_mprintf(UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST, path, playlist_id);
+ ret = media_svc_append_query(query_str, _content_get_uid());
- ret = _content_query_sql(query_str);
- sqlite3_free(query_str);
-
- return ret;
+ return _content_error_capi(ret);
}
static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order)
char *query_str = NULL;
query_str = sqlite3_mprintf(UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP, play_order, playlist_id, playlist_member_id);
+ ret = media_svc_append_query(query_str, _content_get_uid());
- ret = _content_query_sql(query_str);
- sqlite3_free(query_str);
-
- return ret;
-}
-
-static bool __media_playlist_media_info_cb(media_info_h media, void *user_data)
-{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- char **media_id = (char**)user_data;
- ret = media_info_get_media_id(media, media_id);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- media_content_error("Fail to get file path");
- return FALSE;
- }
- return TRUE;
+ return _content_error_capi(ret);
}
static bool __media_playlist_member_cb(int playlist_member_id, media_info_h media, void *user_data)
char *path = NULL;
ret = media_info_get_file_path(media, &path);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- media_content_error("Fail to get file path");
- return FALSE;
- }
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, FALSE, "media_info_get_file_path fail");
*list = g_list_append(*list, path);
return TRUE;
}
-static int __media_playlist_reset_file(const char* playlist_path)
+static int __media_playlist_reset_file(const char *playlist_path)
{
FILE *fp = NULL;
fp = fopen(playlist_path, "wb");
- if(fp == NULL)
- {
- media_content_stderror("fopen fail");
+ if (fp == NULL) {
+ content_stderror("fopen failed");
return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
}
- fputs("", fp); // remove previous playlist
+ fputs("", fp); /* remove previous playlist */
fclose(fp);
return MEDIA_CONTENT_ERROR_NONE;
}
-static int __media_playlist_append_to_file(const char* playlist_path, const char* path)
+static int __media_playlist_append_to_file(const char *playlist_path, const char *path)
{
FILE *fp = NULL;
- fp = fopen(playlist_path, "a"); // append only
- if(fp == NULL)
- {
- media_content_stderror("fopen fail");
+ fp = fopen(playlist_path, "a"); /* append only */
+ if (fp == NULL) {
+ content_stderror("fopen failed");
return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
}
- fputs(path, fp);
+ fputs(path, fp);
fputs("\n", fp);
fclose(fp);
return MEDIA_CONTENT_ERROR_NONE;
}
-static int __media_playlist_import_item_from_file(const char* playlist_path, char*** const item_list, int* item_count)
+static int __media_playlist_import_item_from_file(const char *playlist_path, GSList **item_list)
{
- int current_index = 0; // Current record number
- int current_max_size = PLAYLIST_ARRAY_SIZE; // Current max number of records in array
- int tmp_str_len = 0; // Length of the string
- char *buf = NULL;
- char *tmp_buf = NULL;
- char *tmp_str = NULL; // Next line from buffer, this string is used for parsing
-
+ int tmp_str_len = 0;
+ char tmp_str[MAX_PATH_LEN] = {0, };
FILE *fp = NULL;
- long int file_size = 0;
-
- *item_list = NULL; *item_count = 0;
- fp = fopen(playlist_path, "rb"); // Open as binary for precise estimation of file length
- if(fp == NULL)
- {
- media_content_stderror("fopen fail");
+ fp = fopen(playlist_path, "rb");
+ if (fp == NULL) {
+ content_stderror("fopen failed");
return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
}
- fseek(fp, 0, SEEK_END); // Move to the end of file
- file_size = ftell(fp); // Here we can find the size of file
- fseek(fp, 0 , SEEK_SET); // Return to the beginning of file
+ while (fgets(tmp_str, MAX_PATH_LEN, fp) != NULL) {
+ tmp_str_len = strlen(tmp_str);
+ /* Check for empty file */
+ if (tmp_str_len <= 1)
+ continue;
- if(file_size == 0) {
- media_content_debug("file is empty.");
- fclose(fp);
- return MEDIA_CONTENT_ERROR_NONE;
- }
- // Allocate the memory and copy file content there
- if(file_size > 0)
- buf = malloc(file_size + 1);
-
- if(buf == NULL)
- {
- media_content_error("Out of Memory");
- fclose(fp);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ if (tmp_str[0] == '#')
+ continue;
- tmp_buf = buf;
- if(fread(buf, file_size, 1, fp) != 1) {
- fclose(fp);
- SAFE_FREE(buf);
- media_content_stderror("fread fail");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
- }
- buf[file_size] = 0;
- fclose(fp);
+ if (tmp_str[tmp_str_len - 1] == '\n')
+ tmp_str[tmp_str_len - 1] = '\0';
- // Preliminary memory allocation
- *item_list = calloc(current_max_size, sizeof(char*));
- tmp_str = malloc(MAX_TMP_STR);
- if (tmp_str == NULL || *item_list == NULL) {
- SAFE_FREE(*item_list);
- SAFE_FREE(buf);
- SAFE_FREE(tmp_str);
- media_content_error("Out of Memory");
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
+ *item_list = g_slist_append(*item_list, g_strdup(tmp_str));
}
- // Here we create format string for sscanf(...) that allows to get a line from buffer
- char format[25];
- snprintf(format, 25, "%%%d[^\n]", MAX_TMP_STR);
-
- // This cycle gets lines one by one from buffer till the end of buffer. Empty line ("\n") must be treated specifically
- while((sscanf(tmp_buf, format, tmp_str) == 1) || (*tmp_buf == '\n')) {
- if(*tmp_buf == '\n') {// Check if there is an empty line, skip '\n' symbol
- tmp_buf += 1;
-
- if(tmp_buf < (buf + file_size))
- continue; // We are still in buffer
- else
- break; // Empty line was in the end of buffer
- }
- tmp_str_len = strlen(tmp_str); // Save the length of line
-
- if(tmp_str[0] != '#') { // Check that the line is not a comment
- if(!(current_index < (current_max_size - 1))) { // Check if we have completely filled record array
- // Expand array size and relocate the array (records will be copied into new one)
- current_max_size += PLAYLIST_ARRAY_EXPAND;
- char **tmp_ptr = calloc(current_max_size, sizeof(char*));
- if (tmp_ptr == NULL) {
- __media_playlist_destroy_import_item(*item_list, current_index);
- SAFE_FREE(buf);
- SAFE_FREE(tmp_str);
- media_content_error("Out of Memory");
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- memmove(tmp_ptr, *item_list, sizeof(char*) * current_index);
- SAFE_FREE(*item_list);
- *item_list = tmp_ptr;
- }
-
- // Save new file path (current string in tmp_str)
- (*item_list)[current_index] = malloc(tmp_str_len + 1);
- if ((*item_list)[current_index] == NULL) {
- __media_playlist_destroy_import_item(*item_list, current_index);
- SAFE_FREE(buf);
- SAFE_FREE(tmp_str);
- media_content_error("Out of Memory");
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- memmove((*item_list)[current_index], tmp_str, tmp_str_len + 1);
-
- // Increase the index of buffer
- current_index += 1;
- }
-
- tmp_buf += (tmp_str_len + 1); // Move position in buffer after the string that was parsed
- }
-
- *item_count = current_index; // Now we need to save the number of records in array
-
- SAFE_FREE(buf);
- SAFE_FREE(tmp_str); // Free temporary variables
-
- return MEDIA_CONTENT_ERROR_NONE;
-}
-
-static int __media_playlist_destroy_import_item(char** item_list, int item_count)
-{
- int i;
-
- for(i = 0; i < item_count; ++i) {
- SAFE_FREE(item_list[i]);
- item_list[i] = NULL;
- }
-
- if (item_list != NULL) {
- SAFE_FREE(item_list);
- item_list = NULL;
- }
+ fclose(fp);
return MEDIA_CONTENT_ERROR_NONE;
}
-static void __media_playlist_destroy_export_item(gpointer data)
-{
- SAFE_FREE(data);
- data = NULL;
-}
-
int media_playlist_insert_to_db(const char *name, media_playlist_h *playlist)
{
+ content_warn("DEPRECATION WARNING: media_playlist_insert_to_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
int playlist_id = 0;
- if(!STRING_VALID(name))
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(STRING_VALID(name));
+ content_retip_if_fail(playlist);
- media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
- if(_playlist == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ media_playlist_s *_playlist = g_new0(media_playlist_s, 1);
ret = __media_playlist_insert_playlist_record(name, &playlist_id);
-
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- SAFE_FREE(_playlist);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ g_free(_playlist);
return ret;
}
_playlist->playlist_id = playlist_id;
- _playlist->name = strdup(name);
-
- if(_playlist->name == NULL)
- {
- SAFE_FREE(_playlist);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ _playlist->name = g_strdup(name);
*playlist = (media_playlist_h)_playlist;
int media_playlist_delete_from_db(int playlist_id)
{
+ content_warn("DEPRECATION WARNING: media_playlist_delete_from_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
char *query_str = NULL;
- if(playlist_id < 0)
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retipm_if_fail(playlist_id >= 0, "%d", playlist_id);
query_str = sqlite3_mprintf(DELETE_PLAYLIST_FROM_PLAYLIST, playlist_id);
ret = _content_query_sql(query_str);
-
- sqlite3_free(query_str);
+ SQLITE3_SAFE_FREE(query_str);
return ret;
}
int media_playlist_get_playlist_count_from_db(filter_h filter, int *playlist_count)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ content_warn("DEPRECATION WARNING: media_playlist_get_playlist_count_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(playlist_count);
- if(playlist_count != NULL)
- {
- ret = _media_db_get_group_count(filter, MEDIA_GROUP_PLAYLIST, playlist_count);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- return ret;
+ return _media_db_get_group_count(filter, MEDIA_GROUP_PLAYLIST, playlist_count);
}
int media_playlist_foreach_playlist_from_db(filter_h filter, media_playlist_cb callback, void *user_data)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- if(callback == NULL)
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- ret = _media_db_get_playlist(filter, callback, user_data);
+ content_warn("DEPRECATION WARNING: media_playlist_foreach_playlist_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(callback);
- return ret;
+ return _media_db_get_playlist(filter, callback, user_data);
}
int media_playlist_get_media_count_from_db(int playlist_id, filter_h filter, int *media_count)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ content_warn("DEPRECATION WARNING: media_playlist_get_media_count_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(media_count);
+ content_retipm_if_fail(playlist_id > 0, "%d", playlist_id);
- if((playlist_id > 0) && (media_count != NULL))
- {
- ret = _media_db_get_group_item_count_by_id(playlist_id, filter, MEDIA_GROUP_PLAYLIST, media_count);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- return ret;
+ return _media_db_get_group_item_count_by_id(playlist_id, filter, MEDIA_GROUP_PLAYLIST, media_count);
}
int media_playlist_foreach_media_from_db(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- if((playlist_id > 0) && (callback != NULL))
- {
- ret = _media_db_get_playlist_item(playlist_id, filter, callback, user_data);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_foreach_media_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(callback);
+ content_retipm_if_fail(playlist_id > 0, "%d", playlist_id);
- return ret;
+ return _media_db_get_playlist_item(playlist_id, filter, callback, user_data);
}
int media_playlist_destroy(media_playlist_h playlist)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_destroy() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- if(_playlist)
- {
- SAFE_FREE(_playlist->name);
- SAFE_FREE(_playlist->thumbnail_path);
- SAFE_FREE(_playlist);
+ content_retip_if_fail(playlist);
- ret = MEDIA_CONTENT_ERROR_NONE;
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ __media_playlist_item_release(_playlist);
- return ret;
+ g_free(_playlist->name);
+ g_free(_playlist->thumbnail_path);
+ g_free(_playlist);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_clone(media_playlist_h *dst, media_playlist_h src)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_src = (media_playlist_s*)src;
-
- if(_src != NULL)
- {
- media_playlist_s *_dst = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
- if(_dst == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_clone() is deprecated and will be removed from next release.");
+ media_playlist_s *_src = (media_playlist_s *)src;
- _dst->playlist_id = _src->playlist_id;
-
- if(STRING_VALID(_src->name))
- {
- _dst->name = strdup(_src->name);
- if(_dst->name == NULL)
- {
- media_playlist_destroy((media_playlist_h)_dst);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
+ content_retip_if_fail(dst);
+ content_retip_if_fail(src);
- *dst = (media_playlist_h)_dst;
+ media_playlist_s *_dst = g_new0(media_playlist_s, 1);
- ret = MEDIA_CONTENT_ERROR_NONE;
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ _dst->playlist_id = _src->playlist_id;
+ _dst->name = g_strdup(_src->name);
- return ret;
+ *dst = (media_playlist_h)_dst;
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playlist)
{
+ content_warn("DEPRECATION WARNING: media_playlist_get_playlist_from_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
sqlite3_stmt *stmt = NULL;
- char select_query[DEFAULT_QUERY_SIZE];
-
- if(playlist_id > 0)
- {
- memset(select_query, 0x00, sizeof(select_query));
-
- snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_FROM_PLAYLIST, playlist_id);
-
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
-
- while(sqlite3_step(stmt) == SQLITE_ROW)
- {
- media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
- if(_playlist == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- SQLITE3_FINALIZE(stmt);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
-
- _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0);
- if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
- _playlist->name = strdup((const char *)sqlite3_column_text(stmt, 1));
- if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3)))
- _playlist->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 3));
-
- *playlist = (media_playlist_h)_playlist;
- }
+ char *query = NULL;
- SQLITE3_FINALIZE(stmt);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ content_retipm_if_fail(playlist_id > 0, "%d", playlist_id);
+ content_retip_if_fail(playlist);
+
+ query = sqlite3_mprintf(SELECT_PLAYLIST_FROM_PLAYLIST, playlist_id);
+
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+ media_playlist_s *_playlist = NULL;
+
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
+ _playlist = g_new0(media_playlist_s, 1);
+
+ _playlist->playlist_id = playlist_id;
+ _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
+ _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
+
+ *playlist = (media_playlist_h)_playlist;
+ } else {
+ content_error("Nonexistent playlist id[%d]", playlist_id);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
+ SQLITE3_FINALIZE(stmt);
+
return ret;
}
int media_playlist_get_playlist_id(media_playlist_h playlist, int *playlist_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ content_warn("DEPRECATION WARNING: media_playlist_get_playlist_id() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(playlist_id);
- if((_playlist != NULL) && (playlist_id != NULL))
- {
- *playlist_id = _playlist->playlist_id;
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ *playlist_id = _playlist->playlist_id;
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_name(media_playlist_h playlist, char **name)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- if(_playlist)
- {
- if(STRING_VALID(_playlist->name))
- {
- *name = strdup(_playlist->name);
- if(*name == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
- else
- {
- *name = NULL;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_get_name() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- ret = MEDIA_CONTENT_ERROR_NONE;
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(name);
- return ret;
+ *name = g_strdup(_playlist->name);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_thumbnail_path(media_playlist_h playlist, char **path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- if(_playlist)
- {
- if(STRING_VALID(_playlist->thumbnail_path))
- {
- *path = strdup(_playlist->thumbnail_path);
- if(*path == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
- else
- {
- *path = NULL;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_get_thumbnail_path() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- ret = MEDIA_CONTENT_ERROR_NONE;
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(path);
- return ret;
+ *path = g_strdup(_playlist->thumbnail_path);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_play_order(media_playlist_h playlist, int playlist_member_id, int *play_order)
{
+ content_warn("DEPRECATION WARNING: media_playlist_get_play_order() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- int playlist_id = 0;
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
sqlite3_stmt *stmt = NULL;
- char select_query[DEFAULT_QUERY_SIZE];
-
- if((_playlist == NULL) || (playlist_member_id < 0) || (play_order == NULL))
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- playlist_id = _playlist->playlist_id;
+ char *query = NULL;
- memset(select_query, 0x00, sizeof(select_query));
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(playlist_member_id >= 0, "%d", playlist_member_id);
+ content_retip_if_fail(play_order);
- snprintf(select_query, sizeof(select_query), SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id, playlist_member_id);
+ query = sqlite3_mprintf(SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, _playlist->playlist_id, playlist_member_id);
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
-
- while(sqlite3_step(stmt) == SQLITE_ROW)
- {
- *play_order = (int)sqlite3_column_int(stmt, 0);
- }
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *play_order = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_set_name() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- if(_playlist != NULL && STRING_VALID(playlist_name))
- {
- SAFE_FREE(_playlist->name);
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(STRING_VALID(playlist_name));
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- if(item == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ g_free(_playlist->name);
- item->playlist_name = strdup(playlist_name);
- item->function = MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME;
- if(item->playlist_name == NULL)
- {
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item = g_new0(media_playlist_item_s, 1);
- _playlist->name = strdup(playlist_name);
- if(_playlist->name == NULL)
- {
- SAFE_FREE(item->playlist_name);
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item->playlist_name = g_strdup(playlist_name);
+ item->function = MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME;
- __media_playlist_item_add(item);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ _playlist->name = g_strdup(playlist_name);
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_set_thumbnail_path() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- if(_playlist != NULL && STRING_VALID(path))
- {
- SAFE_FREE(_playlist->thumbnail_path);
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(STRING_VALID(path));
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- if(item == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ g_free(_playlist->thumbnail_path);
- item->thumbnail_path = strdup(path);
- item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH;
- if(item->thumbnail_path == NULL)
- {
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item = g_new0(media_playlist_item_s, 1);
- _playlist->thumbnail_path = strdup(path);
- if(_playlist->thumbnail_path == NULL)
- {
- SAFE_FREE(item->thumbnail_path);
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item->thumbnail_path = g_strdup(path);
+ item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH;
- __media_playlist_item_add(item);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ _playlist->thumbnail_path = g_strdup(path);
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member_id, int play_order)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
-
- if((_playlist != NULL) && (playlist_member_id > 0) && (play_order >= 0))
- {
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- if(item == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_set_play_order() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- item->playlist_member_id = playlist_member_id;
- item->function = MEDIA_PLAYLIST_UPDATE_PLAY_ORDER;
- item->play_order = play_order;
+ 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_add(item);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ item = g_new0(media_playlist_item_s, 1);
- return ret;
+ item->playlist_member_id = playlist_member_id;
+ item->function = MEDIA_PLAYLIST_UPDATE_PLAY_ORDER;
+ item->play_order = play_order;
+
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_add_media(media_playlist_h playlist, const char *media_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
-
- if(_playlist != NULL && STRING_VALID(media_id))
- {
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- if(item == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_add_media() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- item->media_id = strdup(media_id);
- item->function = MEDIA_PLAYLIST_ADD;
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(STRING_VALID(media_id));
- if(item->media_id == NULL)
- {
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item = g_new0(media_playlist_item_s, 1);
- __media_playlist_item_add(item);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ item->media_id = g_strdup(media_id);
+ item->function = MEDIA_PLAYLIST_ADD;
- return ret;
-}
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
+ return MEDIA_CONTENT_ERROR_NONE;
+}
int media_playlist_remove_media(media_playlist_h playlist, int playlist_member_id)
{
+ content_warn("DEPRECATION WARNING: media_playlist_remove_media() is deprecated and will be removed from next release.");
+ 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);
+
+ item = g_new0(media_playlist_item_s, 1);
+
+ item->playlist_member_id = playlist_member_id;
+ item->function = MEDIA_PLAYLIST_REMOVE;
+
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
+void __media_playlist_foreach_request(gpointer data, gpointer user_data)
+{
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
-
- if((_playlist != NULL) && (playlist_member_id > 0))
- {
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- if(item == NULL)
- {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ media_playlist_item_s *_playlist_item = (media_playlist_item_s *)data;
+ int playlist_id = *((int *)user_data);
- item->playlist_member_id = playlist_member_id;
- item->function = MEDIA_PLAYLIST_REMOVE;
+ if (!_playlist_item)
+ return;
- __media_playlist_item_add(item);
- }
- else
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ switch (_playlist_item->function) {
+ case MEDIA_PLAYLIST_ADD:
+ ret = __media_playlist_insert_item_to_playlist(playlist_id, _playlist_item->media_id);
+ break;
+
+ case MEDIA_PLAYLIST_REMOVE:
+ ret = __media_playlist_remove_item_from_playlist(playlist_id, _playlist_item->playlist_member_id);
+ break;
+
+ case MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME:
+ ret = __media_playlist_update_playlist_name(playlist_id, _playlist_item->playlist_name);
+ break;
+
+ case MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH:
+ ret = __media_playlist_update_thumbnail_path(playlist_id, _playlist_item->thumbnail_path);
+ break;
+
+ case MEDIA_PLAYLIST_UPDATE_PLAY_ORDER:
+ ret = __media_playlist_update_play_order(playlist_id, _playlist_item->playlist_member_id, _playlist_item->play_order);
+ break;
+
+ default:
+ break;
}
- return ret;
+ if (ret != MEDIA_CONTENT_ERROR_NONE)
+ content_error("Failed some operation[%d]", _playlist_item->function);
}
int media_playlist_update_to_db(media_playlist_h playlist)
{
+ content_warn("DEPRECATION WARNING: media_playlist_update_to_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- int idx = 0;
- int length = 0;
- media_playlist_item_s *_playlist_item = NULL;
-
- if(_playlist == NULL)
- {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- length = g_list_length(g_playlist_item_list);
-
- for (idx = 0; idx < length; idx++) {
- _playlist_item = (media_playlist_item_s*)g_list_nth_data(g_playlist_item_list, idx);
- if(_playlist_item != NULL) {
- switch(_playlist_item->function) {
- case MEDIA_PLAYLIST_ADD:
- {
- ret = __media_playlist_insert_item_to_playlist(_playlist->playlist_id, _playlist_item->media_id);
- }
- break;
-
- case MEDIA_PLAYLIST_REMOVE:
- {
- ret = __media_playlist_remove_item_from_playlist(_playlist->playlist_id, _playlist_item->playlist_member_id);
- }
- break;
-
- case MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME:
- {
- ret = __media_playlist_update_playlist_name(_playlist->playlist_id, _playlist_item->playlist_name);
- }
- break;
-
- case MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH:
- {
- ret = __media_playlist_update_thumbnail_path(_playlist->playlist_id, _playlist_item->thumbnail_path);
- }
- break;
-
- case MEDIA_PLAYLIST_UPDATE_PLAY_ORDER:
- {
- ret = __media_playlist_update_play_order(_playlist->playlist_id, _playlist_item->playlist_member_id, _playlist_item->play_order);
- }
- break;
- }
- }
- }
+ content_retip_if_fail(playlist);
+ content_retvm_if(!_playlist->item_list, MEDIA_CONTENT_ERROR_NONE, "operation list length is 0");
+
+ g_list_foreach(_playlist->item_list, __media_playlist_foreach_request, &(_playlist->playlist_id));
+
+ ret = media_svc_send_query(_content_get_uid());
+
+ __media_playlist_item_release(_playlist);
+
+ return _content_error_capi(ret);
+}
+
+static int __media_playlist_get_media_id_by_path(const char *path, char **media_id)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char *query = NULL;
+ sqlite3_stmt *stmt = NULL;
- __media_playlist_item_release();
+ content_retip_if_fail(path);
+ content_retip_if_fail(media_id);
+
+#ifdef _USE_TVPD_MODE
+ query = sqlite3_mprintf("SELECT media_id FROM '%q' WHERE media_path='%q'", DB_VIEW_MEDIA, path);
+#else
+ query = sqlite3_mprintf("SELECT media_id FROM '%q' WHERE media_path='%q'", DB_TABLE_MEDIA, path);
+#endif
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Failed to get media_id");
+
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *media_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
+
+ SQLITE3_FINALIZE(stmt);
return ret;
}
-int media_playlist_import_from_file(const char *path, const char *playlist_name, media_playlist_h *playlist)
+static void __media_playlist_foreach_item(gpointer item, gpointer user_data)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- char** import_item_list = NULL;
- int import_item_count = 0;
- int idx;
-
- if(!STRING_VALID(path))
- {
- media_content_error("Invalid path");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ char *path = (char *)item;
+ media_playlist_h *playlist = (media_playlist_h *)user_data;
+ char *media_id = NULL;
- if(!STRING_VALID(playlist_name))
- {
- media_content_error("Invalid playlist_name");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ ret = __media_playlist_get_media_id_by_path(path, &media_id);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ content_sec_error("Fail to get media_id [%s]", path);
+ return;
}
- ret = media_playlist_insert_to_db(playlist_name, playlist);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- media_content_error("Fail to insert playlist to db");
- return ret;
+ ret = media_playlist_add_media(*playlist, media_id);
+ g_free(media_id);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ content_sec_error("Fail to add media [%s]", path);
+ return;
}
+}
- ret = __media_playlist_import_item_from_file(path, &import_item_list, &import_item_count);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_content_error("Fail to get playlist from file");
- return ret;
- }
+int media_playlist_import_from_file(const char *path, const char *playlist_name, media_playlist_h *playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_import_from_file() is deprecated and will be removed from next release.");
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ GSList *item_list = NULL;
- if (import_item_count == 0)
- {
- media_content_debug("The playlist from file is empty");
- }
+ content_retip_if_fail(STRING_VALID(path));
+ content_retip_if_fail(STRING_VALID(playlist_name));
- for (idx=0; idx < import_item_count; idx++)
- {
- filter_h filter = NULL;
- char *media_id = NULL;
- char *condition = NULL;
-
- ret = media_filter_create(&filter);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- media_content_error("error media_filter_create");
- return ret;
- }
- condition = sqlite3_mprintf("path = '%q'", import_item_list[idx]);
- ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- sqlite3_free(condition);
- media_content_error("error media_filter_set_condition");
- return ret;
- }
- ret = _media_db_get_group_item(NULL, filter, __media_playlist_media_info_cb, &media_id, MEDIA_GROUP_NONE);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- SAFE_FREE(media_id);
- sqlite3_free(condition);
- media_content_error("error media_info_foreach_media_from_db");
- return ret;
- }
- ret = media_playlist_add_media((media_playlist_h)*playlist, media_id);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- SAFE_FREE(media_id);
- sqlite3_free(condition);
- media_content_error("error media_playlist_add_media");
- return ret;
- }
- media_filter_destroy(filter);
- SAFE_FREE(media_id);
- sqlite3_free(condition);
- }
+ ret = media_playlist_insert_to_db(playlist_name, playlist);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_playlist_insert_to_db fail");
+
+ ret = __media_playlist_import_item_from_file(path, &item_list);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Fail to get playlist from file");
+
+ g_slist_foreach(item_list, __media_playlist_foreach_item, playlist);
ret = media_playlist_update_to_db(*playlist);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_content_error("Fail to update playlist to db");
- return ret;
- }
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
+ g_slist_free_full(item_list, g_free);
return ret;
}
-int media_playlist_export_to_file(media_playlist_h playlist, const char* path)
+int media_playlist_export_to_file(media_playlist_h playlist, const char *path)
{
+ content_warn("DEPRECATION WARNING: media_playlist_export_to_file() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
GList *item_list = NULL;
- int idx;
-
- if(!STRING_VALID(path))
- {
- media_content_error("Invalid path");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- if(_playlist == NULL)
- {
- media_content_error("Invalid playlist");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ GList *iter = NULL;
+ char *item = NULL;
- if(_playlist->playlist_id <= 0)
- {
- media_content_error("Invalid playlist id");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(STRING_VALID(path));
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(_playlist->playlist_id > 0, "%d", _playlist->playlist_id);
ret = _media_db_get_playlist_item(_playlist->playlist_id, NULL, __media_playlist_member_cb, &item_list);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- media_content_error("Fail to get playlist from db");
- return ret;
- }
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_db_get_playlist_item fail");
ret = __media_playlist_reset_file(path);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- g_list_free_full(item_list, __media_playlist_destroy_export_item);
- media_content_error("Fail to init playlist file");
- return ret;
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ content_error("Fail to init playlist file");
+ goto FINALIZE;
}
- for (idx=0; idx < g_list_length(item_list); idx++)
- {
- char *item = g_list_nth_data(item_list, idx);
+ for (iter = item_list; iter; iter = g_list_next(iter)) {
+ item = (char *)iter->data;
+ if (!STRING_VALID(item))
+ continue;
+
ret = __media_playlist_append_to_file(path, item);
- if(ret != MEDIA_CONTENT_ERROR_NONE)
- {
- g_list_free_full(item_list, __media_playlist_destroy_export_item);
- media_content_error("Fail to export paths into file");
- return ret;
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ content_error("Fail to export paths into file");
+ goto FINALIZE;
}
}
- g_list_free_full(item_list, __media_playlist_destroy_export_item);
+FINALIZE:
+ g_list_free_full(item_list, g_free);
+
+ return ret;
+}
+
+int media_playlist_create(media_playlist_h *playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_create() is deprecated and will be removed from next release.");
+ content_retip_if_fail(playlist);
+
+ media_playlist_s *_playlist = g_new0(media_playlist_s, 1);
+
+ _playlist->playlist_id = -1;
+ _playlist->name = NULL;
+ _playlist->thumbnail_path = NULL;
+ _playlist->item_list = NULL;
+
+ *playlist = (media_playlist_h)_playlist;
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
+int media_playlist_get_play_order_v2(int playlist_id, int playlist_member_id, int *play_order)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_get_play_order_v2() is deprecated and will be removed from next release.");
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ sqlite3_stmt *stmt = NULL;
+ char *query = NULL;
+
+ content_retipm_if_fail(playlist_id >= 0, "%d", playlist_id);
+ content_retipm_if_fail(playlist_member_id >= 0, "%d", playlist_member_id);
+ content_retip_if_fail(play_order);
+
+ query = sqlite3_mprintf(SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id, playlist_member_id);
+
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *play_order = sqlite3_column_int(stmt, 0);
+
+ SQLITE3_FINALIZE(stmt);
return ret;
}
+
+int media_playlist_insert_to_db_v2(media_playlist_h playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_insert_to_db_v2() is deprecated and will be removed from next release.");
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ int playlist_id = 0;
+
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(_playlist->playlist_id == -1, "%d", _playlist->playlist_id);
+
+ ret = __media_playlist_insert_playlist_record(_playlist->name, &playlist_id);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ __media_playlist_item_release(_playlist);
+ content_error("Insert playlist Fail");
+ return ret;
+ }
+
+ _playlist->playlist_id = playlist_id;
+
+ return media_playlist_update_to_db(playlist);
+}
+
+int media_playlist_update_to_db_v2(int playlist_id, media_playlist_h playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_update_to_db_v2() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ content_retip_if_fail(playlist);
+
+ _playlist->playlist_id = playlist_id;
+
+ return media_playlist_update_to_db(playlist);
+}
+// LCOV_EXCL_STOP