4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.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"
26 #include "media-common-utils.h"
27 #include "media-common-db-svc.h"
28 #include "media-common-dbg.h"
29 #include <tzplatform_config.h>
31 #define CONFIG_PATH PATH_LIBDIR"/libmedia-content-plugin.so"
33 static GMutex db_mutex;
34 static void **func_array;
35 static void *func_handle = NULL;
36 static int scan_other_type = -1;
38 typedef int (*CLEANUP_DB)(sqlite3*, uid_t);
39 typedef int (*INSERT_ITEM_BEGIN)(bool, int);
40 typedef int (*INSERT_ITEM_END)(uid_t);
42 typedef int (*SEND_DIR_UPDATE_NOTI)(const char *, const char *, int, int);
43 typedef int (*INSERT_ITEM)(sqlite3 *, const char *, const char *, int, uid_t);
44 typedef int (*SET_ITEM_VALIDITY)(const char *, const char *, int, int, uid_t);
45 typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(sqlite3 *, const char *, const char *, bool, uid_t);
46 typedef int (*UPDATE_FOLDER_TIME)(sqlite3 *, const char *, const char *, uid_t);
47 typedef int (*GET_STORAGE_ID)(sqlite3 *, const char *, char *, uid_t uid);
48 typedef int (*SET_STORAGE_SCAN_STATUS)(sqlite3 *, const char *, int, uid_t);
49 typedef int (*INSERT_FOLDER)(sqlite3 *, const char *, const char *, int, uid_t);
50 typedef int (*SET_FOLDER_VALIDITY)(sqlite3 *, const char *, const char *, int, bool, uid_t);
51 typedef int (*INSERT_ITEM_SCAN)(sqlite3 *, const char *, const char *, int, uid_t);
52 typedef int (*GET_FOLDER_SCAN_STATUS)(sqlite3 *, const char *, const char *, int *);
53 typedef int (*SET_FOLDER_SCAN_STATUS)(sqlite3 *, const char *, const char *, int, uid_t);
54 typedef int (*CHECK_FOLDER_MODIFIED)(sqlite3 *, const char *, const char *, bool *);
55 typedef int (*GET_NULL_SCAN_FOLDER_LIST)(sqlite3 *, const char *, const char *, GPtrArray **);
56 typedef int (*CHANGE_VALIDITY_ITEM_BATCH)(sqlite3 *, const char *, const char *, int, int, uid_t);
58 typedef int (*CHECK_DB)(sqlite3*, uid_t);
59 typedef int (*GET_UUID)(char **);
60 typedef int (*CHECK_STORAGE)(sqlite3 *, const char *, char **, int *, uid_t);
61 typedef int (*INSERT_STORAGE)(sqlite3 *, const char *, int, const char *, uid_t);
62 typedef int (*UPDATE_STORAGE)(sqlite3 *, const char *, const char *, uid_t);
63 typedef int (*SET_STORAGE_VALIDITY)(sqlite3 *, const char *, int, uid_t uid);
64 typedef int (*SET_ALL_STORAGE_VALIDITY)(sqlite3 *, int, uid_t);
66 typedef int (*UPDATE_ITEM_META)(sqlite3 *, uid_t);
68 typedef int (*DELETE_INVALID_FOLDER_BY_PATH)(sqlite3 *, const char *, const char *, uid_t);
69 typedef int (*CHECK_FOLDER_EXIST)(sqlite3*, const char*, const char*);
70 typedef int (*GET_AND_EXTRACT_MEDIA)(sqlite3*, const char*, int, const char *);
71 typedef int (*GET_MEDIA_TYPE)(const char *, int *);
72 typedef int (*REFRESH_ITEM)(sqlite3 *, const char *, const char *, uid_t);
82 eSEND_DIR_UPDATE_NOTI,
85 eSET_STORAGE_SCAN_STATUS,
88 eGET_FOLDER_SCAN_STATUS,
89 eSET_FOLDER_SCAN_STATUS,
90 eCHECK_FOLDER_MODIFIED,
91 eGET_NULL_SCAN_FOLDER_LIST,
92 eCHANGE_VALIDITY_ITEM_BATCH,
98 eSET_STORAGE_VALIDITY,
99 eSET_ALL_STORAGE_VALIDITY,
101 eDELETE_INVALID_FOLDER_BY_PATH,
104 eGET_AND_EXTRACT_MEDIA,
109 int ms_load_functions(void)
112 char func_list[eFUNC_MAX][40] = {
119 "delete_all_invalid_items_in_folder",
120 "send_dir_update_noti",
121 "update_folder_time",
123 "set_storage_scan_status",
125 "set_folder_validity",
126 "get_folder_scan_status",
127 "set_folder_scan_status",
128 "check_folder_modified",
129 "get_null_scan_folder_list",
130 "change_validity_item_batch",
136 "set_storage_validity",
137 "set_all_storage_validity",
139 "delete_invalid_folder_by_path",
140 "check_folder_exist",
142 "get_and_extract_media",
146 func_handle = dlopen(CONFIG_PATH, RTLD_LAZY);
147 MS_DBG_RETVM_IF(!func_handle, MS_MEDIA_ERR_INTERNAL, "%s", dlerror());
151 func_array = g_new0(gpointer, eFUNC_MAX);
153 for (func_index = 0; func_index < eFUNC_MAX ; func_index++) {
154 func_array[func_index] = dlsym(func_handle, func_list[func_index]);
155 if (func_array[func_index] == NULL) {
156 MS_DBG_ERR("dlsym failed[%s]", func_list[func_index]);
158 dlclose(func_handle);
160 return MS_MEDIA_ERR_INTERNAL;
164 return MS_MEDIA_ERR_NONE;
167 void ms_unload_functions(void)
169 dlclose(func_handle);
173 int ms_connect_db(sqlite3 **handle, uid_t uid)
175 int ret = MS_MEDIA_ERR_NONE;
177 g_mutex_lock(&db_mutex);
179 ret = media_db_connect(handle, uid, false);
181 g_mutex_unlock(&db_mutex);
186 void ms_disconnect_db(sqlite3 *handle)
188 media_db_disconnect(handle);
191 int ms_cleanup_db(sqlite3 *handle, uid_t uid)
193 int ret = MS_MEDIA_ERR_NONE;
195 ret = ((CLEANUP_DB)func_array[eCLEANUP_DB])(handle, uid);
196 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CLEANUP_DB failed [%d]", ret);
198 MS_DBG_INFO("Cleanup Media DB");
203 static int __ms_check_item_exist(sqlite3 *handle, const char *storage_id, const char *path, bool *modified)
205 int ret = MS_MEDIA_ERR_NONE;
207 time_t modified_time = 0;
208 unsigned long long file_size = 0;
210 sqlite3_stmt *sql_stmt = NULL;
214 MS_DBG_RETVM_IF(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
216 #ifdef _USE_TVPD_MODE
217 MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
219 sql = sqlite3_mprintf("SELECT media_modified_time, media_size, media_type, media_timeline,folder_id FROM '%q' WHERE media_path='%q'", storage_id, path);
221 sql = sqlite3_mprintf("SELECT media_modified_time, media_size FROM media WHERE media_path='%q'", path);
224 ret = media_db_get_result(handle, sql, &sql_stmt);
225 if (ret != MS_MEDIA_ERR_NONE) {
226 MS_DBG_ERR("Error when media_db_get_result. err = [%d]", ret);
230 if (sqlite3_step(sql_stmt) != SQLITE_ROW) {
231 ret = MS_MEDIA_ERR_DB_NO_RECORD;
233 modified_time = (int)sqlite3_column_int(sql_stmt, 0);
234 file_size = (unsigned long long)sqlite3_column_int64(sql_stmt, 1);
235 #ifdef _USE_TVPD_MODE
236 int media_type = (int)sqlite3_column_int(sql_stmt, 2);
237 if (media_type == MS_MEDIA_TYPE_PVR)
238 modified_time = (int)sqlite3_column_int(sql_stmt, 3);
240 memset(&st, 0, sizeof(struct stat));
241 if (stat(path, &st) == 0) {
242 if ((st.st_mtime != modified_time) || (st.st_size != file_size)) {
246 #ifdef _USE_TVPD_MODE
247 char *folder_id_media = NULL;
248 char *folder_id_folder = NULL;
250 folder_id_media = (char *)sqlite3_column_text(sql_stmt, 4);
251 char *folder_path = NULL;
252 folder_path = g_path_get_dirname(path);
253 ret = ms_get_folder_id(handle, storage_id, folder_path, &folder_id_folder);
255 if(ret == MS_MEDIA_ERR_NONE) {
256 if (g_strcmp0(folder_id_media, folder_id_folder) == 0)
263 g_free(folder_id_folder);
269 MS_SQLITE3_FINALIZE(sql_stmt);
274 int ms_validate_item(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
276 int ret = MS_MEDIA_ERR_NONE;
277 bool modified = false;
279 ret = __ms_check_item_exist(handle, storage_id, path, &modified);
280 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
281 #ifdef _USE_TVPD_MODE
282 ret = ms_scan_item_batch(handle, storage_id, path, uid);
284 ret = ms_insert_item_batch(handle, storage_id, path, uid);
286 } else if (ret == MS_MEDIA_ERR_NONE) {
288 ret = ((SET_ITEM_VALIDITY)func_array[eSET_VALIDITY])(storage_id, path, true, true, uid);
289 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_ITEM_VALIDITY failed [%d]", ret);
291 ret = ((REFRESH_ITEM)func_array[eREFRESH_ITEM])(handle, storage_id, path, uid);
292 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "REFRESH_ITEM failed [%d]", ret);
295 MS_DBG_ERR("check_item_exist failed [%d]", ret);
301 int ms_validity_change_all_items(sqlite3 *handle, const char *storage_id, bool validity , uid_t uid)
303 int ret = MS_MEDIA_ERR_NONE;
305 #ifdef _USE_TVPD_MODE
306 MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
308 char *sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d;", storage_id, validity);
310 char *sql = sqlite3_mprintf("UPDATE media SET validity=%d WHERE storage_uuid=%Q;", validity, storage_id);
313 ret = media_db_update_db_direct(sql, uid);
314 MS_SQLITE3_SAFE_FREE(sql);
319 int ms_insert_item_batch(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
321 int ret = MS_MEDIA_ERR_NONE;
322 ms_user_storage_type_e storage_type = -1;
326 ret = ms_user_get_storage_type(uid, path, &storage_type);
327 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
329 ret = ((INSERT_ITEM)func_array[eINSERT_BATCH])(handle, storage_id, path, storage_type, uid);
330 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "INSERT_ITEM failed [%d]", ret);
335 int ms_scan_item_batch(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
337 int ret = MS_MEDIA_ERR_NONE;
338 ms_user_storage_type_e storage_type;
342 ret = ms_user_get_storage_type(uid, path, &storage_type);
343 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
345 ret = ((INSERT_ITEM_SCAN)func_array[eINSERT_SCAN])(handle, storage_id, path, storage_type, uid);
346 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "INSERT_ITEM_SCAN failed [%d]", ret);
351 int ms_get_and_extract_media(sqlite3 *handle, const char *storage_id, int scan_type, const char *path)
353 int ret = MS_MEDIA_ERR_NONE;
355 ret = ((GET_AND_EXTRACT_MEDIA)func_array[eGET_AND_EXTRACT_MEDIA])(handle, storage_id, scan_type, path);
356 if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
357 MS_DBG_ERR("GET_AND_EXTRACT_MEDIA failed [%d]", ret);
362 int ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, uid_t uid)
364 int ret = MS_MEDIA_ERR_NONE;
365 sqlite3_stmt *sql_stmt = NULL;
366 GPtrArray *thumb_list = NULL;
370 thumb_list = g_ptr_array_new_with_free_func(g_free);
371 #ifdef _USE_TVPD_MODE
372 MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
374 char *sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM '%q' WHERE validity IN (%d, %d) AND media_thumbnail_path IS NOT NULL", storage_id, MS_INVALID, MS_SCANNING);
376 char *sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM media WHERE validity IN (%d, %d) AND media_thumbnail_path IS NOT NULL", MS_INVALID, MS_SCANNING);
378 MS_DBG_SLOG("[SQL query] : %s", sql);
380 ret = media_db_get_result(handle, sql, &sql_stmt);
381 if (ret != MS_MEDIA_ERR_NONE) {
382 MS_DBG_ERR("Query failed. err[%d]", ret);
383 g_ptr_array_free(thumb_list, TRUE);
387 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
388 path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
389 g_ptr_array_add(thumb_list, path);
392 MS_SQLITE3_FINALIZE(sql_stmt);
394 #ifdef _USE_TVPD_MODE
395 sql = sqlite3_mprintf("DELETE FROM '%q' WHERE validity IN (%d, %d)", storage_id, MS_INVALID, MS_SCANNING);
397 sql = sqlite3_mprintf("DELETE FROM media WHERE validity IN (%d, %d)", MS_INVALID, MS_SCANNING);
400 ret = media_db_update_db_direct(sql, uid);
401 MS_SQLITE3_SAFE_FREE(sql);
402 if (ret != MS_MEDIA_ERR_NONE) {
403 g_ptr_array_free(thumb_list, TRUE);
407 for (i = 0; i < thumb_list->len; i++) {
408 path = g_ptr_array_index(thumb_list, i);
410 if (remove(path) != 0)
411 MS_DBG_ERR("fail to remove thumbnail file.");
414 g_ptr_array_free(thumb_list, TRUE);
416 return MS_MEDIA_ERR_NONE;
419 int ms_set_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *path, int validity, int recursive, uid_t uid)
421 int ret = MS_MEDIA_ERR_NONE;
424 MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
425 MS_DBG_RETVM_IF(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
427 #ifdef _USE_TVPD_MODE
429 sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE media_path LIKE '%q/%%';", storage_id, validity, path);
431 sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE folder_id IN (SELECT folder_id FROM folder WHERE folder_path='%q' AND storage_uuid='%q');", storage_id, validity, path, storage_id);
434 sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path LIKE '%q/%%';", INTERNAL_STORAGE_ID, validity, path);
436 sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_id=(SELECT folder_id FROM folder WHERE folder_path=%Q);", INTERNAL_STORAGE_ID, validity, path, storage_id);
439 ret = media_db_update_db_direct(sql, uid);
440 MS_SQLITE3_SAFE_FREE(sql);
445 int ms_delete_invalid_items_in_folder(sqlite3 *handle, const char *storage_id, const char *path, bool is_recursive, uid_t uid)
447 int ret = MS_MEDIA_ERR_NONE;
449 ret = ((DELETE_ALL_INVALID_ITEMS_IN_FOLDER)func_array[eDELETE_FOLDER])(handle, storage_id, path, is_recursive, uid);
450 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "DELETE_ALL_INVALID_ITEMS_IN_FOLDER failed [%d]", ret);
455 int ms_send_dir_update_noti(const char*path, const char*folder_id, ms_noti_type_e noti_type, int pid)
457 int ret = MS_MEDIA_ERR_NONE;
459 ret = ((SEND_DIR_UPDATE_NOTI)func_array[eSEND_DIR_UPDATE_NOTI])(path, folder_id, (int)noti_type, pid);
460 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SEND_DIR_UPDATE_NOTI failed [%d]", ret);
465 int ms_update_folder_time(sqlite3 *handle, const char *storage_id, char *folder_path, uid_t uid)
467 int ret = MS_MEDIA_ERR_NONE;
469 ret = ((UPDATE_FOLDER_TIME)func_array[eUPDATE_FOLDER_TIME])(handle, storage_id, folder_path, uid);
470 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "UPDATE_FOLDER_TIME failed [%d]", ret);
475 int ms_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
477 int ret = MS_MEDIA_ERR_NONE;
481 ret = ((GET_STORAGE_ID)func_array[eGET_STORAGE_ID])(handle, path, storage_id, uid);
482 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_STORAGE_ID failed [%d]", ret);
484 MS_DBG("storage_id [%s]", storage_id);
489 int ms_set_storage_scan_status(sqlite3 *handle, char *storage_id, media_scan_status_e scan_status, uid_t uid)
491 int ret = MS_MEDIA_ERR_NONE;
492 int status = scan_status;
496 ret = ((SET_STORAGE_SCAN_STATUS)func_array[eSET_STORAGE_SCAN_STATUS])(handle, storage_id, status, uid);
497 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_STORAGE_SCAN_STATUS failed [%d]", ret);
499 MS_DBG("storage_id [%s], scan_status [%d]", storage_id, scan_status);
504 int ms_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
506 int ret = MS_MEDIA_ERR_NONE;
507 ms_user_storage_type_e storage_type;
509 ret = ms_user_get_storage_type(uid, path, &storage_type);
510 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
512 ret = ((INSERT_FOLDER)func_array[eINSERT_FOLDER])(handle, storage_id, path, storage_type, uid);
513 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "INSERT_FOLDER failed [%d]", ret);
518 int ms_delete_invalid_folder(const char *storage_id, uid_t uid)
520 int ret = MS_MEDIA_ERR_NONE;
523 #ifdef _USE_TVPD_MODE
524 MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
526 sql = sqlite3_mprintf("DELETE FROM folder WHERE storage_uuid='%q' AND validity IN (%d, %d)", storage_id, MS_INVALID, MS_SCANNING);
528 sql = sqlite3_mprintf("DELETE FROM folder WHERE validity IN (%d, %d)", MS_INVALID, MS_SCANNING);
530 ret = media_db_update_db_direct(sql, uid);
532 MS_SQLITE3_SAFE_FREE(sql);
537 int ms_set_folder_validity(sqlite3 *handle, const char *storage_id, const char *path, int validity, bool is_recursive, uid_t uid)
539 int ret = MS_MEDIA_ERR_NONE;
541 ret = ((SET_FOLDER_VALIDITY)func_array[eSET_FOLDER_VALIDITY])(handle, storage_id, path, validity, is_recursive, uid);
542 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_FOLDER_VALIDITY failed [%d]", ret);
547 int ms_check_db_upgrade(sqlite3 *handle, uid_t uid)
549 int ret = MS_MEDIA_ERR_NONE;
553 ret = ((CHECK_DB)func_array[eCHECK_DB])(handle, uid);
554 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CHECK_DB failed [%d]", ret);
561 int ms_genarate_uuid(char **uuid)
563 int ret = MS_MEDIA_ERR_NONE;
565 ret = ((GET_UUID)func_array[eGET_UUID])(uuid);
566 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_UUID failed [%d]", ret);
571 int ms_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid)
573 int ret = MS_MEDIA_ERR_NONE;
577 ret = ((CHECK_STORAGE)func_array[eCHECK_STORAGE])(handle, storage_id, storage_path, validity, uid);
578 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CHECK_STORAGE failed [%d]", ret);
585 int ms_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
587 int ret = MS_MEDIA_ERR_NONE;
588 ms_user_storage_type_e storage_type;
592 ret = ms_user_get_storage_type(uid, storage_path, &storage_type);
593 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
595 ret = ((INSERT_STORAGE)func_array[eINSERT_STORAGE])(handle, storage_id, storage_type, storage_path, uid);
596 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "INSERT_STORAGE failed [%d]", ret);
603 int ms_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
605 int ret = MS_MEDIA_ERR_NONE;
609 ret = ((UPDATE_STORAGE)func_array[eUPDATE_STORAGE])(handle, storage_id, storage_path, uid);
610 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "UPDATE_STORAGE failed [%d]", ret);
617 int ms_set_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid)
619 int ret = MS_MEDIA_ERR_NONE;
621 ret = ((SET_STORAGE_VALIDITY)func_array[eSET_STORAGE_VALIDITY])(handle, storage_id, validity, uid);
622 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_STORAGE_VALIDITY failed [%d]", ret);
627 int ms_set_all_storage_validity(sqlite3 *handle, int validity, uid_t uid)
629 int ret = MS_MEDIA_ERR_NONE;
631 ret = ((SET_ALL_STORAGE_VALIDITY)func_array[eSET_ALL_STORAGE_VALIDITY])(handle, validity, uid);
632 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_ALL_STORAGE_VALIDITY failed [%d]", ret);
637 int ms_update_meta_batch(sqlite3 *handle, uid_t uid)
639 int ret = MS_MEDIA_ERR_NONE;
643 ret = ((UPDATE_ITEM_META)func_array[eUPDATE_ITEM_META])(handle, uid);
644 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "UPDATE_ITEM_META failed [%d]", ret);
649 int ms_delete_invalid_folder_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path, uid_t uid)
651 int ret = MS_MEDIA_ERR_NONE;
653 ret = ((DELETE_INVALID_FOLDER_BY_PATH)func_array[eDELETE_INVALID_FOLDER_BY_PATH])(handle, storage_id, folder_path, uid);
654 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "DELETE_INVALID_FOLDER_BY_PATH failed [%d]", ret);
659 int ms_check_folder_exist(sqlite3 *handle, const char *storage_id, const char *folder_path)
661 int ret = MS_MEDIA_ERR_NONE;
663 ret = ((CHECK_FOLDER_EXIST)func_array[eCHECK_FOLDER_EXIST])(handle, storage_id, folder_path);
664 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CHECK_FOLDER_EXIST failed [%d]", ret);
669 int ms_get_folder_id(sqlite3 *handle, const char *storage_id, const char *path, char **folder_id)
671 int ret = MS_MEDIA_ERR_NONE;
672 sqlite3_stmt *sql_stmt = NULL;
675 MS_DBG_RETVM_IF(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
676 #ifdef _USE_TVPD_MODE
677 MS_DBG_RETVM_IF(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
679 sql = sqlite3_mprintf("SELECT folder_id FROM folder WHERE (storage_uuid='%q' AND folder_path='%q')", storage_id, path);
681 sql = sqlite3_mprintf("SELECT folder_id FROM folder WHERE folder_path=%Q", path);
683 ret = media_db_get_result(handle, sql, &sql_stmt);
684 MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
686 if (sqlite3_step(sql_stmt) == SQLITE_ROW) {
687 *folder_id = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
688 MS_DBG("folder_id [%s]", *folder_id);
691 ret = MS_MEDIA_ERR_DB_NO_RECORD;
694 MS_SQLITE3_FINALIZE(sql_stmt);
699 void ms_register_start(bool noti_status, int pid)
701 int ret = MS_MEDIA_ERR_NONE;
703 ret = ((INSERT_ITEM_BEGIN)func_array[eINSERT_BEGIN])(noti_status, pid);
704 if (ret != MS_MEDIA_ERR_NONE)
705 MS_DBG_ERR("INSERT_ITEM_BEGIN failed [%d]", ret);
708 void ms_register_end(uid_t uid)
710 int ret = MS_MEDIA_ERR_NONE;
712 ret = ((INSERT_ITEM_END)func_array[eINSERT_END])(uid);
713 if (ret != MS_MEDIA_ERR_NONE)
714 MS_DBG_ERR("INSERT_ITEM_END failed [%d]", ret);
717 int ms_get_folder_scan_status(sqlite3 *handle, const char *storage_id, const char *path, int *scan_status)
719 int ret = MS_MEDIA_ERR_NONE;
722 ret = ((GET_FOLDER_SCAN_STATUS)func_array[eGET_FOLDER_SCAN_STATUS])(handle, storage_id, path, &status);
723 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_FOLDER_SCAN_STATUS failed [%d]", ret);
724 *scan_status = status;
726 MS_DBG_SLOG("OK path = [%s], scan_status = [%d]", path, *scan_status);
731 int ms_set_folder_scan_status(sqlite3 *handle, const char *storage_id, const char *path, int scan_status, uid_t uid)
733 int ret = MS_MEDIA_ERR_NONE;
734 int status = scan_status;
736 ret = ((SET_FOLDER_SCAN_STATUS)func_array[eSET_FOLDER_SCAN_STATUS])(handle, storage_id, path, status, uid);
737 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_FOLDER_SCAN_STATUS failed [%d]", ret);
739 MS_DBG_SLOG("OK path = [%s], scan_status = [%d]", path, scan_status);
744 int ms_check_folder_modified(sqlite3 *handle, const char *path, const char *storage_id, bool *modified)
746 int ret = MS_MEDIA_ERR_NONE;
747 MS_DBG("path = [%s], storage_id = [%s]", path, storage_id);
749 ret = ((CHECK_FOLDER_MODIFIED)func_array[eCHECK_FOLDER_MODIFIED])(handle, path, storage_id, modified);
750 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CHECK_FOLDER_MODIFIED failed [%d]", ret);
755 int ms_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, const char *path, GPtrArray **dir_array)
757 int ret = MS_MEDIA_ERR_NONE;
759 ret = ((GET_NULL_SCAN_FOLDER_LIST)func_array[eGET_NULL_SCAN_FOLDER_LIST])(handle, stroage_id, path, dir_array);
760 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_NULL_SCAN_FOLDER_LIST failed [%d]", ret);
765 int ms_change_validity_item_batch(sqlite3 *handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid)
767 int ret = MS_MEDIA_ERR_NONE;
769 ret = ((CHANGE_VALIDITY_ITEM_BATCH)func_array[eCHANGE_VALIDITY_ITEM_BATCH])(handle, storage_id, path, des_validity, src_validity, uid);
770 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CHANGE_VALIDITY_ITEM_BATCH failed [%d]", ret);
775 int ms_get_media_type(const char *path, int *media_type)
777 int ret = MS_MEDIA_ERR_NONE;
779 ret = ((GET_MEDIA_TYPE)func_array[eGET_MEDIA_TYPE])(path, media_type);
780 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_MEDIA_TYPE failed [%d]", ret);
785 bool ms_check_support_media_type(const char *path)
787 int ret = SYSTEM_INFO_ERROR_NONE;
789 bool is_supported = false;
791 MS_DBG_RETVM_IF(!MS_STRING_VALID(path), false, "path is empty");
793 if (scan_other_type == -1) {
794 ret = system_info_get_platform_bool("http://tizen.org/feature/content.scanning.others", &is_supported);
795 if (ret != SYSTEM_INFO_ERROR_NONE) {
796 MS_DBG_ERR("SYSTEM_INFO_ERROR: content.scanning.others [%d]", ret);
800 scan_other_type = is_supported;
803 if (!scan_other_type) {
804 ret = ms_get_media_type(path, &media_type);
805 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, false, "Failed to get media type");
807 if (media_type == MS_MEDIA_TYPE_OTHER)