diff options
Diffstat (limited to 'src/ipc/media-thumb-ipc.c')
-rwxr-xr-x | src/ipc/media-thumb-ipc.c | 247 |
1 files changed, 114 insertions, 133 deletions
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c index ed5ecb7..64afe5a 100755 --- a/src/ipc/media-thumb-ipc.c +++ b/src/ipc/media-thumb-ipc.c @@ -63,11 +63,11 @@ typedef struct { thumbRawUserData *userData; } thumbRawReq; -static int _media_thumb_send_request(); -static int _media_thumb_raw_data_send_request(); +static int __media_thumb_send_request(void); +static int __media_thumb_raw_data_send_request(void); -int _media_thumb_get_error() +static int __media_thumb_get_error(void) { if (errno == EWOULDBLOCK) { thumb_err("Timeout. Can't try any more"); @@ -78,173 +78,162 @@ int _media_thumb_get_error() } } -void __media_thumb_pop() +static void __media_thumb_pop(void) { int len = 0; int sock = 0; + thumbReq *req = NULL; - 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); - sock = g_io_channel_unix_get_fd(req->channel); - - g_io_channel_shutdown(req->channel, TRUE, NULL); - g_io_channel_unref(req->channel); - close(sock); - if (source_id != NULL) { - g_source_destroy(source_id); - } else { - thumb_err("G_SOURCE_ID is NULL"); - } + if (!g_manage_queue) + return; - SAFE_FREE(req->path); - SAFE_FREE(req->userData); - SAFE_FREE(req); + 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); + sock = g_io_channel_unix_get_fd(req->channel); + + g_io_channel_shutdown(req->channel, TRUE, NULL); + g_io_channel_unref(req->channel); + close(sock); + if (source_id) { + g_source_destroy(source_id); + } else { + thumb_err("G_SOURCE_ID is NULL"); } - /* Check manage queue */ - len = g_queue_get_length(g_manage_queue); - if (len > 0) - _media_thumb_send_request(); + SAFE_FREE(req->path); + SAFE_FREE(req->userData); + SAFE_FREE(req); } + + /* Check manage queue */ + len = g_queue_get_length(g_manage_queue); + if (len > 0) + __media_thumb_send_request(); } -int __media_thumb_cancel(unsigned int request_id) +static int __media_thumb_cancel(unsigned int request_id) { int len = 0, i; - bool flag = false; - - if (g_manage_queue != NULL) { - len = g_queue_get_length(g_manage_queue); - for (i = 0; i < len; i++) { - thumbReq *req = NULL; - req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i); - if (req == NULL) continue; + thumb_retv_if(!g_manage_queue, 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); + len = g_queue_get_length(g_manage_queue); - SAFE_FREE(req->path); - SAFE_FREE(req->userData); - SAFE_FREE(req); - } + for (i = 0; i < len; i++) { + thumbReq *req = NULL; + req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i); + if (req == NULL) continue; - flag = true; + if (req->request_id == request_id) { + if (req->isRequested) { + req->isCanceled = true; + } else { + g_queue_pop_nth(g_manage_queue, i); - break; + SAFE_FREE(req->path); + SAFE_FREE(req->userData); + SAFE_FREE(req); } + + return MS_MEDIA_ERR_NONE; } } - if (flag == false) - return MS_MEDIA_ERR_INTERNAL; - - return MS_MEDIA_ERR_NONE; + return MS_MEDIA_ERR_INTERNAL; } -void __media_thumb_pop_raw_data() +static void __media_thumb_pop_raw_data(void) { int len = 0; int sock = 0; + thumbRawReq *req = NULL; - if (g_manage_raw_queue != NULL) { - thumbRawReq *req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue); - if (req != NULL) { - GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id); - sock = g_io_channel_unix_get_fd(req->channel); - - g_io_channel_shutdown(req->channel, TRUE, NULL); - g_io_channel_unref(req->channel); - close(sock); - if (source_id != NULL) { - g_source_destroy(source_id); - } else { - thumb_err("G_SOURCE_ID is NULL"); - } + if (!g_manage_raw_queue) + return; + + req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue); + if (req != NULL) { + GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id); + sock = g_io_channel_unix_get_fd(req->channel); - SAFE_FREE(req->path); - SAFE_FREE(req->userData); - SAFE_FREE(req); + g_io_channel_shutdown(req->channel, TRUE, NULL); + g_io_channel_unref(req->channel); + close(sock); + if (source_id) { + g_source_destroy(source_id); + } else { + thumb_err("G_SOURCE_ID is NULL"); } - /* Check manage queue */ - len = g_queue_get_length(g_manage_raw_queue); - if (len > 0) - _media_thumb_raw_data_send_request(); + SAFE_FREE(req->path); + SAFE_FREE(req->userData); + SAFE_FREE(req); } + + /* Check manage queue */ + len = g_queue_get_length(g_manage_raw_queue); + if (len > 0) + __media_thumb_raw_data_send_request(); } -int __media_thumb_cancel_raw_data(int request_id) +static int __media_thumb_cancel_raw_data(int request_id) { int len = 0, i; - bool flag = false; - - if (g_manage_raw_queue != NULL) { - len = g_queue_get_length(g_manage_raw_queue); - for (i = 0; i < len; i++) { - thumbRawReq *req = NULL; - req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i); - if (req == NULL) continue; + thumb_retv_if(!g_manage_raw_queue, MS_MEDIA_ERR_NONE); - if (req->request_id == request_id) { - if (req->isRequested == true) { - req->isCanceled = true; - } else { - g_queue_pop_nth(g_manage_raw_queue, i); + len = g_queue_get_length(g_manage_raw_queue); - SAFE_FREE(req->path); - SAFE_FREE(req->userData); - SAFE_FREE(req); - } + for (i = 0; i < len; i++) { + thumbRawReq *req = NULL; + req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i); + if (req == NULL) continue; - flag = true; + if (req->request_id == request_id) { + if (req->isRequested) { + req->isCanceled = true; + } else { + g_queue_pop_nth(g_manage_raw_queue, i); - break; + SAFE_FREE(req->path); + SAFE_FREE(req->userData); + SAFE_FREE(req); } + + return MS_MEDIA_ERR_NONE; } } - if (flag == false) - return MS_MEDIA_ERR_INTERNAL; - - return MS_MEDIA_ERR_NONE; - + return MS_MEDIA_ERR_INTERNAL; } -bool __media_thumb_check_cancel(void) +static bool __media_thumb_check_cancel(void) { thumbReq *req = NULL; req = (thumbReq *)g_queue_peek_head(g_manage_queue); - if (req == NULL) { + if (!req) return false; - } else { - if (req->isCanceled) - return false; - else - return true; - } + + if (req->isCanceled) + return false; + else + return true; } -bool __media_thumb_check_cancel_for_raw(void) +static bool __media_thumb_check_cancel_for_raw(void) { thumbRawReq *req = NULL; req = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue); - if (req == NULL) { + if (!req) return false; - } else { - if (req->isCanceled) - return false; - else - return true; - } + + if (req->isCanceled) + return false; + else + return true; } int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg) @@ -265,7 +254,7 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg) if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) { thumb_stderror("recv failed"); SAFE_FREE(buf); - return _media_thumb_get_error(); + return __media_thumb_get_error(); } header_size -= recv_len; recv_pos += recv_len; @@ -296,15 +285,13 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg) if (msg->thumb_size > 0) { remain_size = msg->thumb_size; THUMB_MALLOC(buf, remain_size); - if (buf == NULL) { - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } + thumb_retv_if(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY); while (remain_size > 0) { if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) { thumb_stderror("recv failed"); SAFE_FREE(buf); - return _media_thumb_get_error(); + return __media_thumb_get_error(); } fsync(sock); @@ -377,7 +364,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi thumb_err("_media_thumb_recv_msg failed "); __media_thumb_pop(); - return FALSE; + return G_SOURCE_REMOVE; } if (recv_msg.status != MS_MEDIA_ERR_NONE) { @@ -397,7 +384,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi thumb_dbg("Done"); - return FALSE; + return G_SOURCE_REMOVE; } gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condition, gpointer data) @@ -418,7 +405,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit thumb_err("_media_thumb_recv_msg failed "); __media_thumb_pop_raw_data(); - return FALSE; + return G_SOURCE_REMOVE; } if (recv_msg.status != MS_MEDIA_ERR_NONE) { @@ -438,10 +425,10 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit thumb_dbg("Done"); - return FALSE; + return G_SOURCE_REMOVE; } -static int _media_thumb_send_request() +static int __media_thumb_send_request(void) { int err = MS_MEDIA_ERR_NONE; int sock = -1; @@ -450,10 +437,7 @@ static int _media_thumb_send_request() int pid; err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("ms_ipc_create_client_socket failed"); - return err; - } + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed"); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sun_family = AF_UNIX; @@ -531,7 +515,7 @@ static int _media_thumb_send_request() return err; } -static int _media_thumb_raw_data_send_request() +static int __media_thumb_raw_data_send_request(void) { int err = MS_MEDIA_ERR_NONE; int sock = -1; @@ -540,10 +524,7 @@ static int _media_thumb_raw_data_send_request() int pid; err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("ms_ipc_create_client_socket failed"); - return err; - } + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed"); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sun_family = AF_UNIX; @@ -647,7 +628,7 @@ int _media_thumb_request_async(int msg_type, unsigned int request_id, const char g_queue_push_tail(g_manage_queue, (gpointer)thumb_req); if (len == 0) - err = _media_thumb_send_request(); + err = __media_thumb_send_request(); return err; } @@ -684,7 +665,7 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char g_queue_push_tail(g_manage_raw_queue, (gpointer)thumb_req); if (len == 0) - err = _media_thumb_raw_data_send_request(); + err = __media_thumb_raw_data_send_request(); return err; } |