From: Minje Ahn Date: Wed, 2 Aug 2017 07:20:51 +0000 (+0900) Subject: Merge thumb request queue X-Git-Tag: accepted/tizen/4.0/unified/20170816.013431^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F141993%2F3;p=platform%2Fcore%2Fmultimedia%2Flibmedia-thumbnail.git Merge thumb request queue Remove request queue and use only manage queue Add flag for check requesting Change-Id: Ia35bcf043389011601df6c071fd623ff9b1727f0 Signed-off-by: Minje Ahn --- diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec index 6a88d67..a7c382e 100644 --- a/packaging/libmedia-thumbnail.spec +++ b/packaging/libmedia-thumbnail.spec @@ -1,6 +1,6 @@ Name: libmedia-thumbnail Summary: Media thumbnail service library for multimedia applications -Version: 0.2.12 +Version: 0.2.13 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 and PD diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c index 63f22d4..78aab2d 100755 --- a/src/ipc/media-thumb-ipc.c +++ b/src/ipc/media-thumb-ipc.c @@ -34,7 +34,6 @@ #define THUMB_SOCK_BLOCK_SIZE 512 #define THUMB_IPC_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcreator.socket") -static GQueue *g_request_queue = NULL; static GQueue *g_manage_queue = NULL; static GQueue *g_request_raw_queue = NULL; static GQueue *g_manage_raw_queue = NULL; @@ -45,6 +44,7 @@ typedef struct { int msg_type; unsigned int request_id; bool isCanceled; + bool isRequested; int source_id; uid_t uid; char *path; @@ -64,8 +64,8 @@ typedef struct { thumbRawUserData *userData; } thumbRawReq; -int _media_thumb_send_request(); -int _media_thumb_raw_data_send_request(); +static int _media_thumb_send_request(); +static int _media_thumb_raw_data_send_request(); int _media_thumb_get_error() @@ -79,128 +79,73 @@ int _media_thumb_get_error() } } -void __media_thumb_shutdown_channel(bool only_shutdown) +void __media_thumb_pop() { - int len = -1; - thumbReq *req = (thumbReq *)g_queue_peek_head(g_request_queue); + int len = 0; - len = g_queue_get_length(g_manage_queue); + if (g_manage_queue != NULL) { + thumbReq *req = (thumbReq *)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); - if (req != NULL) { - if (!only_shutdown) { - if (len == 0 && req->isCanceled == true) { - thumb_dbg("The manage queue will be released"); + if (source_id != NULL) { + g_source_destroy(source_id); } else { - thumb_dbg("There is remain item in the manage queue"); - return; + thumb_err("G_SOURCE_ID is NULL"); } - } - 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 { - thumb_err("G_SOURCE_ID is NULL"); - } - - g_io_channel_shutdown(req->channel, TRUE, NULL); - g_io_channel_unref(req->channel); - g_queue_pop_head(g_request_queue); - SAFE_FREE(req->path); - SAFE_FREE(req->userData); - SAFE_FREE(req); - - if (g_manage_queue && len == 0) { - g_queue_free(g_manage_queue); - g_manage_queue = NULL; + SAFE_FREE(req->path); + SAFE_FREE(req->userData); + SAFE_FREE(req); } - } -} - -int __media_thumb_pop_req_queue() -{ - int req_len = 0; - - req_len = g_queue_get_length(g_request_queue); - - if (req_len <= 0) { -// thumb_dbg("There is no request in the queue"); - } else { - __media_thumb_shutdown_channel(true); - } - - /* Check manage queue */ - if (g_manage_queue) { - req_len = g_queue_get_length(g_manage_queue); - if (req_len > 0) + /* Check manage queue */ + len = g_queue_get_length(g_manage_queue); + if (len > 0) _media_thumb_send_request(); } - - return MS_MEDIA_ERR_NONE; } -int __media_thumb_check_req_queue_for_cancel(unsigned int request_id, const char *path) +int __media_thumb_cancel(unsigned int request_id) { - int req_len = 0; - - req_len = g_queue_get_length(g_request_queue); - - if (req_len <= 0) { -// thumb_dbg("There is no request in the queue"); - } else { - thumbReq *req = NULL; - req = (thumbReq *)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_thumb_shutdown_channel(false); - - return MS_MEDIA_ERR_NONE; - } - } - - return MS_MEDIA_ERR_INTERNAL; -} - -int __media_thumb_pop_manage_queue(unsigned int request_id, const char *path) -{ - int req_len = 0, i; + int len = 0, i; bool flag = false; - req_len = g_queue_get_length(g_manage_queue); + if (g_manage_queue != NULL) { + len = g_queue_get_length(g_manage_queue); - if (req_len < 0) { -// thumb_dbg("There is no request in the queue"); - } else { - for (i = 0; i < req_len; i++) { + for (i = 0; i < len; i++) { thumbReq *req = NULL; req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i); if (req == NULL) continue; - if (strncmp(path, req->path, strlen(path)) == 0 && request_id == req->request_id) { - g_queue_pop_nth(g_manage_queue, i); + if (req->request_id == request_id) { + if (req->isRequested == true) { + req->isCanceled = true; + } else { + g_queue_pop_nth(g_manage_queue, i); + + SAFE_FREE(req->path); + SAFE_FREE(req->userData); + SAFE_FREE(req); + } - SAFE_FREE(req->path); - SAFE_FREE(req->userData); - SAFE_FREE(req); flag = true; + break; } } - if (!flag) { - return __media_thumb_check_req_queue_for_cancel(request_id, path); - } else { - __media_thumb_shutdown_channel(false); - - return MS_MEDIA_ERR_NONE; - } } + if (flag == false) + return MS_MEDIA_ERR_INTERNAL; + return MS_MEDIA_ERR_NONE; } - int __media_thumb_pop_raw_data_req_queue(int request_id, bool shutdown_channel) { int req_len = 0, i; @@ -297,63 +242,11 @@ int __media_thumb_pop_raw_data_manage_queue(int request_id) return MS_MEDIA_ERR_NONE; } -#if 0 -int __media_thumb_check_req_queue(const char *path) -{ - int req_len = 0, i; - req_len = g_queue_get_length(g_request_queue); - -// thumb_dbg("Queue length : %d", req_len); -// thumb_dbg("Queue path : %s", path); - - if (req_len <= 0) { -// thumb_dbg("There is no request in the queue"); - } else { - - for (i = 0; i < req_len; i++) { - thumbReq *req = NULL; - req = (thumbReq *)g_queue_peek_nth(g_request_queue, i); - if (req == NULL) continue; - - if (strncmp(path, req->path, strlen(path)) == 0) { - //thumb_dbg("Same Request - %s", path); - return MS_MEDIA_ERR_INVALID_PARAMETER; - - break; - } - } - } - - if (g_manage_queue != NULL) { - req_len = g_queue_get_length(g_manage_queue); - - if (req_len <= 0) { -// thumb_dbg("There is no request in the queue"); - } else { - for (i = 0; i < req_len; i++) { - thumbReq *req = NULL; - req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i); - if (req == NULL) continue; - - if (strncmp(path, req->path, strlen(path)) == 0) { - //thumb_dbg("Same Request - %s", path); - return MS_MEDIA_ERR_INVALID_PARAMETER; - - break; - } - } - } - } - - - return MS_MEDIA_ERR_NONE; -} -#endif bool __media_thumb_check_cancel(void) { thumbReq *req = NULL; - req = (thumbReq *)g_queue_peek_head(g_request_queue); + req = (thumbReq *)g_queue_peek_head(g_manage_queue); if (req == NULL) { return false; @@ -605,7 +498,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) { thumb_err("_media_thumb_recv_msg failed "); - __media_thumb_pop_req_queue(); + __media_thumb_pop(); return FALSE; } @@ -623,7 +516,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi } } - __media_thumb_pop_req_queue(); + __media_thumb_pop(); thumb_dbg("Done"); @@ -691,7 +584,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit return FALSE; } -int _media_thumb_send_request() +static int _media_thumb_send_request() { int err = MS_MEDIA_ERR_NONE; int sock = -1; @@ -728,10 +621,10 @@ int _media_thumb_send_request() return err; } - req_manager = (thumbReq *)g_queue_pop_head(g_manage_queue); + req_manager = (thumbReq *)g_queue_peek_head(g_manage_queue); if (req_manager == NULL) { - thumb_err("queue pop fail"); + thumb_err("queue peek fail"); g_io_channel_shutdown(channel, TRUE, NULL); g_io_channel_unref(channel); close(sock); @@ -783,31 +676,16 @@ int _media_thumb_send_request() SAFE_FREE(buf); thumb_dbg("Sending msg to thumbnail daemon is successful"); - if (req_manager->msg_type == THUMB_REQUEST_DB_INSERT) { - if (g_request_queue == NULL) { - g_request_queue = g_queue_new(); - } - - thumbReq *thumb_req = NULL; - THUMB_MALLOC(thumb_req, sizeof(thumbReq)); - if (thumb_req == NULL) { - thumb_err("Failed to create request element"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - thumb_req->channel = channel; - thumb_req->path = strdup(req_manager->path); - thumb_req->source_id = source_id; - thumb_req->userData = req_manager->userData; - - g_queue_push_tail(g_request_queue, (gpointer)thumb_req); + req_manager->channel = channel; + req_manager->source_id = source_id; + req_manager->isRequested = true; } return err; } -int _media_thumb_raw_data_send_request() +static int _media_thumb_raw_data_send_request() { int err = MS_MEDIA_ERR_NONE; int sock = -1; @@ -921,62 +799,32 @@ int _media_thumb_raw_data_send_request() int _media_thumb_request_async(int msg_type, unsigned int request_id, const char *origin_path, thumbUserData *userData, uid_t uid) { int err = MS_MEDIA_ERR_NONE; + int len = 0; - if (g_manage_queue == NULL) { - if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) - return MS_MEDIA_ERR_INTERNAL; + if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) + return __media_thumb_cancel(request_id); + if (g_manage_queue == NULL) g_manage_queue = g_queue_new(); - thumbReq *thumb_req = NULL; - THUMB_MALLOC(thumb_req, sizeof(thumbReq)); - if (thumb_req == NULL) { - thumb_err("Failed to create request element"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } + thumbReq *thumb_req = NULL; + THUMB_MALLOC(thumb_req, sizeof(thumbReq)); + thumb_retvm_if(thumb_req == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Failed to create request element"); - thumb_req->msg_type = msg_type; - thumb_req->path = strdup(origin_path); - thumb_req->userData = userData; - thumb_req->isCanceled = false; - thumb_req->request_id = request_id; - thumb_req->uid = uid; + thumb_req->msg_type = msg_type; + thumb_req->path = strdup(origin_path); + thumb_req->userData = userData; + thumb_req->isCanceled = false; + thumb_req->isRequested= false; + thumb_req->request_id = request_id; + thumb_req->uid = uid; - g_queue_push_tail(g_manage_queue, (gpointer)thumb_req); + len = g_queue_get_length(g_manage_queue); + g_queue_push_tail(g_manage_queue, (gpointer)thumb_req); - /* directly request at first time */ + if (len == 0) err = _media_thumb_send_request(); - } else { - if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) { - /* Enqueue */ -#if 0 - if ((msg_type == THUMB_REQUEST_DB_INSERT) && (__media_thumb_check_req_queue(origin_path) < 0)) { - thumb_err("duplicated request"); - return MS_MEDIA_ERR_THUMB_DUPLICATED_REQUEST; - } -#endif - thumbReq *thumb_req = NULL; - THUMB_MALLOC(thumb_req, sizeof(thumbReq)); - if (thumb_req == NULL) { - thumb_err("Failed to create request element"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - thumb_req->msg_type = msg_type; - thumb_req->path = strdup(origin_path); - thumb_req->userData = userData; - thumb_req->isCanceled = false; - thumb_req->request_id = request_id; - thumb_req->uid = uid; - - g_queue_push_tail(g_manage_queue, (gpointer)thumb_req); - } else { - /* Dequeue */ - err = __media_thumb_pop_manage_queue(request_id, origin_path); - } - } - return err; }