Sync register_thread code between scanner and scanner-v2 29/239329/12
authorhj kim <backto.kim@samsung.com>
Fri, 24 Jul 2020 03:35:22 +0000 (12:35 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 28 Jul 2020 05:57:14 +0000 (14:57 +0900)
both scanners do same thing in register_thread.
scanner-v2 codes were old one. so updated it.

Change-Id: Ia8dec97011cfbf59d9ce6506e7eae5fd44516f75

src/scanner-v2/media-scanner-scan-v2.c

index c7d4665..166dc1f 100644 (file)
@@ -84,9 +84,7 @@ struct linux_dirent {
 #define BUF_SIZE 1024
 
 static int __msc_check_stop_status(int scan_type, const char *start_path, int pid);
-static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data);
 static void __msc_clear_file_list(GArray *path_array);
-static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
 static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GArray *dir_array);
 static int __msc_dir_scan_cb(void);
 static int __msc_check_scan_same_path(char *scan_path);
@@ -1366,17 +1364,6 @@ _POWEROFF:
        return NULL;
 }
 
-static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data)
-{
-       MS_DBG_SLOG("path : %.*s", MAX_MSG_SIZE, insert_data->msg);
-
-       if (insert_data->pid == POWEROFF)
-               g_array_prepend_val(register_array, insert_data);
-       else
-               g_array_append_val(register_array, insert_data);
-
-}
-
 static void __msc_clear_file_list(GArray *path_array)
 {
        if (path_array) {
@@ -1469,128 +1456,44 @@ static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
        return ret;
 }
 
-static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data)
-{
-       int remain_request;
-       ms_comm_msg_s *insert_data = NULL;
-
-       while (1) {
-               remain_request = g_async_queue_length(reg_queue2);
-
-               /*updating requests remain*/
-               if (register_array->len != 0 && remain_request == 0) {
-                       *register_data = g_array_index(register_array, ms_comm_msg_s*, 0);
-                       g_array_remove_index(register_array, 0);
-                       if (*register_data == NULL)
-                               continue;
-
-                       break;
-               } else if (remain_request != 0) {
-                       insert_data = g_async_queue_pop(reg_queue2);
-                       __msc_insert_register_request(register_array, insert_data);
-                       continue;
-               } else if (register_array->len == 0 && remain_request == 0) {
-               /*Threre is no request, Wait until pushung new request*/
-                       insert_data = g_async_queue_pop(reg_queue2);
-                       __msc_insert_register_request(register_array, insert_data);
-                       continue;
-               }
-       }
-
-       if ((strlen((*register_data)->msg) <= 0) || (strlen((*register_data)->msg) >= MS_FILE_PATH_LEN_MAX)) {
-               MS_DBG_ERR("message size[%zu] is wrong", strlen((*register_data)->msg));
-               return MS_MEDIA_ERR_IPC;
-       }
-
-       return MS_MEDIA_ERR_NONE;
-
-}
-
 gpointer msc_register_thread(gpointer data)
 {
+       int ret = MS_MEDIA_ERR_NONE;
        ms_comm_msg_s *register_data = NULL;
-       GArray *register_array = NULL;
        GPtrArray *path_array = NULL;
-       char *file_path = NULL;
-       int ret;
-       int pid = 0;
-       uid_t uid = MEDIA_DEFAULT_UID;
-       ms_comm_msg_s *msg_data = NULL;
-
-       /*create array for processing overlay data*/
-       register_array = g_array_new(FALSE, FALSE, sizeof(ms_comm_msg_s *));
-       if (register_array == NULL) {
-               MS_DBG_ERR("g_array_new error");
-               return false;
-       }
 
        while (1) {
-               ret = __msc_pop_register_request(register_array, &register_data);
-               if (register_data == NULL) {
-                       MS_DBG_ERR("register_data is NULL");
-                       continue;
-               }
+               register_data = g_async_queue_pop(reg_queue2);
                if (register_data->pid == POWEROFF) {
                        MS_DBG_ERR("power off");
-                       goto _POWEROFF;
+                       g_free(register_data);
+                       return NULL;
                }
 
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       MS_DBG_ERR("__msc_pop_register_request failed [%d]", ret);
-                       goto FREE_RESOURCE;
-               }
-
-               /* check current request */
-               pid = register_data->pid;
-               uid = register_data->uid;
-
-               if (register_data->msg_type != MS_MSG_BULK_INSERT) {
-                       MS_DBG_ERR("wrong message type");
-                       goto FREE_RESOURCE;
-               }
-
-               file_path = g_strdup(register_data->msg);
+               if (register_data->msg_type == MS_MSG_BULK_INSERT) {
+                       ret = __msc_make_file_list(register_data->msg, &path_array, register_data->uid);
+                       if (ret == MS_MEDIA_ERR_NONE) {
+                               MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
+                               ret = __msc_batch_insert(register_data->pid, path_array, register_data->uid);
+                               g_ptr_array_free(path_array, TRUE);
+                               path_array = NULL;
+                               MS_DBG_WARN("BULK REGISTER END [%d]", ret);
+                       } else {
+                               MS_DBG_ERR("__msc_make_file_list failed [%d]", ret);
+                       }
+               } else {
 
-               ret = __msc_make_file_list(file_path, &path_array, uid);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       MS_DBG_ERR("__msc_make_file_list failed [%d]", ret);
-                       goto FREE_RESOURCE;
+                       MS_DBG_ERR("invalid message type [%d]", register_data->msg_type);
+                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                }
 
-               ret = __msc_batch_insert(pid, path_array, uid);
-
-FREE_RESOURCE:
                /*Active flush */
                malloc_trim(0);
 
-               /* If register_files operation is stopped, there is no necessrty for sending result. */
                msc_send_result(ret, register_data);
-
-               MS_DBG_WARN("BULK REGISTER END [%d |%.*s]", ret, MAX_MSG_SIZE, register_data->msg);
-
-               g_ptr_array_free(path_array, TRUE);
-               path_array = NULL;
-
-               g_free(file_path);
-               file_path = NULL;
                g_free(register_data);
-               register_data = NULL;
-               usleep(SCAN_SLEEP_TIME);
        }                       /*thread while*/
 
-_POWEROFF:
-       g_free(file_path);
-       g_free(register_data);
-       if (register_array) {
-               while (register_array->len != 0) {
-                       msg_data = g_array_index(register_array , ms_comm_msg_s*, 0);
-                       g_array_remove_index(register_array, 0);
-                       g_free(msg_data);
-               }
-               g_array_free(register_array, FALSE);
-               register_array = NULL;
-       }
-
        return NULL;
 }