Fix not to be termiated after finish and etc.. 38/58638/2 accepted/tizen/ivi/20160218.023800 accepted/tizen/mobile/20160211.083311 accepted/tizen/tv/20160211.083329 accepted/tizen/wearable/20160211.083351 submit/tizen/20160211.044444 submit/tizen_common/20160218.142243 submit/tizen_ivi/20160217.000000 submit/tizen_ivi/20160217.000003
authorJi Yong Min <jiyong.min@samsung.com>
Tue, 2 Feb 2016 10:43:09 +0000 (19:43 +0900)
committerJi Yong Min <jiyong.min@samsung.com>
Wed, 3 Feb 2016 01:45:26 +0000 (10:45 +0900)
- Code optimization and fix known issues

Change-Id: I3a464ee844d1aa228f51dce430c97df11ae45f0b
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
14 files changed:
CMakeLists.txt
include/DcmDebugUtils.h
include/DcmIpcUtils.h
include/DcmTypes.h
libdcm-face/dcm-face.c
libdcm-face/dcm-face_mediavision.c
libdcm-face/dcm-face_priv.h
packaging/dcm-service.spec
src/DcmDbUtils.cpp
src/DcmIpcUtils.cpp
src/DcmScanSvc.cpp
svc/DcmMainSvc.cpp
test/CMakeLists.txt [new file with mode: 0755]
test/dcm-test.c [new file with mode: 0755]

index 650ed1fbcb2112be0794055c13a8135b4fec5304..867d7c5f29d381f31f1a9372fd4b4219538747af 100755 (executable)
@@ -73,6 +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)
 
 LINK_DIRECTORIES(${LIB_INSTALL_DIR})
 
index 3cfe0a1bab419b1938e73223b83e3309b3f220f8..9e7d29c932bf21319fd8aa2fcdb6c585ed4fe821 100755 (executable)
                        } \
                } while (0)
 
+#define ERR_BUF_LENGHT 256
+#define dcm_stderror(fmt) do { \
+                                       char dcm_stderror_buf[ERR_BUF_LENGHT] = {0, }; \
+                                       strerror_r(errno, dcm_stderror_buf, ERR_BUF_LENGHT); \
+                                       dcm_error(fmt" : standard error= [%s]", dcm_stderror_buf); \
+                               } while (0)
+
 #define DCM_CHECK_VAL(expr, val)               dcm_retvm_if(!(expr), val, "Invalid parameter, return ERROR code!")
 #define DCM_CHECK_NULL(expr)                   dcm_retvm_if(!(expr), NULL, "Invalid parameter, return NULL!")
 #define DCM_CHECK_FALSE(expr)                  dcm_retvm_if(!(expr), FALSE, "Invalid parameter, return FALSE!")
index 0b37751f53e3525e72ff3cb80d6e20b824cc19c7..34d159695bce5d9c55ca0494b13363304547c45e 100755 (executable)
@@ -25,12 +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 closeSocket(int socket_fd);
-       int createUDPSocket(int *socket_fd);
-       int receiveUDPSocketMsg(int socket_fd, DcmIpcMsg *recv_msg);
-       int sendUDPSocketMsg(DcmIpcMsgType msg_type, const char *msg);
-       int closeUDPSocket(int socket_fd);
-       int sendFaceMsg(const char *media_uuid);
 }
 
 #endif /* _DCM_SVC_IPC_H_ */
