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.
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-env.h"
31 #include "media-svc-media-folder.h"
32 #include "media-svc-album.h"
33 #include "media-svc-noti.h"
34 #include "media-svc-storage.h"
36 static __thread int g_media_svc_item_validity_data_cnt = 1;
37 static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
39 static __thread int g_media_svc_move_item_data_cnt = 1;
40 static __thread int g_media_svc_move_item_cur_data_cnt = 0;
42 static __thread int g_media_svc_insert_item_data_cnt = 1;
43 static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
45 static __thread int g_media_svc_update_item_data_cnt = 1;
46 static __thread int g_media_svc_update_item_cur_data_cnt = 0;
48 static __thread int g_media_svc_insert_folder_data_cnt = 1;
49 static __thread int g_media_svc_insert_folder_cur_data_cnt = 0;
51 /* Flag for items to be published by notification */
52 static __thread int g_insert_with_noti = FALSE;
54 #define BATCH_REQUEST_MAX 300
58 } media_svc_item_info_s;
60 static bool __media_svc_check_storage(media_svc_storage_type_e storage_type)
62 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL)
63 && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)
64 && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)) {
65 media_svc_error("storage type is incorrect[%d]", storage_type);
72 int media_svc_connect(MediaSvcHandle **handle, uid_t uid, bool need_write)
74 int ret = MS_MEDIA_ERR_NONE;
75 MediaDBHandle *db_handle = NULL;
77 media_svc_debug_fenter();
79 ret = media_db_connect(&db_handle, uid, need_write);
80 if (ret != MS_MEDIA_ERR_NONE)
84 return MS_MEDIA_ERR_NONE;
87 int media_svc_disconnect(MediaSvcHandle *handle)
89 MediaDBHandle *db_handle = (MediaDBHandle *)handle;
91 media_svc_debug_fenter();
93 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
95 int ret = MS_MEDIA_ERR_NONE;
97 ret = media_db_disconnect(db_handle);
101 int media_svc_get_user_version(MediaSvcHandle *handle, int *user_version)
103 sqlite3 *db_handle = (sqlite3 *)handle;
105 return _media_svc_get_user_version(db_handle, user_version);
108 int media_svc_create_table(uid_t uid)
110 int ret = MS_MEDIA_ERR_NONE;
113 media_svc_debug_fenter();
115 ret = _media_svc_init_table_query(MEDIA_SVC_DB_TABLE_MEDIA);
116 if (ret != MS_MEDIA_ERR_NONE) {
117 media_svc_error("_media_svc_init_table_query fail.");
121 /*create media table*/
122 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
123 if (ret != MS_MEDIA_ERR_NONE) {
124 media_svc_error("_media_svc_make_table_query fail.");
128 /*create folder table*/
129 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
130 if (ret != MS_MEDIA_ERR_NONE) {
131 media_svc_error("_media_svc_make_table_query fail.");
135 /*create playlist_map table*/
136 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
137 if (ret != MS_MEDIA_ERR_NONE) {
138 media_svc_error("_media_svc_make_table_query fail.");
142 /*create playlist table*/
143 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
144 if (ret != MS_MEDIA_ERR_NONE) {
145 media_svc_error("_media_svc_make_table_query fail.");
149 /* create album table*/
150 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
151 if (ret != MS_MEDIA_ERR_NONE) {
152 media_svc_error("_media_svc_make_table_query fail.");
156 /*create tag_map table*/
157 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
158 if (ret != MS_MEDIA_ERR_NONE) {
159 media_svc_error("_media_svc_make_table_query fail.");
164 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
165 if (ret != MS_MEDIA_ERR_NONE) {
166 media_svc_error("_media_svc_make_table_query fail.");
170 /*create bookmark table*/
171 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
172 if (ret != MS_MEDIA_ERR_NONE) {
173 media_svc_error("_media_svc_make_table_query fail.");
177 /*create storage table from tizen 2.4 */
178 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
179 if (ret != MS_MEDIA_ERR_NONE) {
180 media_svc_error("_media_svc_make_table_query fail.");
184 /*create uhd table from tizen 3.0 */
185 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_UHD, MEDIA_SVC_DB_LIST_UHD, uid);
186 if (ret != MS_MEDIA_ERR_NONE) {
187 media_svc_error("_media_svc_make_table_query fail.");
191 /*create pvr table from tizen 3.0 */
192 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PVR, MEDIA_SVC_DB_LIST_PVR, uid);
193 if (ret != MS_MEDIA_ERR_NONE) {
194 media_svc_error("_media_svc_make_table_query fail.");
198 /*create face table. from tizen 3.0*/
199 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_LIST_FACE_SCAN_LIST, uid);
200 if (ret != MS_MEDIA_ERR_NONE) {
201 media_svc_error("_media_svc_make_table_query fail.");
205 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE, MEDIA_SVC_DB_LIST_FACE, uid);
206 if (ret != MS_MEDIA_ERR_NONE) {
207 media_svc_error("_media_svc_make_table_query fail.");
211 sql = sqlite3_mprintf("pragma user_version = %d;", LATEST_VERSION_NUMBER);
212 ret = _media_svc_sql_query(sql, uid);
213 if (ret != MS_MEDIA_ERR_NONE) {
214 media_svc_error("user_version update fail.");
218 _media_svc_destroy_table_query();
220 media_svc_debug_fleave();
222 return MS_MEDIA_ERR_NONE;
224 _media_svc_destroy_table_query();
226 media_svc_debug_fleave();
231 int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
233 int ret = MS_MEDIA_ERR_NONE;
234 ms_user_storage_type_e type = -1;
236 ret = ms_user_get_storage_type(uid, path, &type);
237 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_storage_type failed : %d", ret);
239 *storage_type = type;
244 int media_svc_get_file_info(MediaSvcHandle *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
246 int ret = MS_MEDIA_ERR_NONE;
247 sqlite3 *db_handle = (sqlite3 *)handle;
249 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
250 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
252 ret = _media_svc_get_fileinfo_by_path(db_handle, storage_id, path, modified_time, size);
257 int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path)
259 int ret = MS_MEDIA_ERR_NONE;
260 sqlite3 *db_handle = (sqlite3 *)handle;
263 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
264 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
265 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
267 ret = _media_svc_count_record_with_path(db_handle, storage_id, path, &count);
268 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
271 media_svc_debug("item is exist in database");
272 return MS_MEDIA_ERR_NONE;
274 media_svc_debug("item is not exist in database");
275 return MS_MEDIA_ERR_DB_NO_RECORD;
278 return MS_MEDIA_ERR_NONE;
281 int media_svc_insert_item_begin(int data_cnt, int with_noti, int from_pid)
283 media_svc_debug("Transaction data count : [%d]", data_cnt);
285 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
287 g_media_svc_insert_item_data_cnt = data_cnt;
288 g_media_svc_insert_item_cur_data_cnt = 0;
290 /* Prepare for making noti item list */
292 media_svc_debug("making noti list from pid[%d]", from_pid);
293 if (_media_svc_create_noti_list(data_cnt) != MS_MEDIA_ERR_NONE)
294 return MS_MEDIA_ERR_OUT_OF_MEMORY;
296 _media_svc_set_noti_from_pid(from_pid);
297 g_insert_with_noti = TRUE;
300 return MS_MEDIA_ERR_NONE;
303 int media_svc_insert_item_end(uid_t uid)
305 int ret = MS_MEDIA_ERR_NONE;
307 media_svc_debug_fenter();
309 if (g_media_svc_insert_item_cur_data_cnt > 0) {
311 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
312 if (g_insert_with_noti) {
313 media_svc_debug("sending noti list");
314 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
315 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
316 g_insert_with_noti = FALSE;
317 _media_svc_set_noti_from_pid(-1);
321 g_media_svc_insert_item_data_cnt = 1;
322 g_media_svc_insert_item_cur_data_cnt = 0;
327 int media_svc_insert_item_bulk(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
329 int ret = MS_MEDIA_ERR_NONE;
330 sqlite3 *db_handle = (sqlite3 *)handle;
331 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
332 media_svc_media_type_e media_type;
334 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
335 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
336 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
337 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
339 media_svc_content_info_s content_info;
340 memset(&content_info, 0, sizeof(media_svc_content_info_s));
343 /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
344 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
345 if (ret != MS_MEDIA_ERR_NONE)
348 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
349 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
350 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
351 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
352 media_svc_debug("Do nothing[%d]", media_type);
353 else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
354 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
356 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
357 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
359 /*Set or Get folder id*/
360 ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
361 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
363 content_info.folder_uuid = g_strdup(folder_uuid);
364 media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
366 if (g_media_svc_insert_item_data_cnt == 1) {
368 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, FALSE, uid);
369 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
371 if (g_insert_with_noti)
372 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
374 } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
376 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
377 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
379 if (g_insert_with_noti)
380 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
382 g_media_svc_insert_item_cur_data_cnt++;
384 } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
386 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
387 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
389 if (g_insert_with_noti)
390 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
392 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
393 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
395 if (g_insert_with_noti) {
396 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
397 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
399 /* Recreate noti list */
400 ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
401 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
404 g_media_svc_insert_item_cur_data_cnt = 0;
407 media_svc_error("Error in media_svc_insert_item_bulk");
408 _media_svc_destroy_content_info(&content_info);
409 return MS_MEDIA_ERR_INTERNAL;
412 _media_svc_destroy_content_info(&content_info);
414 return MS_MEDIA_ERR_NONE;
417 int media_svc_insert_item_immediately(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
419 int ret = MS_MEDIA_ERR_NONE;
420 sqlite3 *db_handle = (sqlite3 *)handle;
421 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
422 media_svc_media_type_e media_type;
424 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
425 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
426 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
427 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
429 media_svc_content_info_s content_info;
430 memset(&content_info, 0, sizeof(media_svc_content_info_s));
433 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
434 if (ret != MS_MEDIA_ERR_NONE)
437 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
438 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
439 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
440 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA)) {
442 } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
443 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
445 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
448 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
450 /*Set or Get folder id*/
451 ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
452 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
454 content_info.folder_uuid = g_strdup(folder_uuid);
455 media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
457 /* Extracting thumbnail */
458 if (content_info.thumbnail_path == NULL) {
459 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
460 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
462 ret = _media_svc_request_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), uid);
463 if (ret == MS_MEDIA_ERR_NONE)
464 content_info.thumbnail_path = g_strdup(thumb_path);
468 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, FALSE, FALSE, uid);
470 if (ret == MS_MEDIA_ERR_NONE) {
471 media_svc_debug("Insertion is successful. Sending noti for this");
472 _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);
473 } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
474 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
477 _media_svc_destroy_content_info(&content_info);
481 int media_svc_move_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e src_storage, const char *src_path,
482 media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid)
484 int ret = MS_MEDIA_ERR_NONE;
485 sqlite3 *db_handle = (sqlite3 *)handle;
486 char *file_name = NULL;
487 char *folder_path = NULL;
488 int modified_time = 0;
489 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
490 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
491 char new_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
494 media_svc_debug_fenter();
496 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
497 media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
498 media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
499 media_svc_retvm_if(__media_svc_check_storage(src_storage) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid src_storage");
500 media_svc_retvm_if(__media_svc_check_storage(dest_storage) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid dest_storage");
502 /*check and update folder*/
503 ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, dest_path, dest_storage, folder_uuid, uid);
504 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
507 file_name = g_path_get_basename(dest_path);
509 /*get modified_time*/
510 modified_time = _media_svc_get_file_time(dest_path);
512 /*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
513 ret = _media_svc_get_media_type_by_path(db_handle, storage_id, src_path, &media_type);
514 if (ret != MS_MEDIA_ERR_NONE) {
515 media_svc_error("_media_svc_get_media_type_by_path failed");
516 SAFE_FREE(file_name);
520 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
521 /*get old thumbnail_path*/
522 ret = _media_svc_get_thumbnail_path_by_path(db_handle, src_path, old_thumb_path);
523 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
524 media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
525 SAFE_FREE(file_name);
529 _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT, uid);
532 if (g_media_svc_move_item_data_cnt == 1) {
535 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
536 ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE, uid);
538 ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid);
540 SAFE_FREE(file_name);
541 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
543 media_svc_debug("Move is successful. Sending noti for this");
545 /* Get notification info */
546 media_svc_noti_item *noti_item = NULL;
547 ret = _media_svc_get_noti_info(db_handle, storage_id, dest_path, MS_MEDIA_ITEM_FILE, ¬i_item);
548 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
550 /* Send notification for move */
551 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
552 _media_svc_destroy_noti_item(noti_item);
554 /*update folder modified_time*/
555 folder_path = g_path_get_dirname(dest_path);
556 ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, FALSE, uid);
557 SAFE_FREE(folder_path);
558 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
560 ret = _media_svc_update_folder_table(storage_id, uid);
561 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
563 } else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) {
566 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
567 ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
569 ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
571 SAFE_FREE(file_name);
572 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
574 /*update folder modified_time*/
575 folder_path = g_path_get_dirname(dest_path);
576 ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, TRUE, uid);
577 SAFE_FREE(folder_path);
578 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
580 g_media_svc_move_item_cur_data_cnt++;
582 } else if (g_media_svc_move_item_cur_data_cnt == (g_media_svc_move_item_data_cnt - 1)) {
584 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
585 ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
587 ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
589 SAFE_FREE(file_name);
590 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
592 /*update folder modified_time*/
593 folder_path = g_path_get_dirname(dest_path);
594 ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, TRUE, uid);
595 SAFE_FREE(folder_path);
596 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
599 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_MOVE_ITEM, uid);
600 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
602 g_media_svc_move_item_cur_data_cnt = 0;
605 media_svc_error("Error in media_svc_move_item");
606 SAFE_FREE(file_name);
607 return MS_MEDIA_ERR_INTERNAL;
610 /*rename thumbnail file*/
611 if (STRING_VALID(old_thumb_path)) {
612 ret = _media_svc_rename_file(old_thumb_path, new_thumb_path);
613 if (ret != MS_MEDIA_ERR_NONE)
614 media_svc_error("_media_svc_rename_file failed : %d", ret);
617 return MS_MEDIA_ERR_NONE;
620 int media_svc_set_item_validity_begin(int data_cnt)
622 media_svc_debug("Transaction data count : [%d]", data_cnt);
624 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
626 g_media_svc_item_validity_data_cnt = data_cnt;
627 g_media_svc_item_validity_cur_data_cnt = 0;
629 return MS_MEDIA_ERR_NONE;
632 int media_svc_set_item_validity_end(uid_t uid)
634 int ret = MS_MEDIA_ERR_NONE;
636 media_svc_debug_fenter();
638 if (g_media_svc_item_validity_cur_data_cnt > 0)
639 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
641 g_media_svc_item_validity_data_cnt = 1;
642 g_media_svc_item_validity_cur_data_cnt = 0;
647 int media_svc_set_item_validity(const char *storage_id, const char *path, int validity, uid_t uid)
649 int ret = MS_MEDIA_ERR_NONE;
651 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
652 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
654 media_svc_debug("path=[%s], validity=[%d]", path, validity);
656 if (g_media_svc_item_validity_data_cnt == 1) {
658 return _media_svc_update_item_validity(storage_id, path, validity, FALSE, uid);
660 } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
662 ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
663 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
665 g_media_svc_item_validity_cur_data_cnt++;
667 } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
669 ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
670 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
672 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
673 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
675 g_media_svc_item_validity_cur_data_cnt = 0;
679 media_svc_error("Error in media_svc_set_item_validity");
680 return MS_MEDIA_ERR_INTERNAL;
683 return MS_MEDIA_ERR_NONE;
686 int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path, uid_t uid)
688 int ret = MS_MEDIA_ERR_NONE;
689 sqlite3 *db_handle = (sqlite3 *)handle;
690 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
692 media_svc_debug_fenter();
694 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
695 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
696 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
699 ret = _media_svc_get_media_type_by_path(db_handle, storage_id, path, &media_type);
700 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
702 /*Get thumbnail path to delete*/
703 ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
704 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
706 if (g_media_svc_insert_item_data_cnt == 1) {
708 /* Get notification info */
709 media_svc_noti_item *noti_item = NULL;
710 ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, ¬i_item);
711 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
714 ret = _media_svc_delete_item_by_path(storage_id, path, FALSE, uid);
715 if (ret != MS_MEDIA_ERR_NONE) {
716 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
717 _media_svc_destroy_noti_item(noti_item);
722 /* Send notification */
723 media_svc_debug("Deletion is successful. Sending noti for this");
724 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
725 _media_svc_destroy_noti_item(noti_item);
727 ret = _media_svc_delete_item_by_path(storage_id, path, TRUE, uid);
728 if (ret != MS_MEDIA_ERR_NONE) {
729 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
736 if (STRING_VALID(thumb_path)) {
737 ret = _media_svc_remove_file(thumb_path);
738 if (ret != MS_MEDIA_ERR_NONE)
739 media_svc_error("fail to remove thumbnail file.");
742 return MS_MEDIA_ERR_NONE;
745 int media_svc_delete_all_items_in_storage(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
747 int ret = MS_MEDIA_ERR_NONE;
748 char *thumb_path = NULL;
750 media_svc_debug("media_svc_delete_all_items_in_storage [%d]", storage_type);
752 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
753 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
755 ret = _media_svc_truncate_table(storage_id, storage_type, uid);
756 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
758 if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
759 ret = ms_user_get_thumb_store_path(uid, (ms_user_storage_type_e)storage_type, &thumb_path);
760 if (!STRING_VALID(thumb_path)) {
761 media_svc_error("fail to get thumbnail path");
762 return MS_MEDIA_ERR_INTERNAL;
765 ret = _media_svc_remove_all_files_in_dir(thumb_path);
766 SAFE_FREE(thumb_path);
767 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
770 return MS_MEDIA_ERR_NONE;
773 int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
775 sqlite3 *db_handle = (sqlite3 *)handle;
777 media_svc_debug_fenter();
779 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
780 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
781 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
783 /*Delete from DB and remove thumbnail files*/
784 return _media_svc_delete_invalid_items(db_handle, storage_id, storage_type, uid);
787 int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
789 sqlite3 *db_handle = (sqlite3 *)handle;
791 media_svc_debug_fenter();
793 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
794 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
796 /*Delete from DB and remove thumbnail files*/
797 return _media_svc_delete_invalid_folder_items(db_handle, storage_id, folder_path, is_recursive, uid);
800 int media_svc_set_all_storage_items_validity(const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
802 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
803 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
805 return _media_svc_update_storage_item_validity(storage_id, storage_type, validity, uid);
808 int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid)
810 sqlite3 *db_handle = (sqlite3 *)handle;
812 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
813 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
814 media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");
817 return _media_svc_update_recursive_folder_item_validity(storage_id, folder_path, validity, uid);
819 return _media_svc_update_folder_item_validity(db_handle, storage_id, folder_path, validity, uid);
822 int media_svc_refresh_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
824 int ret = MS_MEDIA_ERR_NONE;
825 sqlite3 *db_handle = (sqlite3 *)handle;
826 media_svc_media_type_e media_type;
828 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
829 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
830 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
831 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
833 media_svc_content_info_s content_info;
834 memset(&content_info, 0, sizeof(media_svc_content_info_s));
837 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, TRUE);
838 if (ret != MS_MEDIA_ERR_NONE)
841 /* Initialize thumbnail information to remake thumbnail. */
842 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
843 ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
844 if (ret != MS_MEDIA_ERR_NONE) {
845 _media_svc_destroy_content_info(&content_info);
849 if (g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
850 ret = _media_svc_remove_file(thumb_path);
851 if (ret != MS_MEDIA_ERR_NONE)
852 media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
855 ret = _media_svc_update_thumbnail_path(path, NULL, uid);
856 if (ret != MS_MEDIA_ERR_NONE) {
857 _media_svc_destroy_content_info(&content_info);
861 /* Get notification info */
862 media_svc_noti_item *noti_item = NULL;
863 ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, ¬i_item);
864 if (ret != MS_MEDIA_ERR_NONE) {
865 _media_svc_destroy_content_info(&content_info);
869 media_type = noti_item->media_type;
870 content_info.media_type = media_type;
872 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
873 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
874 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
875 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
876 media_svc_debug("Do nothing [%d]", media_type);
877 else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
878 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
880 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
882 if (ret != MS_MEDIA_ERR_NONE) {
883 _media_svc_destroy_noti_item(noti_item);
884 _media_svc_destroy_content_info(&content_info);
888 /* Extracting thumbnail */
889 if (content_info.thumbnail_path == NULL) {
890 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
891 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
893 ret = _media_svc_request_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), uid);
894 if (ret == MS_MEDIA_ERR_NONE)
895 content_info.thumbnail_path = g_strdup(thumb_path);
899 ret = _media_svc_update_item_with_data(storage_id, &content_info, uid);
901 if (ret == MS_MEDIA_ERR_NONE) {
902 media_svc_debug("Update is successful. Sending noti for this");
903 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
905 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
908 _media_svc_destroy_content_info(&content_info);
909 _media_svc_destroy_noti_item(noti_item);
914 int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, const char *src_path, const char *dst_path, uid_t uid)
916 sqlite3 *db_handle = (sqlite3 *)handle;
917 int ret = MS_MEDIA_ERR_NONE;
919 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
920 media_svc_retvm_if(src_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
921 media_svc_retvm_if(dst_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "dst_path is NULL");
923 media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);
925 ret = _media_svc_sql_begin_trans(uid);
926 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
928 /* Update all folder record's modified date, which are changed above */
929 char *update_folder_modified_time_sql = NULL;
933 update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d WHERE path LIKE '%q';", date, dst_path);
935 ret = media_db_request_update_db_batch(update_folder_modified_time_sql, uid);
936 SQLITE3_SAFE_FREE(update_folder_modified_time_sql);
938 if (ret != SQLITE_OK) {
939 media_svc_error("failed to update folder modified time");
940 _media_svc_sql_rollback_trans(uid);
942 return MS_MEDIA_ERR_DB_INTERNAL;
945 /* Update all items */
946 char *select_all_sql = NULL;
947 sqlite3_stmt *sql_stmt = NULL;
948 char dst_child_path[MEDIA_SVC_PATHNAME_SIZE + 1];
950 snprintf(dst_child_path, sizeof(dst_child_path), "%s/%%", dst_path);
952 select_all_sql = sqlite3_mprintf("SELECT media_uuid, path, thumbnail_path, media_type from '%q' where folder_uuid IN ( SELECT folder_uuid FROM folder where path='%q' or path like '%q');", storage_id, dst_path, dst_child_path);
954 media_svc_debug("[SQL query] : %s", select_all_sql);
956 ret = _media_svc_sql_prepare_to_step_simple(db_handle, select_all_sql, &sql_stmt);
957 if (ret != MS_MEDIA_ERR_NONE) {
958 media_svc_error("error when media_svc_rename_folder. err = [%d]", ret);
959 _media_svc_sql_rollback_trans(uid);
963 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
964 char media_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
965 char media_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
966 char media_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
967 char media_new_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
969 bool no_thumb = FALSE;
971 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
972 SAFE_STRLCPY(media_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(media_uuid));
974 media_svc_error("media UUID is NULL");
975 return MS_MEDIA_ERR_DB_INTERNAL;
978 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) {
979 SAFE_STRLCPY(media_path, (const char *)sqlite3_column_text(sql_stmt, 1), sizeof(media_path));
981 media_svc_error("media path is NULL");
982 return MS_MEDIA_ERR_DB_INTERNAL;
985 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2))) {
986 SAFE_STRLCPY(media_thumb_path, (const char *)sqlite3_column_text(sql_stmt, 2), sizeof(media_thumb_path));
988 media_svc_debug("media thumb path doesn't exist in DB");
992 /*media_type = sqlite3_column_int(sql_stmt, 3); */
994 /* Update path, thumbnail path of this item */
995 char *replaced_path = NULL;
996 replaced_path = _media_svc_replace_path(media_path, src_path, dst_path);
997 if (replaced_path == NULL) {
998 media_svc_error("_media_svc_replace_path failed");
999 SQLITE3_FINALIZE(sql_stmt);
1000 _media_svc_sql_rollback_trans(uid);
1001 return MS_MEDIA_ERR_INTERNAL;
1004 media_svc_debug("New media path : %s", replaced_path);
1005 ms_user_storage_type_e storage_type = -1;
1008 ret = ms_user_get_storage_type(uid, replaced_path, &storage_type);
1009 if (ret != MS_MEDIA_ERR_NONE) {
1010 media_svc_sec_error("ms_user_get_storage_type failed : [%d], path[%s] storage_type[%d]", ret, replaced_path, storage_type);
1011 SAFE_FREE(replaced_path);
1012 _media_svc_sql_rollback_trans(uid);
1016 ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT, uid);
1017 if (ret != MS_MEDIA_ERR_NONE) {
1018 media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
1019 SAFE_FREE(replaced_path);
1020 SQLITE3_FINALIZE(sql_stmt);
1021 _media_svc_sql_rollback_trans(uid);
1025 /*media_svc_debug("New media thumbnail path : %s", media_new_thumb_path); */
1028 char *update_item_sql = NULL;
1031 update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_uuid);
1034 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)
1035 update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_new_thumb_path, media_uuid);
1037 update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_thumb_path, media_uuid);
1039 update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_new_thumb_path, media_uuid);
1043 ret = media_db_request_update_db_batch(update_item_sql, uid);
1044 SQLITE3_SAFE_FREE(update_item_sql);
1045 SAFE_FREE(replaced_path);
1047 if (ret != SQLITE_OK) {
1048 media_svc_error("failed to update item");
1049 SQLITE3_FINALIZE(sql_stmt);
1050 _media_svc_sql_rollback_trans(uid);
1052 return MS_MEDIA_ERR_DB_INTERNAL;
1055 /* Rename thumbnail file of file system */
1057 ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
1058 if (ret != MS_MEDIA_ERR_NONE)
1059 media_svc_error("_media_svc_rename_file failed : %d", ret);
1064 SQLITE3_FINALIZE(sql_stmt);
1066 ret = _media_svc_sql_end_trans(uid);
1067 if (ret != MS_MEDIA_ERR_NONE) {
1068 media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
1069 _media_svc_sql_rollback_trans(uid);
1073 media_svc_debug("Folder update is successful. Sending noti for this");
1074 /* Get notification info */
1075 media_svc_noti_item *noti_item = NULL;
1076 ret = _media_svc_get_noti_info(db_handle, storage_id, dst_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
1077 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1079 _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, src_path, -1, noti_item->media_uuid, NULL);
1080 _media_svc_destroy_noti_item(noti_item);
1082 return MS_MEDIA_ERR_NONE;
1085 int media_svc_request_update_db(const char *db_query, uid_t uid)
1087 media_svc_retvm_if(!STRING_VALID(db_query), MS_MEDIA_ERR_INVALID_PARAMETER, "db_query is NULL");
1089 return _media_svc_sql_query(db_query, uid);
1092 int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *storage_id, const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
1094 int ret = MS_MEDIA_ERR_NONE;
1095 sqlite3 *db_handle = (sqlite3 *)handle;
1098 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1099 media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
1101 /* Get notification info */
1102 media_svc_noti_item *noti_item = NULL;
1103 ret = _media_svc_get_noti_info(db_handle, storage_id, dir_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
1104 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1106 if (folder_id != NULL) {
1107 uuid = strndup(folder_id, strlen(folder_id));
1109 if (noti_item->media_uuid != NULL) {
1110 uuid = strndup(noti_item->media_uuid, strlen(noti_item->media_uuid));
1112 _media_svc_destroy_noti_item(noti_item);
1113 media_svc_error("folder uuid is wrong");
1114 return MS_MEDIA_ERR_DB_INTERNAL;
1118 ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, dir_path, -1, noti_item->media_uuid, NULL, pid);
1119 ret = _media_svc_publish_dir_noti_v2(MS_MEDIA_ITEM_DIRECTORY, update_type, dir_path, -1, uuid, NULL, pid);
1120 _media_svc_destroy_noti_item(noti_item);
1126 int media_svc_count_invalid_items_in_folder(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count)
1128 sqlite3 *db_handle = (sqlite3 *)handle;
1130 media_svc_debug_fenter();
1132 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1133 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1134 media_svc_retvm_if(folder_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");
1135 media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
1137 return _media_svc_count_invalid_folder_items(db_handle, storage_id, folder_path, count);
1140 int media_svc_check_db_upgrade(MediaSvcHandle *handle, int user_version, uid_t uid)
1142 sqlite3 *db_handle = (sqlite3 *)handle;
1144 media_svc_debug_fenter();
1146 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1148 return _media_svc_check_db_upgrade(db_handle, user_version, uid);
1151 int media_svc_check_db_corrupt(MediaSvcHandle *handle)
1153 sqlite3 *db_handle = (sqlite3 *)handle;
1155 media_svc_debug_fenter();
1157 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1159 return _media_db_check_corrupt(db_handle);
1162 int media_svc_get_folder_list(MediaSvcHandle *handle, char *start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count)
1164 sqlite3 *db_handle = (sqlite3 *)handle;
1166 media_svc_debug_fenter();
1168 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1169 media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
1171 return _media_svc_get_all_folders(db_handle, start_path, folder_list, modified_time_list, item_num_list, count);
1174 int media_svc_update_folder_time(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid)
1176 int ret = MS_MEDIA_ERR_NONE;
1177 sqlite3 *db_handle = (sqlite3 *)handle;
1178 time_t sto_time = 0;
1179 int cur_time = _media_svc_get_file_time(folder_path);
1180 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
1182 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1184 ret = _media_svc_get_folder_info_by_foldername(db_handle, storage_id, folder_path, folder_uuid, &sto_time);
1185 if (ret == MS_MEDIA_ERR_NONE) {
1186 if (sto_time != cur_time)
1187 ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, FALSE, uid);
1193 int media_svc_update_item_begin(int data_cnt)
1195 media_svc_debug("Transaction data count : [%d]", data_cnt);
1197 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
1199 g_media_svc_update_item_data_cnt = data_cnt;
1200 g_media_svc_update_item_cur_data_cnt = 0;
1202 return MS_MEDIA_ERR_NONE;
1205 int media_svc_update_item_end(uid_t uid)
1207 int ret = MS_MEDIA_ERR_NONE;
1209 media_svc_debug_fenter();
1211 if (g_media_svc_update_item_cur_data_cnt > 0)
1212 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
1214 g_media_svc_update_item_data_cnt = 1;
1215 g_media_svc_update_item_cur_data_cnt = 0;
1220 int media_svc_update_item_meta(MediaSvcHandle *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid)
1222 int ret = MS_MEDIA_ERR_NONE;
1223 sqlite3 *db_handle = (sqlite3 *)handle;
1225 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1227 media_svc_media_type_e media_type;
1228 media_svc_retvm_if(!STRING_VALID(file_path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1229 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1231 media_svc_content_info_s content_info;
1232 memset(&content_info, 0, sizeof(media_svc_content_info_s));
1235 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, file_path, &media_type, FALSE);
1236 if (ret != MS_MEDIA_ERR_NONE)
1239 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)
1240 ret = _media_svc_extract_music_metadata_for_update(db_handle, &content_info, media_type);
1242 _media_svc_destroy_content_info(&content_info);
1243 return MS_MEDIA_ERR_NONE;
1246 if (ret != MS_MEDIA_ERR_NONE) {
1247 _media_svc_destroy_content_info(&content_info);
1251 if (g_media_svc_update_item_data_cnt == 1) {
1253 ret = _media_svc_update_meta_with_data(&content_info);
1254 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1256 } else if (g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {
1258 ret = _media_svc_update_meta_with_data(&content_info);
1259 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1261 g_media_svc_update_item_cur_data_cnt++;
1263 } else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {
1265 ret = _media_svc_update_meta_with_data(&content_info);
1266 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1268 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
1269 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1271 g_media_svc_update_item_cur_data_cnt = 0;
1274 media_svc_error("Error in media_svc_update_item_meta");
1275 _media_svc_destroy_content_info(&content_info);
1276 return MS_MEDIA_ERR_INTERNAL;
1279 _media_svc_destroy_content_info(&content_info);
1284 int media_svc_publish_noti(media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
1286 return _media_svc_publish_noti(update_item, update_type, path, media_type, uuid, mime_type);
1289 int media_svc_get_pinyin(const char *src_str, char **pinyin_str)
1291 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1293 return _media_svc_get_pinyin_str(src_str, pinyin_str);
1296 int media_svc_check_pinyin_support(bool *support)
1298 *support = _media_svc_check_pinyin_support();
1300 return MS_MEDIA_ERR_NONE;
1303 int media_svc_set_storage_validity(MediaSvcHandle *handle, const char *storage_id, int validity, uid_t uid)
1305 int ret = MS_MEDIA_ERR_NONE;
1306 sqlite3 * db_handle = (sqlite3 *)handle;
1308 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1310 ret = _media_svc_update_storage_validity(storage_id, validity, uid);
1311 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);
1313 ret = _media_svc_update_media_view(db_handle, uid);
1314 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
1319 int media_svc_get_storage_id(MediaSvcHandle *handle, const char *path, char *storage_id, uid_t uid)
1321 int ret = MS_MEDIA_ERR_NONE;
1322 sqlite3 * db_handle = (sqlite3 *)handle;
1324 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1325 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1327 ret = _media_svc_get_storage_uuid(db_handle, path, storage_id, uid);
1332 int media_svc_get_storage_path(MediaSvcHandle *handle, const char *storage_uuid, char **storage_path)
1334 int ret = MS_MEDIA_ERR_NONE;
1335 sqlite3 * db_handle = (sqlite3 *)handle;
1337 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1338 media_svc_retvm_if(storage_uuid == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_uuid is NULL");
1340 ret = _media_svc_get_storage_path(db_handle, storage_uuid, storage_path);
1345 int media_svc_get_storage_scan_status(MediaSvcHandle *handle, const char *storage_uuid, media_svc_scan_status_type_e *storage_status)
1347 int ret = MS_MEDIA_ERR_NONE;
1348 sqlite3 * db_handle = (sqlite3 *)handle;
1350 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1351 media_svc_retvm_if(storage_uuid == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_uuid is NULL");
1353 ret = _media_svc_get_storage_scan_status(db_handle, storage_uuid, storage_status);
1358 int media_svc_set_storage_scan_status(const char *storage_uuid, media_svc_scan_status_type_e storage_status, uid_t uid)
1360 int ret = MS_MEDIA_ERR_NONE;
1362 ret = _media_svc_set_storage_scan_status(storage_uuid, storage_status, uid);
1367 int media_svc_get_storage_list(MediaSvcHandle *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count)
1369 sqlite3 * db_handle = (sqlite3 *)handle;
1371 media_svc_debug_fenter();
1373 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1374 media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
1376 return _media_svc_get_all_storage(db_handle, storage_list, storage_id_list, scan_status_list, count);
1379 static int __media_svc_copy_para_to_content(media_svc_content_info_s *content_info, media_svc_content_info_s *new_content_info)
1381 media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1382 media_svc_retvm_if(new_content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1384 if (content_info->added_time > 0)
1385 new_content_info->added_time = content_info->added_time;
1386 new_content_info->last_played_time = content_info->last_played_time;
1387 new_content_info->played_count = content_info->played_count;
1388 new_content_info->favourate = content_info->favourate;
1390 /* Can be NULL if user not to set display_name using media_info_set_displayname().. */
1391 if (STRING_VALID(content_info->file_name)) {
1392 /* Already filled in _media_svc_set_media_info() */
1393 SAFE_FREE(new_content_info->file_name);
1394 new_content_info->file_name = g_strdup(content_info->file_name);
1396 new_content_info->media_meta.title = g_strdup(content_info->media_meta.title);
1397 new_content_info->media_meta.album = g_strdup(content_info->media_meta.album);
1398 new_content_info->media_meta.artist = g_strdup(content_info->media_meta.artist);
1399 new_content_info->media_meta.genre = g_strdup(content_info->media_meta.genre);
1400 new_content_info->media_meta.composer = g_strdup(content_info->media_meta.composer);
1401 new_content_info->media_meta.year = g_strdup(content_info->media_meta.year);
1402 new_content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.recorded_date);
1403 new_content_info->media_meta.copyright = g_strdup(content_info->media_meta.copyright);
1404 new_content_info->media_meta.track_num = g_strdup(content_info->media_meta.track_num);
1405 new_content_info->media_meta.description = g_strdup(content_info->media_meta.description);
1406 new_content_info->media_meta.weather = g_strdup(content_info->media_meta.weather);
1407 new_content_info->media_meta.category = g_strdup(content_info->media_meta.category);
1408 new_content_info->media_meta.keyword = g_strdup(content_info->media_meta.keyword);
1409 new_content_info->media_meta.location_tag = g_strdup(content_info->media_meta.location_tag);
1410 new_content_info->media_meta.content_name = g_strdup(content_info->media_meta.content_name);
1411 new_content_info->media_meta.age_rating = g_strdup(content_info->media_meta.age_rating);
1412 new_content_info->media_meta.author = g_strdup(content_info->media_meta.author);
1413 new_content_info->media_meta.provider = g_strdup(content_info->media_meta.provider);
1415 if (STRING_VALID(content_info->media_meta.datetaken)) {
1416 new_content_info->media_meta.datetaken = g_strdup(content_info->media_meta.datetaken);
1418 new_content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1419 if (new_content_info->timeline == 0) {
1420 media_svc_error("Failed to get timeline : %s", new_content_info->media_meta.datetaken);
1421 new_content_info->timeline = new_content_info->modified_time;
1423 media_svc_debug("Timeline : %ld", new_content_info->timeline);
1427 new_content_info->media_meta.is_360 = content_info->media_meta.is_360;
1428 /* new_content_info->media_meta.bitrate = content_info->media_meta.bitrate; */
1429 /* new_content_info->media_meta.samplerate = content_info->media_meta.samplerate; */
1430 /* new_content_info->media_meta.channel = content_info->media_meta.channel; */
1431 /* new_content_info->media_meta.orientation = content_info->media_meta.orientation; */
1433 if (content_info->media_meta.longitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
1434 new_content_info->media_meta.longitude = content_info->media_meta.longitude;
1435 if (content_info->media_meta.latitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
1436 new_content_info->media_meta.latitude = content_info->media_meta.latitude;
1437 if (content_info->media_meta.altitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
1438 new_content_info->media_meta.altitude = content_info->media_meta.altitude;
1440 new_content_info->media_meta.rating = content_info->media_meta.rating;
1442 return MS_MEDIA_ERR_NONE;
1445 int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_svc_content_info_s *content_info, uid_t uid)
1447 int ret = MS_MEDIA_ERR_NONE;
1448 sqlite3 *db_handle = (sqlite3 *)handle;
1449 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
1450 bool append_album = FALSE;
1452 /* Checking parameters if they are valid */
1453 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1454 media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
1455 media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "file_path is NULL");
1457 media_svc_debug("storage[%d], path[%s], media_type[%d]", content_info->storage_type, content_info->path, content_info->media_type);
1459 media_svc_content_info_s _new_content_info;
1460 memset(&_new_content_info, 0, sizeof(media_svc_content_info_s));
1462 media_svc_media_type_e media_type;
1464 ret = _media_svc_set_media_info(&_new_content_info, content_info->storage_uuid, content_info->storage_type, content_info->path, &media_type, FALSE);
1465 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "fail _media_svc_set_media_info");
1467 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER)
1468 media_svc_debug("Do nothing[%d]", media_type);
1469 else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
1470 ret = _media_svc_extract_image_metadata(db_handle, &_new_content_info);
1472 ret = _media_svc_extract_media_metadata(db_handle, &_new_content_info, uid);
1474 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1476 /* Extracting thumbnail */
1477 if (_new_content_info.thumbnail_path == NULL) {
1478 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1479 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1481 ret = _media_svc_request_thumbnail(_new_content_info.path, thumb_path, sizeof(thumb_path), uid);
1482 if (ret == MS_MEDIA_ERR_NONE)
1483 _new_content_info.thumbnail_path = g_strdup(thumb_path);
1487 /* set othere data to the structure, which is passed as parameters */
1488 __media_svc_copy_para_to_content(content_info, &_new_content_info);
1490 /* Set or Get folder id */
1491 ret = _media_svc_get_and_append_folder_id_by_path(handle, _new_content_info.storage_uuid, _new_content_info.path, _new_content_info.storage_type, folder_uuid, uid);
1492 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &_new_content_info);
1494 _new_content_info.folder_uuid = g_strdup(folder_uuid);
1495 media_svc_retv_del_if(_new_content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &_new_content_info);
1497 /* register album table data */
1500 if (_new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SOUND || _new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
1501 ret = _media_svc_get_album_id(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, &album_id);
1503 if (ret != MS_MEDIA_ERR_NONE) {
1504 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1505 media_svc_debug("album does not exist. So start to make album art");
1506 append_album = TRUE;
1508 media_svc_debug("other error");
1509 append_album = FALSE;
1512 _new_content_info.album_id = album_id;
1513 append_album = FALSE;
1515 if ((!g_strcmp0(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) ||
1516 (!g_strcmp0(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) {
1517 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1520 media_svc_debug("album already exists. don't need to make album art");
1521 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &_new_content_info.thumbnail_path);
1522 media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, &_new_content_info);
1527 if (append_album == TRUE) {
1528 if ((g_strcmp0(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1529 (g_strcmp0(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1530 ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, _new_content_info.thumbnail_path, &album_id, uid);
1532 ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, NULL, &album_id, uid);
1534 _new_content_info.album_id = album_id;
1537 /* Insert to db - calling _media_svc_insert_item_with_data */
1538 ret = _media_svc_insert_item_with_data(db_handle, _new_content_info.storage_uuid, &_new_content_info, FALSE, FALSE, uid);
1540 if (ret == MS_MEDIA_ERR_NONE)
1541 media_svc_debug("Insertion is successful.");
1543 if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL)
1544 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
1546 _media_svc_destroy_content_info(&_new_content_info);
1548 /* handling returned value - important */
1552 void media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1554 _media_svc_destroy_content_info(content_info);
1557 int media_svc_generate_uuid(char **uuid)
1559 char *gen_uuid = NULL;
1560 gen_uuid = _media_info_generate_uuid();
1561 media_svc_retvm_if(gen_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Fail to generate uuid");
1563 *uuid = strdup(gen_uuid);
1565 return MS_MEDIA_ERR_NONE;
1568 int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
1570 sqlite3 * db_handle = (sqlite3 *)handle;
1572 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1574 return _media_svc_get_mmc_info(db_handle, storage_name, storage_path, validity, info_exist);
1577 int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid)
1579 sqlite3 * db_handle = (sqlite3 *)handle;
1581 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1582 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1583 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
1584 media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");
1586 return _media_svc_check_storage(db_handle, storage_id, storage_path, validity, uid);
1589 int media_svc_update_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_path, uid_t uid)
1591 sqlite3 * db_handle = (sqlite3 *)handle;
1593 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1594 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1595 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
1597 return _media_svc_update_storage_path(db_handle, storage_id, storage_path, uid);
1600 int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, media_svc_storage_type_e storage_type, uid_t uid)
1602 int ret = MS_MEDIA_ERR_NONE;
1603 sqlite3 *db_handle = (sqlite3 *)handle;
1605 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1606 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1607 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
1608 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1610 ret = _media_svc_append_storage(storage_id, storage_name, storage_path, storage_type, uid);
1611 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
1613 if (strcmp(storage_id, MEDIA_SVC_DB_TABLE_MEDIA)) {
1614 ret = _media_svc_create_media_table_with_id(storage_id, uid);
1615 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
1617 ret = _media_svc_update_media_view(db_handle, uid);
1618 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
1624 int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, uid_t uid)
1626 int ret = MS_MEDIA_ERR_NONE;
1627 sqlite3 *db_handle = (sqlite3 *)handle;
1628 media_svc_storage_type_e storage_type;
1630 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1631 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1633 ret = _media_svc_get_storage_type(db_handle, storage_id, &storage_type);
1634 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type failed : %d", ret);
1636 ret = _media_svc_delete_storage(storage_id, uid);
1637 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "remove storage failed : %d", ret);
1639 ret = _media_svc_delete_folder_by_storage_id(storage_id, storage_type, uid);
1640 if (ret != MS_MEDIA_ERR_NONE)
1641 media_svc_error("fail to _media_svc_delete_folder_by_storage_id. error : [%d]", ret);
1643 if (storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB) {
1644 ret = _media_svc_drop_media_table(storage_id, uid);
1645 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "drop table failed : %d", ret);
1647 ret = _media_svc_update_media_view(db_handle, uid);
1648 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
1654 int media_svc_insert_folder_begin(int data_cnt)
1656 media_svc_debug("Transaction data count : [%d]", data_cnt);
1658 media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
1660 g_media_svc_insert_folder_data_cnt = data_cnt;
1661 g_media_svc_insert_folder_cur_data_cnt = 0;
1663 return MS_MEDIA_ERR_NONE;
1666 int media_svc_insert_folder_end(uid_t uid)
1668 int ret = MS_MEDIA_ERR_NONE;
1670 media_svc_debug_fenter();
1672 if (g_media_svc_insert_folder_cur_data_cnt > 0)
1673 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
1675 g_media_svc_insert_folder_data_cnt = 1;
1676 g_media_svc_insert_folder_cur_data_cnt = 0;
1681 int media_svc_insert_folder(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
1683 int ret = MS_MEDIA_ERR_NONE;
1684 sqlite3 * db_handle = (sqlite3 *)handle;
1685 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
1687 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1688 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1689 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1690 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1692 if (g_media_svc_insert_folder_data_cnt == 1) {
1694 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, FALSE, uid);
1696 } else if (g_media_svc_insert_folder_cur_data_cnt < (g_media_svc_insert_folder_data_cnt - 1)) {
1698 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
1699 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1701 g_media_svc_insert_folder_cur_data_cnt++;
1703 } else if (g_media_svc_insert_folder_cur_data_cnt == (g_media_svc_insert_folder_data_cnt - 1)) {
1705 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
1706 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1708 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
1709 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1711 g_media_svc_insert_folder_cur_data_cnt = 0;
1714 media_svc_error("Error in media_svc_set_insert_folder");
1715 return MS_MEDIA_ERR_INTERNAL;
1721 int media_svc_delete_invalid_folder(const char *storage_id, int storage_type, uid_t uid)
1723 int ret = MS_MEDIA_ERR_NONE;
1725 ret = _media_svc_delete_invalid_folder(storage_id, storage_type, uid);
1730 int media_svc_set_folder_validity(MediaSvcHandle *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
1732 int ret = MS_MEDIA_ERR_NONE;
1733 sqlite3 * db_handle = (sqlite3 *)handle;
1735 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1737 ret = _media_svc_set_folder_validity(db_handle, storage_id, start_path, validity, is_recursive, uid);
1742 int media_svc_insert_item_pass1(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
1744 int ret = MS_MEDIA_ERR_NONE;
1745 sqlite3 * db_handle = (sqlite3 *)handle;
1746 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
1747 media_svc_media_type_e media_type;
1749 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1750 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1751 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1752 media_svc_retvm_if(__media_svc_check_storage(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1754 media_svc_content_info_s content_info;
1755 memset(&content_info, 0, sizeof(media_svc_content_info_s));
1757 /*Set basic media info*/
1758 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
1759 if (ret != MS_MEDIA_ERR_NONE) {
1760 media_svc_error("_media_svc_set_media_info fail %d", ret);
1764 /*Set or Get folder id*/
1765 ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
1766 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1768 content_info.folder_uuid = g_strdup(folder_uuid);
1769 media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
1771 if (g_media_svc_insert_item_data_cnt == 1) {
1773 ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, FALSE, uid);
1774 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1776 if (g_insert_with_noti)
1777 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
1778 } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
1780 ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
1781 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1783 if (g_insert_with_noti)
1784 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
1786 media_svc_debug("g_media_svc_insert_item_cur_data_cnt %d", g_media_svc_insert_item_cur_data_cnt);
1787 g_media_svc_insert_item_cur_data_cnt++;
1789 } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
1791 ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
1792 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1794 if (g_insert_with_noti)
1795 _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
1797 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
1798 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1800 media_svc_debug("_media_svc_list_query_do over");
1802 if (g_insert_with_noti) {
1803 media_svc_debug("publish noti list %d", g_media_svc_insert_item_cur_data_cnt);
1804 _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
1805 _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
1807 /* Recreate noti list */
1808 ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
1809 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1812 g_media_svc_insert_item_cur_data_cnt = 0;
1815 media_svc_error("Error in media_svc_insert_item_pass1");
1816 _media_svc_destroy_content_info(&content_info);
1817 return MS_MEDIA_ERR_INTERNAL;
1820 _media_svc_destroy_content_info(&content_info);
1822 return MS_MEDIA_ERR_NONE;
1825 int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, int scan_type, const char *extract_path, int is_burst, uid_t uid)
1827 int ret = MS_MEDIA_ERR_NONE;
1828 sqlite3 * db_handle = (sqlite3 *)handle;
1829 sqlite3_stmt *sql_stmt = NULL;
1830 media_svc_media_type_e media_type;
1831 media_svc_content_info_s content_info;
1832 GArray *db_data_array = NULL;
1833 media_svc_item_info_s *db_data = NULL;
1836 media_svc_debug_fenter();
1838 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1839 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1841 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)) {
1842 media_svc_error("storage type is incorrect[%d]", storage_type);
1843 return MS_MEDIA_ERR_INVALID_PARAMETER;
1846 db_data_array = g_array_new(FALSE, FALSE, sizeof(media_svc_item_info_s*));
1847 if (db_data_array == NULL) {
1848 media_svc_error("db_data_array is NULL. Out of memory");
1849 return MS_MEDIA_ERR_OUT_OF_MEMORY;
1853 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
1854 if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE)
1855 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, extract_path, folder_uuid, uid);
1857 if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE && ret == MS_MEDIA_ERR_NONE) {
1858 media_svc_error("folder no recursive extract");
1860 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL and folder_uuid = '%q' ", storage_id, folder_uuid);
1862 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);
1863 } else if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
1864 media_svc_error("folder recursive extract");
1866 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL and path LIKE '%q%%' ", storage_id, extract_path);
1868 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);
1871 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL", storage_id);
1873 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL LIMIT %d", storage_id, BATCH_REQUEST_MAX);
1876 ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
1877 if (ret != MS_MEDIA_ERR_NONE) {
1878 media_svc_error("error when get list. err = [%d]", ret);
1879 g_array_free(db_data_array, FALSE);
1883 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
1885 db_data = malloc(sizeof(media_svc_item_info_s));
1886 if (db_data == NULL) {
1887 media_svc_error("Out of memory");
1891 db_data->path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
1892 db_data->media_type = (int)sqlite3_column_int(sql_stmt, 1);
1894 g_array_append_val(db_data_array, db_data);
1897 SQLITE3_FINALIZE(sql_stmt);
1898 media_svc_error("Insert Pass 2 get %d items!", db_data_array->len);
1900 while (db_data_array->len != 0) {
1902 db_data = g_array_index(db_data_array, media_svc_item_info_s*, 0);
1903 g_array_remove_index(db_data_array, 0);
1905 if ((db_data == NULL) || (db_data->path == NULL)) {
1906 media_svc_error("invalid db data");
1910 media_type = db_data->media_type;
1911 /* media_svc_debug("path is %s, media type %d", db_data->path, media_type); */
1912 memset(&content_info, 0, sizeof(media_svc_content_info_s));
1913 content_info.path = g_strdup(db_data->path);
1915 content_info.media_type = media_type;
1916 content_info.storage_type = storage_type;
1918 _media_svc_set_default_value(&content_info, FALSE);
1920 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
1921 || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
1922 || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
1923 || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
1924 media_svc_debug("Do nothing[%d]", media_type);
1925 else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
1926 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
1928 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
1930 ret = _media_svc_insert_item_pass2(storage_id, &content_info, is_burst, TRUE, uid);
1932 _media_svc_destroy_content_info(&content_info);
1933 SAFE_FREE(db_data->path);
1939 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
1941 _media_svc_publish_noti_list(idx);
1942 _media_svc_destroy_noti_list(idx);
1944 /* Recreate noti list */
1945 ret = _media_svc_create_noti_list(idx);
1949 while (db_data_array->len != 0) {
1951 db_data = g_array_index(db_data_array, media_svc_item_info_s*, 0);
1952 g_array_remove_index(db_data_array, 0);
1955 SAFE_FREE(db_data->path);
1961 g_array_free(db_data_array, FALSE);
1962 db_data_array = NULL;
1964 media_svc_debug_fleave();
1966 return MS_MEDIA_ERR_NONE;
1969 int media_svc_get_folder_scan_status(MediaSvcHandle *handle, const char *storage_id, const char *path, int *storage_status)
1971 int ret = MS_MEDIA_ERR_NONE;
1972 sqlite3 * db_handle = (sqlite3 *)handle;
1974 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1975 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1977 ret = _media_svc_get_folder_scan_status(db_handle, storage_id, path, storage_status);
1982 int media_svc_set_folder_scan_status(const char *storage_id, const char *path, int storage_status, uid_t uid)
1984 int ret = MS_MEDIA_ERR_NONE;
1986 ret = _media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
1991 int media_svc_get_folder_modified_time(MediaSvcHandle *handle, const char *path, const char *storage_id, bool *modified)
1993 int ret = MS_MEDIA_ERR_NONE;
1994 sqlite3 * db_handle = (sqlite3 *)handle;
1995 time_t modified_time = 0;
1996 int system_time = 0;
1998 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2000 ret = _media_svc_get_folder_modified_time_by_path(db_handle, path, storage_id, &modified_time);
2002 system_time = _media_svc_get_file_time(path);
2003 media_svc_error("modified_time = [%ld], system_time = [%d], path = [%s]", modified_time, system_time, path);
2005 if (system_time != modified_time && system_time != 0)
2013 int media_svc_get_null_scan_folder_list(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count)
2015 sqlite3 * db_handle = (sqlite3 *)handle;
2017 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2018 media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
2020 return _media_svc_get_null_scan_folder_list(db_handle, storage_id, folder_path, folder_list, count);
2023 int media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid)
2025 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
2026 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
2028 return _media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
2031 int media_svc_delete_invalid_folder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count)
2033 int ret = MS_MEDIA_ERR_NONE;
2034 sqlite3 * db_handle = (sqlite3 *)handle;
2036 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2038 ret = _media_svc_delete_invalid_folder_by_path(db_handle, storage_id, folder_path, uid, delete_count);
2043 int media_svc_check_folder_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path)
2045 int ret = MS_MEDIA_ERR_NONE;
2046 sqlite3 * db_handle = (sqlite3 *)handle;
2049 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2050 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
2051 media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
2053 ret = _media_svc_count_folder_with_path(db_handle, storage_id, folder_path, &count);
2054 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
2057 media_svc_debug("item is exist in database");
2058 return MS_MEDIA_ERR_NONE;
2060 media_svc_debug("item is not exist in database");
2061 return MS_MEDIA_ERR_DB_NO_RECORD;
2064 return MS_MEDIA_ERR_NONE;
2067 int media_svc_check_subfolder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count)
2069 int ret = MS_MEDIA_ERR_NONE;
2070 sqlite3 * db_handle = (sqlite3 *)handle;
2073 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2074 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
2075 media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
2078 ret = _media_svc_count_subfolder_with_path(db_handle, storage_id, folder_path, &cnt);
2079 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
2083 media_svc_debug("item is exist in database");
2084 return MS_MEDIA_ERR_NONE;
2086 media_svc_debug("item is not exist in database");
2087 return MS_MEDIA_ERR_DB_NO_RECORD;
2090 return MS_MEDIA_ERR_NONE;
2093 int media_svc_get_folder_id(MediaSvcHandle *handle, const char *storage_id, const char *path, char *folder_id)
2095 int ret = MS_MEDIA_ERR_NONE;
2096 sqlite3 * db_handle = (sqlite3 *)handle;
2098 media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2099 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
2101 ret = _media_svc_get_folder_uuid(db_handle, storage_id, path, folder_id);
2106 int media_svc_append_query(const char *query, uid_t uid)
2108 int ret = MS_MEDIA_ERR_NONE;
2110 media_svc_retvm_if(query == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
2112 ret = _media_svc_append_query_list(query, uid);
2117 int media_svc_send_query(uid_t uid)
2119 int ret = MS_MEDIA_ERR_NONE;
2121 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
2126 int media_svc_get_media_type(const char *path, int *mediatype)
2128 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
2130 return _media_svc_get_media_type(path, mediatype);