2. change socket permission.
Change-Id: Ib83f0bdd11724de89681215adc64d2f3d832d781
#define DB_TABLE_MEDIA "media"
#define FACE_ITEM "face_uuid, media_uuid, face_rect_x , face_rect_y, face_rect_w , face_rect_h, orientation"
-#define SELECT_PATH_FROM_UNEXTRACTED_DCM_MEDIA "SELECT media_uuid, path, storage_uuid, width, height, orientation, mime_type FROM media WHERE media_uuid NOT IN (SELECT DISTINCT media_uuid FROM face_scan_list) AND validity=1 AND media_type=0;"
#define SELECT_MEDIA_INFO_BY_FILE_PATH_FROM_DB "SELECT media_uuid, storage_uuid, width, height, orientation, mime_type, modified_time FROM media WHERE path = '%q';"
#define SELECT_SCAN_INFO_BY_MEDIA_ID "SELECT modified_time FROM "DB_TABLE_FACE_SCAN_LIST" WHERE media_uuid = '%q';"
int dcm_svc_db_connect(uid_t uid);
int dcm_svc_db_disconnect();
int dcm_svc_db_get_scan_image_info_by_path(const char *file_path, dcm_svc_item_s **scan_item);
-int dcm_svc_db_get_scan_image_list_from_db(GList **image_list);
-int dcm_svc_db_insert_category_to_db(void *item);
int dcm_svc_db_generate_uuid(dcm_face_item_s **face);
int dcm_svc_db_insert_face_to_db(dcm_face_item_s *face);
int dcm_svc_db_update_color_to_db(const dcm_color_item_s color);
#define FONT_COLOR_RESET "\033[0m"
#define FONT_COLOR_RED "\033[31m"
#define FONT_COLOR_GREEN "\033[32m"
+#define FONT_COLOR_YELLOW "\033[33m"
#define FONT_COLOR_CYAN "\033[36m"
#define dcm_debug(fmt, arg...) do { \
} while (0)
#define dcm_debug_fenter() do { \
- LOGD(FONT_COLOR_RESET"<Enter>"); \
+ LOGD(FONT_COLOR_YELLOW"<ENTER>"FONT_COLOR_RESET); \
} while (0)
#define dcm_debug_fleave() do { \
- LOGD(FONT_COLOR_RESET"<Leave>"); \
+ LOGD(FONT_COLOR_YELLOW"<LEAVE>"FONT_COLOR_RESET); \
} while (0)
#define dcm_retm_if(expr, fmt, arg...) do { \
#define _DCM_SVC_FACE_H_
#include <dcm_svc_internal.h>
+#include <dcm_svc_db.h>
int dcm_face_detect_initialize();
int dcm_face_detect_finalize();
#include <glib.h>
#include <dcm_image_codec.h>
-typedef struct {
- GMainLoop *main_loop;
- GMainContext *main_context;
- gboolean g_scan_cancel;
- GSource *kill_timer_source;
-
- /* scan all images */
- GList *scan_all_item_list;
- unsigned int scan_all_curr_index;
-
- /* scan single images */
- GList *scan_single_item_list;
- unsigned int scan_single_curr_index;
-
- uid_t g_uid;
-} dcm_scan_s;
-
-typedef enum {
- DCM_SCAN_ITEM_TYPE_NONE,
- DCM_SCAN_ITEM_TYPE_SCAN_ALL,
- DCM_SCAN_ITEM_TYPE_SCAN_SINGLE,
- DCM_SCAN_ITEM_TYPE_MAX,
-} dcm_svc_type_e;
-
typedef struct {
char *media_uuid;
char *file_path;
dcm_image_format_e decode_type; /* decoding pre-condition */
} dcm_image_info_s;
-gboolean dcm_scan_thread(void *data);
int dcm_scan_single(const char *file_path, uid_t uid, int *face_count);
-void quit_scan_thread();
-
#endif /* _DCM_SCAN_SVC_H_ */
#define DCM_TIMEOUT_SEC_60 60 /**< Response to media server time out */
typedef enum {
- DCM_IPC_PORT_SCAN_RECV = 0,
- DCM_IPC_PORT_DCM_RECV,
- DCM_IPC_PORT_MS_RECV,
+ DCM_IPC_PORT_DCM_RECV = 0, /*Receive msg from media-server*/
+ DCM_IPC_PORT_MS_RECV, /*Send msg to media-server*/
DCM_IPC_PORT_MAX,
} dcm_ipc_port_e;
int dcm_ipc_accept_socket(int serv_sock, int *client_sock);
int dcm_ipc_receive_message(int client_sock, dcmMsg *recv_msg);
int dcm_ipc_send_message(ms_dcm_msg_type_e msg_type, uid_t uid, const char *msg, dcm_ipc_port_e port);
-int dcm_ipc_send_complete(ms_dcm_msg_type_e msg_type, const unsigned int count, const char *msg, dcm_ipc_port_e port);
int dcm_ipc_send_client_message(int socket_fd, ms_dcm_msg_type_e msg_type, unsigned int result, const char *msg, dcm_ipc_port_e port);
int dcm_ipc_close_socket(int socket_fd);
#define EXPORT_API __attribute__ ((visibility("default")))
#endif
-typedef struct {
- // main thread
- GMainLoop *main_loop;
- GMainContext *main_context;
- GSource *kill_timer_source;
-
- // scan thread
- GThread *scan_thread;
- GAsyncQueue *scan_thread_ready;
- gboolean scan_thread_working;
-} dcm_service_s;
-
#endif /* _DCM_MAIN_SVC_H_ */
Name: dcm-service
Summary: A media DCM(Digital Contents Management) Service
-Version: 0.1.9
+Version: 0.1.10
Release: 0
Group: Multimedia/Service
License: Apache-2.0
static gboolean __dcm_svc_db_check_duplicated(MediaDBHandle *db_handle, dcm_face_item_s *data);
static gboolean __dcm_svc_db_check_duplicated_scan_list(MediaDBHandle *db_handle, const char *data);
static int __dcm_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt);
-static int __dcm_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt);
static gboolean __dcm_svc_db_check_duplicated(MediaDBHandle *db_handle, dcm_face_item_s *data)
{
ret = sqlite3_step(*stmt);
if (ret != SQLITE_ROW) {
- dcm_error("[No-Error] Item not found. end of row [%s]", sqlite3_errmsg(handle));
+ dcm_warn("[No-Error] Item not found. end of row [%s]", sqlite3_errmsg(handle));
DCM_SQLITE3_FINALIZE(*stmt);
return MS_MEDIA_ERR_DB_NO_RECORD;
}
return MS_MEDIA_ERR_NONE;
}
-static int __dcm_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- dcm_sec_debug("[SQL query] : %s", sql_str);
-
- if (!DCM_STRING_VALID(sql_str)) {
- dcm_error("invalid query");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- ret = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
- sqlite3_free((char *)sql_str);
-
- if (ret != SQLITE_OK) {
- dcm_error("prepare error %d[%s]", ret, sqlite3_errmsg(handle));
- if (ret == SQLITE_CORRUPT)
- return MS_MEDIA_ERR_DB_CORRUPT;
- else if (ret == SQLITE_PERM)
- return MS_MEDIA_ERR_DB_PERMISSION;
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
int dcm_svc_db_connect(uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
return ret;
}
-int dcm_svc_db_get_scan_image_list_from_db(GList **image_list)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char * query_string = NULL;
- sqlite3_stmt *sql_stmt = NULL;
-
- dcm_debug_fenter();
-
- dcm_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid db_handle");
- dcm_retvm_if(image_list == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image_list");
-
- /* Make query */
- query_string = sqlite3_mprintf(SELECT_PATH_FROM_UNEXTRACTED_DCM_MEDIA);
- dcm_retvm_if(query_string == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Invalid query_string");
-
- ret = __dcm_svc_sql_prepare_to_step_simple((sqlite3 *)db_handle, query_string, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- dcm_error("error when __dcm_svc_sql_prepare_to_step_simple. ret = [%d]", ret);
- return ret;
- }
-
- while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- dcm_svc_item_s *scan_item = (dcm_svc_item_s *) g_malloc0(sizeof(dcm_svc_item_s));
- if (!scan_item) {
- dcm_error("Failed to allocate memory for scan_item!");
- continue;
- }
-
- scan_item->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- scan_item->file_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 1));
- scan_item->storage_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
- scan_item->image_width = sqlite3_column_int(sql_stmt, 3);
- scan_item->image_height = sqlite3_column_int(sql_stmt, 4);
- scan_item->image_orientation = sqlite3_column_int(sql_stmt, 5);
- scan_item->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 6));
-
- *image_list = g_list_append(*image_list, scan_item);
-
- dcm_sec_debug("media uuid: [%s] file path: [%s]", scan_item->media_uuid, scan_item->file_path);
- }
-
- DCM_SQLITE3_FINALIZE(sql_stmt);
-
- dcm_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
int dcm_svc_db_generate_uuid(dcm_face_item_s **face)
{
int ret = MS_MEDIA_ERR_NONE;
#include <dcm_svc_ipc.h>
#include <dcm_svc_internal.h>
-#include <dcm_svc_main.h>
#include <dcm_svc_db.h>
#include <dcm_svc_debug.h>
#include <dcm_svc_extract_color.h>
#include <dcm_svc_detect_face.h>
-#define DCM_SVC_SCAN_THREAD_TIMEOUT_SEC 1
-
-static int __dcm_scan_create_timer(gpointer data);
-
-static void __dcm_scan_main_loop_quit(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
- if (_data->main_loop != NULL) {
- dcm_warn("Quit scan thread mainloop!");
- g_main_loop_quit(_data->main_loop);
- } else {
- dcm_warn("Scan thread mainloop is invalid!");
- }
-
- return;
-}
-
-gboolean __dcm_scan_kill_scan_thread(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
- int ret;
-
- dcm_debug_fenter();
-
- DCM_CHECK_FALSE(data);
-
- ret = dcm_ipc_send_message(DCM_MSG_SCAN_TERMINATED, 0, NULL, DCM_IPC_PORT_DCM_RECV);
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("send to terminated messge to DCM Main");
-
- if (_data->scan_all_curr_index != 0 || _data->scan_single_curr_index != 0) {
- dcm_warn("Scan thread is working! DO NOT quit main thread!");
- __dcm_scan_create_timer(data);
- } else {
- dcm_warn("Quit dcm-svc main loop!");
- __dcm_scan_main_loop_quit(data);
- }
-
- dcm_debug_fleave();
-
- return FALSE;
-}
-
-static int __dcm_scan_create_timer(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
- dcm_debug_fenter();
-
- if (_data->kill_timer_source != NULL) {
- dcm_debug("Delete old quit timer!");
- g_source_destroy(_data->kill_timer_source);
- _data->kill_timer_source = NULL;
- }
-
- _data->kill_timer_source = g_timeout_source_new_seconds(DCM_SVC_SCAN_THREAD_TIMEOUT_SEC);
- DCM_CHECK_VAL(_data->kill_timer_source, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- g_source_set_callback(_data->kill_timer_source, __dcm_scan_kill_scan_thread, (gpointer)data, NULL);
- g_source_attach(_data->kill_timer_source, _data->main_context);
-
- dcm_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static void __destroy_scan_item(void *data)
-{
- dcm_svc_item_s *scan_item = (dcm_svc_item_s *) data;
-
- dcm_debug_fenter();
-
- DCM_CHECK(scan_item);
- DCM_CHECK(scan_item->file_path);
- DCM_CHECK(scan_item->media_uuid);
- DCM_CHECK(scan_item->storage_uuid);
-
- dcm_sec_debug("Free scan item. path: [%s]", scan_item->file_path);
-
- DCM_SAFE_FREE(scan_item->file_path);
- DCM_SAFE_FREE(scan_item->media_uuid);
- DCM_SAFE_FREE(scan_item->storage_uuid);
- DCM_SAFE_FREE(scan_item);
-
- dcm_debug_fleave();
-
- return;
-}
-
-static int __dcm_scan_get_item_list(dcm_scan_s *data)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- /* Get scan image list from db */
- ret = dcm_svc_db_get_scan_image_list_from_db(&(data->scan_all_item_list));
- if (ret != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to get image list from db! ret: %d", ret);
- return ret;
- }
-
- if (data->scan_all_item_list == NULL) {
- dcm_debug("No image list for scanning");
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- if ((data->scan_all_item_list != NULL) && (g_list_length(data->scan_all_item_list) == 0)) {
- dcm_debug("No image list from db!");
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __dcm_scan_send_result(dcm_scan_s *data, const char *msg, const unsigned int count, dcm_ipc_port_e port)
-{
- if ((data->scan_all_item_list == NULL) && (data->scan_single_item_list == NULL)) {
- dcm_debug("Send completed message");
- dcm_ipc_send_complete(DCM_MSG_SCAN_COMPLETED, count, msg, port);
- } else {
- if (data->scan_all_item_list)
- dcm_warn("scan_all_item_list");
-
- if (data->scan_single_item_list)
- dcm_warn("scan_single_item_list");
-
- dcm_warn("Scan operation is not finished yet. Keep scanning...");
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __dcm_scan_clear_all_items(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
-
- dcm_debug_fenter();
-
- DCM_CHECK_VAL(_data, MS_MEDIA_ERR_INVALID_PARAMETER);
-
- if (_data->scan_all_item_list != NULL) {
- g_list_free_full(_data->scan_all_item_list, __destroy_scan_item);
- _data->scan_all_item_list = NULL;
- }
-
- _data->scan_all_curr_index = 0;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __dcm_scan_clear_single_item(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
-
- dcm_debug_fenter();
-
- DCM_CHECK_VAL(_data, MS_MEDIA_ERR_INVALID_PARAMETER);
-
- if (_data->scan_single_item_list) {
- g_list_free_full(_data->scan_single_item_list, __destroy_scan_item);
- _data->scan_single_item_list = NULL;
- }
-
- _data->scan_single_curr_index = 0;
-
- return MS_MEDIA_ERR_NONE;
-}
-
static int __dcm_scan_process(dcm_svc_item_s *scan_item)
{
dcm_face_scan_status_e scan_status = FACE_SCAN_STATUS_NONE;
return ret;
}
-gboolean __dcm_scan_idle_process(gpointer data)
-{
- int ret = MS_MEDIA_ERR_NONE;
- dcm_scan_s *_data = (dcm_scan_s *)data;
- dcm_svc_item_s *scan_item = NULL;
-
- dcm_debug_fenter();
-
- DCM_CHECK_FALSE(_data);
-
- ret = dcm_svc_db_connect(_data->g_uid);
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to disconnect db! err: %d", ret);
- /* DCM scan started */
- unsigned int list_len = g_list_length(_data->scan_all_item_list);
- if ((_data->scan_all_curr_index < list_len) && !_data->g_scan_cancel) {
- scan_item = (dcm_svc_item_s *)g_list_nth_data(_data->scan_all_item_list, _data->scan_all_curr_index);
- dcm_sec_debug("current index: %d, path: %s state: %s", _data->scan_all_curr_index, scan_item->file_path, (_data->g_scan_cancel) ? "cancel" : "go");
-
- ret = __dcm_scan_process(scan_item);
- if (ret != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to process scan job! err: %d", ret);
-
- /* If the scan item is not scanned, insert media uuid into face_scan_list */
- if (ret != MS_MEDIA_ERROR_ALREADY_SCANNED)
- dcm_svc_db_insert_face_to_face_scan_list(scan_item);
- }
-
- (_data->scan_all_curr_index)++;
- } else {
- dcm_warn("All images are scanned. Scan operation completed");
- __dcm_scan_clear_all_items(data);
- ret = dcm_svc_db_disconnect();
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to disconnect db! err: %d", ret);
- __dcm_scan_clear_all_items(data);
- /* Send scan complete message to main thread (if all scan operations are finished) */
- __dcm_scan_send_result(data, NULL, 0, DCM_IPC_PORT_DCM_RECV);
- dcm_debug_fleave();
- return FALSE;
- }
- ret = dcm_svc_db_disconnect();
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to disconnect db! err: %d", ret);
- dcm_debug_fleave();
-
- return TRUE;
-}
-
-static int __dcm_scan_all_items(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
- int ret = MS_MEDIA_ERR_NONE;
-
- dcm_debug_fenter();
-
- __dcm_scan_clear_all_items(data);
-
- ret = __dcm_scan_get_item_list(_data);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- dcm_debug("No items to Scan. Scan operation completed!!!");
- __dcm_scan_clear_all_items(data);
- /* Send scan complete message to main thread (if all scan operations are finished) */
- __dcm_scan_send_result(data, NULL, 0, DCM_IPC_PORT_DCM_RECV);
- ret = dcm_svc_db_disconnect();
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to disconnect db! err: %d", ret);
- return MS_MEDIA_ERR_NONE;
- }
-
- /* DCM scan started */
- g_idle_add(__dcm_scan_idle_process, (gpointer)data);
-
- dcm_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __dcm_scan_kill_scanner(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *) data;
- dcm_debug("Terminate scanning operations, and quit scan thread main loop");
-
- _data->g_scan_cancel = TRUE;
-
- return __dcm_scan_create_timer(data);
-}
-
-static int __dcm_scan_receive_message(dcmMsg *recv_msg, gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *) data;
- int ret = MS_MEDIA_ERR_NONE;
-
- _data->g_uid = recv_msg->uid;
- DCM_CHECK_VAL(recv_msg, MS_MEDIA_ERR_INVALID_PARAMETER);
-
- dcm_debug("msg_type: %d", recv_msg->msg_type);
-
- if (recv_msg->msg_type == DCM_MSG_REQUEST_KILL_SERVER) {
- /* Destroy scan idles, and quit scan thread main loop */
- ret = __dcm_scan_kill_scanner(data);
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to terminate DCM scan service! err: %d", ret);
- return ret;
- } else if (recv_msg->msg_type == DCM_MSG_REQUEST_ALL_MEDIA) {
- /* Use timer to scan all unscanned images */
- ret = dcm_svc_db_connect(recv_msg->uid);
- if (ret != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to disconnect db! err: %d", ret);
- __dcm_scan_all_items(data);
- ret = dcm_svc_db_disconnect();
- } else {
- dcm_error("Invalid message type(%d)!", recv_msg->msg_type);
- ret = MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
- }
-
- return ret;
-}
-
-int dcm_scan_init(gpointer data)
-{
- dcm_scan_s *_data = (dcm_scan_s *)data;
-
- _data->scan_all_item_list = NULL;
- _data->scan_all_curr_index = 0;
- _data->scan_single_item_list = NULL;
- _data->scan_single_curr_index = 0;
- _data->g_scan_cancel = FALSE;
- _data->kill_timer_source = NULL;
-
- dcm_face_detect_initialize();
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int dcm_scan_finalize(gpointer data)
-{
- /* Only scan item lists are freed here, scan idles should be freed before this function */
- dcm_scan_s *_data = (dcm_scan_s *)data;
-
- __dcm_scan_clear_all_items(data);
- __dcm_scan_clear_single_item(data);
- dcm_face_detect_finalize();
-
- DCM_SAFE_FREE(_data);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-gboolean dcm_scan_reply_for_ready(gpointer data)
-{
- dcm_service_s *_data = (dcm_service_s *) data;
- dcmMsg *async_queue_msg = NULL;
-
- dcm_debug_fenter();
-
- DCM_CHECK_FALSE(data);
- DCM_CHECK_FALSE(_data->scan_thread_ready);
-
- async_queue_msg = (dcmMsg*) g_malloc0(sizeof(dcmMsg));
- if (async_queue_msg == NULL) {
- dcm_error("memory allocation failed");
- return FALSE;
- }
-
- async_queue_msg->msg_type = DCM_MSG_SCAN_READY;
-
- dcm_debug("scan thread ready : %p", _data->scan_thread_ready);
- dcm_debug("async_queue_msg : %d", async_queue_msg->msg_type);
-
- g_async_queue_push(_data->scan_thread_ready, (gpointer) async_queue_msg);
-
- dcm_debug_fleave();
-
- return FALSE;
-}
-
-gboolean dcm_scan_read_request(GIOChannel *src, GIOCondition condition, gpointer data)
-{
- int sock = -1;
- int client_sock = -1;
- dcmMsg recv_msg;
- int err = 0;
-
- DCM_CHECK_FALSE(data);
-
- /* Get socket fd from IO channel */
- sock = g_io_channel_unix_get_fd(src);
- if (sock < 0) {
- dcm_error("Invalid socket fd!");
- return TRUE;
- }
-
- /* Accept tcp client socket */
- err = dcm_ipc_accept_socket(sock, &client_sock);
- if (err != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to accept tcp socket! err: %d", err);
- return TRUE;
- }
-
- /* Receive message from tcp socket */
- err = dcm_ipc_receive_message(client_sock, &recv_msg);
- if (err != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to receive tcp msg! err: %d", err);
- goto DCM_SVC_SCAN_READ_THREAD_RECV_SOCKET_FAILED;
- }
-
- /* Process received message */
- err = __dcm_scan_receive_message(&recv_msg, data);
- if (err != MS_MEDIA_ERR_NONE) {
- dcm_error("Error ocurred when process received message: %d", err);
- goto DCM_SVC_SCAN_READ_THREAD_RECV_SOCKET_FAILED;
- }
-
-DCM_SVC_SCAN_READ_THREAD_RECV_SOCKET_FAILED:
- dcm_ipc_close_socket(client_sock);
-
- return TRUE;
-}
-
int dcm_scan_single(const char *file_path, uid_t uid, int *face_count)
{
int ret = MS_MEDIA_ERR_NONE;
*face_count = scan_item->face_count;
dcm_debug("*face_count is %d", *face_count);
+ DCM_SAFE_FREE(scan_item->media_uuid);
+ DCM_SAFE_FREE(scan_item->file_path);
+ DCM_SAFE_FREE(scan_item->storage_uuid);
DCM_SAFE_FREE(scan_item);
dcm_debug_fleave();
return ret;
}
-gboolean dcm_scan_thread(void *data)
-{
- int socket_fd = -1;
- GSource *source = NULL;
- GIOChannel *channel = NULL;
- GMainContext *context = NULL;
- GSource *scan_thread_ready_idle = NULL;
- dcm_scan_s *dcm_scan_data = NULL;
- int err = 0;
-
- DCM_CHECK_FALSE(data);
-
- dcm_scan_data = (dcm_scan_s *)calloc(1, sizeof(dcm_scan_s));
- if (dcm_scan_data == NULL) {
- dcm_error("Failed to create DCM scan data!");
- return FALSE;
- }
-
- /* Create TCP Socket to receive message from main thread */
- err = dcm_ipc_create_socket(&socket_fd, DCM_IPC_PORT_SCAN_RECV);
- if (err != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to create socket! err: %d", err);
- goto DCM_SVC_SCAN_CREATE_SCAN_THREAD_FAILED;
- }
- dcm_sec_warn("scan thread recv socket: %d", socket_fd);
-
- /* Init global variables */
- err = dcm_scan_init(dcm_scan_data);
- if (err != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to initialize scan thread global variable! err: %d", err);
- goto DCM_SVC_SCAN_CREATE_SCAN_THREAD_FAILED;
- }
-
- /* Create a new main context for scan thread */
- context = g_main_context_new();
- dcm_scan_data->main_context = context;
-
- /* Create a new main event loop */
- dcm_scan_data->main_loop = g_main_loop_new(context, FALSE);
-
- /* Create a new channel to watch TCP socket */
- channel = g_io_channel_unix_new(socket_fd);
- source = g_io_create_watch(channel, G_IO_IN);
-
- /* Attach channel to main context in scan thread */
- g_source_set_callback(source, (GSourceFunc) dcm_scan_read_request, (gpointer) dcm_scan_data, NULL);
- g_source_attach(source, context);
-
- /* Create a idle after scan thread is ready */
- scan_thread_ready_idle = g_idle_source_new();
- g_source_set_callback(scan_thread_ready_idle, dcm_scan_reply_for_ready, (gpointer) data, NULL);
- g_source_attach(scan_thread_ready_idle, context);
-
- /* Push main context to scan thread */
- g_main_context_push_thread_default(context);
-
- dcm_debug("********************************************");
- dcm_debug("*** DCM Service scan thread is running ***");
- dcm_debug("********************************************");
-
- /* Start to run main event loop for scan thread */
- g_main_loop_run(dcm_scan_data->main_loop);
-
- dcm_debug("*** DCM Service scan thread will be closed ***");
-
- /* Destroy IO channel */
- g_io_channel_shutdown(channel, FALSE, NULL);
- g_io_channel_unref(channel);
-
- /* Descrease the reference count of main loop of scan thread */
- g_main_loop_unref(dcm_scan_data->main_loop);
- dcm_scan_data->main_loop = NULL;
-
-DCM_SVC_SCAN_CREATE_SCAN_THREAD_FAILED:
- /* Close the TCP socket */
- dcm_ipc_close_socket(socket_fd);
-
- err = dcm_scan_finalize(dcm_scan_data);
- if (err != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to de-initialize scan thread global variable! err: %d", err);
-
- return FALSE;
-}
-
#include <tzplatform_config.h>
static char DCM_IPC_PATH[][100] = {
- {"media-server/dcm_ipc_scanthread.socket"},
{"media-server/media_ipc_dcmdaemon.socket"},
{"media-server/media_ipc_dcmcomm.socket"},
};
dcm_debug("Listening...");
/* change permission of local socket file */
- if (chmod(tzplatform_mkpath(TZ_SYS_RUN, DCM_IPC_PATH[port]), 0777) < 0)
+ if (chmod(tzplatform_mkpath(TZ_SYS_RUN, DCM_IPC_PATH[port]), 0770) < 0)
dcm_stderror("chmod failed");
*socket_fd = sock;
return MS_MEDIA_ERR_NONE;
}
-int dcm_ipc_send_complete(ms_dcm_msg_type_e msg_type, const unsigned int count, const char *msg, dcm_ipc_port_e port)
-{
- if (port < 0 || port >= DCM_IPC_PORT_MAX) {
- dcm_error("Invalid port! Stop sending message...");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- dcm_debug_fenter();
-
- dcm_debug("Send message type: %d", msg_type);
-
- int socket_fd = -1;
- struct sockaddr_un serv_addr;
- dcmMsg send_msg;
-
- /* Prepare send message */
- memset((void *)&send_msg, 0, sizeof(dcmMsg));
- send_msg.msg_type = msg_type;
- send_msg.result = count;
- if (msg != NULL) {
- send_msg.msg_size = strlen(msg);
- g_strlcpy(send_msg.msg, msg, DCM_IPC_MSG_MAX_SIZE);
- }
-
- /* If message size is larget than max_size, then message is invalid */
- if (send_msg.msg_size >= DCM_IPC_MSG_MAX_SIZE) {
- dcm_error("Message size is invalid!");
- return MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
- }
-
- /* Create a new TCP socket */
- if ((socket_fd = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
- dcm_stderror("socket failed");
- return MS_MEDIA_ERR_SOCKET_INTERNAL;
- }
-
- /* Set dcm thread socket address */
- memset(&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sun_family = AF_UNIX;
- DCM_SAFE_STRLCPY(serv_addr.sun_path, tzplatform_mkpath(TZ_SYS_RUN, DCM_IPC_PATH[port]), sizeof(serv_addr.sun_path));
-
- /* Connect to the socket */
- if (connect(socket_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
- dcm_stderror("connect error");
- close(socket_fd);
- return MS_MEDIA_ERR_SOCKET_CONN;
- }
-
- /* Send msg to the socket */
- if (send(socket_fd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) {
- dcm_stderror("send failed");
- close(socket_fd);
- return MS_MEDIA_ERR_SOCKET_SEND;
- }
-
- close(socket_fd);
-
- dcm_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
-
int dcm_ipc_close_socket(int socket_fd)
{
if (socket_fd < 0) {
#include <dcm_svc_ipc.h>
#include <dcm_svc_internal.h>
#include <dcm_svc_debug.h>
+#include <dcm_svc_detect_face.h>
-#define DCM_SVC_MAIN_THREAD_TIMEOUT_SEC 1
+GMainLoop *g_dcm_svc_mainloop;
-int _dcm_svc_create_timer(gpointer data);
-
-void __dcm_svc_main_loop_quit(gpointer data)
+gboolean __dcm_svc_kill_service()
{
- dcm_service_s *_data = (dcm_service_s *) data;
-
- if (_data->main_loop != NULL) {
- dcm_debug("Quit DCM thread main loop!");
- g_main_loop_quit(_data->main_loop);
+ if (g_dcm_svc_mainloop != NULL) {
+ dcm_error("[No-Error] Quit DCM Service");
+ g_main_loop_quit(g_dcm_svc_mainloop);
} else {
dcm_error("Invalid DCM thread main loop!");
}
-}
-
-gboolean __dcm_svc_kill_service(gpointer data)
-{
- dcm_service_s *_data = (dcm_service_s *) data;
-
- dcm_debug_fenter();
-
- DCM_CHECK_FALSE(data);
-
- if (_data->scan_thread_working == true) {
- dcm_warn("Scan thread is working! DO NOT quit main thread!");
- return TRUE;
- } else {
- dcm_warn("Quit dcm-svc main loop!");
- __dcm_svc_main_loop_quit(data);
- }
-
- dcm_debug_fleave();
return FALSE;
}
-int _dcm_svc_create_timer(gpointer data)
-{
- dcm_service_s *_data = (dcm_service_s *) data;
- GSource *quit_timer = NULL;
-
- dcm_debug_fenter();
-
- if (_data->kill_timer_source != NULL) {
- dcm_debug("Delete old quit timer!");
- g_source_destroy(_data->kill_timer_source);
- _data->kill_timer_source = NULL;
- }
-
- quit_timer = g_timeout_source_new_seconds(DCM_SVC_MAIN_THREAD_TIMEOUT_SEC);
- DCM_CHECK_VAL(quit_timer, MS_MEDIA_ERR_OUT_OF_MEMORY);
-
- g_source_set_callback(quit_timer, __dcm_svc_kill_service, (gpointer) data, NULL);
- g_source_attach(quit_timer, _data->main_context);
- _data->kill_timer_source = quit_timer;
-
- dcm_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _dcm_svc_wait_scan_thread(gpointer data)
-{
- dcm_service_s *_data = (dcm_service_s *)data;
- int ret = MS_MEDIA_ERR_NONE;
- dcmMsg *async_queue_msg = NULL;
-
- /* Wait until the scan thread is ready (timeout: 5 sec) */
- async_queue_msg = (dcmMsg *)g_async_queue_timeout_pop(_data->scan_thread_ready, 5000000);
- if (async_queue_msg == NULL) {
- dcm_error("Async queue timeout!");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- /* Check if scan thread is created */
- if (async_queue_msg->msg_type == DCM_MSG_SCAN_READY) {
- dcm_warn("DCM scan thread is ready!");
- g_async_queue_unref(_data->scan_thread_ready);
- _data->scan_thread_ready = NULL;
- } else {
- dcm_error("Invalid async queue message!");
- ret = MS_MEDIA_ERR_INTERNAL;
- }
-
- /* Free the received ipc message */
- DCM_SAFE_FREE(async_queue_msg);
-
- return ret;
-}
-
-static int _dcm_svc_create_scan_thread(gpointer data)
-{
- dcm_service_s *_data = (dcm_service_s *)data;
- int ret = MS_MEDIA_ERR_NONE;
-
- dcm_debug_fenter();
-
- /* Create a new async queue to wait util scan thread is created */
- _data->scan_thread_ready = g_async_queue_new();
- if (_data->scan_thread_ready == NULL) {
- dcm_error("Failed to create async queue!");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- /* Create the scan thread */
- _data->scan_thread = g_thread_new("dcm_scan_thread", (GThreadFunc) dcm_scan_thread, (gpointer) data);
- if (_data->scan_thread == NULL) {
- dcm_error("Failed to create scan thread!");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- ret = _dcm_svc_wait_scan_thread(data);
- /* Wait until scan thread is ready */
- if (ret != MS_MEDIA_ERR_NONE) {
- dcm_error("Failed to wait for scan thread to be ready! err: %d", ret);
- return ret;
- }
-
- dcm_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static void dcm_service_start(gpointer data)
-{
- if (_dcm_svc_create_scan_thread(data) != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to create scan thread! Exit main thread...");
-
- /* Send ready response to dcm launcher */
- if (dcm_ipc_send_message(DCM_MSG_SERVER_READY, 0, NULL, DCM_IPC_PORT_MS_RECV) != MS_MEDIA_ERR_NONE)
- dcm_error("Failed to send ready message");
-}
-
-static void dcm_service_finish(gpointer data)
-{
- dcm_service_s *_data = (dcm_service_s *)data;
- DCM_SAFE_FREE(_data);
-}
-
gboolean dcm_service_recieve_request(GIOChannel *src, GIOCondition condition, gpointer data)
{
dcmMsg recv_msg;
int client_sock = -1;
int ret = 0;
int face_count = 0;;
- dcm_service_s *_data = (dcm_service_s *)data;
memset((void *)&recv_msg, 0, sizeof(recv_msg));
dcm_sec_info("Received uid : [%d]", recv_msg.uid);
dcm_sec_info("Received msg : [%s]", recv_msg.msg);
- if (recv_msg.msg_type == DCM_MSG_SCAN_TERMINATED) {
- dcm_debug("Scan terminated!");
- _data->scan_thread_working = false;
- _dcm_svc_create_timer(data);
- } else if (recv_msg.msg_type == DCM_MSG_SCAN_COMPLETED) {
- dcm_debug("Scan completed!");
- ret = dcm_ipc_send_client_message(-1, DCM_MSG_EXTRACT_ALL_DONE, recv_msg.result, recv_msg.msg, DCM_IPC_PORT_MS_RECV);
- } else if (recv_msg.msg_type == DCM_MSG_REQUEST_KILL_SERVER) {
- dcm_warn("Quit dcm-svc main loop!");
- ret = dcm_ipc_send_message(DCM_MSG_REQUEST_KILL_SERVER, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_SCAN_RECV);
- } else if (recv_msg.msg_type == DCM_MSG_REQUEST_ALL_MEDIA) {
- ret = dcm_ipc_send_message(DCM_MSG_REQUEST_ALL_MEDIA, recv_msg.uid, NULL, DCM_IPC_PORT_SCAN_RECV);
- if (ret == MS_MEDIA_ERR_NONE)
- ret = dcm_ipc_send_client_message(client_sock, DCM_MSG_REQUEST_ALL_MEDIA, recv_msg.uid, NULL, DCM_IPC_PORT_DCM_RECV);
+ if (recv_msg.msg_type == DCM_MSG_REQUEST_KILL_SERVER) {
+ dcm_warn("Receive DCM_MSG_REQUEST_KILL_SERVER");
+ __dcm_svc_kill_service();
+
} else if (recv_msg.msg_type == DCM_MSG_REQUEST_MEDIA) {
dcm_debug("Scan single");
ret = dcm_scan_single(recv_msg.msg, recv_msg.uid, &face_count);
if (ret != MS_MEDIA_ERR_NONE)
dcm_error("Failed to dcm_ipc_send_client_message! err: %d", ret);
}
- _dcm_svc_create_timer(data);
+
} else {
dcm_debug("createDcmSvcReadSocket, invalid message(%d).", recv_msg.msg_type);
}
GIOChannel *channel = NULL;
GMainContext *context = NULL;
/* threads related */
- dcm_service_s *dcm_svc_data = NULL;
-
- dcm_svc_data = (dcm_service_s *)calloc(1, sizeof(dcm_service_s));
- if (dcm_svc_data == NULL) {
- dcm_error("Failed to create DCM Service data!");
- return -1;
- }
/* Create and bind new socket to main_loop */
if (dcm_ipc_create_socket(&sockfd, DCM_IPC_PORT_DCM_RECV) != MS_MEDIA_ERR_NONE) {
dcm_error("Failed to create socket");
- dcm_service_finish(dcm_svc_data);
return -1;
}
- dcm_svc_data->main_loop = g_main_loop_new(context, FALSE);
- context = g_main_loop_get_context(dcm_svc_data->main_loop);
- dcm_svc_data->main_context = context;
+ g_dcm_svc_mainloop = g_main_loop_new(context, FALSE);
+ context = g_main_loop_get_context(g_dcm_svc_mainloop);
/* Create new channel to watch new socket for main_loop */
channel = g_io_channel_unix_new(sockfd);
source = g_io_create_watch(channel, G_IO_IN);
/* Set callback to be called when socket is readable */
- g_source_set_callback(source, (GSourceFunc)dcm_service_recieve_request, NULL, (gpointer) dcm_svc_data);
+ g_source_set_callback(source, (GSourceFunc)dcm_service_recieve_request, NULL, NULL);
g_source_attach(source, context);
- dcm_service_start(dcm_svc_data);
+ if (dcm_face_detect_initialize() != MS_MEDIA_ERR_NONE)
+ dcm_error("Failed to dcm_face_detect_initialize");
+
+ /* Send ready response to dcm launcher */
+ if (dcm_ipc_send_message(DCM_MSG_SERVER_READY, 0, NULL, DCM_IPC_PORT_MS_RECV) != MS_MEDIA_ERR_NONE)
+ dcm_error("Failed to send ready message");
- dcm_debug("********************************************");
- dcm_debug("****** DCM Service is running ******");
- dcm_debug("********************************************");
+ dcm_info("DCM Service is running");
- g_main_loop_run(dcm_svc_data->main_loop);
+ g_main_loop_run(g_dcm_svc_mainloop);
- dcm_debug("DCM Service is shutting down...");
+ dcm_info("DCM Service is shutting down");
g_io_channel_shutdown(channel, FALSE, NULL);
g_io_channel_unref(channel);
dcm_ipc_close_socket(sockfd);
- g_main_loop_unref(dcm_svc_data->main_loop);
+ g_main_loop_unref(g_dcm_svc_mainloop);
- dcm_service_finish(dcm_svc_data);
+ dcm_face_detect_finalize();
return 0;
}