Merge dcm manage queue with request queue 77/143177/1 accepted/tizen/unified/20170809.135233 accepted/tizen/unified/20170814.060117 submit/tizen/20170809.023747 submit/tizen/20170811.053616
authorJiyong Min <jiyong.min@samsung.com>
Wed, 9 Aug 2017 01:53:33 +0000 (10:53 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 9 Aug 2017 02:21:08 +0000 (11:21 +0900)
Change-Id: I0f5c6dfc0750c71c083236739758b6235a62370b
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
lib/media-util-dcm.c
packaging/media-server.spec

index 85b0518..fb7aaba 100755 (executable)
@@ -33,7 +33,6 @@
 #include <media-util-ipc.h>
 #include <tzplatform_config.h>
 
-static GQueue *g_request_queue = NULL;
 static GQueue *g_manage_queue = NULL;
 
 typedef struct {
@@ -45,6 +44,7 @@ typedef struct {
        GIOChannel *channel;
        int msg_type;
        gboolean isCanceled;
+       gboolean isRequested;
        int request_id;
        int source_id;
        uid_t uid;
@@ -54,14 +54,12 @@ typedef struct {
 
 extern char MEDIA_IPC_PATH[][70];
 
-int __media_dcm_check_req_queue(const char *path);
-int __media_dcm_pop_manage_queue(const unsigned int request_id, const char *path);
 static int __media_dcm_send_request();
 
 gboolean __media_dcm_check_cancel(void)
 {
        dcmReq *req = NULL;
-       req = (dcmReq *)g_queue_peek_head(g_request_queue);
+       req = (dcmReq *)g_queue_peek_head(g_manage_queue);
 
        if (req == NULL) {
                return FALSE;
@@ -73,88 +71,68 @@ gboolean __media_dcm_check_cancel(void)
        }
 }
 
-void __media_dcm_shutdown_channel(gboolean only_shutdown)
+int __media_dcm_pop_data()
 {
-       int len = -1;
-       dcmReq *req = (dcmReq *)g_queue_peek_head(g_request_queue);
+       int len = 0;
 
-       len = g_queue_get_length(g_manage_queue);
-
-       if (req != NULL) {
-               if (!only_shutdown) {
-                       if (len == 0 && req->isCanceled == TRUE) {
-                               MSAPI_DBG("The manage queue will be released");
-                       } else {
-                               MSAPI_DBG("There is remain item in the manage queue");
-                               return;
-                       }
-               }
-               GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
-               if (source_id != NULL) {
-                       g_source_destroy(source_id);
-               } else {
-                       MSAPI_DBG_ERR("G_SOURCE_ID is NULL");
-               }
+       if (g_manage_queue != NULL) {
+               dcmReq *req = (dcmReq *)g_queue_pop_head(g_manage_queue);
+               if (req != NULL) {
+                       GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
 
-               g_io_channel_shutdown(req->channel, TRUE, NULL);
-               g_io_channel_unref(req->channel);
-               g_queue_pop_head(g_request_queue);
+                       g_io_channel_shutdown(req->channel, TRUE, NULL);
+                       g_io_channel_unref(req->channel);
 
-               MS_SAFE_FREE(req->path);
-               MS_SAFE_FREE(req->userData);
-               MS_SAFE_FREE(req);
+                       if (source_id != NULL)
+                               g_source_destroy(source_id);
+                       else
+                               MSAPI_DBG_ERR("G_SOURCE_ID is NULL");
 
-               if (g_manage_queue && len == 0) {
-                       g_queue_free(g_manage_queue);
-                       g_manage_queue = NULL;
+                       MS_SAFE_FREE(req->path);
+                       MS_SAFE_FREE(req->userData);
+                       MS_SAFE_FREE(req);
                }
        }
-}
-
-int __media_dcm_pop_req_queue(const char *path)
-{
-       int req_len = 0;
 
-       req_len = g_queue_get_length(g_request_queue);
-
-       if (req_len <= 0) {
-               MSAPI_DBG("There is no request in the queue");
-       } else {
-               __media_dcm_shutdown_channel(TRUE);
-       }
+       len = g_queue_get_length(g_manage_queue);
 
-       /* Check manage queue */
-       if (g_manage_queue) {
-               req_len = g_queue_get_length(g_manage_queue);
-
-               if (req_len > 0)
-                       __media_dcm_send_request();
-       }
+       if (len > 0)
+               __media_dcm_send_request();
 
        return MS_MEDIA_ERR_NONE;
 }
 
-int __media_dcm_check_req_queue_for_cancel(unsigned int request_id, const char *path)
+int __media_dcm_cancel_data(int request_id)
 {
-       int req_len = 0;
-
-       req_len = g_queue_get_length(g_request_queue);
+       int len = 0, i = 0;
+       bool flag = false;
 
-       if (req_len <= 0) {
-               MSAPI_DBG("There is no request in the queue");
-       } else {
-               dcmReq *req = NULL;
-               req = (dcmReq *)g_queue_peek_head(g_request_queue);
-
-               if (req != NULL && strncmp(path, req->path, strlen(path)) == 0 && request_id == req->request_id) {
-                       req->isCanceled = true;
-                       __media_dcm_shutdown_channel(FALSE);
+       if (g_manage_queue != NULL) {
+               len = g_queue_get_length(g_manage_queue);
+               for (i = 0; i < len; i++) {
+                       dcmReq *req = NULL;
+                       req = (dcmReq *)g_queue_peek_nth(g_manage_queue, i);
+                       if (req == NULL) continue;
 
-                       return MS_MEDIA_ERR_NONE;
+                       if (req->request_id == request_id) {
+                               if (req->isRequested == true) {
+                                       req->isCanceled = true;
+                               } else {
+                                       g_queue_pop_nth(g_manage_queue, i);
+                                       MS_SAFE_FREE(req->path);
+                                       MS_SAFE_FREE(req->userData);
+                                       MS_SAFE_FREE(req);
+                               }
+                               flag = true;
+                               break;
+                       }
                }
        }
 
-       return MS_MEDIA_ERR_INTERNAL;
+       if (flag == false)
+               return MS_MEDIA_ERR_INTERNAL;
+
+       return MS_MEDIA_ERR_NONE;
 }
 
 gboolean __media_dcm_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
@@ -171,7 +149,7 @@ gboolean __media_dcm_write_socket(GIOChannel *src, GIOCondition condition, gpoin
        if ((err = recv(sock, &recv_msg, sizeof(dcmMsg), 0)) < 0) {
                MSAPI_DBG_STRERROR("recv failed ");
                if (recv_msg.msg_size > 0) {
-                       __media_dcm_pop_req_queue(recv_msg.msg);
+                       __media_dcm_pop_data();
                } else {
                        MSAPI_DBG_ERR("origin path size is wrong.");
                }
@@ -191,78 +169,13 @@ gboolean __media_dcm_write_socket(GIOChannel *src, GIOCondition condition, gpoin
                }
        }
 
-       __media_dcm_pop_req_queue(recv_msg.msg);
+       __media_dcm_pop_data();
 
        MSAPI_DBG("Done");
 
        return FALSE;
 }
 
-int __media_dcm_check_req_queue(const char *path)
-{
-       int req_len = 0, i;
-
-       req_len = g_queue_get_length(g_request_queue);
-
-       MSAPI_DBG("Queue length : %d", req_len);
-       MSAPI_DBG("Queue path : %s", path);
-
-       if (req_len <= 0) {
-               MSAPI_DBG("There is no request in the queue");
-       } else {
-
-               for (i = 0; i < req_len; i++) {
-                       dcmReq *req = NULL;
-                       req = (dcmReq *)g_queue_peek_nth(g_request_queue, i);
-                       if (req == NULL) continue;
-
-                       if (strncmp(path, req->path, strlen(path)) == 0) {
-                               MSAPI_DBG("Same Request - %s", path);
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-               }
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int __media_dcm_pop_manage_queue(const unsigned int request_id, const char *path)
-{
-       int req_len = 0, i;
-       gboolean flag = FALSE;
-
-       req_len = g_queue_get_length(g_manage_queue);
-
-       if (req_len < 0) {
-               MSAPI_DBG("There is no request in the queue");
-       } else {
-               for (i = 0; i < req_len; i++) {
-                       dcmReq *req = NULL;
-                       req = (dcmReq *)g_queue_peek_nth(g_manage_queue, i);
-                       if (req == NULL) continue;
-
-                       if (strncmp(path, req->path, strlen(path)) == 0) {
-                               g_queue_pop_nth(g_manage_queue, i);
-
-                               MS_SAFE_FREE(req->path);
-                               MS_SAFE_FREE(req->userData);
-                               MS_SAFE_FREE(req);
-                               flag = TRUE;
-                               break;
-                       }
-               }
-               if (!flag) {
-                       return __media_dcm_check_req_queue_for_cancel(request_id, path);
-               } else {
-                       __media_dcm_shutdown_channel(FALSE);
-
-                       return MS_MEDIA_ERR_NONE;
-               }
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 static int __media_dcm_send_request()
 {
        int err = MS_MEDIA_ERR_NONE;
@@ -295,10 +208,10 @@ static int __media_dcm_send_request()
                return MS_MEDIA_ERR_SOCKET_CONN;
        }
 
-       req_manager = (dcmReq *)g_queue_pop_head(g_manage_queue);
+       req_manager = (dcmReq *)g_queue_peek_head(g_manage_queue);
 
        if (req_manager == NULL) {
-               MSAPI_DBG_ERR("queue pop fail");
+               MSAPI_DBG_ERR("queue peek fail");
                g_io_channel_shutdown(channel, TRUE, NULL);
                g_io_channel_unref(channel);
                close(sock);
@@ -334,22 +247,9 @@ static int __media_dcm_send_request()
        MSAPI_DBG("Sending msg to dcm service is successful");
 
        if (req_manager->msg_type == DCM_MSG_REQUEST_MEDIA) {
-               if (g_request_queue == NULL) {
-                       g_request_queue = g_queue_new();
-               }
-
-               dcmReq *dcm_req = calloc(1, sizeof(dcmReq));
-               if (dcm_req == NULL) {
-                       MSAPI_DBG_ERR("Failed to create request element");
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
-
-               dcm_req->channel = channel;
-               dcm_req->path = g_strdup(req_manager->path);
-               dcm_req->source_id = source_id;
-               dcm_req->userData = req_manager->userData;
-
-               g_queue_push_tail(g_request_queue, (gpointer)dcm_req);
+               req_manager->channel = channel;
+               req_manager->source_id = source_id;
+               req_manager->isRequested = true;
        }
 
        return err;
@@ -424,63 +324,36 @@ int _media_dcm_request(int msg_type, const char *path, uid_t uid)
 static int __media_dcm_request_async(int msg_type, const unsigned int request_id, const char *path, faceUserData *userData, uid_t uid)
 {
        int err = MS_MEDIA_ERR_NONE;
+       int len = 0;
+       dcmReq *dcm_req = NULL;
 
-       MSAPI_DBG_SLOG("Path : %s", path);
-
-       if (g_manage_queue == NULL) {
-               MSAPI_DBG("g_manage_queue is NULL");
-               if (msg_type == DCM_MSG_REQUEST_CANCEL_FACE)
-                       return MS_MEDIA_ERR_INTERNAL;
+       if (msg_type == DCM_MSG_REQUEST_CANCEL_FACE)
+               return __media_dcm_cancel_data(request_id);
 
+       if (g_manage_queue == NULL)
                g_manage_queue = g_queue_new();
 
-               dcmReq *dcm_req = NULL;
-               dcm_req = calloc(1, sizeof(dcmReq));
-               if (dcm_req == NULL) {
-                       MSAPI_DBG_ERR("Failed to create request element");
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
+       dcm_req = calloc(1, sizeof(dcmReq));
+       if (dcm_req == NULL) {
+               MSAPI_DBG_ERR("Failed to create request element");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       }
 
-               dcm_req->msg_type = msg_type;
-               dcm_req->path = g_strdup(path);
-               dcm_req->userData = userData;
-               dcm_req->isCanceled = FALSE;
-               dcm_req->request_id = request_id;
-               dcm_req->uid = uid;
+       dcm_req->msg_type = msg_type;
+       dcm_req->path = g_strdup(path);
+       dcm_req->userData = userData;
+       dcm_req->isCanceled = FALSE;
+       dcm_req->request_id = request_id;
+       dcm_req->uid = uid;
 
-               MSAPI_DBG("Enqueue");
-               g_queue_push_tail(g_manage_queue, (gpointer)dcm_req);
+       MSAPI_DBG("Enqueue");
+       len = g_queue_get_length(g_manage_queue);
+       g_queue_push_tail(g_manage_queue, (gpointer)dcm_req);
 
-               /* directly request at first time */
+       /* directly request at first time */
+       if (len == 0)
                err = __media_dcm_send_request();
 
-       } else {
-               MSAPI_DBG("g_manage_queue is not NULL");
-               if (msg_type != DCM_MSG_REQUEST_CANCEL_FACE) {
-                       /* Enqueue */
-                       dcmReq *dcm_req = NULL;
-                       dcm_req = calloc(1, sizeof(dcmReq));
-                       if (dcm_req == NULL) {
-                               MSAPI_DBG_ERR("Failed to create request element");
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-
-                       dcm_req->msg_type = msg_type;
-                       dcm_req->path = g_strdup(path);
-                       dcm_req->userData = userData;
-                       dcm_req->isCanceled = FALSE;
-                       dcm_req->request_id = request_id;
-                       dcm_req->uid = uid;
-
-                       MSAPI_DBG("Enqueue");
-                       g_queue_push_tail(g_manage_queue, (gpointer)dcm_req);
-               } else {
-                       /* Dequeue */
-                       MSAPI_DBG("Dequeue");
-                       err = __media_dcm_pop_manage_queue(request_id, path);
-               }
-       }
-
        return err;
 }
 
@@ -569,7 +442,7 @@ int dcm_request_cancel_face(const unsigned int request_id, const char *path)
        /* Request for image file to the daemon "Dcm generator" */
        err = __media_dcm_request_async(DCM_MSG_REQUEST_CANCEL_FACE, request_id, path, NULL, request_id);
        if (err != MS_MEDIA_ERR_NONE) {
-               MSAPI_DBG_ERR("_media_dcm_request failed : %d", err);
+               MSAPI_DBG_ERR("__media_dcm_request_async failed : %d", err);
                return err;
        }
 
index b7c8fdd..90308f2 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.3.47
+Version:    0.3.48
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0