#define LAST_EVENT 1
#define NORMAL_EVENT 0
-static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid);
+static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid, bool is_end);
static int __msc_set_storage_extract_status(ms_storage_scan_status_e status);
static int __msc_get_storage_extract_status(ms_storage_scan_status_e *status);
static int __msc_resume_extract();
#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
-static int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, int pid, uid_t uid, unsigned int *io_err_count);
+static int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, int pid, uid_t uid, unsigned int *io_err_count, bool is_end);
int msc_init_extract_thread()
{
return MS_MEDIA_ERR_NONE;
}
-int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, int pid, uid_t uid, unsigned int *io_err_count)
+int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, int pid, uid_t uid, unsigned int *io_err_count, bool is_end)
{
MS_DBG_WARN("begin of __msc_folder_bulk_extract");
int ret = MS_MEDIA_ERR_NONE;
while (data_array->len != 0) {
tmp_ret = MS_MEDIA_ERR_NONE;
db_data = NULL;
+
+ tmp_ret = __msc_check_extract_stop_status(scan_type, storage_type, path, pid, is_end);
+ if (tmp_ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
+ MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
+ break;
+ }
+
db_data = g_array_index(data_array, ms_item_info_s*, 0);
g_array_remove_index (data_array, 0);
free(db_data);
db_data = NULL;
}
-
- tmp_ret = __msc_check_extract_stop_status(scan_type, storage_type, path, pid);
- if (tmp_ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
- MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
- break;
- }
}
if(extract_count > 0) {
char *update_path = NULL;
unsigned int io_err_count = 0;
uid_t uid = MEDIA_DEFAULT_UID;
+ int disc_state = 0;
+ int end_flag = NORMAL_EVENT;
while (1) {
extract_data = g_async_queue_pop(folder_extract_queue);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
+ end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
storage_type = ms_get_storage_type_by_full(extract_data->msg, uid);
- ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid);
+ ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid, end_flag);
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP");
}
/*insert data into media db */
- int end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
-
ret = msc_check_db_size(uid, extract_data->msg_type);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("NOT ENOUGH MEMORY");
}
//ret = ms_insert_item_pass2(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag);
- ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count);
+ ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count, end_flag);
NEXT:
if (power_off2) {
g_directory_extract_processing = false;
msc_del_cur_extract_item();
msc_del_cancel_extract_item();
+ if (msc_get_disc_dir_scan_status()) {
+ MS_DBG("[DISC ACCESS END]");
+ msc_set_disc_dir_scan_status(false);
+
+ ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
+ if (disc_state == MS_DISC_ACCESS) {
+ MS_DBG("[CHANGE DISC STATE]");
+ ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
+ }
+ }
MS_DBG_WARN("DIRECTORY EXTRACT END [%d]", ret);
//GArray *dir_array = NULL;
unsigned int io_err_count = 0;
uid_t uid = MEDIA_DEFAULT_UID;
+ int disc_state = 0;
+ int end_flag = NORMAL_EVENT;
while (1) {
__msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
__msc_set_storage_extract_status(MS_STORAGE_SCAN_META_PROCESSING);
io_err_count = 0;
-
+
MS_DBG_WARN("STORAGE extract START extract len is %d ", g_async_queue_length(storage_extract_queue));
scan_type = extract_data->msg_type;
continue;
}
+ end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
update_path = strndup(extract_data->msg, extract_data->msg_size);
MS_DBG_WARN("extract storage_id is [%s], path [%s]", extract_data->storage_id, update_path);
ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, uid);
__msc_extract_set_db_status(MS_DB_UPDATING);
- ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid);
+ ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid, end_flag);
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
- MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP");
+ MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP[%s]", update_path);
+ if (end_flag) {
+ __msc_extract_set_db_status(MS_DB_STOPPED);
+
+ if (strncmp(update_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0) {
+ if (msc_get_disc_stg_scan_status()) {
+ MS_DBG("[DISC ACCESS STOP]");
+ msc_set_disc_stg_scan_status(false);
+
+ ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
+ if (disc_state == MS_DISC_ACCESS) {
+ MS_DBG("[CHANGE DISC STATE]");
+ ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
+ }
+ }
+ }
+ }
goto NEXT;
}
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("NOT ENOUGH MEMORY");
__msc_extract_set_db_status(MS_DB_STOPPED);
+ if (strncmp(update_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0) {
+ if (msc_get_disc_stg_scan_status()) {
+ MS_DBG("[DISC ACCESS STOP]");
+ msc_set_disc_stg_scan_status(false);
+
+ ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
+ if (disc_state == MS_DISC_ACCESS) {
+ MS_DBG("[CHANGE DISC STATE]");
+ ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
+ }
+ }
+ }
+
goto NEXT;
}
storage_type = ms_get_storage_type_by_full(extract_data->msg, uid);
/*extract meta*/
- int end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
//ret = ms_insert_item_pass2(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag);
- ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count);
+ ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count, end_flag);
msc_del_extract_blocked_path();
__msc_set_storage_extract_status(MS_STORAGE_SCAN_META_STOP);
/* set vconf key db extract status */
__msc_extract_set_db_status(MS_DB_STOPPED);
+ if (msc_get_disc_stg_scan_status()) {
+ MS_DBG("[DISC ACCESS STOP]");
+ msc_set_disc_stg_scan_status(false);
+
+ ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
+ if (disc_state == MS_DISC_ACCESS) {
+ MS_DBG("[CHANGE DISC STATE]");
+ ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
+ }
+ }
} else if (extract_data->result == TRUE) {
MS_DBG_WARN("extract_data->result == TRUE, MS_STORAGE_SCAN_COMPLETE");
ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, uid);
__msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
/* set vconf key db extract status */
__msc_extract_set_db_status(MS_DB_UPDATED);
+ if (msc_get_disc_stg_scan_status()) {
+ MS_DBG("[DISC ACCESS END]");
+ msc_set_disc_stg_scan_status(false);
+
+ ms_config_get_int(MS_DISC_ACCESS_STATE, &disc_state);
+ if (disc_state == MS_DISC_ACCESS) {
+ MS_DBG("[CHANGE DISC STATE]");
+ ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_NOT_ACCESS);
+ }
+
+ }
}
#if 0
return MS_MEDIA_ERR_NONE;
}
-static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid)
+static int __msc_check_extract_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path, int pid, bool is_end)
{
int ret = MS_MEDIA_ERR_NONE;
/* check block path */
if (g_extract_blocked_path != NULL) {
MS_DBG_WARN("check blocked storage [%s][%s]", g_extract_blocked_path, start_path);
- if (strncmp(start_path, g_extract_blocked_path, strlen(start_path)) == 0) {
+ if (strncmp(start_path, g_extract_blocked_path, strlen(g_extract_blocked_path)) == 0) {
MS_DBG_ERR("Receive blocked message[%s][%s]. STOP extract!!", g_extract_blocked_path, start_path);
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
}
-
- MS_SAFE_FREE(g_extract_blocked_path);
+ if (is_end) {
+ MS_DBG("[END REQUEST]");
+ MS_SAFE_FREE(g_extract_blocked_path);
+ } else {
+ MS_DBG("[NOT END REQUEST]");
+ }
}
g_mutex_unlock(&extract_blocked_mutex);
return;
}
+#ifdef _USE_SENIOR_MODE
+extern GAsyncQueue *storage_queue2;
+extern GAsyncQueue *storage_extract_queue;
+extern int g_directory_scan_processing2;
+extern bool g_directory_extract_processing;
+
+void _msc_datadisc_vconf_cb(void *data)
+{
+ int disc_state = 0;
+ char *disc_type = NULL;
+ char *disc_path = NULL;
+ char *valid_type = "data";
+ char storage_path[11] = {0,};
+
+ /*check disc type */
+ if (!ms_config_get_str(MS_DISC_TYPE, &disc_type)) {
+ MS_DBG_ERR("Get MS_DISC_TYPE failed.");
+ goto END;
+ }
+
+ MS_DBG("[disc type] %s", disc_type);
+
+ if (strcmp(disc_type, valid_type) == 0) {
+ ms_config_get_int(MS_DISC_STATE, &disc_state);
+
+ if (disc_state == 1) {
+ MS_DBG_WARN("[DISC INSERTED]");
+ } else {
+ MS_DBG_WARN("[DISC REMOVED]");
+ int status = -1;
+
+ /* check mount path */
+ if (!ms_config_get_str(MS_DISC_PATH, &disc_path)) {
+ MS_DBG_ERR("Get MS_DISC_PATH failed.");
+ goto END;
+ }
+
+ MS_DBG("[disc path] %s", disc_path);
+ memset(storage_path, 0x0, sizeof(storage_path));
+ strncpy(storage_path, disc_path, sizeof(storage_path)-1);
+
+ if (msc_get_disc_dir_scan_status() ||
+ msc_get_disc_stg_scan_status()) {
+ MS_DBG("[DATA DISC IS READING]");
+ ms_config_set_int(MS_DISC_ACCESS_STATE, MS_DISC_ACCESS);
+ }
+
+ if(!ms_config_get_int(VCONFKEY_FILEMANAGER_DB_STATUS, &status)) {
+ MS_DBG_ERR("ms_config_get_int[VCONFKEY_FILEMANAGER_DB_STATUS]");
+ }
+
+ if (!(g_async_queue_length(storage_queue2) == 0 && status == VCONFKEY_FILEMANAGER_DB_UPDATED)) {
+ msc_set_blocked_path(storage_path);
+ }
+
+ if (g_directory_scan_processing2 != 0) {
+ MS_DBG_WARN("Doing directory scanning. Set cancel path");
+ msc_set_cancel_scan_item(storage_path, -1);
+ }
+
+ if (!(g_async_queue_length(storage_extract_queue) == 0 && status == VCONFKEY_FILEMANAGER_DB_UPDATED)) {
+ msc_set_extract_blocked_path(storage_path);
+ }
+
+ if (g_directory_extract_processing == true) {
+ MS_DBG_WARN("Doing directory extracting. Set cancel path");
+ msc_set_cancel_extract_item(storage_path, -1);
+ }
+ }
+ }
+
+END:
+ MS_SAFE_FREE(disc_type);
+
+ return;
+}
+#endif
+
int main(int argc, char **argv)
{
GThread *storage_scan_thread = NULL;
/*set power off callback function*/
ms_sys_set_poweroff_cb(__msc_power_off_cb, NULL);
ms_sys_set_device_block_event_cb(msc_device_block_changed_cb, NULL);
+
+#ifdef _USE_SENIOR_MODE
+ if (vconf_notify_key_changed(MS_DISC_STATE, (vconf_callback_fn) _msc_datadisc_vconf_cb, NULL) == -1)
+ MS_DBG_ERR("add call back function for event %s fails", MS_DISC_STATE);
+#endif
}
static void __msc_remove_event_receiver(void)
return MS_MEDIA_ERR_NONE;
}
+static int __ms_check_disc_status(void)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ int disc_state = 0;
+ int validity = 0;
+ char *disc_type = NULL;
+ char *disc_path = NULL;
+ char *valid_type = "data";
+ ms_dir_scan_type_t scan_type = MS_SCAN_PART;
+ uid_t uid = MEDIA_DEFAULT_UID;
+ char mnt_path[11] = {0,};
+ char *storage_path = NULL;
+ void **handle = NULL;
+
+ ms_config_get_int(MS_DISC_STATE, &disc_state);
+ if (disc_state == 1) {
+ /*check disc type */
+ if (!ms_config_get_str(MS_DISC_TYPE, &disc_type)) {
+ MS_DBG_ERR("Get MS_DISC_TYPE failed.");
+ goto END;
+ }
+
+ if (strcmp(disc_type, valid_type) == 0) {
+ MS_DBG_WARN("[DISC INSERTED][%s]",disc_type);
+ MS_DBG_WARN("MOUNT PATH [%s]", mnt_path);
+
+ /* check mount path */
+ if (!ms_config_get_str(MS_DISC_PATH, &disc_path)) {
+ MS_DBG_ERR("Get MS_DISC_PATH failed.");
+ goto END;
+ }
+
+ MS_DBG("[disc path] %s", disc_path);
+ memset(mnt_path, 0x0, sizeof(mnt_path));
+ strncpy(mnt_path, disc_path, sizeof(mnt_path)-1);
+
+ ret = ms_load_functions();
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_load_functions failed [%d]", ret);
+ return;
+ }
+
+ /* request scanning */
+ ms_sys_get_uid(&uid);
+
+ ms_connect_db(&handle, uid);
+
+ /* update storage information into media DB */
+ ret = ms_check_storage(handle, DATADISC_STORAGE_ID, NULL, &storage_path, &validity);
+ if (ret == 0) {
+ ms_set_storage_validity(handle, DATADISC_STORAGE_ID, 1, uid);
+ if (ms_set_storage_scan_status(handle, DATADISC_STORAGE_ID, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_set_storage_scan_status failed");
+ }
+
+ MS_DBG_WARN("init storage data in DB");
+ /* update storage_id table set validity=0 first */
+ ms_validaty_change_all_items(handle, DATADISC_STORAGE_ID, MS_STORAGE_EXTERNAL, false, uid);
+ /*update folder table set validity = 0*/
+ ms_set_folder_validity(handle, DATADISC_STORAGE_ID, mnt_path, MS_INVALID, TRUE, uid);
+ /* update folder table set scan_status=0 first */
+ ms_set_folder_scan_status(handle, DATADISC_STORAGE_ID, NULL, MS_DIR_SCAN_NONE, uid);
+ MS_DBG_WARN("init storage data in DB end");
+
+ } else {
+ ret = ms_insert_storage(handle, DATADISC_STORAGE_ID, NULL, mnt_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_insert_storage failed");
+ goto END;
+ }
+ }
+
+ ms_send_storage_scan_request(mnt_path, DATADISC_STORAGE_ID, scan_type, uid);
+
+ ms_disconnect_db(&handle);
+
+ ms_unload_functions();
+ }
+ }
+
+END:
+ MS_SAFE_FREE(disc_type);
+ MS_SAFE_FREE(disc_path);
+ MS_SAFE_FREE(storage_path);
+
+
+ return MS_MEDIA_ERR_NONE;
+}
+
static void __ms_check_mediadb(void)
{
#ifndef _USE_MULTI_USER
if (_USE_SDCARD)
__ms_check_mmc_status();
__ms_check_usb_status();
+
+#ifdef _USE_SENIOR_MODE
+ __ms_check_disc_status();
+#endif
+
}
static bool __ms_is_dcm_supported()