improve way to notify updated DB
authorYong Yeon Kim <yy9875.kim@samsung.com>
Fri, 5 Apr 2013 02:36:52 +0000 (11:36 +0900)
committerYong Yeon Kim <yy9875.kim@samsung.com>
Fri, 5 Apr 2013 04:23:30 +0000 (13:23 +0900)
If there is no changing, notification does not send

Change-Id: I33b8bd99ee81a5d69781a8b46c390e9a64464362

packaging/media-server.spec
src/common/media-common-utils.c
src/scanner/include/media-scanner-db-svc.h
src/scanner/media-scanner-db-svc.c
src/scanner/media-scanner-scan.c

index ecc4684..94fbeb2 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    File manager service server.
-Version: 0.2.41
+Version: 0.2.42
 Release:    1
 Group:      utils
 License:    Apache License, Version 2.0
index 3e9b589..274dd00 100755 (executable)
@@ -29,7 +29,6 @@
  */
 
 #include <errno.h>
-#include <pmapi.h>
 #include <vconf.h>
 #include <aul/aul.h>
 
index 5854035..1e0df36 100755 (executable)
@@ -51,6 +51,7 @@ typedef int (*SET_FOLDER_ITEM_VALIDITY)(void*, const char*, int, int, char**);
 typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void*, const char*, char**);
 typedef int (*INSERT_BURST_ITEM)(void *, const char *, int , char **);
 typedef int (*SEND_DIR_UPDATE_NOTI)(void *, const char *, char **);
+typedef int (*COUNT_DELETE_ITEMS_IN_FOLDER)(void *, const char *, int *, char **);
 
 int
 msc_load_functions(void);
@@ -91,6 +92,9 @@ msc_delete_invalid_items_in_folder(void **handle, const char*path);
 int
 msc_send_dir_update_noti(void **handle, const char*path);
 
+int
+msc_count_delete_items_in_folder(void **handle, const char*path, int *count);
+
 /****************************************************************************************************
 FOR BULK COMMIT
 *****************************************************************************************************/
index 9295840..5669798 100755 (executable)
@@ -48,6 +48,7 @@ GArray *so_array;
 void ***func_array;
 int lib_num;
 void **scan_func_handle = NULL; /*dlopen handel*/
+extern int insert_count;
 
 enum func_list {
        eCHECK,
@@ -69,6 +70,7 @@ enum func_list {
        eDELETE_FOLDER,
        eINSERT_BURST,
        eSEND_DIR_UPDATE_NOTI,
+       eCOUNT_DELETE_ITEMS_IN_FOLDER,
        eFUNC_MAX
 };
 
@@ -161,6 +163,7 @@ msc_load_functions(void)
                "delete_all_invalid_items_in_folder",
                "insert_burst_item",
                "send_dir_update_noti",
+               "count_delete_items_in_folder",
                };
        /*init array for adding name of so*/
        so_array = g_array_new(FALSE, FALSE, sizeof(char*));
@@ -340,6 +343,8 @@ msc_validate_item(void **handle, const char *path)
                                        MSC_DBG_ERR("[%s]", path);
                                        MS_SAFE_FREE(err_msg);
                                        res = MS_MEDIA_ERR_DB_INSERT_FAIL;
+                               } else {
+                                       insert_count++;
                                }
                        } else {
                                /*if meta data of file exist, change valid field to "1" */
@@ -548,6 +553,26 @@ msc_send_dir_update_noti(void **handle, const char*path)
        return MS_MEDIA_ERR_NONE;
 }
 
+int
+msc_count_delete_items_in_folder(void **handle, const char*path, int *count)
+{
+       int lib_index;
+       int ret;
+       char *err_msg = NULL;
+
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((COUNT_DELETE_ITEMS_IN_FOLDER)func_array[lib_index][eCOUNT_DELETE_ITEMS_IN_FOLDER])(handle[lib_index], path, count, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+                       MS_SAFE_FREE(err_msg);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+       }
+
+       return MS_MEDIA_ERR_NONE;
+
+}
+
 /****************************************************************************************************
 FOR BULK COMMIT
 *****************************************************************************************************/
