From: Minje Ahn Date: Tue, 12 Jan 2016 07:44:58 +0000 (+0900) Subject: update scanner v2 X-Git-Tag: accepted/tizen/mobile/20160122.030529~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F07%2F56707%2F2;p=platform%2Fcore%2Fmultimedia%2Flibmedia-service.git update scanner v2 Change-Id: I71ea64abc2414fd7437fd06f4e7c9d6311c7c464 Signed-off-by: Minje Ahn --- diff --git a/include/media-svc.h b/include/media-svc.h index 9bf6e60..2c40d1c 100755 --- a/include/media-svc.h +++ b/include/media-svc.h @@ -94,6 +94,11 @@ int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, int media_svc_insert_folder_begin(int data_cnt); int media_svc_insert_folder_end(uid_t uid); +int media_svc_get_folder_scan_status(MediaSvcHandle *handle, const char *storage_id, const char *path, int *storage_status); +int media_svc_set_folder_scan_status(const char *storage_id, const char *path, int storage_status, uid_t uid); +int media_svc_get_folder_modified_time(MediaSvcHandle *handle, const char *path, const char *storage_id, bool *modified); +int media_svc_get_null_scan_folder_list(MediaSvcHandle *handle, char *storage_id, char* folder_path, char ***folder_list, int *count); +int media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid); int media_svc_delete_invalid_folder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count); int media_svc_check_folder_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path); int media_svc_check_subfolder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count); diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec index 298c418..fac37be 100644 --- a/packaging/libmedia-service.spec +++ b/packaging/libmedia-service.spec @@ -1,6 +1,6 @@ Name: libmedia-service Summary: Media information service library for multimedia applications -Version: 0.2.62 +Version: 0.2.63 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 and public domain diff --git a/plugin/media-content-plugin.c b/plugin/media-content-plugin.c index 435638c..aaef050 100755 --- a/plugin/media-content-plugin.c +++ b/plugin/media-content-plugin.c @@ -892,7 +892,7 @@ int insert_item_scan(void * handle, const char *storage_id, const char *file_pat return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int update_item_extract(void * handle, const char *storage_id, int storage_type, int scan_type, uid_t uid, const char *path, char **err_msg) +int update_item_extract(void * handle, const char *storage_id, int storage_type, int scan_type, uid_t uid, const char *path, int burst, char **err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -906,7 +906,7 @@ int update_item_extract(void * handle, const char *storage_id, int storage_type, return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, FALSE, uid); + ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, burst, uid); if (ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -1000,6 +1000,101 @@ int set_folder_validity(void * handle, const char *storage_id, const char* start return MEDIA_SVC_PLUGIN_ERROR_NONE; } +int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg) +{ + int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; + int storage_status = 0; + + if(handle == NULL) { + __set_error_message(ERR_HANDLE, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status); + if(ret < 0) { + __set_error_message(ret, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + *status = storage_status; + + return ret; +} + +int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg) +{ + int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; + int storage_status = status; + + ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid); + if(ret < 0) { + __set_error_message(ret, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + return ret; +} + +int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg) +{ + int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; + *modified = TRUE; + + if(handle == NULL) { + __set_error_message(ERR_HANDLE, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + if (!STRING_VALID(path)) { + __set_error_message(ERR_FILE_PATH, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified); + if (ret < 0) { + __set_error_message(ret, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + return ret; +} + +int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg) +{ + int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; + + if(handle == NULL) { + __set_error_message(ERR_HANDLE, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + if(count == NULL) { + __set_error_message(ERR_HANDLE, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count); + if(ret < 0) { + __set_error_message(ret, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + return ret; +} + +int change_validity_item_batch(void **handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid, char **err_msg) +{ + int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; + + ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid); + if(ret < 0) { + __set_error_message(ret, err_msg); + return MEDIA_SVC_PLUGIN_ERROR; + } + + return ret; +} + int delete_invalid_folder_by_path(void * handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count, char **err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -1076,4 +1171,3 @@ int get_folder_id(void * handle, const char *storage_id, const char *path, char } - diff --git a/src/common/media-svc-db-utils.c b/src/common/media-svc-db-utils.c index 5856902..bed8aa2 100755 --- a/src/common/media-svc-db-utils.c +++ b/src/common/media-svc-db-utils.c @@ -682,7 +682,7 @@ int _media_svc_init_table_query(const char *event_table_name) media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "content_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_content_name_idx", false, false, true); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); - ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "category", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_category_idx", false, false, true); + ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "category", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "location_tag", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_location_tag_idx", false, false, true); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); @@ -767,6 +767,8 @@ int _media_svc_init_table_query(const char *event_table_name) media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", USER_V4, NULL, false, false, false); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); + ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "scan_status", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false); + media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); /*playlist_map*/ ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, false, true); diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c index e8f4724..b3d6df8 100755 --- a/src/common/media-svc-media-folder.c +++ b/src/common/media-svc-media-folder.c @@ -27,6 +27,8 @@ #include "media-svc-util.h" #include "media-svc-db-utils.h" +#define FOLDER_SCAN_DONE 4 + extern __thread GList *g_media_svc_move_item_query_list; static __thread GList *g_media_svc_insert_folder_query_list; @@ -619,6 +621,200 @@ GList ** _media_svc_get_folder_list_ptr(void) return &g_media_svc_insert_folder_query_list; } +int _media_svc_get_folder_scan_status(sqlite3 *handle, const char *storage_id, const char *path, int *scan_status) +{ + int ret = MS_MEDIA_ERR_NONE; + sqlite3_stmt *sql_stmt = NULL; + char *sql = NULL; + + if (!STRING_VALID(path)) { + media_svc_error("Not found valid path"); + ret = MS_MEDIA_ERR_INVALID_PARAMETER; + } + + sql = sqlite3_mprintf("SELECT scan_status FROM '%s' WHERE path = '%q' AND storage_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id); + + ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); + + media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); + + while(sqlite3_step(sql_stmt) == SQLITE_ROW) { + *scan_status = sqlite3_column_int(sql_stmt, 0); + } + + SQLITE3_FINALIZE(sql_stmt); + + return ret; +} + +int _media_svc_set_folder_scan_status(const char *storage_id, const char *path, int scan_status, uid_t uid) +{ + int ret = MS_MEDIA_ERR_NONE; + char *sql = NULL; + + if (path) { + sql = sqlite3_mprintf("UPDATE '%s' SET scan_status=%d WHERE path = '%q' AND storage_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, scan_status, path, storage_id); + } else { + sql = sqlite3_mprintf("UPDATE '%s' SET scan_status=%d WHERE storage_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, scan_status, storage_id); + } + + ret = _media_svc_sql_query(sql, uid); + sqlite3_free(sql); + + return ret; +} + +int _media_svc_get_folder_modified_time_by_path(sqlite3 *handle, const char *path, const char *storage_id, time_t *modified_time) +{ + int ret = MS_MEDIA_ERR_NONE; + sqlite3_stmt *sql_stmt = NULL; + + char *sql = sqlite3_mprintf("SELECT modified_time FROM '%s' WHERE path = '%q' AND storage_uuid = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id); + + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + + if (ret != MS_MEDIA_ERR_NONE) { + if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { + media_svc_debug("there is no folder."); + } else { + media_svc_error("error when _media_svc_get_folder_modified_time_by_path. err = [%d]", ret); + } + return ret; + } + + *modified_time = (int)sqlite3_column_int(sql_stmt, 0); + + SQLITE3_FINALIZE(sql_stmt); + + return ret; +} + +int _media_svc_get_null_scan_folder_list(sqlite3 *handle, char *storage_id, char *path, char ***folder_list, int *count) +{ + int ret = MS_MEDIA_ERR_NONE; + int idx = 0; + int cnt = 0; + char *sql = NULL; + char folder_id[MEDIA_SVC_UUID_SIZE+1] = {0,}; + sqlite3_stmt *sql_stmt = NULL; + + if (path == NULL) { + sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE storage_uuid = '%q' AND scan_status!=%d", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, FOLDER_SCAN_DONE); + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + + if (ret != MS_MEDIA_ERR_NONE) { + if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { + media_svc_debug("there is no folder."); + } else { + media_svc_error("error when get folder_id by path. err = [%d]", ret); + } + + *folder_list = NULL; + *count = 0; + + return ret; + } + + cnt = sqlite3_column_int(sql_stmt, 0); + SQLITE3_FINALIZE(sql_stmt); + if (cnt > 0) { + sql = sqlite3_mprintf("SELECT path FROM '%s' WHERE storage_uuid = '%q' AND scan_status!=%d", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, FOLDER_SCAN_DONE); + } else { + *folder_list = NULL; + *count = 0; + + return MS_MEDIA_ERR_INTERNAL; + } + + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("prepare error [%s]", sqlite3_errmsg(handle)); + + *folder_list = NULL; + *count = 0; + + return ret; + } + } else { + sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE storage_uuid = '%q' AND path = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, path); + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + + if (ret != MS_MEDIA_ERR_NONE) { + if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { + media_svc_debug("there is no folder."); + } else { + media_svc_error("error when get folder_id by path [%s]. err = [%d]", path, ret); + } + return ret; + } + + _strncpy_safe(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1); + + SQLITE3_FINALIZE(sql_stmt); + + sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE path LIKE '%q%%' AND parent_folder_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, path, folder_id); + + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("error when _media_svc_sql_prepare_to_step. err = [%d]", ret); + return ret; + } + + cnt = sqlite3_column_int(sql_stmt, 0); + SQLITE3_FINALIZE(sql_stmt); + if (cnt > 0) { + sql = sqlite3_mprintf("SELECT path FROM '%s' WHERE path LIKE '%q%%' AND parent_folder_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, path, folder_id); + } else { + *folder_list = NULL; + *count = 0; + + return MS_MEDIA_ERR_NONE; + } + + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("prepare error [%s]", sqlite3_errmsg(handle)); + + *folder_list = NULL; + *count = 0; + + return ret; + } + } + + *folder_list = malloc(sizeof(char *) * cnt); + + while (1) { + (*folder_list)[idx] = strdup((char *)sqlite3_column_text(sql_stmt, 0)); + + if(sqlite3_step(sql_stmt) != SQLITE_ROW) + break; + idx++; + } + + if (cnt == idx + 1) { + *count = cnt; + media_svc_debug("OK"); + } else { + /* free all data */ + int i =0; + for (i = 0; i < idx; i ++) + { + SAFE_FREE((*folder_list)[i]); + } + SAFE_FREE(*folder_list); + *count = 0; + ret = MS_MEDIA_ERR_INTERNAL; + } + + SQLITE3_FINALIZE(sql_stmt); + + return ret; +} + int _media_svc_delete_invalid_folder_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count) { int ret = MS_MEDIA_ERR_NONE; diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c index 8a2eaf5..546803e 100755 --- a/src/common/media-svc-media.c +++ b/src/common/media-svc-media.c @@ -1029,53 +1029,24 @@ int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *storage_id, con return MS_MEDIA_ERR_NONE; } -int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid) +int _media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; - char *burst_id = NULL; - media_svc_debug("START pass1"); + char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE validity=%d AND path LIKE '%q%%'", storage_id, des_validity, src_validity, path); - char * db_fields = (char *)"media_uuid, folder_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, is_drm, storage_type, timeline, burst_id, storage_uuid"; -#if 0 - if (is_burst) { - int burst_id_int = 0; - ret = _media_svc_get_burst_id(handle, storage_id, &burst_id_int); - if (ret != MS_MEDIA_ERR_NONE) { - burst_id = NULL; - } - - if (burst_id_int > 0) { - media_svc_debug("Burst id : %d", burst_id_int); - burst_id = sqlite3_mprintf("%d", burst_id_int); - } - - /* Get thumbnail for burst shot */ - char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, }; - int width = 0; - int height = 0; - - ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height); - if (ret == MS_MEDIA_ERR_NONE) { - ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path); - if (ret != MS_MEDIA_ERR_NONE) { - content_info->thumbnail_path = NULL; - } - } + ret = _media_svc_sql_query(sql, uid); + sqlite3_free(sql); - if (content_info->media_meta.width <= 0) - content_info->media_meta.width = width; + return ret; +} - if (content_info->media_meta.height <= 0) - content_info->media_meta.height = height; - } +int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid) +{ + int ret = MS_MEDIA_ERR_NONE; + char *burst_id = NULL; - /* Update Pinyin If Support Pinyin */ - if (_media_svc_check_pinyin_support()) { - if (STRING_VALID(content_info->file_name)) - _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin); - } -#endif + char * db_fields = (char *)"media_uuid, folder_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, is_drm, storage_type, timeline, burst_id, storage_uuid"; char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, \ %d, %d, %d, %d, %d, %Q, %Q);", @@ -1146,7 +1117,6 @@ int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_ _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin); } - /*modified month does not exist in Tizen 2.4*/ char *sql = sqlite3_mprintf("UPDATE '%s' SET \ thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, year=%Q, \ recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, \ @@ -1155,7 +1125,7 @@ int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_ artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q WHERE path=%Q;", storage_id, //content_info->folder_uuid, - content_info->thumbnail_path, /**/ + content_info->thumbnail_path, content_info->media_meta.title, content_info->album_id, content_info->media_meta.album, @@ -1167,7 +1137,7 @@ int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_ content_info->media_meta.recorded_date, content_info->media_meta.copyright, content_info->media_meta.track_num, - content_info->media_meta.description, /**/ + content_info->media_meta.description, content_info->media_meta.bitrate, content_info->media_meta.bitpersample, content_info->media_meta.samplerate, diff --git a/src/common/media-svc-storage.c b/src/common/media-svc-storage.c index 102aaa0..b28e96d 100755 --- a/src/common/media-svc-storage.c +++ b/src/common/media-svc-storage.c @@ -203,28 +203,20 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage return MS_MEDIA_ERR_NONE; } - sql = sqlite3_mprintf("SELECT storage_uuid, storage_path FROM '%s' WHERE validity=1", MEDIA_SVC_DB_TABLE_STORAGE); - - ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); - - media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); - remain_path = strstr(path + (STRING_VALID(MEDIA_ROOT_PATH_USB) ? strlen(MEDIA_ROOT_PATH_USB) : 0) + 1, "/"); if (remain_path != NULL) remain_len = strlen(remain_path); storage_path = strndup(path, strlen(path) - remain_len); - while (sqlite3_step(sql_stmt) == SQLITE_ROW) { - if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) { - if (strlen(storage_path) == strlen((const char *)sqlite3_column_text(sql_stmt, 1))) { - if (strncmp(storage_path, (const char *)sqlite3_column_text(sql_stmt, 1), strlen(storage_path)) == 0) { - _strncpy_safe(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1); - break; - } - } - } + sql = sqlite3_mprintf("SELECT storage_uuid FROM '%s' WHERE validity=1 AND storage_path = '%s'", MEDIA_SVC_DB_TABLE_STORAGE, storage_path); + + ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); + if(STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) + { + _strncpy_safe(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1); } SQLITE3_FINALIZE(sql_stmt); @@ -307,25 +299,21 @@ int _media_svc_get_storage_scan_status(sqlite3 *handle, const char *storage_id, char *sql = NULL; if (!STRING_VALID(storage_id)) { - media_svc_error("Invalid storage_id"); - return MS_MEDIA_ERR_INVALID_PARAMETER; + media_svc_error("Not found valid storage id"); + ret = MS_MEDIA_ERR_INVALID_PARAMETER; } sql = sqlite3_mprintf("SELECT scan_status FROM '%s' WHERE (storage_uuid=%Q AND validity=1)", MEDIA_SVC_DB_TABLE_STORAGE, storage_id); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); - if (ret != MS_MEDIA_ERR_NONE) { - if (ret == MS_MEDIA_ERR_DB_NO_RECORD) - media_svc_debug("there is no storage."); - else - media_svc_error("error when _media_svc_get_storage_scan_status. err = [%d]", ret); + media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); - return ret; + while(sqlite3_step(sql_stmt) == SQLITE_ROW) + { + *scan_status = sqlite3_column_int(sql_stmt, 0); } - *scan_status = sqlite3_column_int(sql_stmt, 0); - SQLITE3_FINALIZE(sql_stmt); return ret; diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index 52f8a79..6494346 100755 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -149,12 +149,17 @@ typedef enum { char *_media_info_generate_uuid(void) { uuid_t uuid_value; - static char uuid_unparsed[50]; + static char uuid_unparsed[37]; +RETRY_GEN: uuid_generate(uuid_value); uuid_unparse(uuid_value, uuid_unparsed); - /*media_svc_debug("UUID : %s", uuid_unparsed); */ + if (strlen(uuid_unparsed) < 36) { + media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed); + goto RETRY_GEN; + } + return uuid_unparsed; } diff --git a/src/common/media-svc.c b/src/common/media-svc.c index 3af8367..f7995ec 100755 --- a/src/common/media-svc.c +++ b/src/common/media-svc.c @@ -52,7 +52,7 @@ static __thread int g_media_svc_insert_folder_cur_data_cnt = 0; static __thread int g_insert_with_noti = FALSE; #define DEFAULT_MEDIA_SVC_STORAGE_ID "media" - +#define BATCH_REQUEST_MAX 300 typedef struct { int media_type; char *path; @@ -2079,38 +2079,59 @@ int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, GArray *db_data_array = NULL; media_svc_item_info_s *db_data = NULL; int idx = 0; - char *sql = NULL; media_svc_debug_fenter(); media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL"); media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL"); - media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type"); - if (scan_type == MS_MSG_DIRECTORY_SCANNING) { - sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL AND path LIKE '%q/%%'", storage_id, extract_path); - } else if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) { - char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0, }; + if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)) { + media_svc_error("storage type is incorrect[%d]", storage_type); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + db_data_array = g_array_new(FALSE, FALSE, sizeof(media_svc_item_info_s*)); + if (db_data_array == NULL) { + media_svc_error("db_data_array is NULL. Out of memory"); + return MS_MEDIA_ERR_OUT_OF_MEMORY; + } + + char *sql; + char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,}; + if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) + { ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, extract_path, folder_uuid, uid); - media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); + } - sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL AND folder_uuid = '%q'", storage_id, folder_uuid); - } else { /*Storage Scanning*/ - sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL", storage_id); + if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE && ret == MS_MEDIA_ERR_NONE) { + media_svc_error("folder no recursive extract"); + if (is_burst == 1) { + sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL and folder_uuid = '%q' ", storage_id, folder_uuid); + } else { + sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL and folder_uuid = '%q' LIMIT %d", storage_id, folder_uuid, BATCH_REQUEST_MAX); + } + } else if (scan_type == MS_MSG_DIRECTORY_SCANNING) { + media_svc_error("folder recursive extract"); + if (is_burst == 1) { + sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL and path LIKE '%q%%' ", storage_id, extract_path); + } else { + sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL and path LIKE '%q%%' LIMIT %d", storage_id, extract_path, BATCH_REQUEST_MAX); + } + } else { + if(is_burst == 1) { + sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL", storage_id); + } else { + sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL LIMIT %d", storage_id, BATCH_REQUEST_MAX); + } } ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); if (ret != MS_MEDIA_ERR_NONE) { media_svc_error("error when get list. err = [%d]", ret); + g_array_free(db_data_array, FALSE); return ret; } - db_data_array = g_array_new(FALSE, FALSE, sizeof(media_svc_item_info_s*)); - if (db_data_array == NULL) { - media_svc_error("db_data_array is NULL. Out of memory"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - while (sqlite3_step(sql_stmt) == SQLITE_ROW) { db_data = NULL; db_data = malloc(sizeof(media_svc_item_info_s)); @@ -2126,6 +2147,7 @@ int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, } SQLITE3_FINALIZE(sql_stmt); + media_svc_error("Insert Pass 2 get %d items!", db_data_array->len); while (db_data_array->len != 0) { db_data = NULL; @@ -2138,7 +2160,7 @@ int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, } media_type = db_data->media_type; - media_svc_debug("path is %s, media type %d", db_data->path, media_type); + //media_svc_debug("path is %s, media type %d", db_data->path, media_type); memset(&content_info, 0, sizeof(media_svc_content_info_s)); __media_svc_malloc_and_strncpy(&content_info.path, db_data->path); @@ -2163,9 +2185,16 @@ int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, idx++; } - if (idx > 0) + if (idx > 0) { ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid); + if (0) { + _media_svc_publish_noti_list(idx); + _media_svc_destroy_noti_list(idx); + /* Recreate noti list */ + ret = _media_svc_create_noti_list(idx); + } + } g_array_free(db_data_array, FALSE); db_data_array = NULL; @@ -2174,6 +2203,69 @@ int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, return MS_MEDIA_ERR_NONE; } +int media_svc_get_folder_scan_status(MediaSvcHandle *handle, const char *storage_id, const char *path, int *storage_status) +{ + int ret = MS_MEDIA_ERR_NONE; + sqlite3 * db_handle = (sqlite3 *)handle; + + media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL"); + media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL"); + + ret = _media_svc_get_folder_scan_status(db_handle, storage_id, path, storage_status); + + return ret; +} + +int media_svc_set_folder_scan_status(const char *storage_id, const char *path, int storage_status, uid_t uid) +{ + int ret = MS_MEDIA_ERR_NONE; + + ret = _media_svc_set_folder_scan_status(storage_id, path, storage_status, uid); + + return ret; +} + +int media_svc_get_folder_modified_time(MediaSvcHandle *handle, const char *path, const char *storage_id, bool *modified) +{ + int ret = MS_MEDIA_ERR_NONE; + sqlite3 * db_handle = (sqlite3 *)handle; + time_t modified_time = 0; + int system_time = 0; + + media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL"); + + ret = _media_svc_get_folder_modified_time_by_path(db_handle, path, storage_id, &modified_time); + + system_time = _media_svc_get_file_time(path); + media_svc_error("modified_time = [%d], system_time = [%d], path = [%s]", modified_time, system_time, path); + + if (system_time != modified_time && system_time != 0) { + *modified = TRUE; + } else { + *modified = FALSE; + } + + return ret; +} + +int media_svc_get_null_scan_folder_list(MediaSvcHandle *handle, char *storage_id, char* folder_path, char ***folder_list, int *count) +{ + sqlite3 * db_handle = (sqlite3 *)handle; + + media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL"); + media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL"); + + return _media_svc_get_null_scan_folder_list(db_handle, storage_id, folder_path, folder_list, count); +} + +int media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid) +{ + media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL"); + media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL"); + + return _media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid); +} + int media_svc_delete_invalid_folder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count) { int ret = MS_MEDIA_ERR_NONE; diff --git a/src/include/common/media-svc-media-folder.h b/src/include/common/media-svc-media-folder.h index 17c5899..3a48652 100755 --- a/src/include/common/media-svc-media-folder.h +++ b/src/include/common/media-svc-media-folder.h @@ -38,10 +38,14 @@ int _media_svc_delete_invalid_folder(const char *storage_id, uid_t uid); int _media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid); int _media_svc_delete_folder_by_storage_id(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid); GList ** _media_svc_get_folder_list_ptr(void); + +int _media_svc_get_folder_scan_status(sqlite3 *handle, const char *storage_id, const char *path, int *scan_status); +int _media_svc_set_folder_scan_status(const char *storage_id, const char *path, int scan_status, uid_t uid); +int _media_svc_get_folder_modified_time_by_path(sqlite3 *handle, const char *path, const char *storage_id, time_t *modified_time); +int _media_svc_get_null_scan_folder_list(sqlite3 *handle, char *storage_id, char *path, char ***folder_list, int *count); int _media_svc_delete_invalid_folder_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path, uid_t uid, int *del_count); int _media_svc_count_folder_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count); int _media_svc_count_subfolder_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count); int _media_svc_get_folder_uuid(sqlite3 *handle, const char *storage_id, const char *path, char *folder_id); - #endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/ diff --git a/src/include/common/media-svc-media.h b/src/include/common/media-svc-media.h index 2db1fff..414b716 100755 --- a/src/include/common/media-svc-media.h +++ b/src/include/common/media-svc-media.h @@ -52,6 +52,7 @@ char *_media_svc_get_thumb_default_path(uid_t uid); int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size); int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info); +int _media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid); int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid); int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid); diff --git a/src/include/common/media-svc-storage.h b/src/include/common/media-svc-storage.h index 5acb354..0118abd 100755 --- a/src/include/common/media-svc-storage.h +++ b/src/include/common/media-svc-storage.h @@ -38,5 +38,4 @@ int _media_svc_get_storage_scan_status(sqlite3 *handle, const char*storage_id, m int _media_svc_set_storage_scan_status(const char*storage_id, media_svc_scan_status_type_e scan_status, uid_t uid); int _media_svc_get_all_storage(sqlite3 *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count); - #endif /*_MEDIA_SVC_STORAGE_H_*/ diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h index 6784ab3..4b7474f 100755 --- a/src/include/common/media-svc-util.h +++ b/src/include/common/media-svc-util.h @@ -74,7 +74,6 @@ int _media_svc_get_ini_value(); char *_media_svc_get_title_from_path(const char *path); void _media_svc_print_stderror(void); - #ifdef __cplusplus } #endif