Add to scan dcm after media scanning was done
[platform/core/multimedia/libmedia-service.git] / plugin / media-content-plugin.c
index 40480ae..cece7d4 100755 (executable)
@@ -23,6 +23,7 @@
 #include <sys/stat.h>
 #include <mm_file.h>
 #include <media-thumbnail.h>
+#include <media-util.h>
 #include "media-svc.h"
 #include "media-svc-util.h"
 
@@ -32,7 +33,7 @@
 #define STRING_VALID(str)      \
        ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
 #define STORAGE_VALID(storage)\
-       (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
+       (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL_USB)) ? TRUE : FALSE)
 
 
 typedef enum {
@@ -119,7 +120,7 @@ int disconnect_db(void *handle, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int check_item_exist(void *handle, const char *file_path, bool *modified, char **err_msg)
+int check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
        *modified = TRUE;
@@ -134,21 +135,18 @@ int check_item_exist(void *handle, const char *file_path, bool *modified, char *
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_check_item_exist_by_path(handle, file_path);
+       time_t modified_time = 0;
+       unsigned long long file_size = 0;
+       struct stat st;
+
+       ret = media_svc_get_file_info(handle, storage_id, file_path, &modified_time, &file_size);
        if (ret == MS_MEDIA_ERR_NONE) {
-               time_t modified_time = 0;
-               unsigned long long file_size = 0;
-               struct stat st;
-
-               ret = media_svc_get_file_info(handle, file_path, &modified_time, &file_size);
-               if (ret == MS_MEDIA_ERR_NONE) {
-                       memset(&st, 0, sizeof(struct stat));
-                       if (stat(file_path, &st) == 0) {
-                               if ((st.st_mtime != modified_time) || (st.st_size != file_size))
-                                       *modified = TRUE;
-                               else
-                                       *modified = FALSE;
-                       }
+               memset(&st, 0, sizeof(struct stat));
+               if (stat(file_path, &st) == 0) {
+                       if ((st.st_mtime != modified_time) || (st.st_size != file_size))
+                               *modified = TRUE;
+                       else
+                               *modified = FALSE;
                }
 
                return MEDIA_SVC_PLUGIN_ERROR_NONE;     /*exist */
@@ -163,12 +161,20 @@ int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, c
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
-       if (handle == NULL) {
-               __set_error_message(ERR_HANDLE, err_msg);
+       ret = media_svc_insert_item_begin(item_cnt, with_noti, from_pid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int insert_item_end(void *handle, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_insert_item_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -177,7 +183,7 @@ int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, c
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int insert_item_end(void *handle, uid_t uid, char **err_msg)
+int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -186,7 +192,17 @@ int insert_item_end(void *handle, uid_t uid, char **err_msg)
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_insert_item_end(handle, uid);
+       if (!STRING_VALID(file_path)) {
+               __set_error_message(ERR_FILE_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STORAGE_VALID(storage_type)) {
+               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -195,7 +211,7 @@ int insert_item_end(void *handle, uid_t uid, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int insert_item(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
+int insert_item_immediately(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -214,7 +230,7 @@ int insert_item(void *handle, const char *file_path, int storage_type, uid_t uid
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE, uid);
+       ret = media_svc_insert_item_immediately(handle, storage_id, storage_type, file_path, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -223,7 +239,7 @@ int insert_item(void *handle, const char *file_path, int storage_type, uid_t uid
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int insert_item_immediately(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
+int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -242,7 +258,74 @@ int insert_item_immediately(void *handle, const char *file_path, int storage_typ
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_insert_item_immediately(handle, storage_type, file_path, uid);
+       ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (!STORAGE_VALID(storage_type)) {
+               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_folder_item_validity(void *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STRING_VALID(folder_path)) {
+               __set_error_message(ERR_FOLDER_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_set_item_validity_begin(item_cnt);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_set_item_validity_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -251,7 +334,26 @@ int insert_item_immediately(void *handle, const char *file_path, int storage_typ
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int insert_burst_item(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
+int set_item_validity(void *handle, const char *storage_id, const char *file_path, int storage_type, int validity, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (!STRING_VALID(file_path)) {
+               __set_error_message(ERR_FILE_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
+
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -265,12 +367,31 @@ int insert_burst_item(void *handle, const char *file_path, int storage_type, uid
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
+       ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
+       if (ret == 0) {
+               ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
+
+               if (ret < 0) {
+                       __set_error_message(ret, err_msg);
+                       return MEDIA_SVC_PLUGIN_ERROR;
+               } else
+                       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+       }
+
+       __set_error_message(ERR_CHECK_ITEM, err_msg);   /*not exist in DB so can't delete item. */
+       return MEDIA_SVC_PLUGIN_ERROR;
+}
+
+int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
        if (!STORAGE_VALID(storage_type)) {
                __set_error_message(ERR_STORAGE_TYPE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE, uid);
+       ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -279,7 +400,7 @@ int insert_burst_item(void *handle, const char *file_path, int storage_type, uid
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int set_all_storage_items_validity(void *handle, int storage_type, int validity, uid_t uid, char **err_msg)
+int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -293,7 +414,7 @@ int set_all_storage_items_validity(void *handle, int storage_type, int validity,
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity, uid);
+       ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -302,7 +423,7 @@ int set_all_storage_items_validity(void *handle, int storage_type, int validity,
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int set_folder_item_validity(void *handle, const char *folder_path, int validity, int recursive, uid_t uid, char **err_msg)
+int delete_all_invalid_items_in_folder(void *handle, const char *storage_id, const char *folder_path, bool is_recursve, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -316,7 +437,7 @@ int set_folder_item_validity(void *handle, const char *folder_path, int validity
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive, uid);
+       ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -325,7 +446,50 @@ int set_folder_item_validity(void *handle, const char *folder_path, int validity
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
+
+int update_begin(void)
+{
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_end(const char *start_path, uid_t uid)
+{
+#if 0
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = thumbnail_request_extract_all_thumbs(uid);
+       if (ret < 0) {
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+#endif
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = dcm_svc_request_extract_all(uid);
+       if (ret < 0) {
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int send_dir_update_noti(void *handle, const char *storage_id, const char *dir_path, const char *folder_id, int update_type, int pid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (!STRING_VALID(dir_path)) {
+               __set_error_message(ERR_FOLDER_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -334,7 +498,17 @@ int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_set_item_validity_begin(handle, item_cnt);
+       if (count == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STRING_VALID(folder_path)) {
+               __set_error_message(ERR_FOLDER_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -343,7 +517,51 @@ int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
+int check_db(void *handle, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       int user_version = -1;
+
+       ret = media_svc_get_user_version(handle, &user_version);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (user_version == 0) {
+               /*check db schema*/
+               ret = media_svc_create_table(uid);
+               if (ret < 0) {
+                       __set_error_message(ret, err_msg);
+                       return MEDIA_SVC_PLUGIN_ERROR;
+               }
+       } else {
+               /*check db version*/
+               ret = media_svc_check_db_upgrade(handle, user_version, uid);
+               if (ret < 0) {
+                       __set_error_message(ret, err_msg);
+                       return MEDIA_SVC_PLUGIN_ERROR;
+               }
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int check_db_corrupt(void *handle, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       /*check db version*/
+       ret = media_svc_check_db_corrupt(handle);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int get_folder_list(void *handle, const char *storage_id, char *start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -352,7 +570,12 @@ int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_set_item_validity_end(handle, uid);
+       if (count == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -361,7 +584,7 @@ int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int set_item_validity(void *handle, const char *file_path, int storage_type, int validity, uid_t uid, char **err_msg)
+int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -370,18 +593,25 @@ int set_item_validity(void *handle, const char *file_path, int storage_type, int
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STRING_VALID(file_path)) {
-               __set_error_message(ERR_FILE_PATH, err_msg);
+       if (folder_path == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STORAGE_VALID(storage_type)) {
-               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+       ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_set_item_validity(handle, file_path, validity, uid);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int get_uuid(void * handle, char **uuid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
+       ret = media_svc_generate_uuid(uuid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -390,7 +620,7 @@ int set_item_validity(void *handle, const char *file_path, int storage_type, int
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int delete_item(void *handle, const char *file_path, uid_t uid, char **err_msg)
+int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -399,27 +629,34 @@ int delete_item(void *handle, const char *file_path, uid_t uid, char **err_msg)
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STRING_VALID(file_path)) {
-               __set_error_message(ERR_FILE_PATH, err_msg);
+       ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
+       if (ret < 0) {
+               __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_check_item_exist_by_path(handle, file_path);
-       if (ret == 0) {
-               ret = media_svc_delete_item_by_path(handle, "media", file_path, uid);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
 
-               if (ret < 0) {
-                       __set_error_message(ret, err_msg);
-                       return MEDIA_SVC_PLUGIN_ERROR;
-               } else
-                       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       __set_error_message(ERR_CHECK_ITEM, err_msg);   /*not exist in DB so can't delete item. */
-       return MEDIA_SVC_PLUGIN_ERROR;
+       ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int delete_all_items_in_storage(void *handle, int storage_type, uid_t uid, char **err_msg)
+int insert_storage(void *handle, const char *storage_id, int storage_type, const char *storage_name, const char *storage_path, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -428,12 +665,25 @@ int delete_all_items_in_storage(void *handle, int storage_type, uid_t uid, char
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STORAGE_VALID(storage_type)) {
-               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+       ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_delete_all_items_in_storage(handle, storage_type, uid);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -442,7 +692,7 @@ int delete_all_items_in_storage(void *handle, int storage_type, uid_t uid, char
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int delete_all_invalid_items_in_storage(void *handle, int storage_type, uid_t uid, char **err_msg)
+int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -451,12 +701,25 @@ int delete_all_invalid_items_in_storage(void *handle, int storage_type, uid_t ui
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STORAGE_VALID(storage_type)) {
-               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+       ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_delete_invalid_items_in_storage(handle, storage_type, uid);
+       ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -465,7 +728,7 @@ int delete_all_invalid_items_in_storage(void *handle, int storage_type, uid_t ui
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int delete_all_invalid_items_in_folder(void *handle, const char *folder_path, uid_t uid, char **err_msg)
+int set_all_storage_validity(void * handle, int validity, char **err_msg, uid_t uid)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -474,12 +737,25 @@ int delete_all_invalid_items_in_folder(void *handle, const char *folder_path, ui
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STRING_VALID(folder_path)) {
-               __set_error_message(ERR_FOLDER_PATH, err_msg);
+       ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_delete_invalid_items_in_folder(handle, folder_path, uid);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int get_storage_id(void * handle, const char *path, char *storage_id, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_get_storage_id(handle, path, storage_id);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -488,34 +764,82 @@ int delete_all_invalid_items_in_folder(void *handle, const char *folder_path, ui
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
+int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       media_svc_scan_status_type_e storage_status = 0;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
 
-int update_begin(void)
+       ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       *status = storage_status;
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
 {
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       media_svc_scan_status_type_e storage_status = status;
+
+       ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int update_end(uid_t uid)
+int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
-       ret = thumbnail_request_extract_all_thumbs(uid);
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (count == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
        if (ret < 0) {
+               __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int send_dir_update_noti(void *handle, const char *dir_path, char **err_msg)
+int update_item_begin(void *handle, int item_cnt, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
-       if (!STRING_VALID(dir_path)) {
-               __set_error_message(ERR_FOLDER_PATH, err_msg);
+       ret = media_svc_update_item_begin(item_cnt);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_send_dir_update_noti(handle, dir_path);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_item_end(void *handle, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_update_item_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -524,7 +848,7 @@ int send_dir_update_noti(void *handle, const char *dir_path, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int count_delete_items_in_folder(void *handle, const char *folder_path, int *count, char **err_msg)
+int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -533,17 +857,17 @@ int count_delete_items_in_folder(void *handle, const char *folder_path, int *cou
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (count == NULL) {
+       if (file_path == NULL) {
                __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (!STRING_VALID(folder_path)) {
-               __set_error_message(ERR_FOLDER_PATH, err_msg);
+       if (storage_id == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
+       ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -552,19 +876,49 @@ int count_delete_items_in_folder(void *handle, const char *folder_path, int *cou
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int check_db(void *handle, uid_t uid, char **err_msg)
+int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
-       /*check db schema*/
-       ret = media_svc_create_table(handle, uid);
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STRING_VALID(file_path)) {
+               __set_error_message(ERR_FILE_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STORAGE_VALID(storage_type)) {
+               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       /*check db version*/
-       ret = media_svc_check_db_upgrade(handle, uid);
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_item_extract(void * handle, const char *storage_id, int storage_type, int scan_type, uid_t uid, const char *path, int burst, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STORAGE_VALID(storage_type)) {
+               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, burst, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -573,12 +927,24 @@ int check_db(void *handle, uid_t uid, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int check_db_corrupt(void *handle, char **err_msg)
+int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
-       /*check db version*/
-       ret = media_svc_check_db_corrupt(handle);
+       ret = media_svc_insert_folder_begin(item_cnt);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int insert_folder_end(void *handle, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_insert_folder_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -587,7 +953,7 @@ int check_db_corrupt(void *handle, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int get_folder_list(void *handle, char *start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char **err_msg)
+int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -596,12 +962,48 @@ int get_folder_list(void *handle, char *start_path, char ***folder_list, int **m
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (count == NULL) {
+       if (!STRING_VALID(file_path)) {
+               __set_error_message(ERR_FILE_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (!STORAGE_VALID(storage_type)) {
+               __set_error_message(ERR_STORAGE_TYPE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_delete_invalid_folder(storage_id, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_folder_validity(void * handle, const char *storage_id, const char* start_path, int validity, bool is_recursive, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
                __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
+       ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -610,30 +1012,102 @@ int get_folder_list(void *handle, char *start_path, char ***folder_list, int **m
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int update_folder_time(void *handle, char *folder_path, uid_t uid, char **err_msg)
+int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       int storage_status = 0;
 
        if (handle == NULL) {
                __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (folder_path == NULL) {
+       ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       *status = storage_status;
+
+       return ret;
+}
+
+int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       int storage_status = status;
+
+       ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return ret;
+}
+
+int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       *modified = TRUE;
+
+       if (handle == NULL) {
                __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_update_folder_time(handle, folder_path, uid);
+       if (!STRING_VALID(path)) {
+               __set_error_message(ERR_FILE_PATH, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+       return ret;
 }
 
-int update_item_begin(void *handle, int item_cnt, char **err_msg)
+int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       if (count == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return ret;
+}
+
+int change_validity_item_batch(void **handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       return ret;
+}
+
+int delete_invalid_folder_by_path(void * handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -642,7 +1116,7 @@ int update_item_begin(void *handle, int item_cnt, char **err_msg)
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_update_item_begin(handle, item_cnt);
+       ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -651,7 +1125,7 @@ int update_item_begin(void *handle, int item_cnt, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int update_item_end(void *handle, uid_t uid, char **err_msg)
+int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
 
@@ -660,7 +1134,7 @@ int update_item_end(void *handle, uid_t uid, char **err_msg)
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_update_item_end(handle, uid);
+       ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -669,21 +1143,37 @@ int update_item_end(void *handle, uid_t uid, char **err_msg)
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int update_item_meta(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
+int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
 {
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+       int cnt = 0;
 
        if (handle == NULL) {
                __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       if (file_path == NULL) {
+       ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
+       if (ret < 0) {
+               __set_error_message(ret, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       *count = cnt;
+
+       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
+{
+       int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+       if (handle == NULL) {
                __set_error_message(ERR_HANDLE, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
+       ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -691,3 +1181,5 @@ int update_item_meta(void *handle, const char *file_path, int storage_type, uid_
 
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
+
+