summaryrefslogtreecommitdiff
path: root/src/scanner/media-scanner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scanner/media-scanner.c')
-rwxr-xr-xsrc/scanner/media-scanner.c258
1 files changed, 48 insertions, 210 deletions
diff --git a/src/scanner/media-scanner.c b/src/scanner/media-scanner.c
index c62dbbd..b41c6b9 100755
--- a/src/scanner/media-scanner.c
+++ b/src/scanner/media-scanner.c
@@ -19,15 +19,6 @@
*
*/
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-main.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief
- */
-
#include <dirent.h>
#include <vconf.h>
#include <sys/types.h>
@@ -37,167 +28,20 @@
#include "media-common-utils.h"
#include "media-common-external-storage.h"
+#include "media-common-db-svc.h"
+#include "media-common-system.h"
#include "media-util.h"
#include "media-scanner-dbg.h"
-#include "media-scanner-db-svc.h"
+#include "media-scanner-device-block.h"
#include "media-scanner-scan.h"
#include "media-scanner-socket.h"
-#define APP_NAME "media-scanner"
-
-extern int mmc_state;
-
-extern GAsyncQueue *storage_queue;
-extern GAsyncQueue *scan_queue;
-extern GAsyncQueue *reg_queue;
-extern GMutex *db_mutex;
-bool power_off; /*If this is TRUE, poweroff notification received*/
-
static GMainLoop *scanner_mainloop = NULL;
-bool check_process(void)
-{
- DIR *pdir;
- struct dirent pinfo;
- struct dirent *result = NULL;
- bool ret = false;
- int find_pid = 0;
- pid_t current_pid = 0;
-
- current_pid = getpid();
-
- pdir = opendir("/proc");
- if (pdir == NULL) {
- MSC_DBG_ERR("err: NO_DIR\n");
- return 0;
- }
-
- while (!readdir_r(pdir, &pinfo, &result)) {
- if (result == NULL)
- break;
-
- if (pinfo.d_type != 4 || pinfo.d_name[0] == '.'
- || pinfo.d_name[0] > 57)
- continue;
-
- FILE *fp;
- char buff[128];
- char path[128];
-
- ms_strcopy(path, sizeof(path), "/proc/%s/status", pinfo.d_name);
- fp = fopen(path, "rt");
- if (fp) {
- if (fgets(buff, 128, fp) == NULL)
- MSC_DBG_ERR("fgets failed");
- fclose(fp);
-
- if (strstr(buff, APP_NAME)) {
- find_pid = atoi(pinfo.d_name);
- if (find_pid == current_pid)
- ret = true;
- else {
- ret = false;
- break;
- }
- }
- } else {
- MSC_DBG_ERR("Can't read file [%s]", path);
- }
- }
-
- closedir(pdir);
-
- return ret;
-}
-
-void init_process()
-{
-
-}
-
-static void _power_off_cb(void* data)
-{
- ms_comm_msg_s *scan_data;
- ms_comm_msg_s *reg_data;
-
- MSC_DBG_INFO("++++++++++++++++++++++++++++++++++++++");
- MSC_DBG_INFO("POWER OFF");
- MSC_DBG_INFO("++++++++++++++++++++++++++++++++++++++");
-
- power_off = true;
-
- if (scan_queue) {
- /*notify to scannig thread*/
- MS_MALLOC(scan_data, sizeof(ms_comm_msg_s));
- scan_data->pid = POWEROFF;
- g_async_queue_push(scan_queue, GINT_TO_POINTER(scan_data));
- }
-
- if (reg_queue) {
- /*notify to register thread*/
- MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
- reg_data->pid = POWEROFF;
- g_async_queue_push(reg_queue, GINT_TO_POINTER(reg_data));
- }
-
- if (storage_queue) {
- /*notify to register thread*/
- MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
- reg_data->pid = POWEROFF;
- g_async_queue_push(storage_queue, GINT_TO_POINTER(reg_data));
- }
-
- if (g_main_loop_is_running(scanner_mainloop)) g_main_loop_quit(scanner_mainloop);
-}
-
-void
-_msc_mmc_vconf_cb(keynode_t *key, void* data)
-{
- int status = 0;
-/*
- ms_comm_msg_s *scan_msg;
- ms_dir_scan_type_t scan_type = MS_SCAN_PART;
-*/
- if (!ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status)) {
- MSC_DBG_ERR("Get VCONFKEY_SYSMAN_MMC_STATUS failed.");
- }
-
- MSC_DBG_INFO("VCONFKEY_SYSMAN_MMC_STATUS :%d", status);
-
- mmc_state = status;
-/*
- MS_MALLOC(scan_msg, sizeof(ms_comm_msg_s));
-
- if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED ||
- mmc_state == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
- scan_type = MS_SCAN_INVALID;
- } else if (mmc_state == VCONFKEY_SYSMAN_MMC_MOUNTED) {
- scan_type = ms_get_mmc_state();
- }
-
- switch (scan_type) {
- case MS_SCAN_ALL:
- scan_msg->msg_type = MS_MSG_STORAGE_ALL;
- break;
- case MS_SCAN_PART:
- scan_msg->msg_type = MS_MSG_STORAGE_PARTIAL;
- break;
- case MS_SCAN_INVALID:
- scan_msg->msg_type = MS_MSG_STORAGE_INVALID;
- break;
- }
-
- scan_msg->pid = 0;
- scan_msg->msg_size = strlen(MEDIA_ROOT_PATH_SDCARD);
- ms_strcopy(scan_msg->msg, scan_msg->msg_size+1, "%s", MEDIA_ROOT_PATH_SDCARD);
-
- MSC_DBG_INFO("ms_get_mmc_state is %d", scan_msg->msg_type);
-
- g_async_queue_push(storage_queue, GINT_TO_POINTER(scan_msg));
-*/
- return;
-}
+static void __msc_power_off_cb(ms_power_info_s *power_info, void* data);
+static void __msc_add_event_receiver(void *data);
+static void __msc_remove_event_receiver(void);
int main(int argc, char **argv)
{
@@ -211,52 +55,36 @@ int main(int argc, char **argv)
int err = -1;
int fd = -1;
-#if 0 /* temporary */
- check_result = check_process();
- if (check_result == false)
- exit(0);
-#endif
- if (!g_thread_supported()) {
- g_thread_init(NULL);
- }
-
- /*Init main loop*/
- scanner_mainloop = g_main_loop_new(NULL, FALSE);
-
/*set power off callback function*/
- ms_add_poweoff_event_receiver(_power_off_cb, NULL);
+ __msc_add_event_receiver(NULL);
/*load functions from plusin(s)*/
- err = msc_load_functions();
+ err = ms_load_functions();
if (err != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("function load failed[%d]", err);
+ MS_DBG_ERR("function load failed[%d]", err);
goto EXIT;
}
- /*Init for register file*/
- /*These are a communicator for thread*/
- if (!scan_queue) scan_queue = g_async_queue_new();
- if (!reg_queue) reg_queue = g_async_queue_new();
- if (!storage_queue) storage_queue = g_async_queue_new();
+ /*Init main loop*/
+ scanner_mainloop = g_main_loop_new(NULL, FALSE);
- /*Init mutex variable*/
- if (!db_mutex) db_mutex = g_mutex_new();
+ msc_init_scanner();
/* Create pipe */
err = unlink(MS_SCANNER_FIFO_PATH_REQ);
if (err !=0) {
- MSC_DBG_STRERROR("unlink failed");
+ MS_DBG_STRERROR("unlink failed");
}
err = mkfifo(MS_SCANNER_FIFO_PATH_REQ, MS_SCANNER_FIFO_MODE);
if (err !=0) {
- MSC_DBG_STRERROR("mkfifo failed");
- return MS_MEDIA_ERR_FIFO_MAKE_FAIL;
+ MS_DBG_STRERROR("mkfifo failed");
+ return MS_MEDIA_ERR_INTERNAL;
}
fd = open(MS_SCANNER_FIFO_PATH_REQ, O_RDWR);
if (fd < 0) {
- MSC_DBG_STRERROR("fifo open failed");
+ MS_DBG_STRERROR("fifo open failed");
return MS_MEDIA_ERR_FILE_OPEN_FAIL;
}
@@ -276,22 +104,17 @@ int main(int argc, char **argv)
scan_thread = g_thread_new("scanner_thread", (GThreadFunc)msc_directory_scan_thread, NULL);
register_thread = g_thread_new("register_thread", (GThreadFunc)msc_register_thread, NULL);
- /*set vconf callback function*/
- err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) _msc_mmc_vconf_cb, NULL);
- if (err == -1)
- MSC_DBG_ERR("add call back function for event %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
-
if (ms_is_mmc_inserted()) {
- mmc_state = VCONFKEY_SYSMAN_MMC_MOUNTED;
+ msc_set_mmc_status(MS_STG_INSERTED);
}
- MSC_DBG_INFO("scanner is ready");
+ MS_DBG_INFO("scanner is ready");
msc_send_ready();
- MSC_DBG_ERR("*****************************************");
- MSC_DBG_ERR("*** Scanner is running ***");
- MSC_DBG_ERR("*****************************************");
+ MS_DBG_ERR("*****************************************");
+ MS_DBG_ERR("*** Scanner is running ***");
+ MS_DBG_ERR("*****************************************");
g_main_loop_run(scanner_mainloop);
@@ -299,27 +122,42 @@ int main(int argc, char **argv)
g_thread_join (register_thread);
g_thread_join (storage_scan_thread);
- if (power_off) {
- g_io_channel_shutdown(channel, FALSE, NULL);
- g_io_channel_unref(channel);
- }
+ g_io_channel_shutdown(channel, FALSE, NULL);
+ g_io_channel_unref(channel);
- if (scan_queue) g_async_queue_unref(scan_queue);
- if (reg_queue) g_async_queue_unref(reg_queue);
- if (storage_queue) g_async_queue_unref(storage_queue);
-
- /*Clear db mutex variable*/
- if (db_mutex) g_mutex_free (db_mutex);
+ msc_deinit_scanner();
/*close pipe*/
close(fd);
/*unload functions*/
- msc_unload_functions();
+ ms_unload_functions();
+
+ __msc_remove_event_receiver();
EXIT:
- MSC_DBG_INFO("SCANNER IS END");
+ MS_DBG_INFO("SCANNER IS END");
return 0;
}
+static void __msc_power_off_cb(ms_power_info_s *power_info, void* data)
+{
+ msc_send_power_off_request();
+
+ if (g_main_loop_is_running(scanner_mainloop)) g_main_loop_quit(scanner_mainloop);
+}
+
+static void __msc_add_event_receiver(void *data)
+{
+ /*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);
+}
+
+static void __msc_remove_event_receiver(void)
+{
+ ms_sys_unset_device_block_event_cb();
+ ms_sys_unset_poweroff_cb();
+}
+