#include <media_info_private.h>
-static int __media_bookmark_check_media_id(const char *media_id);
-
static int __media_bookmark_check_media_id(const char *media_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
sqlite3_stmt *stmt = NULL;
int item_count = 0;
- media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
+ content_retip_if_fail(STRING_VALID(media_id));
query_str = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID, media_id);
- ret = _content_query_prepare(&stmt, query_str, NULL, NULL);
+ ret = _content_get_result(query_str, &stmt);
SQLITE3_SAFE_FREE(query_str);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while (sqlite3_step(stmt) == SQLITE_ROW)
+ if (sqlite3_step(stmt) == SQLITE_ROW)
item_count = (int)sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
- media_content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
+ content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
return MEDIA_CONTENT_ERROR_NONE;
}
int ret = MEDIA_CONTENT_ERROR_NONE;
char *sql = NULL;
- if (STRING_VALID(media_id)) {
- sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, MEDIA_CONTENT_EMPTY_STRING);
- ret = _content_query_sql(sql);
- SQLITE3_SAFE_FREE(sql);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(STRING_VALID(media_id));
+
+ sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, MEDIA_CONTENT_EMPTY_STRING);
+ ret = _content_query_sql(sql);
+ SQLITE3_SAFE_FREE(sql);
return ret;
}
int ret = MEDIA_CONTENT_ERROR_NONE;
char *query_str = NULL;
- if (bookmark_id < 0) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(bookmark_id >= 0);
query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);
-
ret = _content_query_sql(query_str);
-
SQLITE3_SAFE_FREE(query_str);
return ret;
int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ content_retip_if_fail(bookmark_count);
- if (bookmark_count == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- ret = _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
-
- return ret;
+ return _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
}
int media_bookmark_foreach_bookmark_from_db(filter_h filter, media_bookmark_cb callback, void *user_data)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ content_retip_if_fail(callback);
- media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid paramter");
-
- ret = _media_db_get_bookmark(NULL, filter, callback, user_data);
-
- return ret;
+ return _media_db_get_bookmark(NULL, filter, callback, user_data);
}
int media_bookmark_destroy(media_bookmark_h bookmark)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
-
- if (_bookmark) {
- SAFE_FREE(_bookmark->media_id);
- SAFE_FREE(_bookmark->thumbnail_path);
- SAFE_FREE(_bookmark->name);
- SAFE_FREE(_bookmark);
- 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_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- return ret;
+ content_retip_if_fail(bookmark);
+
+ g_free(_bookmark->media_id);
+ g_free(_bookmark->thumbnail_path);
+ g_free(_bookmark->name);
+ g_free(_bookmark);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_bookmark_s *_src = (media_bookmark_s *)src;
- if ((src != NULL)) {
- media_bookmark_s *_src = (media_bookmark_s*)src;
- media_bookmark_s *_dst = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
- media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
- _dst->bookmark_id = _src->bookmark_id;
-
- if (STRING_VALID(_src->media_id)) {
- _dst->media_id = (char *)strdup(_src->media_id);
- if (_dst->media_id == NULL) {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- media_bookmark_destroy((media_bookmark_h)_dst);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
-
- _dst->marked_time = _src->marked_time;
-
- if (STRING_VALID(_src->thumbnail_path)) {
- _dst->thumbnail_path = (char*)strdup(_src->thumbnail_path);
- if (_dst->thumbnail_path == NULL) {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- media_bookmark_destroy((media_bookmark_h)_dst);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
-
- if (STRING_VALID(_src->name)) {
- _dst->name = (char*)strdup(_src->name);
- if (_dst->name == NULL) {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- media_bookmark_destroy((media_bookmark_h)_dst);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
-
- *dst = (media_bookmark_h)_dst;
-
- 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(dst);
+ content_retip_if_fail(src);
- return ret;
+ media_bookmark_s *_dst = g_new0(media_bookmark_s, 1);
+
+ _dst->bookmark_id = _src->bookmark_id;
+ _dst->media_id = g_strdup(_src->media_id);
+ _dst->marked_time = _src->marked_time;
+ _dst->thumbnail_path = g_strdup(_src->thumbnail_path);
+ _dst->name = g_strdup(_src->name);
+
+ *dst = (media_bookmark_h)_dst;
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- if (_bookmark) {
- *bookmark_id = _bookmark->bookmark_id;
- 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(bookmark);
+ content_retip_if_fail(bookmark_id);
- return ret;
+ *bookmark_id = _bookmark->bookmark_id;
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- if (_bookmark) {
- *marked_time = _bookmark->marked_time;
- 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(bookmark);
+ content_retip_if_fail(marked_time);
- return ret;
+ *marked_time = _bookmark->marked_time;
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
-
- if (_bookmark) {
- if (STRING_VALID(_bookmark->thumbnail_path)) {
- *path = strdup(_bookmark->thumbnail_path);
- media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
- *path = NULL;
- }
-
- 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_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- return ret;
+ content_retip_if_fail(bookmark);
+ content_retip_if_fail(path);
+
+ *path = g_strdup(_bookmark->thumbnail_path);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_get_name(media_bookmark_h bookmark, char **name)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- if (_bookmark) {
- *name = g_strdup(_bookmark->name);
- media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(bookmark);
+ content_retip_if_fail(name);
- return ret;
+ *name = g_strdup(_bookmark->name);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_set_name(media_bookmark_h bookmark, const char *name)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- if (_bookmark != NULL) {
- if (STRING_VALID(name))
- _bookmark->name = g_strdup(name);
- else
- _bookmark->name = g_strdup(MEDIA_CONTENT_EMPTY_STRING);
+ content_retip_if_fail(bookmark);
- media_content_retvm_if(_bookmark->name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ g_free(_bookmark->name);
+ _bookmark->name = g_strdup(STRING_VALID(name) ? name : MEDIA_CONTENT_EMPTY_STRING);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_update_to_db(media_bookmark_h bookmark)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
char *sql = NULL;
- if (_bookmark != NULL) {
- sql = sqlite3_mprintf(UPDATE_BOOKMARK_FROM_BOOKMARK, _bookmark->name, _bookmark->bookmark_id);
- ret = _content_query_sql(sql);
- SQLITE3_SAFE_FREE(sql);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(bookmark);
+
+ sql = sqlite3_mprintf(UPDATE_BOOKMARK_FROM_BOOKMARK, _bookmark->name, _bookmark->bookmark_id);
+ ret = _content_query_sql(sql);
+ SQLITE3_SAFE_FREE(sql);
return ret;
}
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
- media_content_retvm_if(bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
+ content_retip_if_fail(bookmark);
ret = __media_bookmark_check_media_id(media_id);
- media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Not exist media_id");
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Not exist media_id");
- media_bookmark_s *_bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
- media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ media_bookmark_s *_bookmark = g_new0(media_bookmark_s, 1);
_bookmark->media_id = g_strdup(media_id);
- if (!STRING_VALID(_bookmark->media_id)) {
- media_content_error("MEDIA_CONTENT_ERROR_OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- SAFE_FREE(_bookmark->media_id);
- SAFE_FREE(_bookmark);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
-
_bookmark->bookmark_id = -1;
_bookmark->marked_time = time;
int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
-
- media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
- if (STRING_VALID(path))
- _bookmark->thumbnail_path = g_strdup(path);
- else
- _bookmark->thumbnail_path = g_strdup(MEDIA_CONTENT_EMPTY_STRING);
+ content_retip_if_fail(bookmark);
- media_content_retvm_if(_bookmark->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ g_free(_bookmark->thumbnail_path);
+ _bookmark->thumbnail_path = g_strdup(path);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
char *sql = NULL;
- char *select_query = NULL;
sqlite3_stmt *stmt = NULL;
int bookmark_id = -1;
- media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
- media_content_retvm_if(_bookmark->bookmark_id != -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark insert");
+ content_retip_if_fail(bookmark);
+ content_retip_if_fail(_bookmark->bookmark_id == -1);
+
+ sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK,
+ _bookmark->media_id, _bookmark->marked_time, _bookmark->thumbnail_path, _bookmark->name);
- sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, _bookmark->media_id, _bookmark->marked_time, _bookmark->thumbnail_path, _bookmark->name);
ret = _content_query_sql(sql);
SQLITE3_SAFE_FREE(sql);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
-
- select_query = sqlite3_mprintf(SELECT_BOOKMARK_ID_FROM_BOOKMARK, _bookmark->media_id, _bookmark->marked_time);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- SQLITE3_SAFE_FREE(select_query);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ sql = sqlite3_mprintf(SELECT_BOOKMARK_ID_FROM_BOOKMARK, _bookmark->media_id, _bookmark->marked_time);
+ ret = _content_get_result(sql, &stmt);
+ SQLITE3_SAFE_FREE(sql);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while (sqlite3_step(stmt) == SQLITE_ROW)
- bookmark_id = (int)sqlite3_column_int(stmt, 0);
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ bookmark_id = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);