summaryrefslogtreecommitdiff
path: root/src/ipc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipc')
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 2f56457..e9d7c0c 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -23,7 +23,6 @@
#include "media-thumb-ipc.h"
#include "media-thumb-util.h"
#include "media-thumb-db.h"
-#include "media-thumb-debug.h"
#include <glib.h>
#include <fcntl.h>
#include <string.h>
@@ -47,7 +46,7 @@ _media_thumb_create_socket(int sock_type, int *sock)
if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
thumb_err("socket failed: %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
if (sock_type == CLIENT_SOCKET) {
@@ -61,7 +60,7 @@ _media_thumb_create_socket(int sock_type, int *sock)
if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
thumb_err("setsockopt failed: %s", strerror(errno));
close(sock_fd);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
} else if (sock_type == SERVER_SOCKET) {
@@ -70,13 +69,13 @@ _media_thumb_create_socket(int sock_type, int *sock)
if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) {
thumb_err("setsockopt failed: %s", strerror(errno));
close(sock_fd);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
}
*sock = sock_fd;
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
}
@@ -87,7 +86,7 @@ _media_thumb_create_udp_socket(int *sock)
if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
thumb_err("socket failed: %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
#ifdef _USE_MEDIA_UTIL_
@@ -99,22 +98,22 @@ _media_thumb_create_udp_socket(int *sock)
if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
thumb_err("setsockopt failed: %s", strerror(errno));
close(sock_fd);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
*sock = sock_fd;
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
}
int _media_thumb_get_error()
{
if (errno == EWOULDBLOCK) {
thumb_err("Timeout. Can't try any more");
- return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
+ return MEDIA_THUMB_ERROR_TIMEOUT;
} else {
thumb_err("recvfrom failed : %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_RECEIVE;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
}
@@ -158,14 +157,14 @@ int __media_thumb_pop_req_queue(const char *path, bool shutdown_channel)
}
}
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
}
int __media_thumb_check_req_queue(const char *path)
{
int req_len = 0, i;
- if (g_request_queue == NULL) return MS_MEDIA_ERR_NONE;
+ if (g_request_queue == NULL) return MEDIA_THUMB_ERROR_NONE;
req_len = g_queue_get_length(g_request_queue);
// thumb_dbg("Queue length : %d", req_len);
@@ -182,14 +181,14 @@ int __media_thumb_check_req_queue(const char *path)
if (strncmp(path, req->path, strlen(path)) == 0) {
//thumb_dbg("Same Request - %s", path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return -1;
break;
}
}
}
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
}
int
@@ -235,7 +234,7 @@ _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
//thumb_dbg("destination path : %s", msg->dst_path);
SAFE_FREE(buf);
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
}
#ifdef _USE_UDS_SOCKET_
@@ -267,7 +266,7 @@ _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct socka
if (msg->origin_path_size <= 0 || msg->origin_path_size > MAX_PATH_SIZE) {
SAFE_FREE(buf);
thumb_err("msg->origin_path_size is invalid %d", msg->origin_path_size );
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
strncpy(msg->org_path, (char*)buf + header_size, msg->origin_path_size);
@@ -276,7 +275,7 @@ _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct socka
if (msg->dest_path_size <= 0 || msg->dest_path_size > MAX_PATH_SIZE) {
SAFE_FREE(buf);
thumb_err("msg->origin_path_size is invalid %d", msg->dest_path_size );
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
strncpy(msg->dst_path, (char*)buf + header_size + msg->origin_path_size, msg->dest_path_size);
@@ -285,14 +284,14 @@ _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct socka
SAFE_FREE(buf);
*from_size = from_addr_size;
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
}
int
_media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
{
if (req_msg == NULL || buf == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return -1;
}
int org_path_len = 0;
@@ -314,7 +313,7 @@ _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
*buf_size = size;
- return MS_MEDIA_ERR_NONE;
+ return 0;
}
int
@@ -331,7 +330,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
#endif
int recv_str_len = 0;
- int err = MS_MEDIA_ERR_NONE;
+ int err;
int pid;
@@ -344,13 +343,13 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) {
#endif
thumb_err("ms_ipc_create_client_socket failed");
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
#else
/* Creaete a TCP socket */
if (_media_thumb_create_socket(CLIENT_SOCKET, &sock) < 0) {
thumb_err("_media_thumb_create_socket failed");
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
#endif
@@ -380,7 +379,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
/* Connecting to the thumbnail server */
if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
thumb_err("connect error : %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
thumbMsg req_msg;
@@ -411,7 +410,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
close(sock);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
}
unsigned char *buf = NULL;
@@ -425,7 +424,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
thumb_err("sendto failed: %d\n", errno);
SAFE_FREE(buf);
close(sock);
- return MS_MEDIA_ERR_SOCKET_SEND;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
thumb_dbg("Sending msg to thumbnail daemon is successful");
@@ -445,12 +444,12 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
if (recv_str_len > max_length) {
thumb_err("user buffer is too small. Output's length is %d", recv_str_len);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
}
if (recv_msg.status == THUMB_FAIL) {
thumb_err("Failed to make thumbnail");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return -1;
}
if (msg_type != THUMB_REQUEST_SAVE_FILE) {
@@ -460,7 +459,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
thumb_info->origin_width = recv_msg.origin_width;
thumb_info->origin_height = recv_msg.origin_height;
- return MS_MEDIA_ERR_NONE;
+ return 0;
}
static int _mkdir(const char *dir, mode_t mode) {
@@ -537,7 +536,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
if (req_msg == NULL || res_msg == NULL) {
thumb_err("Invalid msg!");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
}
int msg_type = req_msg->msg_type;
@@ -552,22 +551,22 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
max_length = sizeof(res_msg->dst_path);
err = _media_thumb_db_connect(uid);
- if (err != MS_MEDIA_ERR_NONE) {
+ if (err < 0) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
- return MS_MEDIA_ERR_DB_CONNECT_FAIL;
+ return MEDIA_THUMB_ERROR_DB;
}
if (msg_type == THUMB_REQUEST_DB_INSERT) {
err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h);
- if (err == MS_MEDIA_ERR_NONE) {
+ if (err == 0) {
res_msg->origin_width = origin_w;
res_msg->origin_height = origin_h;
_media_thumb_db_disconnect();
- return MS_MEDIA_ERR_NONE;
+ return MEDIA_THUMB_ERROR_NONE;
} else {
if (strlen(thumb_path) == 0) {
err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid);
- if (err != MS_MEDIA_ERR_NONE) {
+ if (err < 0) {
thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length);
_media_thumb_db_disconnect();
@@ -600,7 +599,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
}
err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &gdkdata, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
- if (err != MS_MEDIA_ERR_NONE) {
+ if (err < 0) {
thumb_err("_thumbnail_get_data failed - %d\n", err);
if ( gdkdata != NULL ){
g_object_unref(gdkdata);
@@ -670,14 +669,14 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
/* DB update if needed */
if (need_update_db == 1) {
err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height, uid);
- if (err != MS_MEDIA_ERR_NONE) {
+ if (err < 0) {
thumb_err("_media_thumb_update_db failed : %d", err);
}
}
_media_thumb_db_disconnect();
- return MS_MEDIA_ERR_NONE;
+ return 0;
}
gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
@@ -686,7 +685,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
int header_size = 0;
int recv_str_len = 0;
int sock = 0;
- int err = MS_MEDIA_ERR_NONE;
+ int err = MEDIA_THUMB_ERROR_NONE;
memset((void *)&recv_msg, 0, sizeof(thumbMsg));
sock = g_io_channel_unix_get_fd(src);
@@ -711,7 +710,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
if (recv_msg.status == THUMB_FAIL) {
thumb_err("Failed to make thumbnail");
- err = MS_MEDIA_ERR_INTERNAL;
+ err = MEDIA_THUMB_ERROR_UNSUPPORTED;
goto callback;
}
@@ -743,7 +742,7 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
int pid;
if ((msg_type == THUMB_REQUEST_DB_INSERT) && (__media_thumb_check_req_queue(origin_path) < 0)) {
- return MS_MEDIA_ERR_THUMB_DUPLICATED_REQUEST;
+ return MEDIA_THUMB_ERROR_DUPLICATED_REQUEST;
}
#ifdef _USE_MEDIA_UTIL_
@@ -755,13 +754,13 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) {
#endif
thumb_err("ms_ipc_create_client_socket failed");
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
#else
/* Creaete a TCP socket */
if (_media_thumb_create_socket(CLIENT_SOCKET, &sock) < 0) {
thumb_err("_media_thumb_create_socket failed");
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
#endif
@@ -796,7 +795,7 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
thumb_err("connect error : %s", strerror(errno));
g_io_channel_shutdown(channel, TRUE, NULL);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) {
@@ -829,7 +828,7 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
g_io_channel_shutdown(channel, TRUE, NULL);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
}
unsigned char *buf = NULL;
@@ -843,7 +842,7 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
SAFE_FREE(buf);
g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
g_io_channel_shutdown(channel, TRUE, NULL);
- return MS_MEDIA_ERR_SOCKET_SEND;
+ return MEDIA_THUMB_ERROR_NETWORK;
}
SAFE_FREE(buf);
@@ -868,7 +867,7 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
thumb_req = calloc(1, sizeof(thumbReq));
if (thumb_req == NULL) {
thumb_err("Failed to create request element");
- return MS_MEDIA_ERR_NONE;
+ return 0;
}
thumb_req->channel = channel;
@@ -880,5 +879,6 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char
}
#endif
- return MS_MEDIA_ERR_NONE;
+ return 0;
}
+