static __thread int g_media_svc_insert_item_data_cnt = 1;
static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
-static __thread int g_media_svc_update_item_data_cnt = 1;
-static __thread int g_media_svc_update_item_cur_data_cnt = 0;
-
/* Flag for items to be published by notification */
static __thread bool g_insert_with_noti = false;
return _media_svc_check_db_upgrade(handle, user_version, uid);
}
-int media_svc_update_item_begin(int data_cnt)
+static void __media_svc_noti_all_storage(sqlite3 *handle, uid_t uid)
{
- media_svc_debug("Transaction data count : [%d]", data_cnt);
-
- media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
+ int ret = MS_MEDIA_ERR_NONE;
+ char *root_path = NULL;
+ GArray *path_list = NULL;
- g_media_svc_update_item_data_cnt = data_cnt;
- g_media_svc_update_item_cur_data_cnt = 0;
+ ms_user_get_internal_root_path(uid, &root_path);
+ ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_UPDATE, root_path, NULL, 0);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("Fail to send noti");
- return MS_MEDIA_ERR_NONE;
-}
+ SAFE_FREE(root_path);
-int media_svc_update_item_end(uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
+ path_list = g_array_new(FALSE, FALSE, sizeof(char *));
+ _media_svc_get_storage_path(handle, &path_list);
- media_svc_debug_fenter();
+ while (path_list->len != 0) {
+ root_path = g_array_index(path_list , char *, 0);
+ g_array_remove_index(path_list, 0);
- if (g_media_svc_update_item_cur_data_cnt > 0)
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+ ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_UPDATE, root_path, NULL, 0);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("Fail to send noti");
- g_media_svc_update_item_data_cnt = 1;
- g_media_svc_update_item_cur_data_cnt = 0;
+ SAFE_FREE(root_path);
+ }
- return ret;
+ g_array_free(path_list, false);
}
-int media_svc_update_item_meta(const char *file_path, const char *storage_id, int storage_type, uid_t uid)
+int media_svc_update_item_meta(sqlite3 *handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
+ /* NOTICE : After 6.0, change 'media_view' to 'media', add 'AND validity=1', and no need storage id */
+ char *sql = NULL;
media_svc_content_info_s content_info;
- memset(&content_info, 0, sizeof(media_svc_content_info_s));
+ media_svc_file_s *file_info = NULL;
+ GArray *path_list = NULL;
- /*Set media info*/
- ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, file_path, false);
- if (ret != MS_MEDIA_ERR_NONE)
- return ret;
-
- if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)
- ret = _media_svc_extract_music_metadata_for_update(&content_info, content_info.media_type);
- else {
- _media_svc_destroy_content_info(&content_info);
- return MS_MEDIA_ERR_NONE;
- }
+ path_list = g_array_new(FALSE, FALSE, sizeof(media_svc_file_s *));
+ media_svc_retvm_if(!path_list, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
+ sql = sqlite3_mprintf("SELECT media_path, storage_uuid FROM %q WHERE media_type=3", MEDIA_SVC_DB_VIEW_MEDIA);
+ ret = _media_svc_get_media(handle, sql, &path_list);
if (ret != MS_MEDIA_ERR_NONE) {
- _media_svc_destroy_content_info(&content_info);
+ media_svc_error("Fail to get media list");
+ g_array_free(path_list, false);
return ret;
}
- if (g_media_svc_update_item_data_cnt == 1) {
-
- ret = _media_svc_update_meta_with_data(&content_info);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- } else if (g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {
+ while (path_list->len != 0) {
+ file_info = g_array_index(path_list, media_svc_file_s *, 0);
+ g_array_remove_index(path_list, 0);
- ret = _media_svc_update_meta_with_data(&content_info);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- g_media_svc_update_item_cur_data_cnt++;
-
- } else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {
+ memset(&content_info, 0, sizeof(media_svc_content_info_s));
+ ret = _media_svc_extract_music_metadata_for_update(&content_info, file_info->storage_id, file_info->path);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to extract metadata");
+ _media_svc_destroy_content_info(&content_info);
+ SAFE_FREE(file_info);
+ continue;
+ }
ret = _media_svc_update_meta_with_data(&content_info);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- g_media_svc_update_item_cur_data_cnt = 0;
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("Fail to append item[%s]", content_info.path);
- } else {
- media_svc_error("Error in media_svc_update_item_meta");
_media_svc_destroy_content_info(&content_info);
- return MS_MEDIA_ERR_INTERNAL;
+ SAFE_FREE(file_info);
}
- _media_svc_destroy_content_info(&content_info);
+ g_array_free(path_list, false);
+
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_list_query_do failed");
+
+ /* Noti for this */
+ __media_svc_noti_all_storage(handle, uid);
return ret;
}