*
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
#include <malloc.h>
-#include <vconf.h>
-#include <usb-device.h>
#include "media-util.h"
#include "media-server-ipc.h"
int g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
static char *g_storage_scan_path;
static char* g_dir_scan_path;
-
-typedef int (*DIR_SCAN_CB)();
-static DIR_SCAN_CB g_dir_scan_cb;
+static bool is_scanner_paused = false;
static int __msc_check_stop_status(int scan_type, const char *start_path, int pid);
static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array);
-static int __msc_dir_scan_cb(void);
static int __msc_check_scan_same_path(char *scan_path);
static void __msc_set_storage_scan_cur_path(char *scan_path);
static void __msc_set_dir_scan_cur_path(char *scan_path);
static int __msc_check_remain_space(uid_t uid);
static void __msc_del_blocked_path(void);
-static int __msc_set_dir_scan_cb(DIR_SCAN_CB cb)
-{
- g_dir_scan_cb = cb;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __msc_call_dir_scan_cb(void)
-{
- if (g_dir_scan_cb != NULL) {
- g_dir_scan_cb();
-
- return MS_MEDIA_ERR_NONE;
- }
-
- return MS_MEDIA_ERR_INTERNAL;
-}
-
-static int __msc_remove_dir_scan_cb(void)
-{
- g_dir_scan_cb = NULL;
-
- return MS_MEDIA_ERR_NONE;
-}
-
void msc_init_scan_thread(void)
{
g_mutex_init(&data_mutex2);
g_cond_clear(&data_cond2);
}
-static int __msc_resume_scan(void)
+static void __msc_resume_scan(void)
{
g_mutex_lock(&data_mutex2);
- g_cond_signal(&data_cond2);
+ if (is_scanner_paused) {
+ is_scanner_paused = false;
+ g_cond_signal(&data_cond2);
+ MS_DBG_WARN("storage scan resumed");
+ }
g_mutex_unlock(&data_mutex2);
-
- return MS_MEDIA_ERR_NONE;
}
static void __msc_pause_scan(void)
{
g_mutex_lock(&data_mutex2);
- g_cond_wait(&data_cond2, &data_mutex2);
+ if (!is_scanner_paused) {
+ is_scanner_paused = true;
+ MS_DBG_WARN("storage scan paused");
+
+ while (is_scanner_paused)
+ g_cond_wait(&data_cond2, &data_mutex2);
+ }
g_mutex_unlock(&data_mutex2);
}
}
}
} else {
- if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+ if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
new_path = g_strdup(path);
g_ptr_array_add(dir_array, new_path);
if (ret != MS_MEDIA_ERR_NONE)
break;
} else {
- __msc_set_dir_scan_cb(__msc_dir_scan_cb);
-
__msc_pause_scan();
- MS_DBG_WARN("wait folder scan callback");
-
- __msc_remove_dir_scan_cb();
-
ret = __msc_get_null_scan_folder_list(handle, storage_id, NULL, dir_array);
if (ret != MS_MEDIA_ERR_NONE)
}
if ((g_directory_scan_processing2 != DIR_SCAN_NON_SCAN)
- && (__msc_dir_and_storage_scan_same_path(new_start_path) == MS_MEDIA_ERR_NONE)) {
- __msc_set_dir_scan_cb(__msc_dir_scan_cb);
- MS_DBG_WARN("storage scan pause");
+ && (__msc_dir_and_storage_scan_same_path(new_start_path) == MS_MEDIA_ERR_NONE))
__msc_pause_scan();
- MS_DBG_WARN("wait folder scan callback");
-
- __msc_remove_dir_scan_cb();
- }
-
goto END_SCAN;
STOP_SCAN:
ms_batch_commit_disable(uid);
MS_DBG_WARN("folder scan done, sent cb event path = [%.*s]", MAX_MSG_SIZE, scan_data->msg);
- __msc_call_dir_scan_cb();
+
+ __msc_resume_scan();
/*revert to 3.0,folder scan should only delete invalid in folder instead of delete invalid in storage*/
if (ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, uid) != MS_MEDIA_ERR_NONE)
return NULL;
}
-static int __msc_dir_scan_cb(void)
-{
- return __msc_resume_scan();
-}
-
static void __msc_check_pvr_svc(void)
{
if (ms_is_support_pvr()) {