Enable DCM on-demand 44/75644/1 accepted/tizen/common/20160627.191509 accepted/tizen/common/20160627.192117 accepted/tizen/ivi/20160627.092436 accepted/tizen/mobile/20160627.091841 accepted/tizen/tv/20160627.092032 accepted/tizen/wearable/20160627.092215 submit/tizen/20160623.063229 submit/tizen/20160627.070732
authorJiyong Min <jiyong.min@samsung.com>
Tue, 21 Jun 2016 01:00:57 +0000 (10:00 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Tue, 21 Jun 2016 01:01:34 +0000 (10:01 +0900)
Change-Id: I4d385fee807fc695ea3179cbe20c58036dc4274d
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
CMakeLists.txt
include/DcmIpcUtils.h
include/DcmTypes.h
packaging/dcm-service.spec
src/DcmFaceUtils.cpp
src/DcmIpcUtils.cpp
src/DcmScanSvc.cpp
svc/DcmMainSvc.cpp

index 205a3905c66bb35181f7902f3bb1afb984a87149..4dc49d6065733ba2188b72fa6cf44fc3c9ca1deb 100755 (executable)
@@ -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})
 
index 34d159695bce5d9c55ca0494b13363304547c45e..62a63820c72a28ba00616747fb2897d5de8630c8 100755 (executable)
@@ -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);
 }
 
index 557971e801d65703f7b993e32178633f10ad9cdb..c92a84188a8d0ad9c61c3a369ed23a1fb3f879a3 100755 (executable)
@@ -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;
 
index 5c3863314fca0882b1577282453d87cb718e5f6e..a5f39f303b5943ef62eb0aec28439b7c020b3320 100755 (executable)
@@ -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
index ca08c91eb2f38dcec822f87294dc7716647201fb..6d1764fdb5e1acabc38b3cb6dbd03dc71ed5ca73 100755 (executable)
@@ -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);
index 80b1939cb6d6dc1a01fd46855c7f78e490e4e6ac..ad5f3953768da5466715e68908dfb97711f3dd3e 100755 (executable)
@@ -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);
index 0fffa47325589bdfd3fd4d4491f8d91a96c4e278..5818e8500bf2db7f14cb94ef50c39c75c758b3a1 100755 (executable)
@@ -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;
        }
index 775d43d511f007adfdef8d1cf6d60bfc608a3437..eaf0d550661f2805be2f25c4c0cc720cd033e4ad 100755 (executable)
@@ -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) {