Move set_all_storage_items_validity 13/198013/2
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 17 Jan 2019 23:24:07 +0000 (08:24 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 18 Jan 2019 00:23:56 +0000 (09:23 +0900)
Move API from plugin to media-common

Change-Id: Ia8d9ddef013367dd23a2697260efc18f6aadc809
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/common/include/media-common-db-svc.h
src/common/media-common-db-svc.c

index 2a2ce68..07eb01f 100755 (executable)
@@ -60,7 +60,6 @@ typedef int (*SET_ITEM_VALIDITY_END)(uid_t);
 
 typedef int (*SEND_DIR_UPDATE_NOTI)(sqlite3 *, const char *, const char *, const char *, int, int);
 typedef int (*INSERT_ITEM)(sqlite3 *, const char *, const char *, int, uid_t);
-typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(sqlite3 *, const char *, int, int, uid_t);
 typedef int (*SET_FOLDER_ITEM_VALIDITY)(sqlite3 *, const char *, const char *, int, int, uid_t);
 typedef int (*SET_ITEM_VALIDITY)(const char *, const char *, int, int, uid_t);
 typedef int (*DELETE_ITEM)(sqlite3 *, const char *, const char *, uid_t);
index 86f33ca..1aff3d7 100755 (executable)
@@ -47,7 +47,6 @@ enum func_list {
        eINSERT_END,
        eINSERT_BATCH,
        eINSERT_SCAN,
-       eSET_ALL_VALIDITY,
        eSET_VALIDITY_BEGIN,
        eSET_VALIDITY_END,
        eSET_VALIDITY,
@@ -151,7 +150,6 @@ int ms_load_functions(void)
                "insert_item_end",
                "insert_item",
                "insert_item_scan",
-               "set_all_storage_items_validity",
                "set_item_validity_begin",
                "set_item_validity_end",
                "set_item_validity",
@@ -441,15 +439,29 @@ int ms_scan_validate_item(sqlite3 *handle, const char *storage_id, const char *p
        return ret;
 }
 
+bool __ms_check_storage_type(ms_user_storage_type_e storage_type)
+{
+       if ((storage_type != MS_USER_STORAGE_INTERNAL)
+               && (storage_type != MS_USER_STORAGE_EXTERNAL)
+               && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
+               MS_DBG_ERR("storage type is incorrect[%d]", storage_type);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 int ms_validity_change_all_items(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, bool validity , uid_t uid)
 {
-       int lib_index;
        int ret = MS_MEDIA_ERR_NONE;
 
-       for (lib_index = 0; lib_index < lib_num; lib_index++) {
-               ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle, storage_id, storage_type, validity, uid); /*dlopen*/
-               MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Error : %s", g_array_index(so_array, char*, lib_index));
-       }
+       MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+       MS_DBG_RETVM_IF(__ms_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
+
+       char *sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_type=%d;", storage_id, validity, storage_type);
+
+       ret = media_db_request_update_db(sql, uid);
+       MS_SQLITE3_SAFE_FREE(sql);
 
        return ret;
 }
@@ -1151,4 +1163,3 @@ void ms_bacth_commit_disable(bool ins_status, bool valid_status, uid_t uid)
 
        return;
 }
-