index 4636bba..cf9f6f2 100755 (executable)
@@ -54,6 +54,7 @@ bool power_off;
 GAsyncQueue * storage_queue;
 GAsyncQueue *scan_queue;
 GAsyncQueue *reg_queue;
+int insert_count;
 
 #ifdef FMS_PERF
 extern struct timeval g_mmc_start_time;
@@ -286,7 +287,6 @@ static int _msc_db_update(void **handle, const ms_comm_msg_s * scan_data)
        int scan_type;
        int err = MS_MEDIA_ERR_NONE;
        char *start_path = NULL;
-       char *noti_path = NULL;
        ms_storage_type_t storage_type;
 
        storage_type = ms_get_storage_type_by_full(scan_data->msg);
@@ -301,10 +301,6 @@ static int _msc_db_update(void **handle, const ms_comm_msg_s * scan_data)
                err = _msc_dir_scan(handle, start_path, storage_type, scan_type);
                if (err != MS_MEDIA_ERR_NONE) {
                        MSC_DBG_ERR("error : %d", err);
-               } else {
-                       noti_path = strndup(scan_data->msg, scan_data->msg_size);
-                       msc_send_dir_update_noti(handle, noti_path);
-                       MS_SAFE_FREE(noti_path);
                }
        } else if ( scan_type == MS_MSG_STORAGE_INVALID) {
                MSC_DBG_INFO("INVALID");
@@ -313,12 +309,6 @@ static int _msc_db_update(void **handle, const ms_comm_msg_s * scan_data)
                err = msc_invalidate_all_items(handle, storage_type);
                if (err != MS_MEDIA_ERR_NONE) {
                        MSC_DBG_ERR("error : %d", err);
-               } else {
-                       if (storage_type == MS_STORAGE_INTERNAL) {
-                               msc_send_dir_update_noti(handle, MEDIA_ROOT_PATH_INTERNAL);
-                       } else {
-                               msc_send_dir_update_noti(handle, MEDIA_ROOT_PATH_SDCARD);
-                       }
                }
        }
 
@@ -337,6 +327,7 @@ gboolean msc_directory_scan_thread(void *data)
        void **handle = NULL;
        ms_storage_type_t storage_type;
        int scan_type;
+       char *noti_path = NULL;
 
        while (1) {
                scan_data = g_async_queue_pop(scan_queue);
@@ -385,9 +376,24 @@ gboolean msc_directory_scan_thread(void *data)
 
                if (ret == MS_MEDIA_ERR_NONE) {
                        MSC_DBG_INFO("working normally");
+                       int count = 0;
+
+                       noti_path = strndup(scan_data->msg, scan_data->msg_size);
+                       msc_count_delete_items_in_folder(handle, noti_path, &count);
+
+                       MSC_DBG_INFO("delete count %d", count);
+                       MSC_DBG_INFO("insert count %d", insert_count);
+
                        msc_delete_invalid_items_in_folder(handle, scan_data->msg);
+
+                       if ( !(count == 0 && insert_count == 0)) {
+                               msc_send_dir_update_noti(handle, noti_path);
+                       }
+                       MS_SAFE_FREE(noti_path);
                }
 
+               insert_count = 0;
+
                if (power_off) {
                        MSC_DBG_INFO("power off");
                        goto _POWEROFF;
@@ -423,6 +429,7 @@ gboolean msc_storage_scan_thread(void *data)
        void **handle = NULL;
        ms_storage_type_t storage_type;
        int scan_type;
+       char *noti_path = NULL;
 
        while (1) {
                scan_data = g_async_queue_pop(storage_queue);
@@ -495,6 +502,11 @@ gboolean msc_storage_scan_thread(void *data)
                        }
                }
 
+               /* send notification */
+               noti_path = strndup(scan_data->msg, scan_data->msg_size);
+               msc_send_dir_update_noti(handle, noti_path);
+               MS_SAFE_FREE(noti_path);
+
 #ifdef FMS_PERF
                if (storage_type == MS_STORAGE_EXTERNAL) {
                        ms_check_end_time(&g_mmc_end_time);