index 32c7d9712adb052007610b9d66b698159a115f4c..3cc3364234d8b698b603819d400d59cb5131c822 100755 (executable)
@@ -55,27 +55,29 @@ typedef enum {
 } DcmErrorType;
 
 typedef enum {
-       DCM_IPC_MSG_NONE,
-       DCM_IPC_MSG_SERVICE_READY,
-       DCM_IPC_MSG_SERVICE_TERMINATED,
+       DCM_IPC_MSG_SCAN_SINGLE,
+       DCM_IPC_MSG_SCAN_ALL,
+       DCM_IPC_MSG_CANCEL,
+       DCM_IPC_MSG_CANCEL_ALL,
        DCM_IPC_MSG_KILL_SERVICE,
        DCM_IPC_MSG_SCAN_READY,
-       DCM_IPC_MSG_SCAN_ALL,
-       DCM_IPC_MSG_SCAN_SINGLE,
        DCM_IPC_MSG_SCAN_COMPLETED,
        DCM_IPC_MSG_SCAN_TERMINATED,
+       DCM_IPC_MSG_SERVICE_READY = 20,
+       DCM_IPC_MSG_SERVICE_COMPLETED,
        DCM_IPC_MSG_MAX,
 } DcmIpcMsgType;
 
 typedef enum {
-       DCM_IPC_PORT_SCAN_RECV,
+       DCM_IPC_PORT_SCAN_RECV = 0,
        DCM_IPC_PORT_DCM_RECV,
-       DCM_IPC_PORT_THUMB_RECV,
+       DCM_IPC_PORT_MS_RECV,
        DCM_IPC_PORT_MAX,
 } DcmIpcPortType;
 
 typedef struct {
        DcmIpcMsgType msg_type;
+       int pid;
        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];
index 729fcbb6e23b62322a070cdb388df54bf49e675f..39b22f42ac60173007c29c382e9d72abd8cb16c3 100755 (executable)
@@ -19,6 +19,7 @@
 
 #include "dcm-face.h"
 #include "dcm-face_priv.h"
+#include "dcm-face-debug.h"
 
 
 #define FACE_MAGIC_VALID       (0xFF993311)
index c181d47c5f5ec25b4b0dbc31941b711ca386ac9b..153829df9eb62837c0989146e8bdd754b58cd79f 100755 (executable)
@@ -23,6 +23,9 @@
 #include "dcm-face.h"
 #include "dcm-face_priv.h"
 
