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.
22 #include "media-svc-media.h"
23 #include "media-svc-debug.h"
24 #include "media-svc-util.h"
25 #include "media-svc-db-utils.h"
26 #include "media-svc-env.h"
27 #include "media-svc-media-folder.h"
28 #include "media-svc-album.h"
29 #include "media-svc-noti.h"
30 #include "media-svc-storage.h"
32 #include <iniparser.h>
34 #define CONTENT_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
36 //static __thread int g_media_svc_data_cnt = 0;
37 static __thread int g_media_svc_cur_data_cnt = 0;
39 /* Flag for items to be published by notification */
40 static __thread bool g_insert_with_noti = false;
42 #define BATCH_ITEM_COUNT_MAX 100
44 int media_svc_check_table_exist(sqlite3 *handle, bool *exist)
46 return _media_svc_check_table_exist(handle, exist);
49 int media_svc_create_table(uid_t uid)
51 int ret = MS_MEDIA_ERR_NONE;
52 media_svc_debug_fenter();
54 ret = _media_svc_init_table_query();
55 if (ret != MS_MEDIA_ERR_NONE) {
56 media_svc_error("_media_svc_init_table_query fail.");
60 /*create media table*/
61 ret = _media_svc_make_table_query(DB_TABLE_MEDIA, DB_LIST_MEDIA, uid);
62 if (ret != MS_MEDIA_ERR_NONE) {
63 media_svc_error("_media_svc_make_table_query fail.");
67 /*create folder table*/
68 ret = _media_svc_make_table_query(DB_TABLE_FOLDER, DB_LIST_FOLDER, uid);
69 if (ret != MS_MEDIA_ERR_NONE) {
70 media_svc_error("_media_svc_make_table_query fail.");
74 /*create playlist_map table*/
75 ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST_MAP, DB_LIST_PLAYLIST_MAP, uid);
76 if (ret != MS_MEDIA_ERR_NONE) {
77 media_svc_error("_media_svc_make_table_query fail.");
81 /*create playlist table*/
82 ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST, DB_LIST_PLAYLIST, uid);
83 if (ret != MS_MEDIA_ERR_NONE) {
84 media_svc_error("_media_svc_make_table_query fail.");
88 /* create album table*/
89 ret = _media_svc_make_table_query(DB_TABLE_ALBUM, DB_LIST_ALBUM, uid);
90 if (ret != MS_MEDIA_ERR_NONE) {
91 media_svc_error("_media_svc_make_table_query fail.");
95 /*create tag_map table*/
96 ret = _media_svc_make_table_query(DB_TABLE_TAG_MAP, DB_LIST_TAG_MAP, uid);
97 if (ret != MS_MEDIA_ERR_NONE) {
98 media_svc_error("_media_svc_make_table_query fail.");
103 ret = _media_svc_make_table_query(DB_TABLE_TAG, DB_LIST_TAG, uid);
104 if (ret != MS_MEDIA_ERR_NONE) {
105 media_svc_error("_media_svc_make_table_query fail.");
109 /*create bookmark table*/
110 ret = _media_svc_make_table_query(DB_TABLE_BOOKMARK, DB_LIST_BOOKMARK, uid);
111 if (ret != MS_MEDIA_ERR_NONE) {
112 media_svc_error("_media_svc_make_table_query fail.");
116 /*create storage table from tizen 2.4 */
117 ret = _media_svc_make_table_query(DB_TABLE_STORAGE, DB_LIST_STORAGE, uid);
118 if (ret != MS_MEDIA_ERR_NONE) {
119 media_svc_error("_media_svc_make_table_query fail.");
123 /*create face table. from tizen 3.0*/
124 ret = _media_svc_make_table_query(DB_TABLE_FACE_SCAN_LIST, DB_LIST_FACE_SCAN_LIST, uid);
125 if (ret != MS_MEDIA_ERR_NONE) {
126 media_svc_error("_media_svc_make_table_query fail.");
130 ret = _media_svc_make_table_query(DB_TABLE_FACE, DB_LIST_FACE, uid);
131 if (ret != MS_MEDIA_ERR_NONE) {
132 media_svc_error("_media_svc_make_table_query fail.");
136 _media_svc_destroy_table_query();
138 media_svc_debug_fleave();
143 int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
145 return _media_svc_check_data_by_path(handle, path);
148 int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
150 return _media_svc_get_modified_time(handle, path, modified_time);
153 int media_svc_insert_item_begin(bool with_noti, int from_pid)
155 g_media_svc_cur_data_cnt = 0;
157 /* Prepare for making noti item list */
159 media_svc_debug("making noti list from pid[%d]", from_pid);
160 _media_svc_initialize_noti_list();
161 _media_svc_set_noti_from_pid(from_pid);
162 g_insert_with_noti = true;
165 return MS_MEDIA_ERR_NONE;
168 int media_svc_insert_item_end(uid_t uid)
170 int ret = MS_MEDIA_ERR_NONE;
172 media_svc_debug_fenter();
174 if (g_media_svc_cur_data_cnt > 0) {
175 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
176 if (g_insert_with_noti) {
177 media_svc_debug("sending noti list");
178 _media_svc_publish_noti_list();
179 g_insert_with_noti = false;
180 _media_svc_set_noti_from_pid(-1);
184 g_media_svc_cur_data_cnt = 0;
189 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)
191 int ret = MS_MEDIA_ERR_NONE;
192 long long int folder_id = 0;
194 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
195 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
196 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
197 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
199 media_svc_content_info_s content_info;
200 memset(&content_info, 0, sizeof(media_svc_content_info_s));
203 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, false);
204 if (ret != MS_MEDIA_ERR_NONE)
207 switch (content_info.media_type) {
208 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
209 ret = _media_svc_extract_image_metadata(&content_info);
211 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
212 case MEDIA_SVC_MEDIA_TYPE_SOUND:
213 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
214 ret = _media_svc_extract_media_metadata(handle, true, &content_info, uid);
216 case MEDIA_SVC_MEDIA_TYPE_BOOK:
217 ret = _media_svc_extract_book_metadata(&content_info);
218 /* The 'TITLE' should always be filled in */
219 if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
220 g_free(content_info.media_meta.title);
221 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
225 /* The 'TITLE' should always be filled in */
226 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
230 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
232 /*Set or Get folder id*/
233 ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, storage_type, &folder_id, uid);
234 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
236 content_info.folder_id = folder_id;
237 media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
239 ret = _media_svc_insert_item_with_data(true, &content_info, true, uid);
240 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
242 if (g_insert_with_noti)
243 _media_svc_insert_item_to_noti_list(&content_info);
245 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
246 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
247 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
248 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
250 if (g_insert_with_noti)
251 _media_svc_publish_noti_list();
253 g_media_svc_cur_data_cnt = 0;
256 _media_svc_destroy_content_info(&content_info);
258 return MS_MEDIA_ERR_NONE;
261 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)
263 int ret = MS_MEDIA_ERR_NONE;
264 long long int folder_id = 0;
266 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
267 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
268 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
269 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
271 media_svc_content_info_s content_info;
272 memset(&content_info, 0, sizeof(media_svc_content_info_s));
275 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, false);
276 if (ret != MS_MEDIA_ERR_NONE)
279 switch (content_info.media_type) {
280 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
281 ret = _media_svc_extract_image_metadata(&content_info);
283 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
284 case MEDIA_SVC_MEDIA_TYPE_SOUND:
285 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
286 ret = _media_svc_extract_media_metadata(handle, false, &content_info, uid);
288 case MEDIA_SVC_MEDIA_TYPE_BOOK:
289 ret = _media_svc_extract_book_metadata(&content_info);
290 /* The 'TITLE' should always be filled in */
291 if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
292 g_free(content_info.media_meta.title);
293 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
297 /* The 'TITLE' should always be filled in */
298 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
302 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
304 /*Set or Get folder id*/
305 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, storage_type, &folder_id, uid);
306 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
308 content_info.folder_id = folder_id;
309 media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
311 /* Extracting thumbnail */
312 if (content_info.thumbnail_path == NULL) {
313 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
314 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
316 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
317 if (ret == MS_MEDIA_ERR_NONE)
318 content_info.thumbnail_path = g_strdup(thumb_path);
322 ret = _media_svc_insert_item_with_data(false, &content_info, false, uid);
324 if (ret == MS_MEDIA_ERR_NONE) {
325 media_svc_debug("Insertion is successful. Sending noti for this");
326 _media_svc_publish_noti(MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
327 } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
328 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
331 _media_svc_destroy_content_info(&content_info);
335 int media_svc_move_item(sqlite3 *handle,
336 const char *src_path,
337 const char *dest_path,
338 const char *media_id,
340 const char *mime_type,
343 int ret = MS_MEDIA_ERR_NONE;
344 char *file_name = NULL;
345 char *folder_path = NULL;
346 int modified_time = 0;
347 long long int folder_id = 0;
348 char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
349 char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
350 ms_user_storage_type_e org_stg_type = MS_USER_STORAGE_INTERNAL;
351 ms_user_storage_type_e dst_stg_type = MS_USER_STORAGE_INTERNAL;
353 media_svc_debug_fenter();
355 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
356 media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
357 media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
358 media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
359 media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
362 ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
363 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
364 /* Get storage_type */
365 ret = ms_user_get_storage_type(uid, src_path, &org_stg_type);
366 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
367 ret = ms_user_get_storage_type(uid, dest_path, &dst_stg_type);
368 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
370 /*check and update folder*/
371 ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, dst_stg_type, &folder_id, uid);
372 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
375 file_name = g_path_get_basename(dest_path);
377 /*get modified_time*/
378 modified_time = _media_svc_get_file_time(dest_path);
380 /*get old thumbnail_path and remove thumbnail */
381 ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
382 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
383 media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
388 _media_svc_remove_file(old_thumb_path);
391 ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_id, uid);
393 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
395 media_svc_debug("Move is successful. Sending noti for this");
396 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
398 /*update folder modified_time*/
399 folder_path = g_path_get_dirname(dest_path);
400 ret = _media_svc_update_folder_modified_time(folder_path, uid);
402 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
404 return MS_MEDIA_ERR_NONE;
407 int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
409 int ret = MS_MEDIA_ERR_NONE;
411 ret = _media_svc_update_item_validity(path, validity, true, uid);
412 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
414 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
415 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
416 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
417 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
419 g_media_svc_cur_data_cnt = 0;
425 int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
427 int ret = MS_MEDIA_ERR_NONE;
428 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
429 media_svc_noti_item *noti_item = NULL;
431 media_svc_debug_fenter();
433 /*Get thumbnail path to delete*/
434 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
435 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
437 /* Get notification info */
438 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
439 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
442 ret = _media_svc_delete_item_by_path(path, uid);
443 if (ret != MS_MEDIA_ERR_NONE) {
444 media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
445 _media_svc_destroy_noti_item(noti_item);
450 /* Send notification */
451 media_svc_debug("Deletion is successful. Sending noti for this");
452 _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
453 _media_svc_destroy_noti_item(noti_item);
456 _media_svc_remove_file(thumb_path);
458 return MS_MEDIA_ERR_NONE;
461 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)
463 int ret = MS_MEDIA_ERR_NONE;
464 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
465 media_svc_content_info_s content_info = {0, };
466 media_svc_noti_item *noti_item = NULL;
468 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
469 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
470 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
471 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
474 ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, true);
475 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
477 /* Initialize thumbnail information to remake thumbnail. */
478 ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
479 if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
480 goto REFRESH_FINALIZE;
482 if (STRING_VALID(thumb_path)) {
483 _media_svc_remove_file(thumb_path);
485 ret = _media_svc_update_thumbnail_path(path, NULL, uid);
486 if (ret != MS_MEDIA_ERR_NONE)
487 goto REFRESH_FINALIZE;
490 /* Get notification info */
491 ret = _media_svc_get_noti_info(handle, path, ¬i_item);
492 if (ret != MS_MEDIA_ERR_NONE)
493 goto REFRESH_FINALIZE;
495 content_info.media_type = noti_item->media_type;
496 content_info.mime_type = g_strdup(noti_item->mime_type);
498 switch (content_info.media_type) {
499 case MEDIA_SVC_MEDIA_TYPE_IMAGE:
500 ret = _media_svc_extract_image_metadata(&content_info);
502 case MEDIA_SVC_MEDIA_TYPE_VIDEO:
503 case MEDIA_SVC_MEDIA_TYPE_SOUND:
504 case MEDIA_SVC_MEDIA_TYPE_MUSIC:
505 ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
507 case MEDIA_SVC_MEDIA_TYPE_BOOK:
508 ret = _media_svc_extract_book_metadata(&content_info);
509 /* The 'TITLE' should always be filled in */
510 if (!content_info.media_meta.title || strlen(content_info.media_meta.title) == 0) {
511 g_free(content_info.media_meta.title);
512 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
516 /* The 'TITLE' should always be filled in */
517 content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
521 if (ret != MS_MEDIA_ERR_NONE)
522 goto REFRESH_FINALIZE;
524 /* Extracting thumbnail */
525 if (content_info.thumbnail_path == NULL) {
526 if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
527 memset(thumb_path, 0, sizeof(thumb_path));
529 ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
530 if (ret == MS_MEDIA_ERR_NONE)
531 content_info.thumbnail_path = g_strdup(thumb_path);
535 ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
537 if (ret == MS_MEDIA_ERR_NONE) {
539 /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
540 if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
541 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
542 if (ret != MS_MEDIA_ERR_NONE)
543 goto REFRESH_FINALIZE;
545 g_media_svc_cur_data_cnt = 0;
548 /* Except scanner case */
549 media_svc_debug("Update is successful. Sending noti for this");
550 _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
553 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
557 _media_svc_destroy_content_info(&content_info);
558 _media_svc_destroy_noti_item(noti_item);
563 int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
565 media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
567 return _media_svc_publish_dir_noti(update_type, dir_path, folder_id, pid);
570 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)
572 return _media_svc_publish_noti(update_type, path, media_type, uuid, mime_type);
575 int media_svc_set_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid)
577 int ret = MS_MEDIA_ERR_NONE;
579 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
581 ret = _media_svc_update_storage_validity(storage_id, validity, uid);
582 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);
587 int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
589 return _media_svc_get_storage_uuid(handle, path, storage_id, uid);
592 int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
594 return _media_svc_check_storage(handle, storage_id, storage_path, validity);
597 int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
599 return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
602 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)
604 int ret = MS_MEDIA_ERR_NONE;
606 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
607 media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
608 media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
609 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
611 ret = _media_svc_append_storage(storage_id, storage_path, storage_type, uid);
612 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
614 /* Remove external storage that validity is 0 */
615 ret = _media_svc_delete_invalid_storage(handle, uid);
616 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
621 int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
623 media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
624 media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
625 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
626 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
628 return _media_svc_append_by_folder_path(handle, storage_id, path, storage_type, uid);
631 int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
633 return _media_svc_set_folder_validity(true, start_path, validity, is_recursive, uid);
636 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *folder_path)
638 return _media_svc_check_folder_by_path(handle, folder_path);
641 int media_svc_append_query(const char *query, uid_t uid)
643 return _media_svc_append_query_list(query, uid);
646 int media_svc_send_query(uid_t uid)
648 return _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
651 int media_svc_get_media_type(const char *path, int *mediatype)
653 return _media_svc_get_media_type(path, mediatype);
656 int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
658 int ret = MS_MEDIA_ERR_NONE;
659 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
662 // 1. Check media type
663 if (media_type != MS_MEDIA_IMAGE && media_type != MS_MEDIA_VIDEO)
664 return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
666 // 2. try to create thumbnail
667 ret = _media_svc_create_thumbnail(file_path, thumb_path, media_type, uid);
668 if (ret != MS_MEDIA_ERR_NONE) {
669 media_svc_error("Failed to create thumbnail [%d]", ret);
670 if (ret == MS_MEDIA_ERR_THUMB_UNSUPPORTED)
674 // 3. Update creation result to media db
675 sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
677 ret = _media_svc_sql_query(sql, uid);
678 SQLITE3_SAFE_FREE(sql);
679 if (ret != MS_MEDIA_ERR_NONE) {
680 media_svc_error("Failed to update media db [%d]", ret);
681 *thumbnail_path = g_strdup("");
683 *thumbnail_path = g_strdup(thumb_path);
689 static int __media_svc_get_ebook_search_type(void)
691 dictionary *dict = NULL;
692 static int _ebook_search_type = -1;
694 if (_ebook_search_type == -1) {
695 dict = iniparser_load(CONTENT_INI_DEFAULT_PATH);
697 media_svc_error("%s load failed. Use direct search.", CONTENT_INI_DEFAULT_PATH);
698 return MEDIA_SVC_SEARCH_TYPE_DIRECT;
701 _ebook_search_type = iniparser_getint(dict, "media-content-config:ebook_search_type", 0);
702 media_svc_debug("ebook_search_type [%d]", _ebook_search_type);
704 iniparser_freedict(dict);
707 return _ebook_search_type;
710 int media_svc_get_book_by_keyword(sqlite3 *handle, const char *keyword, uid_t uid, GList **result)
712 int ret = MS_MEDIA_ERR_NONE;
713 GList *item_list = NULL;
717 media_svc_retvm_if(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "db handle is NULL");
718 media_svc_retvm_if(!keyword, MS_MEDIA_ERR_INVALID_PARAMETER, "keyword is NULL");
719 media_svc_retvm_if(!result, MS_MEDIA_ERR_INVALID_PARAMETER, "result is NULL");
721 query = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=%d AND validity=1;",
722 DB_TABLE_MEDIA, MEDIA_SVC_MEDIA_TYPE_BOOK);
724 ret = _media_svc_get_media(handle, query, &item_list);
725 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_media failed");
727 if (__media_svc_get_ebook_search_type() == MEDIA_SVC_SEARCH_TYPE_DB) {
728 for (iter = item_list; iter; iter = g_list_next(iter))
729 _media_svc_update_wordbook((char *)iter->data, uid);
731 _media_svc_clean_wordbook(uid);
733 if (!_media_svc_get_matched_list(keyword, uid, result))
734 media_svc_error("_media_svc_get_matched_list failed");
736 for (iter = item_list; iter; iter = g_list_next(iter)) {
737 if (_media_svc_is_keyword_included((char *)iter->data, keyword))
738 *result = g_list_append(*result, g_strdup((gchar *)iter->data));
742 g_list_free_full(item_list, g_free);