add feature send partial list to client 60/168960/3 accepted/tizen/unified/20180206.064141 submit/tizen/20180205.005408
authorchen89.chen <chen89.chen@samsung.com>
Thu, 1 Feb 2018 11:49:38 +0000 (19:49 +0800)
committerchen89.chen <chen89.chen@samsung.com>
Thu, 1 Feb 2018 12:17:49 +0000 (20:17 +0800)
Change-Id: Icbad0bd8de06b8c0baa8a0b54bf31e5420e41ff3

src/common/media-common-db-svc.c
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner-v2/media-scanner-socket-v2.c
src/server/media-server-socket.c

index 4e07296..7d190f3 100755 (executable)
@@ -38,8 +38,6 @@ static GArray *so_array;
 static void ***func_array;
 static int lib_num;
 static void **func_handle = NULL; /*dlopen handel*/
-int insert_count_for_partial = 0;
-int set_count_for_partial = 0;
 static int scan_other_type = -1;
 
 enum func_list {
@@ -452,8 +450,6 @@ int ms_scan_validate_item(void **handle, const char *storage_id, const char *pat
                        ret = ms_scan_item_batch(handle, storage_id, path, uid);
                        if (ret != 0)
                                res = MS_MEDIA_ERR_DB_INSERT_FAIL;
-                       else
-                               insert_count_for_partial++;
                } else {
                        if (modified == FALSE) {
                                /*if meta data of file exist, change valid field to "1" */
@@ -462,8 +458,6 @@ int ms_scan_validate_item(void **handle, const char *storage_id, const char *pat
                                        MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
                                        MS_SAFE_FREE(err_msg);
                                        res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
-                               } else {
-                                       set_count_for_partial++;
                                }
                        } else {
                                /* the file has same name but it is changed, so we have to update DB */
@@ -476,8 +470,6 @@ int ms_scan_validate_item(void **handle, const char *storage_id, const char *pat
                                        ret = ms_scan_item_batch(handle, storage_id, path, uid);
                                        if (ret != 0)
                                                res = MS_MEDIA_ERR_DB_INSERT_FAIL;
-                                       else
-                                               insert_count_for_partial++;
                                }
                        }
                }
index c02982c..ba30d2b 100755 (executable)
@@ -281,6 +281,7 @@ NEXT:
                malloc_trim(0);
 
                if (extract_data->result) {
+                       MS_DBG_ERR("MS_MSG_SCANNER_COMPLETE");
                        if (noti_type == MS_ITEM_INSERT || noti_type == MS_ITEM_UPDATE) {
                                /*send notification*/
                                char *folder_uuid = NULL;
@@ -290,6 +291,9 @@ NEXT:
                        }
                        extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
                        msc_send_result(ret, extract_data);
+               } else {
+                       MS_DBG_ERR("MS_MSG_SCANNER_PARTIAL");
+                       msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, extract_data->pid, extract_data->msg);
                }
 
                MS_SAFE_FREE(update_path);
index 43e4072..8fbd22d 100755 (executable)
@@ -70,8 +70,6 @@ char *g_blocked_path2;
 s_scan_item* cancel_scan_item = NULL;
 s_scan_item* cur_scan_item = NULL;
 
-extern int insert_count_for_partial;
-extern int set_count_for_partial;
 int g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
 char *g_storage_scan_path;
 char* g_dir_scan_path;
@@ -271,8 +269,6 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
 
        const char *trash = "$RECYCLE.BIN";
 
-       insert_count_for_partial = 0;
-       set_count_for_partial = 0;
 
        MS_DBG_WARN("storage id [%s] start path [%s]", storage_id, start_path);
 
@@ -485,7 +481,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                        /* insert into media DB */
                                        ret = ms_scan_validate_item(handle, storage_id, path, uid);
                                        if (ret != MS_MEDIA_ERR_NONE) {
-                                               MS_DBG_ERR("failed to update db : %d", scan_type);
+                                               MS_DBG_ERR("failed to update db : %d", ret);
                                                if (ret == MS_MEDIA_ERR_FILE_IO)
                                                        MS_DBG_ERR("I/O ERROR COUNT[%d]", io_err_folder++);
 
@@ -505,20 +501,10 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                                                        ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
                                                                goto STOP_SCAN;
                                                        }
-                                               }
 
-                                               if (insert_count_for_partial >= MAX_SCAN_COUNT) {
-                                                       if (pid != 0)
-                                                               msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, pid, (char*)start_path);
 
-                                                       insert_count_for_partial = 0;
-                                               }
 
-                                               if (set_count_for_partial >= MAX_SCAN_COUNT) {
-                                                       if (pid != 0)
-                                                               msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, pid, (char*)start_path);
 
-                                                       set_count_for_partial = 0;
                                                }
                                        }
                                } else if (d->d_type == DT_DIR) {
@@ -1086,7 +1072,6 @@ gboolean msc_directory_scan_thread(void *data)
        int scan_type;
        char *storage_id = NULL;
        bool modified = FALSE;
-       int index = 0;
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
        ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
        ms_noti_type_e noti_type = MS_ITEM_INSERT;
@@ -1192,15 +1177,12 @@ gboolean msc_directory_scan_thread(void *data)
                                        if (ret != MS_MEDIA_ERR_NONE)
                                                goto NEXT;
 
-                                       if ((++index) % 3 == 0)
-                                               msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, scan_data->pid, scan_data->msg);
 
                                        err = __msc_check_scan_same_path(scan_data->msg);
                                        if (err != MS_MEDIA_ERR_NONE)
                                                break;
                                }
 
