4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <drm_client.h>
24 #include <media-util.h>
25 #include "media-svc.h"
26 #include "media-svc-media.h"
27 #include "media-svc-debug.h"
28 #include "media-svc-util.h"
29 #include "media-svc-db-utils.h"
30 #include "media-svc-media-folder.h"
31 #include "media-svc-album.h"
32 #include "media-svc-noti.h"
34 static __thread int g_media_svc_item_validity_data_cnt = 1;
35 static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
37 static __thread int g_media_svc_move_item_data_cnt = 1;
38 static __thread int g_media_svc_move_item_cur_data_cnt = 0;
40 static __thread int g_media_svc_insert_item_data_cnt = 1;
41 static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
43 /* Flag for items to be published by notification */
44 static __thread int g_insert_with_noti = FALSE;
46 int media_svc_connect(MediaSvcHandle **handle)
48 int ret = MEDIA_INFO_ERROR_NONE;
49 MediaDBHandle *db_handle = NULL;
51 media_svc_debug_func();
53 #if 1 //Use libmedia_utils API
54 ret = media_db_connect(&db_handle);
55 if(ret != MS_MEDIA_ERR_NONE)
56 return _media_svc_error_convert(ret);
59 sqlite3 * db_handle = NULL;
61 ret = _media_svc_connect_db_with_handle(&db_handle);
62 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
66 return MEDIA_INFO_ERROR_NONE;
70 int media_svc_disconnect(MediaSvcHandle *handle)
72 MediaDBHandle * db_handle = (MediaDBHandle *)handle;
74 media_svc_debug_func();
76 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
78 #if 1 //Use libmedia_utils API
79 int ret = MEDIA_INFO_ERROR_NONE;
81 ret = media_db_disconnect(db_handle);
82 return _media_svc_error_convert(ret);
84 sqlite3 * db_handle = (sqlite3 *)handle;
86 return _media_svc_disconnect_db_with_handle(db_handle);
90 int media_svc_create_table(MediaSvcHandle *handle)
92 int ret = MEDIA_INFO_ERROR_NONE;
93 sqlite3 * db_handle = (sqlite3 *)handle;
95 media_svc_debug_func();
97 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
99 /*create media table*/
100 ret = _media_svc_create_media_table(handle);
101 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
103 /*create folder table*/
104 ret = _media_svc_create_folder_table(handle);
105 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
107 /*create playlist table*/
108 ret = _media_svc_create_playlist_table(handle);
109 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
111 /* create album table*/
112 ret = _media_svc_create_album_table(handle);
113 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
116 ret = _media_svc_create_tag_table(handle);
117 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
119 /*create bookmark table*/
120 ret = _media_svc_create_bookmark_table(handle);
121 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
123 #if 0 /*unify media and custom table*/
124 /*create custom table*/
125 ret = _media_svc_create_custom_table(handle);
126 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
129 return MEDIA_INFO_ERROR_NONE;
132 int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type)
134 int ret = MEDIA_INFO_ERROR_NONE;
135 media_svc_storage_type_e type;
137 ret = _media_svc_get_store_type_by_path(path, &type);
138 media_svc_retvm_if(ret < MEDIA_INFO_ERROR_NONE, ret, "_media_svc_get_store_type_by_path failed : %d", ret);
140 *storage_type = type;
145 int media_svc_get_mime_type(const char *path, char *mimetype)
147 int ret = MEDIA_INFO_ERROR_NONE;
148 drm_bool_type_e is_drm = DRM_FALSE;
149 drm_content_info_s *drm_contentInfo = NULL;
151 ret = _media_svc_get_mime_type(path, mimetype, &is_drm, &drm_contentInfo);
153 SAFE_FREE(drm_contentInfo);
158 int media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
160 int ret = MEDIA_INFO_ERROR_NONE;
162 ret = _media_svc_get_media_type(path, mime_type, media_type);
167 int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *path)
169 int ret = MEDIA_INFO_ERROR_NONE;
170 sqlite3 * db_handle = (sqlite3 *)handle;
173 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
174 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "Path is NULL");
176 ret = _media_svc_count_record_with_path(db_handle, path, &count);
177 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
180 media_svc_debug("item is exist in database");
181 return MEDIA_INFO_ERROR_NONE;
183 media_svc_debug("item is not exist in database");
184 return MEDIA_INFO_ERROR_DATABASE_NO_RECORD;
187 return MEDIA_INFO_ERROR_NONE;
190 int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt, int with_noti, int from_pid)
192 sqlite3 * db_handle = (sqlite3 *)handle;
194 media_svc_debug("Transaction data count : [%d]", data_cnt);
196 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
197 media_svc_retvm_if(data_cnt < 1, MEDIA_INFO_ERROR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
199 g_media_svc_insert_item_data_cnt = data_cnt;
200 g_media_svc_insert_item_cur_data_cnt = 0;
202 /* Prepare for making noti item list */
204 media_svc_debug("making noti list from pid[%d]", from_pid);
205 if (_media_svc_create_noti_list(data_cnt) != MEDIA_INFO_ERROR_NONE) {
206 return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
209 _media_svc_set_noti_from_pid(from_pid);
210 g_insert_with_noti = TRUE;
213 return MEDIA_INFO_ERROR_NONE;
216 int media_svc_insert_item_end(MediaSvcHandle *handle)
218 int ret = MEDIA_INFO_ERROR_NONE;
219 sqlite3 * db_handle = (sqlite3 *)handle;
221 media_svc_debug_func();
223 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
225 if (g_media_svc_insert_item_cur_data_cnt > 0) {
227 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
228 if (g_insert_with_noti) {
229 media_svc_debug("sending noti list");
230 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
231 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
232 g_insert_with_noti = FALSE;
233 _media_svc_set_noti_from_pid(-1);
237 g_media_svc_insert_item_data_cnt = 1;
238 g_media_svc_insert_item_cur_data_cnt = 0;
243 int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst)
245 int ret = MEDIA_INFO_ERROR_NONE;
246 sqlite3 * db_handle = (sqlite3 *)handle;
247 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
248 media_svc_media_type_e media_type;
249 drm_content_info_s *drm_contentInfo = NULL;
251 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
252 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
254 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
255 media_svc_error("storage type is incorrect[%d]", storage_type);
256 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
259 media_svc_content_info_s content_info;
260 memset(&content_info, 0, sizeof(media_svc_content_info_s));
263 /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
264 ret = _media_svc_set_media_info(&content_info, storage_type, path, &media_type, FALSE, &drm_contentInfo);
265 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
267 if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
269 } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
270 ret = _media_svc_extract_image_metadata(&content_info, media_type);
272 ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo);
274 SAFE_FREE(drm_contentInfo);
275 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
277 /*Set or Get folder id*/
278 ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid);
279 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
281 ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
282 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
284 if (g_media_svc_insert_item_data_cnt == 1) {
286 ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, FALSE);
287 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
289 if (g_insert_with_noti)
290 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
292 } else if(g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
294 ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE);
295 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
297 if (g_insert_with_noti)
298 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
300 g_media_svc_insert_item_cur_data_cnt ++;
302 } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
304 ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE);
305 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
307 if (g_insert_with_noti)
308 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
310 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
311 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
313 if (g_insert_with_noti) {
314 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
315 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
317 /* Recreate noti list */
318 if (_media_svc_create_noti_list(g_media_svc_insert_item_data_cnt) != MEDIA_INFO_ERROR_NONE) {
319 return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
323 g_media_svc_insert_item_cur_data_cnt = 0;
326 media_svc_error("Error in media_svc_insert_item_bulk");
327 _media_svc_destroy_content_info(&content_info);
328 return MEDIA_INFO_ERROR_INTERNAL;
331 _media_svc_destroy_content_info(&content_info);
333 return MEDIA_INFO_ERROR_NONE;
336 int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
338 int ret = MEDIA_INFO_ERROR_NONE;
339 sqlite3 * db_handle = (sqlite3 *)handle;
340 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
341 media_svc_media_type_e media_type;
342 drm_content_info_s *drm_contentInfo = NULL;
344 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
345 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
347 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
348 media_svc_error("storage type is incorrect[%d]", storage_type);
349 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
352 media_svc_content_info_s content_info;
353 memset(&content_info, 0, sizeof(media_svc_content_info_s));
356 ret = _media_svc_set_media_info(&content_info, storage_type, path, &media_type, FALSE, &drm_contentInfo);
357 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
359 if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
361 } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
362 ret = _media_svc_extract_image_metadata(&content_info, media_type);
363 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
365 ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo);
366 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
369 /*Set or Get folder id*/
370 ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid);
371 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
373 ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
374 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
376 /* Extracting thumbnail */
377 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
378 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
382 ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height);
384 media_svc_error("thumbnail_request_from_db failed: %d", ret);
386 media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
387 ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
388 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
391 if (content_info.media_meta.width <= 0)
392 content_info.media_meta.width = width;
394 if (content_info.media_meta.height <= 0)
395 content_info.media_meta.height = height;
398 ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE);
400 if (ret == MEDIA_INFO_ERROR_NONE) {
401 media_svc_debug("Insertion is successful. Sending noti for this");
402 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
405 _media_svc_destroy_content_info(&content_info);
409 int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
411 int ret = MEDIA_INFO_ERROR_NONE;
412 sqlite3 * db_handle = (sqlite3 *)handle;
414 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
415 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
417 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
418 media_svc_error("storage type is incorrect[%d]", storage_type);
419 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
422 media_svc_debug("storage[%d], folder_path[%s]", storage_type, path);
425 char *folder_name = NULL;
426 int folder_modified_date = 0;
427 char *folder_uuid = _media_info_generate_uuid();
428 if(folder_uuid == NULL ) {
429 media_svc_error("Invalid UUID");
430 return MEDIA_INFO_ERROR_INTERNAL;
433 folder_name = g_path_get_basename(path);
434 folder_modified_date = _media_svc_get_file_time(path);
436 ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date);
437 SAFE_FREE(folder_name);
439 if (ret < MEDIA_INFO_ERROR_NONE) {
440 media_svc_error("_media_svc_append_folder error [%d]", ret);
444 return MEDIA_INFO_ERROR_NONE;
447 int media_svc_move_item_begin(MediaSvcHandle *handle, int data_cnt)
449 sqlite3 * db_handle = (sqlite3 *)handle;
451 media_svc_debug("Transaction data count : [%d]", data_cnt);
453 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
454 media_svc_retvm_if(data_cnt < 1, MEDIA_INFO_ERROR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
456 g_media_svc_move_item_data_cnt = data_cnt;
457 g_media_svc_move_item_cur_data_cnt = 0;
459 return MEDIA_INFO_ERROR_NONE;
462 int media_svc_move_item_end(MediaSvcHandle *handle)
464 int ret = MEDIA_INFO_ERROR_NONE;
465 sqlite3 * db_handle = (sqlite3 *)handle;
467 media_svc_debug_func();
469 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
471 if (g_media_svc_move_item_cur_data_cnt > 0) {
473 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM);
476 /*clean up old folder path*/
477 ret = _media_svc_update_folder_table(handle);
478 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
480 g_media_svc_move_item_data_cnt = 1;
481 g_media_svc_move_item_cur_data_cnt = 0;
486 int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path,
487 media_svc_storage_type_e dest_storage, const char *dest_path)
489 int ret = MEDIA_INFO_ERROR_NONE;
490 sqlite3 * db_handle = (sqlite3 *)handle;
491 char *file_name = NULL;
492 char *folder_path = NULL;
493 int modified_time = 0;
494 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
495 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0,};
496 char new_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0,};
499 media_svc_debug_func();
501 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
502 media_svc_retvm_if(!STRING_VALID(src_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "src_path is NULL");
503 media_svc_retvm_if(!STRING_VALID(dest_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "dest_path is NULL");
505 if ((src_storage != MEDIA_SVC_STORAGE_INTERNAL) && (src_storage != MEDIA_SVC_STORAGE_EXTERNAL)) {
506 media_svc_error("src_storage type is incorrect[%d]", src_storage);
507 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
509 if ((dest_storage != MEDIA_SVC_STORAGE_INTERNAL) && (dest_storage != MEDIA_SVC_STORAGE_EXTERNAL)) {
510 media_svc_error("dest_storage type is incorrect[%d]", dest_storage);
511 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
514 /*check and update folder*/
515 ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid);
516 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
519 file_name = g_path_get_basename(dest_path);
521 /*get modified_time*/
522 modified_time = _media_svc_get_file_time(dest_path);
524 /*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
525 ret = _media_svc_get_media_type_by_path(handle, src_path, &media_type);
526 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
528 if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
529 /*get old thumbnail_path*/
530 ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
531 media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
533 _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT);
536 if (g_media_svc_move_item_data_cnt == 1) {
539 if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
540 ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE);
542 ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE);
544 SAFE_FREE(file_name);
545 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
547 media_svc_debug("Move is successful. Sending noti for this");
549 /* Get notification info */
550 media_svc_noti_item *noti_item = NULL;
551 ret = _media_svc_get_noti_info(handle, dest_path, MS_MEDIA_ITEM_FILE, ¬i_item);
552 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
554 /* Send notification for move */
555 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
556 _media_svc_destroy_noti_item(noti_item);
558 /*update folder modified_time*/
559 folder_path = g_path_get_dirname(dest_path);
560 ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE);
561 SAFE_FREE(folder_path);
562 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
564 ret = _media_svc_update_folder_table(handle);
565 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
567 } else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) {
570 if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
571 ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE);
573 ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE);
575 SAFE_FREE(file_name);
576 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
578 /*update folder modified_time*/
579 folder_path = g_path_get_dirname(dest_path);
580 ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE);
581 SAFE_FREE(folder_path);
582 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
584 g_media_svc_move_item_cur_data_cnt ++;
586 } else if (g_media_svc_move_item_cur_data_cnt == (g_media_svc_move_item_data_cnt - 1)) {
589 if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
590 ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE);
592 ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE);
594 SAFE_FREE(file_name);
595 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
597 /*update folder modified_time*/
598 folder_path = g_path_get_dirname(dest_path);
599 ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE);
600 SAFE_FREE(folder_path);
601 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
604 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM);
605 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
607 g_media_svc_move_item_cur_data_cnt = 0;
610 media_svc_error("Error in media_svc_move_item");
611 return MEDIA_INFO_ERROR_INTERNAL;
614 /*rename thumbnail file*/
615 if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
616 if(strlen(old_thumb_path) > 0) {
617 ret = _media_svc_rename_file(old_thumb_path,new_thumb_path);
618 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
622 return MEDIA_INFO_ERROR_NONE;
625 int media_svc_set_item_validity_begin(MediaSvcHandle *handle, int data_cnt)
627 sqlite3 * db_handle = (sqlite3 *)handle;
629 media_svc_debug("Transaction data count : [%d]", data_cnt);
631 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
632 media_svc_retvm_if(data_cnt < 1, MEDIA_INFO_ERROR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
634 g_media_svc_item_validity_data_cnt = data_cnt;
635 g_media_svc_item_validity_cur_data_cnt = 0;
637 return MEDIA_INFO_ERROR_NONE;
640 int media_svc_set_item_validity_end(MediaSvcHandle *handle)
642 int ret = MEDIA_INFO_ERROR_NONE;
643 sqlite3 * db_handle = (sqlite3 *)handle;
645 media_svc_debug_func();
647 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
649 if (g_media_svc_item_validity_cur_data_cnt > 0) {
651 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY);
654 g_media_svc_item_validity_data_cnt = 1;
655 g_media_svc_item_validity_cur_data_cnt = 0;
660 int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity)
662 int ret = MEDIA_INFO_ERROR_NONE;
663 sqlite3 * db_handle = (sqlite3 *)handle;
665 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
666 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
668 media_svc_debug("path=[%s], validity=[%d]", path, validity);
670 if (g_media_svc_item_validity_data_cnt == 1) {
672 return _media_svc_update_item_validity(db_handle, path, validity, FALSE);
674 } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
676 ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE);
677 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
679 g_media_svc_item_validity_cur_data_cnt ++;
681 } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
683 ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE);
684 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
686 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY);
687 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
689 g_media_svc_item_validity_cur_data_cnt = 0;
693 media_svc_error("Error in media_svc_set_item_validity");
694 return MEDIA_INFO_ERROR_INTERNAL;
697 return MEDIA_INFO_ERROR_NONE;
700 int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path)
702 int ret = MEDIA_INFO_ERROR_NONE;
703 sqlite3 * db_handle = (sqlite3 *)handle;
704 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0,};
706 media_svc_debug_func();
708 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
709 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
712 ret = _media_svc_get_media_type_by_path(db_handle, path, &media_type);
713 media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE), ret);
715 if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
716 /*Get thumbnail path to delete*/
717 ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
718 media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
719 } else if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
721 ret = _media_svc_get_media_count_with_album_id_by_path(db_handle, path, &count);
722 media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE), ret);
725 /*Get thumbnail path to delete*/
726 ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
727 media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
731 /* Get notification info */
732 media_svc_noti_item *noti_item = NULL;
733 ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, ¬i_item);
734 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
737 ret = _media_svc_delete_item_by_path(db_handle, path);
738 if (ret != MEDIA_INFO_ERROR_NONE) {
739 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
740 _media_svc_destroy_noti_item(noti_item);
745 /* Send notification */
746 media_svc_debug("Deletion is successful. Sending noti for this");
747 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
748 _media_svc_destroy_noti_item(noti_item);
751 if (strlen(thumb_path) > 0) {
752 if (_media_svc_remove_file(thumb_path) == FALSE) {
753 media_svc_error("fail to remove thumbnail file.");
757 return MEDIA_INFO_ERROR_NONE;
760 int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type)
762 int ret = MEDIA_INFO_ERROR_NONE;
763 sqlite3 * db_handle = (sqlite3 *)handle;
764 char * dirpath = NULL;
766 media_svc_debug("media_svc_delete_all_items_in_storage [%d]", storage_type);
768 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
770 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
771 media_svc_error("storage type is incorrect[%d]", storage_type);
772 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
775 ret = _media_svc_truncate_table(db_handle, storage_type);
776 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
778 dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
780 /* remove thumbnails */
781 ret = _media_svc_remove_all_files_in_dir(dirpath);
782 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
784 return MEDIA_INFO_ERROR_NONE;
787 int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type)
789 sqlite3 * db_handle = (sqlite3 *)handle;
791 media_svc_debug_func();
793 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
795 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
796 media_svc_error("storage type is incorrect[%d]", storage_type);
797 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
800 /*Delete from DB and remove thumbnail files*/
801 return _media_svc_delete_invalid_items(db_handle, storage_type);
804 int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path)
806 sqlite3 * db_handle = (sqlite3 *)handle;
808 media_svc_debug_func();
810 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
812 /*Delete from DB and remove thumbnail files*/
813 return _media_svc_delete_invalid_folder_items(db_handle, folder_path);
816 int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity)
818 sqlite3 * db_handle = (sqlite3 *)handle;
820 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
822 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
823 media_svc_error("storage type is incorrect[%d]", storage_type);
824 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
827 return _media_svc_update_storage_item_validity(db_handle, storage_type, validity);
830 int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive)
832 sqlite3 * db_handle = (sqlite3 *)handle;
834 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
835 media_svc_retvm_if(!STRING_VALID(folder_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "folder_path is NULL");
838 return _media_svc_update_recursive_folder_item_validity(db_handle, folder_path, validity);
840 return _media_svc_update_folder_item_validity(db_handle, folder_path, validity);
843 int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
845 int ret = MEDIA_INFO_ERROR_NONE;
846 sqlite3 * db_handle = (sqlite3 *)handle;
847 media_svc_media_type_e media_type;
848 drm_content_info_s *drm_contentInfo = NULL;
850 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
851 media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
853 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
854 media_svc_error("storage type is incorrect[%d]", storage_type);
855 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
858 /* Get notification info */
859 media_svc_noti_item *noti_item = NULL;
860 ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, ¬i_item);
861 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
863 media_svc_content_info_s content_info;
864 memset(&content_info, 0, sizeof(media_svc_content_info_s));
867 ret = _media_svc_set_media_info(&content_info, storage_type, path, &media_type, TRUE, &drm_contentInfo);
868 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
870 /* Initialize thumbnail information to remake thumbnail. */
871 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
872 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
873 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
875 if (g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
876 ret = _media_svc_remove_file(thumb_path);
877 media_svc_retv_if(ret != TRUE, ret);
880 ret = _media_svc_update_thumbnail_path(handle, path, NULL);
881 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
883 if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
885 } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
886 ret = _media_svc_extract_image_metadata(&content_info, media_type);
887 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
889 ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo);
890 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
893 /* Extracting thumbnail */
894 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
895 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
899 ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height);
901 media_svc_error("thumbnail_request_from_db failed: %d", ret);
903 media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
904 ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
905 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
908 if (content_info.media_meta.width <= 0)
909 content_info.media_meta.width = width;
911 if (content_info.media_meta.height <= 0)
912 content_info.media_meta.height = height;
915 ret = _media_svc_update_item_with_data(db_handle, &content_info);
917 if (ret == MEDIA_INFO_ERROR_NONE) {
918 media_svc_debug("Update is successful. Sending noti for this");
919 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, media_type, noti_item->media_uuid, noti_item->mime_type);
921 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
924 _media_svc_destroy_content_info(&content_info);
925 _media_svc_destroy_noti_item(noti_item);
930 int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path)
932 sqlite3 * db_handle = (sqlite3 *)handle;
933 int ret = MEDIA_INFO_ERROR_NONE;
935 media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
936 media_svc_retvm_if(src_path == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "src_path is NULL");
937 media_svc_retvm_if(dst_path == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "dst_path is NULL");
939 media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);
941 /* Get notification info */
942 media_svc_noti_item *noti_item = NULL;
943 ret = _media_svc_get_noti_info(handle, src_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
944 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
946 ret = _media_svc_sql_begin_trans(handle);
947 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
949 /* Update all folder record's path, which are matched by old parent path */
950 char *update_folder_path_sql = NULL;
951 char src_path_slash[MEDIA_SVC_PATHNAME_SIZE + 1];
952 char dst_path_slash[MEDIA_SVC_PATHNAME_SIZE + 1];
954 snprintf(src_path_slash, sizeof(src_path_slash), "%s/", src_path);
955 snprintf(dst_path_slash, sizeof(dst_path_slash), "%s/", dst_path);
957 update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash);
959 //ret = _media_svc_sql_query(handle, update_folder_path_sql);
960 ret = media_db_request_update_db_batch(update_folder_path_sql);
961 sqlite3_free(update_folder_path_sql);
963 if (ret != SQLITE_OK) {
964 media_svc_error("failed to update folder path");
965 _media_svc_sql_rollback_trans(handle);
967 return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
970 /* Update all folder record's modified date, which are changed above */
971 char *update_folder_modified_time_sql = NULL;
975 update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d where path like '%q';", date, dst_path);
977 ret = media_db_request_update_db_batch(update_folder_modified_time_sql);
978 //ret = _media_svc_sql_query(handle, update_folder_modified_time_sql);
979 sqlite3_free(update_folder_modified_time_sql);
981 if (ret != SQLITE_OK) {
982 media_svc_error("failed to update folder modified time");
983 _media_svc_sql_rollback_trans(handle);
985 return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
988 /* Update all items */
989 char *select_all_sql = NULL;
990 sqlite3_stmt *sql_stmt = NULL;
991 char dst_child_path[MEDIA_SVC_PATHNAME_SIZE + 1];
993 snprintf(dst_child_path, sizeof(dst_child_path), "%s/%%", dst_path);
995 select_all_sql = sqlite3_mprintf("SELECT media_uuid, path, thumbnail_path, media_type from media where folder_uuid IN ( SELECT folder_uuid FROM folder where path='%q' or path like '%q');", dst_path, dst_child_path);
997 media_svc_debug("[SQL query] : %s", select_all_sql);
999 ret = sqlite3_prepare_v2(handle, select_all_sql, -1, &sql_stmt, NULL);
1000 sqlite3_free((char *)select_all_sql);
1002 if (ret != SQLITE_OK) {
1003 media_svc_error ("prepare error [%s]", sqlite3_errmsg(handle));
1004 _media_svc_sql_rollback_trans(handle);
1005 return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
1009 ret = sqlite3_step(sql_stmt);
1010 if (ret != SQLITE_ROW) {
1011 media_svc_debug("end of iteration");
1015 char media_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0,};
1016 char media_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
1017 char media_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
1018 char media_new_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
1020 bool no_thumb = FALSE;
1022 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
1023 strncpy(media_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(media_uuid));
1024 media_uuid[sizeof(media_uuid) - 1] = '\0';
1026 media_svc_error("media UUID is NULL");
1027 return MEDIA_INFO_ERROR_DATABASE_INVALID;
1030 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) {
1031 strncpy(media_path, (const char *)sqlite3_column_text(sql_stmt, 1), sizeof(media_path));
1032 media_path[sizeof(media_path) - 1] = '\0';
1034 media_svc_error("media path is NULL");
1035 return MEDIA_INFO_ERROR_DATABASE_INVALID;
1038 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2))) {
1039 strncpy(media_thumb_path, (const char *)sqlite3_column_text(sql_stmt, 2), sizeof(media_thumb_path));
1040 media_thumb_path[sizeof(media_thumb_path) - 1] = '\0';
1042 media_svc_debug("media thumb path doesn't exist in DB");
1046 media_type = sqlite3_column_int(sql_stmt, 3);
1048 /* Update path, thumbnail path of this item */
1049 char *replaced_path = NULL;
1050 replaced_path = _media_svc_replace_path(media_path, src_path, dst_path);
1051 if (replaced_path == NULL) {
1052 media_svc_error("_media_svc_replace_path failed");
1053 SQLITE3_FINALIZE(sql_stmt);
1054 _media_svc_sql_rollback_trans(handle);
1055 return MEDIA_INFO_ERROR_INTERNAL;
1058 media_svc_debug("New media path : %s", replaced_path);
1059 media_svc_storage_type_e storage_type;
1062 ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type);
1064 media_svc_error("_media_svc_get_store_type_by_path failed : %d", ret);
1065 SAFE_FREE(replaced_path);
1066 _media_svc_sql_rollback_trans(handle);
1067 return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
1070 ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT);
1072 media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
1073 SAFE_FREE(replaced_path);
1074 SQLITE3_FINALIZE(sql_stmt);
1075 _media_svc_sql_rollback_trans(handle);
1076 return MEDIA_INFO_ERROR_INTERNAL;
1079 //media_svc_debug("New media thumbnail path : %s", media_new_thumb_path);
1082 char *update_item_sql = NULL;
1085 update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q' WHERE media_uuid='%q'", replaced_path, media_uuid);
1087 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1088 update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
1090 update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_thumb_path, media_uuid);
1094 ret = media_db_request_update_db_batch(update_item_sql);
1095 //ret = _media_svc_sql_query(handle, update_item_sql);
1096 sqlite3_free(update_item_sql);
1097 SAFE_FREE(replaced_path);
1099 if (ret != SQLITE_OK) {
1100 media_svc_error("failed to update item");
1101 SQLITE3_FINALIZE(sql_stmt);
1102 _media_svc_sql_rollback_trans(handle);
1104 return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
1107 /* Rename thumbnail file of file system */
1108 if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
1109 ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
1111 media_svc_error("_media_svc_rename_file failed : %d", ret);
1112 SQLITE3_FINALIZE(sql_stmt);
1113 _media_svc_sql_rollback_trans(handle);
1115 return MEDIA_INFO_ERROR_INTERNAL;
1120 SQLITE3_FINALIZE(sql_stmt);
1122 ret = _media_svc_sql_end_trans(handle);
1123 if (ret != MEDIA_INFO_ERROR_NONE) {
1124 media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n");
1125 _media_svc_sql_rollback_trans(handle);
1129 media_svc_debug("Folder update is successful. Sending noti for this");
1130 _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, src_path, -1, noti_item->media_uuid, NULL);
1131 _media_svc_destroy_noti_item(noti_item);
1133 return MEDIA_INFO_ERROR_NONE;
1136 int media_svc_request_update_db(const char *db_query)
1138 int ret = MEDIA_INFO_ERROR_NONE;
1140 media_svc_retvm_if(!STRING_VALID(db_query), MEDIA_INFO_ERROR_INVALID_PARAMETER, "db_query is NULL");
1142 ret = _media_svc_request_update_db(db_query);
1144 return _media_svc_error_convert(ret);
1147 int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *dir_path)
1149 int ret = MEDIA_INFO_ERROR_NONE;
1150 sqlite3 * db_handle = (sqlite3 *)handle;
1152 media_svc_retvm_if(!STRING_VALID(dir_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "dir_path is NULL");
1154 /* Get notification info */
1155 media_svc_noti_item *noti_item = NULL;
1156 ret = _media_svc_get_noti_info(db_handle, dir_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
1157 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
1159 ret = _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, dir_path, -1, noti_item->media_uuid, NULL);
1160 _media_svc_destroy_noti_item(noti_item);