+#include <stdio.h>
+#include <stdlib.h>
+
 typedef struct media_vision_h {
        mv_engine_config_h cfg;
        mv_source_h source;
@@ -191,6 +194,7 @@ int _face_detect_faces(__in dcm_face_h handle, __out face_rect_s *face_rect[], _
        dcm_retvm_if(count == NULL, FACE_ERROR_OUT_OF_MEMORY, "invalid count");
 
        mv_handle *_fengine = (mv_handle *)handle->fengine;
+       memset(&result, 0x00, sizeof(result));
 
        __convert_to_mv_colorspace_e(handle->image_info->colorspace, &colorspace);
 
@@ -203,8 +207,10 @@ int _face_detect_faces(__in dcm_face_h handle, __out face_rect_s *face_rect[], _
        }
 
        err = mv_face_detect(_fengine->source, _fengine->cfg, (mv_face_detected_cb)__face_detected_cb, &result);
-
-/*     wait_for_async(); */
+       if (err != MEDIA_VISION_ERROR_NONE) {
+               dcm_error("Fail to mv_face_detect");
+               return __convert_to_mv_error_e(err);
+       }
 
        if (result.error == FACE_ERROR_NONE) {
                *face_rect = result.face_rect;
index 797984dafef87f959d3dd02fb463bb97d99e8345..3dcdefd2ab16d2a2c73062bc70f561d86728f76c 100755 (executable)
@@ -18,7 +18,6 @@
 
 #include <stdlib.h>
 #include <glib.h>
-#include "dcm-face-debug.h"
 
 #undef __in
 #define __in
index a3dce9ca71ce14d15fac9dc1cc8732aa7d74b8fd..7a6491747910cacdc9f3d8c00ccdceff56dd3928 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       dcm-service
 Summary:    A media DCM(Digital Contents Management) Service
-Version:    0.0.5
+Version:    0.0.6
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
@@ -59,7 +59,7 @@ cp -rf %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 %{buildroot}/%{_datadir}/
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
 %{_libdir}/*.so*
-%{_bindir}/dcm-svc
+%{_bindir}/*
 %{_datadir}/license/%{name}
 
 %files devel
index fa3a2ecaa3698ff8b7aa0efe94cc844005d1e37e..41814d93d664ff8efa0322667ecb473ac31ce0b6 100755 (executable)
@@ -234,18 +234,20 @@ int DcmDbUtils::_dcm_svc_db_disconnect(void)
 
        dcm_warn("media db handle: %p", db_handle);
 
-       err = media_db_disconnect(db_handle);
-       if (err != MS_MEDIA_ERR_NONE) {
-               dcm_error("media_db_disconnect failed: %d", err);
-               db_handle = NULL;
-               return err;
+       if (db_handle != NULL) {
+               err = media_db_disconnect(db_handle);
+               if (err != MS_MEDIA_ERR_NONE) {
+                       dcm_error("media_db_disconnect failed: %d", err);
+                       db_handle = NULL;
+                       return err;
+               }
        }
 
        db_handle = NULL;
 
        dcm_debug_fleave();
 
-       return err;
+       return MS_MEDIA_ERR_NONE;
 }
 
 
index 12fa2488b2fef62153a4828e064b9dcb44f4b20d..0eb3bd4a5798dde7c20e367de0c682e5a32d3da5 100755 (executable)
 #include <DcmTypes.h>
 #include <DcmDebugUtils.h>
 
-static char DCM_IPC_PATH[][100] =
-                       {"/var/run/media-server/dcm_ipc_scanthread_recv",
-                        "/var/run/media-server/dcm_ipc_thumbserver_comm_recv",
-                        "/var/run/media-server/media_ipc_thumbdcm_dcmrecv"};
+static char DCM_IPC_PATH[][100] = {
+                       {"/var/run/media-server/dcm_ipc_scanthread.socket"},
+                       {"/var/run/media-server/media_ipc_dcmdaemon.socket"},
+                       {"/var/run/media-server/media_ipc_dcmcomm.socket"},
+};
 
 int DcmIpcUtils::receiveSocketMsg(int client_sock, DcmIpcMsg *recv_msg)
 {
@@ -47,11 +48,11 @@ int DcmIpcUtils::receiveSocketMsg(int client_sock, DcmIpcMsg *recv_msg)
                        dcm_error("Timeout. Can't try any more");
                        return DCM_ERROR_IPC;
                } else {
-                       dcm_error("recv failed : %s", strerror(errno));
+                       dcm_stderror("recv failed");
                        return DCM_ERROR_NETWORK;
                }
        }
-       dcm_sec_debug("[receive msg] type: %d, uid: %d, msg: %s, msg_size: %d", recv_msg->msg_type, recv_msg->uid, recv_msg->msg, recv_msg->msg_size);
+       dcm_sec_debug("[receive msg] type: %d, pid: %d, uid: %d, msg: %s, msg_size: %d", recv_msg->msg_type, recv_msg->pid, recv_msg->uid, (recv_msg->msg)?recv_msg->msg:"NULL", recv_msg->msg_size);
 
        if (!(recv_msg->msg_type >= 0 && recv_msg->msg_type < DCM_IPC_MSG_MAX)) {
                dcm_error("IPC message is wrong!");
@@ -69,7 +70,7 @@ int DcmIpcUtils::acceptSocket(int serv_sock, int* client_sock)
        socklen_t client_addr_len = sizeof(client_addr);
 
        if ((sockfd = accept(serv_sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
-               dcm_error("accept failed : %s", strerror(errno));
+               dcm_stderror("accept failed");
                *client_sock = -1;
                return DCM_ERROR_NETWORK;
        }
@@ -89,7 +90,7 @@ int DcmIpcUtils::createSocket(int *socket_fd, DcmIpcPortType port)
 
        /* Create a new TCP socket */
        if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
-               dcm_error("socket failed: %s", strerror(errno));
+               dcm_stderror("socket failed");
                return DCM_ERROR_NETWORK;
        }
 
@@ -100,7 +101,7 @@ int DcmIpcUtils::createSocket(int *socket_fd, DcmIpcPortType port)
        strncpy(serv_addr.sun_path, DCM_IPC_PATH[port], sizeof(serv_addr.sun_path) - 1);
 
        /* Bind socket to local address */
-       for (i = 0; i < 20; i++) {
+       for (i = 0; i < 100; i++) {
                if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == 0) {
                        bind_success = true;
                        break;
@@ -110,7 +111,7 @@ int DcmIpcUtils::createSocket(int *socket_fd, DcmIpcPortType port)
        }
 
        if (bind_success == false) {
-               dcm_error("bind failed : %s %d_", strerror(errno), errno);
+               dcm_stderror("bind failed");
                close(sock);
                return DCM_ERROR_NETWORK;
        }
@@ -118,21 +119,91 @@ int DcmIpcUtils::createSocket(int *socket_fd, DcmIpcPortType port)
 
        /* Listenint */
        if (listen(sock, SOMAXCONN) < 0) {
-               dcm_error("listen failed : %s", strerror(errno));
+               dcm_stderror("listen failed");
                close(sock);
                return DCM_ERROR_NETWORK;
        }
        dcm_debug("Listening...");
 
        /* change permission of local socket file */
-       if (chmod(DCM_IPC_PATH[port], 0660) < 0)
-               dcm_error("chmod failed [%s]", strerror(errno));
+       if (chmod(DCM_IPC_PATH[port], 0777) < 0)
+               dcm_stderror("chmod failed");
 
        *socket_fd = sock;
 
        return DCM_SUCCESS;
 }
 
+int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, uid_t uid, 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);
+
+       DcmIpcMsg send_msg;
+       int err = 0;
+       int sock = -1;
+
+       if (socket_fd < 0) {
+               struct sockaddr_un serv_addr;
+               struct timeval tv_timeout = { 10, 0 };
+               
+               if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
+                       dcm_stderror("socket failed");
+                       return DCM_ERROR_NETWORK;
+               }
+
+               if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
+                       dcm_stderror("setsockopt failed");
+                       close(sock);
+                       return DCM_ERROR_NETWORK;
+               }
+
+               memset(&serv_addr, 0, sizeof(serv_addr));
+               serv_addr.sun_family = AF_UNIX;
+               strncpy(serv_addr.sun_path, DCM_IPC_PATH[port], sizeof(DCM_IPC_PATH[port]));
+               
+               /* Connecting to the thumbnail server */
+               if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+                       dcm_stderror("connect");
+                       close(sock);
+                       return DCM_ERROR_NETWORK;
+               }
+       } else {
+               sock = socket_fd;
+       }
+
+       /* Prepare send message */
+       memset((void *)&send_msg, 0, sizeof(DcmIpcMsg));
+       send_msg.msg_type = msg_type;
+       send_msg.uid = uid;
+       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!");
+               close(sock);
+               return DCM_ERROR_NETWORK;
+       }
+
+       /* Send msg to the socket */
+       if (send(sock, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) {
+               dcm_stderror("send failed");
+               close(sock);
+               return DCM_ERROR_NETWORK;
+       }
+
+       dcm_debug("Sent message type: %d", msg_type);
+
+       close(sock);
+       return DCM_SUCCESS;
+}
+
 int DcmIpcUtils::sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *msg, DcmIpcPortType port)
 {
        if (port < 0 || port >= DCM_IPC_PORT_MAX) {
@@ -163,7 +234,7 @@ int DcmIpcUtils::sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *ms
 
        /* Create a new TCP socket */
        if ((socket_fd = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
-               dcm_error("socket failed: %s", strerror(errno));
+               dcm_stderror("socket failed");
                return DCM_ERROR_NETWORK;
        }
 
@@ -174,14 +245,14 @@ int DcmIpcUtils::sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *ms
 
        /* Connect to the socket */
        if (connect(socket_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
-               dcm_error("connect error : %s", strerror(errno));
+               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_error("send failed : %s", strerror(errno));
+               dcm_stderror("send failed");
                close(socket_fd);
                return DCM_ERROR_NETWORK;
        }
@@ -195,53 +266,3 @@ int DcmIpcUtils::closeSocket(int socket_fd)
        close(socket_fd);
        return DCM_SUCCESS;
 }
-
-#define DCM_SVC_FACE_ASYNC_MEDIA_UUID_LENGTH 64
-#define DCM_SVC_FACE_ASYNC_UDP_SEND_PORT 1551
-#define DCM_SVC_FACE_ASYNC_INET_ADDR "127.0.0.1"
-typedef struct
-{
-       int type; /* type should be set to 0 */
-       char media_uuid[DCM_SVC_FACE_ASYNC_MEDIA_UUID_LENGTH];
-} dcm_svc_face_async_msg_s;
-
-int DcmIpcUtils::sendFaceMsg(const char *media_uuid)
-{
-       dcm_debug_fenter();
-       DCM_CHECK_VAL(media_uuid, DCM_ERROR_INVALID_PARAMETER);
-       dcm_sec_debug("media_id: %s", media_uuid);
-       struct sockaddr_in client_addr;
-       int socket_fd = 0;
-       int ret = 0;
-
-       /* Create send socket */
-       if ((socket_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-               dcm_error("Failed to create socket for libface-svc! err: %s", strerror(errno));
-               return DCM_ERROR_NETWORK;
-       }
-       dcm_debug("socket fd: %d", socket_fd);
-
-       /* Set send message */
-       dcm_svc_face_async_msg_s face_async_msg;
-       memset(&face_async_msg, 0x00, sizeof(dcm_svc_face_async_msg_s));
-       face_async_msg.type = 0;
-       g_strlcpy(face_async_msg.media_uuid, media_uuid, sizeof(face_async_msg.media_uuid));
-
-       /* Set face async port and address */
-       client_addr.sin_family = AF_INET;
-       client_addr.sin_port = htons(DCM_SVC_FACE_ASYNC_UDP_SEND_PORT);
-       client_addr.sin_addr.s_addr = inet_addr(DCM_SVC_FACE_ASYNC_INET_ADDR);
-
-       /* Send message to libface-svc */
-       ret = sendto(socket_fd, &face_async_msg, sizeof(dcm_svc_face_async_msg_s), MSG_NOSIGNAL, (struct sockaddr*)&client_addr, sizeof(client_addr));
-       if (ret < 0) {
-               dcm_error("Failed to send message to libface-svc! err: %s", strerror(errno));
-               close(socket_fd);
-               return DCM_ERROR_NETWORK;
-       }
-
-       close(socket_fd);
-       dcm_debug_fleave();
-       return DCM_SUCCESS;
-}
-
index 750cf7c2cb2c28ee3e2ae73f4e68b7834c424621..5f6a0d40580a29f76df621b93ba4ad9aa20794de 100755 (executable)
@@ -46,6 +46,8 @@ public:
        GMainContext *scan_thread_main_context;
        gboolean g_scan_cancel;
        GSource *scan_thread_quit_timer;
+       DcmDbUtils *dcmDBUtils;
+       uid_t g_uid;
 
        /* scan all images */
        GList *scan_all_item_list;
@@ -65,6 +67,7 @@ public:
        int initialize();
        int finalize();
        int sendCompletedMsg(const char *msg, DcmIpcPortType port);
+       int sendTerminatedMsg();
        int getScanStatus(DcmScanItem *scan_item, bool *media_scanned);
        int runScanProcess(DcmScanItem *scan_item);
        int ScanAllItems();
@@ -97,11 +100,17 @@ void DcmScanSvc::quitScanThread()
 gboolean DcmScanCallback::quitTimerAtScanThread(gpointer data)
 {
        DcmScanSvc *dcmScanSvc = (DcmScanSvc *) data;
+       int ret;
 
        dcm_debug_fenter();
 
        DCM_CHECK_FALSE(data);
 
+       ret = DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SCAN_TERMINATED, 0, NULL, DCM_IPC_PORT_DCM_RECV);
+       if (ret != DCM_SUCCESS) {
+               dcm_error("send to terminated messge to DCM Main");
+       }
+
        if (dcmScanSvc->scan_all_curr_index != 0 || dcmScanSvc->scan_single_curr_index != 0) {
                dcm_warn("Scan thread is working! DO NOT quit main thread!");
                dcmScanSvc->createQuitTimerScanThread();
@@ -253,6 +262,7 @@ int DcmScanSvc::initialize()
        g_scan_cancel = FALSE;
 
        DcmFaceUtils::initialize();
+       dcmDBUtils = DcmDbUtils::getInstance();
 
        return DCM_SUCCESS;
 }
@@ -285,6 +295,13 @@ int DcmScanSvc::sendCompletedMsg(const char *msg, DcmIpcPortType port)
        return DCM_SUCCESS;
 }
 
+int DcmScanSvc::sendTerminatedMsg()
+{
+       dcm_debug("Terminated message is sent to DCM main...");
+
+       return ;
+}
+
 int DcmScanSvc::getScanStatus(DcmScanItem *scan_item, bool *media_scanned)
 {
        int ret = DCM_SUCCESS;
@@ -418,6 +435,10 @@ int DcmScanSvc::ScanAllItems()
                clearAllItemList();
                /* Send scan complete message to main thread (if all scan operations are finished) */
                sendCompletedMsg( NULL, DCM_IPC_PORT_DCM_RECV);
+               ret = dcmDBUtils->_dcm_svc_db_disconnect();
+               if (ret != DCM_SUCCESS) {
+                       dcm_error("Failed to disconnect db! err: %d", ret);
+               }
                return DCM_SUCCESS;
        }
 
@@ -483,16 +504,16 @@ int DcmScanSvc::terminateScanOperations()
        dcm_debug("Terminate scanning operations, and quit scan thread main loop");
 
        g_scan_cancel = TRUE;
-       createQuitTimerScanThread();
 
-       return DCM_SUCCESS;
+       return createQuitTimerScanThread();
 }
 
 int DcmScanSvc::receiveMsg(DcmIpcMsg *recv_msg)
 {
        int ret = DCM_SUCCESS;
 
-       DcmDbUtils *dcmDbUtils = DcmDbUtils::getInstance();
+       dcmDBUtils = DcmDbUtils::getInstance();
+       g_uid = recv_msg->uid;
        DCM_CHECK_VAL(recv_msg, DCM_ERROR_INVALID_PARAMETER);
 
        dcm_debug("msg_type: %d", recv_msg->msg_type);
@@ -500,22 +521,29 @@ int DcmScanSvc::receiveMsg(DcmIpcMsg *recv_msg)
        if (recv_msg->msg_type == DCM_IPC_MSG_KILL_SERVICE)
        {
                /* Destroy scan idles, and quit scan thread main loop */
-               terminateScanOperations();
-       }
-
-       ret = dcmDbUtils->_dcm_svc_db_connect(recv_msg->uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               dcm_error("Failed to connect DB! err: %d", ret);
-               return DCM_ERROR_DB_OPERATION;
+               ret = terminateScanOperations();
+               if (ret != DCM_SUCCESS) {
+                       dcm_error("Failed to terminate DCM scan service! err: %d", ret);
+                       return DCM_ERROR_DB_OPERATION;
+               }
+               return ret;
        }
-
-       if (recv_msg->msg_type == DCM_IPC_MSG_SCAN_ALL)
+       else if (recv_msg->msg_type == DCM_IPC_MSG_SCAN_ALL)
        {
                /* Use timer to scan all unscanned images */
+               ret = dcmDBUtils->_dcm_svc_db_connect(recv_msg->uid);
+               if (ret != DCM_SUCCESS) {
+                       dcm_error("Failed to disconnect db! err: %d", ret);
+               }
                ScanAllItems();
+               ret = dcmDBUtils->_dcm_svc_db_disconnect();
        }
        else if (recv_msg->msg_type == DCM_IPC_MSG_SCAN_SINGLE)
        {
+               ret = dcmDBUtils->_dcm_svc_db_connect(recv_msg->uid);
+               if (ret != DCM_SUCCESS) {
+                       dcm_error("Failed to connect db! err: %d", ret);
+               }
                /* Create a scan idle if not exist, and scan single image of which file path is reveived from tcp socket */
                if (recv_msg->msg_size > 0 && recv_msg->msg_size < DCM_IPC_MSG_MAX_SIZE) {
                        char *file_path = NULL;
@@ -531,18 +559,16 @@ int DcmScanSvc::receiveMsg(DcmIpcMsg *recv_msg)
                        dcm_error("Invalid receive message!");
                        ret = DCM_ERROR_IPC_INVALID_MSG;
                }
+               ret = dcmDBUtils->_dcm_svc_db_disconnect();
+               if (ret != DCM_SUCCESS) {
+                       dcm_error("Failed to disconnect db! err: %d", ret);
+               }
        }
        else {
-               dcm_error("Invalid message type!");
+               dcm_error("Invalid message type(%d)!", recv_msg->msg_type);
                ret = DCM_ERROR_IPC_INVALID_MSG;
        }
 
-       ret = dcmDbUtils->_dcm_svc_db_disconnect();
-       if (ret != DCM_SUCCESS) {
-               dcm_error("Failed to disconnect DB! err: %d", ret);
-               return DCM_ERROR_DB_OPERATION;
-       }
-
        return ret;
 }
 
@@ -632,6 +658,10 @@ gboolean DcmScanCallback::runScanThreadIdle(gpointer data)
        DCM_CHECK_FALSE(scanSvc);
        DCM_CHECK_FALSE(dcmDbUtils);
 
+       ret = scanSvc->dcmDBUtils->_dcm_svc_db_connect(scanSvc->g_uid);
+       if (ret != DCM_SUCCESS) {
+               dcm_error("Failed to disconnect db! err: %d", ret);
+       }
        /* DCM scan started */
        unsigned int list_len = g_list_length(scanSvc->scan_all_item_list);
        if ((scanSvc->scan_all_curr_index < list_len) && !scanSvc->g_scan_cancel) {
@@ -652,9 +682,20 @@ gboolean DcmScanCallback::runScanThreadIdle(gpointer data)
        } else {
                dcm_warn("All images are scanned. Scan operation completed");
                scanSvc->clearAllItemList();
+               ret = scanSvc->dcmDBUtils->_dcm_svc_db_disconnect();
+               if (ret != DCM_SUCCESS) {
+                       dcm_error("Failed to disconnect db! err: %d", ret);
+               }
+               scanSvc->clearAllItemList();
+               /* Send scan complete message to main thread (if all scan operations are finished) */
+               scanSvc->sendCompletedMsg( NULL, DCM_IPC_PORT_DCM_RECV);
                dcm_debug_fleave();
                return FALSE;
        }
+       ret = scanSvc->dcmDBUtils->_dcm_svc_db_disconnect();
+       if (ret != DCM_SUCCESS) {
+               dcm_error("Failed to disconnect db! err: %d", ret);
+       }
 
        dcm_debug_fleave();
 
index 568657f840f76711e24027bbb1f83e931dbaa7b2..a2ac83b7e3a1088434fa39fe393d254c530523e5 100755 (executable)
@@ -29,7 +29,7 @@
 #include <DcmDebugUtils.h>
 
 
-#define DCM_SVC_MAIN_THREAD_TIMEOUT_SEC 20
+#define DCM_SVC_MAIN_THREAD_TIMEOUT_SEC 1
 
 namespace DcmMainSvcCallBack {
 gboolean readMsg(GIOChannel *src, GIOCondition condition, gpointer data);
@@ -59,7 +59,7 @@ static DcmMainSvc* DcmMainSvc::getInstance(void)
 void DcmMainSvc::dcmServiceStartjobs(void)
 {
        /* Send ready response to dcm launcher */
-       if (DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SERVICE_READY, 0, NULL, DCM_IPC_PORT_THUMB_RECV) != DCM_SUCCESS) {
+       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");
        }
 }
@@ -67,9 +67,6 @@ void DcmMainSvc::dcmServiceStartjobs(void)
 void DcmMainSvc::dcmServiceFinishjobs(void)
 {
        /* TODO: free resources for dcm-service */
-       if (DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SERVICE_TERMINATED, 0, NULL, DCM_IPC_PORT_THUMB_RECV) != DCM_SUCCESS) {
-               dcm_error("Failed to send terminated message");
-       }
 }
 
 int DcmMainSvc::waitScanThreadReady()
@@ -136,8 +133,8 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp
 {
        DcmIpcMsg recv_msg;
        int sock = -1;
+       int client_sock = -1;
        int ret = 0;
-       int client_sock;
 
        DcmMainSvc *dcmSvc = DcmMainSvc::getInstance();
 
@@ -176,18 +173,26 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp
                dcm_debug("scan thread is already running!");
        }
 
-       if ((recv_msg.msg_type == DCM_IPC_MSG_SCAN_COMPLETED) ||
-                       (recv_msg.msg_type == DCM_IPC_MSG_SCAN_TERMINATED)) {
-               dcm_debug("Scan completed!");
+       if (recv_msg.msg_type == DCM_IPC_MSG_SCAN_TERMINATED) {
+               dcm_debug("Scan terminated!");
                dcmSvc->scan_thread_working = false;
                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);
        } 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);
        } else if (recv_msg.msg_type == DCM_IPC_MSG_SCAN_ALL) {
                ret = DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SCAN_ALL, recv_msg.uid, NULL, DCM_IPC_PORT_SCAN_RECV);