-                               index = 0;
                                MS_DBG_WARN("[%s] scan done, wait finished", scan_data->msg);
                                goto SCAN_DONE;
 
@@ -1239,8 +1221,6 @@ gboolean msc_directory_scan_thread(void *data)
                                                if (ret != MS_MEDIA_ERR_NONE)
                                                        goto NEXT;
 
-                                               if ((++index) % 3 == 0)
-                                                       msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, scan_data->pid, scan_data->msg);
 
                                                ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
                                                if ((scan_status == MS_DIR_SCAN_DONE) || (scan_status == MS_DIR_SCAN_STOP)) {
@@ -1249,7 +1229,6 @@ gboolean msc_directory_scan_thread(void *data)
                                                }
                                        }
 
-                                       index = 0;
                                        if (scan_status == MS_DIR_SCAN_DONE) {
                                                MS_DBG_WARN("[%s] scan done, wait finished", scan_data->msg);
                                                goto SCAN_DONE;
index 641882e..e53e111 100755 (executable)
@@ -33,6 +33,7 @@
 #include "media-scanner-scan-v2.h"
 #include "media-scanner-socket-v2.h"
 #include "media-scanner-extract-v2.h"
+#define SUPPORT_PARTIAL_EVENT
 
 extern GAsyncQueue *storage_queue2;
 extern GAsyncQueue *scan_queue2;
@@ -40,7 +41,7 @@ extern GAsyncQueue *reg_queue2;
 extern GMutex scan_req_mutex2;
 extern GAsyncQueue *folder_extract_queue;
 extern int g_directory_scan_processing2;
-//#define SUPPORT_PARTIAL_EVENT
+
 static int _msc_remove_request(GAsyncQueue *req_queue, ms_comm_msg_s *recv_msg)
 {
        char *cancel_path = recv_msg->msg;
@@ -279,11 +280,11 @@ int msc_send_result(int result, ms_comm_msg_s *res_data)
        return res;
 }
 
-/* define of  SUPPORT_PARTIAL_EVENT is disabled, send partial result will not be active */ 
+/* define of  SUPPORT_PARTIAL_EVENT is disabled, send partial result will not be active */
 int msc_send_result_partial(int result, ms_msg_type_e msg_type, int pid, const char *msg)
 {
 #ifdef SUPPORT_PARTIAL_EVENT
-       MS_DBG_SLOG("msc_send_result msg_type=%d", msg_type);
+       MS_DBG_SLOG("msc_send_result_partial %d,%d,%s", msg_type, pid, msg);
        int res = MS_MEDIA_ERR_NONE;
        ms_comm_msg_s send_msg;
        int fd = -1;
index 9642b35..a43bea6 100755 (executable)
@@ -194,16 +194,26 @@ static int __ms_send_result_to_client(int pid, ms_comm_msg_s *recv_msg)
                        MS_DBG_ERR("res_path is NULL");
                        return MS_MEDIA_ERR_OUT_OF_MEMORY;
                }
-
+               if (recv_msg->msg_type == MS_MSG_SCANNER_PARTIAL) {
+                       ms_req_owner_data *data = NULL;
+                       int len = owner_list->len;
+                       MS_DBG_ERR("length list : %d", len);
+                       for (int i = 0; i < len; i++) {
+                               data = g_array_index(owner_list, ms_req_owner_data*, i);
+                               MS_DBG_ERR("PARTIAL message:pid %d,path %s", data->pid, data->req_path);
+                               ms_ipc_send_msg_to_client_tcp(data->client_sockfd, recv_msg, NULL);
+                       }
+                       MS_SAFE_FREE(res_path);
+               } else {
                __ms_find_owner(pid, res_path, &owner_data);
                if (owner_data != NULL) {
-                       MS_DBG("PID : %d", owner_data->pid);
                        /* owner data exists */
                        /* send result to the owner of request */
                        ms_ipc_send_msg_to_client_tcp(owner_data->client_sockfd, recv_msg, NULL);
-                       MS_DBG("add handle MS_MSG_SCANNER_PARTIAL message");
-                       if ((recv_msg->msg_type != MS_MSG_SCANNER_COMPLETE) && (recv_msg->msg_type != MS_MSG_SCANNER_PARTIAL))
+                       MS_DBG_ERR("OTHER message: pid %d, path %s", owner_data->pid, owner_data->req_path);
+                       if ((recv_msg->msg_type != MS_MSG_SCANNER_COMPLETE) && (recv_msg->msg_type != MS_MSG_SCANNER_PARTIAL)) {
                                close(owner_data->client_sockfd);
+                       }
 
                        MS_SAFE_FREE(res_path);
 
@@ -213,6 +223,7 @@ static int __ms_send_result_to_client(int pid, ms_comm_msg_s *recv_msg)
                        MS_DBG_ERR("Not found Owner");
                        MS_SAFE_FREE(res_path);
                        return MS_MEDIA_ERR_INTERNAL;
+                       }
                }
        } else {
                /* owner data does not exist*/