From: Jiyong Min Date: Tue, 21 Jun 2016 01:00:57 +0000 (+0900) Subject: Enable DCM on-demand X-Git-Tag: submit/tizen/20160623.063229^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94251874877e911c7d54bc04e40e944e22b76b26;p=platform%2Fcore%2Fmultimedia%2Fdcm-service.git Enable DCM on-demand Change-Id: I4d385fee807fc695ea3179cbe20c58036dc4274d Signed-off-by: Jiyong Min --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 205a390..4dc49d6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ CONFIGURE_FILE(dcm-service.pc.in dcm-service.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/dcm-service.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) ADD_SUBDIRECTORY(svc) -ADD_SUBDIRECTORY(test) +#ADD_SUBDIRECTORY(test) LINK_DIRECTORIES(${LIB_INSTALL_DIR}) diff --git a/include/DcmIpcUtils.h b/include/DcmIpcUtils.h index 34d1596..62a6382 100755 --- a/include/DcmIpcUtils.h +++ b/include/DcmIpcUtils.h @@ -25,7 +25,8 @@ namespace DcmIpcUtils { int acceptSocket(int serv_sock, int *client_sock); int receiveSocketMsg(int client_sock, DcmIpcMsg *recv_msg); int sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *msg, DcmIpcPortType port); - int sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, uid_t uid, const char *msg, DcmIpcPortType port); + int sendCompleteMsg(DcmIpcMsgType msg_type, const unsigned int count, const char *msg, DcmIpcPortType port); + int sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, unsigned int result, const char *msg, DcmIpcPortType port); int closeSocket(int socket_fd); } diff --git a/include/DcmTypes.h b/include/DcmTypes.h index 557971e..c92a841 100755 --- a/include/DcmTypes.h +++ b/include/DcmTypes.h @@ -81,6 +81,7 @@ typedef struct { uid_t uid; size_t msg_size; /*this is size of message below and this does not include the terminationg null byte ('\0'). */ char msg[DCM_IPC_MSG_MAX_SIZE]; + int result; } DcmIpcMsg; typedef enum { @@ -98,6 +99,7 @@ typedef struct { int image_height; int image_orientation; char *mime_type; + int face_count; DcmScanItemType scan_item_type; } DcmScanItem; diff --git a/packaging/dcm-service.spec b/packaging/dcm-service.spec index 5c38633..a5f39f3 100755 --- a/packaging/dcm-service.spec +++ b/packaging/dcm-service.spec @@ -1,6 +1,6 @@ Name: dcm-service Summary: A media DCM(Digital Contents Management) Service -Version: 0.0.9 +Version: 0.0.10 Release: 0 Group: Multimedia/Service License: Apache-2.0 diff --git a/src/DcmFaceUtils.cpp b/src/DcmFaceUtils.cpp index ca08c91..6d1764f 100755 --- a/src/DcmFaceUtils.cpp +++ b/src/DcmFaceUtils.cpp @@ -122,8 +122,10 @@ int DcmFaceUtils::runFaceRecognizeProcess(DcmScanItem *scan_item, DcmImageInfo * dcm_warn("detected face count: %d", face_info->count); if (face_info->count <= 0) { + scan_item->face_count = 0; goto DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED; } + scan_item->face_count = face_info->count; /* Compute scale factor between decode size and original size */ scale_factor = DcmFaceApi::caculateScaleFactor(image_info); diff --git a/src/DcmIpcUtils.cpp b/src/DcmIpcUtils.cpp index 80b1939..ad5f395 100755 --- a/src/DcmIpcUtils.cpp +++ b/src/DcmIpcUtils.cpp @@ -134,7 +134,7 @@ int DcmIpcUtils::createSocket(int *socket_fd, DcmIpcPortType port) return DCM_SUCCESS; } -int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, uid_t uid, const char *msg, DcmIpcPortType port) +int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, unsigned int result, const char *msg, DcmIpcPortType port) { if (port < 0 || port >= DCM_IPC_PORT_MAX) { dcm_error("Invalid port! Stop sending message..."); @@ -177,7 +177,7 @@ int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, uid_ /* Prepare send message */ memset((void *)&send_msg, 0, sizeof(DcmIpcMsg)); send_msg.msg_type = msg_type; - send_msg.uid = uid; + send_msg.result = result; if (msg != NULL) { send_msg.msg_size = strlen(msg); strncpy(send_msg.msg, msg, send_msg.msg_size); @@ -260,6 +260,64 @@ int DcmIpcUtils::sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *ms return DCM_SUCCESS; } +int DcmIpcUtils::sendCompleteMsg(DcmIpcMsgType msg_type, const unsigned int count, const char *msg, DcmIpcPortType port) +{ + if (port < 0 || port >= DCM_IPC_PORT_MAX) { + dcm_error("Invalid port! Stop sending message..."); + return DCM_ERROR_INVALID_PARAMETER; + } + dcm_debug("Send message type: %d", msg_type); + + int socket_fd = -1; + struct sockaddr_un serv_addr; + //struct timeval tv_timeout = { 10, 0 }; /* timeout: 10 seconds */ + DcmIpcMsg send_msg; + + /* Prepare send message */ + memset((void *)&send_msg, 0, sizeof(DcmIpcMsg)); + send_msg.msg_type = msg_type; + send_msg.result = count; + if (msg != NULL) { + send_msg.msg_size = strlen(msg); + strncpy(send_msg.msg, msg, send_msg.msg_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 DCM_ERROR_NETWORK; + } + + /* Create a new TCP socket */ + if ((socket_fd = socket(PF_FILE, SOCK_STREAM, 0)) < 0) { + dcm_stderror("socket failed"); + return DCM_ERROR_NETWORK; + } + + /* Set dcm thread socket address */ + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sun_family = AF_UNIX; + strncpy(serv_addr.sun_path, DCM_IPC_PATH[port], sizeof(serv_addr.sun_path) - 1); + + /* Connect to the socket */ + if (connect(socket_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { + dcm_stderror("connect error"); + close(socket_fd); + return DCM_ERROR_NETWORK; + } + + /* 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 DCM_ERROR_NETWORK; + } + + close(socket_fd); + return DCM_SUCCESS; +} + + int DcmIpcUtils::closeSocket(int socket_fd) { close(socket_fd); diff --git a/src/DcmScanSvc.cpp b/src/DcmScanSvc.cpp index 0fffa47..5818e85 100755 --- a/src/DcmScanSvc.cpp +++ b/src/DcmScanSvc.cpp @@ -66,7 +66,7 @@ public: int clearSingleItemList(); int initialize(); int finalize(); - int sendCompletedMsg(const char *msg, DcmIpcPortType port); + int sendCompletedMsg(const char *msg, const unsigned int count, DcmIpcPortType port); int sendTerminatedMsg(); int getScanStatus(DcmScanItem *scan_item, bool *media_scanned); int runScanProcess(DcmScanItem *scan_item); @@ -275,11 +275,11 @@ int DcmScanSvc::finalize() return DCM_SUCCESS; } -int DcmScanSvc::sendCompletedMsg(const char *msg, DcmIpcPortType port) +int DcmScanSvc::sendCompletedMsg(const char *msg, const unsigned int count, DcmIpcPortType port) { if ((scan_all_item_list == NULL) && (scan_single_item_list == NULL)) { dcm_debug("Send completed message"); - DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SCAN_COMPLETED, 0, msg, port); + DcmIpcUtils::sendCompleteMsg(DCM_IPC_MSG_SCAN_COMPLETED, count, msg, port); } else { if (scan_all_item_list) dcm_warn("scan_all_item_list"); @@ -432,7 +432,7 @@ int DcmScanSvc::ScanAllItems() dcm_debug("No items to Scan. Scan operation completed!!!"); clearAllItemList(); /* Send scan complete message to main thread (if all scan operations are finished) */ - sendCompletedMsg( NULL, DCM_IPC_PORT_DCM_RECV); + sendCompletedMsg( NULL, 0, DCM_IPC_PORT_DCM_RECV); ret = dcmDBUtils->_dcm_svc_db_disconnect(); if (ret != DCM_SUCCESS) { dcm_error("Failed to disconnect db! err: %d", ret); @@ -465,7 +465,7 @@ int DcmScanSvc::ScanSingleItem(const char *file_path) dcm_debug("No items to Scan. Scan operation completed!!!"); clearSingleItemList(); /* Send scan complete message to main thread (if all scan operations are finished) */ - sendCompletedMsg( file_path/*ret*/, DCM_IPC_PORT_DCM_RECV); + sendCompletedMsg( file_path/*ret*/, 0, DCM_IPC_PORT_DCM_RECV); return DCM_SUCCESS; } @@ -490,6 +490,8 @@ int DcmScanSvc::ScanSingleItem(const char *file_path) (scan_single_curr_index)++; } + sendCompletedMsg( file_path/*ret*/, scan_item->face_count, DCM_IPC_PORT_DCM_RECV); + clearSingleItemList(); dcm_debug_fleave(); @@ -686,7 +688,7 @@ gboolean DcmScanCallback::runScanThreadIdle(gpointer data) } scanSvc->clearAllItemList(); /* Send scan complete message to main thread (if all scan operations are finished) */ - scanSvc->sendCompletedMsg( NULL, DCM_IPC_PORT_DCM_RECV); + scanSvc->sendCompletedMsg( NULL, 0, DCM_IPC_PORT_DCM_RECV); dcm_debug_fleave(); return FALSE; } diff --git a/svc/DcmMainSvc.cpp b/svc/DcmMainSvc.cpp index 775d43d..eaf0d55 100755 --- a/svc/DcmMainSvc.cpp +++ b/svc/DcmMainSvc.cpp @@ -58,6 +58,11 @@ DcmMainSvc* DcmMainSvc::getInstance(void) void DcmMainSvc::dcmServiceStartjobs(void) { + if (createScanThread() != DCM_SUCCESS) { + dcm_error("Failed to create scan thread! Exit main thread..."); + return TRUE; + } + /* Send ready response to dcm launcher */ if (DcmIpcUtils::sendClientSocketMsg(-1, DCM_IPC_MSG_SERVICE_READY, 0, NULL, DCM_IPC_PORT_MS_RECV) != DCM_SUCCESS) { dcm_error("Failed to send ready message"); @@ -179,7 +184,7 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp dcmSvc->createQuitTimerMainLoop(); } else if (recv_msg.msg_type == DCM_IPC_MSG_SCAN_COMPLETED) { dcm_debug("Scan completed!"); - ret = DcmIpcUtils::sendClientSocketMsg(-1, DCM_IPC_MSG_SERVICE_COMPLETED, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_MS_RECV); + ret = DcmIpcUtils::sendClientSocketMsg(-1, DCM_IPC_MSG_SERVICE_COMPLETED, recv_msg.result, recv_msg.msg, DCM_IPC_PORT_MS_RECV); } else if (recv_msg.msg_type == DCM_IPC_MSG_KILL_SERVICE) { dcm_warn("Quit dcm-svc main loop!"); ret = DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_KILL_SERVICE, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_SCAN_RECV); @@ -190,11 +195,11 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp } } else if (recv_msg.msg_type == DCM_IPC_MSG_SCAN_SINGLE) { ret = DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SCAN_SINGLE, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_SCAN_RECV); - if (ret == DCM_SUCCESS) { +/* if (ret == DCM_SUCCESS) { ret = DcmIpcUtils::sendClientSocketMsg(client_sock, DCM_IPC_MSG_SCAN_SINGLE, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_DCM_RECV); - } + }*/ } else { - dcm_debug("createDcmSvcReadSocket, invalid message."); + dcm_debug("createDcmSvcReadSocket, invalid message(%d).", recv_msg.msg_type); } if (DcmIpcUtils::closeSocket(client_sock) < 0) {