4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "media-svc-media.h"
21 #include "media-svc-debug.h"
22 #include "media-svc-util.h"
23 #include "media-svc-db-utils.h"
24 #include "media-svc-env.h"
25 #include "media-svc-media-folder.h"
26 #include "media-svc-album.h"
27 #include "media-svc-noti.h"
28 #include "media-svc-storage.h"
30 #include <iniparser.h>
32 #define CONTENT_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
34 //static __thread int g_media_svc_data_cnt = 0;
35 static __thread int g_media_svc_cur_data_cnt = 0;
37 /* Flag for items to be published by notification */
38 static __thread bool g_insert_with_noti = false;
40 #define BATCH_ITEM_COUNT_MAX 100
42 int media_svc_check_table_exist(sqlite3 *handle, bool *exist)
44 return _media_svc_check_table_exist(handle, exist);
47 int media_svc_create_table(uid_t uid)
49 int ret = MS_MEDIA_ERR_NONE;
50 media_svc_debug_fenter();
52 ret = _media_svc_init_table_query();
53 if (ret != MS_MEDIA_ERR_NONE) {
54 media_svc_error("_media_svc_init_table_query fail.");
58 /*create media table*/
59 ret = _media_svc_make_table_query(DB_TABLE_MEDIA, DB_LIST_MEDIA, uid);
60 if (ret != MS_MEDIA_ERR_NONE) {
61 media_svc_error("_media_svc_make_table_query fail.");
65 /*create folder table*/
66 ret = _media_svc_make_table_query(DB_TABLE_FOLDER, DB_LIST_FOLDER, uid);
67 if (ret != MS_MEDIA_ERR_NONE) {
68 media_svc_error("_media_svc_make_table_query fail.");
72 /*create playlist_map table*/
73 ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST_MAP, DB_LIST_PLAYLIST_MAP, uid);
74 if (ret != MS_MEDIA_ERR_NONE) {
75 media_svc_error("_media_svc_make_table_query fail.");
79 /*create playlist table*/
80 ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST, DB_LIST_PLAYLIST, uid);
81 if (ret != MS_MEDIA_ERR_NONE) {
82 media_svc_error("_media_svc_make_table_query fail.");
86 /* create album table*/
87 ret = _media_svc_make_table_query(DB_TABLE_ALBUM, DB_LIST_ALBUM, uid);
88 if (ret != MS_MEDIA_ERR_NONE) {
89 media_svc_error("_media_svc_make_table_query fail.");
93 /*create tag_map table*/
94 ret = _media_svc_make_table_query(DB_TABLE_TAG_MAP, DB_LIST_TAG_MAP, uid);
95 if (ret != MS_MEDIA_ERR_NONE) {
96 media_svc_error("_media_svc_make_table_query fail.");
101 ret = _media_svc_make_table_query(DB_TABLE_TAG, DB_LIST_TAG, uid);
102 if (ret != MS_MEDIA_ERR_NONE) {
103 media_svc_error("_media_svc_make_table_query fail.");
107 /*create bookmark table*/
108 ret = _media_svc_make_table_query(DB_TABLE_BOOKMARK, DB_LIST_BOOKMARK, uid);
109 if (ret != MS_MEDIA_ERR_NONE) {
110 media_svc_error("_media_svc_make_table_query fail.");
114 /*create storage table from tizen 2.4 */
115 ret = _media_svc_make_table_query(DB_TABLE_STORAGE, DB_LIST_STORAGE, uid);
116 if (ret != MS_MEDIA_ERR_NONE) {
117 media_svc_error("_media_svc_make_table_query fail.");
121 /*create face table. from tizen 3.0*/
122 ret = _media_svc_make_table_query(DB_TABLE_FACE_SCAN_LIST, DB_LIST_FACE_SCAN_LIST, uid);
123 if (ret != MS_MEDIA_ERR_NONE) {
124 media_svc_error("_media_svc_make_table_query fail.");
128 ret = _media_svc_make_table_query(DB_TABLE_FACE, DB_LIST_FACE, uid);
129 if (ret != MS_MEDIA_ERR_NONE) {
130 media_svc_error("_media_svc_make_table_query fail.");
134 _media_svc_destroy_table_query();
136 media_svc_debug_fleave();
141 int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
143 return _media_svc_check_data_by_path(handle, path);
146 int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
148 return _media_svc_get_modified_time(handle, path, modified_time);
151 int media_svc_insert_item_begin(bool with_noti, int from_pid)
153 g_media_svc_cur_data_cnt = 0;
155 /* Prepare for making noti item list */
157 media_svc_debug("making noti list from pid[%d]", from_pid);
158 _media_svc_initialize_noti_list();
159 _media_svc_set_noti_from_pid(from_pid);
160 g_insert_with_noti = true;
163 return MS_MEDIA_ERR_NONE;
166 int media_svc_insert_item_end(uid_t uid)
168 int ret = MS_MEDIA_ERR_NONE;
170 media_svc_debug_fenter();
172 if (g_media_svc_cur_data_cnt > 0) {
173 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
174 if (g_insert_with_noti) {
175 media_svc_debug("sending noti list");
176 _media_svc_publish_noti_list();
177 g_insert_with_noti = false;
178 _media_svc_set_noti_from_pid(-1);
182 g_media_svc_cur_data_cnt = 0;
187 int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
189 int ret = MS_MEDIA_ERR_NONE;
190 long long int folder_id = 0;
192 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
193 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
194 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
195 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
197 media_svc_content_info_s content_info;
198 memset(&content_info, 0, sizeof(media_svc_content_info_s));
201 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, false);
202 if (ret != MS_MEDIA_ERR_NONE)
205 switch (content_info.media_type) {
206 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
207 ret = _media_svc_extract_image_metadata(&content_info);
209 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
210 case MEDIA_SVC_MEDIA_TYPE_SOUND:
211 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
212 ret = _media_svc_extract_media_metadata(handle, true, &content_info, uid);
214 case MEDIA_SVC_MEDIA_TYPE_BOOK:
215 ret = _media_svc_extract_book_metadata(&content_info);
216 /* The 'TITLE' should always be filled in */
217 if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
218 g_free(content_info.media_meta.title);
219 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
223 /* The 'TITLE' should always be filled in */
224 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
228 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
230 /*Set or Get folder id*/
231 ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, storage_type, &folder_id, uid);
232 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
234 content_info.folder_id = folder_id;
235 media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
237 ret = _media_svc_insert_item_with_data(true, &content_info, true, uid);
238 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
240 if (g_insert_with_noti)
241 _media_svc_insert_item_to_noti_list(&content_info);
243 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
244 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
245 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
246 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
248 if (g_insert_with_noti)
249 _media_svc_publish_noti_list();
251 g_media_svc_cur_data_cnt = 0;
254 _media_svc_destroy_content_info(&content_info);
256 return MS_MEDIA_ERR_NONE;
259 int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
261 int ret = MS_MEDIA_ERR_NONE;
262 long long int folder_id = 0;
264 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
265 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
266 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
267 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
269 media_svc_content_info_s content_info;
270 memset(&content_info, 0, sizeof(media_svc_content_info_s));
273 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, false);
274 if (ret != MS_MEDIA_ERR_NONE)
277 switch (content_info.media_type) {
278 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
279 ret = _media_svc_extract_image_metadata(&content_info);
281 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
282 case MEDIA_SVC_MEDIA_TYPE_SOUND:
283 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
284 ret = _media_svc_extract_media_metadata(handle, false, &content_info, uid);
286 case MEDIA_SVC_MEDIA_TYPE_BOOK:
287 ret = _media_svc_extract_book_metadata(&content_info);
288 /* The 'TITLE' should always be filled in */
289 if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
290 g_free(content_info.media_meta.title);
291 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
295 /* The 'TITLE' should always be filled in */
296 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
300 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
302 /*Set or Get folder id*/
303 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, storage_type, &folder_id, uid);
304 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
306 content_info.folder_id = folder_id;
307 media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
309 /* Extracting thumbnail */
310 if (content_info.thumbnail_path == NULL) {
311 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
312 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
314 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
315 if (ret == MS_MEDIA_ERR_NONE)
316 content_info.thumbnail_path = g_strdup(thumb_path);
320 ret = _media_svc_insert_item_with_data(false, &content_info, false, uid);
322 if (ret == MS_MEDIA_ERR_NONE) {
323 media_svc_debug("Insertion is successful. Sending noti for this");
324 _media_svc_publish_noti(MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
325 } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
326 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
329 _media_svc_destroy_content_info(&content_info);
333 int media_svc_move_item(sqlite3 *handle,
334 const char *src_path,
335 const char *dest_path,
336 const char *media_id,
338 const char *mime_type,
341 int ret = MS_MEDIA_ERR_NONE;
342 char *file_name = NULL;
343 char *folder_path = NULL;
344 int modified_time = 0;
345 long long int folder_id = 0;
346 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
347 char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
348 ms_user_storage_type_e org_stg_type = MS_USER_STORAGE_INTERNAL;
349 ms_user_storage_type_e dst_stg_type = MS_USER_STORAGE_INTERNAL;
351 media_svc_debug_fenter();
353 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
354 media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
355 media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
356 media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
357 media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
360 ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
361 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
362 /* Get storage_type */
363 ret = ms_user_get_storage_type(uid, src_path, &org_stg_type);
364 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
365 ret = ms_user_get_storage_type(uid, dest_path, &dst_stg_type);
366 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
368 /*check and update folder*/
369 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, dst_stg_type, &folder_id, uid);
370 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
373 file_name = g_path_get_basename(dest_path);
375 /*get modified_time*/
376 modified_time = _media_svc_get_file_time(dest_path);
378 /*get old thumbnail_path and remove thumbnail */
379 ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
380 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
381 media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
386 _media_svc_remove_file(old_thumb_path);
389 ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_id, uid);
391 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
393 media_svc_debug("Move is successful. Sending noti for this");
394 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
396 /*update folder modified_time*/
397 folder_path = g_path_get_dirname(dest_path);
398 ret = _media_svc_update_folder_modified_time(folder_path, uid);
400 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
402 return MS_MEDIA_ERR_NONE;
405 int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
407 int ret = MS_MEDIA_ERR_NONE;
409 ret = _media_svc_update_item_validity(path, validity, true, uid);
410 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
412 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
413 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
414 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
415 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
417 g_media_svc_cur_data_cnt = 0;
423 int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
425 int ret = MS_MEDIA_ERR_NONE;
426 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
427 media_svc_noti_item *noti_item = NULL;
429 media_svc_debug_fenter();
431 /*Get thumbnail path to delete*/
432 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
433 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
435 /* Get notification info */
436 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
437 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
440 ret = _media_svc_delete_item_by_path(path, uid);
441 if (ret != MS_MEDIA_ERR_NONE) {
442 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
443 _media_svc_destroy_noti_item(noti_item);
448 /* Send notification */
449 media_svc_debug("Deletion is successful. Sending noti for this");
450 _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
451 _media_svc_destroy_noti_item(noti_item);
454 _media_svc_remove_file(thumb_path);
456 return MS_MEDIA_ERR_NONE;
459 int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
461 int ret = MS_MEDIA_ERR_NONE;
462 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
463 media_svc_content_info_s content_info = {0, };
464 media_svc_noti_item *noti_item = NULL;
466 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
467 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
468 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
469 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
472 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, true);
473 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
475 /* Initialize thumbnail information to remake thumbnail. */
476 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
477 if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
478 goto REFRESH_FINALIZE;
480 if (STRING_VALID(thumb_path)) {
481 _media_svc_remove_file(thumb_path);
483 ret = _media_svc_update_thumbnail_path(path, NULL, uid);
484 if (ret != MS_MEDIA_ERR_NONE)
485 goto REFRESH_FINALIZE;
488 /* Get notification info */
489 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
490 if (ret != MS_MEDIA_ERR_NONE)
491 goto REFRESH_FINALIZE;
493 content_info.media_type = noti_item->media_type;
494 content_info.mime_type = g_strdup(noti_item->mime_type);
496 switch (content_info.media_type) {
497 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
498 ret = _media_svc_extract_image_metadata(&content_info);
500 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
501 case MEDIA_SVC_MEDIA_TYPE_SOUND:
502 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
503 ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
505 case MEDIA_SVC_MEDIA_TYPE_BOOK:
506 ret = _media_svc_extract_book_metadata(&content_info);
507 /* The 'TITLE' should always be filled in */
508 if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
509 g_free(content_info.media_meta.title);
510 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
514 /* The 'TITLE' should always be filled in */
515 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
519 if (ret != MS_MEDIA_ERR_NONE)
520 goto REFRESH_FINALIZE;
522 /* Extracting thumbnail */
523 if (content_info.thumbnail_path == NULL) {
524 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
525 memset(thumb_path, 0, sizeof(thumb_path));
527 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
528 if (ret == MS_MEDIA_ERR_NONE)
529 content_info.thumbnail_path = g_strdup(thumb_path);
533 ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
535 if (ret == MS_MEDIA_ERR_NONE) {
537 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
538 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
539 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
540 if (ret != MS_MEDIA_ERR_NONE)
541 goto REFRESH_FINALIZE;
543 g_media_svc_cur_data_cnt = 0;
546 /* Except scanner case */
547 media_svc_debug("Update is successful. Sending noti for this");
548 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
551 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
555 _media_svc_destroy_content_info(&content_info);
556 _media_svc_destroy_noti_item(noti_item);
561 int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
563 media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
565 return _media_svc_publish_dir_noti(update_type, dir_path, folder_id, pid);
568 int media_svc_publish_noti(media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
570 return _media_svc_publish_noti(update_type, path, media_type, uuid, mime_type);
573 int media_svc_set_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid)
575 int ret = MS_MEDIA_ERR_NONE;
577 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
579 ret = _media_svc_update_storage_validity(storage_id, validity, uid);
580 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);
585 int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
587 return _media_svc_get_storage_uuid(handle, path, storage_id, uid);
590 int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
592 return _media_svc_check_storage(handle, storage_id, storage_path, validity);
595 int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
597 return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
600 int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, ms_user_storage_type_e storage_type, uid_t uid)
602 int ret = MS_MEDIA_ERR_NONE;
604 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
605 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
606 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
607 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
609 ret = _media_svc_append_storage(storage_id, storage_path, storage_type, uid);
610 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
612 /* Remove external storage that validity is 0 */
613 ret = _media_svc_delete_invalid_storage(handle, uid);
614 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
619 int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
621 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
622 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
623 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
624 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
626 return _media_svc_append_by_folder_path(handle, storage_id, path, storage_type, uid);
629 int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
631 return _media_svc_set_folder_validity(true, start_path, validity, is_recursive, uid);
634 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *folder_path)
636 return _media_svc_check_folder_by_path(handle, folder_path);
639 int media_svc_append_query(const char *query, uid_t uid)
641 return _media_svc_append_query_list(query, uid);
644 int media_svc_send_query(uid_t uid)
646 return _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
649 int media_svc_get_media_type(const char *path, int *mediatype)
651 return _media_svc_get_media_type(path, mediatype);
654 int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
656 int ret = MS_MEDIA_ERR_NONE;
657 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
660 // 1. Check media type
661 if (media_type != MS_MEDIA_IMAGE && media_type != MS_MEDIA_VIDEO)
662 return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
664 // 2. try to create thumbnail
665 ret = _media_svc_create_thumbnail(file_path, thumb_path, media_type, uid);
666 if (ret != MS_MEDIA_ERR_NONE) {
667 media_svc_error("Failed to create thumbnail [%d]", ret);
668 if (ret == MS_MEDIA_ERR_THUMB_UNSUPPORTED)
672 // 3. Update creation result to media db
673 sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
675 ret = _media_svc_sql_query(sql, uid);
676 SQLITE3_SAFE_FREE(sql);
677 if (ret != MS_MEDIA_ERR_NONE) {
678 media_svc_error("Failed to update media db [%d]", ret);
679 *thumbnail_path = g_strdup("");
681 *thumbnail_path = g_strdup(thumb_path);
687 static int __media_svc_get_ebook_search_type(void)
689 dictionary *dict = NULL;
690 static int _ebook_search_type = -1;
692 if (_ebook_search_type == -1) {
693 dict = iniparser_load(CONTENT_INI_DEFAULT_PATH);
695 media_svc_error("%s load failed. Use direct search.", CONTENT_INI_DEFAULT_PATH);
696 return MEDIA_SVC_SEARCH_TYPE_DIRECT;
699 _ebook_search_type = iniparser_getint(dict, "media-content-config:ebook_search_type", 0);
700 media_svc_debug("ebook_search_type [%d]", _ebook_search_type);
702 iniparser_freedict(dict);
705 return _ebook_search_type;
708 int media_svc_get_book_by_keyword(sqlite3 *handle, const char *keyword, uid_t uid, GList **result)
710 int ret = MS_MEDIA_ERR_NONE;
711 GList *item_list = NULL;
715 media_svc_retvm_if(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "db handle is NULL");
716 media_svc_retvm_if(!keyword, MS_MEDIA_ERR_INVALID_PARAMETER, "keyword is NULL");
717 media_svc_retvm_if(!result, MS_MEDIA_ERR_INVALID_PARAMETER, "result is NULL");
719 query = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=%d AND validity=1;",
720 DB_TABLE_MEDIA, MEDIA_SVC_MEDIA_TYPE_BOOK);
722 ret = _media_svc_get_media(handle, query, &item_list);
723 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_media failed");
725 if (__media_svc_get_ebook_search_type() == MEDIA_SVC_SEARCH_TYPE_DB) {
726 for (iter = item_list; iter; iter = g_list_next(iter))
727 _media_svc_update_wordbook((char *)iter->data, uid);
729 _media_svc_clean_wordbook(uid);
731 if (!_media_svc_get_matched_list(keyword, uid, result))
732 media_svc_error("_media_svc_get_matched_list failed");
734 for (iter = item_list; iter; iter = g_list_next(iter)) {
735 if (_media_svc_is_keyword_included((char *)iter->data, keyword))
736 *result = g_list_append(*result, g_strdup((gchar *)iter->data));
740 g_list_free_full(item_list, g_free);