From fdb9c2cb15133d7d547c29742d5753b98f4e30e6 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Fri, 22 Mar 2013 13:37:13 +0000 Subject: [PATCH] Define the livebox-errno LB_STATUS_XXXX series status codes are defined. This lb status codes are has to be shared with provider & master & viewer. (including all other packages which are related with livebox f/w) Change-Id: Ia45a7116d842897acbb029913b2eae8f44d13fd2 --- include/livebox-errno.h | 33 +++++ include/livebox.h | 2 +- src/client.c | 105 ++++++-------- src/critical_log.c | 9 +- src/desc_parser.c | 65 ++++----- src/fb.c | 61 ++++---- src/livebox.c | 364 ++++++++++++++++++++++++------------------------ src/master_rpc.c | 17 +-- src/util.c | 15 +- 9 files changed, 344 insertions(+), 327 deletions(-) create mode 100644 include/livebox-errno.h diff --git a/include/livebox-errno.h b/include/livebox-errno.h new file mode 100644 index 0000000..5362189 --- /dev/null +++ b/include/livebox-errno.h @@ -0,0 +1,33 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. + */ + +enum livebox_status { + LB_STATUS_SUCCESS = 0x00000000, + LB_STATUS_ERROR = 0x80000000, + LB_STATUS_ERROR_INVALID = LB_STATUS_ERROR | 0x0001, + LB_STATUS_ERROR_FAULT = LB_STATUS_ERROR | 0x0002, + LB_STATUS_ERROR_MEMORY = LB_STATUS_ERROR | 0x0004, + LB_STATUS_ERROR_EXIST = LB_STATUS_ERROR | 0x0008, + LB_STATUS_ERROR_BUSY = LB_STATUS_ERROR | 0x0010, + LB_STATUS_ERROR_PERMISSION = LB_STATUS_ERROR | 0x0020, + LB_STATUS_ERROR_ALREADY = LB_STATUS_ERROR | 0x0040, + LB_STATUS_ERROR_CANCEL = LB_STATUS_ERROR | 0x0080, + LB_STATUS_ERROR_IO = LB_STATUS_ERROR | 0x00100, +}; + +#define LB_STATUS_IS_ERROR(s) (!!((s) & LB_STATUS_ERROR)) + +/* End of a file */ diff --git a/include/livebox.h b/include/livebox.h index a3e11e6..400828d 100644 --- a/include/livebox.h +++ b/include/livebox.h @@ -163,7 +163,7 @@ struct livebox_script_operators { * Listed functions will be called when parser meets each typed component */ int (*update_text)(struct livebox *handle, const char *id, const char *part, const char *data); /*!< Update text content */ - int (*update_image)(struct livebox *handle, const char *id, const char *part, const char *data); /*!< Update image content */ + int (*update_image)(struct livebox *handle, const char *id, const char *part, const char *data, const char *option); /*!< Update image content */ int (*update_script)(struct livebox *handle, const char *id, const char *part, const char *file, const char *group); /*!< Update script content */ int (*update_signal)(struct livebox *handle, const char *id, const char *emission, const char *signal); /*!< Update signal */ int (*update_drag)(struct livebox *handle, const char *id, const char *part, double dx, double dy); /*!< Update drag info */ diff --git a/src/client.c b/src/client.c index e3370cc..f421fa9 100644 --- a/src/client.c +++ b/src/client.c @@ -37,6 +37,7 @@ #include "master_rpc.h" #include "conf.h" #include "critical_log.h" +#include "livebox-errno.h" static inline void make_connection(void); @@ -78,13 +79,12 @@ static struct packet *master_pinup(pid_t pid, int handle, const struct packet *p ret = packet_get(packet, "iisss", &ret, &pinup, &pkgname, &id, &content); if (ret != 5) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; goto out; } handler = lb_find_livebox(pkgname, id); if (!handler) { - ret = -ENOENT; + ErrPrint("Instance (%s) is not exists\n", id); goto out; } @@ -96,7 +96,7 @@ static struct packet *master_pinup(pid_t pid, int handle, const struct packet *p handler->is_pinned_up = pinup; } else { ErrPrint("Heap: %s\n", strerror(errno)); - ret = -ENOMEM; + ret = LB_STATUS_ERROR_MEMORY; } } @@ -105,11 +105,10 @@ static struct packet *master_pinup(pid_t pid, int handle, const struct packet *p handler->pinup_cb = NULL; /*!< Reset pinup cb */ handler->pinup_cbdata = NULL; - } else { + } else if (ret == 0) { lb_invoke_event_handler(handler, LB_EVENT_PINUP_CHANGED); } - ret = 0; out: return NULL; } @@ -169,14 +168,14 @@ static struct packet *master_deleted(pid_t pid, int handle, const struct packet handler->deleted_cbdata = NULL; } - DbgPrint("Call the created cb with -ECANCELED\n"); - handler->created_cb(handler, -ECANCELED, handler->created_cbdata); + DbgPrint("Call the created cb with LB_STATUS_ERROR_CANCEL\n"); + handler->created_cb(handler, LB_STATUS_ERROR_CANCEL, handler->created_cbdata); handler->created_cb = NULL; handler->created_cbdata = NULL; } else if (handler->id) { if (handler->deleted_cb) { DbgPrint("Call the deleted cb\n"); - handler->deleted_cb(handler, 0, handler->deleted_cbdata); + handler->deleted_cb(handler, LB_STATUS_SUCCESS, handler->deleted_cbdata); handler->deleted_cb = NULL; handler->deleted_cbdata = NULL; @@ -214,13 +213,12 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack &priority, &content, &title); if (ret != 8) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; goto out; } handler = lb_find_livebox(pkgname, id); if (!handler) { - ret = -ENOENT; + ErrPrint("instance(%s) is not exists\n", id); goto out; } @@ -231,7 +229,7 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack * Don't try to notice anything with this, Just ignore all events * Beacuse the user doesn't wants know about this anymore */ - ret = -EPERM; + DbgPrint("(%s) is not exists, but updated\n", id); goto out; } @@ -241,10 +239,11 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack if (lb_text_lb(handler)) { lb_set_size(handler, lb_w, lb_h); - ret = parse_desc(handler, livebox_filename(handler), 0); + (void)parse_desc(handler, livebox_filename(handler), 0); /*! * \note * DESC parser will call the "text event callback". + * Don't need to call global event callback in this case. */ goto out; } else if (lb_get_lb_fb(handler)) { @@ -252,7 +251,7 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack lb_set_lb_fb(handler, fbfile); ret = fb_sync(lb_get_lb_fb(handler)); if (ret < 0) - ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); + ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret); } else { lb_set_size(handler, lb_w, lb_h); ret = 0; @@ -284,12 +283,12 @@ static struct packet *master_pd_created(pid_t pid, int handle, const struct pack handler = lb_find_livebox(pkgname, id); if (!handler) { - ret = -ENOENT; + ErrPrint("Instance(%s) is not exists\n", id); goto out; } if (handler->state != CREATE) { - ret = -EPERM; + ErrPrint("Instance(%s) is not created\n", id); goto out; } @@ -299,11 +298,8 @@ static struct packet *master_pd_created(pid_t pid, int handle, const struct pack } else { (void)lb_set_pd_fb(handler, buf_id); ret = fb_sync(lb_get_pd_fb(handler)); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s)\n", - pkgname, - util_basename(util_uri_to_path(id))); - } + if (ret < 0) + ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); } handler->is_pd_created = (status == 0); @@ -319,7 +315,6 @@ static struct packet *master_pd_created(pid_t pid, int handle, const struct pack lb_invoke_event_handler(handler, LB_EVENT_PD_CREATED); } - ret = 0; out: return NULL; } @@ -340,12 +335,12 @@ static struct packet *master_pd_destroyed(pid_t pid, int handle, const struct pa handler = lb_find_livebox(pkgname, id); if (!handler) { - ret = -ENOENT; + ErrPrint("Instance(%s) is not exists\n", id); goto out; } if (handler->state != CREATE) { - ret = -EPERM; + ErrPrint("Instance(%s) is not created\n", id); goto out; } @@ -362,7 +357,6 @@ static struct packet *master_pd_destroyed(pid_t pid, int handle, const struct pa lb_invoke_event_handler(handler, LB_EVENT_PD_DESTROYED); } - ret = 0; out: return NULL; } @@ -384,13 +378,12 @@ static struct packet *master_pd_updated(pid_t pid, int handle, const struct pack &pd_w, &pd_h); if (ret != 6) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; goto out; } handler = lb_find_livebox(pkgname, id); if (!handler) { - ret = -ENOENT; + ErrPrint("Instance(%s) is not exists\n", id); goto out; } @@ -401,27 +394,22 @@ static struct packet *master_pd_updated(pid_t pid, int handle, const struct pack * So don't try to notice anything about this anymore. * Just ignore all events. */ - ret = -EPERM; + ErrPrint("Instance(%s) is not created\n", id); goto out; } lb_set_pdsize(handler, pd_w, pd_h); if (lb_text_pd(handler)) { - ret = parse_desc(handler, descfile, 1); + (void)parse_desc(handler, descfile, 1); } else { (void)lb_set_pd_fb(handler, fbfile); ret = fb_sync(lb_get_pd_fb(handler)); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s)\n", - pkgname, - util_basename(util_uri_to_path(id))); - goto out; - } - - lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED); - ret = 0; + if (ret < 0) + ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); + else + lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED); } out: @@ -441,14 +429,12 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa if (!packet) { ErrPrint("Invalid packet\n"); - ret = -EINVAL; goto out; } ret = packet_get(packet, "ssiiii", &pkgname, &id, &is_pd, &w, &h, &status); if (ret != 6) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; goto out; } @@ -456,14 +442,12 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa handler = lb_find_livebox(pkgname, id); if (!handler) { - ErrPrint("Livebox(%s - %s) is not found\n", pkgname, id); - ret = -ENOENT; + ErrPrint("Livebox(%s) is not found\n", id); goto out; } if (handler->state != CREATE) { - ErrPrint("Hander is not created yet\n"); - ret = -EPERM; + ErrPrint("Livebox(%s) is not created yet\n", id); goto out; } @@ -480,7 +464,7 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa lb_set_pdsize(handler, w, h); lb_invoke_event_handler(handler, LB_EVENT_PD_SIZE_CHANGED); } else { - ErrPrint("This is not possible. PD Size is changed but the return value is not ZERO\n"); + ErrPrint("This is not possible. PD Size is changed but the return value is not ZERO (%d)\n", status); } } else { if (status == 0) { @@ -493,7 +477,7 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa * Update it too. */ if (lb_get_lb_fb(handler)) - lb_set_lb_fb(handler, id); + (void)lb_set_lb_fb(handler, id); /*! * \NOTE @@ -535,19 +519,17 @@ static struct packet *master_period_changed(pid_t pid, int handle, const struct ret = packet_get(packet, "idss", &status, &period, &pkgname, &id); if (ret != 4) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; goto out; } handler = lb_find_livebox(pkgname, id); if (!handler) { - ErrPrint("Livebox(%s - %s) is not found\n", pkgname, id); - ret = -ENOENT; + ErrPrint("Livebox(%s) is not found\n", id); goto out; } if (handler->state != CREATE) { - ret = -EPERM; + ErrPrint("Livebox(%s) is not created\n", id); goto out; } @@ -560,12 +542,10 @@ static struct packet *master_period_changed(pid_t pid, int handle, const struct handler->period_changed_cb = NULL; handler->period_cbdata = NULL; - } else { + } else if (status == 0) { lb_invoke_event_handler(handler, LB_EVENT_PERIOD_CHANGED); } - ret = 0; - out: return NULL; } @@ -583,13 +563,12 @@ static struct packet *master_group_changed(pid_t pid, int handle, const struct p ret = packet_get(packet, "ssiss", &pkgname, &id, &status, &cluster, &category); if (ret != 5) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; goto out; } handler = lb_find_livebox(pkgname, id); if (!handler) { - ret = -ENOENT; + ErrPrint("Livebox(%s) is not exists\n", id); goto out; } @@ -599,25 +578,23 @@ static struct packet *master_group_changed(pid_t pid, int handle, const struct p * Do no access this handler, * You cannot believe this handler anymore. */ - ret = -EPERM; + ErrPrint("Livebox(%s) is not created\n", id); goto out; } DbgPrint("Group is changed? [%s] / [%s] (%d)\n", cluster, category, status); if (status == 0) - lb_set_group(handler, cluster, category); + (void)lb_set_group(handler, cluster, category); if (handler->group_changed_cb) { handler->group_changed_cb(handler, status, handler->group_cbdata); handler->group_changed_cb = NULL; handler->group_cbdata = NULL; - } else { + } else if (status == 0) { lb_invoke_event_handler(handler, LB_EVENT_GROUP_CHANGED); } - ret = 0; - out: return NULL; } @@ -664,7 +641,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet &lb_type, &pd_type, &period, &title, &is_pinned_up); if (ret != 22) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; goto out; } @@ -684,7 +661,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet handler = lb_new_livebox(pkgname, id, timestamp); if (!handler) { ErrPrint("Failed to create a new livebox\n"); - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; goto out; } @@ -697,7 +674,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet * This is not possible!!! */ ErrPrint("Invalid handler\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; goto out; } @@ -718,7 +695,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet content, cluster, category, lb_fname, pd_fname); - ret = -EALREADY; + ret = LB_STATUS_ERROR_ALREADY; goto out; } @@ -818,7 +795,7 @@ out: * Do not clear this to use this from the deleted event callback. * if this value is not cleared when the deleted event callback check it, * it means that the created function is not called yet. - * Then the call the deleted event callback with -ECANCELED errno. + * Then the call the deleted event callback with LB_STATUS_ERROR_CANCEL errno. */ } diff --git a/src/critical_log.c b/src/critical_log.c index 8b626c5..91610f9 100644 --- a/src/critical_log.c +++ b/src/critical_log.c @@ -30,6 +30,7 @@ #include "debug.h" #include "util.h" #include "critical_log.h" +#include "livebox-errno.h" /* For error code */ static struct { FILE *fp; @@ -52,7 +53,7 @@ int critical_log(const char *func, int line, const char *fmt, ...) struct timeval tv; if (!s_info.fp) - return -EIO; + return LB_STATUS_ERROR_IO; gettimeofday(&tv, NULL); fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, util_basename((char *)func), line); @@ -101,7 +102,7 @@ int critical_log_init(const char *name) s_info.filename = strdup(name); if (!s_info.filename) { ErrPrint("Failed to create a log file\n"); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } namelen = strlen(name) + strlen(SLAVE_LOG_PATH) + 20; @@ -111,7 +112,7 @@ int critical_log_init(const char *name) ErrPrint("Failed to create a log file\n"); free(s_info.filename); s_info.filename = NULL; - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, name); @@ -122,7 +123,7 @@ int critical_log_init(const char *name) free(s_info.filename); s_info.filename = NULL; free(filename); - return -EIO; + return LB_STATUS_ERROR_IO; } free(filename); diff --git a/src/desc_parser.c b/src/desc_parser.c index 25595c0..660cee6 100644 --- a/src/desc_parser.c +++ b/src/desc_parser.c @@ -29,6 +29,7 @@ #include "dlist.h" #include "util.h" #include "critical_log.h" +#include "livebox-errno.h" #define TYPE_TEXT "text" #define TYPE_IMAGE "image" @@ -53,8 +54,8 @@ struct block { char *file; int file_len; - char *group; - int group_len; + char *option; + int option_len; char *id; int id_len; @@ -66,7 +67,7 @@ static int update_text(struct livebox *handle, struct block *block, int is_pd) if (!block || !block->part || !block->data) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops; @@ -81,12 +82,12 @@ static int update_image(struct livebox *handle, struct block *block, int is_pd) struct livebox_script_operators *ops; if (!block || !block->part) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops; if (ops->update_image) - ops->update_image(handle, block->id, block->part, block->data); + ops->update_image(handle, block->id, block->part, block->data, block->option); return 0; } @@ -96,12 +97,12 @@ static int update_script(struct livebox *handle, struct block *block, int is_pd) struct livebox_script_operators *ops; if (!block || !block->part) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops; if (ops->update_script) - ops->update_script(handle, block->id, block->part, block->data, block->group); + ops->update_script(handle, block->id, block->part, block->data, block->option); return 0; } @@ -112,7 +113,7 @@ static int update_signal(struct livebox *handle, struct block *block, int is_pd) if (!block) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops; @@ -129,14 +130,14 @@ static int update_drag(struct livebox *handle, struct block *block, int is_pd) if (!block || !block->data || !block->part) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops; if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) { ErrPrint("Invalid format of data\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (ops->update_drag) @@ -151,7 +152,7 @@ static int update_info(struct livebox *handle, struct block *block, int is_pd) if (!block || !block->part || !block->data) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops; @@ -161,7 +162,7 @@ static int update_info(struct livebox *handle, struct block *block, int is_pd) if (sscanf(block->data, "%dx%d", &w, &h) != 2) { ErrPrint("Invalid format (%s)\n", block->data); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (ops->update_info_size) @@ -214,7 +215,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) VALUE_PART = 0x01, VALUE_DATA = 0x02, VALUE_FILE = 0x03, - VALUE_GROUP = 0x04, + VALUE_OPTION = 0x04, VALUE_ID = 0x05, }; const char *field_name[] = { @@ -222,7 +223,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) "part", "data", "file", - "group", + "option", "id", NULL }; @@ -268,7 +269,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) fp = fopen(descfile, "rt"); if (!fp) { ErrPrint("Error: %s\n", strerror(errno)); - return -EIO; + return LB_STATUS_ERROR_IO; } update_begin(handle, is_pd); @@ -290,7 +291,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) if (!isspace(ch)) { update_end(handle, is_pd); fclose(fp); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } break; @@ -306,7 +307,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) CRITICAL_LOG("Heap: %s\n", strerror(errno)); update_end(handle, is_pd); fclose(fp); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } state = FIELD; @@ -365,11 +366,11 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) idx = 0; break; case 4: - state = VALUE_GROUP; - if (block->group) { - free(block->group); - block->group = NULL; - block->group_len = 0; + state = VALUE_OPTION; + if (block->option) { + free(block->option); + block->option = NULL; + block->option_len = 0; } idx = 0; break; @@ -496,25 +497,25 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) idx++; break; - case VALUE_GROUP: - if (idx == block->group_len) { - block->group_len += 256; - block->group = realloc(block->group, block->group_len); - if (!block->group) { + case VALUE_OPTION: + if (idx == block->option_len) { + block->option_len += 256; + block->option = realloc(block->option, block->option_len); + if (!block->option) { CRITICAL_LOG("Heap: %s\n", strerror(errno)); goto errout; } } if (ch == '\n') { - block->group[idx] = '\0'; + block->option[idx] = '\0'; state = FIELD; idx = 0; field_idx = 0; break; } - block->group[idx] = ch; + block->option[idx] = ch; idx++; break; case VALUE_ID: @@ -561,7 +562,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd) free(block->type); free(block->part); free(block->data); - free(block->group); + free(block->option); free(block->id); free(block); block = NULL; @@ -589,7 +590,7 @@ errout: free(block->type); free(block->part); free(block->data); - free(block->group); + free(block->option); free(block->id); free(block); } @@ -597,7 +598,7 @@ errout: update_end(handle, is_pd); fclose(fp); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } /* End of a file */ diff --git a/src/fb.c b/src/fb.c index 1e687ef..9d2204d 100644 --- a/src/fb.c +++ b/src/fb.c @@ -37,6 +37,7 @@ #include "util.h" #include "fb.h" #include "critical_log.h" +#include "livebox-errno.h" /* For error code */ int errno; @@ -113,16 +114,16 @@ static inline int sync_for_file(struct fb_info *info) buffer = info->buffer; if (!buffer) /* Ignore this sync request */ - return 0; + return LB_STATUS_SUCCESS; if (buffer->state != CREATED) { ErrPrint("Invalid state of a FB\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (buffer->type != BUFFER_TYPE_FILE) { DbgPrint("Invalid buffer\n"); - return 0; + return LB_STATUS_SUCCESS; } fd = open(util_uri_to_path(info->id), O_RDONLY); @@ -137,7 +138,7 @@ static inline int sync_for_file(struct fb_info *info) * * and then update it after it gots update events */ - return 0; + return LB_STATUS_SUCCESS; } if (read(fd, buffer->data, info->bufsz) != info->bufsz) { @@ -151,11 +152,11 @@ static inline int sync_for_file(struct fb_info *info) * * and then update it after it gots update events */ - return 0; + return LB_STATUS_SUCCESS; } close(fd); - return 0; + return LB_STATUS_SUCCESS; } static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info *info) @@ -166,16 +167,16 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info buffer = info->buffer; if (!buffer) /*!< Ignore this sync request */ - return 0; + return LB_STATUS_SUCCESS; if (buffer->state != CREATED) { ErrPrint("Invalid state of a FB\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (buffer->type != BUFFER_TYPE_PIXMAP) { DbgPrint("Invalid buffer\n"); - return 0; + return LB_STATUS_SUCCESS; } if (!s_info.disp) { @@ -191,24 +192,24 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info s_info.visual = DefaultVisualOfScreen(screen); } else { ErrPrint("Failed to open a display\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } } if (info->handle == 0) { DbgPrint("Pixmap ID is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (info->bufsz == 0) { DbgPrint("Nothing can be sync\n"); - return 0; + return LB_STATUS_SUCCESS; } si.shmid = shmget(IPC_PRIVATE, info->bufsz, IPC_CREAT | 0666); if (si.shmid < 0) { ErrPrint("shmget: %s\n", strerror(errno)); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } si.readOnly = False; @@ -218,7 +219,7 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info if (shmctl(si.shmid, IPC_RMID, 0) < 0) ErrPrint("shmctl: %s\n", strerror(errno)); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } /*! @@ -236,7 +237,7 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info if (shmctl(si.shmid, IPC_RMID, 0) < 0) ErrPrint("shmctl: %s\n", strerror(errno)); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } xim->data = si.shmaddr; @@ -256,19 +257,19 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info if (shmctl(si.shmid, IPC_RMID, 0) < 0) ErrPrint("shmctl: %s\n", strerror(errno)); - return 0; + return LB_STATUS_SUCCESS; } int fb_sync(struct fb_info *info) { if (!info) { ErrPrint("FB Handle is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!info->id || info->id[0] == '\0') { DbgPrint("Ingore sync\n"); - return 0; + return LB_STATUS_SUCCESS; } if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { @@ -277,10 +278,10 @@ int fb_sync(struct fb_info *info) return sync_for_pixmap(info); } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { /* No need to do sync */ - return 0; + return LB_STATUS_SUCCESS; } - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } struct fb_info *fb_create(const char *id, int w, int h) @@ -310,7 +311,7 @@ struct fb_info *fb_create(const char *id, int w, int h) } else if (sscanf(info->id, SCHEMA_PIXMAP "%d", &info->handle) == 1) { DbgPrint("PIXMAP-SHMID: %d is gotten\n", info->handle); } else { - info->handle = -EINVAL; + info->handle = LB_STATUS_ERROR_INVALID; } info->bufsz = 0; @@ -325,7 +326,7 @@ int fb_destroy(struct fb_info *info) { if (!info) { ErrPrint("Handle is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (info->buffer) { @@ -337,7 +338,7 @@ int fb_destroy(struct fb_info *info) free(info->id); free(info); - return 0; + return LB_STATUS_SUCCESS; } int fb_is_created(struct fb_info *info) @@ -454,7 +455,7 @@ int fb_release_buffer(void *data) if (buffer->state != CREATED) { ErrPrint("Invalid handle\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } switch (buffer->type) { @@ -503,20 +504,20 @@ int fb_refcnt(void *data) int ret; if (!data) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; buffer = container_of(data, struct buffer, data); if (buffer->state != CREATED) { ErrPrint("Invalid handle\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } switch (buffer->type) { case BUFFER_TYPE_SHM: if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) { ErrPrint("Error: %s\n", strerror(errno)); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } ret = buf.shm_nattch; @@ -528,7 +529,7 @@ int fb_refcnt(void *data) ret = buffer->refcnt; break; default: - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; break; } @@ -544,12 +545,12 @@ int fb_get_size(struct fb_info *info, int *w, int *h) { if (!info) { ErrPrint("Handle is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } *w = info->w; *h = info->h; - return 0; + return LB_STATUS_SUCCESS; } int fb_size(struct fb_info *info) diff --git a/src/livebox.c b/src/livebox.c index da3ebef..c9246bc 100644 --- a/src/livebox.c +++ b/src/livebox.c @@ -36,6 +36,7 @@ #include "master_rpc.h" #include "client.h" #include "critical_log.h" +#include "livebox-errno.h" #define EAPI __attribute__((visibility("default"))) #define MINIMUM_EVENT s_info.event_filter @@ -147,10 +148,10 @@ static void resize_cb(struct livebox *handler, const struct packet *result, void destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } /*! @@ -184,10 +185,10 @@ static void text_signal_cb(struct livebox *handler, const struct packet *result, destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (cb) @@ -207,10 +208,10 @@ static void set_group_ret_cb(struct livebox *handler, const struct packet *resul destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (ret == 0) { /*!< Group information is successfully changed */ @@ -235,10 +236,10 @@ static void period_ret_cb(struct livebox *handler, const struct packet *result, destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (ret == 0) { @@ -262,10 +263,10 @@ static void del_ret_cb(struct livebox *handler, const struct packet *result, voi if (!result) { ErrPrint("Connection lost?\n"); - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { ErrPrint("Invalid argument\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (ret == 0) { @@ -299,9 +300,9 @@ static void new_ret_cb(struct livebox *handler, const struct packet *result, voi destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (ret >= 0) { @@ -339,9 +340,9 @@ static void pd_create_cb(struct livebox *handler, const struct packet *result, v destroy_cb_info(data); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (ret == 0) { @@ -367,9 +368,9 @@ static void activated_cb(struct livebox *handler, const struct packet *result, v destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "is", &ret, &pkgname) != 2) { - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (cb) @@ -389,10 +390,10 @@ static void pd_destroy_cb(struct livebox *handler, const struct packet *result, if (!result) { DbgPrint("Result is NIL (may connection lost)\n"); - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { DbgPrint("Invalid parameter\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } if (ret == 0) { @@ -418,9 +419,9 @@ static void delete_cluster_cb(struct livebox *handler, const struct packet *resu destroy_cb_info(info); if (!result) { - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } else if (packet_get(result, "i", &ret) != 1) { - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } DbgPrint("Delete category returns: %d\n", ret); @@ -441,9 +442,9 @@ static void delete_category_cb(struct livebox *handler, const struct packet *res destroy_cb_info(info); if (!result) - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; else if (packet_get(result, "i", &ret) != 1) - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; DbgPrint("Delete category returns: %d\n", ret); @@ -483,9 +484,9 @@ static void pinup_done_cb(struct livebox *handler, const struct packet *result, destroy_cb_info(info); if (!result) - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; else if (packet_get(result, "i", &ret) != 1) - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; if (ret == 0) { handler->pinup_cb = cb; @@ -504,7 +505,7 @@ static int send_mouse_event(struct livebox *handler, const char *event, int x, i packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y); if (!packet) { ErrPrint("Failed to build param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } DbgPrint("Send: %dx%d\n", x, y); @@ -518,7 +519,7 @@ EAPI int livebox_init(void *disp) if (s_info.init_count > 0) { s_info.init_count++; - return 0; + return LB_STATUS_SUCCESS; } env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE"); if (env && !strcasecmp(env, "true")) @@ -542,27 +543,27 @@ EAPI int livebox_init(void *disp) client_init(); s_info.init_count++; - return 0; + return LB_STATUS_SUCCESS; } EAPI int livebox_fini(void) { if (s_info.init_count <= 0) { DbgPrint("Didn't initialized\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } s_info.init_count--; if (s_info.init_count > 0) { DbgPrint("init count : %d\n", s_info.init_count); - return 0; + return LB_STATUS_SUCCESS; } client_fini(); fb_fini(); livebox_service_fini(); critical_log_fini(); - return 0; + return LB_STATUS_SUCCESS; } static inline char *lb_pkgname(const char *pkgname) @@ -717,28 +718,28 @@ EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, if (!handler || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->period_changed_cb) { ErrPrint("Previous request for changing period is not finished\n"); - return -EBUSY; + return LB_STATUS_ERROR_BUSY; } if (!handler->is_user) { ErrPrint("CA Livebox is not able to change the period\n"); - return -EPERM; + return LB_STATUS_ERROR_PERMISSION; } if (handler->lb.period == period) { DbgPrint("No changes\n"); - return -EALREADY; + return LB_STATUS_ERROR_ALREADY; } packet = packet_create("set_period", "ssd", handler->pkgname, handler->id, period); if (!packet) { ErrPrint("Failed to build a packet %s\n", handler->pkgname); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -751,12 +752,12 @@ EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE) { ErrPrint("Handler is already deleted\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } handler->state = DELETE; @@ -773,7 +774,7 @@ EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data) */ if (cb) cb(handler, 0, data); - return 0; + return LB_STATUS_SUCCESS; } if (!cb) @@ -787,19 +788,19 @@ EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char struct fault_info *info; if (!cb) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; info = malloc(sizeof(*info)); if (!info) { CRITICAL_LOG("Heap: %s\n", strerror(errno)); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } info->handler = cb; info->user_data = data; s_info.fault_list = dlist_append(s_info.fault_list, info); - return 0; + return LB_STATUS_SUCCESS; } EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *)) @@ -827,20 +828,20 @@ EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_even if (!cb) { ErrPrint("Invalid argument cb is nil\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } info = malloc(sizeof(*info)); if (!info) { CRITICAL_LOG("Heap: %s\n", strerror(errno)); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } info->handler = cb; info->user_data = data; s_info.event_list = dlist_append(s_info.event_list, info); - return 0; + return LB_STATUS_SUCCESS; } EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *)) @@ -871,38 +872,38 @@ EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *da if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->size_changed_cb) { ErrPrint("Previous resize request is not finished yet\n"); - return -EBUSY; + return LB_STATUS_ERROR_BUSY; } if (!handler->is_user) { ErrPrint("CA Livebox is not able to be resized\n"); - return -EPERM; + return LB_STATUS_ERROR_PERMISSION; } if (livebox_service_get_size(type, &w, &h) != 0) { ErrPrint("Invalid size type\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->lb.width == w && handler->lb.height == h) { DbgPrint("No changes\n"); - return -EALREADY; + return LB_STATUS_ERROR_ALREADY;; } packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h); if (!packet) { ErrPrint("Failed to build param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -919,12 +920,12 @@ EAPI int livebox_click(struct livebox *handler, double x, double y) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->lb.auto_launch) @@ -935,10 +936,11 @@ EAPI int livebox_click(struct livebox *handler, double x, double y) packet = packet_create_noack("clicked", "sssddd", handler->pkgname, handler->id, "clicked", timestamp, x, y); if (!packet) { ErrPrint("Failed to build param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } ret = master_rpc_request_only(handler, packet); + DbgPrint("Click request: %d\n", ret); if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) { int ret; /* Shadow variable */ @@ -962,12 +964,12 @@ EAPI int livebox_has_pd(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } return !!handler->pd.data.fb; @@ -977,12 +979,12 @@ EAPI int livebox_pd_is_created(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } return handler->is_pd_created; @@ -999,23 +1001,23 @@ EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, doub if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->is_pd_created == 1) { DbgPrint("PD already created\n"); - return 0; + return LB_STATUS_SUCCESS; } packet = packet_create("create_pd", "ssdd", handler->pkgname, handler->id, x, y); if (!packet) { ErrPrint("Failed to build param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -1030,23 +1032,23 @@ EAPI int livebox_move_pd(struct livebox *handler, double x, double y) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->is_pd_created) { DbgPrint("PD is not created\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y); if (!packet) { ErrPrint("Failed to build param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(handler, packet); @@ -1057,12 +1059,12 @@ EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data) struct packet *packet; if (!pkgname) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; packet = packet_create("activate_package", "s", pkgname); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_async_request(NULL, packet, 0, activated_cb, create_cb_info(cb, data)); @@ -1074,23 +1076,23 @@ EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->is_pd_created) { ErrPrint("PD is not created\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } packet = packet_create("destroy_pd", "ss", handler->pkgname, handler->id); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -1108,12 +1110,12 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (type & CONTENT_EVENT_PD_MASK) { @@ -1121,18 +1123,18 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type if (!handler->is_pd_created) { ErrPrint("PD is not created\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (type & CONTENT_EVENT_MOUSE_MASK) { if (!handler->pd.data.fb) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (type & CONTENT_EVENT_MOUSE_MOVE) { if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT) - return -EBUSY; + return LB_STATUS_ERROR_BUSY; } else if (type & CONTENT_EVENT_MOUSE_SET) { flag = 0; } @@ -1152,17 +1154,17 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type if (type & CONTENT_EVENT_MOUSE_MASK) { if (!handler->lb.mouse_event) { ErrPrint("Box is not support the mouse event\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!handler->lb.data.fb) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (type & CONTENT_EVENT_MOUSE_MOVE) { if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT) - return -EBUSY; + return LB_STATUS_ERROR_BUSY; } else if (type & CONTENT_EVENT_MOUSE_SET) { flag = 0; } @@ -1226,7 +1228,7 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type break; default: ErrPrint("Invalid event type\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } return send_mouse_event(handler, cmd, x * w, y * h); @@ -1258,12 +1260,12 @@ EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!w) @@ -1280,7 +1282,7 @@ EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h) *h = handler->pd.height; } - return 0; + return LB_STATUS_SUCCESS; } EAPI int livebox_size(struct livebox *handler) @@ -1290,12 +1292,12 @@ EAPI int livebox_size(struct livebox *handler) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } w = handler->lb.width; @@ -1323,33 +1325,33 @@ EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const c if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!cluster || !category || handler->state != CREATE || !handler->id) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->group_changed_cb) { ErrPrint("Previous group changing request is not finished yet\n"); - return -EBUSY; + return LB_STATUS_ERROR_BUSY; } if (!handler->is_user) { ErrPrint("CA Livebox is not able to change the group\n"); - return -EPERM; + return LB_STATUS_ERROR_PERMISSION; } if (!strcmp(handler->cluster, cluster) && !strcmp(handler->category, category)) { DbgPrint("No changes\n"); - return -EALREADY; + return LB_STATUS_ERROR_ALREADY; } packet = packet_create("change_group", "ssss", handler->pkgname, handler->id, cluster, category); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -1362,17 +1364,17 @@ EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!cluster || !category || handler->state != CREATE || !handler->id) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } *cluster = handler->cluster; *category = handler->category; - return 0; + return LB_STATUS_SUCCESS; } EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list) @@ -1382,12 +1384,12 @@ EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *siz if (!handler || !size_list) { ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!cnt || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } for (j = i = 0; i < NR_OF_SIZE_LIST; i++) { @@ -1400,7 +1402,7 @@ EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *siz } *cnt = j; - return 0; + return LB_STATUS_SUCCESS; } EAPI const char *livebox_pkgname(struct livebox *handler) @@ -1440,7 +1442,7 @@ EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data) packet = packet_create("delete_cluster", "s", cluster); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, create_cb_info(cb, data)); @@ -1453,7 +1455,7 @@ EAPI int livebox_delete_category(const char *cluster, const char *category, ret_ packet = packet_create("delete_category", "ss", cluster, category); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_async_request(NULL, packet, 0, delete_category_cb, create_cb_info(cb, data)); @@ -1527,32 +1529,32 @@ EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_scr { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } memcpy(&handler->pd.data.ops, ops, sizeof(*ops)); - return 0; + return LB_STATUS_SUCCESS; } EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } memcpy(&handler->lb.data.ops, ops, sizeof(*ops)); - return 0; + return LB_STATUS_SUCCESS; } EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data) @@ -1562,27 +1564,27 @@ EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *d if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Invalid handle\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) { ErrPrint("Handler is not valid type\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } id = fb_id(handler->lb.data.fb); if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; packet = packet_create("lb_acquire_pixmap", "ss", handler->pkgname, handler->id); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data)); @@ -1594,23 +1596,23 @@ EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Invalid handle\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) { ErrPrint("Handler is not valid type\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } packet = packet_create_noack("lb_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_INVALID; } return master_rpc_request_only(handler, packet); @@ -1623,27 +1625,27 @@ EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *d if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Invalid handle\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) { ErrPrint("Handler is not valid type\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } id = fb_id(handler->pd.data.fb); if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; packet = packet_create("pd_acquire_pixmap", "ss", handler->pkgname, handler->id); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_async_request(handler, packet, 0, pixmap_acquired_cb, create_cb_info(cb, data)); @@ -1713,23 +1715,23 @@ EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap) if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Invalid handle\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) { ErrPrint("Handler is not valid type\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } packet = packet_create_noack("pd_release_pixmap", "ssi", handler->pkgname, handler->id, pixmap); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(handler, packet); @@ -1799,12 +1801,12 @@ EAPI int livebox_pdfb_bufsz(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } return fb_size(handler->pd.data.fb); @@ -1814,12 +1816,12 @@ EAPI int livebox_lbfb_bufsz(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } return fb_size(handler->lb.data.fb); @@ -1829,12 +1831,12 @@ EAPI int livebox_is_user(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE) { ErrPrint("Handler is invalid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } return handler->is_user; @@ -1846,28 +1848,28 @@ EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->pinup_cb) { ErrPrint("Previous pinup request is not finished\n"); - return -EBUSY; + return LB_STATUS_ERROR_BUSY; } if (handler->is_pinned_up == flag) { DbgPrint("No changes\n"); - return -EALREADY; + return LB_STATUS_ERROR_ALREADY; } packet = packet_create("pinup_changed", "ssi", handler->pkgname, handler->id, flag); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -1880,11 +1882,11 @@ EAPI int livebox_is_pinned_up(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; return handler->is_pinned_up; } @@ -1893,11 +1895,11 @@ EAPI int livebox_has_pinup(struct livebox *handler) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; return handler->lb.pinup_supported; } @@ -1906,14 +1908,14 @@ EAPI int livebox_set_data(struct livebox *handler, void *data) { if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; handler->data = data; - return 0; + return LB_STATUS_SUCCESS; } EAPI void *livebox_get_data(struct livebox *handler) @@ -1974,12 +1976,12 @@ EAPI int livebox_emit_text_signal(struct livebox *handler, const char *emission, if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) { ErrPrint("Handler is not valid\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!emission) @@ -1992,7 +1994,7 @@ EAPI int livebox_emit_text_signal(struct livebox *handler, const char *emission, handler->pkgname, handler->id, emission, source, sx, sy, ex, ey); if (!packet) { ErrPrint("Failed to build a param\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_async_request(handler, packet, 0, text_signal_cb, create_cb_info(cb, data)); @@ -2011,7 +2013,7 @@ EAPI int livebox_subscribe_group(const char *cluster, const char *category) packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : ""); if (!packet) { ErrPrint("Failed to create a packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(NULL, packet); @@ -2031,7 +2033,7 @@ EAPI int livebox_unsubscribe_group(const char *cluster, const char *category) packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : ""); if (!packet) { ErrPrint("Failed to create a packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(NULL, packet); @@ -2043,16 +2045,16 @@ EAPI int livebox_refresh(struct livebox *handler) if (!handler) { ErrPrint("Hnalder is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; packet = packet_create_noack("update", "ss", handler->pkgname, handler->id); if (!packet) { ErrPrint("Failed to create a packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(handler, packet); @@ -2064,13 +2066,13 @@ EAPI int livebox_refresh_group(const char *cluster, const char *category) if (!cluster || !category) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } packet = packet_create_noack("refresh_group", "ss", cluster, category); if (!packet) { ErrPrint("Failed to create a packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(NULL, packet); @@ -2083,29 +2085,29 @@ EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_st if (!handler) { ErrPrint("Handler is NIL\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->state != CREATE || !handler->id) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; if (!handler->is_user) { /* System cluster livebox cannot be changed its visible states */ if (state == LB_HIDE_WITH_PAUSE) { ErrPrint("CA Livebox is not able to change the visibility\n"); - return -EPERM; + return LB_STATUS_ERROR_PERMISSION; } } DbgPrint("Change the visibility %d <> %d, %s\n", handler->visible, state, handler->id); if (handler->visible == state) - return 0; + return LB_STATUS_ERROR_ALREADY; packet = packet_create_noack("change,visibility", "ssi", handler->pkgname, handler->id, (int)state); if (!packet) { ErrPrint("Failed to create a packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } ret = master_rpc_request_only(handler, packet); @@ -2137,7 +2139,7 @@ int lb_set_group(struct livebox *handler, const char *cluster, const char *categ pc = strdup(cluster); if (!pc) { CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } } @@ -2146,7 +2148,7 @@ int lb_set_group(struct livebox *handler, const char *cluster, const char *categ if (!ps) { CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category); free(pc); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } } @@ -2159,7 +2161,7 @@ int lb_set_group(struct livebox *handler, const char *cluster, const char *categ handler->cluster = pc; handler->category = ps; - return 0; + return LB_STATUS_SUCCESS; } void lb_set_size(struct livebox *handler, int w, int h) @@ -2329,7 +2331,7 @@ int lb_delete_all(void) lb_unref(handler); } - return 0; + return LB_STATUS_SUCCESS; } int lb_set_content(struct livebox *handler, const char *content) @@ -2343,11 +2345,11 @@ int lb_set_content(struct livebox *handler, const char *content) handler->content = strdup(content); if (!handler->content) { CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } } - return 0; + return LB_STATUS_SUCCESS; } int lb_set_title(struct livebox *handler, const char *title) @@ -2361,11 +2363,11 @@ int lb_set_title(struct livebox *handler, const char *title) handler->title = strdup(title); if (!handler->title) { CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } } - return 0; + return LB_STATUS_SUCCESS; } void lb_set_size_list(struct livebox *handler, int size_list) @@ -2413,18 +2415,18 @@ int lb_set_lb_fb(struct livebox *handler, const char *filename) struct fb_info *fb; if (!handler) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; fb = handler->lb.data.fb; if (fb && !strcmp(fb_id(fb), filename)) /*!< BUFFER is not changed, */ - return 0; + return LB_STATUS_SUCCESS; handler->lb.data.fb = NULL; if (!filename || filename[0] == '\0') { if (fb) fb_destroy(fb); - return 0; + return LB_STATUS_SUCCESS; } handler->lb.data.fb = fb_create(filename, handler->lb.width, handler->lb.height); @@ -2432,13 +2434,13 @@ int lb_set_lb_fb(struct livebox *handler, const char *filename) ErrPrint("Faield to create a FB\n"); if (fb) fb_destroy(fb); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (fb) fb_destroy(fb); - return 0; + return LB_STATUS_SUCCESS; } int lb_set_pd_fb(struct livebox *handler, const char *filename) @@ -2446,19 +2448,19 @@ int lb_set_pd_fb(struct livebox *handler, const char *filename) struct fb_info *fb; if (!handler) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; fb = handler->pd.data.fb; if (fb && !strcmp(fb_id(fb), filename)) { /* BUFFER is not changed, just update the content */ - return -EEXIST; + return LB_STATUS_ERROR_EXIST; } handler->pd.data.fb = NULL; if (!filename || filename[0] == '\0') { if (fb) fb_destroy(fb); - return 0; + return LB_STATUS_SUCCESS; } handler->pd.data.fb = fb_create(filename, handler->pd.width, handler->pd.height); @@ -2466,12 +2468,12 @@ int lb_set_pd_fb(struct livebox *handler, const char *filename) ErrPrint("Failed to create a FB\n"); if (fb) fb_destroy(fb); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (fb) fb_destroy(fb); - return 0; + return LB_STATUS_SUCCESS; } struct fb_info *lb_get_lb_fb(struct livebox *handler) @@ -2567,21 +2569,21 @@ int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data) if (!cb && !!data) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (handler->deleted_cb) { ErrPrint("Already in-progress\n"); - return -EINPROGRESS; + return LB_STATUS_ERROR_BUSY; } packet = packet_create("delete", "ss", handler->pkgname, handler->id); if (!packet) { ErrPrint("Failed to build a param\n"); if (cb) - cb(handler, -EFAULT, data); + cb(handler, LB_STATUS_ERROR_FAULT, data); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } if (!cb) @@ -2597,7 +2599,7 @@ EAPI int livebox_client_paused(void) packet = packet_create_noack("client_paused", "d", util_timestamp()); if (!packet) { ErrPrint("Failed to create a pause packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(NULL, packet); @@ -2610,7 +2612,7 @@ EAPI int livebox_client_resumed(void) packet = packet_create_noack("client_resumed", "d", util_timestamp()); if (!packet) { ErrPrint("Failed to create a resume packet\n"); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } return master_rpc_request_only(NULL, packet); diff --git a/src/master_rpc.c b/src/master_rpc.c index d3b68e1..a9f7e3e 100644 --- a/src/master_rpc.c +++ b/src/master_rpc.c @@ -32,6 +32,7 @@ #include "master_rpc.h" #include "client.h" #include "util.h" +#include "livebox-errno.h" #define DEFAULT_TTL 10 #define REQUEST_DELAY 10 @@ -169,7 +170,7 @@ static int done_cb(pid_t pid, int handle, const struct packet *packet, void *dat if (packet_get(packet, "i", &ret) != 1) { ErrPrint("Invalid result packet\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } DbgPrint("[%s] Returns: %d\n", packet_command(packet), ret); @@ -203,7 +204,7 @@ int master_rpc_async_request(struct livebox *handler, struct packet *packet, int ret_cb(handler, NULL, data); packet_unref(packet); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } command->ret_cb = ret_cb; @@ -217,7 +218,7 @@ int master_rpc_async_request(struct livebox *handler, struct packet *packet, int push_command(command); packet_unref(packet); - return 0; + return LB_STATUS_SUCCESS; } int master_rpc_request_only(struct livebox *handler, struct packet *packet) @@ -228,7 +229,7 @@ int master_rpc_request_only(struct livebox *handler, struct packet *packet) if (!command) { ErrPrint("Failed to create a command\n"); packet_unref(packet); - return -EFAULT; + return LB_STATUS_ERROR_FAULT; } command->ret_cb = NULL; @@ -238,7 +239,7 @@ int master_rpc_request_only(struct livebox *handler, struct packet *packet) push_command(command); packet_unref(packet); - return 0; + return LB_STATUS_SUCCESS; } int master_rpc_clear_fault_package(const char *pkgname) @@ -248,7 +249,7 @@ int master_rpc_clear_fault_package(const char *pkgname) struct command *command; if (!pkgname) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; DbgPrint("Clear requests of the fault package(%s)\n", pkgname); @@ -297,13 +298,13 @@ int master_rpc_sync_request(struct packet *packet) if (result) { if (packet_get(result, "i", &ret) != 1) { ErrPrint("Invalid result packet\n"); - ret = -EINVAL; + ret = LB_STATUS_ERROR_INVALID; } packet_unref(result); } else { ErrPrint("Failed to send a sync request\n"); - ret = -EFAULT; + ret = LB_STATUS_ERROR_FAULT; } packet_unref(packet); diff --git a/src/util.c b/src/util.c index a62a7d0..619bd36 100644 --- a/src/util.c +++ b/src/util.c @@ -25,6 +25,7 @@ #include "debug.h" #include "util.h" +#include "livebox-errno.h" /* For error code */ int errno; @@ -35,7 +36,7 @@ int util_check_extension(const char *filename, const char *check_ptr) name_len = strlen(filename); while (--name_len >= 0 && *check_ptr) { if (filename[name_len] != *check_ptr) - return -EINVAL; + return LB_STATUS_ERROR_INVALID; check_ptr ++; } @@ -75,14 +76,14 @@ static inline int check_native_livebox(const char *pkgname) path = malloc(len + 1); if (!path) { ErrPrint("Heap: %s\n", strerror(errno)); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname); if (access(path, F_OK | R_OK) != 0) { ErrPrint("%s is not a valid package\n", pkgname); free(path); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } free(path); @@ -100,14 +101,14 @@ static inline int check_web_livebox(const char *pkgname) path = malloc(len + 1); if (!path) { ErrPrint("Heap: %s\n", strerror(errno)); - return -ENOMEM; + return LB_STATUS_ERROR_MEMORY; } snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname); if (access(path, F_OK | R_OK) != 0) { ErrPrint("%s is not a valid package\n", pkgname); free(path); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } free(path); @@ -118,13 +119,13 @@ int util_validate_livebox_package(const char *pkgname) { if (!pkgname) { ErrPrint("Invalid argument\n"); - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname)) return 0; - return -EINVAL; + return LB_STATUS_ERROR_INVALID; } const char *util_uri_to_path(const char *uri) -- 2.7.4