+               if (ret == DCM_SUCCESS) {
+                       ret = DcmIpcUtils::sendClientSocketMsg(client_sock, DCM_IPC_MSG_SCAN_ALL, recv_msg.uid, NULL, DCM_IPC_PORT_DCM_RECV);
+               }
        } 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) {
+                       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.");
        }
@@ -209,6 +214,7 @@ gboolean DcmMainSvcCallBack::quitTimerAtMainLoop(gpointer data)
 
        if (dcmSvcApp->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!");
                dcmSvcApp->quitDcmSvcMainLoop();
@@ -294,6 +300,7 @@ EXPORT_API int main(int argc, char *argv[])
        dcm_debug("DCM Service is shutting down...");
        g_io_channel_shutdown(channel, FALSE, NULL);
        g_io_channel_unref(channel);
+       close(sockfd);
        g_main_loop_unref(g_dcm_svc_mainloop);
 
        return 0;
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..55b2c17
--- /dev/null
@@ -0,0 +1,20 @@
+SET(fw_test "dcm-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 libmedia-utils libtzplatform-config)
+
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+    MESSAGE("${src_name}")
+    ADD_EXECUTABLE(${fw_test} ${src})
+    TARGET_LINK_LIBRARIES(${fw_test} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
+
+#INSTALL(TARGETS ${fw_test} DESTINATION bin)
diff --git a/test/dcm-test.c b/test/dcm-test.c
new file mode 100755 (executable)
index 0000000..e605f0a
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  com.samsung.dcm-svc-client
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jiyong Min <jiyong.min@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <glib.h>
+#include <media-util.h>
+#include <tzplatform_config.h>
+
+#define MAX_STRING_LEN 4096
+#define ALL "ALL"
+#define SINGLE "SINGLE"
+
+static char *g_path = NULL;
+static char *g_command = NULL;
+
+int main(int argc, char **argv)
+{
+       if (argc < 1) {
+               printf("Usage: dcm_test ALL|SINGLE file_path \n");
+               return 0;
+       }
+
+       g_command = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
+       memset(g_command, 0x00, MAX_STRING_LEN);
+       snprintf(g_command, MAX_STRING_LEN, "%s", argv[1]);
+
+       if (strcmp(g_command, SINGLE) == 0) {
+               if (argc < 2) {
+                       printf("Usage: dcm_test ALL|SINGLE file_path \n");
+                       return 0;
+               }
+
+               g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
+               memset(g_path, 0x00, MAX_STRING_LEN);
+               snprintf(g_path, MAX_STRING_LEN, "%s", argv[2]);
+
+               printf("dcm_test SINGLE file_path=%s \n", g_path);
+
+               dcm_svc_request_extract_media(g_path, tzplatform_getuid(TZ_USER_NAME));
+       } else if (strcmp(g_command, ALL) == 0) {
+               printf("dcm_test ALL \n");
+
+               dcm_svc_request_extract_all(tzplatform_getuid(TZ_USER_NAME));
+       } else {
+               printf("Usage: dcm_test ALL|SINGLE file_path \n");
+               return 0;
+       }
+
+       return -1;
+}