Add to scan dcm after media scanning was done
[platform/core/multimedia/libmedia-service.git] / plugin / media-content-plugin.c
index cfbf296..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"
 
@@ -160,12 +161,7 @@ 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);
-               return MEDIA_SVC_PLUGIN_ERROR;
-       }
-
-       ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
+       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;
@@ -178,12 +174,7 @@ int insert_item_end(void *handle, 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_insert_item_end(handle, uid);
+       ret = media_svc_insert_item_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -280,17 +271,12 @@ int set_all_storage_items_validity(void *handle, const char *storage_id, int sto
 {
        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_set_all_storage_items_validity(handle, storage_id, storage_type, validity, uid);
+       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;
@@ -326,12 +312,7 @@ int set_item_validity_begin(void *handle, int item_cnt, 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_set_item_validity_begin(handle, item_cnt);
+       ret = media_svc_set_item_validity_begin(item_cnt);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -344,12 +325,7 @@ int set_item_validity_end(void *handle, 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_set_item_validity_end(handle, uid);
+       ret = media_svc_set_item_validity_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -362,17 +338,12 @@ int set_item_validity(void *handle, const char *storage_id, const char *file_pat
 {
        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(file_path)) {
                __set_error_message(ERR_FILE_PATH, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_set_item_validity(handle, storage_id, file_path, validity, uid);
+       ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
 
        if (ret < 0) {
                __set_error_message(ret, err_msg);
@@ -415,17 +386,12 @@ int delete_all_items_in_storage(void *handle, const char *storage_id, int storag
 {
        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_delete_all_items_in_storage(handle, storage_id, storage_type, 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;
@@ -488,13 +454,20 @@ int update_begin(void)
 
 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;
 }
 
@@ -544,22 +517,31 @@ int count_delete_items_in_folder(void *handle, const char *storage_id, const cha
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int check_db(void *handle, bool *need_full_scan, 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;
 
-       /*check db schema*/
-       ret = media_svc_create_table(handle, uid);
+       ret = media_svc_get_user_version(handle, &user_version);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       /*check db version*/
-       ret = media_svc_check_db_upgrade(handle, need_full_scan, uid);
-       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;
@@ -629,11 +611,6 @@ int get_uuid(void * handle, char **uuid, 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_generate_uuid(uuid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
@@ -813,12 +790,7 @@ int set_storage_scan_status(void *handle, const char *storage_id, int status, ui
        int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
        media_svc_scan_status_type_e storage_status = status;
 
-       if (handle == NULL) {
-               __set_error_message(ERR_HANDLE, err_msg);
-               return MEDIA_SVC_PLUGIN_ERROR;
-       }
-
-       ret = media_svc_set_storage_scan_status(handle, storage_id, storage_status, uid);
+       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;
@@ -854,12 +826,7 @@ int update_item_begin(void *handle, int item_cnt, 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_begin(handle, item_cnt);
+       ret = media_svc_update_item_begin(item_cnt);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -872,12 +839,7 @@ int update_item_end(void *handle, 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_item_end(handle, uid);
+       ret = media_svc_update_item_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -886,7 +848,7 @@ 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 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;
 
@@ -900,7 +862,12 @@ int update_item_meta(void *handle, const char *file_path, int storage_type, uid_
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
+       if (storage_id == NULL) {
+               __set_error_message(ERR_HANDLE, err_msg);
+               return MEDIA_SVC_PLUGIN_ERROR;
+       }
+
+       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;
@@ -937,7 +904,7 @@ int insert_item_scan(void * handle, const char *storage_id, const char *file_pat
        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, char **err_msg)
+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;
 
@@ -951,7 +918,7 @@ int update_item_extract(void * handle, const char *storage_id, int storage_type,
                return MEDIA_SVC_PLUGIN_ERROR;
        }
 
-       ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, FALSE, uid);
+       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;
@@ -964,12 +931,7 @@ int insert_folder_begin(void * handle, int item_cnt, 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_insert_folder_begin(handle, item_cnt);
+       ret = media_svc_insert_folder_begin(item_cnt);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -982,12 +944,7 @@ int insert_folder_end(void *handle, 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_insert_folder_end(handle, uid);
+       ret = media_svc_insert_folder_end(uid);
        if (ret < 0) {
                __set_error_message(ret, err_msg);
                return MEDIA_SVC_PLUGIN_ERROR;
@@ -1028,12 +985,25 @@ int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char
 {
        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_delete_invalid_folder(handle, storage_id, uid);
+       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;
@@ -1042,22 +1012,99 @@ int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char
        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 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;
        }
 
-       ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
+       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;
        }
 
-       return MEDIA_SVC_PLUGIN_ERROR_NONE;
+       *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;
+       }
+
+       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 ret;
+}
+
+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)
@@ -1096,7 +1143,7 @@ int check_folder_exist(void * handle, const char *storage_id, const char *folder
        return MEDIA_SVC_PLUGIN_ERROR_NONE;
 }
 
-int count_subfolder(void * handle, const char *storage_id, const char *folder_path, int *count, 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;
@@ -1136,4 +1183,3 @@ int get_folder_id(void * handle, const char *storage_id, const char *path, char
 }
 
 
-