#include <media_info_private.h>
#include <media_util_private.h>
-
-static attribute_h g_attr_handle = NULL;
-static attribute_h g_alias_attr_handle = NULL;
static sqlite3 *db_handle = NULL;
static int ref_count = 0;
static GMutex db_mutex;
static uid_t content_g_uid = 0;
-static int __media_content_create_attribute_handles(void);
-static int __media_content_destroy_attribute_handle(void);
-
-typedef struct {
- char *user_attr;
- char *platform_attr;
- char *platform_alias_attr;
-} media_content_attribute_info_s;
-
-static media_content_attribute_info_s g_content_attrs_info[] = {
- /* Media Info */
- {MEDIA_ID, DB_FIELD_MEDIA_ID, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ID},
- {MEDIA_PATH, DB_FIELD_MEDIA_PATH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PATH},
- {MEDIA_DISPLAY_NAME, DB_FIELD_MEDIA_DISPLAY_NAME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DISPLAY_NAME},
- {MEDIA_TYPE, DB_FIELD_MEDIA_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TYPE},
- {MEDIA_MIME_TYPE, DB_FIELD_MEDIA_MIME_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_MIME_TYPE},
- {MEDIA_SIZE, DB_FIELD_MEDIA_SIZE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_SIZE},
- {MEDIA_ADDED_TIME, DB_FIELD_MEDIA_ADDED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ADDED_TIME},
- {MEDIA_MODIFIED_TIME, DB_FIELD_MEDIA_MODIFIED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_MODIFIED_TIME},
- {MEDIA_TIMELINE, DB_FIELD_MEDIA_TIMELINE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TIMELINE},
- {MEDIA_THUMBNAIL_PATH, DB_FIELD_MEDIA_THUMBNAIL_PATH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_THUMBNAIL_PATH},
- {MEDIA_TITLE, DB_FIELD_MEDIA_TITLE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TITLE},
- {MEDIA_ALBUM, DB_FIELD_MEDIA_ALBUM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM},
- {MEDIA_ARTIST, DB_FIELD_MEDIA_ARTIST, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ARTIST},
- {MEDIA_ALBUM_ARTIST, DB_FIELD_MEDIA_ALBUM_ARTIST, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_ARTIST},
- {MEDIA_GENRE, DB_FIELD_MEDIA_GENRE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_GENRE},
- {MEDIA_COMPOSER, DB_FIELD_MEDIA_COMPOSER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COMPOSER},
- {MEDIA_YEAR, DB_FIELD_MEDIA_YEAR, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_YEAR},
- {MEDIA_RECORDED_DATE, DB_FIELD_MEDIA_RECORDED_DATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_RECORDED_DATE},
- {MEDIA_COPYRIGHT, DB_FIELD_MEDIA_COPYRIGHT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COPYRIGHT},
- {MEDIA_TRACK_NUM, DB_FIELD_MEDIA_TRACK_NUM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TRACK_NUM},
- {MEDIA_DESCRIPTION, DB_FIELD_MEDIA_DESCRIPTION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DESCRIPTION},
- {MEDIA_BITRATE, DB_FIELD_MEDIA_BITRATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BITRATE},
- {MEDIA_BITPERSAMPLE, DB_FIELD_MEDIA_BITPERSAMPLE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BITPERSAMPLE},
- {MEDIA_SAMPLERATE, DB_FIELD_MEDIA_SAMPLERATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_SAMPLERATE},
- {MEDIA_CHANNEL, DB_FIELD_MEDIA_CHANNEL, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CHANNEL},
- {MEDIA_DURATION, DB_FIELD_MEDIA_DURATION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DURATION},
- {MEDIA_LONGITUDE, DB_FIELD_MEDIA_LONGITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LONGITUDE},
- {MEDIA_LATITUDE, DB_FIELD_MEDIA_LATITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LATITUDE},
- {MEDIA_ALTITUDE, DB_FIELD_MEDIA_ALTITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALTITUDE},
- {MEDIA_WIDTH, DB_FIELD_MEDIA_WIDTH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_WIDTH},
- {MEDIA_HEIGHT, DB_FIELD_MEDIA_HEIGHT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_HEIGHT},
- {MEDIA_DATETAKEN, DB_FIELD_MEDIA_DATETAKEN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DATETAKEN},
- {MEDIA_ORIENTATION, DB_FIELD_MEDIA_ORIENTATION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ORIENTATION},
- {MEDIA_RATING, DB_FIELD_MEDIA_RATING, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_RATING},
- {MEDIA_FAVOURITE, DB_FIELD_MEDIA_FAVOURITE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FAVOURITE},
- {MEDIA_IS_DRM, DB_FIELD_MEDIA_IS_DRM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_IS_DRM},
- {MEDIA_STORAGE_TYPE, DB_FIELD_MEDIA_STORAGE_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_STORAGE_TYPE},
- {MEDIA_360, DB_FIELD_MEDIA_360, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_360},
-
- /* Pinyin */
- {MEDIA_FILE_NAME_PINYIN, DB_FIELD_MEDIA_FILE_NAME_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FILE_NAME_PINYIN},
- {MEDIA_TITLE_PINYIN, DB_FIELD_MEDIA_TITLE_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TITLE_PINYIN},
- {MEDIA_ALBUM_PINYIN, DB_FIELD_MEDIA_ALBUM_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_PINYIN},
- {MEDIA_ARTIST_PINYIN, DB_FIELD_MEDIA_ARTIST_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ARTIST_PINYIN},
- {MEDIA_ALBUM_ARTIST_PINYIN, DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN},
- {MEDIA_GENRE_PINYIN, DB_FIELD_MEDIA_GENRE_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_GENRE_PINYIN},
- {MEDIA_COMPOSER_PINYIN, DB_FIELD_MEDIA_COMPOSER_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COMPOSER_PINYIN},
- {MEDIA_COPYRIGHT_PINYIN, DB_FIELD_MEDIA_COPYRIGHT_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COPYRIGHT_PINYIN},
- {MEDIA_DESCRIPTION_PINYIN, DB_FIELD_MEDIA_DESCRIPTION_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DESCRIPTION_PINYIN},
-
- /* Folder */
- {FOLDER_ID, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_ID},
- {FOLDER_PATH, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_PATH},
- {FOLDER_NAME, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME},
- {FOLDER_STORAGE_TYPE, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_STORAGE_TYPE},
- {FOLDER_NAME_PINYIN, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME_PINYIN},
-
- /* Playlist */
- {MEDIA_PLAYLIST_ID, DB_FIELD_PLAYLIST_ID, NULL},
- {PLAYLIST_NAME, DB_FIELD_PLAYLIST_NAME, DB_TABLE_ALIAS_PLAYLIST"."DB_FIELD_PLAYLIST_NAME},
- {PLAYLIST_MEMBER_ORDER, DB_FIELD_PLAYLIST_MEMBER_ORDER, DB_TABLE_ALIAS_PLAYLIST_MAP"."DB_FIELD_PLAYLIST_MEMBER_ORDER},
-
- /* Playlist View */
- {PLAYLIST_MEDIA_COUNT, DB_FIELD_PLAYLIST_MEDIA_COUNT, NULL},
-
- /* Tag */
- {MEDIA_TAG_ID, DB_FIELD_TAG_ID, NULL},
- {TAG_NAME, DB_FIELD_TAG_NAME, DB_TABLE_ALIAS_TAG"."DB_FIELD_TAG_NAME},
-
- /* Tag View */
- {TAG_MEDIA_COUNT, DB_FIELD_TAG_MEDIA_COUNT, NULL},
-
- /* Bookmark */
- {MEDIA_BOOKMARK_ID, DB_FIELD_BOOKMARK_ID, DB_TABLE_ALIAS_BOOKMARK"."DB_FIELD_BOOKMARK_ID},
- {BOOKMARK_MARKED_TIME, DB_FIELD_BOOKMARK_MARKED_TIME, DB_TABLE_ALIAS_BOOKMARK"."DB_FIELD_BOOKMARK_MARKED_TIME},
- {BOOKMARK_NAME, DB_FIELD_BOOKMARK_NAME, DB_TABLE_ALIAS_BOOKMARK"."DB_FIELD_BOOKMARK_NAME},
-
- /* Storage */
- {MEDIA_STORAGE_ID, DB_FIELD_STORAGE_ID, NULL},
- {MEDIA_STORAGE_PATH, DB_FIELD_STORAGE_PATH, NULL},
-
- /* Face */
- {MEDIA_FACE_ID, DB_FIELD_FACE_ID, DB_TABLE_ALIAS_FACE"."DB_FIELD_FACE_ID},
- {MEDIA_FACE_TAG, DB_FIELD_FACE_TAG, DB_TABLE_ALIAS_FACE"."DB_FIELD_FACE_TAG},
-
-#ifdef _USE_SENIOR_MODE
- {MEDIA_CONTACT, DB_FIELD_MEDIA_CONTACT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CONTACT},
- {MEDIA_APP_DATA, DB_FIELD_MEDIA_APP_DATA, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_APP_DATA},
-#endif
-#ifdef _USE_TVPD_MODE
- {MEDIA_PLAYED_COUNT, DB_FIELD_MEDIA_PLAYED_COUNT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PLAYED_COUNT},
- {MEDIA_LAST_PLAYED_TIME, DB_FIELD_MEDIA_LAST_PLAYED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LAST_PLAYED_TIME},
- {MEDIA_LAST_PLAYED_POSITION, DB_FIELD_MEDIA_LAST_PLAYED_POSITION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LAST_PLAYED_POSITION},
- {MEDIA_FOLDER_ID, DB_FIELD_MEDIA_FOLDER_ID, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FOLDER_ID},
- {MEDIA_STITCHED_INFO, DB_FIELD_MEDIA_STITCHED_INFO, NULL},
- {MEDIA_MODIFIED_MONTH, DB_FIELD_MEDIA_MODIFIED_MONTH, NULL},
- {MEDIA_MODIFIED_DATE, DB_FIELD_MEDIA_MODIFIED_DATE, NULL},
-
- /* PVR */
- {PVR_DURATION, DB_FIELD_PVR_DURATION, NULL},
- {PVR_TIME_ZONE, DB_FIELD_PVR_TIME_ZONE, NULL},
- {PVR_PTC, DB_FIELD_PVR_PTC, NULL},
- {PVR_MAJOR, DB_FIELD_PVR_MAJOR, NULL},
- {PVR_MINOR, DB_FIELD_PVR_MINOR, NULL},
- {PVR_CHANNEL_TYPE, DB_FIELD_PVR_CHANNEL_TYPE, NULL},
- {PVR_CHANNEL_NAME, DB_FIELD_PVR_CHANNEL_NAME, NULL},
- {PVR_CHANNEL_NUM, DB_FIELD_PVR_CHANNEL_NUM, NULL},
- {PVR_PROGRAM_TITLE, DB_FIELD_PVR_PROGRAM_TITLE, NULL},
- {PVR_PROGRAM_NUM, DB_FIELD_PVR_PROGRAM_NUM, NULL},
- {PVR_PROGRAM_CRID, DB_FIELD_PVR_PROGRAM_CRID, NULL},
- {PVR_GUIDANCE, DB_FIELD_PVR_GUIDANCE, NULL},
- {PVR_SYNOPSIS, DB_FIELD_PVR_SYNOPSIS, NULL},
- {PVR_GENRE, DB_FIELD_PVR_GENRE, NULL},
- {PVR_LANGUAGE, DB_FIELD_PVR_LANGUAGE, NULL},
- {PVR_EMBARGO_TIME, DB_FIELD_PVR_EMBARGO_TIME, NULL},
- {PVR_EXPIRY_TIME, DB_FIELD_PVR_EXPIRY_TIME, NULL},
- {PVR_START_TIME, DB_FIELD_PVR_START_TIME, NULL},
- {PVR_PROGRAM_START_TIME, DB_FIELD_PVR_PROGRAM_START_TIME, NULL},
- {PVR_PROGRAM_END_TIME, DB_FIELD_PVR_PROGRAM_END_TIME, NULL},
- {PVR_PROGRAM_DATE, DB_FIELD_PVR_PROGRAM_DATE, NULL},
- {PVR_PARENTAL_RATING, DB_FIELD_PVR_PARENTAL_RATING, NULL},
- {PVR_TIMER_RECORD, DB_FIELD_PVR_TIMER_RECORD, NULL},
- {PVR_SERIES_RECORD, DB_FIELD_PVR_SERIES_RECORD, NULL},
- {PVR_HD, DB_FIELD_PVR_HD, NULL},
- {PVR_SUBTITLE, DB_FIELD_PVR_SUBTITLE, NULL},
- {PVR_TTX, DB_FIELD_PVR_TTX, NULL},
- {PVR_AD, DB_FIELD_PVR_AD, NULL},
- {PVR_TTX, DB_FIELD_PVR_TTX, NULL},
- {PVR_DATA_SERVICE, DB_FIELD_PVR_DATA_SERVICE, NULL},
- {PVR_CONTENT_LOCK, DB_FIELD_PVR_CONTENT_LOCK, NULL},
- {PVR_CONTENT_WATCH, DB_FIELD_PVR_CONTENT_WATCH, NULL},
- {PVR_CONTENT_HAS_AUDIO_ONLY, DB_FIELD_PVR_HAS_AUDIO_ONLY, NULL},
- {PVR_CONTENT_IS_LOCAL_RECORD, DB_FIELD_PVR_IS_LOCAL_RECORD, NULL},
- {PVR_CONTENT_RESOLUTION, DB_FIELD_PVR_RESOLUTION, NULL},
- {PVR_CONTENT_ASPECTRATIO, DB_FIELD_PVR_ASPECTRATIO, NULL},
- {PVR_MODIFIED_MONTH, DB_FIELD_PVR_MODIFIED_DATE, NULL},
- {PVR_MODIFIED_DATE, DB_FIELD_PVR_MODIFIED_DATE, NULL},
- {PVR_SPORTS_TYPE, DB_FIELD_PVR_SPORTS_TYPE, NULL},
- {PVR_GUIDANCE_LENGTH, DB_FIELD_PVR_GUIDANCE_LENGTH, NULL},
- {PVR_TVMODE, DB_FIELD_PVR_TVMODE, NULL},
- {PVR_PLAY_COUNT, DB_FIELD_PVR_PLAY_COUNT, NULL},
- {PVR_PRIVATE_DATA, DB_FIELD_PVR_PRIVATE_DATA, NULL},
-
- /* UHD */
- {UHD_CONTENT_TITLE, DB_FIELD_UHD_CONTENT_TITLE, NULL},
- {UHD_RELEASE_DATE, DB_FIELD_UHD_RELEASE_DATE, NULL},
- {UHD_SUB_TYPE, DB_FIELD_UHD_SUB_TYPE, NULL},
- {UHD_FILE_NAME, DB_FIELD_UHD_FILE_NAME, NULL},
- {UHD_FOLDER_ID, DB_FIELD_FOLDER_ID, NULL},
- {UHD_PLAYED_COUNT, DB_FIELD_UHD_PLAYED_COUNT, NULL},
-#endif
-};
-
-static int __media_content_create_attribute_handles(void)
-{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- int idx = 0;
- int count = 0;
- char *_attr_user = NULL;
- char *_attr_platform = NULL;
- char *_alias_attr_user = NULL;
- char *_alias_attr_platform = NULL;
- attribute_s *_attr = NULL;
- attribute_s *_alias_attr = NULL;
-
- ret = _media_filter_attribute_create(&g_attr_handle);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
-
- ret = _media_filter_attribute_create(&g_alias_attr_handle);
- if (ret != MEDIA_CONTENT_ERROR_NONE)
- goto ERROR;
-
- _attr = (attribute_s*)g_attr_handle;
- _alias_attr = (attribute_s*)g_alias_attr_handle;
-
- count = sizeof(g_content_attrs_info) / sizeof((g_content_attrs_info)[0]);
-
- for (idx = 0; idx < count; idx++) {
- _attr_user = NULL;
- _attr_platform = NULL;
- _alias_attr_user = NULL;
- _alias_attr_platform = NULL;
-
- if (STRING_VALID(g_content_attrs_info[idx].user_attr)) {
- /*attribute*/
- if (STRING_VALID(g_content_attrs_info[idx].platform_attr)) {
- _attr_user = g_strdup(g_content_attrs_info[idx].user_attr);
- _attr_platform = g_strdup(g_content_attrs_info[idx].platform_attr);
-
- if (_attr_user == NULL || _attr_platform == NULL) {
- SAFE_G_FREE(_attr_user);
- SAFE_G_FREE(_attr_platform);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- goto ERROR;
- }
-
- g_hash_table_insert(_attr->attr_map, _attr_user, _attr_platform);
-
- }
-
- /*alias attribute*/
- if (STRING_VALID(g_content_attrs_info[idx].platform_alias_attr)) {
- _alias_attr_user = g_strdup(g_content_attrs_info[idx].user_attr);
- _alias_attr_platform = g_strdup(g_content_attrs_info[idx].platform_alias_attr);
-
- if (_alias_attr_user == NULL || _alias_attr_platform == NULL) {
- SAFE_G_FREE(_alias_attr_user);
- SAFE_G_FREE(_alias_attr_platform);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- goto ERROR;
- }
-
- g_hash_table_insert(_alias_attr->attr_map, _alias_attr_user, _alias_attr_platform);
- }
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- goto ERROR;
- }
- }
-
- return ret;
-
-ERROR:
- media_content_error("Fail media_content_create_attribute_handles");
- __media_content_destroy_attribute_handle();
-
- return ret;
-}
-
-static int __media_content_destroy_attribute_handle(void)
-{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- ret = _media_filter_attribute_destory(g_attr_handle);
- ret = _media_filter_attribute_destory(g_alias_attr_handle);
-
- g_attr_handle = NULL;
- g_alias_attr_handle = NULL;
-
- return ret;
-}
-
-attribute_h _content_get_attirbute_handle(void)
-{
- return g_attr_handle;
-}
-
-attribute_h _content_get_alias_attirbute_handle(void)
-{
- return g_alias_attr_handle;
-}
-
sqlite3 * _content_get_db_handle(void)
{
return db_handle;
return content_g_uid;
}
-int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query)
+int _content_query_prepare(const char *select_query, const char *condition_query, const char *option_query, sqlite3_stmt **stmt)
{
- int len = 0;
- int err = MEDIA_CONTENT_ERROR_NONE;
- char query[MAX_QUERY_SIZE] = {0, };
- memset(query, '\0', sizeof(query));
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char *query = NULL;
- media_content_retvm_if(db_handle == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
media_content_retvm_if(!STRING_VALID(select_query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query");
- if (!STRING_VALID(condition_query))
- condition_query = (char *)" ";
+ if (STRING_VALID(condition_query)) {
+ if (STRING_VALID(option_query))
+ query = sqlite3_mprintf("%s AND %s %s", select_query, condition_query, option_query);
+ else
+ query = sqlite3_mprintf("%s AND %s", select_query, condition_query);
+ } else {
+ if (STRING_VALID(option_query))
+ query = sqlite3_mprintf("%s %s", select_query, option_query);
+ else
+ query = sqlite3_mprintf("%s", select_query);
+ }
- if (!STRING_VALID(option_query))
- option_query = (char *)" ";
+ ret = _content_get_result(query, stmt);
+ SQLITE3_SAFE_FREE(query);
- /*query = sqlite3_mprintf("%s %s %s", select_query, condition_query, option_query);*/
- len = snprintf(query, sizeof(query), "%s %s %s", select_query, condition_query, option_query);
- if (len > 0 && len < sizeof(query))
- query[len] = '\0';
- else if (len >= sizeof(query))
- query[MAX_QUERY_SIZE -1] = '\0';
- else {
- media_content_error("snprintf failed");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ return ret;
+}
- media_content_sec_debug("Query : [%s]", query);
+int _content_get_result(char *query, sqlite3_stmt **stmt)
+{
+ int err = MEDIA_CONTENT_ERROR_NONE;
- err = sqlite3_prepare_v2(db_handle, query, strlen(query), stmt, NULL);
- if (err != SQLITE_OK) {
- media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(db_handle));
+ media_content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
+ media_content_retvm_if(!STRING_VALID(query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid query");
- if (err == SQLITE_BUSY) {
- media_content_error(" BUSY ERROR");
+ media_content_sec_debug("Query[%s]", query);
+
+ err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
+ if (err != SQLITE_OK) {
+ media_content_error("Failed to sqlite3_prepare_v2[%s]", sqlite3_errmsg(_content_get_db_handle()));
+ if (err == SQLITE_BUSY)
return MEDIA_CONTENT_ERROR_DB_BUSY;
- } else if (err == SQLITE_PERM) {
- media_content_error("PERMISSION EROR");
+ else if (err == SQLITE_PERM)
return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
- } else {
- media_content_error("OTHER ERROR");
+ else
return MEDIA_CONTENT_ERROR_DB_FAILED;
- }
}
return MEDIA_CONTENT_ERROR_NONE;
char query[MAX_QUERY_SIZE] = {0, };
memset(query, '\0', sizeof(query));
- media_content_retvm_if(db_handle == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
+ media_content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
media_content_retvm_if(!STRING_VALID(select_query1), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query1");
media_content_retvm_if(!STRING_VALID(select_query2), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query2");
media_content_sec_debug("Query : [%s]", query);
- err = sqlite3_prepare_v2(db_handle, query, strlen(query), stmt, NULL);
+ err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
if (err != SQLITE_OK) {
- media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(db_handle));
+ media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(_content_get_db_handle()));
if (err == SQLITE_BUSY) {
media_content_error(" BUSY ERROR");
}
#endif
-int _content_error_capi(int type, int content_error)
+int _content_error_capi(int internal_error)
{
- if (content_error != MEDIA_CONTENT_ERROR_NONE)
- media_content_error("[type : %d] content_error : %d ", type, content_error);
-
- /*Error None*/
- if (content_error == MS_MEDIA_ERR_NONE)
+ if (internal_error == MS_MEDIA_ERR_NONE)
return MEDIA_CONTENT_ERROR_NONE;
- /* Internal operation error*/
- else if ((content_error == MS_MEDIA_ERR_INVALID_PARAMETER) ||
- (content_error == MS_MEDIA_ERR_INVALID_PATH) ||
- (content_error == MS_MEDIA_ERR_THUMB_DUPLICATED_REQUEST))
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ media_content_error("MS Error[%d]", internal_error);
- else if (content_error == MS_MEDIA_ERR_OUT_OF_MEMORY)
+ switch (internal_error) {
+ case MS_MEDIA_ERR_INVALID_PARAMETER:
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ case MS_MEDIA_ERR_OUT_OF_MEMORY:
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-
- /* DB operation error*/
- else if (content_error == MS_MEDIA_ERR_DB_BUSY_FAIL)
+ case MS_MEDIA_ERR_DB_BUSY_FAIL:
return MEDIA_CONTENT_ERROR_DB_BUSY;
-
- else if ((content_error <= MS_MEDIA_ERR_DB_CONNECT_FAIL) && (content_error >= MS_MEDIA_ERR_DB_INTERNAL))
+ case MS_MEDIA_ERR_DB_CONSTRAINT_FAIL:
+ case MS_MEDIA_ERR_DB_NO_RECORD:
+ case MS_MEDIA_ERR_DB_CORRUPT:
+ case MS_MEDIA_ERR_DB_FULL_FAIL:
+ case MS_MEDIA_ERR_DB_RESET:
+ case MS_MEDIA_ERR_DB_INTERNAL:
return MEDIA_CONTENT_ERROR_DB_FAILED;
-
- /* IPC operation error*/
- else if ((content_error <= MS_MEDIA_ERR_SOCKET_CONN) && (content_error >= MS_MEDIA_ERR_SOCKET_INTERNAL))
+ case MS_MEDIA_ERR_IPC:
return MEDIA_CONTENT_ERROR_NETWORK;
-
- /* MEDIA SERVER error*/
- else if (content_error == MS_MEDIA_ERR_PERMISSION_DENIED)
+ case MS_MEDIA_ERR_PERMISSION_DENIED:
return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
-
- /* Thumbnail error*/
- else if ((content_error == MS_MEDIA_ERR_THUMB_TOO_BIG) || (content_error == MS_MEDIA_ERR_THUMB_UNSUPPORTED))
- return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
-
- /*ETC*/
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ case MS_MEDIA_ERR_THUMB_TOO_BIG:
+ case MS_MEDIA_ERR_THUMB_UNSUPPORTED:
+ return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
+ default:
+ return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ }
}
int _content_query_sql(char *query_str)
int ret = MEDIA_CONTENT_ERROR_NONE;
/*DB will be updated by Media Server.*/
- ret = media_svc_request_update_db(query_str, _content_get_uid());
+ ret = media_db_request_update_db(query_str, _content_get_uid());
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
int media_content_connect(void)
if (ref_count == 0) {
if (db_handle == NULL) {
- ret = __media_content_create_attribute_handles();
- if (ret == MEDIA_CONTENT_ERROR_NONE) {
- ret = media_db_connect(&db_handle, _content_get_uid(), false);
- ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
- if (ret == MEDIA_CONTENT_ERROR_NONE)
- ref_count++;
- else
- __media_content_destroy_attribute_handle();
-
- } else {
- media_content_error("Internal DB Connection Error");
- }
+ ret = media_db_connect(&db_handle, _content_get_uid(), false);
+ ret = _content_error_capi(ret);
+ if (ret == MEDIA_CONTENT_ERROR_NONE)
+ ref_count++;
} else {
media_content_error("Wrong DB Connection status");
ret = MEDIA_CONTENT_ERROR_DB_FAILED;
int media_content_disconnect(void)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
g_mutex_lock(&db_mutex);
media_content_debug("ref count : %d", ref_count);
- if (ref_count > 0) {
- if (db_handle != NULL) {
- ref_count--;
- } else {
- media_content_error("Wrong DB Handle status");
- ret = MEDIA_CONTENT_ERROR_DB_FAILED;
+
+ if (db_handle && ref_count > 0) {
+ if (--ref_count == 0) {
+ media_db_disconnect(db_handle);
+ db_handle = NULL;
}
} else {
- media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED);
+ media_content_error("Database is not connected");
g_mutex_unlock(&db_mutex);
return MEDIA_CONTENT_ERROR_DB_FAILED;
}
- if (ref_count == 0) {
- if (db_handle != NULL) {
- ret = media_db_disconnect(db_handle);
- ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
- if (ret == MEDIA_CONTENT_ERROR_NONE) {
- ret = __media_content_destroy_attribute_handle();
- db_handle = NULL;
- } else {
- media_content_error("database disconnect fail");
- ref_count++;
- }
- } else {
- media_content_error("Wrong DB Handle status");
- ret = MEDIA_CONTENT_ERROR_DB_FAILED;
- }
-
- g_mutex_unlock(&db_mutex);
-
- media_content_info("ref count changed to: %d", ref_count);
-
- return ret;
- }
-
g_mutex_unlock(&db_mutex);
media_content_info("ref count changed to: %d", ref_count);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_content_scan_file(const char *path)
ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
if (ret != MS_MEDIA_ERR_NONE) {
media_content_error("media_svc_get_storage_id failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
check_file = _media_util_check_file_exist(repl_path);
/* This means this path has to be inserted or refreshed */
folder_path = g_path_get_dirname(repl_path);
ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
- SAFE_FREE(folder_path);
+ g_free(folder_path);
media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
/* check feature */
ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path);
if (ret == MS_MEDIA_ERR_NONE) {
/* Refresh */
- ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, repl_path, _content_get_uid());
+ ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, repl_path, _content_get_uid());
if (ret != MS_MEDIA_ERR_NONE) {
media_content_error("media_svc_refresh_item failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
} else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path);
}
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
} else {
media_content_error("media_svc_check_item_exist_by_path failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
} else if (check_file == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) {
media_content_error("You have no permission for this file %d", ret);
}
media_content_error("media_svc_delete_item_by_path failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
}
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
void _media_content_scan_cb(media_request_result_s* result, void *user_data)
int err = -1;
media_content_scan_cb_data *cb_data = user_data;
- err = _content_error_capi(MEDIA_REGISTER_TYPE, result->result);
+ err = _content_error_capi(result->result);
#ifdef _USE_TVPD_MODE
if (result->request_type != MEDIA_REQUEST_SCAN_COMPLETE &&
- result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) {
+ result->request_type != MEDIA_REQUEST_SCAN_PARTIAL &&
+ result->request_type != MEDIA_RECURSIVE_START) {
if (cb_data && cb_data->callback) {
media_content_debug("begin:User callback is being called now, result=%d", err);
cb_data->callback(err, cb_data->user_data);
media_content_complete_phase_e complete_phase = -1;
if (!cb_data)
media_content_debug("cb_data is NULL");
- err = _content_error_capi(MEDIA_REGISTER_TYPE, result->result);
+ err = _content_error_capi(result->result);
media_content_debug("result is %d", err);
if (result->request_type == MEDIA_REQUEST_SCAN_PARTIAL)
complete_phase = MEDIA_CONTENT_SCAN_COMPLETE;
else if (result->request_type == MEDIA_REQUEST_EXTRACT_COMPLETE)
complete_phase = MEDIA_CONTENT_EXTRACT_COMPLETE;
+ else if (result->request_type == MEDIA_RECURSIVE_START)
+ complete_phase = MEDIA_CONTENT_RECURSIVE_START;
if (cb_data && cb_data->callback)
cb_data->callback(err, complete_phase, cb_data->user_data);
media_content_debug("run error");
if ((result->request_type != MEDIA_REQUEST_SCAN_COMPLETE) &&
- (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL))
+ (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) &&
+ (result->request_type != MEDIA_RECURSIVE_START))
SAFE_FREE(cb_data);
return;
ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
media_content_debug("This path doesn't exists in file system... So will be deleted it from DB");
ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
if (ret != MS_MEDIA_ERR_NONE) {
media_content_error("media_svc_get_storage_id failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
media_content_scan_cb_data *cb_data = NULL;
SAFE_FREE(cb_data);
}
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
#ifdef _USE_TVPD_MODE
if (ret != MS_MEDIA_ERR_NONE)
media_content_error("media_directory_scanning_async failed : %d", ret);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
#endif
if (ret != MS_MEDIA_ERR_NONE)
media_content_error("media_directory_scanning_async failed : %d", ret);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
void _media_content_db_update_noti_cb(
char *mime_type,
void *user_data)
{
- int error_value = MEDIA_CONTENT_ERROR_NONE;
-
media_noti_cb_s *_noti_info = (media_noti_cb_s *)user_data;
- if (_noti_info != NULL) {
- if (_noti_info->update_noti_cb)
- _noti_info->update_noti_cb(error_value, pid, item, update_type, content_type, uuid, path, mime_type, _noti_info->user_data);
- }
-
- return;
+ if (_noti_info != NULL && _noti_info->update_noti_cb)
+ _noti_info->update_noti_cb(
+ MEDIA_CONTENT_ERROR_NONE,
+ pid,
+ item,
+ update_type,
+ content_type,
+ uuid,
+ path,
+ mime_type,
+ _noti_info->user_data);
}
int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle)
int ret = MEDIA_CONTENT_ERROR_NONE;
media_noti_cb_s *noti_info = NULL;
- if (noti_handle == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- if (callback == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ media_content_retvm_if(noti_handle == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "handle is NULL");
+ media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "callback is NULL");
noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
- if (noti_info == NULL) {
- media_content_error("Failed to create noti info");
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ media_content_retvm_if(noti_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Failed to create noti info");
noti_info->update_noti_cb = callback;
noti_info->user_data = user_data;
ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
+ if (ret != MS_MEDIA_ERR_NONE)
+ SAFE_FREE(noti_info);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
+#ifdef TIZEN_FEATURE_COMPATIBILITY
+int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data)
+{
+ media_content_warn("DEPRECATION WARNING: media_content_set_db_updated_cb() is removed from 5.0.");
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+#endif
+
void __media_content_clear_user_data(void *user_data)
{
media_noti_cb_s *noti_info = user_data;
ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
#ifdef _USE_TVPD_MODE
GMutex* _content_get_db_mutex(void)