From 36f870bd789d362136ec70c665635494c3717719 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Fri, 31 Oct 2014 21:22:22 +0900 Subject: [PATCH] Control the priority of slave process [model] Redwood,Kiran,B3(Wearable) [binary_type] AP [customer] Docomo/Orange/ATT/Open [issue#] N/A [problem] [cause] [solution] [team] HomeTF [request] [horizontal_expansion] Change-Id: Ib80efa8f52b96c9189f370c6c09a4411fd2726e9 --- data/x11.mobile.480x800.conf.ini | 2 + include/slave_life.h | 4 + src/abi.c | 162 +- src/badge_service.c | 828 +-- src/buffer_handler.c | 2210 +++--- src/buffer_handler_wayland.c | 1118 +-- src/client_life.c | 1118 +-- src/client_rpc.c | 314 +- src/conf.c | 4 +- src/critical_log.c | 182 +- src/dead_monitor.c | 82 +- src/event.c | 1306 ++-- src/fault_manager.c | 526 +- src/file_service.c | 1038 +-- src/group.c | 1206 ++-- src/io.c | 1374 ++-- src/liveinfo.c | 202 +- src/main.c | 604 +- src/notification_service.c | 1186 ++-- src/package.c | 2004 +++--- src/parser.c | 1222 ++-- src/pkgmgr.c | 762 +-- src/script_handler.c | 2202 +++--- src/server.c | 13546 +++++++++++++++++++------------------ src/service_common.c | 1650 ++--- src/setting.c | 296 +- src/shortcut_service.c | 292 +- src/slave_life.c | 2299 ++++--- src/slave_rpc.c | 966 +-- src/util.c | 946 +-- src/util_wayland.c | 10 +- src/util_x11.c | 24 +- src/utility_service.c | 580 +- src/xmonitor.c | 622 +- src/xmonitor_wayland.c | 252 +- 35 files changed, 20621 insertions(+), 20518 deletions(-) diff --git a/data/x11.mobile.480x800.conf.ini b/data/x11.mobile.480x800.conf.ini index ebea45a..56fb7f4 100644 --- a/data/x11.mobile.480x800.conf.ini +++ b/data/x11.mobile.480x800.conf.ini @@ -38,3 +38,5 @@ premultiplied=0 auto_align=false use_event_time=true use_gettimeofday=true +slave_event_boost_on=-10 +slave_event_boost_off=0 diff --git a/include/slave_life.h b/include/slave_life.h index 330abdf..3b65f12 100644 --- a/include/slave_life.h +++ b/include/slave_life.h @@ -213,4 +213,8 @@ extern void slave_set_control_option(struct slave_node *slave, int ctrl); extern int slave_control_option(struct slave_node *slave); extern char *slave_package_name(const char *abi, const char *lbid); + +extern int slave_priority(struct slave_node *slave); +extern int slave_set_priority(struct slave_node *slave, int priority); + /* End of a file */ diff --git a/src/abi.c b/src/abi.c index dfc9251..80abcd2 100644 --- a/src/abi.c +++ b/src/abi.c @@ -29,126 +29,126 @@ int errno; struct item { - char *abi; - char *pkgname; /*!< Slave package name */ + char *abi; + char *pkgname; /*!< Slave package name */ }; static struct { - Eina_List *list; + Eina_List *list; } s_abi = { - .list = NULL, + .list = NULL, }; HAPI int abi_add_entry(const char *abi, const char *pkgname) { - struct item *item; - - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Failed to add a new entry for abi[%s - %s]\n", abi, pkgname); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - item->abi = strdup(abi); - if (!item->abi) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - item->pkgname = strdup(pkgname); - if (!item->pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item->abi); - DbgFree(item); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - s_abi.list = eina_list_append(s_abi.list, item); - return DBOX_STATUS_ERROR_NONE; + struct item *item; + + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Failed to add a new entry for abi[%s - %s]\n", abi, pkgname); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + item->abi = strdup(abi); + if (!item->abi) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + item->pkgname = strdup(pkgname); + if (!item->pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item->abi); + DbgFree(item); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + s_abi.list = eina_list_append(s_abi.list, item); + return DBOX_STATUS_ERROR_NONE; } HAPI int abi_update_entry(const char *abi, const char *pkgname) { - Eina_List *l; - Eina_List *n; - struct item *item; - char *_pkgname; - - _pkgname = strdup(pkgname); - if (!_pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + Eina_List *l; + Eina_List *n; + struct item *item; + char *_pkgname; + + _pkgname = strdup(pkgname); + if (!_pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) { + if (!strcasecmp(item->abi, abi)) { + DbgFree(item->pkgname); + item->pkgname = _pkgname; + return 0; } + } - EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) { - if (!strcasecmp(item->abi, abi)) { - DbgFree(item->pkgname); - item->pkgname = _pkgname; - return 0; - } - } - - DbgFree(_pkgname); - return DBOX_STATUS_ERROR_NOT_EXIST; + DbgFree(_pkgname); + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int abi_del_entry(const char *abi) { - Eina_List *l; - Eina_List *n; - struct item *item; - - EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) { - if (!strcasecmp(item->abi, abi)) { - s_abi.list = eina_list_remove(s_abi.list, item); - DbgFree(item->abi); - DbgFree(item->pkgname); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; - } + Eina_List *l; + Eina_List *n; + struct item *item; + + EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) { + if (!strcasecmp(item->abi, abi)) { + s_abi.list = eina_list_remove(s_abi.list, item); + DbgFree(item->abi); + DbgFree(item->pkgname); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI void abi_del_all(void) { - struct item *item; + struct item *item; - EINA_LIST_FREE(s_abi.list, item) { - DbgFree(item->abi); - DbgFree(item->pkgname); - DbgFree(item); - } + EINA_LIST_FREE(s_abi.list, item) { + DbgFree(item->abi); + DbgFree(item->pkgname); + DbgFree(item); + } } HAPI const char *abi_find_slave(const char *abi) { - Eina_List *l; - struct item *item; + Eina_List *l; + struct item *item; - EINA_LIST_FOREACH(s_abi.list, l, item) { - if (!strcasecmp(item->abi, abi)) { - return item->pkgname; - } + EINA_LIST_FOREACH(s_abi.list, l, item) { + if (!strcasecmp(item->abi, abi)) { + return item->pkgname; } + } - return NULL; + return NULL; } HAPI const char *abi_find_by_pkgname(const char *pkgname) { - Eina_List *l; - struct item *item; + Eina_List *l; + struct item *item; - EINA_LIST_FOREACH(s_abi.list, l, item) { - if (!strcmp(item->pkgname, pkgname)) { - return item->abi; - } + EINA_LIST_FOREACH(s_abi.list, l, item) { + if (!strcmp(item->pkgname, pkgname)) { + return item->abi; } + } - return NULL; + return NULL; } /* End of a file */ diff --git a/src/badge_service.c b/src/badge_service.c index 5502245..d8d4e8b 100644 --- a/src/badge_service.c +++ b/src/badge_service.c @@ -39,25 +39,25 @@ #include "conf.h" static struct info { - Eina_List *context_list; - struct service_context *svc_ctx; + Eina_List *context_list; + struct service_context *svc_ctx; } s_info = { - .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ - .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ + .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ + .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ }; #define ENABLE_BS_ACCESS_CONTROL 1 struct context { - struct tcb *tcb; - double seq; + struct tcb *tcb; + double seq; }; struct badge_service { - const char *cmd; - void (*handler)(struct tcb *tcb, struct packet *packet, void *data); - const char *rule; - const char *access; + const char *cmd; + void (*handler)(struct tcb *tcb, struct packet *packet, void *data); + const char *rule; + const char *access; }; /*! @@ -65,31 +65,31 @@ struct badge_service { */ static int _is_valid_permission(int fd, struct badge_service *service) { - int ret; + int ret; - if (service->rule != NULL && service->access != NULL) { - ret = security_server_check_privilege_by_sockfd(fd, service->rule, service->access); - if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { - ErrPrint("SMACK:Access denied\n"); - return 0; - } + if (service->rule != NULL && service->access != NULL) { + ret = security_server_check_privilege_by_sockfd(fd, service->rule, service->access); + if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ErrPrint("SMACK:Access denied\n"); + return 0; } + } - return 1; + return 1; } static int _is_manager_permission(int fd) { - int ret; + int ret; - ret = security_server_check_privilege_by_sockfd(fd, - "data-provider-master::badge.manager", "w"); - if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { - ErrPrint("SMACK:not a manager\n"); - return 0; - } + ret = security_server_check_privilege_by_sockfd(fd, + "data-provider-master::badge.manager", "w"); + if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ErrPrint("SMACK:not a manager\n"); + return 0; + } - return 1; + return 1; } /*! @@ -97,14 +97,14 @@ static int _is_manager_permission(int fd) */ static inline char *get_string(char *string) { - if (string == NULL) { - return NULL; - } - if (string[0] == '\0') { - return NULL; - } - - return string; + if (string == NULL) { + return NULL; + } + if (string[0] == '\0') { + return NULL; + } + + return string; } /*! @@ -112,322 +112,322 @@ static inline char *get_string(char *string) */ static void _handler_insert_badge(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - char *writable_pkg = NULL; - char *caller = NULL; - - if (packet_get(packet, "sss", &pkgname, &writable_pkg, &caller) == 3) { - pkgname = get_string(pkgname); - writable_pkg = get_string(writable_pkg); - caller = get_string(caller); - - if (pkgname != NULL && writable_pkg != NULL && caller != NULL) { - ret = badge_db_insert(pkgname, writable_pkg, caller); - } else { - ret = BADGE_ERROR_INVALID_PARAMETER; - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + char *writable_pkg = NULL; + char *caller = NULL; + + if (packet_get(packet, "sss", &pkgname, &writable_pkg, &caller) == 3) { + pkgname = get_string(pkgname); + writable_pkg = get_string(writable_pkg); + caller = get_string(caller); + + if (pkgname != NULL && writable_pkg != NULL && caller != NULL) { + ret = badge_db_insert(pkgname, writable_pkg, caller); + } else { + ret = BADGE_ERROR_INVALID_PARAMETER; + } - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } - if (ret == BADGE_ERROR_NONE) { - packet_service = packet_create("insert_badge", "is", ret, pkgname); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("Failed to send a muticast packet:%d", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("Failed to create a multicast packet"); - } - } else { - ErrPrint("Failed to insert a badge:%d", ret); + if (ret == BADGE_ERROR_NONE) { + packet_service = packet_create("insert_badge", "is", ret, pkgname); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("Failed to send a muticast packet:%d", ret_p); } + packet_destroy(packet_service); + } else { + ErrPrint("Failed to create a multicast packet"); + } } else { - ErrPrint("Failed to get data from the packet"); + ErrPrint("Failed to insert a badge:%d", ret); } + } else { + ErrPrint("Failed to get data from the packet"); + } } static void _handler_delete_badge(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - char *caller = NULL; - - if (packet_get(packet, "ss", &pkgname, &caller) == 2) { - pkgname = get_string(pkgname); - caller = get_string(caller); - - if (pkgname != NULL && caller != NULL) { - if (_is_manager_permission(tcb_fd(tcb)) == 1) { - ret = badge_db_delete(pkgname, pkgname); - } else { - ret = badge_db_delete(pkgname, caller); - } - } else { - ret = BADGE_ERROR_INVALID_PARAMETER; - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + char *caller = NULL; + + if (packet_get(packet, "ss", &pkgname, &caller) == 2) { + pkgname = get_string(pkgname); + caller = get_string(caller); + + if (pkgname != NULL && caller != NULL) { + if (_is_manager_permission(tcb_fd(tcb)) == 1) { + ret = badge_db_delete(pkgname, pkgname); + } else { + ret = badge_db_delete(pkgname, caller); + } + } else { + ret = BADGE_ERROR_INVALID_PARAMETER; + } - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } - if (ret == BADGE_ERROR_NONE) { - packet_service = packet_create("delete_badge", "is", ret, pkgname); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("Failed to send a muticast packet:%d", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("Failed to create a multicast packet"); - } - } else { - ErrPrint("Failed to delete a badge:%d", ret); + if (ret == BADGE_ERROR_NONE) { + packet_service = packet_create("delete_badge", "is", ret, pkgname); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("Failed to send a muticast packet:%d", ret_p); } + packet_destroy(packet_service); + } else { + ErrPrint("Failed to create a multicast packet"); + } } else { - ErrPrint("Failed to get data from the packet"); + ErrPrint("Failed to delete a badge:%d", ret); } + } else { + ErrPrint("Failed to get data from the packet"); + } } static void _handler_set_badge_count(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - char *caller = NULL; - int count = 0; - - if (packet_get(packet, "ssi", &pkgname, &caller, &count) == 3) { - pkgname = get_string(pkgname); - caller = get_string(caller); - - if (pkgname != NULL && caller != NULL) { - ret = badge_db_set_count(pkgname, caller, count); - } else { - ret = BADGE_ERROR_INVALID_PARAMETER; - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + char *caller = NULL; + int count = 0; + + if (packet_get(packet, "ssi", &pkgname, &caller, &count) == 3) { + pkgname = get_string(pkgname); + caller = get_string(caller); + + if (pkgname != NULL && caller != NULL) { + ret = badge_db_set_count(pkgname, caller, count); + } else { + ret = BADGE_ERROR_INVALID_PARAMETER; + } - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } - if (ret == BADGE_ERROR_NONE) { - packet_service = packet_create("set_badge_count", "isi", ret, pkgname, count); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("Failed to send a muticast packet:%d", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("Failed to create a multicast packet"); - } - } else { - ErrPrint("Failed to set count of badge:%d", ret); + if (ret == BADGE_ERROR_NONE) { + packet_service = packet_create("set_badge_count", "isi", ret, pkgname, count); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("Failed to send a muticast packet:%d", ret_p); } + packet_destroy(packet_service); + } else { + ErrPrint("Failed to create a multicast packet"); + } } else { - ErrPrint("Failed to get data from the packet"); + ErrPrint("Failed to set count of badge:%d", ret); } + } else { + ErrPrint("Failed to get data from the packet"); + } } static void _handler_set_display_option(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - char *caller = NULL; - int is_display = 0; - - if (packet_get(packet, "ssi", &pkgname, &caller, &is_display) == 3) { - pkgname = get_string(pkgname); - caller = get_string(caller); - - if (pkgname != NULL && caller != NULL) { - ret = badge_db_set_display_option(pkgname, caller, is_display); - } else { - ret = BADGE_ERROR_INVALID_PARAMETER; - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + char *caller = NULL; + int is_display = 0; + + if (packet_get(packet, "ssi", &pkgname, &caller, &is_display) == 3) { + pkgname = get_string(pkgname); + caller = get_string(caller); + + if (pkgname != NULL && caller != NULL) { + ret = badge_db_set_display_option(pkgname, caller, is_display); + } else { + ret = BADGE_ERROR_INVALID_PARAMETER; + } - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } - if (ret == BADGE_ERROR_NONE) { - packet_service = packet_create("set_disp_option", "isi", ret, pkgname, is_display); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("Failed to send a muticast packet:%d", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("Failed to create a multicast packet"); - } - } else { - ErrPrint("Failed to set display option of badge:%d", ret); + if (ret == BADGE_ERROR_NONE) { + packet_service = packet_create("set_disp_option", "isi", ret, pkgname, is_display); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("Failed to send a muticast packet:%d", ret_p); } + packet_destroy(packet_service); + } else { + ErrPrint("Failed to create a multicast packet"); + } } else { - ErrPrint("Failed to get data from the packet"); + ErrPrint("Failed to set display option of badge:%d", ret); } + } else { + ErrPrint("Failed to get data from the packet"); + } } static void _handler_set_setting_property(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - int is_display = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - char *property = NULL; - char *value = NULL; - - if (packet_get(packet, "sss", &pkgname, &property, &value) == 3) { - pkgname = get_string(pkgname); - property = get_string(property); - value = get_string(value); - - if (pkgname != NULL && property != NULL && value != NULL) { - ret = badge_setting_db_set(pkgname, property, value); - } else { - ret = BADGE_ERROR_INVALID_PARAMETER; - } + int ret = 0, ret_p = 0; + int is_display = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + char *property = NULL; + char *value = NULL; + + if (packet_get(packet, "sss", &pkgname, &property, &value) == 3) { + pkgname = get_string(pkgname); + property = get_string(property); + value = get_string(value); + + if (pkgname != NULL && property != NULL && value != NULL) { + ret = badge_setting_db_set(pkgname, property, value); + } else { + ret = BADGE_ERROR_INVALID_PARAMETER; + } - packet_reply = packet_create_reply(packet, "ii", ret, ret); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); + packet_reply = packet_create_reply(packet, "ii", ret, ret); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } + + if (ret == BADGE_ERROR_NONE) { + if (strcmp(property, "OPT_BADGE") == 0) { + if (strcmp(value, "ON") == 0) { + is_display = 1; } else { - ErrPrint("failed to create a reply packet\n"); + is_display = 0; } - if (ret == BADGE_ERROR_NONE) { - if (strcmp(property, "OPT_BADGE") == 0) { - if (strcmp(value, "ON") == 0) { - is_display = 1; - } else { - is_display = 0; - } - - packet_service = packet_create("set_disp_option", "isi", ret, pkgname, is_display); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("Failed to send a muticast packet:%d", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("Failed to create a multicast packet"); - } - } + packet_service = packet_create("set_disp_option", "isi", ret, pkgname, is_display); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("Failed to send a muticast packet:%d", ret_p); + } + packet_destroy(packet_service); } else { - ErrPrint("failed to set noti property:%d\n", ret); + ErrPrint("Failed to create a multicast packet"); } + } } else { - ErrPrint("Failed to get data from the packet"); + ErrPrint("failed to set noti property:%d\n", ret); } + } else { + ErrPrint("Failed to get data from the packet"); + } } static void _handler_get_setting_property(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - char *pkgname = NULL; - char *property = NULL; - char *value = NULL; - - if (packet_get(packet, "sss", &pkgname, &property) == 2) { - pkgname = get_string(pkgname); - property = get_string(property); - - if (pkgname != NULL && property != NULL) { - ret = badge_setting_db_get(pkgname, property, &value); - } else { - ret = BADGE_ERROR_INVALID_PARAMETER; - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + char *pkgname = NULL; + char *property = NULL; + char *value = NULL; + + if (packet_get(packet, "sss", &pkgname, &property) == 2) { + pkgname = get_string(pkgname); + property = get_string(property); + + if (pkgname != NULL && property != NULL) { + ret = badge_setting_db_get(pkgname, property, &value); + } else { + ret = BADGE_ERROR_INVALID_PARAMETER; + } - packet_reply = packet_create_reply(packet, "is", ret, value); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } + packet_reply = packet_create_reply(packet, "is", ret, value); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } - if (value != NULL) { - DbgFree(value); - } + if (value != NULL) { + DbgFree(value); } + } } static void _handler_service_register(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0; - struct packet *packet_reply; - - ret = tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); - if (ret < 0) { - ErrPrint("Failed to set the type of client:%d", ret); - } - - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); + int ret = 0; + struct packet *packet_reply; + + ret = tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); + if (ret < 0) { + ErrPrint("Failed to set the type of client:%d", ret); + } + + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret); } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } } static void _handler_access_control_error(struct tcb *tcb, struct packet *packet) { - int ret_p = 0; - struct packet *packet_reply = NULL; + int ret_p = 0; + struct packet *packet_reply = NULL; - packet_reply = packet_create_reply(packet, "i", BADGE_ERROR_PERMISSION_DENIED); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); + packet_reply = packet_create_reply(packet, "i", BADGE_ERROR_PERMISSION_DENIED); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } } /*! @@ -435,107 +435,107 @@ static void _handler_access_control_error(struct tcb *tcb, struct packet *packet */ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data) { - int i = 0; - const char *command; - static struct badge_service service_req_table[] = { - { - .cmd = "insert_badge", - .handler = _handler_insert_badge, - .rule = "data-provider-master::badge.client", - .access = "w", - }, - { - .cmd = "delete_badge", - .handler = _handler_delete_badge, - .rule = "data-provider-master::badge.client", - .access = "w", - }, - { - .cmd = "set_badge_count", - .handler = _handler_set_badge_count, - .rule = "data-provider-master::badge.client", - .access = "w", - }, - { - .cmd = "set_disp_option", - .handler = _handler_set_display_option, - .rule = "data-provider-master::badge.client", - .access = "w", - }, - { - .cmd = "set_noti_property", - .handler = _handler_set_setting_property, - .rule = "data-provider-master::badge.client", - .access = "w", - }, - { - .cmd = "get_noti_property", - .handler = _handler_get_setting_property, - .rule = "data-provider-master::badge.client", - .access = "r", - }, - { - .cmd = "service_register", - .handler = _handler_service_register, - .rule = NULL, - .access = NULL, - }, - { - .cmd = NULL, - .handler = NULL, - .rule = NULL, - .access = NULL, - }, - }; - - if (!packet) { - DbgPrint("TCB: %p is terminated (NIL packet)\n", tcb); - return 0; - } + int i = 0; + const char *command; + static struct badge_service service_req_table[] = { + { + .cmd = "insert_badge", + .handler = _handler_insert_badge, + .rule = "data-provider-master::badge.client", + .access = "w", + }, + { + .cmd = "delete_badge", + .handler = _handler_delete_badge, + .rule = "data-provider-master::badge.client", + .access = "w", + }, + { + .cmd = "set_badge_count", + .handler = _handler_set_badge_count, + .rule = "data-provider-master::badge.client", + .access = "w", + }, + { + .cmd = "set_disp_option", + .handler = _handler_set_display_option, + .rule = "data-provider-master::badge.client", + .access = "w", + }, + { + .cmd = "set_noti_property", + .handler = _handler_set_setting_property, + .rule = "data-provider-master::badge.client", + .access = "w", + }, + { + .cmd = "get_noti_property", + .handler = _handler_get_setting_property, + .rule = "data-provider-master::badge.client", + .access = "r", + }, + { + .cmd = "service_register", + .handler = _handler_service_register, + .rule = NULL, + .access = NULL, + }, + { + .cmd = NULL, + .handler = NULL, + .rule = NULL, + .access = NULL, + }, + }; + + if (!packet) { + DbgPrint("TCB: %p is terminated (NIL packet)\n", tcb); + return 0; + } - command = packet_command(packet); - if (!command) { - ErrPrint("Invalid command\n"); - return -EINVAL; - } - DbgPrint("Command: [%s], Packet type[%d]\n", command, packet_type(packet)); + command = packet_command(packet); + if (!command) { + ErrPrint("Invalid command\n"); + return -EINVAL; + } + DbgPrint("Command: [%s], Packet type[%d]\n", command, packet_type(packet)); - switch (packet_type(packet)) { + switch (packet_type(packet)) { case PACKET_REQ: - /* Need to send reply packet */ - for (i = 0; service_req_table[i].cmd; i++) { - if (strcmp(service_req_table[i].cmd, command)) { - continue; - } + /* Need to send reply packet */ + for (i = 0; service_req_table[i].cmd; i++) { + if (strcmp(service_req_table[i].cmd, command)) { + continue; + } #if ENABLE_BS_ACCESS_CONTROL - if (_is_valid_permission(tcb_fd(tcb), &(service_req_table[i])) == 1) { - service_req_table[i].handler(tcb, packet, data); - } else { - _handler_access_control_error(tcb, packet); - } + if (_is_valid_permission(tcb_fd(tcb), &(service_req_table[i])) == 1) { + service_req_table[i].handler(tcb, packet, data); + } else { + _handler_access_control_error(tcb, packet); + } #else - _is_valid_permission(tcb_fd(tcb), &(service_req_table[i])); - service_req_table[i].handler(tcb, packet, data); + _is_valid_permission(tcb_fd(tcb), &(service_req_table[i])); + service_req_table[i].handler(tcb, packet, data); #endif - break; - } - break; + } + + break; case PACKET_REQ_NOACK: - break; + break; case PACKET_ACK: - break; + break; default: - ErrPrint("Packet type is not valid[%s]\n", command); - return -EINVAL; - } - - /*! - * return value has no meanning, - * it will be printed by dlogutil. - */ - return 0; + ErrPrint("Packet type is not valid[%s]\n", command); + return -EINVAL; + } + + /*! + * return value has no meanning, + * it will be printed by dlogutil. + */ + return 0; } @@ -545,49 +545,49 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat */ HAPI int badge_service_init(void) { - if (s_info.svc_ctx) { - ErrPrint("Already initialized\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - s_info.svc_ctx = service_common_create(BADGE_SOCKET, service_thread_main, NULL); - if (!s_info.svc_ctx) { - ErrPrint("Unable to activate service thread\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), BADGE_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } + if (s_info.svc_ctx) { + ErrPrint("Already initialized\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + s_info.svc_ctx = service_common_create(BADGE_SOCKET, service_thread_main, NULL); + if (!s_info.svc_ctx) { + ErrPrint("Unable to activate service thread\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), BADGE_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; } - - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), BADGE_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), BADGE_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; } + } - DbgPrint("Successfully initiated\n"); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("Successfully initiated\n"); + return DBOX_STATUS_ERROR_NONE; } HAPI int badge_service_fini(void) { - if (!s_info.svc_ctx) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - DbgPrint("Successfully finalized\n"); - return DBOX_STATUS_ERROR_NONE; + if (!s_info.svc_ctx) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + DbgPrint("Successfully finalized\n"); + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/buffer_handler.c b/src/buffer_handler.c index 54531b3..b118ca3 100644 --- a/src/buffer_handler.c +++ b/src/buffer_handler.c @@ -61,776 +61,776 @@ * \brief Allocate this in the buffer->data. */ struct gem_data { - DRI2Buffer *dri2_buffer; - unsigned int attachments[1]; - tbm_bo pixmap_bo; - int count; - int buf_count; - int w; - int h; - int depth; - Pixmap pixmap; - void *data; /* Gem layer */ - int refcnt; - - void *compensate_data; /* Check the pitch value, copy this to data */ + DRI2Buffer *dri2_buffer; + unsigned int attachments[1]; + tbm_bo pixmap_bo; + int count; + int buf_count; + int w; + int h; + int depth; + Pixmap pixmap; + void *data; /* Gem layer */ + int refcnt; + + void *compensate_data; /* Check the pitch value, copy this to data */ }; struct buffer_info { - void *buffer; - char *id; - dynamicbox_lock_info_t lock_info; + void *buffer; + char *id; + dynamicbox_lock_info_t lock_info; - enum dynamicbox_fb_type type; + enum dynamicbox_fb_type type; - int w; - int h; - int pixel_size; - int is_loaded; + int w; + int h; + int pixel_size; + int is_loaded; - struct inst_info *inst; - void *data; + struct inst_info *inst; + void *data; }; static struct { - tbm_bufmgr slp_bufmgr; - int evt_base; - int err_base; - int fd; - Eina_List *pixmap_list; + tbm_bufmgr slp_bufmgr; + int evt_base; + int err_base; + int fd; + Eina_List *pixmap_list; } s_info = { - .slp_bufmgr = NULL, - .evt_base = 0, - .err_base = 0, - .fd = -1, - .pixmap_list = NULL, + .slp_bufmgr = NULL, + .evt_base = 0, + .err_base = 0, + .fd = -1, + .pixmap_list = NULL, }; static inline dynamicbox_fb_t create_pixmap(struct buffer_info *info) { - struct gem_data *gem; - dynamicbox_fb_t buffer; - Display *disp; - Window parent; - XGCValues gcv; - GC gc; - - disp = ecore_x_display_get(); - if (!disp) { - return NULL; - } - - parent = DefaultRootWindow(disp); + struct gem_data *gem; + dynamicbox_fb_t buffer; + Display *disp; + Window parent; + XGCValues gcv; + GC gc; - buffer = calloc(1, sizeof(*buffer) + sizeof(*gem)); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + disp = ecore_x_display_get(); + if (!disp) { + return NULL; + } - gem = (struct gem_data *)buffer->data; + parent = DefaultRootWindow(disp); - buffer->type = DBOX_FB_TYPE_PIXMAP; - buffer->refcnt = 1; - buffer->state = DBOX_FB_STATE_CREATED; + buffer = calloc(1, sizeof(*buffer) + sizeof(*gem)); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - gem->attachments[0] = DRI2BufferFrontLeft; - gem->count = 1; - gem->w = info->w; /*!< This can be changed by DRI2GetBuffers */ - gem->h = info->h; /*!< This can be changed by DRI2GetBuffers */ - gem->depth = info->pixel_size; - /*! - * \NOTE - * Use the 24 Bits - * 32 Bits is not supported for video playing. - * But for the transparent background, use the 32 bits, and give up video. - */ - gem->pixmap = XCreatePixmap(disp, parent, info->w, info->h, (info->pixel_size << 3)); - if (gem->pixmap == (Pixmap)0) { - ErrPrint("Failed to create a pixmap\n"); - DbgFree(buffer); - return NULL; - } + gem = (struct gem_data *)buffer->data; + + buffer->type = DBOX_FB_TYPE_PIXMAP; + buffer->refcnt = 1; + buffer->state = DBOX_FB_STATE_CREATED; + + gem->attachments[0] = DRI2BufferFrontLeft; + gem->count = 1; + gem->w = info->w; /*!< This can be changed by DRI2GetBuffers */ + gem->h = info->h; /*!< This can be changed by DRI2GetBuffers */ + gem->depth = info->pixel_size; + /*! + * \NOTE + * Use the 24 Bits + * 32 Bits is not supported for video playing. + * But for the transparent background, use the 32 bits, and give up video. + */ + gem->pixmap = XCreatePixmap(disp, parent, info->w, info->h, (info->pixel_size << 3)); + if (gem->pixmap == (Pixmap)0) { + ErrPrint("Failed to create a pixmap\n"); + DbgFree(buffer); + return NULL; + } - /*! - * \note - * Clear pixmap - */ - memset(&gcv, 0, sizeof(gcv)); - gc = XCreateGC(disp, gem->pixmap, GCForeground, &gcv); - if (gc) { - XFillRectangle(disp, gem->pixmap, gc, 0, 0, info->w, info->h); - XSync(disp, False); - XFreeGC(disp, gc); - } else { - XSync(disp, False); - ErrPrint("Unable to clear the pixmap\n"); - } + /*! + * \note + * Clear pixmap + */ + memset(&gcv, 0, sizeof(gcv)); + gc = XCreateGC(disp, gem->pixmap, GCForeground, &gcv); + if (gc) { + XFillRectangle(disp, gem->pixmap, gc, 0, 0, info->w, info->h); + XSync(disp, False); + XFreeGC(disp, gc); + } else { + XSync(disp, False); + ErrPrint("Unable to clear the pixmap\n"); + } - return buffer; + return buffer; } static inline int create_gem(dynamicbox_fb_t buffer) { - struct gem_data *gem; - Display *disp; - - disp = ecore_x_display_get(); - if (!disp) { - ErrPrint("Failed to get display\n"); - return DBOX_STATUS_ERROR_IO_ERROR; - } + struct gem_data *gem; + Display *disp; - gem = (struct gem_data *)buffer->data; + disp = ecore_x_display_get(); + if (!disp) { + ErrPrint("Failed to get display\n"); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (s_info.fd < 0) { - gem->data = calloc(1, gem->w * gem->h * gem->depth); - if (!gem->data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + gem = (struct gem_data *)buffer->data; - ErrPrint("DRI2(gem) is not supported - Fallback to the S/W Backend\n"); - return DBOX_STATUS_ERROR_NONE; + if (s_info.fd < 0) { + gem->data = calloc(1, gem->w * gem->h * gem->depth); + if (!gem->data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; } - DRI2CreateDrawable(disp, gem->pixmap); + ErrPrint("DRI2(gem) is not supported - Fallback to the S/W Backend\n"); + return DBOX_STATUS_ERROR_NONE; + } + + DRI2CreateDrawable(disp, gem->pixmap); - gem->dri2_buffer = DRI2GetBuffers(disp, gem->pixmap, - &gem->w, &gem->h, gem->attachments, gem->count, &gem->buf_count); - if (!gem->dri2_buffer || !gem->dri2_buffer->name) { - ErrPrint("Failed to get a gem buffer\n"); - DRI2DestroyDrawable(disp, gem->pixmap); - return DBOX_STATUS_ERROR_FAULT; - } - /*! - * \How can I destroy this? - */ - gem->pixmap_bo = tbm_bo_import(s_info.slp_bufmgr, gem->dri2_buffer->name); - if (!gem->pixmap_bo) { - ErrPrint("Failed to import BO\n"); - DRI2DestroyDrawable(disp, gem->pixmap); - return DBOX_STATUS_ERROR_FAULT; - } + gem->dri2_buffer = DRI2GetBuffers(disp, gem->pixmap, + &gem->w, &gem->h, gem->attachments, gem->count, &gem->buf_count); + if (!gem->dri2_buffer || !gem->dri2_buffer->name) { + ErrPrint("Failed to get a gem buffer\n"); + DRI2DestroyDrawable(disp, gem->pixmap); + return DBOX_STATUS_ERROR_FAULT; + } + /*! + * \How can I destroy this? + */ + gem->pixmap_bo = tbm_bo_import(s_info.slp_bufmgr, gem->dri2_buffer->name); + if (!gem->pixmap_bo) { + ErrPrint("Failed to import BO\n"); + DRI2DestroyDrawable(disp, gem->pixmap); + return DBOX_STATUS_ERROR_FAULT; + } - if (DYNAMICBOX_CONF_AUTO_ALIGN && gem->dri2_buffer->pitch != gem->w * gem->depth) { - gem->compensate_data = calloc(1, gem->w * gem->h * gem->depth); - if (!gem->compensate_data) { - ErrPrint("Failed to allocate heap\n"); - } + if (DYNAMICBOX_CONF_AUTO_ALIGN && gem->dri2_buffer->pitch != gem->w * gem->depth) { + gem->compensate_data = calloc(1, gem->w * gem->h * gem->depth); + if (!gem->compensate_data) { + ErrPrint("Failed to allocate heap\n"); } + } - DbgPrint("dri2_buffer: %p, name: %p, %dx%d, pitch: %d, buf_count: %d, depth: %d, compensate: %p (%d)\n", - gem->dri2_buffer, gem->dri2_buffer->name, gem->w, gem->h, - gem->dri2_buffer->pitch, gem->buf_count, gem->depth, gem->compensate_data, DYNAMICBOX_CONF_AUTO_ALIGN); + DbgPrint("dri2_buffer: %p, name: %p, %dx%d, pitch: %d, buf_count: %d, depth: %d, compensate: %p (%d)\n", + gem->dri2_buffer, gem->dri2_buffer->name, gem->w, gem->h, + gem->dri2_buffer->pitch, gem->buf_count, gem->depth, gem->compensate_data, DYNAMICBOX_CONF_AUTO_ALIGN); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline void *acquire_gem(dynamicbox_fb_t buffer) { - struct gem_data *gem; + struct gem_data *gem; - if (!buffer) { - return NULL; - } + if (!buffer) { + return NULL; + } - gem = (struct gem_data *)buffer->data; - if (s_info.fd < 0) { - ErrPrint("GEM is not supported - Use the fake gem buffer\n"); - } else { - if (!gem->pixmap_bo) { - ErrPrint("GEM is not created\n"); - return NULL; - } + gem = (struct gem_data *)buffer->data; + if (s_info.fd < 0) { + ErrPrint("GEM is not supported - Use the fake gem buffer\n"); + } else { + if (!gem->pixmap_bo) { + ErrPrint("GEM is not created\n"); + return NULL; + } - if (!gem->data) { - tbm_bo_handle handle; + if (!gem->data) { + tbm_bo_handle handle; - if (gem->refcnt) { - ErrPrint("Already acquired. but the buffer is not valid\n"); - return NULL; - } + if (gem->refcnt) { + ErrPrint("Already acquired. but the buffer is not valid\n"); + return NULL; + } - handle = tbm_bo_map(gem->pixmap_bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE); - gem->data = handle.ptr; - } + handle = tbm_bo_map(gem->pixmap_bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE); + gem->data = handle.ptr; } + } - gem->refcnt++; + gem->refcnt++; - /*! - * \note - * If there is a compensate canvas buffer, - * use it - */ - return gem->compensate_data ? gem->compensate_data : gem->data; + /*! + * \note + * If there is a compensate canvas buffer, + * use it + */ + return gem->compensate_data ? gem->compensate_data : gem->data; } static inline void release_gem(dynamicbox_fb_t buffer) { - struct gem_data *gem; + struct gem_data *gem; - gem = (struct gem_data *)buffer->data; - if (s_info.fd >= 0 && !gem->pixmap_bo) { - ErrPrint("GEM is not created\n"); - return; - } + gem = (struct gem_data *)buffer->data; + if (s_info.fd >= 0 && !gem->pixmap_bo) { + ErrPrint("GEM is not created\n"); + return; + } - if (!gem->data) { - if (gem->refcnt > 0) { - ErrPrint("Reference count is not valid %d\n", gem->refcnt); - gem->refcnt = 0; - } - return; + if (!gem->data) { + if (gem->refcnt > 0) { + ErrPrint("Reference count is not valid %d\n", gem->refcnt); + gem->refcnt = 0; } + return; + } - gem->refcnt--; - if (gem->refcnt == 0) { - if (s_info.fd < 0) { - DbgPrint("S/W Gem buffer has no reference\n"); - } else { - /*! - * \note - * Update the gem buffer using compensate data buffer if it is exists - */ - if (gem->compensate_data) { - register int x; - register int y; - int *gem_pixel; - int *pixel; - int gap; - - pixel = gem->compensate_data; - gem_pixel = gem->data; - gap = gem->dri2_buffer->pitch - (gem->w * gem->depth); - - for (y = 0; y < gem->h; y++) { - for (x = 0; x < gem->w; x++) { - *gem_pixel++ = *pixel++; - } - - gem_pixel = (int *)(((char *)gem_pixel) + gap); - } - } - - if (gem->pixmap_bo) { - tbm_bo_unmap(gem->pixmap_bo); - } + gem->refcnt--; + if (gem->refcnt == 0) { + if (s_info.fd < 0) { + DbgPrint("S/W Gem buffer has no reference\n"); + } else { + /*! + * \note + * Update the gem buffer using compensate data buffer if it is exists + */ + if (gem->compensate_data) { + register int x; + register int y; + int *gem_pixel; + int *pixel; + int gap; + + pixel = gem->compensate_data; + gem_pixel = gem->data; + gap = gem->dri2_buffer->pitch - (gem->w * gem->depth); + + for (y = 0; y < gem->h; y++) { + for (x = 0; x < gem->w; x++) { + *gem_pixel++ = *pixel++; + } - gem->data = NULL; + gem_pixel = (int *)(((char *)gem_pixel) + gap); } - } else if (gem->refcnt < 0) { - ErrPrint("Invalid refcnt: %d (reset)\n", gem->refcnt); - gem->refcnt = 0; + } + + if (gem->pixmap_bo) { + tbm_bo_unmap(gem->pixmap_bo); + } + + gem->data = NULL; } + } else if (gem->refcnt < 0) { + ErrPrint("Invalid refcnt: %d (reset)\n", gem->refcnt); + gem->refcnt = 0; + } } static inline int destroy_pixmap(dynamicbox_fb_t buffer) { - struct gem_data *gem; - - gem = (struct gem_data *)buffer->data; + struct gem_data *gem; - if (gem->pixmap) { - Display *disp; + gem = (struct gem_data *)buffer->data; - disp = ecore_x_display_get(); - if (!disp) { - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (gem->pixmap) { + Display *disp; - DbgPrint("pixmap %lu\n", gem->pixmap); - XFreePixmap(disp, gem->pixmap); + disp = ecore_x_display_get(); + if (!disp) { + return DBOX_STATUS_ERROR_IO_ERROR; } - buffer->state = DBOX_FB_STATE_DESTROYED; - DbgFree(buffer); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("pixmap %lu\n", gem->pixmap); + XFreePixmap(disp, gem->pixmap); + } + + buffer->state = DBOX_FB_STATE_DESTROYED; + DbgFree(buffer); + return DBOX_STATUS_ERROR_NONE; } static inline int destroy_gem(dynamicbox_fb_t buffer) { - struct gem_data *gem; + struct gem_data *gem; - if (!buffer) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!buffer) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - /*! - * Forcely release the acquire_buffer. - */ - gem = (struct gem_data *)buffer->data; - if (!gem) { - return DBOX_STATUS_ERROR_FAULT; - } + /*! + * Forcely release the acquire_buffer. + */ + gem = (struct gem_data *)buffer->data; + if (!gem) { + return DBOX_STATUS_ERROR_FAULT; + } - if (s_info.fd >= 0) { - if (gem->compensate_data) { - DbgPrint("Release compensate buffer %p\n", gem->compensate_data); - DbgFree(gem->compensate_data); - gem->compensate_data = NULL; - } + if (s_info.fd >= 0) { + if (gem->compensate_data) { + DbgPrint("Release compensate buffer %p\n", gem->compensate_data); + DbgFree(gem->compensate_data); + gem->compensate_data = NULL; + } - if (gem->pixmap_bo) { - DbgPrint("unref pixmap bo\n"); - tbm_bo_unref(gem->pixmap_bo); - gem->pixmap_bo = NULL; + if (gem->pixmap_bo) { + DbgPrint("unref pixmap bo\n"); + tbm_bo_unref(gem->pixmap_bo); + gem->pixmap_bo = NULL; - DRI2DestroyDrawable(ecore_x_display_get(), gem->pixmap); - } - } else if (gem->data) { - DbgPrint("Release fake gem buffer\n"); - DbgFree(gem->data); - gem->data = NULL; + DRI2DestroyDrawable(ecore_x_display_get(), gem->pixmap); } + } else if (gem->data) { + DbgPrint("Release fake gem buffer\n"); + DbgFree(gem->data); + gem->data = NULL; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline int load_file_buffer(struct buffer_info *info) { - dynamicbox_fb_t buffer; - double timestamp; - int size; - char *new_id; - int len; - - len = strlen(DYNAMICBOX_CONF_IMAGE_PATH) + 40; - new_id = malloc(len); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + dynamicbox_fb_t buffer; + double timestamp; + int size; + char *new_id; + int len; + + len = strlen(DYNAMICBOX_CONF_IMAGE_PATH) + 40; + new_id = malloc(len); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - timestamp = util_timestamp(); - snprintf(new_id, len, SCHEMA_FILE "%s%lf", DYNAMICBOX_CONF_IMAGE_PATH, timestamp); + timestamp = util_timestamp(); + snprintf(new_id, len, SCHEMA_FILE "%s%lf", DYNAMICBOX_CONF_IMAGE_PATH, timestamp); - size = sizeof(*buffer) + info->w * info->h * info->pixel_size; - if (!size) { - ErrPrint("Canvas buffer size is ZERO\n"); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + size = sizeof(*buffer) + info->w * info->h * info->pixel_size; + if (!size) { + ErrPrint("Canvas buffer size is ZERO\n"); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - buffer = calloc(1, size); - if (!buffer) { - ErrPrint("Failed to allocate buffer\n"); - DbgFree(new_id); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + buffer = calloc(1, size); + if (!buffer) { + ErrPrint("Failed to allocate buffer\n"); + DbgFree(new_id); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - buffer->type = DBOX_FB_TYPE_FILE; - buffer->refcnt = 0; - buffer->state = DBOX_FB_STATE_CREATED; - buffer->info = info; + buffer->type = DBOX_FB_TYPE_FILE; + buffer->refcnt = 0; + buffer->state = DBOX_FB_STATE_CREATED; + buffer->info = info; - DbgFree(info->id); - info->id = new_id; - info->buffer = buffer; - info->is_loaded = 1; + DbgFree(info->id); + info->id = new_id; + info->buffer = buffer; + info->is_loaded = 1; - DbgPrint("FILE type %d created\n", size); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("FILE type %d created\n", size); + return DBOX_STATUS_ERROR_NONE; } static inline int load_shm_buffer(struct buffer_info *info) { - int id; - int size; - dynamicbox_fb_t buffer; /* Just for getting a size */ - char *new_id; - int len; - - size = info->w * info->h * info->pixel_size; - if (!size) { - ErrPrint("Invalid buffer size\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - id = shmget(IPC_PRIVATE, size + sizeof(*buffer), IPC_CREAT | 0666); - if (id < 0) { - ErrPrint("shmget: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } + int id; + int size; + dynamicbox_fb_t buffer; /* Just for getting a size */ + char *new_id; + int len; + + size = info->w * info->h * info->pixel_size; + if (!size) { + ErrPrint("Invalid buffer size\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - buffer = shmat(id, NULL, 0); - if (buffer == (void *)-1) { - ErrPrint("%s shmat: %s\n", info->id, strerror(errno)); + id = shmget(IPC_PRIVATE, size + sizeof(*buffer), IPC_CREAT | 0666); + if (id < 0) { + ErrPrint("shmget: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } - if (shmctl(id, IPC_RMID, 0) < 0) { - ErrPrint("%s shmctl: %s\n", info->id, strerror(errno)); - } + buffer = shmat(id, NULL, 0); + if (buffer == (void *)-1) { + ErrPrint("%s shmat: %s\n", info->id, strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; + if (shmctl(id, IPC_RMID, 0) < 0) { + ErrPrint("%s shmctl: %s\n", info->id, strerror(errno)); } - buffer->type = DBOX_FB_TYPE_SHM; - buffer->refcnt = id; - buffer->state = DBOX_FB_STATE_CREATED; /*!< Needless */ - buffer->info = (void *)size; /*!< Use this field to indicates the size of SHM */ + return DBOX_STATUS_ERROR_FAULT; + } - len = strlen(SCHEMA_SHM) + 30; /* strlen("shm://") + 30 */ + buffer->type = DBOX_FB_TYPE_SHM; + buffer->refcnt = id; + buffer->state = DBOX_FB_STATE_CREATED; /*!< Needless */ + buffer->info = (void *)size; /*!< Use this field to indicates the size of SHM */ - new_id = malloc(len); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - if (shmdt(buffer) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } + len = strlen(SCHEMA_SHM) + 30; /* strlen("shm://") + 30 */ - if (shmctl(id, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } + new_id = malloc(len); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + if (shmdt(buffer) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + if (shmctl(id, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); } - snprintf(new_id, len, SCHEMA_SHM "%d", id); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + snprintf(new_id, len, SCHEMA_SHM "%d", id); - DbgFree(info->id); - info->id = new_id; - info->buffer = buffer; - info->is_loaded = 1; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->id); + info->id = new_id; + info->buffer = buffer; + info->is_loaded = 1; + return DBOX_STATUS_ERROR_NONE; } static inline int load_pixmap_buffer(struct buffer_info *info) { - dynamicbox_fb_t buffer; - struct gem_data *gem; - char *new_id; - int len; - - /*! - * \NOTE - * Before call the buffer_handler_pixmap_ref function, - * You should make sure that the is_loaded value is toggled (1) - * Or the buffer_handler_pixmap_ref function will return NULL - */ - info->is_loaded = 1; - - if (info->buffer) { - DbgPrint("Buffer is already exists, but override it with new one\n"); - } + dynamicbox_fb_t buffer; + struct gem_data *gem; + char *new_id; + int len; + + /*! + * \NOTE + * Before call the buffer_handler_pixmap_ref function, + * You should make sure that the is_loaded value is toggled (1) + * Or the buffer_handler_pixmap_ref function will return NULL + */ + info->is_loaded = 1; + + if (info->buffer) { + DbgPrint("Buffer is already exists, but override it with new one\n"); + } - buffer = buffer_handler_pixmap_ref(info); - if (!buffer) { - DbgPrint("Failed to make a reference of a pixmap\n"); - info->is_loaded = 0; - return DBOX_STATUS_ERROR_FAULT; - } + buffer = buffer_handler_pixmap_ref(info); + if (!buffer) { + DbgPrint("Failed to make a reference of a pixmap\n"); + info->is_loaded = 0; + return DBOX_STATUS_ERROR_FAULT; + } - len = strlen(SCHEMA_PIXMAP) + 30; /* strlen("pixmap://") + 30 */ - new_id = malloc(len); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - info->is_loaded = 0; - buffer_handler_pixmap_unref(buffer); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + len = strlen(SCHEMA_PIXMAP) + 30; /* strlen("pixmap://") + 30 */ + new_id = malloc(len); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + info->is_loaded = 0; + buffer_handler_pixmap_unref(buffer); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->id); - info->id = new_id; + DbgFree(info->id); + info->id = new_id; - gem = (struct gem_data *)buffer->data; + gem = (struct gem_data *)buffer->data; - snprintf(info->id, len, SCHEMA_PIXMAP "%d:%d", (int)gem->pixmap, info->pixel_size); - DbgPrint("Loaded pixmap(info->id): %s\n", info->id); - return DBOX_STATUS_ERROR_NONE; + snprintf(info->id, len, SCHEMA_PIXMAP "%d:%d", (int)gem->pixmap, info->pixel_size); + DbgPrint("Loaded pixmap(info->id): %s\n", info->id); + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_load(struct buffer_info *info) { - int ret; - dynamicbox_target_type_e type = DBOX_TYPE_GBAR; + int ret; + dynamicbox_target_type_e type = DBOX_TYPE_GBAR; - if (!info) { - ErrPrint("buffer handler is nil\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("buffer handler is nil\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->is_loaded) { - DbgPrint("Buffer is already loaded\n"); - return DBOX_STATUS_ERROR_NONE; - } + if (info->is_loaded) { + DbgPrint("Buffer is already loaded\n"); + return DBOX_STATUS_ERROR_NONE; + } - switch (info->type) { + switch (info->type) { case DBOX_FB_TYPE_FILE: - ret = load_file_buffer(info); + ret = load_file_buffer(info); - if (script_handler_buffer_info(instance_gbar_script(info->inst)) != info && instance_gbar_buffer(info->inst) != info) { - type = DBOX_TYPE_DBOX; - } - info->lock_info = dynamicbox_service_create_lock(instance_id(info->inst), type, DBOX_LOCK_WRITE); - break; + if (script_handler_buffer_info(instance_gbar_script(info->inst)) != info && instance_gbar_buffer(info->inst) != info) { + type = DBOX_TYPE_DBOX; + } + info->lock_info = dynamicbox_service_create_lock(instance_id(info->inst), type, DBOX_LOCK_WRITE); + break; case DBOX_FB_TYPE_SHM: - ret = load_shm_buffer(info); + ret = load_shm_buffer(info); - if (script_handler_buffer_info(instance_gbar_script(info->inst)) != info && instance_gbar_buffer(info->inst) != info) { - type = DBOX_TYPE_DBOX; - } - info->lock_info = dynamicbox_service_create_lock(instance_id(info->inst), type, DBOX_LOCK_WRITE); - break; + if (script_handler_buffer_info(instance_gbar_script(info->inst)) != info && instance_gbar_buffer(info->inst) != info) { + type = DBOX_TYPE_DBOX; + } + info->lock_info = dynamicbox_service_create_lock(instance_id(info->inst), type, DBOX_LOCK_WRITE); + break; case DBOX_FB_TYPE_PIXMAP: - ret = load_pixmap_buffer(info); - break; + ret = load_pixmap_buffer(info); + break; default: - ErrPrint("Invalid buffer\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ErrPrint("Invalid buffer\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - return ret; + return ret; } static inline int unload_file_buffer(struct buffer_info *info) { - const char *path; - char *new_id; + const char *path; + char *new_id; - new_id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + new_id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->buffer); - info->buffer = NULL; + DbgFree(info->buffer); + info->buffer = NULL; - path = util_uri_to_path(info->id); - if (path && unlink(path) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } + path = util_uri_to_path(info->id); + if (path && unlink(path) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); + } - DbgFree(info->id); - info->id = new_id; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->id); + info->id = new_id; + return DBOX_STATUS_ERROR_NONE; } static inline int unload_shm_buffer(struct buffer_info *info) { - int id; - char *new_id; + int id; + char *new_id; - new_id = strdup(SCHEMA_SHM "-1"); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + new_id = strdup(SCHEMA_SHM "-1"); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - if (sscanf(info->id, SCHEMA_SHM "%d", &id) != 1) { - ErrPrint("%s Invalid ID\n", info->id); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (sscanf(info->id, SCHEMA_SHM "%d", &id) != 1) { + ErrPrint("%s Invalid ID\n", info->id); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (id < 0) { - ErrPrint("(%s) Invalid id: %d\n", info->id, id); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (id < 0) { + ErrPrint("(%s) Invalid id: %d\n", info->id, id); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (shmdt(info->buffer) < 0) { - ErrPrint("Detach shm: %s\n", strerror(errno)); - } + if (shmdt(info->buffer) < 0) { + ErrPrint("Detach shm: %s\n", strerror(errno)); + } - if (shmctl(id, IPC_RMID, 0) < 0) { - ErrPrint("Remove shm: %s\n", strerror(errno)); - } + if (shmctl(id, IPC_RMID, 0) < 0) { + ErrPrint("Remove shm: %s\n", strerror(errno)); + } - info->buffer = NULL; + info->buffer = NULL; - DbgFree(info->id); - info->id = new_id; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->id); + info->id = new_id; + return DBOX_STATUS_ERROR_NONE; } static inline int unload_pixmap_buffer(struct buffer_info *info) { - int id; - char *new_id; - int pixels; - - new_id = strdup(SCHEMA_PIXMAP "0:0"); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - if (sscanf(info->id, SCHEMA_PIXMAP "%d:%d", &id, &pixels) != 2) { - ErrPrint("Invalid ID (%s)\n", info->id); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (id == 0) { - ErrPrint("(%s) Invalid id: %d\n", info->id, id); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + int id; + char *new_id; + int pixels; + + new_id = strdup(SCHEMA_PIXMAP "0:0"); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - /*! - * Decrease the reference counter. - */ - buffer_handler_pixmap_unref(info->buffer); + if (sscanf(info->id, SCHEMA_PIXMAP "%d:%d", &id, &pixels) != 2) { + ErrPrint("Invalid ID (%s)\n", info->id); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - /*! - * \note - * Just clear the info->buffer. - * It will be reallocated again. - */ - info->buffer = NULL; + if (id == 0) { + ErrPrint("(%s) Invalid id: %d\n", info->id, id); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - DbgFree(info->id); - info->id = new_id; - return DBOX_STATUS_ERROR_NONE; + /*! + * Decrease the reference counter. + */ + buffer_handler_pixmap_unref(info->buffer); + + /*! + * \note + * Just clear the info->buffer. + * It will be reallocated again. + */ + info->buffer = NULL; + + DbgFree(info->id); + info->id = new_id; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_unload(struct buffer_info *info) { - int ret; + int ret; - if (!info) { - ErrPrint("buffer handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("buffer handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->is_loaded) { - ErrPrint("Buffer is not loaded\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info->is_loaded) { + ErrPrint("Buffer is not loaded\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (info->type) { + switch (info->type) { case DBOX_FB_TYPE_FILE: - dynamicbox_service_destroy_lock(info->lock_info); - info->lock_info = NULL; - ret = unload_file_buffer(info); - break; + dynamicbox_service_destroy_lock(info->lock_info); + info->lock_info = NULL; + ret = unload_file_buffer(info); + break; case DBOX_FB_TYPE_SHM: - dynamicbox_service_destroy_lock(info->lock_info); - info->lock_info = NULL; - ret = unload_shm_buffer(info); - break; + dynamicbox_service_destroy_lock(info->lock_info); + info->lock_info = NULL; + ret = unload_shm_buffer(info); + break; case DBOX_FB_TYPE_PIXMAP: - ret = unload_pixmap_buffer(info); - break; + ret = unload_pixmap_buffer(info); + break; default: - ErrPrint("Invalid buffer\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ErrPrint("Invalid buffer\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - if (ret == 0) { - info->is_loaded = 0; - } + if (ret == 0) { + info->is_loaded = 0; + } - return ret; + return ret; } EAPI const char *buffer_handler_id(const struct buffer_info *info) { - return info ? info->id : ""; + return info ? info->id : ""; } EAPI enum dynamicbox_fb_type buffer_handler_type(const struct buffer_info *info) { - return info ? info->type : DBOX_FB_TYPE_ERROR; + return info ? info->type : DBOX_FB_TYPE_ERROR; } EAPI void *buffer_handler_fb(struct buffer_info *info) { - dynamicbox_fb_t buffer; + dynamicbox_fb_t buffer; - if (!info) { - return NULL; - } + if (!info) { + return NULL; + } - buffer = info->buffer; + buffer = info->buffer; - if (info->type == DBOX_FB_TYPE_PIXMAP) { - void *canvas; - int ret; + if (info->type == DBOX_FB_TYPE_PIXMAP) { + void *canvas; + int ret; - /*! - * \note - * For getting the buffer address of gem. - */ - canvas = buffer_handler_pixmap_acquire_buffer(info); - ret = buffer_handler_pixmap_release_buffer(canvas); - if (ret < 0) { - ErrPrint("Failed to release buffer: %d\n", ret); - } - return canvas; + /*! + * \note + * For getting the buffer address of gem. + */ + canvas = buffer_handler_pixmap_acquire_buffer(info); + ret = buffer_handler_pixmap_release_buffer(canvas); + if (ret < 0) { + ErrPrint("Failed to release buffer: %d\n", ret); } + return canvas; + } - return buffer->data; + return buffer->data; } EAPI int buffer_handler_pixmap(const struct buffer_info *info) { - dynamicbox_fb_t buf; - struct gem_data *gem; + dynamicbox_fb_t buf; + struct gem_data *gem; - if (!info) { - ErrPrint("Inavlid buffer handler\n"); - return 0; - } + if (!info) { + ErrPrint("Inavlid buffer handler\n"); + return 0; + } - if (info->type != DBOX_FB_TYPE_PIXMAP) { - ErrPrint("Invalid buffer type\n"); - return 0; - } + if (info->type != DBOX_FB_TYPE_PIXMAP) { + ErrPrint("Invalid buffer type\n"); + return 0; + } - buf = (dynamicbox_fb_t)info->buffer; - if (!buf) { - ErrPrint("Invalid buffer data\n"); - return 0; - } + buf = (dynamicbox_fb_t)info->buffer; + if (!buf) { + ErrPrint("Invalid buffer data\n"); + return 0; + } - gem = (struct gem_data *)buf->data; - return gem->pixmap; + gem = (struct gem_data *)buf->data; + return gem->pixmap; } EAPI void *buffer_handler_pixmap_acquire_buffer(struct buffer_info *info) { - dynamicbox_fb_t buffer; + dynamicbox_fb_t buffer; - if (!info || !info->is_loaded) { - ErrPrint("Buffer is not loaded\n"); - return NULL; - } + if (!info || !info->is_loaded) { + ErrPrint("Buffer is not loaded\n"); + return NULL; + } - buffer = buffer_handler_pixmap_ref(info); - if (!buffer) { - return NULL; - } + buffer = buffer_handler_pixmap_ref(info); + if (!buffer) { + return NULL; + } - return acquire_gem(buffer); + return acquire_gem(buffer); } EAPI void *buffer_handler_pixmap_buffer(struct buffer_info *info) { - dynamicbox_fb_t buffer; - struct gem_data *gem; + dynamicbox_fb_t buffer; + struct gem_data *gem; - if (!info) { - return NULL; - } + if (!info) { + return NULL; + } - if (!info->is_loaded) { - ErrPrint("Buffer is not loaded\n"); - return NULL; - } + if (!info->is_loaded) { + ErrPrint("Buffer is not loaded\n"); + return NULL; + } - buffer = info->buffer; - if (!buffer) { - return NULL; - } + buffer = info->buffer; + if (!buffer) { + return NULL; + } - gem = (struct gem_data *)buffer->data; - return gem->compensate_data ? gem->compensate_data : gem->data; + gem = (struct gem_data *)buffer->data; + return gem->compensate_data ? gem->compensate_data : gem->data; } /** @@ -918,64 +918,64 @@ EAPI void *buffer_handler_pixmap_ref(struct buffer_info *info) */ EAPI void *buffer_handler_pixmap_find(int pixmap) { - dynamicbox_fb_t buffer; - struct gem_data *gem; - Eina_List *l; - Eina_List *n; + dynamicbox_fb_t buffer; + struct gem_data *gem; + Eina_List *l; + Eina_List *n; - if (pixmap == 0) { - return NULL; - } + if (pixmap == 0) { + return NULL; + } - EINA_LIST_FOREACH_SAFE(s_info.pixmap_list, l, n, buffer) { - if (!buffer || buffer->state != DBOX_FB_STATE_CREATED || buffer->type != DBOX_FB_TYPE_PIXMAP) { - s_info.pixmap_list = eina_list_remove(s_info.pixmap_list, buffer); - DbgPrint("Invalid buffer (List Removed: %p)\n", buffer); - continue; - } + EINA_LIST_FOREACH_SAFE(s_info.pixmap_list, l, n, buffer) { + if (!buffer || buffer->state != DBOX_FB_STATE_CREATED || buffer->type != DBOX_FB_TYPE_PIXMAP) { + s_info.pixmap_list = eina_list_remove(s_info.pixmap_list, buffer); + DbgPrint("Invalid buffer (List Removed: %p)\n", buffer); + continue; + } - gem = (struct gem_data *)buffer->data; - if (gem->pixmap == pixmap) { - return buffer; - } + gem = (struct gem_data *)buffer->data; + if (gem->pixmap == pixmap) { + return buffer; } + } - return NULL; + return NULL; } EAPI int buffer_handler_pixmap_release_buffer(void *canvas) { - dynamicbox_fb_t buffer; - struct gem_data *gem; - Eina_List *l; - Eina_List *n; - void *_ptr; - - if (!canvas) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + dynamicbox_fb_t buffer; + struct gem_data *gem; + Eina_List *l; + Eina_List *n; + void *_ptr; - EINA_LIST_FOREACH_SAFE(s_info.pixmap_list, l, n, buffer) { - if (!buffer || buffer->state != DBOX_FB_STATE_CREATED || buffer->type != DBOX_FB_TYPE_PIXMAP) { - s_info.pixmap_list = eina_list_remove(s_info.pixmap_list, buffer); - continue; - } + if (!canvas) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + EINA_LIST_FOREACH_SAFE(s_info.pixmap_list, l, n, buffer) { + if (!buffer || buffer->state != DBOX_FB_STATE_CREATED || buffer->type != DBOX_FB_TYPE_PIXMAP) { + s_info.pixmap_list = eina_list_remove(s_info.pixmap_list, buffer); + continue; + } - gem = (struct gem_data *)buffer->data; - _ptr = gem->compensate_data ? gem->compensate_data : gem->data; + gem = (struct gem_data *)buffer->data; + _ptr = gem->compensate_data ? gem->compensate_data : gem->data; - if (!_ptr) { - continue; - } + if (!_ptr) { + continue; + } - if (_ptr == canvas) { - release_gem(buffer); - buffer_handler_pixmap_unref(buffer); - return DBOX_STATUS_ERROR_NONE; - } + if (_ptr == canvas) { + release_gem(buffer); + buffer_handler_pixmap_unref(buffer); + return DBOX_STATUS_ERROR_NONE; } + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } /*! @@ -986,101 +986,101 @@ EAPI int buffer_handler_pixmap_release_buffer(void *canvas) */ EAPI int buffer_handler_pixmap_unref(void *buffer_ptr) { - dynamicbox_fb_t buffer = buffer_ptr; - struct buffer_info *info; + dynamicbox_fb_t buffer = buffer_ptr; + struct buffer_info *info; - buffer->refcnt--; - if (buffer->refcnt > 0) { - return DBOX_STATUS_ERROR_NONE; /* Return NULL means, gem buffer still in use */ - } + buffer->refcnt--; + if (buffer->refcnt > 0) { + return DBOX_STATUS_ERROR_NONE; /* Return NULL means, gem buffer still in use */ + } - s_info.pixmap_list = eina_list_remove(s_info.pixmap_list, buffer); + s_info.pixmap_list = eina_list_remove(s_info.pixmap_list, buffer); - info = buffer->info; + info = buffer->info; - if (destroy_gem(buffer) < 0) { - ErrPrint("Failed to destroy gem buffer\n"); - } + if (destroy_gem(buffer) < 0) { + ErrPrint("Failed to destroy gem buffer\n"); + } - if (destroy_pixmap(buffer) < 0) { - ErrPrint("Failed to destroy pixmap\n"); - } + if (destroy_pixmap(buffer) < 0) { + ErrPrint("Failed to destroy pixmap\n"); + } - if (info && info->buffer == buffer) { - info->buffer = NULL; - } + if (info && info->buffer == buffer) { + info->buffer = NULL; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_is_loaded(const struct buffer_info *info) { - return info ? info->is_loaded : 0; + return info ? info->is_loaded : 0; } EAPI void buffer_handler_update_size(struct buffer_info *info, int w, int h) { - if (!info) { - return; - } + if (!info) { + return; + } - info->w = w; - info->h = h; + info->w = w; + info->h = h; } EAPI int buffer_handler_resize(struct buffer_info *info, int w, int h) { - int ret; + int ret; - if (!info) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("Invalid handler\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->w == w && info->h == h) { - DbgPrint("No changes\n"); - return DBOX_STATUS_ERROR_NONE; - } + if (info->w == w && info->h == h) { + DbgPrint("No changes\n"); + return DBOX_STATUS_ERROR_NONE; + } - buffer_handler_update_size(info, w, h); + buffer_handler_update_size(info, w, h); - if (!info->is_loaded) { - DbgPrint("Buffer size is updated[%dx%d]\n", w, h); - return DBOX_STATUS_ERROR_NONE; - } + if (!info->is_loaded) { + DbgPrint("Buffer size is updated[%dx%d]\n", w, h); + return DBOX_STATUS_ERROR_NONE; + } - ret = buffer_handler_unload(info); - if (ret < 0) { - ErrPrint("Unload: %d\n", ret); - } + ret = buffer_handler_unload(info); + if (ret < 0) { + ErrPrint("Unload: %d\n", ret); + } - ret = buffer_handler_load(info); - if (ret < 0) { - ErrPrint("Load: %d\n", ret); - } + ret = buffer_handler_load(info); + if (ret < 0) { + ErrPrint("Load: %d\n", ret); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_get_size(struct buffer_info *info, int *w, int *h) { - if (!info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (w) { - *w = info->w; - } - if (h) { - *h = info->h; - } + if (w) { + *w = info->w; + } + if (h) { + *h = info->h; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI struct inst_info *buffer_handler_instance(struct buffer_info *info) { - return info->inst; + return info->inst; } /*! @@ -1089,540 +1089,540 @@ EAPI struct inst_info *buffer_handler_instance(struct buffer_info *info) */ static inline int sync_for_pixmap(dynamicbox_fb_t buffer) { - XShmSegmentInfo si; - XImage *xim; - GC gc; - Display *disp; - struct gem_data *gem; - Screen *screen; - Visual *visual; - - if (buffer->state != DBOX_FB_STATE_CREATED) { - ErrPrint("Invalid state of a FB\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (buffer->type != DBOX_FB_TYPE_PIXMAP) { - ErrPrint("Invalid buffer\n"); - return DBOX_STATUS_ERROR_NONE; - } - - disp = ecore_x_display_get(); - if (!disp) { - ErrPrint("Failed to get a display\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - gem = (struct gem_data *)buffer->data; - if (gem->w == 0 || gem->h == 0) { - DbgPrint("Nothing can be sync\n"); - return DBOX_STATUS_ERROR_NONE; - } - - si.shmid = shmget(IPC_PRIVATE, gem->w * gem->h * gem->depth, IPC_CREAT | 0666); - if (si.shmid < 0) { - ErrPrint("shmget: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } - - si.readOnly = False; - si.shmaddr = shmat(si.shmid, NULL, 0); - if (si.shmaddr == (void *)-1) { - if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_FAULT; - } - - screen = DefaultScreenOfDisplay(disp); - visual = DefaultVisualOfScreen(screen); - /*! - * \NOTE - * XCreatePixmap can only uses 24 bits depth only. - */ - xim = XShmCreateImage(disp, visual, (gem->depth << 3), ZPixmap, NULL, &si, gem->w, gem->h); - if (xim == NULL) { - if (shmdt(si.shmaddr) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } + XShmSegmentInfo si; + XImage *xim; + GC gc; + Display *disp; + struct gem_data *gem; + Screen *screen; + Visual *visual; + + if (buffer->state != DBOX_FB_STATE_CREATED) { + ErrPrint("Invalid state of a FB\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_FAULT; - } + if (buffer->type != DBOX_FB_TYPE_PIXMAP) { + ErrPrint("Invalid buffer\n"); + return DBOX_STATUS_ERROR_NONE; + } - xim->data = si.shmaddr; - XShmAttach(disp, &si); - XSync(disp, False); + disp = ecore_x_display_get(); + if (!disp) { + ErrPrint("Failed to get a display\n"); + return DBOX_STATUS_ERROR_FAULT; + } - gc = XCreateGC(disp, gem->pixmap, 0, NULL); - if (!gc) { - XShmDetach(disp, &si); - XDestroyImage(xim); + gem = (struct gem_data *)buffer->data; + if (gem->w == 0 || gem->h == 0) { + DbgPrint("Nothing can be sync\n"); + return DBOX_STATUS_ERROR_NONE; + } - if (shmdt(si.shmaddr) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } + si.shmid = shmget(IPC_PRIVATE, gem->w * gem->h * gem->depth, IPC_CREAT | 0666); + if (si.shmid < 0) { + ErrPrint("shmget: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } - if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } + si.readOnly = False; + si.shmaddr = shmat(si.shmid, NULL, 0); + if (si.shmaddr == (void *)-1) { + if (shmctl(si.shmid, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_FAULT; + } - return DBOX_STATUS_ERROR_FAULT; + screen = DefaultScreenOfDisplay(disp); + visual = DefaultVisualOfScreen(screen); + /*! + * \NOTE + * XCreatePixmap can only uses 24 bits depth only. + */ + xim = XShmCreateImage(disp, visual, (gem->depth << 3), ZPixmap, NULL, &si, gem->w, gem->h); + if (xim == NULL) { + if (shmdt(si.shmaddr) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); } - memcpy(xim->data, gem->data, gem->w * gem->h * gem->depth); + if (shmctl(si.shmid, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_FAULT; + } - /*! - * \note Do not send the event. - * Instead of X event, master will send the updated event to the viewer - */ - XShmPutImage(disp, gem->pixmap, gc, xim, 0, 0, 0, 0, gem->w, gem->h, False); - XSync(disp, False); + xim->data = si.shmaddr; + XShmAttach(disp, &si); + XSync(disp, False); - XFreeGC(disp, gc); + gc = XCreateGC(disp, gem->pixmap, 0, NULL); + if (!gc) { XShmDetach(disp, &si); XDestroyImage(xim); if (shmdt(si.shmaddr) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); + ErrPrint("shmdt: %s\n", strerror(errno)); } if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); + ErrPrint("shmctl: %s\n", strerror(errno)); } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_FAULT; + } + + memcpy(xim->data, gem->data, gem->w * gem->h * gem->depth); + + /*! + * \note Do not send the event. + * Instead of X event, master will send the updated event to the viewer + */ + XShmPutImage(disp, gem->pixmap, gc, xim, 0, 0, 0, 0, gem->w, gem->h, False); + XSync(disp, False); + + XFreeGC(disp, gc); + XShmDetach(disp, &si); + XDestroyImage(xim); + + if (shmdt(si.shmaddr) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } + + if (shmctl(si.shmid, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); + } + + return DBOX_STATUS_ERROR_NONE; } EAPI void buffer_handler_flush(struct buffer_info *info) { - int fd; - int size; - dynamicbox_fb_t buffer; - - if (!info || !info->buffer) { - return; - } + int fd; + int size; + dynamicbox_fb_t buffer; - buffer = info->buffer; - - if (buffer->type == DBOX_FB_TYPE_PIXMAP) { - if (s_info.fd > 0) { - //return; - //PERF_INIT(); - //PERF_BEGIN(); - XRectangle rect; - XserverRegion region; - - rect.x = 0; - rect.y = 0; - rect.width = info->w; - rect.height = info->h; - - region = XFixesCreateRegion(ecore_x_display_get(), &rect, 1); - XDamageAdd(ecore_x_display_get(), buffer_handler_pixmap(info), region); - XFixesDestroyRegion(ecore_x_display_get(), region); - XFlush(ecore_x_display_get()); - //PERF_MARK("XFlush"); - } else { - if (sync_for_pixmap(buffer) < 0) { - ErrPrint("Failed to sync via S/W Backend\n"); - } - } - } else if (buffer->type == DBOX_FB_TYPE_FILE) { - fd = open(util_uri_to_path(info->id), O_WRONLY | O_CREAT, 0644); - if (fd < 0) { - ErrPrint("%s open falied: %s\n", util_uri_to_path(info->id), strerror(errno)); - return; - } + if (!info || !info->buffer) { + return; + } - size = info->w * info->h * info->pixel_size; - dynamicbox_service_acquire_lock(info->lock_info); - if (write(fd, info->buffer, size) != size) { - ErrPrint("Write is not completed: %s\n", strerror(errno)); - } - dynamicbox_service_release_lock(info->lock_info); + buffer = info->buffer; - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + if (buffer->type == DBOX_FB_TYPE_PIXMAP) { + if (s_info.fd > 0) { + //return; + //PERF_INIT(); + //PERF_BEGIN(); + XRectangle rect; + XserverRegion region; + + rect.x = 0; + rect.y = 0; + rect.width = info->w; + rect.height = info->h; + + region = XFixesCreateRegion(ecore_x_display_get(), &rect, 1); + XDamageAdd(ecore_x_display_get(), buffer_handler_pixmap(info), region); + XFixesDestroyRegion(ecore_x_display_get(), region); + XFlush(ecore_x_display_get()); + //PERF_MARK("XFlush"); } else { - DbgPrint("Flush nothing\n"); + if (sync_for_pixmap(buffer) < 0) { + ErrPrint("Failed to sync via S/W Backend\n"); + } + } + } else if (buffer->type == DBOX_FB_TYPE_FILE) { + fd = open(util_uri_to_path(info->id), O_WRONLY | O_CREAT, 0644); + if (fd < 0) { + ErrPrint("%s open falied: %s\n", util_uri_to_path(info->id), strerror(errno)); + return; + } + + size = info->w * info->h * info->pixel_size; + dynamicbox_service_acquire_lock(info->lock_info); + if (write(fd, info->buffer, size) != size) { + ErrPrint("Write is not completed: %s\n", strerror(errno)); + } + dynamicbox_service_release_lock(info->lock_info); + + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } + } else { + DbgPrint("Flush nothing\n"); + } } HAPI int buffer_handler_init(void) { - int dri2Major, dri2Minor; - char *driverName, *deviceName; - drm_magic_t magic; - - if (!DRI2QueryExtension(ecore_x_display_get(), &s_info.evt_base, &s_info.err_base)) { - ErrPrint("DRI2 is not supported\n"); - return DBOX_STATUS_ERROR_NONE; - } + int dri2Major, dri2Minor; + char *driverName, *deviceName; + drm_magic_t magic; - if (!DRI2QueryVersion(ecore_x_display_get(), &dri2Major, &dri2Minor)) { - ErrPrint("DRI2 is not supported\n"); - s_info.evt_base = 0; - s_info.err_base = 0; - return DBOX_STATUS_ERROR_NONE; - } + if (!DRI2QueryExtension(ecore_x_display_get(), &s_info.evt_base, &s_info.err_base)) { + ErrPrint("DRI2 is not supported\n"); + return DBOX_STATUS_ERROR_NONE; + } - if (!DRI2Connect(ecore_x_display_get(), DefaultRootWindow(ecore_x_display_get()), &driverName, &deviceName)) { - ErrPrint("DRI2 is not supported\n"); - s_info.evt_base = 0; - s_info.err_base = 0; - return DBOX_STATUS_ERROR_NONE; - } + if (!DRI2QueryVersion(ecore_x_display_get(), &dri2Major, &dri2Minor)) { + ErrPrint("DRI2 is not supported\n"); + s_info.evt_base = 0; + s_info.err_base = 0; + return DBOX_STATUS_ERROR_NONE; + } - if (DYNAMICBOX_CONF_USE_SW_BACKEND) { - DbgPrint("Fallback to the S/W Backend\n"); - s_info.evt_base = 0; - s_info.err_base = 0; - DbgFree(deviceName); - DbgFree(driverName); - return DBOX_STATUS_ERROR_NONE; - } + if (!DRI2Connect(ecore_x_display_get(), DefaultRootWindow(ecore_x_display_get()), &driverName, &deviceName)) { + ErrPrint("DRI2 is not supported\n"); + s_info.evt_base = 0; + s_info.err_base = 0; + return DBOX_STATUS_ERROR_NONE; + } - s_info.fd = open(deviceName, O_RDWR); + if (DYNAMICBOX_CONF_USE_SW_BACKEND) { + DbgPrint("Fallback to the S/W Backend\n"); + s_info.evt_base = 0; + s_info.err_base = 0; DbgFree(deviceName); DbgFree(driverName); - if (s_info.fd < 0) { - ErrPrint("Failed to open a drm device: (%s)\n", strerror(errno)); - s_info.evt_base = 0; - s_info.err_base = 0; - return DBOX_STATUS_ERROR_NONE; - } + return DBOX_STATUS_ERROR_NONE; + } - drmGetMagic(s_info.fd, &magic); - DbgPrint("DRM Magic: 0x%X\n", magic); - if (!DRI2Authenticate(ecore_x_display_get(), DefaultRootWindow(ecore_x_display_get()), (unsigned int)magic)) { - ErrPrint("Failed to do authenticate for DRI2\n"); - if (close(s_info.fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - s_info.fd = -1; - s_info.evt_base = 0; - s_info.err_base = 0; - return DBOX_STATUS_ERROR_NONE; - } + s_info.fd = open(deviceName, O_RDWR); + DbgFree(deviceName); + DbgFree(driverName); + if (s_info.fd < 0) { + ErrPrint("Failed to open a drm device: (%s)\n", strerror(errno)); + s_info.evt_base = 0; + s_info.err_base = 0; + return DBOX_STATUS_ERROR_NONE; + } - s_info.slp_bufmgr = tbm_bufmgr_init(s_info.fd); - if (!s_info.slp_bufmgr) { - ErrPrint("Failed to init bufmgr\n"); - if (close(s_info.fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - s_info.fd = -1; - s_info.evt_base = 0; - s_info.err_base = 0; - return DBOX_STATUS_ERROR_NONE; + drmGetMagic(s_info.fd, &magic); + DbgPrint("DRM Magic: 0x%X\n", magic); + if (!DRI2Authenticate(ecore_x_display_get(), DefaultRootWindow(ecore_x_display_get()), (unsigned int)magic)) { + ErrPrint("Failed to do authenticate for DRI2\n"); + if (close(s_info.fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } + s_info.fd = -1; + s_info.evt_base = 0; + s_info.err_base = 0; + return DBOX_STATUS_ERROR_NONE; + } + s_info.slp_bufmgr = tbm_bufmgr_init(s_info.fd); + if (!s_info.slp_bufmgr) { + ErrPrint("Failed to init bufmgr\n"); + if (close(s_info.fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + s_info.fd = -1; + s_info.evt_base = 0; + s_info.err_base = 0; return DBOX_STATUS_ERROR_NONE; + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int buffer_handler_fini(void) { - if (s_info.fd >= 0) { - if (close(s_info.fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - s_info.fd = -1; + if (s_info.fd >= 0) { + if (close(s_info.fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } + s_info.fd = -1; + } - if (s_info.slp_bufmgr) { - tbm_bufmgr_deinit(s_info.slp_bufmgr); - s_info.slp_bufmgr = NULL; - } + if (s_info.slp_bufmgr) { + tbm_bufmgr_deinit(s_info.slp_bufmgr); + s_info.slp_bufmgr = NULL; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline dynamicbox_fb_t raw_open_file(const char *filename) { - dynamicbox_fb_t buffer; - int fd; - off_t off; - int ret; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - return NULL; - } + dynamicbox_fb_t buffer; + int fd; + off_t off; + int ret; - off = lseek(fd, 0L, SEEK_END); - if (off == (off_t)-1) { - ErrPrint("lseek: %s\n", strerror(errno)); + fd = open(filename, O_RDONLY); + if (fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + off = lseek(fd, 0L, SEEK_END); + if (off == (off_t)-1) { + ErrPrint("lseek: %s\n", strerror(errno)); - return NULL; + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } - if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) { - ErrPrint("lseek: %s\n", strerror(errno)); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) { + ErrPrint("lseek: %s\n", strerror(errno)); - return NULL; + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } - buffer = calloc(1, sizeof(*buffer) + off); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + buffer = calloc(1, sizeof(*buffer) + off); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } - buffer->state = DBOX_FB_STATE_CREATED; - buffer->type = DBOX_FB_TYPE_FILE; - buffer->refcnt = 0; - buffer->info = (void *)off; - - ret = read(fd, buffer->data, off); - if (ret < 0) { - ErrPrint("read: %s\n", strerror(errno)); - DbgFree(buffer); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + buffer->state = DBOX_FB_STATE_CREATED; + buffer->type = DBOX_FB_TYPE_FILE; + buffer->refcnt = 0; + buffer->info = (void *)off; - return NULL; - } + ret = read(fd, buffer->data, off); + if (ret < 0) { + ErrPrint("read: %s\n", strerror(errno)); + DbgFree(buffer); if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); + ErrPrint("close: %s\n", strerror(errno)); } - return buffer; + return NULL; + } + + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + + return buffer; } static inline int raw_close_file(dynamicbox_fb_t buffer) { - DbgFree(buffer); - return 0; + DbgFree(buffer); + return 0; } static inline dynamicbox_fb_t raw_open_shm(int shm) { - dynamicbox_fb_t buffer; + dynamicbox_fb_t buffer; - buffer = (dynamicbox_fb_t)shmat(shm, NULL, SHM_RDONLY); - if (buffer == (dynamicbox_fb_t)-1) { - ErrPrint("shmat: %s\n", strerror(errno)); - return NULL; - } + buffer = (dynamicbox_fb_t)shmat(shm, NULL, SHM_RDONLY); + if (buffer == (dynamicbox_fb_t)-1) { + ErrPrint("shmat: %s\n", strerror(errno)); + return NULL; + } - return buffer; + return buffer; } static inline int raw_close_shm(dynamicbox_fb_t buffer) { - int ret; + int ret; - ret = shmdt(buffer); - if (ret < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } + ret = shmdt(buffer); + if (ret < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } - return ret; + return ret; } static inline dynamicbox_fb_t raw_open_pixmap(unsigned int pixmap) { - dynamicbox_fb_t buffer; + dynamicbox_fb_t buffer; - buffer = calloc(1, sizeof(*buffer) + DYNAMICBOX_CONF_DEFAULT_PIXELS); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + buffer = calloc(1, sizeof(*buffer) + DYNAMICBOX_CONF_DEFAULT_PIXELS); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - buffer->state = DBOX_FB_STATE_CREATED; - buffer->type = DBOX_FB_TYPE_PIXMAP; + buffer->state = DBOX_FB_STATE_CREATED; + buffer->type = DBOX_FB_TYPE_PIXMAP; - return buffer; + return buffer; } static inline int raw_close_pixmap(dynamicbox_fb_t buffer) { - DbgFree(buffer); - return 0; + DbgFree(buffer); + return 0; } EAPI void *buffer_handler_raw_data(dynamicbox_fb_t buffer) { - if (!buffer || buffer->state != DBOX_FB_STATE_CREATED) { - return NULL; - } + if (!buffer || buffer->state != DBOX_FB_STATE_CREATED) { + return NULL; + } - return buffer->data; + return buffer->data; } EAPI int buffer_handler_raw_size(dynamicbox_fb_t buffer) { - if (!buffer || buffer->state != DBOX_FB_STATE_CREATED) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!buffer || buffer->state != DBOX_FB_STATE_CREATED) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return (int)buffer->info; + return (int)buffer->info; } EAPI dynamicbox_fb_t buffer_handler_raw_open(enum dynamicbox_fb_type dynamicbox_fb_type, void *resource) { - dynamicbox_fb_t handle; + dynamicbox_fb_t handle; - switch (dynamicbox_fb_type) { + switch (dynamicbox_fb_type) { case DBOX_FB_TYPE_SHM: - handle = raw_open_shm((int)resource); - break; + handle = raw_open_shm((int)resource); + break; case DBOX_FB_TYPE_FILE: - handle = raw_open_file(resource); - break; + handle = raw_open_file(resource); + break; case DBOX_FB_TYPE_PIXMAP: - handle = raw_open_pixmap((unsigned int)resource); - break; + handle = raw_open_pixmap((unsigned int)resource); + break; default: - handle = NULL; - break; - } + handle = NULL; + break; + } - return handle; + return handle; } EAPI int buffer_handler_raw_close(dynamicbox_fb_t buffer) { - int ret; + int ret; - if (!buffer || buffer->state != DBOX_FB_STATE_CREATED) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!buffer || buffer->state != DBOX_FB_STATE_CREATED) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (buffer->type) { + switch (buffer->type) { case DBOX_FB_TYPE_SHM: - ret = raw_close_shm(buffer); - break; + ret = raw_close_shm(buffer); + break; case DBOX_FB_TYPE_FILE: - ret = raw_close_file(buffer); - break; + ret = raw_close_file(buffer); + break; case DBOX_FB_TYPE_PIXMAP: - ret = raw_close_pixmap(buffer); - break; + ret = raw_close_pixmap(buffer); + break; default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - return ret; + return ret; } EAPI int buffer_handler_lock(struct buffer_info *info) { - if (!info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->type == DBOX_FB_TYPE_PIXMAP) { - return DBOX_STATUS_ERROR_NONE; - } + if (info->type == DBOX_FB_TYPE_PIXMAP) { + return DBOX_STATUS_ERROR_NONE; + } - if (info->type == DBOX_FB_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } + if (info->type == DBOX_FB_TYPE_FILE) { + return DBOX_STATUS_ERROR_NONE; + } - return dynamicbox_service_acquire_lock(info->lock_info); + return dynamicbox_service_acquire_lock(info->lock_info); } EAPI int buffer_handler_unlock(struct buffer_info *info) { - if (!info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->type == DBOX_FB_TYPE_PIXMAP) { - return DBOX_STATUS_ERROR_NONE; - } + if (info->type == DBOX_FB_TYPE_PIXMAP) { + return DBOX_STATUS_ERROR_NONE; + } - if (info->type == DBOX_FB_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } + if (info->type == DBOX_FB_TYPE_FILE) { + return DBOX_STATUS_ERROR_NONE; + } - return dynamicbox_service_release_lock(info->lock_info); + return dynamicbox_service_release_lock(info->lock_info); } EAPI int buffer_handler_pixels(struct buffer_info *info) { - if (!info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return info->pixel_size; + return info->pixel_size; } EAPI int buffer_handler_auto_align(void) { - return DYNAMICBOX_CONF_AUTO_ALIGN; + return DYNAMICBOX_CONF_AUTO_ALIGN; } EAPI int buffer_handler_stride(struct buffer_info *info) { - dynamicbox_fb_t buffer; - struct gem_data *gem; - int stride; + dynamicbox_fb_t buffer; + struct gem_data *gem; + int stride; - if (!info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (info->type) { + switch (info->type) { case DBOX_FB_TYPE_FILE: case DBOX_FB_TYPE_SHM: - stride = info->w * info->pixel_size; - break; + stride = info->w * info->pixel_size; + break; case DBOX_FB_TYPE_PIXMAP: - buffer = info->buffer; - if (!buffer) { - stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } - - gem = (struct gem_data *)buffer->data; - if (!gem) { - stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } - - if (!gem->dri2_buffer) { - /* - * Uhm... - */ - ErrPrint("dri2_buffer info is not ready yet!\n"); - stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + buffer = info->buffer; + if (!buffer) { + stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - stride = gem->dri2_buffer->pitch; + gem = (struct gem_data *)buffer->data; + if (!gem) { + stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; break; - default: + } + + if (!gem->dri2_buffer) { + /* + * Uhm... + */ + ErrPrint("dri2_buffer info is not ready yet!\n"); stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; break; - } + } + + stride = gem->dri2_buffer->pitch; + break; + default: + stride = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - return stride; + return stride; } /*! @@ -1633,109 +1633,109 @@ EAPI int buffer_handler_stride(struct buffer_info *info) HAPI int buffer_handler_set_data(struct buffer_info *info, void *data) { - if (!info) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - info->data = data; - return DBOX_STATUS_ERROR_NONE; + info->data = data; + return DBOX_STATUS_ERROR_NONE; } HAPI void *buffer_handler_data(struct buffer_info *info) { - if (!info) { - ErrPrint("Invalid handle\n"); - return NULL; - } + if (!info) { + ErrPrint("Invalid handle\n"); + return NULL; + } - return info->data; + return info->data; } HAPI int buffer_handler_destroy(struct buffer_info *info) { - Eina_List *l; - dynamicbox_fb_t buffer; + Eina_List *l; + dynamicbox_fb_t buffer; - if (!info) { - DbgPrint("Buffer is not created yet. info is NIL\n"); - return DBOX_STATUS_ERROR_NONE; - } + if (!info) { + DbgPrint("Buffer is not created yet. info is NIL\n"); + return DBOX_STATUS_ERROR_NONE; + } - EINA_LIST_FOREACH(s_info.pixmap_list, l, buffer) { - if (buffer->info == info) { - buffer->info = NULL; - } + EINA_LIST_FOREACH(s_info.pixmap_list, l, buffer) { + if (buffer->info == info) { + buffer->info = NULL; } + } - buffer_handler_unload(info); - DbgFree(info->id); - DbgFree(info); - return DBOX_STATUS_ERROR_NONE; + buffer_handler_unload(info); + DbgFree(info->id); + DbgFree(info); + return DBOX_STATUS_ERROR_NONE; } HAPI struct buffer_info *buffer_handler_create(struct inst_info *inst, enum dynamicbox_fb_type type, int w, int h, int pixel_size) { - struct buffer_info *info; + struct buffer_info *info; - info = malloc(sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + info = malloc(sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - switch (type) { + switch (type) { case DBOX_FB_TYPE_SHM: - if (pixel_size != DYNAMICBOX_CONF_DEFAULT_PIXELS) { - DbgPrint("SHM only supportes %d bytes pixels (requested: %d)\n", DYNAMICBOX_CONF_DEFAULT_PIXELS, pixel_size); - pixel_size = DYNAMICBOX_CONF_DEFAULT_PIXELS; - } + if (pixel_size != DYNAMICBOX_CONF_DEFAULT_PIXELS) { + DbgPrint("SHM only supportes %d bytes pixels (requested: %d)\n", DYNAMICBOX_CONF_DEFAULT_PIXELS, pixel_size); + pixel_size = DYNAMICBOX_CONF_DEFAULT_PIXELS; + } - info->id = strdup(SCHEMA_SHM "-1"); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info); - return NULL; - } - break; + info->id = strdup(SCHEMA_SHM "-1"); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info); + return NULL; + } + break; case DBOX_FB_TYPE_FILE: - if (pixel_size != DYNAMICBOX_CONF_DEFAULT_PIXELS) { - DbgPrint("FILE only supportes %d bytes pixels (requested: %d)\n", DYNAMICBOX_CONF_DEFAULT_PIXELS, pixel_size); - pixel_size = DYNAMICBOX_CONF_DEFAULT_PIXELS; - } + if (pixel_size != DYNAMICBOX_CONF_DEFAULT_PIXELS) { + DbgPrint("FILE only supportes %d bytes pixels (requested: %d)\n", DYNAMICBOX_CONF_DEFAULT_PIXELS, pixel_size); + pixel_size = DYNAMICBOX_CONF_DEFAULT_PIXELS; + } - info->id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info); - return NULL; - } - break; + info->id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info); + return NULL; + } + break; case DBOX_FB_TYPE_PIXMAP: - info->id = strdup(SCHEMA_PIXMAP "0:0"); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info); - return NULL; - } - break; - default: - ErrPrint("Invalid type\n"); + info->id = strdup(SCHEMA_PIXMAP "0:0"); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); DbgFree(info); return NULL; - } - - info->lock_info = NULL; - info->w = w; - info->h = h; - info->pixel_size = pixel_size; - info->type = type; - info->is_loaded = 0; - info->inst = inst; - info->buffer = NULL; - info->data = NULL; + } + break; + default: + ErrPrint("Invalid type\n"); + DbgFree(info); + return NULL; + } - return info; + info->lock_info = NULL; + info->w = w; + info->h = h; + info->pixel_size = pixel_size; + info->type = type; + info->is_loaded = 0; + info->inst = inst; + info->buffer = NULL; + info->data = NULL; + + return info; } /* End of a file */ diff --git a/src/buffer_handler_wayland.c b/src/buffer_handler_wayland.c index 8530dd5..1eaef62 100644 --- a/src/buffer_handler_wayland.c +++ b/src/buffer_handler_wayland.c @@ -43,431 +43,431 @@ #include "script_handler.h" // Reverse dependency. must has to be broken struct buffer { - enum { - CREATED = 0x00beef00, - DESTROYED = 0x00dead00 - } state; - enum buffer_type type; - int refcnt; - void *info; - char data[]; + enum { + CREATED = 0x00beef00, + DESTROYED = 0x00dead00 + } state; + enum buffer_type type; + int refcnt; + void *info; + char data[]; }; struct buffer_info { - void *buffer; - char *id; - char *lock; - int lock_fd; + void *buffer; + char *id; + char *lock; + int lock_fd; - enum buffer_type type; + enum buffer_type type; - int w; - int h; - int pixel_size; - int auto_align; - int is_loaded; + int w; + int h; + int pixel_size; + int auto_align; + int is_loaded; - struct inst_info *inst; - void *data; + struct inst_info *inst; + void *data; }; static int destroy_lock_file(struct buffer_info *info) { - if (!info->inst) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info->inst) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->lock) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info->lock) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (close(info->lock_fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - info->lock_fd = -1; + if (close(info->lock_fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + info->lock_fd = -1; - if (unlink(info->lock) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } + if (unlink(info->lock) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); + } - DbgFree(info->lock); - info->lock = NULL; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->lock); + info->lock = NULL; + return DBOX_STATUS_ERROR_NONE; } static int create_lock_file(struct buffer_info *info) { - const char *id; - int len; - char *file; - char target[3] = "pd"; - - if (!info->inst) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - id = instance_id(info->inst); - if (!id) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - len = strlen(id); - file = malloc(len + 20); - if (!file) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - if (script_handler_buffer_info(instance_gbar_script(info->inst)) != info && instance_gbar_buffer(info->inst) != info) { - target[0] = 'l'; - target[1] = 'b'; - /* target[2] = '\0'; // We already have this ;) */ - } - - snprintf(file, len + 20, "%s.%s.lck", util_uri_to_path(id), target); - info->lock_fd = open(file, O_WRONLY|O_CREAT, 0644); - if (info->lock_fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - DbgFree(file); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - info->lock = file; - return DBOX_STATUS_ERROR_NONE; + const char *id; + int len; + char *file; + char target[3] = "pd"; + + if (!info->inst) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + id = instance_id(info->inst); + if (!id) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + len = strlen(id); + file = malloc(len + 20); + if (!file) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + if (script_handler_buffer_info(instance_gbar_script(info->inst)) != info && instance_gbar_buffer(info->inst) != info) { + target[0] = 'l'; + target[1] = 'b'; + /* target[2] = '\0'; // We already have this ;) */ + } + + snprintf(file, len + 20, "%s.%s.lck", util_uri_to_path(id), target); + info->lock_fd = open(file, O_WRONLY|O_CREAT, 0644); + if (info->lock_fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + DbgFree(file); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + info->lock = file; + return DBOX_STATUS_ERROR_NONE; } static int do_buffer_lock(struct buffer_info *buffer) { - struct flock flock; - int ret; + struct flock flock; + int ret; - if (buffer->lock_fd < 0) { - return DBOX_STATUS_ERROR_NONE; - } + if (buffer->lock_fd < 0) { + return DBOX_STATUS_ERROR_NONE; + } - flock.l_type = F_WRLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 0; - flock.l_pid = getpid(); + flock.l_type = F_WRLCK; + flock.l_whence = SEEK_SET; + flock.l_start = 0; + flock.l_len = 0; + flock.l_pid = getpid(); - do { - ret = fcntl(buffer->lock_fd, F_SETLKW, &flock); - if (ret < 0) { - ret = errno; - ErrPrint("fcntl: %s\n", strerror(errno)); - } - } while (ret == EINTR); + do { + ret = fcntl(buffer->lock_fd, F_SETLKW, &flock); + if (ret < 0) { + ret = errno; + ErrPrint("fcntl: %s\n", strerror(errno)); + } + } while (ret == EINTR); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static int do_buffer_unlock(struct buffer_info *buffer) { - struct flock flock; - int ret; + struct flock flock; + int ret; - if (buffer->lock_fd < 0) { - return DBOX_STATUS_ERROR_NONE; - } + if (buffer->lock_fd < 0) { + return DBOX_STATUS_ERROR_NONE; + } - flock.l_type = F_UNLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 0; - flock.l_pid = getpid(); + flock.l_type = F_UNLCK; + flock.l_whence = SEEK_SET; + flock.l_start = 0; + flock.l_len = 0; + flock.l_pid = getpid(); - do { - ret = fcntl(buffer->lock_fd, F_SETLKW, &flock); - if (ret < 0) { - ret = errno; - ErrPrint("fcntl: %s\n", strerror(errno)); - } - } while (ret == EINTR); + do { + ret = fcntl(buffer->lock_fd, F_SETLKW, &flock); + if (ret < 0) { + ret = errno; + ErrPrint("fcntl: %s\n", strerror(errno)); + } + } while (ret == EINTR); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline int load_file_buffer(struct buffer_info *info) { - struct buffer *buffer; - double timestamp; - int size; - char *new_id; - int len; - - len = strlen(IMAGE_PATH) + 40; - new_id = malloc(len); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - timestamp = util_timestamp(); - snprintf(new_id, len, SCHEMA_FILE "%s%lf", IMAGE_PATH, timestamp); - - size = sizeof(*buffer) + info->w * info->h * info->pixel_size; - if (!size) { - ErrPrint("Canvas buffer size is ZERO\n"); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - buffer = calloc(1, size); - if (!buffer) { - ErrPrint("Failed to allocate buffer\n"); - DbgFree(new_id); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - buffer->type = BUFFER_TYPE_FILE; - buffer->refcnt = 0; - buffer->state = CREATED; - buffer->info = info; - - DbgFree(info->id); - info->id = new_id; - info->buffer = buffer; - info->is_loaded = 1; - - DbgPrint("FILE type %d created\n", size); - return DBOX_STATUS_ERROR_NONE; + struct buffer *buffer; + double timestamp; + int size; + char *new_id; + int len; + + len = strlen(IMAGE_PATH) + 40; + new_id = malloc(len); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + timestamp = util_timestamp(); + snprintf(new_id, len, SCHEMA_FILE "%s%lf", IMAGE_PATH, timestamp); + + size = sizeof(*buffer) + info->w * info->h * info->pixel_size; + if (!size) { + ErrPrint("Canvas buffer size is ZERO\n"); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + buffer = calloc(1, size); + if (!buffer) { + ErrPrint("Failed to allocate buffer\n"); + DbgFree(new_id); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + buffer->type = BUFFER_TYPE_FILE; + buffer->refcnt = 0; + buffer->state = CREATED; + buffer->info = info; + + DbgFree(info->id); + info->id = new_id; + info->buffer = buffer; + info->is_loaded = 1; + + DbgPrint("FILE type %d created\n", size); + return DBOX_STATUS_ERROR_NONE; } static inline int load_shm_buffer(struct buffer_info *info) { - int id; - int size; - struct buffer *buffer; /* Just for getting a size */ - char *new_id; - int len; + int id; + int size; + struct buffer *buffer; /* Just for getting a size */ + char *new_id; + int len; - size = info->w * info->h * info->pixel_size; - if (!size) { - ErrPrint("Invalid buffer size\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - id = shmget(IPC_PRIVATE, size + sizeof(*buffer), IPC_CREAT | 0666); - if (id < 0) { - ErrPrint("shmget: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } + size = info->w * info->h * info->pixel_size; + if (!size) { + ErrPrint("Invalid buffer size\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - buffer = shmat(id, NULL, 0); - if (buffer == (void *)-1) { - ErrPrint("%s shmat: %s\n", info->id, strerror(errno)); + id = shmget(IPC_PRIVATE, size + sizeof(*buffer), IPC_CREAT | 0666); + if (id < 0) { + ErrPrint("shmget: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } - if (shmctl(id, IPC_RMID, 0) < 0) { - ErrPrint("%s shmctl: %s\n", info->id, strerror(errno)); - } + buffer = shmat(id, NULL, 0); + if (buffer == (void *)-1) { + ErrPrint("%s shmat: %s\n", info->id, strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; + if (shmctl(id, IPC_RMID, 0) < 0) { + ErrPrint("%s shmctl: %s\n", info->id, strerror(errno)); } - buffer->type = BUFFER_TYPE_SHM; - buffer->refcnt = id; - buffer->state = CREATED; /*!< Needless */ - buffer->info = (void *)size; /*!< Use this field to indicates the size of SHM */ + return DBOX_STATUS_ERROR_FAULT; + } - len = strlen(SCHEMA_SHM) + 30; /* strlen("shm://") + 30 */ + buffer->type = BUFFER_TYPE_SHM; + buffer->refcnt = id; + buffer->state = CREATED; /*!< Needless */ + buffer->info = (void *)size; /*!< Use this field to indicates the size of SHM */ - new_id = malloc(len); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - if (shmdt(buffer) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } + len = strlen(SCHEMA_SHM) + 30; /* strlen("shm://") + 30 */ - if (shmctl(id, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } + new_id = malloc(len); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + if (shmdt(buffer) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + if (shmctl(id, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); } - snprintf(new_id, len, SCHEMA_SHM "%d", id); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->id); - info->id = new_id; - info->buffer = buffer; - info->is_loaded = 1; - return DBOX_STATUS_ERROR_NONE; + snprintf(new_id, len, SCHEMA_SHM "%d", id); + + DbgFree(info->id); + info->id = new_id; + info->buffer = buffer; + info->is_loaded = 1; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_load(struct buffer_info *info) { - int ret; + int ret; - if (!info) { - ErrPrint("buffer handler is nil\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("buffer handler is nil\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->is_loaded) { - DbgPrint("Buffer is already loaded\n"); - return DBOX_STATUS_ERROR_NONE; - } + if (info->is_loaded) { + DbgPrint("Buffer is already loaded\n"); + return DBOX_STATUS_ERROR_NONE; + } - switch (info->type) { + switch (info->type) { case BUFFER_TYPE_FILE: - ret = load_file_buffer(info); - (void)create_lock_file(info); - break; + ret = load_file_buffer(info); + (void)create_lock_file(info); + break; case BUFFER_TYPE_SHM: - ret = load_shm_buffer(info); - (void)create_lock_file(info); - break; + ret = load_shm_buffer(info); + (void)create_lock_file(info); + break; case BUFFER_TYPE_PIXMAP: default: - ErrPrint("Invalid buffer\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ErrPrint("Invalid buffer\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - return ret; + return ret; } static inline int unload_file_buffer(struct buffer_info *info) { - const char *path; - char *new_id; + const char *path; + char *new_id; - new_id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + new_id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->buffer); - info->buffer = NULL; + DbgFree(info->buffer); + info->buffer = NULL; - path = util_uri_to_path(info->id); - if (path && unlink(path) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } + path = util_uri_to_path(info->id); + if (path && unlink(path) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); + } - DbgFree(info->id); - info->id = new_id; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->id); + info->id = new_id; + return DBOX_STATUS_ERROR_NONE; } static inline int unload_shm_buffer(struct buffer_info *info) { - int id; - char *new_id; + int id; + char *new_id; - new_id = strdup(SCHEMA_SHM "-1"); - if (!new_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + new_id = strdup(SCHEMA_SHM "-1"); + if (!new_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - if (sscanf(info->id, SCHEMA_SHM "%d", &id) != 1) { - ErrPrint("%s Invalid ID\n", info->id); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (sscanf(info->id, SCHEMA_SHM "%d", &id) != 1) { + ErrPrint("%s Invalid ID\n", info->id); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (id < 0) { - ErrPrint("(%s) Invalid id: %d\n", info->id, id); - DbgFree(new_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (id < 0) { + ErrPrint("(%s) Invalid id: %d\n", info->id, id); + DbgFree(new_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (shmdt(info->buffer) < 0) { - ErrPrint("Detach shm: %s\n", strerror(errno)); - } + if (shmdt(info->buffer) < 0) { + ErrPrint("Detach shm: %s\n", strerror(errno)); + } - if (shmctl(id, IPC_RMID, 0) < 0) { - ErrPrint("Remove shm: %s\n", strerror(errno)); - } + if (shmctl(id, IPC_RMID, 0) < 0) { + ErrPrint("Remove shm: %s\n", strerror(errno)); + } - info->buffer = NULL; + info->buffer = NULL; - DbgFree(info->id); - info->id = new_id; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->id); + info->id = new_id; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_unload(struct buffer_info *info) { - int ret; + int ret; - if (!info) { - ErrPrint("buffer handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("buffer handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->is_loaded) { - ErrPrint("Buffer is not loaded\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info->is_loaded) { + ErrPrint("Buffer is not loaded\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (info->type) { + switch (info->type) { case BUFFER_TYPE_FILE: - (void)destroy_lock_file(info); - ret = unload_file_buffer(info); - break; + (void)destroy_lock_file(info); + ret = unload_file_buffer(info); + break; case BUFFER_TYPE_SHM: - (void)destroy_lock_file(info); - ret = unload_shm_buffer(info); - break; + (void)destroy_lock_file(info); + ret = unload_shm_buffer(info); + break; case BUFFER_TYPE_PIXMAP: default: - ErrPrint("Invalid buffer\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ErrPrint("Invalid buffer\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - if (ret == 0) { - info->is_loaded = 0; - } + if (ret == 0) { + info->is_loaded = 0; + } - return ret; + return ret; } EAPI const char *buffer_handler_id(const struct buffer_info *info) { - return info ? info->id : ""; + return info ? info->id : ""; } EAPI enum buffer_type buffer_handler_type(const struct buffer_info *info) { - return info ? info->type : BUFFER_TYPE_ERROR; + return info ? info->type : BUFFER_TYPE_ERROR; } EAPI void *buffer_handler_fb(struct buffer_info *info) { - struct buffer *buffer; + struct buffer *buffer; - if (!info) { - return NULL; - } + if (!info) { + return NULL; + } - buffer = info->buffer; + buffer = info->buffer; - if (info->type == BUFFER_TYPE_PIXMAP) { - return NULL; - } + if (info->type == BUFFER_TYPE_PIXMAP) { + return NULL; + } - return buffer->data; + return buffer->data; } EAPI int buffer_handler_pixmap(const struct buffer_info *info) { - return 0; + return 0; } EAPI void *buffer_handler_pixmap_acquire_buffer(struct buffer_info *info) { - return NULL; + return NULL; } EAPI void *buffer_handler_pixmap_buffer(struct buffer_info *info) { - return NULL; + return NULL; } /*! @@ -475,7 +475,7 @@ EAPI void *buffer_handler_pixmap_buffer(struct buffer_info *info) */ EAPI void *buffer_handler_pixmap_ref(struct buffer_info *info) { - return NULL; + return NULL; } /*! @@ -483,12 +483,12 @@ EAPI void *buffer_handler_pixmap_ref(struct buffer_info *info) */ EAPI void *buffer_handler_pixmap_find(int pixmap) { - return NULL; + return NULL; } EAPI int buffer_handler_pixmap_release_buffer(void *canvas) { - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } /*! @@ -499,323 +499,323 @@ EAPI int buffer_handler_pixmap_release_buffer(void *canvas) */ EAPI int buffer_handler_pixmap_unref(void *buffer_ptr) { - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_is_loaded(const struct buffer_info *info) { - return info ? info->is_loaded : 0; + return info ? info->is_loaded : 0; } EAPI void buffer_handler_update_size(struct buffer_info *info, int w, int h) { - if (!info) { - return; - } + if (!info) { + return; + } - info->w = w; - info->h = h; + info->w = w; + info->h = h; } EAPI int buffer_handler_resize(struct buffer_info *info, int w, int h) { - int ret; + int ret; - if (!info) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("Invalid handler\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->w == w && info->h == h) { - DbgPrint("No changes\n"); - return DBOX_STATUS_ERROR_NONE; - } + if (info->w == w && info->h == h) { + DbgPrint("No changes\n"); + return DBOX_STATUS_ERROR_NONE; + } - buffer_handler_update_size(info, w, h); + buffer_handler_update_size(info, w, h); - if (!info->is_loaded) { - DbgPrint("Buffer size is updated[%dx%d]\n", w, h); - return DBOX_STATUS_ERROR_NONE; - } + if (!info->is_loaded) { + DbgPrint("Buffer size is updated[%dx%d]\n", w, h); + return DBOX_STATUS_ERROR_NONE; + } - ret = buffer_handler_unload(info); - if (ret < 0) { - ErrPrint("Unload: %d\n", ret); - } + ret = buffer_handler_unload(info); + if (ret < 0) { + ErrPrint("Unload: %d\n", ret); + } - ret = buffer_handler_load(info); - if (ret < 0) { - ErrPrint("Load: %d\n", ret); - } + ret = buffer_handler_load(info); + if (ret < 0) { + ErrPrint("Load: %d\n", ret); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int buffer_handler_get_size(struct buffer_info *info, int *w, int *h) { - if (!info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (w) { - *w = info->w; - } - if (h) { - *h = info->h; - } + if (w) { + *w = info->w; + } + if (h) { + *h = info->h; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI struct inst_info *buffer_handler_instance(struct buffer_info *info) { - return info->inst; + return info->inst; } EAPI void buffer_handler_flush(struct buffer_info *info) { - int fd; - int size; - struct buffer *buffer; + int fd; + int size; + struct buffer *buffer; + + if (!info || !info->buffer) { + return; + } - if (!info || !info->buffer) { - return; + buffer = info->buffer; + + if (buffer->type == BUFFER_TYPE_PIXMAP) { + /*! + * \note + * Not supported for wayland or this should be ported correctly + */ + } else if (buffer->type == BUFFER_TYPE_FILE) { + fd = open(util_uri_to_path(info->id), O_WRONLY | O_CREAT, 0644); + if (fd < 0) { + ErrPrint("%s open falied: %s\n", util_uri_to_path(info->id), strerror(errno)); + return; } - buffer = info->buffer; - - if (buffer->type == BUFFER_TYPE_PIXMAP) { - /*! - * \note - * Not supported for wayland or this should be ported correctly - */ - } else if (buffer->type == BUFFER_TYPE_FILE) { - fd = open(util_uri_to_path(info->id), O_WRONLY | O_CREAT, 0644); - if (fd < 0) { - ErrPrint("%s open falied: %s\n", util_uri_to_path(info->id), strerror(errno)); - return; - } - - size = info->w * info->h * info->pixel_size; - do_buffer_lock(info); - if (write(fd, info->buffer, size) != size) { - ErrPrint("Write is not completed: %s\n", strerror(errno)); - } - do_buffer_unlock(info); - - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - } else { - DbgPrint("Flush nothing\n"); + size = info->w * info->h * info->pixel_size; + do_buffer_lock(info); + if (write(fd, info->buffer, size) != size) { + ErrPrint("Write is not completed: %s\n", strerror(errno)); } + do_buffer_unlock(info); + + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + } else { + DbgPrint("Flush nothing\n"); + } } HAPI int buffer_handler_init(void) { - /*! - * \TODO - * Implement this for wayland - */ - if (USE_SW_BACKEND) { - DbgPrint("Fallback to the S/W Backend\n"); - return DBOX_STATUS_ERROR_NONE; - } - + /*! + * \TODO + * Implement this for wayland + */ + if (USE_SW_BACKEND) { + DbgPrint("Fallback to the S/W Backend\n"); return DBOX_STATUS_ERROR_NONE; + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int buffer_handler_fini(void) { - /*! - * \TODO - * Implement this for wayland - */ - return DBOX_STATUS_ERROR_NONE; + /*! + * \TODO + * Implement this for wayland + */ + return DBOX_STATUS_ERROR_NONE; } static inline struct buffer *raw_open_file(const char *filename) { - struct buffer *buffer; - int fd; - off_t off; - int ret; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - return NULL; - } + struct buffer *buffer; + int fd; + off_t off; + int ret; - off = lseek(fd, 0L, SEEK_END); - if (off == (off_t)-1) { - ErrPrint("lseek: %s\n", strerror(errno)); + fd = open(filename, O_RDONLY); + if (fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + off = lseek(fd, 0L, SEEK_END); + if (off == (off_t)-1) { + ErrPrint("lseek: %s\n", strerror(errno)); - return NULL; + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } - if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) { - ErrPrint("lseek: %s\n", strerror(errno)); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) { + ErrPrint("lseek: %s\n", strerror(errno)); - return NULL; + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } - buffer = calloc(1, sizeof(*buffer) + off); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + buffer = calloc(1, sizeof(*buffer) + off); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } - buffer->state = CREATED; - buffer->type = BUFFER_TYPE_FILE; - buffer->refcnt = 0; - buffer->info = (void *)off; - - ret = read(fd, buffer->data, off); - if (ret < 0) { - ErrPrint("read: %s\n", strerror(errno)); - DbgFree(buffer); + return NULL; + } - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + buffer->state = CREATED; + buffer->type = BUFFER_TYPE_FILE; + buffer->refcnt = 0; + buffer->info = (void *)off; - return NULL; - } + ret = read(fd, buffer->data, off); + if (ret < 0) { + ErrPrint("read: %s\n", strerror(errno)); + DbgFree(buffer); if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); + ErrPrint("close: %s\n", strerror(errno)); } - return buffer; + return NULL; + } + + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + + return buffer; } static inline int raw_close_file(struct buffer *buffer) { - DbgFree(buffer); - return 0; + DbgFree(buffer); + return 0; } static inline struct buffer *raw_open_shm(int shm) { - struct buffer *buffer; + struct buffer *buffer; - buffer = (struct buffer *)shmat(shm, NULL, SHM_RDONLY); - if (buffer == (struct buffer *)-1) { - ErrPrint("shmat: %s\n", strerror(errno)); - return NULL; - } + buffer = (struct buffer *)shmat(shm, NULL, SHM_RDONLY); + if (buffer == (struct buffer *)-1) { + ErrPrint("shmat: %s\n", strerror(errno)); + return NULL; + } - return buffer; + return buffer; } static inline int raw_close_shm(struct buffer *buffer) { - int ret; + int ret; - ret = shmdt(buffer); - if (ret < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } + ret = shmdt(buffer); + if (ret < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } - return ret; + return ret; } EAPI void *buffer_handler_raw_data(struct buffer *buffer) { - if (!buffer || buffer->state != CREATED) { - return NULL; - } + if (!buffer || buffer->state != CREATED) { + return NULL; + } - return buffer->data; + return buffer->data; } EAPI int buffer_handler_raw_size(struct buffer *buffer) { - if (!buffer || buffer->state != CREATED) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!buffer || buffer->state != CREATED) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return (int)buffer->info; + return (int)buffer->info; } EAPI struct buffer *buffer_handler_raw_open(enum buffer_type buffer_type, void *resource) { - struct buffer *handle; + struct buffer *handle; - switch (buffer_type) { + switch (buffer_type) { case BUFFER_TYPE_SHM: - handle = raw_open_shm((int)resource); - break; + handle = raw_open_shm((int)resource); + break; case BUFFER_TYPE_FILE: - handle = raw_open_file(resource); - break; + handle = raw_open_file(resource); + break; case BUFFER_TYPE_PIXMAP: default: - handle = NULL; - break; - } + handle = NULL; + break; + } - return handle; + return handle; } EAPI int buffer_handler_raw_close(struct buffer *buffer) { - int ret; + int ret; - switch (buffer->type) { + switch (buffer->type) { case BUFFER_TYPE_SHM: - ret = raw_close_shm(buffer); - break; + ret = raw_close_shm(buffer); + break; case BUFFER_TYPE_FILE: - ret = raw_close_file(buffer); - break; + ret = raw_close_file(buffer); + break; case BUFFER_TYPE_PIXMAP: default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - return ret; + return ret; } EAPI int buffer_handler_lock(struct buffer_info *buffer) { - if (buffer->type == BUFFER_TYPE_PIXMAP) { - return DBOX_STATUS_ERROR_NONE; - } + if (buffer->type == BUFFER_TYPE_PIXMAP) { + return DBOX_STATUS_ERROR_NONE; + } - if (buffer->type == BUFFER_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } + if (buffer->type == BUFFER_TYPE_FILE) { + return DBOX_STATUS_ERROR_NONE; + } - return do_buffer_lock(buffer); + return do_buffer_lock(buffer); } EAPI int buffer_handler_unlock(struct buffer_info *buffer) { - if (buffer->type == BUFFER_TYPE_PIXMAP) { - return DBOX_STATUS_ERROR_NONE; - } + if (buffer->type == BUFFER_TYPE_PIXMAP) { + return DBOX_STATUS_ERROR_NONE; + } - if (buffer->type == BUFFER_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } + if (buffer->type == BUFFER_TYPE_FILE) { + return DBOX_STATUS_ERROR_NONE; + } - return do_buffer_unlock(buffer); + return do_buffer_unlock(buffer); } /*! @@ -826,98 +826,98 @@ EAPI int buffer_handler_unlock(struct buffer_info *buffer) HAPI int buffer_handler_set_data(struct buffer_info *buffer, void *data) { - if (!buffer) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!buffer) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - buffer->data = data; - return DBOX_STATUS_ERROR_NONE; + buffer->data = data; + return DBOX_STATUS_ERROR_NONE; } HAPI void *buffer_handler_data(struct buffer_info *buffer) { - if (!buffer) { - ErrPrint("Invalid handle\n"); - return NULL; - } + if (!buffer) { + ErrPrint("Invalid handle\n"); + return NULL; + } - return buffer->data; + return buffer->data; } HAPI int buffer_handler_destroy(struct buffer_info *info) { - Eina_List *l; - struct buffer *buffer; - - if (!info) { - DbgPrint("Buffer is not created yet. info is NIL\n"); - return DBOX_STATUS_ERROR_NONE; - } + Eina_List *l; + struct buffer *buffer; - buffer_handler_unload(info); - DbgFree(info->id); - DbgFree(info); + if (!info) { + DbgPrint("Buffer is not created yet. info is NIL\n"); return DBOX_STATUS_ERROR_NONE; + } + + buffer_handler_unload(info); + DbgFree(info->id); + DbgFree(info); + return DBOX_STATUS_ERROR_NONE; } HAPI struct buffer_info *buffer_handler_create(struct inst_info *inst, enum buffer_type type, int w, int h, int pixel_size, int auto_align) { - struct buffer_info *info; + struct buffer_info *info; - info = malloc(sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + info = malloc(sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - switch (type) { + switch (type) { case BUFFER_TYPE_SHM: - if (pixel_size != DEFAULT_PIXELS) { - DbgPrint("SHM only supportes %d bytes pixels (requested: %d)\n", DEFAULT_PIXELS, pixel_size); - pixel_size = DEFAULT_PIXELS; - } - - info->id = strdup(SCHEMA_SHM "-1"); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info); - return NULL; - } - break; - case BUFFER_TYPE_FILE: - if (pixel_size != DEFAULT_PIXELS) { - DbgPrint("FILE only supportes %d bytes pixels (requested: %d)\n", DEFAULT_PIXELS, pixel_size); - pixel_size = DEFAULT_PIXELS; - } - - info->id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info); - return NULL; - } - break; - case BUFFER_TYPE_PIXMAP: - default: - ErrPrint("Invalid type\n"); + if (pixel_size != DEFAULT_PIXELS) { + DbgPrint("SHM only supportes %d bytes pixels (requested: %d)\n", DEFAULT_PIXELS, pixel_size); + pixel_size = DEFAULT_PIXELS; + } + + info->id = strdup(SCHEMA_SHM "-1"); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); DbgFree(info); return NULL; - } - - info->lock = NULL; - info->lock_fd = -1; - info->w = w; - info->h = h; - info->pixel_size = pixel_size; - info->type = type; - info->is_loaded = 0; - info->inst = inst; - info->buffer = NULL; - info->data = NULL; - info->auto_align = auto_align; + } + break; + case BUFFER_TYPE_FILE: + if (pixel_size != DEFAULT_PIXELS) { + DbgPrint("FILE only supportes %d bytes pixels (requested: %d)\n", DEFAULT_PIXELS, pixel_size); + pixel_size = DEFAULT_PIXELS; + } - return info; + info->id = strdup(SCHEMA_FILE "/tmp/.live.undefined"); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info); + return NULL; + } + break; + case BUFFER_TYPE_PIXMAP: + default: + ErrPrint("Invalid type\n"); + DbgFree(info); + return NULL; + } + + info->lock = NULL; + info->lock_fd = -1; + info->w = w; + info->h = h; + info->pixel_size = pixel_size; + info->type = type; + info->is_loaded = 0; + info->inst = inst; + info->buffer = NULL; + info->data = NULL; + info->auto_align = auto_align; + + return info; } /* End of a file */ diff --git a/src/client_life.c b/src/client_life.c index edb5048..289b6eb 100644 --- a/src/client_life.c +++ b/src/client_life.c @@ -42,267 +42,267 @@ int errno; static struct { - Eina_List *client_list; - int nr_of_paused_clients; + Eina_List *client_list; + int nr_of_paused_clients; - enum global_event_process { - GLOBAL_EVENT_PROCESS_IDLE = 0x00, - GLOBAL_EVENT_PROCESS_CREATE = 0x01, - GLOBAL_EVENT_PROCESS_DESTROY = 0x02 - } in_event_process; + enum global_event_process { + GLOBAL_EVENT_PROCESS_IDLE = 0x00, + GLOBAL_EVENT_PROCESS_CREATE = 0x01, + GLOBAL_EVENT_PROCESS_DESTROY = 0x02 + } in_event_process; - Eina_List *create_event_list; - Eina_List *destroy_event_list; + Eina_List *create_event_list; + Eina_List *destroy_event_list; } s_info = { - .client_list = NULL, - .nr_of_paused_clients = 0, - .in_event_process = GLOBAL_EVENT_PROCESS_IDLE, - .create_event_list = NULL, - .destroy_event_list = NULL, + .client_list = NULL, + .nr_of_paused_clients = 0, + .in_event_process = GLOBAL_EVENT_PROCESS_IDLE, + .create_event_list = NULL, + .destroy_event_list = NULL, }; struct subscribe_item { - char *cluster; - char *category; + char *cluster; + char *category; }; struct global_event_item { - void *cbdata; - int (*cb)(struct client_node *client, void *data); - int deleted; + void *cbdata; + int (*cb)(struct client_node *client, void *data); + int deleted; }; struct event_item { - void *data; - int (*cb)(struct client_node *, void *); - int deleted; + void *data; + int (*cb)(struct client_node *, void *); + int deleted; }; struct data_item { - char *tag; - void *data; + char *tag; + void *data; }; struct client_node { - pid_t pid; - int refcnt; + pid_t pid; + int refcnt; - int paused; + int paused; - enum client_event_process { - CLIENT_EVENT_PROCESS_IDLE = 0x00, - CLIENT_EVENT_PROCESS_DEACTIVATE = 0x01, - CLIENT_EVENT_PROCESS_ACTIVATE = 0x02 - } in_event_process; - Eina_List *event_deactivate_list; - Eina_List *event_activate_list; + enum client_event_process { + CLIENT_EVENT_PROCESS_IDLE = 0x00, + CLIENT_EVENT_PROCESS_DEACTIVATE = 0x01, + CLIENT_EVENT_PROCESS_ACTIVATE = 0x02 + } in_event_process; + Eina_List *event_deactivate_list; + Eina_List *event_activate_list; - Eina_List *data_list; - Eina_List *subscribe_list; + Eina_List *data_list; + Eina_List *subscribe_list; - int faulted; - char *direct_addr; + int faulted; + char *direct_addr; }; static inline void invoke_global_destroyed_cb(struct client_node *client) { - Eina_List *l; - Eina_List *n; - struct global_event_item *item; - - s_info.in_event_process |= GLOBAL_EVENT_PROCESS_DESTROY; - EINA_LIST_FOREACH_SAFE(s_info.destroy_event_list, l, n, item) { - /*! - * The first, - * item->deleted will be checked, so if it is deleted, remove item from the list - * The second, if the first routine takes false path, - * item->cb will be called, if it returns negative value, remove item from the list - * The third, if the second routine takes false path, - * Check the item->deleted again, so if it is turnned on, remove item from the list - */ - if (item->deleted || item->cb(client, item->cbdata) < 0 || item->deleted) { - s_info.destroy_event_list = eina_list_remove(s_info.destroy_event_list, item); - DbgFree(item); - } + Eina_List *l; + Eina_List *n; + struct global_event_item *item; + + s_info.in_event_process |= GLOBAL_EVENT_PROCESS_DESTROY; + EINA_LIST_FOREACH_SAFE(s_info.destroy_event_list, l, n, item) { + /*! + * The first, + * item->deleted will be checked, so if it is deleted, remove item from the list + * The second, if the first routine takes false path, + * item->cb will be called, if it returns negative value, remove item from the list + * The third, if the second routine takes false path, + * Check the item->deleted again, so if it is turnned on, remove item from the list + */ + if (item->deleted || item->cb(client, item->cbdata) < 0 || item->deleted) { + s_info.destroy_event_list = eina_list_remove(s_info.destroy_event_list, item); + DbgFree(item); } - s_info.in_event_process &= ~GLOBAL_EVENT_PROCESS_DESTROY; + } + s_info.in_event_process &= ~GLOBAL_EVENT_PROCESS_DESTROY; } static inline void invoke_global_created_cb(struct client_node *client) { - Eina_List *l; - Eina_List *n; - struct global_event_item *item; - - s_info.in_event_process |= GLOBAL_EVENT_PROCESS_CREATE; - EINA_LIST_FOREACH_SAFE(s_info.create_event_list, l, n, item) { - /*! - * The first, - * item->deleted will be checked, so if it is deleted, remove item from the list - * The second, if the first routine takes false path, - * item->cb will be called, if it returns negative value, remove item from the list - * The third, if the second routine takes false path, - * Check the item->deleted again, so if it is turnned on, remove item from the list - */ - - if (item->deleted || item->cb(client, item->cbdata) < 0 || item->deleted) { - s_info.create_event_list = eina_list_remove(s_info.create_event_list, item); - DbgFree(item); - } + Eina_List *l; + Eina_List *n; + struct global_event_item *item; + + s_info.in_event_process |= GLOBAL_EVENT_PROCESS_CREATE; + EINA_LIST_FOREACH_SAFE(s_info.create_event_list, l, n, item) { + /*! + * The first, + * item->deleted will be checked, so if it is deleted, remove item from the list + * The second, if the first routine takes false path, + * item->cb will be called, if it returns negative value, remove item from the list + * The third, if the second routine takes false path, + * Check the item->deleted again, so if it is turnned on, remove item from the list + */ + + if (item->deleted || item->cb(client, item->cbdata) < 0 || item->deleted) { + s_info.create_event_list = eina_list_remove(s_info.create_event_list, item); + DbgFree(item); } - s_info.in_event_process &= ~GLOBAL_EVENT_PROCESS_CREATE; + } + s_info.in_event_process &= ~GLOBAL_EVENT_PROCESS_CREATE; } static inline void invoke_deactivated_cb(struct client_node *client) { - struct event_item *item; - Eina_List *l; - Eina_List *n; - - client->in_event_process |= CLIENT_EVENT_PROCESS_DEACTIVATE; - EINA_LIST_FOREACH_SAFE(client->event_deactivate_list, l, n, item) { - /*! - * The first, - * item->deleted will be checked, so if it is deleted, remove item from the list - * The second, if the first routine takes false path, - * item->cb will be called, if it returns negative value, remove item from the list - * The third, if the second routine takes false path, - * Check the item->deleted again, so if it is turnned on, remove item from the list - */ - - if (item->deleted || item->cb(client, item->data) < 0 || item->deleted) { - client->event_deactivate_list = eina_list_remove(client->event_deactivate_list, item); - DbgFree(item); - } + struct event_item *item; + Eina_List *l; + Eina_List *n; + + client->in_event_process |= CLIENT_EVENT_PROCESS_DEACTIVATE; + EINA_LIST_FOREACH_SAFE(client->event_deactivate_list, l, n, item) { + /*! + * The first, + * item->deleted will be checked, so if it is deleted, remove item from the list + * The second, if the first routine takes false path, + * item->cb will be called, if it returns negative value, remove item from the list + * The third, if the second routine takes false path, + * Check the item->deleted again, so if it is turnned on, remove item from the list + */ + + if (item->deleted || item->cb(client, item->data) < 0 || item->deleted) { + client->event_deactivate_list = eina_list_remove(client->event_deactivate_list, item); + DbgFree(item); } - client->in_event_process &= ~CLIENT_EVENT_PROCESS_DEACTIVATE; + } + client->in_event_process &= ~CLIENT_EVENT_PROCESS_DEACTIVATE; } static inline void invoke_activated_cb(struct client_node *client) { - struct event_item *item; - Eina_List *l; - Eina_List *n; - - client->in_event_process |= CLIENT_EVENT_PROCESS_ACTIVATE; - EINA_LIST_FOREACH_SAFE(client->event_activate_list, l, n, item) { - /*! - * The first, - * item->deleted will be checked, so if it is deleted, remove item from the list - * The second, if the first routine takes false path, - * item->cb will be called, if it returns negative value, remove item from the list - * The third, if the second routine takes false path, - * Check the item->deleted again, so if it is turnned on, remove item from the list - */ - - if (item->deleted || item->cb(client, item->data) < 0 || item->deleted) { - client->event_activate_list = eina_list_remove(client->event_activate_list, item); - DbgFree(item); - } + struct event_item *item; + Eina_List *l; + Eina_List *n; + + client->in_event_process |= CLIENT_EVENT_PROCESS_ACTIVATE; + EINA_LIST_FOREACH_SAFE(client->event_activate_list, l, n, item) { + /*! + * The first, + * item->deleted will be checked, so if it is deleted, remove item from the list + * The second, if the first routine takes false path, + * item->cb will be called, if it returns negative value, remove item from the list + * The third, if the second routine takes false path, + * Check the item->deleted again, so if it is turnned on, remove item from the list + */ + + if (item->deleted || item->cb(client, item->data) < 0 || item->deleted) { + client->event_activate_list = eina_list_remove(client->event_activate_list, item); + DbgFree(item); } - client->in_event_process &= ~CLIENT_EVENT_PROCESS_ACTIVATE; + } + client->in_event_process &= ~CLIENT_EVENT_PROCESS_ACTIVATE; } static inline void destroy_client_data(struct client_node *client) { - struct event_item *event; - struct data_item *data; - struct subscribe_item *item; - Ecore_Timer *timer; + struct event_item *event; + struct data_item *data; + struct subscribe_item *item; + Ecore_Timer *timer; - timer = client_del_data(client, "create,timer"); - if (timer) { - ecore_timer_del(timer); - } + timer = client_del_data(client, "create,timer"); + if (timer) { + ecore_timer_del(timer); + } - DbgPrint("Destroy client: %p\n", client); + DbgPrint("Destroy client: %p\n", client); - invoke_global_destroyed_cb(client); - client_rpc_fini(client); /*!< Finalize the RPC after invoke destroy callbacks */ + invoke_global_destroyed_cb(client); + client_rpc_fini(client); /*!< Finalize the RPC after invoke destroy callbacks */ - EINA_LIST_FREE(client->data_list, data) { - DbgPrint("Tag is not cleared (%s)\n", data->tag); - DbgFree(data->tag); - DbgFree(data); - } + EINA_LIST_FREE(client->data_list, data) { + DbgPrint("Tag is not cleared (%s)\n", data->tag); + DbgFree(data->tag); + DbgFree(data); + } - EINA_LIST_FREE(client->event_deactivate_list, event) { - DbgFree(event); - } + EINA_LIST_FREE(client->event_deactivate_list, event) { + DbgFree(event); + } - EINA_LIST_FREE(client->subscribe_list, item) { - DbgFree(item->cluster); - DbgFree(item->category); - DbgFree(item); - } + EINA_LIST_FREE(client->subscribe_list, item) { + DbgFree(item->cluster); + DbgFree(item->category); + DbgFree(item); + } - if (client->paused) { - s_info.nr_of_paused_clients--; - } + if (client->paused) { + s_info.nr_of_paused_clients--; + } - if (client->direct_addr) { - (void)unlink(client->direct_addr); - DbgFree(client->direct_addr); - } + if (client->direct_addr) { + (void)unlink(client->direct_addr); + DbgFree(client->direct_addr); + } - s_info.client_list = eina_list_remove(s_info.client_list, client); - DbgFree(client); + s_info.client_list = eina_list_remove(s_info.client_list, client); + DbgFree(client); - /*! - * \note - * If there is any changes of clients, - * We should check the pause/resume states again. - */ - xmonitor_handle_state_changes(); + /*! + * \note + * If there is any changes of clients, + * We should check the pause/resume states again. + */ + xmonitor_handle_state_changes(); } static inline struct client_node *create_client_data(pid_t pid, const char *direct_addr) { - struct client_node *client; + struct client_node *client; - client = calloc(1, sizeof(*client)); - if (!client) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + client = calloc(1, sizeof(*client)); + if (!client) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - client->pid = pid; - client->refcnt = 1; + client->pid = pid; + client->refcnt = 1; - if (direct_addr && direct_addr[0]) { - client->direct_addr = strdup(direct_addr); - if (!client->direct_addr) { - ErrPrint("Failed to allocate direct_addr (%s)\n", direct_addr); - } + if (direct_addr && direct_addr[0]) { + client->direct_addr = strdup(direct_addr); + if (!client->direct_addr) { + ErrPrint("Failed to allocate direct_addr (%s)\n", direct_addr); } + } - s_info.client_list = eina_list_append(s_info.client_list, client); + s_info.client_list = eina_list_append(s_info.client_list, client); - /*! - * \note - * Right after create a client ADT, - * We assume that the client is paused. - */ - client_paused(client); - xmonitor_handle_state_changes(); - return client; + /*! + * \note + * Right after create a client ADT, + * We assume that the client is paused. + */ + client_paused(client); + xmonitor_handle_state_changes(); + return client; } static Eina_Bool created_cb(void *data) { - (void)client_del_data(data, "create,timer"); + (void)client_del_data(data, "create,timer"); - invoke_global_created_cb(data); - invoke_activated_cb(data); - /*! - * \note - * Client PAUSE/RESUME event must has to be sent after created event. - */ - xmonitor_update_state(client_pid(data)); + invoke_global_created_cb(data); + invoke_activated_cb(data); + /*! + * \note + * Client PAUSE/RESUME event must has to be sent after created event. + */ + xmonitor_update_state(client_pid(data)); - (void)client_unref(data); - return ECORE_CALLBACK_CANCEL; + (void)client_unref(data); + return ECORE_CALLBACK_CANCEL; } /*! @@ -314,581 +314,581 @@ static Eina_Bool created_cb(void *data) */ HAPI struct client_node *client_create(pid_t pid, int handle, const char *direct_addr) { - struct client_node *client; - int ret; + struct client_node *client; + int ret; - client = client_find_by_rpc_handle(handle); - if (client) { - ErrPrint("Client %d(%d) is already exists\n", pid, handle); - return client; - } + client = client_find_by_rpc_handle(handle); + if (client) { + ErrPrint("Client %d(%d) is already exists\n", pid, handle); + return client; + } - client = create_client_data(pid, direct_addr); - if (!client) { - ErrPrint("Failed to create a new client (%d)\n", pid); - return NULL; + client = create_client_data(pid, direct_addr); + if (!client) { + ErrPrint("Failed to create a new client (%d)\n", pid); + return NULL; + } + + ret = client_rpc_init(client, handle); + if (ret < 0) { + client = client_unref(client); + ErrPrint("Failed to initialize the RPC for %d, Destroy client data %p(has to be 0x0)\n", pid, client); + } else { + Ecore_Timer *create_timer; + /*! + * \note + * To save the time to send reply packet to the client. + */ + create_timer = ecore_timer_add(DELAY_TIME, created_cb, client_ref(client)); + if (create_timer == NULL) { + ErrPrint("Failed to add a timer for client created event\n"); + client = client_unref(client); /* Decrease refcnt for argument */ + client = client_unref(client); /* Destroy client object */ + return NULL; } - ret = client_rpc_init(client, handle); - if (ret < 0) { - client = client_unref(client); - ErrPrint("Failed to initialize the RPC for %d, Destroy client data %p(has to be 0x0)\n", pid, client); - } else { - Ecore_Timer *create_timer; - /*! - * \note - * To save the time to send reply packet to the client. - */ - create_timer = ecore_timer_add(DELAY_TIME, created_cb, client_ref(client)); - if (create_timer == NULL) { - ErrPrint("Failed to add a timer for client created event\n"); - client = client_unref(client); /* Decrease refcnt for argument */ - client = client_unref(client); /* Destroy client object */ - return NULL; - } - - ret = client_set_data(client, "create,timer", create_timer); - DbgPrint("Set data: %d\n", ret); - } + ret = client_set_data(client, "create,timer", create_timer); + DbgPrint("Set data: %d\n", ret); + } - return client; + return client; } HAPI struct client_node *client_ref(struct client_node *client) { - if (!client) { - return NULL; - } + if (!client) { + return NULL; + } - client->refcnt++; - return client; + client->refcnt++; + return client; } HAPI struct client_node *client_unref(struct client_node *client) { - if (!client) { - return NULL; - } + if (!client) { + return NULL; + } - if (client->refcnt == 0) { - ErrPrint("Client refcnt is not managed correctly\n"); - return NULL; - } + if (client->refcnt == 0) { + ErrPrint("Client refcnt is not managed correctly\n"); + return NULL; + } - client->refcnt--; - if (client->refcnt == 0) { - destroy_client_data(client); - client = NULL; - } + client->refcnt--; + if (client->refcnt == 0) { + destroy_client_data(client); + client = NULL; + } - return client; + return client; } HAPI const int const client_refcnt(const struct client_node *client) { - return client->refcnt; + return client->refcnt; } HAPI const pid_t const client_pid(const struct client_node *client) { - return client ? client->pid : (pid_t)-1; + return client ? client->pid : (pid_t)-1; } HAPI struct client_node *client_find_by_pid(pid_t pid) { - Eina_List *l; - struct client_node *client; + Eina_List *l; + struct client_node *client; - EINA_LIST_FOREACH(s_info.client_list, l, client) { - if (client->pid == pid) { - return client; - } + EINA_LIST_FOREACH(s_info.client_list, l, client) { + if (client->pid == pid) { + return client; } + } - return NULL; + return NULL; } HAPI struct client_node *client_find_by_rpc_handle(int handle) { - Eina_List *l; - struct client_node *client; + Eina_List *l; + struct client_node *client; - if (handle <= 0) { - ErrPrint("Invalid handle %d\n", handle); - return NULL; - } + if (handle <= 0) { + ErrPrint("Invalid handle %d\n", handle); + return NULL; + } - EINA_LIST_FOREACH(s_info.client_list, l, client) { - if (client_rpc_handle(client) == handle) { - return client; - } + EINA_LIST_FOREACH(s_info.client_list, l, client) { + if (client_rpc_handle(client) == handle) { + return client; } + } - return NULL; + return NULL; } HAPI const int const client_count_paused(void) { - return s_info.nr_of_paused_clients; + return s_info.nr_of_paused_clients; } HAPI int client_is_all_paused(void) { - DbgPrint("%d, %d\n", eina_list_count(s_info.client_list), s_info.nr_of_paused_clients); - return eina_list_count(s_info.client_list) == s_info.nr_of_paused_clients; + DbgPrint("%d, %d\n", eina_list_count(s_info.client_list), s_info.nr_of_paused_clients); + return eina_list_count(s_info.client_list) == s_info.nr_of_paused_clients; } HAPI int client_count(void) { - return eina_list_count(s_info.client_list); + return eina_list_count(s_info.client_list); } HAPI struct client_node *client_deactivated_by_fault(struct client_node *client) { - if (!client || client->faulted) { - return client; - } + if (!client || client->faulted) { + return client; + } - ErrPrint("Client[%p] is faulted(%d), pid(%d)\n", client, client->refcnt, client->pid); - client->faulted = 1; - client->pid = (pid_t)-1; + ErrPrint("Client[%p] is faulted(%d), pid(%d)\n", client, client->refcnt, client->pid); + client->faulted = 1; + client->pid = (pid_t)-1; - invoke_deactivated_cb(client); - client = client_destroy(client); - /*! - * \todo - * Who invokes this function has to care the reference counter of a client - * do I need to invoke the deactivated callback from here? - * client->pid = (pid_t)-1; - * slave_unref(client) - */ - return client; + invoke_deactivated_cb(client); + client = client_destroy(client); + /*! + * \todo + * Who invokes this function has to care the reference counter of a client + * do I need to invoke the deactivated callback from here? + * client->pid = (pid_t)-1; + * slave_unref(client) + */ + return client; } HAPI const int const client_is_faulted(const struct client_node *client) { - /*! - * \note - * If the "client" is NIL, I assume that it is fault so returns TRUE(1) - */ - return client ? client->faulted : 1; + /*! + * \note + * If the "client" is NIL, I assume that it is fault so returns TRUE(1) + */ + return client ? client->faulted : 1; } HAPI void client_reset_fault(struct client_node *client) { - if (client) { - client->faulted = 0; - } + if (client) { + client->faulted = 0; + } } HAPI int client_event_callback_add(struct client_node *client, enum client_event event, int (*cb)(struct client_node *, void *), void *data) { - struct event_item *item; - - if (!cb) { - ErrPrint("Invalid callback (cb == NULL)\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - item->cb = cb; - item->data = data; - item->deleted = 0; - - /*! - * \note - * Use the eina_list_prepend API. - * To keep the sequence of a callback invocation. - * - * Here is an example sequence. - * - * client_event_callback_add(CALLBACK_01); - * client_event_callback_add(CALLBACK_02); - * client_event_callback_add(CALLBACK_03); - * - * Then the invoke_event_callback function will call the CALLBACKS as below sequence - * - * invoke_CALLBACK_03 - * invoke_CALLBACK_02 - * invoke_CALLBACK_01 - */ - - switch (event) { + struct event_item *item; + + if (!cb) { + ErrPrint("Invalid callback (cb == NULL)\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + item->cb = cb; + item->data = data; + item->deleted = 0; + + /*! + * \note + * Use the eina_list_prepend API. + * To keep the sequence of a callback invocation. + * + * Here is an example sequence. + * + * client_event_callback_add(CALLBACK_01); + * client_event_callback_add(CALLBACK_02); + * client_event_callback_add(CALLBACK_03); + * + * Then the invoke_event_callback function will call the CALLBACKS as below sequence + * + * invoke_CALLBACK_03 + * invoke_CALLBACK_02 + * invoke_CALLBACK_01 + */ + + switch (event) { case CLIENT_EVENT_DEACTIVATE: - client->event_deactivate_list = eina_list_prepend(client->event_deactivate_list, item); - break; + client->event_deactivate_list = eina_list_prepend(client->event_deactivate_list, item); + break; case CLIENT_EVENT_ACTIVATE: - client->event_activate_list = eina_list_prepend(client->event_activate_list, item); - break; + client->event_activate_list = eina_list_prepend(client->event_activate_list, item); + break; default: - DbgFree(item); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + DbgFree(item); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int client_event_callback_del(struct client_node *client, enum client_event event, int (*cb)(struct client_node *, void *), void *data) { - struct event_item *item; - Eina_List *l; - Eina_List *n; + struct event_item *item; + Eina_List *l; + Eina_List *n; - if (!cb) { - ErrPrint("Invalid callback (cb == NULL)\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!cb) { + ErrPrint("Invalid callback (cb == NULL)\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (event) { + switch (event) { case CLIENT_EVENT_DEACTIVATE: - EINA_LIST_FOREACH_SAFE(client->event_deactivate_list, l, n, item) { - if (item->cb == cb && item->data == data) { - if (client->in_event_process & CLIENT_EVENT_PROCESS_DEACTIVATE) { - item->deleted = 1; - } else { - client->event_deactivate_list = eina_list_remove(client->event_deactivate_list, item); - DbgFree(item); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(client->event_deactivate_list, l, n, item) { + if (item->cb == cb && item->data == data) { + if (client->in_event_process & CLIENT_EVENT_PROCESS_DEACTIVATE) { + item->deleted = 1; + } else { + client->event_deactivate_list = eina_list_remove(client->event_deactivate_list, item); + DbgFree(item); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case CLIENT_EVENT_ACTIVATE: - EINA_LIST_FOREACH_SAFE(client->event_activate_list, l, n, item) { - if (item->cb == cb && item->data == data) { - if (client->in_event_process & CLIENT_EVENT_PROCESS_ACTIVATE) { - item->deleted = 1; - } else { - client->event_activate_list = eina_list_remove(client->event_activate_list, item); - DbgFree(item); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(client->event_activate_list, l, n, item) { + if (item->cb == cb && item->data == data) { + if (client->in_event_process & CLIENT_EVENT_PROCESS_ACTIVATE) { + item->deleted = 1; + } else { + client->event_activate_list = eina_list_remove(client->event_activate_list, item); + DbgFree(item); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; default: - ErrPrint("Invalid event\n"); - break; - } + ErrPrint("Invalid event\n"); + break; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int client_set_data(struct client_node *client, const char *tag, void *data) { - struct data_item *item; + struct data_item *item; - item = calloc(1, sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = calloc(1, sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->tag = strdup(tag); - if (!item->tag) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item->tag = strdup(tag); + if (!item->tag) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->data = data; + item->data = data; - client->data_list = eina_list_append(client->data_list, item); - return DBOX_STATUS_ERROR_NONE; + client->data_list = eina_list_append(client->data_list, item); + return DBOX_STATUS_ERROR_NONE; } HAPI void *client_data(struct client_node *client, const char *tag) { - Eina_List *l; - struct data_item *item; + Eina_List *l; + struct data_item *item; - EINA_LIST_FOREACH(client->data_list, l, item) { - if (!strcmp(item->tag, tag)) { - return item->data; - } + EINA_LIST_FOREACH(client->data_list, l, item) { + if (!strcmp(item->tag, tag)) { + return item->data; } + } - return NULL; + return NULL; } HAPI void *client_del_data(struct client_node *client, const char *tag) { - Eina_List *l; - Eina_List *n; - struct data_item *item; + Eina_List *l; + Eina_List *n; + struct data_item *item; - EINA_LIST_FOREACH_SAFE(client->data_list, l, n, item) { - if (!strcmp(item->tag, tag)) { - void *data; - client->data_list = eina_list_remove(client->data_list, item); - data = item->data; - DbgFree(item->tag); - DbgFree(item); - return data; - } + EINA_LIST_FOREACH_SAFE(client->data_list, l, n, item) { + if (!strcmp(item->tag, tag)) { + void *data; + client->data_list = eina_list_remove(client->data_list, item); + data = item->data; + DbgFree(item->tag); + DbgFree(item); + return data; } + } - return NULL; + return NULL; } HAPI void client_paused(struct client_node *client) { - if (client->paused) { - return; - } + if (client->paused) { + return; + } - client->paused = 1; - s_info.nr_of_paused_clients++; + client->paused = 1; + s_info.nr_of_paused_clients++; } HAPI void client_resumed(struct client_node *client) { - if (client->paused == 0) { - return; - } + if (client->paused == 0) { + return; + } - client->paused = 0; - s_info.nr_of_paused_clients--; + client->paused = 0; + s_info.nr_of_paused_clients--; } HAPI int client_init(void) { - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI void client_fini(void) { - struct global_event_item *handler; - struct client_node *client; - Eina_List *l; - Eina_List *n; + struct global_event_item *handler; + struct client_node *client; + Eina_List *l; + Eina_List *n; - EINA_LIST_FOREACH_SAFE(s_info.client_list, l, n, client) { - (void)client_destroy(client); - } + EINA_LIST_FOREACH_SAFE(s_info.client_list, l, n, client) { + (void)client_destroy(client); + } - EINA_LIST_FREE(s_info.create_event_list, handler) { - DbgFree(handler); - } + EINA_LIST_FREE(s_info.create_event_list, handler) { + DbgFree(handler); + } - EINA_LIST_FREE(s_info.destroy_event_list, handler) { - DbgFree(handler); - } + EINA_LIST_FREE(s_info.destroy_event_list, handler) { + DbgFree(handler); + } } HAPI int client_global_event_handler_add(enum client_global_event event_type, int (*cb)(struct client_node *client, void *data), void *data) { - struct global_event_item *handler; + struct global_event_item *handler; - handler = malloc(sizeof(*handler)); - if (!handler) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + handler = malloc(sizeof(*handler)); + if (!handler) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - handler->cbdata = data; - handler->cb = cb; - handler->deleted = 0; + handler->cbdata = data; + handler->cb = cb; + handler->deleted = 0; - switch (event_type) { + switch (event_type) { case CLIENT_GLOBAL_EVENT_CREATE: - s_info.create_event_list = eina_list_prepend(s_info.create_event_list, handler); - break; + s_info.create_event_list = eina_list_prepend(s_info.create_event_list, handler); + break; case CLIENT_GLOBAL_EVENT_DESTROY: - s_info.destroy_event_list = eina_list_prepend(s_info.destroy_event_list, handler); - break; + s_info.destroy_event_list = eina_list_prepend(s_info.destroy_event_list, handler); + break; default: - DbgFree(handler); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + DbgFree(handler); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int client_global_event_handler_del(enum client_global_event event_type, int (*cb)(struct client_node *, void *), void *data) { - Eina_List *l; - Eina_List *n; - struct global_event_item *item; + Eina_List *l; + Eina_List *n; + struct global_event_item *item; - switch (event_type) { + switch (event_type) { case CLIENT_GLOBAL_EVENT_CREATE: - EINA_LIST_FOREACH_SAFE(s_info.create_event_list, l, n, item) { - if (item->cb == cb && item->cbdata == data) { - if (s_info.in_event_process & GLOBAL_EVENT_PROCESS_CREATE) { - item->deleted = 1; - } else { - s_info.create_event_list = eina_list_remove(s_info.create_event_list, item); - DbgFree(item); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.create_event_list, l, n, item) { + if (item->cb == cb && item->cbdata == data) { + if (s_info.in_event_process & GLOBAL_EVENT_PROCESS_CREATE) { + item->deleted = 1; + } else { + s_info.create_event_list = eina_list_remove(s_info.create_event_list, item); + DbgFree(item); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case CLIENT_GLOBAL_EVENT_DESTROY: - EINA_LIST_FOREACH_SAFE(s_info.destroy_event_list, l, n, item) { - if (item->cb == cb && item->cbdata == data) { - if (s_info.in_event_process & GLOBAL_EVENT_PROCESS_DESTROY) { - item->deleted = 1; - } else { - s_info.destroy_event_list = eina_list_remove(s_info.destroy_event_list, item); - DbgFree(item); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.destroy_event_list, l, n, item) { + if (item->cb == cb && item->cbdata == data) { + if (s_info.in_event_process & GLOBAL_EVENT_PROCESS_DESTROY) { + item->deleted = 1; + } else { + s_info.destroy_event_list = eina_list_remove(s_info.destroy_event_list, item); + DbgFree(item); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; default: - break; - } + break; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int client_subscribe(struct client_node *client, const char *cluster, const char *category) { - struct subscribe_item *item; + struct subscribe_item *item; - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->cluster = strdup(cluster); - if (!item->cluster) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item->cluster = strdup(cluster); + if (!item->cluster) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->category = strdup(category); - if (!item->category) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item->cluster); - DbgFree(item); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item->category = strdup(category); + if (!item->category) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item->cluster); + DbgFree(item); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - client->subscribe_list = eina_list_append(client->subscribe_list, item); - return DBOX_STATUS_ERROR_NONE; + client->subscribe_list = eina_list_append(client->subscribe_list, item); + return DBOX_STATUS_ERROR_NONE; } HAPI int client_unsubscribe(struct client_node *client, const char *cluster, const char *category) { - struct subscribe_item *item; - Eina_List *l; - Eina_List *n; + struct subscribe_item *item; + Eina_List *l; + Eina_List *n; - EINA_LIST_FOREACH_SAFE(client->subscribe_list, l, n, item) { - if (!strcasecmp(cluster, item->cluster) && !strcasecmp(category, item->category)) { - client->subscribe_list = eina_list_remove(client->subscribe_list, item); - DbgFree(item->cluster); - DbgFree(item->category); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(client->subscribe_list, l, n, item) { + if (!strcasecmp(cluster, item->cluster) && !strcasecmp(category, item->category)) { + client->subscribe_list = eina_list_remove(client->subscribe_list, item); + DbgFree(item->cluster); + DbgFree(item->category); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int client_is_subscribed(struct client_node *client, const char *cluster, const char *category) { - struct subscribe_item *item; - Eina_List *l; + struct subscribe_item *item; + Eina_List *l; - EINA_LIST_FOREACH(client->subscribe_list, l, item) { - if (!strcmp(item->cluster, "*")) { - return 1; - } + EINA_LIST_FOREACH(client->subscribe_list, l, item) { + if (!strcmp(item->cluster, "*")) { + return 1; + } - if (strcasecmp(item->cluster, cluster)) { - continue; - } + if (strcasecmp(item->cluster, cluster)) { + continue; + } - if (!strcmp(item->category, "*")) { - return 1; - } + if (!strcmp(item->category, "*")) { + return 1; + } - if (!strcasecmp(item->category, category)) { - return 1; - } + if (!strcasecmp(item->category, category)) { + return 1; } + } - return 0; + return 0; } HAPI int client_browse_list(const char *cluster, const char *category, int (*cb)(struct client_node *client, void *data), void *data) { - Eina_List *l; - struct client_node *client; - int cnt; + Eina_List *l; + struct client_node *client; + int cnt; - if (!cb || !cluster || !category) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!cb || !cluster || !category) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - cnt = 0; - EINA_LIST_FOREACH(s_info.client_list, l, client) { - if (!client_is_subscribed(client, cluster, category)) { - continue; - } - - if (cb(client, data) < 0) { - return DBOX_STATUS_ERROR_CANCEL; - } + cnt = 0; + EINA_LIST_FOREACH(s_info.client_list, l, client) { + if (!client_is_subscribed(client, cluster, category)) { + continue; + } - cnt++; + if (cb(client, data) < 0) { + return DBOX_STATUS_ERROR_CANCEL; } - return cnt; + cnt++; + } + + return cnt; } HAPI int client_nr_of_subscriber(const char *cluster, const char *category) { - Eina_List *l; - struct client_node *client; - int cnt; + Eina_List *l; + struct client_node *client; + int cnt; - cnt = 0; - EINA_LIST_FOREACH(s_info.client_list, l, client) { - cnt += !!client_is_subscribed(client, cluster, category); - } + cnt = 0; + EINA_LIST_FOREACH(s_info.client_list, l, client) { + cnt += !!client_is_subscribed(client, cluster, category); + } - return cnt; + return cnt; } HAPI int client_broadcast(struct inst_info *inst, struct packet *packet) { - Eina_List *l; - Eina_List *list; - struct client_node *client; - - list = inst ? instance_client_list(inst) : s_info.client_list; - EINA_LIST_FOREACH(list, l, client) { - if (client_pid(client) == -1) { - ErrPrint("Client[%p] has PID[%d]\n", client, client_pid(client)); - continue; - } + Eina_List *l; + Eina_List *list; + struct client_node *client; - (void)client_rpc_async_request(client, packet_ref(packet)); + list = inst ? instance_client_list(inst) : s_info.client_list; + EINA_LIST_FOREACH(list, l, client) { + if (client_pid(client) == -1) { + ErrPrint("Client[%p] has PID[%d]\n", client, client_pid(client)); + continue; } - packet_unref(packet); - return DBOX_STATUS_ERROR_NONE; + (void)client_rpc_async_request(client, packet_ref(packet)); + } + + packet_unref(packet); + return DBOX_STATUS_ERROR_NONE; } HAPI const char *client_direct_addr(const struct client_node *client) { - return client ? client->direct_addr : NULL; + return client ? client->direct_addr : NULL; } /* End of a file */ diff --git a/src/client_rpc.c b/src/client_rpc.c index fb9c99f..7dad2ac 100644 --- a/src/client_rpc.c +++ b/src/client_rpc.c @@ -41,20 +41,20 @@ * Static component information structure. */ static struct info { - Eina_List *command_list; /*!< Packet Q: Before sending the request, all request commands will stay here */ - Ecore_Timer *command_consumer; /*!< This timer will consuming the command Q. sending them to the specified client */ + Eina_List *command_list; /*!< Packet Q: Before sending the request, all request commands will stay here */ + Ecore_Timer *command_consumer; /*!< This timer will consuming the command Q. sending them to the specified client */ } s_info = { - .command_list = NULL, - .command_consumer = NULL, + .command_list = NULL, + .command_consumer = NULL, }; struct client_rpc { - int handle; /*!< Handler for communication with client */ + int handle; /*!< Handler for communication with client */ }; struct command { - struct packet *packet; - struct client_node *client; /*!< Target client. who should receive this command */ + struct packet *packet; + struct client_node *client; /*!< Target client. who should receive this command */ }; /*! @@ -63,223 +63,223 @@ struct command { */ static inline struct command *create_command(struct client_node *client, struct packet *packet) { - struct command *command; + struct command *command; - command = calloc(1, sizeof(*command)); - if (!command) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + command = calloc(1, sizeof(*command)); + if (!command) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - command->packet = packet_ref(packet); - command->client = client_ref(client); + command->packet = packet_ref(packet); + command->client = client_ref(client); - return command; + return command; } static inline void destroy_command(struct command *command) { - client_unref(command->client); - packet_unref(command->packet); - DbgFree(command); + client_unref(command->client); + packet_unref(command->packet); + DbgFree(command); } static inline int count_command(void) { - return eina_list_count(s_info.command_list); + return eina_list_count(s_info.command_list); } static inline struct command *pop_command(void) { - struct command *command; + struct command *command; - command = eina_list_nth(s_info.command_list, 0); - if (!command) { - return NULL; - } + command = eina_list_nth(s_info.command_list, 0); + if (!command) { + return NULL; + } - s_info.command_list = eina_list_remove(s_info.command_list, command); - return command; + s_info.command_list = eina_list_remove(s_info.command_list, command); + return command; } static Eina_Bool command_consumer_cb(void *data) { - struct command *command; - struct client_rpc *rpc; - int ret; - - command = pop_command(); - if (!command) { - s_info.command_consumer = NULL; - return ECORE_CALLBACK_CANCEL; - } - - if (!command->client) { - DbgPrint("Has no client\n"); - goto out; - } - - if (client_is_faulted(command->client)) { - ErrPrint("Client[%p] is faulted, discard command\n", command->client); - goto out; - } - - rpc = client_data(command->client, RPC_TAG); - if (!rpc) { - ErrPrint("Client is not activated\n"); - goto out; - } - - if (rpc->handle < 0) { - DbgPrint("RPC is not initialized\n"); - goto out; - } - - ret = com_core_packet_send_only(rpc->handle, command->packet); - if (ret < 0) { - ErrPrint("Failed to send packet %d\n", ret); - } + struct command *command; + struct client_rpc *rpc; + int ret; + + command = pop_command(); + if (!command) { + s_info.command_consumer = NULL; + return ECORE_CALLBACK_CANCEL; + } + + if (!command->client) { + DbgPrint("Has no client\n"); + goto out; + } + + if (client_is_faulted(command->client)) { + ErrPrint("Client[%p] is faulted, discard command\n", command->client); + goto out; + } + + rpc = client_data(command->client, RPC_TAG); + if (!rpc) { + ErrPrint("Client is not activated\n"); + goto out; + } + + if (rpc->handle < 0) { + DbgPrint("RPC is not initialized\n"); + goto out; + } + + ret = com_core_packet_send_only(rpc->handle, command->packet); + if (ret < 0) { + ErrPrint("Failed to send packet %d\n", ret); + } out: - destroy_command(command); - return ECORE_CALLBACK_RENEW; + destroy_command(command); + return ECORE_CALLBACK_RENEW; } static inline void push_command(struct command *command) { - s_info.command_list = eina_list_append(s_info.command_list, command); + s_info.command_list = eina_list_append(s_info.command_list, command); - if (s_info.command_consumer) { - return; - } + if (s_info.command_consumer) { + return; + } - s_info.command_consumer = ecore_timer_add(DYNAMICBOX_CONF_PACKET_TIME, command_consumer_cb, NULL); - if (!s_info.command_consumer) { - ErrPrint("Failed to add command consumer\n"); - s_info.command_list = eina_list_remove(s_info.command_list, command); - destroy_command(command); - } + s_info.command_consumer = ecore_timer_add(DYNAMICBOX_CONF_PACKET_TIME, command_consumer_cb, NULL); + if (!s_info.command_consumer) { + ErrPrint("Failed to add command consumer\n"); + s_info.command_list = eina_list_remove(s_info.command_list, command); + destroy_command(command); + } } HAPI int client_rpc_async_request(struct client_node *client, struct packet *packet) { - struct command *command; - struct client_rpc *rpc; - - if (!client || !packet) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + struct command *command; + struct client_rpc *rpc; - if (client_is_faulted(client)) { - ErrPrint("Client[%p] is faulted\n", client); - packet_unref(packet); - return DBOX_STATUS_ERROR_FAULT; - } + if (!client || !packet) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - rpc = client_data(client, RPC_TAG); - if (!rpc) { - ErrPrint("Client[%p] is not ready for communication (%s)\n", client, packet_command(packet)); - } + if (client_is_faulted(client)) { + ErrPrint("Client[%p] is faulted\n", client); + packet_unref(packet); + return DBOX_STATUS_ERROR_FAULT; + } - command = create_command(client, packet); - if (!command) { - packet_unref(packet); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + rpc = client_data(client, RPC_TAG); + if (!rpc) { + ErrPrint("Client[%p] is not ready for communication (%s)\n", client, packet_command(packet)); + } - push_command(command); + command = create_command(client, packet); + if (!command) { packet_unref(packet); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + push_command(command); + packet_unref(packet); + return DBOX_STATUS_ERROR_NONE; } static int deactivated_cb(struct client_node *client, void *data) { - struct client_rpc *rpc; - struct command *command; - Eina_List *l; - Eina_List *n; - - rpc = client_data(client, RPC_TAG); - if (!rpc) { - ErrPrint("client is not valid\n"); - return DBOX_STATUS_ERROR_NONE; - } + struct client_rpc *rpc; + struct command *command; + Eina_List *l; + Eina_List *n; + + rpc = client_data(client, RPC_TAG); + if (!rpc) { + ErrPrint("client is not valid\n"); + return DBOX_STATUS_ERROR_NONE; + } - DbgPrint("Reset handle for %d\n", client_pid(client)); - rpc->handle = -1; + DbgPrint("Reset handle for %d\n", client_pid(client)); + rpc->handle = -1; - DbgPrint("Begin: Destroying command\n"); - EINA_LIST_FOREACH_SAFE(s_info.command_list, l, n, command) { - if (command->client == client) { - s_info.command_list = eina_list_remove(s_info.command_list, command); - destroy_command(command); - } + DbgPrint("Begin: Destroying command\n"); + EINA_LIST_FOREACH_SAFE(s_info.command_list, l, n, command) { + if (command->client == client) { + s_info.command_list = eina_list_remove(s_info.command_list, command); + destroy_command(command); } - DbgPrint("End: Destroying command\n"); + } + DbgPrint("End: Destroying command\n"); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int client_rpc_init(struct client_node *client, int handle) { - struct client_rpc *rpc; - int ret; - - rpc = calloc(1, sizeof(*rpc)); - if (!rpc) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - ret = client_set_data(client, RPC_TAG, rpc); - if (ret < 0) { - ErrPrint("Failed to set \"rpc\" for client\n"); - DbgFree(rpc); - return ret; - } + struct client_rpc *rpc; + int ret; + + rpc = calloc(1, sizeof(*rpc)); + if (!rpc) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + ret = client_set_data(client, RPC_TAG, rpc); + if (ret < 0) { + ErrPrint("Failed to set \"rpc\" for client\n"); + DbgFree(rpc); + return ret; + } - DbgPrint("CLIENT: New handle assigned for %d, %d (old: %d)\n", client_pid(client), handle, rpc->handle); - rpc->handle = handle; + DbgPrint("CLIENT: New handle assigned for %d, %d (old: %d)\n", client_pid(client), handle, rpc->handle); + rpc->handle = handle; - ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, deactivated_cb, NULL); - if (ret < 0) { - struct client_rpc *weird; + ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, deactivated_cb, NULL); + if (ret < 0) { + struct client_rpc *weird; - weird = client_del_data(client, RPC_TAG); - if (weird != rpc) { - ErrPrint("What happens? (%p <> %p)\n", weird, rpc); - } - DbgFree(rpc); + weird = client_del_data(client, RPC_TAG); + if (weird != rpc) { + ErrPrint("What happens? (%p <> %p)\n", weird, rpc); } + DbgFree(rpc); + } - return ret; + return ret; } HAPI int client_rpc_fini(struct client_node *client) { - struct client_rpc *rpc; + struct client_rpc *rpc; - rpc = client_del_data(client, RPC_TAG); - if (!rpc) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + rpc = client_del_data(client, RPC_TAG); + if (!rpc) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, deactivated_cb, NULL); - DbgFree(rpc); - return DBOX_STATUS_ERROR_NONE; + client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, deactivated_cb, NULL); + DbgFree(rpc); + return DBOX_STATUS_ERROR_NONE; } HAPI int client_rpc_handle(struct client_node *client) { - struct client_rpc *rpc; + struct client_rpc *rpc; - rpc = client_data(client, RPC_TAG); - if (!rpc) { - DbgPrint("Client has no RPC\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + rpc = client_data(client, RPC_TAG); + if (!rpc) { + DbgPrint("Client has no RPC\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return rpc->handle; + return rpc->handle; } /* End of a file */ diff --git a/src/conf.c b/src/conf.c index 8f52983..be0730a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,8 +1,8 @@ #include "conf.h" struct conf g_conf = { - .debug_mode = 0, - .slave_max_load = -1, + .debug_mode = 0, + .slave_max_load = -1, }; /* End of a file */ diff --git a/src/critical_log.c b/src/critical_log.c index 2ff1e7d..ceb10a3 100644 --- a/src/critical_log.c +++ b/src/critical_log.c @@ -40,139 +40,139 @@ #include "critical_log.h" static struct { - FILE *fp; - int file_id; - int nr_of_lines; - char *filename; - pthread_mutex_t cri_lock; + FILE *fp; + int file_id; + int nr_of_lines; + char *filename; + pthread_mutex_t cri_lock; } s_info = { - .fp = NULL, - .file_id = 0, - .nr_of_lines = 0, - .filename = NULL, - .cri_lock = PTHREAD_MUTEX_INITIALIZER, + .fp = NULL, + .file_id = 0, + .nr_of_lines = 0, + .filename = NULL, + .cri_lock = PTHREAD_MUTEX_INITIALIZER, }; static inline void rotate_log(void) { - char *filename; - int namelen; + char *filename; + int namelen; - if (s_info.nr_of_lines < DYNAMICBOX_CONF_MAX_LOG_LINE) { - return; - } - - s_info.file_id = (s_info.file_id + 1) % DYNAMICBOX_CONF_MAX_LOG_FILE; + if (s_info.nr_of_lines < DYNAMICBOX_CONF_MAX_LOG_LINE) { + return; + } - namelen = strlen(s_info.filename) + strlen(DYNAMICBOX_CONF_LOG_PATH) + 30; - filename = malloc(namelen); - if (filename) { - snprintf(filename, namelen, "%s/%d_%s.%d", DYNAMICBOX_CONF_LOG_PATH, s_info.file_id, s_info.filename, getpid()); + s_info.file_id = (s_info.file_id + 1) % DYNAMICBOX_CONF_MAX_LOG_FILE; - if (s_info.fp) { - if (fclose(s_info.fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } - } + namelen = strlen(s_info.filename) + strlen(DYNAMICBOX_CONF_LOG_PATH) + 30; + filename = malloc(namelen); + if (filename) { + snprintf(filename, namelen, "%s/%d_%s.%d", DYNAMICBOX_CONF_LOG_PATH, s_info.file_id, s_info.filename, getpid()); - s_info.fp = fopen(filename, "w+"); - if (!s_info.fp) { - ErrPrint("Failed to open a file: %s\n", filename); - } + if (s_info.fp) { + if (fclose(s_info.fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); + } + } - DbgFree(filename); + s_info.fp = fopen(filename, "w+"); + if (!s_info.fp) { + ErrPrint("Failed to open a file: %s\n", filename); } - s_info.nr_of_lines = 0; + DbgFree(filename); + } + + s_info.nr_of_lines = 0; } HAPI int critical_log(const char *func, int line, const char *fmt, ...) { - va_list ap; - int ret; + va_list ap; + int ret; - if (!s_info.fp) { - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (!s_info.fp) { + return DBOX_STATUS_ERROR_IO_ERROR; + } - CRITICAL_SECTION_BEGIN(&s_info.cri_lock); + CRITICAL_SECTION_BEGIN(&s_info.cri_lock); - fprintf(s_info.fp, "%lf [%s:%d] ", util_timestamp(), util_basename((char *)func), line); + fprintf(s_info.fp, "%lf [%s:%d] ", util_timestamp(), util_basename((char *)func), line); - va_start(ap, fmt); - ret = vfprintf(s_info.fp, fmt, ap); - va_end(ap); + va_start(ap, fmt); + ret = vfprintf(s_info.fp, fmt, ap); + va_end(ap); - fflush(s_info.fp); + fflush(s_info.fp); - s_info.nr_of_lines++; - rotate_log(); + s_info.nr_of_lines++; + rotate_log(); - CRITICAL_SECTION_END(&s_info.cri_lock); - return ret; + CRITICAL_SECTION_END(&s_info.cri_lock); + return ret; } HAPI int critical_log_init(const char *name) { - int namelen; - char *filename; - - if (s_info.fp) { - return DBOX_STATUS_ERROR_NONE; - } - - s_info.filename = strdup(name); - if (!s_info.filename) { - ErrPrint("Failed to create a log file\n"); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + int namelen; + char *filename; - namelen = strlen(name) + strlen(DYNAMICBOX_CONF_LOG_PATH) + 30; - - filename = malloc(namelen); - if (!filename) { - ErrPrint("Failed to create a log file\n"); - DbgFree(s_info.filename); - s_info.filename = NULL; - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - snprintf(filename, namelen, "%s/%d_%s.%d", DYNAMICBOX_CONF_LOG_PATH, s_info.file_id, name, getpid()); - - s_info.fp = fopen(filename, "w+"); - if (!s_info.fp) { - ErrPrint("Failed to open log: %s\n", strerror(errno)); - DbgFree(s_info.filename); - s_info.filename = NULL; - DbgFree(filename); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - DbgFree(filename); + if (s_info.fp) { return DBOX_STATUS_ERROR_NONE; + } + + s_info.filename = strdup(name); + if (!s_info.filename) { + ErrPrint("Failed to create a log file\n"); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + namelen = strlen(name) + strlen(DYNAMICBOX_CONF_LOG_PATH) + 30; + + filename = malloc(namelen); + if (!filename) { + ErrPrint("Failed to create a log file\n"); + DbgFree(s_info.filename); + s_info.filename = NULL; + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + snprintf(filename, namelen, "%s/%d_%s.%d", DYNAMICBOX_CONF_LOG_PATH, s_info.file_id, name, getpid()); + + s_info.fp = fopen(filename, "w+"); + if (!s_info.fp) { + ErrPrint("Failed to open log: %s\n", strerror(errno)); + DbgFree(s_info.filename); + s_info.filename = NULL; + DbgFree(filename); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + DbgFree(filename); + return DBOX_STATUS_ERROR_NONE; } HAPI void critical_log_fini(void) { - if (s_info.filename) { - DbgFree(s_info.filename); - s_info.filename = NULL; - } - - if (s_info.fp) { - if (fclose(s_info.fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } - s_info.fp = NULL; + if (s_info.filename) { + DbgFree(s_info.filename); + s_info.filename = NULL; + } + + if (s_info.fp) { + if (fclose(s_info.fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); } + s_info.fp = NULL; + } } diff --git a/src/dead_monitor.c b/src/dead_monitor.c index bd2a0ee..c308b5b 100644 --- a/src/dead_monitor.c +++ b/src/dead_monitor.c @@ -36,64 +36,64 @@ static int evt_cb(int handle, void *data) { - struct slave_node *slave; - struct client_node *client; - struct liveinfo *liveinfo; - - slave = slave_find_by_rpc_handle(handle); - if (slave) { - if (slave_pid(slave) != (pid_t)-1) { - switch (slave_state(slave)) { - case SLAVE_REQUEST_TO_DISCONNECT: - DbgPrint("Disconnected from %d\n", slave_pid(slave)); - case SLAVE_REQUEST_TO_TERMINATE: - slave = slave_deactivated(slave); - break; - default: - slave = slave_deactivated_by_fault(slave); - break; - } - } - - if (!slave) { - DbgPrint("Slave is deleted\n"); - } - - return 0; + struct slave_node *slave; + struct client_node *client; + struct liveinfo *liveinfo; + + slave = slave_find_by_rpc_handle(handle); + if (slave) { + if (slave_pid(slave) != (pid_t)-1) { + switch (slave_state(slave)) { + case SLAVE_REQUEST_TO_DISCONNECT: + DbgPrint("Disconnected from %d\n", slave_pid(slave)); + case SLAVE_REQUEST_TO_TERMINATE: + slave = slave_deactivated(slave); + break; + default: + slave = slave_deactivated_by_fault(slave); + break; + } } - client = client_find_by_rpc_handle(handle); - if (client) { - if (client_pid(client) != (pid_t)-1) { - client = client_deactivated_by_fault(client); - } + if (!slave) { + DbgPrint("Slave is deleted\n"); + } - if (!client) { - DbgPrint("Client is deleted\n"); - } + return 0; + } - return 0; + client = client_find_by_rpc_handle(handle); + if (client) { + if (client_pid(client) != (pid_t)-1) { + client = client_deactivated_by_fault(client); } - liveinfo = liveinfo_find_by_handle(handle); - if (liveinfo) { - liveinfo_destroy(liveinfo); - return 0; + if (!client) { + DbgPrint("Client is deleted\n"); } return 0; + } + + liveinfo = liveinfo_find_by_handle(handle); + if (liveinfo) { + liveinfo_destroy(liveinfo); + return 0; + } + + return 0; } HAPI int dead_init(void) { - com_core_add_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL); - return 0; + com_core_add_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL); + return 0; } HAPI int dead_fini(void) { - com_core_del_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL); - return 0; + com_core_del_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL); + return 0; } /* End of a file */ diff --git a/src/event.c b/src/event.c index 937a515..436f4bf 100644 --- a/src/event.c +++ b/src/event.c @@ -50,56 +50,56 @@ int errno; static struct info { - pthread_t tid; - Eina_List *event_list; - int handle; - pthread_mutex_t event_list_lock; - int evt_pipe[PIPE_MAX]; - int tcb_pipe[PIPE_MAX]; - Ecore_Fd_Handler *event_handler; + pthread_t tid; + Eina_List *event_list; + int handle; + pthread_mutex_t event_list_lock; + int evt_pipe[PIPE_MAX]; + int tcb_pipe[PIPE_MAX]; + Ecore_Fd_Handler *event_handler; - struct event_data event_data; + struct event_data event_data; - Eina_List *event_listener_list; - Eina_List *reactivate_list; + Eina_List *event_listener_list; + Eina_List *reactivate_list; - int event_handler_activated; - int timestamp_updated; + int event_handler_activated; + int timestamp_updated; } s_info = { - .event_handler_activated = 0, - .event_list = NULL, - .handle = -1, - .event_handler = NULL, - .evt_pipe = { -1, -1 }, - .tcb_pipe = { -1, -1 }, - - .event_data = { - .x = -1, - .y = -1, - .device = -1, - .slot = -1, - .keycode = 0, - }, - - .event_listener_list = NULL, - .reactivate_list = NULL, - .timestamp_updated = 0, + .event_handler_activated = 0, + .event_list = NULL, + .handle = -1, + .event_handler = NULL, + .evt_pipe = { -1, -1 }, + .tcb_pipe = { -1, -1 }, + + .event_data = { + .x = -1, + .y = -1, + .device = -1, + .slot = -1, + .keycode = 0, + }, + + .event_listener_list = NULL, + .reactivate_list = NULL, + .timestamp_updated = 0, }; struct event_listener { - int (*event_cb)(enum event_state state, struct event_data *event, void *data); - void *cbdata; + int (*event_cb)(enum event_state state, struct event_data *event, void *data); + void *cbdata; - enum event_state prev_state; - enum event_state state; + enum event_state prev_state; + enum event_state state; #if defined(_USE_ECORE_TIME_GET) - double tv; + double tv; #else - struct timeval tv; /* Recording Activate / Deactivate time */ + struct timeval tv; /* Recording Activate / Deactivate time */ #endif - int x; /* RelX */ - int y; /* RelY */ + int x; /* RelX */ + int y; /* RelY */ }; static int activate_thread(void); @@ -108,29 +108,29 @@ static int event_control_fini(void); HAPI int event_init(void) { - int ret; + int ret; - ret = pthread_mutex_init(&s_info.event_list_lock, NULL); - if (ret != 0) { - ErrPrint("Mutex: %s\n", strerror(ret)); - return DBOX_STATUS_ERROR_FAULT; - } + ret = pthread_mutex_init(&s_info.event_list_lock, NULL); + if (ret != 0) { + ErrPrint("Mutex: %s\n", strerror(ret)); + return DBOX_STATUS_ERROR_FAULT; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int event_fini(void) { - int ret; + int ret; - event_control_fini(); + event_control_fini(); - ret = pthread_mutex_destroy(&s_info.event_list_lock); - if (ret != 0) { - ErrPrint("Mutex destroy failed: %s\n", strerror(ret)); - } + ret = pthread_mutex_destroy(&s_info.event_list_lock); + if (ret != 0) { + ErrPrint("Mutex destroy failed: %s\n", strerror(ret)); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /* @@ -138,294 +138,294 @@ HAPI int event_fini(void) */ static int push_event_item(void) { - struct event_data *item; + struct event_data *item; - if (s_info.event_data.x < 0 || s_info.event_data.y < 0) { - /* Waiting full event packet */ - return DBOX_STATUS_ERROR_NONE; - } - - item = malloc(sizeof(*item)); - if (item) { - char event_ch = EVENT_CH; + if (s_info.event_data.x < 0 || s_info.event_data.y < 0) { + /* Waiting full event packet */ + return DBOX_STATUS_ERROR_NONE; + } - memcpy(item, &s_info.event_data, sizeof(*item)); + item = malloc(sizeof(*item)); + if (item) { + char event_ch = EVENT_CH; - CRITICAL_SECTION_BEGIN(&s_info.event_list_lock); - s_info.event_list = eina_list_append(s_info.event_list, item); - CRITICAL_SECTION_END(&s_info.event_list_lock); + memcpy(item, &s_info.event_data, sizeof(*item)); - if (write(s_info.evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { - ErrPrint("Unable to send an event: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; - } + CRITICAL_SECTION_BEGIN(&s_info.event_list_lock); + s_info.event_list = eina_list_append(s_info.event_list, item); + CRITICAL_SECTION_END(&s_info.event_list_lock); - /* Take a breathe */ - pthread_yield(); - } else { - ErrPrint("Heap: %s\n", strerror(errno)); + if (write(s_info.evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { + ErrPrint("Unable to send an event: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; } - return DBOX_STATUS_ERROR_NONE; + /* Take a breathe */ + pthread_yield(); + } else { + ErrPrint("Heap: %s\n", strerror(errno)); + } + + return DBOX_STATUS_ERROR_NONE; } static double current_time_get(void) { - double ret; - - if (DYNAMICBOX_CONF_USE_GETTIMEOFDAY) { - struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) { - ErrPrint("gettimeofday: %s\n", strerror(errno)); - ret = ecore_time_get(); - } else { - ret = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f); - } + double ret; + + if (DYNAMICBOX_CONF_USE_GETTIMEOFDAY) { + struct timeval tv; + if (gettimeofday(&tv, NULL) < 0) { + ErrPrint("gettimeofday: %s\n", strerror(errno)); + ret = ecore_time_get(); } else { - ret = ecore_time_get(); + ret = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f); } + } else { + ret = ecore_time_get(); + } - return ret; + return ret; } static void update_timestamp(struct input_event *event) { #if !defined(_USE_ECORE_TIME_GET) - /*! - * WARN - * Input event uses MONOTONIC CLOCK TIME - * So this case will not be work correctly. - */ - if (DYNAMICBOX_CONF_USE_EVENT_TIME) { - memcpy(&s_info.event_data.tv, &event->time, sizeof(event->time)); - } else { - if (gettimeofday(&s_info.event_data.tv, NULL) < 0) { - ErrPrint("gettimeofday: %s\n", strerror(errno)); - } + /*! + * WARN + * Input event uses MONOTONIC CLOCK TIME + * So this case will not be work correctly. + */ + if (DYNAMICBOX_CONF_USE_EVENT_TIME) { + memcpy(&s_info.event_data.tv, &event->time, sizeof(event->time)); + } else { + if (gettimeofday(&s_info.event_data.tv, NULL) < 0) { + ErrPrint("gettimeofday: %s\n", strerror(errno)); } + } #else - /* - * Input event uses timeval instead of timespec, - * but its value is same as MONOTIC CLOCK TIME - * So we should handles it properly. - */ - if (DYNAMICBOX_CONF_USE_EVENT_TIME) { - s_info.event_data.tv = (double)event->time.tv_sec + (double)event->time.tv_usec / 1000000.0f; - } else { - s_info.event_data.tv = current_time_get(); - } + /* + * Input event uses timeval instead of timespec, + * but its value is same as MONOTIC CLOCK TIME + * So we should handles it properly. + */ + if (DYNAMICBOX_CONF_USE_EVENT_TIME) { + s_info.event_data.tv = (double)event->time.tv_sec + (double)event->time.tv_usec / 1000000.0f; + } else { + s_info.event_data.tv = current_time_get(); + } #endif - s_info.timestamp_updated = 1; + s_info.timestamp_updated = 1; } static void processing_ev_abs(struct input_event *event) { - switch (event->code) { + switch (event->code) { #if defined(ABS_X) case ABS_X: - break; + break; #endif #if defined(ABS_Y) case ABS_Y: - break; + break; #endif #if defined(ABS_Z) case ABS_Z: - break; + break; #endif #if defined(ABS_RX) case ABS_RX: - break; + break; #endif #if defined(ABS_RY) case ABS_RY: - break; + break; #endif #if defined(ABS_RZ) case ABS_RZ: - break; + break; #endif #if defined(ABS_THROTTLE) case ABS_THROTTLE: - break; + break; #endif #if defined(ABS_RUDDER) case ABS_RUDDER: - break; + break; #endif #if defined(ABS_WHEEL) case ABS_WHEEL: - break; + break; #endif #if defined(ABS_GAS) case ABS_GAS: - break; + break; #endif #if defined(ABS_BRAKE) case ABS_BRAKE: - break; + break; #endif #if defined(ABS_HAT0X) case ABS_HAT0X: - break; + break; #endif #if defined(ABS_HAT0Y) case ABS_HAT0Y: - break; + break; #endif #if defined(ABS_HAT1X) case ABS_HAT1X: - break; + break; #endif #if defined(ABS_HAT1Y) case ABS_HAT1Y: - break; + break; #endif #if defined(ABS_HAT2X) case ABS_HAT2X: - break; + break; #endif #if defined(ABS_HAT2Y) case ABS_HAT2Y: - break; + break; #endif #if defined(ABS_HAT3X) case ABS_HAT3X: - break; + break; #endif #if defined(ABS_HAT3Y) case ABS_HAT3Y: - break; + break; #endif #if defined(ABS_PRESSURE) case ABS_PRESSURE: - break; + break; #endif #if defined(ABS_TILT_X) case ABS_TILT_X: - break; + break; #endif #if defined(ABS_TILT_Y) case ABS_TILT_Y: - break; + break; #endif #if defined(ABS_TOOL_WIDTH) case ABS_TOOL_WIDTH: - break; + break; #endif #if defined(ABS_VOLUME) case ABS_VOLUME: - break; + break; #endif #if defined(ABS_MISC) case ABS_MISC: - break; + break; #endif #if defined(ABS_DISTANCE) case ABS_DISTANCE: - s_info.event_data.distance = event->value; - break; + s_info.event_data.distance = event->value; + break; #endif #if defined(ABS_MT_POSITION_X) case ABS_MT_POSITION_X: - s_info.event_data.x = event->value; - break; + s_info.event_data.x = event->value; + break; #endif #if defined(ABS_MT_POSITION_Y) case ABS_MT_POSITION_Y: - s_info.event_data.y = event->value; - break; + s_info.event_data.y = event->value; + break; #endif #if defined(ABS_MT_SLOT) case ABS_MT_SLOT: - s_info.event_data.slot = event->value; - break; + s_info.event_data.slot = event->value; + break; #endif #if defined(ABS_MT_TRACKING_ID) case ABS_MT_TRACKING_ID: - s_info.event_data.device = event->value; - break; + s_info.event_data.device = event->value; + break; #endif #if defined(ABS_MT_TOUCH_MAJOR) case ABS_MT_TOUCH_MAJOR: - s_info.event_data.touch.major = event->value; - break; + s_info.event_data.touch.major = event->value; + break; #endif #if defined(ABS_MT_TOUCH_MINOR) case ABS_MT_TOUCH_MINOR: - s_info.event_data.touch.minor = event->value; - break; + s_info.event_data.touch.minor = event->value; + break; #endif #if defined(ABS_MT_WIDTH_MAJOR) case ABS_MT_WIDTH_MAJOR: - s_info.event_data.width.major = event->value; - break; + s_info.event_data.width.major = event->value; + break; #endif #if defined(ABS_MT_WIDTH_MINOR) case ABS_MT_WIDTH_MINOR: - s_info.event_data.width.minor = event->value; - break; + s_info.event_data.width.minor = event->value; + break; #endif #if defined(ABS_MT_ORIENTATION) case ABS_MT_ORIENTATION: - s_info.event_data.orientation = event->value; - break; + s_info.event_data.orientation = event->value; + break; #endif #if defined(ABS_MT_PRESSURE) case ABS_MT_PRESSURE: - s_info.event_data.pressure = event->value; - break; + s_info.event_data.pressure = event->value; + break; #endif #if defined(ABS_MT_TOOL_X) case ABS_MT_TOOL_X: - DbgPrint("TOOL_X: %d\n", event->value); - break; + DbgPrint("TOOL_X: %d\n", event->value); + break; #endif #if defined(ABS_MT_TOOL_Y) case ABS_MT_TOOL_Y: - DbgPrint("TOOL_Y: %d\n", event->value); - break; + DbgPrint("TOOL_Y: %d\n", event->value); + break; #endif #if defined(ABS_MT_TOOL_TYPE) case ABS_MT_TOOL_TYPE: - DbgPrint("TOOL_TYPE: %d\n", event->value); - break; + DbgPrint("TOOL_TYPE: %d\n", event->value); + break; #endif #if defined(ABS_MT_BLOB_ID) case ABS_MT_BLOB_ID: - DbgPrint("BLOB_ID: %d\n", event->value); - break; + DbgPrint("BLOB_ID: %d\n", event->value); + break; #endif #if defined(ABS_MT_DISTANCE) case ABS_MT_DISTANCE: - DbgPrint("DISTANCE: %d\n", event->value); - break; + DbgPrint("DISTANCE: %d\n", event->value); + break; #endif #if defined(ABS_MT_ANGLE) case ABS_MT_ANGLE: - DbgPrint("ANGLE: %d\n", event->value); - break; + DbgPrint("ANGLE: %d\n", event->value); + break; #endif #if defined(ABS_MT_PALM) case ABS_MT_PALM: - DbgPrint("PALM: %d\n", event->value); - break; + DbgPrint("PALM: %d\n", event->value); + break; #endif #if defined(ABS_MT_COMPONENT) case ABS_MT_COMPONENT: - DbgPrint("COMPONENT: %d\n", event->value); - break; + DbgPrint("COMPONENT: %d\n", event->value); + break; #endif #if defined(ABS_MT_SUMSIZE) case ABS_MT_SUMSIZE: - DbgPrint("SUMSIZE: %d\n", event->value); - break; + DbgPrint("SUMSIZE: %d\n", event->value); + break; #endif default: - break; - } + break; + } - return; + return; } /* @@ -433,47 +433,47 @@ static void processing_ev_abs(struct input_event *event) */ static inline int processing_input_event(struct input_event *event) { - int ret; + int ret; - if (s_info.timestamp_updated == 0) { - update_timestamp(event); - } + if (s_info.timestamp_updated == 0) { + update_timestamp(event); + } - switch (event->type) { + switch (event->type) { case EV_SYN: - switch (event->code) { - break; + switch (event->code) { + break; case SYN_CONFIG: - break; + break; case SYN_MT_REPORT: case SYN_REPORT: - s_info.timestamp_updated = 0; - ret = push_event_item(); - if (ret < 0) { - return ret; - } + s_info.timestamp_updated = 0; + ret = push_event_item(); + if (ret < 0) { + return ret; + } - break; + break; #if defined(SYN_DROPPED) case SYN_DROPPED: - DbgPrint("EV_SYN, SYN_DROPPED\n"); - break; + DbgPrint("EV_SYN, SYN_DROPPED\n"); + break; #endif default: - DbgPrint("EV_SYN, 0x%x\n", event->code); - break; - } + DbgPrint("EV_SYN, 0x%x\n", event->code); break; + } + break; case EV_KEY: - DbgPrint("EV_KEY: 0x%X\n", event->value); - s_info.event_data.keycode = event->value; - break; + DbgPrint("EV_KEY: 0x%X\n", event->value); + s_info.event_data.keycode = event->value; + break; case EV_REL: - DbgPrint("EV_REL: 0x%X\n", event->value); - break; + DbgPrint("EV_REL: 0x%X\n", event->value); + break; case EV_ABS: - processing_ev_abs(event); - break; + processing_ev_abs(event); + break; case EV_MSC: case EV_SW: case EV_LED: @@ -483,353 +483,353 @@ static inline int processing_input_event(struct input_event *event) case EV_PWR: case EV_FF_STATUS: default: - DbgPrint("0x%X, 0x%X\n", event->type, event->code); - break; - } + DbgPrint("0x%X, 0x%X\n", event->type, event->code); + break; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static void *event_thread_main(void *data) { - fd_set set; - long ret = 0; - struct input_event input_event; - char *ptr = (char *)&input_event; - int offset = 0; - int readsize = 0; - int fd; - char event_ch; - - while (1) { - FD_ZERO(&set); - FD_SET(s_info.handle, &set); - FD_SET(s_info.tcb_pipe[PIPE_READ], &set); - - fd = s_info.handle > s_info.tcb_pipe[PIPE_READ] ? s_info.handle : s_info.tcb_pipe[PIPE_READ]; - ret = select(fd + 1, &set, NULL, NULL, NULL); - if (ret < 0) { - ret = -errno; - if (errno == EINTR) { - DbgPrint("Select receives INTR\n"); - continue; - } - ErrPrint("Error: %s\n", strerror(errno)); - break; - } else if (ret == 0) { - ErrPrint("Timeout expired\n"); - ret = DBOX_STATUS_ERROR_TIMEOUT; - break; - } + fd_set set; + long ret = 0; + struct input_event input_event; + char *ptr = (char *)&input_event; + int offset = 0; + int readsize = 0; + int fd; + char event_ch; + + while (1) { + FD_ZERO(&set); + FD_SET(s_info.handle, &set); + FD_SET(s_info.tcb_pipe[PIPE_READ], &set); + + fd = s_info.handle > s_info.tcb_pipe[PIPE_READ] ? s_info.handle : s_info.tcb_pipe[PIPE_READ]; + ret = select(fd + 1, &set, NULL, NULL, NULL); + if (ret < 0) { + ret = -errno; + if (errno == EINTR) { + DbgPrint("Select receives INTR\n"); + continue; + } + ErrPrint("Error: %s\n", strerror(errno)); + break; + } else if (ret == 0) { + ErrPrint("Timeout expired\n"); + ret = DBOX_STATUS_ERROR_TIMEOUT; + break; + } - if (FD_ISSET(s_info.handle, &set)) { - readsize = read(s_info.handle, ptr + offset, sizeof(input_event) - offset); - if (readsize < 0) { - ErrPrint("Unable to read device: %s / fd: %d / offset: %d / size: %d - %d\n", strerror(errno), s_info.handle, offset, sizeof(input_event), readsize); - ret = DBOX_STATUS_ERROR_FAULT; - break; - } - - offset += readsize; - if (offset == sizeof(input_event)) { - offset = 0; - if (processing_input_event(&input_event) < 0) { - ret = DBOX_STATUS_ERROR_FAULT; - break; - } - } - - /* - * If there is input event, - * Try again to get the input event. - */ - } else if (FD_ISSET(s_info.tcb_pipe[PIPE_READ], &set)) { - if (read(s_info.tcb_pipe[PIPE_READ], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { - ErrPrint("Unable to read TCB_PIPE: %s\n", strerror(errno)); - } - - ret = DBOX_STATUS_ERROR_CANCEL; - break; + if (FD_ISSET(s_info.handle, &set)) { + readsize = read(s_info.handle, ptr + offset, sizeof(input_event) - offset); + if (readsize < 0) { + ErrPrint("Unable to read device: %s / fd: %d / offset: %d / size: %d - %d\n", strerror(errno), s_info.handle, offset, sizeof(input_event), readsize); + ret = DBOX_STATUS_ERROR_FAULT; + break; + } + + offset += readsize; + if (offset == sizeof(input_event)) { + offset = 0; + if (processing_input_event(&input_event) < 0) { + ret = DBOX_STATUS_ERROR_FAULT; + break; } + } + + /* + * If there is input event, + * Try again to get the input event. + */ + } else if (FD_ISSET(s_info.tcb_pipe[PIPE_READ], &set)) { + if (read(s_info.tcb_pipe[PIPE_READ], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { + ErrPrint("Unable to read TCB_PIPE: %s\n", strerror(errno)); + } + + ret = DBOX_STATUS_ERROR_CANCEL; + break; } + } - event_ch = EVENT_EXIT; - if (write(s_info.evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { - ErrPrint("Unable to send an event: %s\n", strerror(errno)); - } + event_ch = EVENT_EXIT; + if (write(s_info.evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { + ErrPrint("Unable to send an event: %s\n", strerror(errno)); + } - return (void *)ret; + return (void *)ret; } static int invoke_event_cb(struct event_listener *listener, struct event_data *item) { - struct event_data modified_item; + struct event_data modified_item; - memcpy(&modified_item, item, sizeof(modified_item)); + memcpy(&modified_item, item, sizeof(modified_item)); - modified_item.x -= listener->x; - modified_item.y -= listener->y; + modified_item.x -= listener->x; + modified_item.y -= listener->y; - if (listener->event_cb(listener->state, &modified_item, listener->cbdata) < 0) { - if (eina_list_data_find(s_info.event_listener_list, listener)) { - s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); - DbgFree(listener); - return 1; - } + if (listener->event_cb(listener->state, &modified_item, listener->cbdata) < 0) { + if (eina_list_data_find(s_info.event_listener_list, listener)) { + s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); + DbgFree(listener); + return 1; } + } - return 0; + return 0; } static inline void clear_all_listener_list(void) { - struct event_listener *listener; - enum event_state next_state; - struct event_data event_data; - struct event_data *p_event_data; - Eina_List *l; - Eina_List *n; - - DbgPrint("event listeners: %d\n", eina_list_count(s_info.event_listener_list)); - while (s_info.event_listener_list) { - EINA_LIST_FOREACH_SAFE(s_info.event_listener_list, l, n, listener) { - - DbgPrint("listener[%p] prev[%x] state[%x]\n", listener, listener->prev_state, listener->state); - - switch (listener->state) { - case EVENT_STATE_ACTIVATE: - p_event_data = &s_info.event_data; - next_state = EVENT_STATE_ACTIVATED; - break; - case EVENT_STATE_ACTIVATED: - p_event_data = &s_info.event_data; - next_state = EVENT_STATE_DEACTIVATE; - break; - case EVENT_STATE_DEACTIVATE: - memcpy(&event_data, &s_info.event_data, sizeof(event_data)); - p_event_data = &event_data; - - if (listener->prev_state == EVENT_STATE_ACTIVATE) { - /* There is no move event. we have to emulate it */ - DbgPrint ("Let's emulate move event (%dx%d)\n", p_event_data->x, p_event_data->y); - listener->state = EVENT_STATE_ACTIVATED; - next_state = EVENT_STATE_DEACTIVATE; - } else { - next_state = EVENT_STATE_DEACTIVATED; - } - break; - case EVENT_STATE_DEACTIVATED: - default: - s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); - DbgFree(listener); - continue; - } - - if (invoke_event_cb(listener, p_event_data)) { - continue; - } - - /*! - * Changing state of listener will affect to the event collecting thread. - */ - listener->prev_state = listener->state; - listener->state = next_state; - } + struct event_listener *listener; + enum event_state next_state; + struct event_data event_data; + struct event_data *p_event_data; + Eina_List *l; + Eina_List *n; + + DbgPrint("event listeners: %d\n", eina_list_count(s_info.event_listener_list)); + while (s_info.event_listener_list) { + EINA_LIST_FOREACH_SAFE(s_info.event_listener_list, l, n, listener) { + + DbgPrint("listener[%p] prev[%x] state[%x]\n", listener, listener->prev_state, listener->state); + + switch (listener->state) { + case EVENT_STATE_ACTIVATE: + p_event_data = &s_info.event_data; + next_state = EVENT_STATE_ACTIVATED; + break; + case EVENT_STATE_ACTIVATED: + p_event_data = &s_info.event_data; + next_state = EVENT_STATE_DEACTIVATE; + break; + case EVENT_STATE_DEACTIVATE: + memcpy(&event_data, &s_info.event_data, sizeof(event_data)); + p_event_data = &event_data; + + if (listener->prev_state == EVENT_STATE_ACTIVATE) { + /* There is no move event. we have to emulate it */ + DbgPrint ("Let's emulate move event (%dx%d)\n", p_event_data->x, p_event_data->y); + listener->state = EVENT_STATE_ACTIVATED; + next_state = EVENT_STATE_DEACTIVATE; + } else { + next_state = EVENT_STATE_DEACTIVATED; + } + break; + case EVENT_STATE_DEACTIVATED: + default: + s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); + DbgFree(listener); + continue; + } + + if (invoke_event_cb(listener, p_event_data)) { + continue; + } + + /*! + * Changing state of listener will affect to the event collecting thread. + */ + listener->prev_state = listener->state; + listener->state = next_state; } + } } #if defined(_USE_ECORE_TIME_GET) static int compare_timestamp(struct event_listener *listener, struct event_data *item) { - int ret; - if (listener->tv > item->tv) { - ret = 1; - } else if (listener->tv < item->tv) { - ret = -1; - } else { - ret = 0; - } - return ret; + int ret; + if (listener->tv > item->tv) { + ret = 1; + } else if (listener->tv < item->tv) { + ret = -1; + } else { + ret = 0; + } + return ret; } #else static int compare_timestamp(struct event_listener *listener, struct event_data *item) { - int ret; - if (timercmp(&listener->tv, &item->tv, >)) { - ret = 1; - } else if (timercmp(&listener->tv, &item->tv, <)) { - ret = -1; - } else { - ret = 0; - } - return ret; + int ret; + if (timercmp(&listener->tv, &item->tv, >)) { + ret = 1; + } else if (timercmp(&listener->tv, &item->tv, <)) { + ret = -1; + } else { + ret = 0; + } + return ret; } #endif static Eina_Bool event_read_cb(void *data, Ecore_Fd_Handler *handler) { - int fd; - struct event_data *item; - char event_ch; - struct event_listener *listener; - Eina_List *l; - Eina_List *n; - enum event_state next_state; - - fd = ecore_main_fd_handler_fd_get(handler); - if (fd < 0) { - ErrPrint("Invalid fd\n"); - return ECORE_CALLBACK_CANCEL; - } - - if (read(fd, &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { - ErrPrint("Unable to read event ch: %s\n", strerror(errno)); - return ECORE_CALLBACK_CANCEL; - } + int fd; + struct event_data *item; + char event_ch; + struct event_listener *listener; + Eina_List *l; + Eina_List *n; + enum event_state next_state; + + fd = ecore_main_fd_handler_fd_get(handler); + if (fd < 0) { + ErrPrint("Invalid fd\n"); + return ECORE_CALLBACK_CANCEL; + } + + if (read(fd, &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { + ErrPrint("Unable to read event ch: %s\n", strerror(errno)); + return ECORE_CALLBACK_CANCEL; + } + + if (event_ch == EVENT_EXIT) { + /*! + * If the master gets event exit from evt_pipe, + * The event item list should be empty. + */ + if (!s_info.event_list) { + /* This callback must has to clear all listeners in this case */ + ecore_main_fd_handler_del(s_info.event_handler); + s_info.event_handler = NULL; + clear_all_listener_list(); - if (event_ch == EVENT_EXIT) { - /*! - * If the master gets event exit from evt_pipe, - * The event item list should be empty. - */ - if (!s_info.event_list) { - /* This callback must has to clear all listeners in this case */ - ecore_main_fd_handler_del(s_info.event_handler); - s_info.event_handler = NULL; - clear_all_listener_list(); - - EINA_LIST_FREE(s_info.reactivate_list, listener) { - s_info.event_listener_list = eina_list_append(s_info.event_listener_list, listener); - } - DbgPrint("Reactivate: %p\n", s_info.event_listener_list); - - if (s_info.event_listener_list) { - if (activate_thread() < 0) { - EINA_LIST_FREE(s_info.event_listener_list, listener) { - (void)listener->event_cb(EVENT_STATE_ERROR, NULL, listener->cbdata); - } - } - } - - DbgPrint("Event read callback finshed (%p)\n", s_info.event_listener_list); - return ECORE_CALLBACK_CANCEL; - } else { - ErrPrint("Something goes wrong, the event_list is not flushed\n"); + EINA_LIST_FREE(s_info.reactivate_list, listener) { + s_info.event_listener_list = eina_list_append(s_info.event_listener_list, listener); + } + DbgPrint("Reactivate: %p\n", s_info.event_listener_list); + + if (s_info.event_listener_list) { + if (activate_thread() < 0) { + EINA_LIST_FREE(s_info.event_listener_list, listener) { + (void)listener->event_cb(EVENT_STATE_ERROR, NULL, listener->cbdata); + } } - } + } - CRITICAL_SECTION_BEGIN(&s_info.event_list_lock); - item = eina_list_nth(s_info.event_list, 0); - if (item) { - s_info.event_list = eina_list_remove(s_info.event_list, item); + DbgPrint("Event read callback finshed (%p)\n", s_info.event_listener_list); + return ECORE_CALLBACK_CANCEL; + } else { + ErrPrint("Something goes wrong, the event_list is not flushed\n"); } - CRITICAL_SECTION_END(&s_info.event_list_lock); + } - if (!item) { - ErrPrint("There is no remained event\n"); - return ECORE_CALLBACK_RENEW; - } + CRITICAL_SECTION_BEGIN(&s_info.event_list_lock); + item = eina_list_nth(s_info.event_list, 0); + if (item) { + s_info.event_list = eina_list_remove(s_info.event_list, item); + } + CRITICAL_SECTION_END(&s_info.event_list_lock); - EINA_LIST_FOREACH_SAFE(s_info.event_listener_list, l, n, listener) { - switch (listener->state) { - case EVENT_STATE_ACTIVATE: - if (compare_timestamp(listener, item) > 0) { - continue; - } - next_state = EVENT_STATE_ACTIVATED; - break; - case EVENT_STATE_DEACTIVATE: - if (compare_timestamp(listener, item) < 0) { - /* Consuming all events occurred while activating this listener */ - listener->prev_state = listener->state; - listener->state = EVENT_STATE_ACTIVATED; - if (invoke_event_cb(listener, item) == 1) { - /* listener is deleted */ - continue; - } - - listener->prev_state = listener->state; - listener->state = EVENT_STATE_DEACTIVATE; - } - - /* Do not terminate this listener, until this mets EVENT_EXIT */ - continue; - case EVENT_STATE_ACTIVATED: - if (compare_timestamp(listener, item) > 0) { - continue; - } - next_state = listener->state; - break; - case EVENT_STATE_DEACTIVATED: - default: - /* Remove this from the list */ - /* Check the item again. the listener can be deleted from the callback */ - if (eina_list_data_find(s_info.event_listener_list, listener)) { - s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); - DbgFree(listener); - } + if (!item) { + ErrPrint("There is no remained event\n"); + return ECORE_CALLBACK_RENEW; + } + EINA_LIST_FOREACH_SAFE(s_info.event_listener_list, l, n, listener) { + switch (listener->state) { + case EVENT_STATE_ACTIVATE: + if (compare_timestamp(listener, item) > 0) { + continue; + } + next_state = EVENT_STATE_ACTIVATED; + break; + case EVENT_STATE_DEACTIVATE: + if (compare_timestamp(listener, item) < 0) { + /* Consuming all events occurred while activating this listener */ + listener->prev_state = listener->state; + listener->state = EVENT_STATE_ACTIVATED; + if (invoke_event_cb(listener, item) == 1) { + /* listener is deleted */ continue; + } + + listener->prev_state = listener->state; + listener->state = EVENT_STATE_DEACTIVATE; } - if (invoke_event_cb(listener, item) == 1) { - continue; + /* Do not terminate this listener, until this mets EVENT_EXIT */ + continue; + case EVENT_STATE_ACTIVATED: + if (compare_timestamp(listener, item) > 0) { + continue; + } + next_state = listener->state; + break; + case EVENT_STATE_DEACTIVATED: + default: + /* Remove this from the list */ + /* Check the item again. the listener can be deleted from the callback */ + if (eina_list_data_find(s_info.event_listener_list, listener)) { + s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); + DbgFree(listener); } - listener->prev_state = listener->state; - listener->state = next_state; + continue; } - DbgFree(item); + if (invoke_event_cb(listener, item) == 1) { + continue; + } - return ECORE_CALLBACK_RENEW; + listener->prev_state = listener->state; + listener->state = next_state; + } + + DbgFree(item); + + return ECORE_CALLBACK_RENEW; } static int event_control_init(void) { - int status; - - DbgPrint("Initializing event controller\n"); - if (s_info.handle != -1) { - return DBOX_STATUS_ERROR_NONE; - } - - s_info.handle = open(DYNAMICBOX_CONF_INPUT_PATH, O_RDONLY); - if (s_info.handle < 0) { - ErrPrint("Unable to access the device: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - if (fcntl(s_info.handle, F_SETFD, FD_CLOEXEC) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - } - - if (fcntl(s_info.handle, F_SETFL, O_NONBLOCK) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - } + int status; - status = pipe2(s_info.evt_pipe, O_CLOEXEC); - if (status < 0) { - ErrPrint("Unable to prepare evt pipe: %s\n", strerror(errno)); - if (close(s_info.handle) < 0) { - ErrPrint("Failed to close handle: %s\n", strerror(errno)); - } - s_info.handle = -1; - return DBOX_STATUS_ERROR_FAULT; + DbgPrint("Initializing event controller\n"); + if (s_info.handle != -1) { + return DBOX_STATUS_ERROR_NONE; + } + + s_info.handle = open(DYNAMICBOX_CONF_INPUT_PATH, O_RDONLY); + if (s_info.handle < 0) { + ErrPrint("Unable to access the device: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + if (fcntl(s_info.handle, F_SETFD, FD_CLOEXEC) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + } + + if (fcntl(s_info.handle, F_SETFL, O_NONBLOCK) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + } + + status = pipe2(s_info.evt_pipe, O_CLOEXEC); + if (status < 0) { + ErrPrint("Unable to prepare evt pipe: %s\n", strerror(errno)); + if (close(s_info.handle) < 0) { + ErrPrint("Failed to close handle: %s\n", strerror(errno)); } - - status = pipe2(s_info.tcb_pipe, O_CLOEXEC); - if (status < 0) { - ErrPrint("Unable to prepare tcb pipe: %s\n", strerror(errno)); - if (close(s_info.handle) < 0) { - ErrPrint("Failed to close handle: %s\n", strerror(errno)); - } - s_info.handle = -1; - CLOSE_PIPE(s_info.evt_pipe); - return DBOX_STATUS_ERROR_FAULT; + s_info.handle = -1; + return DBOX_STATUS_ERROR_FAULT; + } + + status = pipe2(s_info.tcb_pipe, O_CLOEXEC); + if (status < 0) { + ErrPrint("Unable to prepare tcb pipe: %s\n", strerror(errno)); + if (close(s_info.handle) < 0) { + ErrPrint("Failed to close handle: %s\n", strerror(errno)); } + s_info.handle = -1; + CLOSE_PIPE(s_info.evt_pipe); + return DBOX_STATUS_ERROR_FAULT; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /*! @@ -837,87 +837,87 @@ static int event_control_init(void) */ static int event_control_fini(void) { - DbgPrint("Finalizing event controller\n"); - if (s_info.handle != -1) { - if (close(s_info.handle) < 0) { - ErrPrint("Unable to release the fd: %s\n", strerror(errno)); - } - - s_info.handle = -1; + DbgPrint("Finalizing event controller\n"); + if (s_info.handle != -1) { + if (close(s_info.handle) < 0) { + ErrPrint("Unable to release the fd: %s\n", strerror(errno)); } - if (!eina_list_count(s_info.event_list)) { - if (s_info.event_handler) { - ecore_main_fd_handler_del(s_info.event_handler); - s_info.event_handler = NULL; - } - clear_all_listener_list(); + s_info.handle = -1; + } + + if (!eina_list_count(s_info.event_list)) { + if (s_info.event_handler) { + ecore_main_fd_handler_del(s_info.event_handler); + s_info.event_handler = NULL; } + clear_all_listener_list(); + } - CLOSE_PIPE(s_info.tcb_pipe); - CLOSE_PIPE(s_info.evt_pipe); + CLOSE_PIPE(s_info.tcb_pipe); + CLOSE_PIPE(s_info.evt_pipe); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static int activate_thread(void) { - int ret; - - ret = event_control_init(); - if (ret != DBOX_STATUS_ERROR_NONE) { - return ret; - } - - if (s_info.event_handler_activated) { - ErrPrint("Event handler is already activated\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - if (s_info.event_handler) { - ErrPrint("Event handler is already registered\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - s_info.event_handler = ecore_main_fd_handler_add(s_info.evt_pipe[PIPE_READ], ECORE_FD_READ, event_read_cb, NULL, NULL, NULL); - if (!s_info.event_handler) { - ErrPrint("Failed to add monitor for EVT READ\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = pthread_create(&s_info.tid, NULL, event_thread_main, NULL); - if (ret != 0) { - ErrPrint("Failed to initiate the thread: %s\n", strerror(ret)); - ecore_main_fd_handler_del(s_info.event_handler); - s_info.event_handler = NULL; - return DBOX_STATUS_ERROR_FAULT; - } + int ret; - DbgPrint("Event handler activated\n"); - s_info.event_handler_activated = 1; - return DBOX_STATUS_ERROR_NONE; + ret = event_control_init(); + if (ret != DBOX_STATUS_ERROR_NONE) { + return ret; + } + + if (s_info.event_handler_activated) { + ErrPrint("Event handler is already activated\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + if (s_info.event_handler) { + ErrPrint("Event handler is already registered\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + s_info.event_handler = ecore_main_fd_handler_add(s_info.evt_pipe[PIPE_READ], ECORE_FD_READ, event_read_cb, NULL, NULL, NULL); + if (!s_info.event_handler) { + ErrPrint("Failed to add monitor for EVT READ\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = pthread_create(&s_info.tid, NULL, event_thread_main, NULL); + if (ret != 0) { + ErrPrint("Failed to initiate the thread: %s\n", strerror(ret)); + ecore_main_fd_handler_del(s_info.event_handler); + s_info.event_handler = NULL; + return DBOX_STATUS_ERROR_FAULT; + } + + DbgPrint("Event handler activated\n"); + s_info.event_handler_activated = 1; + return DBOX_STATUS_ERROR_NONE; } static int deactivate_thread(void) { - int status; - void *ret; - char event_ch = EVENT_CH; - - /* Terminating thread */ - if (write(s_info.tcb_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { - ErrPrint("Unable to write tcb_pipe: %s\n", strerror(errno)); - } - - status = pthread_join(s_info.tid, &ret); - if (status != 0) { - ErrPrint("Failed to join a thread: %s\n", strerror(errno)); - } else { - DbgPrint("Thread returns: %p\n", ret); - } - - s_info.event_handler_activated = 0; - return DBOX_STATUS_ERROR_NONE; + int status; + void *ret; + char event_ch = EVENT_CH; + + /* Terminating thread */ + if (write(s_info.tcb_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) { + ErrPrint("Unable to write tcb_pipe: %s\n", strerror(errno)); + } + + status = pthread_join(s_info.tid, &ret); + if (status != 0) { + ErrPrint("Failed to join a thread: %s\n", strerror(errno)); + } else { + DbgPrint("Thread returns: %p\n", ret); + } + + s_info.event_handler_activated = 0; + return DBOX_STATUS_ERROR_NONE; } /*! @@ -925,134 +925,134 @@ static int deactivate_thread(void) */ HAPI int event_activate(int x, int y, int (*event_cb)(enum event_state state, struct event_data *event, void *data), void *data) { - struct event_listener *listener; - int ret = DBOX_STATUS_ERROR_NONE; + struct event_listener *listener; + int ret = DBOX_STATUS_ERROR_NONE; - listener = malloc(sizeof(*listener)); - if (!listener) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + listener = malloc(sizeof(*listener)); + if (!listener) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } #if defined(_USE_ECORE_TIME_GET) - listener->tv = current_time_get() - DELAY_COMPENSATOR; // Let's use the previous event. - DbgPrint("Activated at: %lf (%dx%d)\n", listener->tv, x, y); + listener->tv = current_time_get() - DELAY_COMPENSATOR; // Let's use the previous event. + DbgPrint("Activated at: %lf (%dx%d)\n", listener->tv, x, y); #else - if (gettimeofday(&listener->tv, NULL) < 0) { - ErrPrint("gettimeofday: %s\n", strerror(errno)); - DbgFree(listener); - return DBOX_STATUS_ERROR_FAULT; - } - DbgPrint("Activated at: %lu sec %lu msec (%dx%d)\n", listener->tv.tv_sec, listener->tv.tv_usec, x, y); - /* NEED TO DO COMPENSATION (DELAY) */ + if (gettimeofday(&listener->tv, NULL) < 0) { + ErrPrint("gettimeofday: %s\n", strerror(errno)); + DbgFree(listener); + return DBOX_STATUS_ERROR_FAULT; + } + DbgPrint("Activated at: %lu sec %lu msec (%dx%d)\n", listener->tv.tv_sec, listener->tv.tv_usec, x, y); + /* NEED TO DO COMPENSATION (DELAY) */ #endif - listener->event_cb = event_cb; - listener->cbdata = data; - listener->prev_state = EVENT_STATE_DEACTIVATED; - listener->state = EVENT_STATE_ACTIVATE; - listener->x = x; - listener->y = y; - - if (!s_info.event_handler_activated) { - /*! - * \note - * We don't need to lock to access event_list here. - * If the _sinfo.handle is greater than 0, the event_list will not be touched. - * But if the s_info.handle is less than 0, it means, there is not thread, - * so we can access the event_list without lock. - */ - if (s_info.event_list) { - DbgPrint("Event thread is deactivating now. activating will be delayed\n"); - s_info.reactivate_list = eina_list_append(s_info.reactivate_list, listener); - } else { - s_info.event_listener_list = eina_list_append(s_info.event_listener_list, listener); - - if ((ret = activate_thread()) < 0) { - s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); - DbgFree(listener); - } - } + listener->event_cb = event_cb; + listener->cbdata = data; + listener->prev_state = EVENT_STATE_DEACTIVATED; + listener->state = EVENT_STATE_ACTIVATE; + listener->x = x; + listener->y = y; + + if (!s_info.event_handler_activated) { + /*! + * \note + * We don't need to lock to access event_list here. + * If the _sinfo.handle is greater than 0, the event_list will not be touched. + * But if the s_info.handle is less than 0, it means, there is not thread, + * so we can access the event_list without lock. + */ + if (s_info.event_list) { + DbgPrint("Event thread is deactivating now. activating will be delayed\n"); + s_info.reactivate_list = eina_list_append(s_info.reactivate_list, listener); } else { - s_info.event_listener_list = eina_list_append(s_info.event_listener_list, listener); + s_info.event_listener_list = eina_list_append(s_info.event_listener_list, listener); + + if ((ret = activate_thread()) < 0) { + s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); + DbgFree(listener); + } } + } else { + s_info.event_listener_list = eina_list_append(s_info.event_listener_list, listener); + } - return ret; + return ret; } HAPI int event_deactivate(int (*event_cb)(enum event_state state, struct event_data *event, void *data), void *data) { - struct event_listener *listener = NULL; - struct event_listener *item; - Eina_List *l; - int keep_thread = 0; - - EINA_LIST_FOREACH(s_info.event_listener_list, l, item) { - if (item->event_cb == event_cb && item->cbdata == data) { - switch (item->state) { - case EVENT_STATE_ACTIVATE: - case EVENT_STATE_ACTIVATED: - item->prev_state = item->state; - item->state = EVENT_STATE_DEACTIVATE; - listener = item; - break; - default: - /* Item is already deactivated */ - break; - } - } - - keep_thread += (item->state == EVENT_STATE_ACTIVATE || item->state == EVENT_STATE_ACTIVATED); - } - - if (!listener) { - ErrPrint("Listener is not registered or already deactivated\n"); - return DBOX_STATUS_ERROR_NOT_EXIST; + struct event_listener *listener = NULL; + struct event_listener *item; + Eina_List *l; + int keep_thread = 0; + + EINA_LIST_FOREACH(s_info.event_listener_list, l, item) { + if (item->event_cb == event_cb && item->cbdata == data) { + switch (item->state) { + case EVENT_STATE_ACTIVATE: + case EVENT_STATE_ACTIVATED: + item->prev_state = item->state; + item->state = EVENT_STATE_DEACTIVATE; + listener = item; + break; + default: + /* Item is already deactivated */ + break; + } } - if (s_info.event_handler_activated == 0) { - ErrPrint("Event handler is not actiavated\n"); - s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); - DbgFree(listener); - return DBOX_STATUS_ERROR_NONE; - } + keep_thread += (item->state == EVENT_STATE_ACTIVATE || item->state == EVENT_STATE_ACTIVATED); + } - if (keep_thread) { - DbgPrint("Keep thread\n"); - return DBOX_STATUS_ERROR_NONE; - } + if (!listener) { + ErrPrint("Listener is not registered or already deactivated\n"); + return DBOX_STATUS_ERROR_NOT_EXIST; + } - deactivate_thread(); + if (s_info.event_handler_activated == 0) { + ErrPrint("Event handler is not actiavated\n"); + s_info.event_listener_list = eina_list_remove(s_info.event_listener_list, listener); + DbgFree(listener); + return DBOX_STATUS_ERROR_NONE; + } + if (keep_thread) { + DbgPrint("Keep thread\n"); return DBOX_STATUS_ERROR_NONE; + } + + deactivate_thread(); + + return DBOX_STATUS_ERROR_NONE; } HAPI int event_reset_cbdata(int (*event_cb)(enum event_state state, struct event_data *event, void *data), void *data, void *new_data) { - struct event_listener *item; - Eina_List *l; - int updated = 0; - - EINA_LIST_FOREACH(s_info.event_listener_list, l, item) { - if (item->event_cb == event_cb && item->cbdata == data) { - item->cbdata = new_data; - updated++; - } + struct event_listener *item; + Eina_List *l; + int updated = 0; + + EINA_LIST_FOREACH(s_info.event_listener_list, l, item) { + if (item->event_cb == event_cb && item->cbdata == data) { + item->cbdata = new_data; + updated++; } + } - EINA_LIST_FOREACH(s_info.reactivate_list, l, item) { - if (item->event_cb == event_cb && item->cbdata == data) { - item->cbdata = new_data; - updated++; - } + EINA_LIST_FOREACH(s_info.reactivate_list, l, item) { + if (item->event_cb == event_cb && item->cbdata == data) { + item->cbdata = new_data; + updated++; } + } - return updated; + return updated; } HAPI int event_is_activated(void) { - return s_info.handle >= 0; + return s_info.handle >= 0; } /* End of a file */ diff --git a/src/fault_manager.c b/src/fault_manager.c index ebb0824..1ea694a 100644 --- a/src/fault_manager.c +++ b/src/fault_manager.c @@ -40,334 +40,334 @@ #include "critical_log.h" static struct info { - Eina_List *call_list; - int fault_mark_count; + Eina_List *call_list; + int fault_mark_count; } s_info = { - .call_list = NULL, - .fault_mark_count = 0, + .call_list = NULL, + .fault_mark_count = 0, }; struct fault_info { - struct slave_node *slave; - double timestamp; - char *pkgname; - char *filename; - char *func; + struct slave_node *slave; + double timestamp; + char *pkgname; + char *filename; + char *func; }; HAPI int const fault_is_occured(void) { - return s_info.fault_mark_count; + return s_info.fault_mark_count; } static void clear_log_file(struct slave_node *slave) { - char filename[BUFSIZ]; - int ret; - - ret = snprintf(filename, sizeof(filename) - 1, "%s/slave.%d", DYNAMICBOX_CONF_LOG_PATH, slave_pid(slave)); - if (ret == sizeof(filename) - 1) { - filename[sizeof(filename) - 1] = '\0'; - ErrPrint("filename buffer is overflowed\n"); - } - - if (unlink(filename) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } + char filename[BUFSIZ]; + int ret; + + ret = snprintf(filename, sizeof(filename) - 1, "%s/slave.%d", DYNAMICBOX_CONF_LOG_PATH, slave_pid(slave)); + if (ret == sizeof(filename) - 1) { + filename[sizeof(filename) - 1] = '\0'; + ErrPrint("filename buffer is overflowed\n"); + } + + if (unlink(filename) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); + } } static char *check_log_file(struct slave_node *slave) { - char libexec[BUFSIZ]; - char *ptr; - FILE *fp; - char filename[BUFSIZ]; - - snprintf(filename, sizeof(filename), "%s/slave.%d", DYNAMICBOX_CONF_LOG_PATH, slave_pid(slave)); - fp = fopen(filename, "rt"); - if (!fp) { - ErrPrint("No log file found [%s]\n", strerror(errno)); - return NULL; - } - - ptr = fgets(libexec, sizeof(libexec), fp); - if (fclose(fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } - - if (ptr != libexec) { - ErrPrint("Invalid log\n"); - return NULL; - } - - if (unlink(filename) < 0) { - ErrPrint("Failed to unlink %s\n", filename); - } - - ptr = dynamicbox_service_dbox_id_by_libexec(libexec); - if (!ptr) { - ErrPrint("Failed to find the faulted package\n"); - } - - DbgPrint("Faulted package: %s\n", ptr); - return ptr; + char libexec[BUFSIZ]; + char *ptr; + FILE *fp; + char filename[BUFSIZ]; + + snprintf(filename, sizeof(filename), "%s/slave.%d", DYNAMICBOX_CONF_LOG_PATH, slave_pid(slave)); + fp = fopen(filename, "rt"); + if (!fp) { + ErrPrint("No log file found [%s]\n", strerror(errno)); + return NULL; + } + + ptr = fgets(libexec, sizeof(libexec), fp); + if (fclose(fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); + } + + if (ptr != libexec) { + ErrPrint("Invalid log\n"); + return NULL; + } + + if (unlink(filename) < 0) { + ErrPrint("Failed to unlink %s\n", filename); + } + + ptr = dynamicbox_service_dbox_id_by_libexec(libexec); + if (!ptr) { + ErrPrint("Failed to find the faulted package\n"); + } + + DbgPrint("Faulted package: %s\n", ptr); + return ptr; } HAPI void fault_unicast_info(struct client_node *client, const char *pkgname, const char *filename, const char *func) { - struct packet *packet; - unsigned int cmd = CMD_FAULT_PACKAGE; + struct packet *packet; + unsigned int cmd = CMD_FAULT_PACKAGE; - if (!client || !pkgname || !filename || !func) { - return; - } + if (!client || !pkgname || !filename || !func) { + return; + } - packet = packet_create_noack((const char *)&cmd, "sss", pkgname, filename, func); - if (!packet) { - return; - } + packet = packet_create_noack((const char *)&cmd, "sss", pkgname, filename, func); + if (!packet) { + return; + } - client_rpc_async_request(client, packet); + client_rpc_async_request(client, packet); } HAPI void fault_broadcast_info(const char *pkgname, const char *filename, const char *func) { - struct packet *packet; - unsigned int cmd = CMD_FAULT_PACKAGE; + struct packet *packet; + unsigned int cmd = CMD_FAULT_PACKAGE; - packet = packet_create_noack((const char *)&cmd, "sss", pkgname, filename, func); - if (!packet) { - ErrPrint("Failed to create a param\n"); - return; - } + packet = packet_create_noack((const char *)&cmd, "sss", pkgname, filename, func); + if (!packet) { + ErrPrint("Failed to create a param\n"); + return; + } - client_broadcast(NULL, packet); + client_broadcast(NULL, packet); } static inline void dump_fault_info(const char *name, pid_t pid, const char *pkgname, const char *filename, const char *funcname) { - CRITICAL_LOG("Slavename: %s[%d]\n" \ - "Package: %s\n" \ - "Filename: %s\n" \ - "Funcname: %s\n", name, pid, pkgname, filename, funcname); + CRITICAL_LOG("Slavename: %s[%d]\n" \ + "Package: %s\n" \ + "Filename: %s\n" \ + "Funcname: %s\n", name, pid, pkgname, filename, funcname); } HAPI int fault_info_set(struct slave_node *slave, const char *pkgname, const char *id, const char *func) { - struct pkg_info *pkg; - int ret; - - pkg = package_find(pkgname); - if (!pkg) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } - - ret = package_set_fault_info(pkg, util_timestamp(), id, func); - if (ret < 0) { - return DBOX_STATUS_ERROR_FAULT; - } + struct pkg_info *pkg; + int ret; - dump_fault_info(slave_name(slave), slave_pid(slave), pkgname, id, func); - ErrPrint("Set fault %s(%d)\n", !ret ? "Success" : "Failed", ret); - fault_broadcast_info(pkgname, id, func); - - /*! - * \note - * Update statistics - */ - s_info.fault_mark_count++; - return DBOX_STATUS_ERROR_NONE; + pkg = package_find(pkgname); + if (!pkg) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } + + ret = package_set_fault_info(pkg, util_timestamp(), id, func); + if (ret < 0) { + return DBOX_STATUS_ERROR_FAULT; + } + + dump_fault_info(slave_name(slave), slave_pid(slave), pkgname, id, func); + ErrPrint("Set fault %s(%d)\n", !ret ? "Success" : "Failed", ret); + fault_broadcast_info(pkgname, id, func); + + /*! + * \note + * Update statistics + */ + s_info.fault_mark_count++; + return DBOX_STATUS_ERROR_NONE; } HAPI int fault_check_pkgs(struct slave_node *slave) { - struct fault_info *info; - struct pkg_info *pkg; - const char *pkgname; - Eina_List *l; - Eina_List *n; - int checked; - - /*! - * \note - * First step. - * Check the log file - */ - pkgname = (const char *)check_log_file(slave); - if (pkgname) { - pkg = package_find(pkgname); - if (pkg) { - (void)package_set_fault_info(pkg, util_timestamp(), NULL, NULL); - dump_fault_info(slave_name(slave), slave_pid(slave), pkgname, "", ""); - fault_broadcast_info(pkgname, "", ""); - DbgFree((char *)pkgname); - - s_info.fault_mark_count = 0; - clear_log_file(slave); - EINA_LIST_REVERSE_FOREACH_SAFE(s_info.call_list, l, n, info) { - if (info->slave != slave) { - continue; - } - - s_info.call_list = eina_list_remove_list(s_info.call_list, l); - - DbgFree(info->pkgname); - DbgFree(info->filename); - DbgFree(info->func); - DbgFree(info); - } - return 0; - } - DbgFree((char *)pkgname); - } - - /*! - * \note - * Second step. - * Is it secured slave? - */ - pkgname = package_find_by_secured_slave(slave); - if (pkgname) { - pkg = package_find(pkgname); - if (pkg) { - (void)package_set_fault_info(pkg, util_timestamp(), NULL, NULL); - dump_fault_info(slave_name(slave), slave_pid(slave), pkgname, "", ""); - fault_broadcast_info(pkgname, "", ""); - - s_info.fault_mark_count = 0; - clear_log_file(slave); - EINA_LIST_REVERSE_FOREACH_SAFE(s_info.call_list, l, n, info) { - if (info->slave != slave) { - continue; - } - - s_info.call_list = eina_list_remove_list(s_info.call_list, l); - - DbgFree(info->pkgname); - DbgFree(info->filename); - DbgFree(info->func); - DbgFree(info); - } - return 0; - } - } - - /*! - * \note - * At last, check the pair of function call and return mark - */ - checked = 0; - EINA_LIST_REVERSE_FOREACH_SAFE(s_info.call_list, l, n, info) { - if (info->slave == slave) { - const char *filename; - const char *func; - - pkg = package_find(info->pkgname); - if (!pkg) { - ErrPrint("Failed to find a package %s\n", info->pkgname); - continue; - } - - filename = info->filename ? info->filename : ""; - func = info->func ? info->func : ""; - - if (!checked) { - (void)package_set_fault_info(pkg, info->timestamp, info->filename, info->func); - fault_broadcast_info(info->pkgname, info->filename, info->func); - } else { - DbgPrint("Treated as a false log\n"); - dump_fault_info( - slave_name(info->slave), slave_pid(info->slave), info->pkgname, filename, func); - } - - s_info.call_list = eina_list_remove_list(s_info.call_list, l); - - DbgFree(info->pkgname); - DbgFree(info->filename); - DbgFree(info->func); - DbgFree(info); - checked = 1; + struct fault_info *info; + struct pkg_info *pkg; + const char *pkgname; + Eina_List *l; + Eina_List *n; + int checked; + + /*! + * \note + * First step. + * Check the log file + */ + pkgname = (const char *)check_log_file(slave); + if (pkgname) { + pkg = package_find(pkgname); + if (pkg) { + (void)package_set_fault_info(pkg, util_timestamp(), NULL, NULL); + dump_fault_info(slave_name(slave), slave_pid(slave), pkgname, "", ""); + fault_broadcast_info(pkgname, "", ""); + DbgFree((char *)pkgname); + + s_info.fault_mark_count = 0; + clear_log_file(slave); + EINA_LIST_REVERSE_FOREACH_SAFE(s_info.call_list, l, n, info) { + if (info->slave != slave) { + continue; } - } - - s_info.fault_mark_count = 0; - clear_log_file(slave); - return 0; -} - -HAPI int fault_func_call(struct slave_node *slave, const char *pkgname, const char *filename, const char *func) -{ - struct fault_info *info; - - info = malloc(sizeof(*info)); - if (!info) { - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - info->slave = slave; - - info->pkgname = strdup(pkgname); - if (!info->pkgname) { - DbgFree(info); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + s_info.call_list = eina_list_remove_list(s_info.call_list, l); - info->filename = strdup(filename); - if (!info->filename) { DbgFree(info->pkgname); + DbgFree(info->filename); + DbgFree(info->func); DbgFree(info); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + return 0; } + DbgFree((char *)pkgname); + } + + /*! + * \note + * Second step. + * Is it secured slave? + */ + pkgname = package_find_by_secured_slave(slave); + if (pkgname) { + pkg = package_find(pkgname); + if (pkg) { + (void)package_set_fault_info(pkg, util_timestamp(), NULL, NULL); + dump_fault_info(slave_name(slave), slave_pid(slave), pkgname, "", ""); + fault_broadcast_info(pkgname, "", ""); + + s_info.fault_mark_count = 0; + clear_log_file(slave); + EINA_LIST_REVERSE_FOREACH_SAFE(s_info.call_list, l, n, info) { + if (info->slave != slave) { + continue; + } + + s_info.call_list = eina_list_remove_list(s_info.call_list, l); - info->func = strdup(func); - if (!info->func) { - DbgFree(info->filename); DbgFree(info->pkgname); + DbgFree(info->filename); + DbgFree(info->func); DbgFree(info); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + return 0; } + } + + /*! + * \note + * At last, check the pair of function call and return mark + */ + checked = 0; + EINA_LIST_REVERSE_FOREACH_SAFE(s_info.call_list, l, n, info) { + if (info->slave == slave) { + const char *filename; + const char *func; + + pkg = package_find(info->pkgname); + if (!pkg) { + ErrPrint("Failed to find a package %s\n", info->pkgname); + continue; + } + + filename = info->filename ? info->filename : ""; + func = info->func ? info->func : ""; + + if (!checked) { + (void)package_set_fault_info(pkg, info->timestamp, info->filename, info->func); + fault_broadcast_info(info->pkgname, info->filename, info->func); + } else { + DbgPrint("Treated as a false log\n"); + dump_fault_info( + slave_name(info->slave), slave_pid(info->slave), info->pkgname, filename, func); + } + + s_info.call_list = eina_list_remove_list(s_info.call_list, l); + + DbgFree(info->pkgname); + DbgFree(info->filename); + DbgFree(info->func); + DbgFree(info); + checked = 1; + } + } - info->timestamp = util_timestamp(); - - s_info.call_list = eina_list_append(s_info.call_list, info); + s_info.fault_mark_count = 0; + clear_log_file(slave); + return 0; +} - s_info.fault_mark_count++; - return DBOX_STATUS_ERROR_NONE; +HAPI int fault_func_call(struct slave_node *slave, const char *pkgname, const char *filename, const char *func) +{ + struct fault_info *info; + + info = malloc(sizeof(*info)); + if (!info) { + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->slave = slave; + + info->pkgname = strdup(pkgname); + if (!info->pkgname) { + DbgFree(info); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->filename = strdup(filename); + if (!info->filename) { + DbgFree(info->pkgname); + DbgFree(info); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->func = strdup(func); + if (!info->func) { + DbgFree(info->filename); + DbgFree(info->pkgname); + DbgFree(info); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->timestamp = util_timestamp(); + + s_info.call_list = eina_list_append(s_info.call_list, info); + + s_info.fault_mark_count++; + return DBOX_STATUS_ERROR_NONE; } HAPI int fault_func_ret(struct slave_node *slave, const char *pkgname, const char *filename, const char *func) { - struct fault_info *info; - Eina_List *l; + struct fault_info *info; + Eina_List *l; - EINA_LIST_FOREACH(s_info.call_list, l, info) { - if (info->slave != slave) { - continue; - } + EINA_LIST_FOREACH(s_info.call_list, l, info) { + if (info->slave != slave) { + continue; + } - if (strcmp(info->pkgname, pkgname)) { - continue; - } + if (strcmp(info->pkgname, pkgname)) { + continue; + } - if (strcmp(info->filename, filename)) { - continue; - } + if (strcmp(info->filename, filename)) { + continue; + } - if (strcmp(info->func, func)) { - continue; - } + if (strcmp(info->func, func)) { + continue; + } - s_info.call_list = eina_list_remove_list(s_info.call_list, l); - DbgFree(info->filename); - DbgFree(info->pkgname); - DbgFree(info->func); - DbgFree(info); + s_info.call_list = eina_list_remove_list(s_info.call_list, l); + DbgFree(info->filename); + DbgFree(info->pkgname); + DbgFree(info->func); + DbgFree(info); - s_info.fault_mark_count--; - return 0; - } + s_info.fault_mark_count--; + return 0; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } /* End of a file */ diff --git a/src/file_service.c b/src/file_service.c index 1502d04..8c53a02 100644 --- a/src/file_service.c +++ b/src/file_service.c @@ -46,34 +46,34 @@ #define PKT_CHUNKSZ 4096 static struct info { - struct service_context *svc_ctx; + struct service_context *svc_ctx; - pthread_t push_thid; + pthread_t push_thid; - Eina_List *request_list; - pthread_mutex_t request_list_lock; + Eina_List *request_list; + pthread_mutex_t request_list_lock; - int request_pipe[PIPE_MAX]; + int request_pipe[PIPE_MAX]; } s_info = { - .svc_ctx = NULL, - .request_list = NULL, - .request_list_lock = PTHREAD_MUTEX_INITIALIZER, - .request_pipe = { 0, }, + .svc_ctx = NULL, + .request_list = NULL, + .request_list_lock = PTHREAD_MUTEX_INITIALIZER, + .request_pipe = { 0, }, }; struct request_item { - enum { - REQUEST_TYPE_FILE = 0x00, - REQUEST_TYPE_SHM = 0x01, - REQUEST_TYPE_PIXMAP = 0x02, - REQUEST_TYPE_MAX = 0x02, - } type; - union { - char *filename; - int shm; - unsigned int pixmap; - } data; - struct tcb *tcb; + enum { + REQUEST_TYPE_FILE = 0x00, + REQUEST_TYPE_SHM = 0x01, + REQUEST_TYPE_PIXMAP = 0x02, + REQUEST_TYPE_MAX = 0x02, + } type; + union { + char *filename; + int shm; + unsigned int pixmap; + } data; + struct tcb *tcb; }; typedef int (*send_data_func_t)(int fd, const struct request_item *item); @@ -83,637 +83,637 @@ typedef int (*send_data_func_t)(int fd, const struct request_item *item); * This must should be shared with client. */ struct burst_head { - off_t size; - int flen; - char fname[]; + off_t size; + int flen; + char fname[]; }; struct burst_data { - int size; - char data[]; + int size; + char data[]; }; static inline struct request_item *create_request_item(struct tcb *tcb, int type, void *data) { - struct request_item *item; + struct request_item *item; - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - switch (type) { + switch (type) { case REQUEST_TYPE_FILE: - item->data.filename = strdup(data); - if (!item->data.filename) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item); - return NULL; - } - break; + item->data.filename = strdup(data); + if (!item->data.filename) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item); + return NULL; + } + break; case REQUEST_TYPE_PIXMAP: - item->data.pixmap = (unsigned int)data; - break; + item->data.pixmap = (unsigned int)data; + break; case REQUEST_TYPE_SHM: - item->data.shm = (int)data; - break; + item->data.shm = (int)data; + break; default: - ErrPrint("Invalid type of request\n"); - DbgFree(item); - return NULL; - } - - item->type = type; - item->tcb = tcb; - return item; + ErrPrint("Invalid type of request\n"); + DbgFree(item); + return NULL; + } + + item->type = type; + item->tcb = tcb; + return item; } static inline int destroy_request_item(struct request_item *item) { - switch (item->type) { + switch (item->type) { case REQUEST_TYPE_FILE: - DbgFree(item->data.filename); - break; + DbgFree(item->data.filename); + break; case REQUEST_TYPE_SHM: case REQUEST_TYPE_PIXMAP: - break; + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } static int request_file_handler(struct tcb *tcb, struct packet *packet, struct request_item **item) { - const char *filename; + const char *filename; - if (packet_get(packet, "s", &filename) != 1) { - ErrPrint("Invalid packet\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (packet_get(packet, "s", &filename) != 1) { + ErrPrint("Invalid packet\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - *item = create_request_item(tcb, REQUEST_TYPE_FILE, (void *)filename); - return *item ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_OUT_OF_MEMORY; + *item = create_request_item(tcb, REQUEST_TYPE_FILE, (void *)filename); + return *item ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_OUT_OF_MEMORY; } static int request_pixmap_handler(struct tcb *tcb, struct packet *packet, struct request_item **item) { - unsigned int pixmap; - - if (packet_get(packet, "i", &pixmap) != 1) { - ErrPrint("Invalid packet\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (pixmap == 0) { - ErrPrint("pixmap is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - /*! - * \TODO - * Attach to pixmap and copy its data to the client - */ - *item = create_request_item(tcb, REQUEST_TYPE_PIXMAP, (void *)pixmap); - return *item ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_OUT_OF_MEMORY; + unsigned int pixmap; + + if (packet_get(packet, "i", &pixmap) != 1) { + ErrPrint("Invalid packet\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (pixmap == 0) { + ErrPrint("pixmap is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + /*! + * \TODO + * Attach to pixmap and copy its data to the client + */ + *item = create_request_item(tcb, REQUEST_TYPE_PIXMAP, (void *)pixmap); + return *item ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_OUT_OF_MEMORY; } static int request_shm_handler(struct tcb *tcb, struct packet *packet, struct request_item **item) { - int shm; - - if (packet_get(packet, "i", &shm) != 1) { - ErrPrint("Invalid packet\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (shm < 0) { - ErrPrint("shm is not valid: %d\n", shm); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - /*! - * \TODO - * Attach to SHM and copy its buffer to the client - */ - *item = create_request_item(tcb, REQUEST_TYPE_SHM, (void *)shm); - return *item ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_OUT_OF_MEMORY; + int shm; + + if (packet_get(packet, "i", &shm) != 1) { + ErrPrint("Invalid packet\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (shm < 0) { + ErrPrint("shm is not valid: %d\n", shm); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + /*! + * \TODO + * Attach to SHM and copy its buffer to the client + */ + *item = create_request_item(tcb, REQUEST_TYPE_SHM, (void *)shm); + return *item ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_OUT_OF_MEMORY; } /* SERVER THREAD */ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data) { + const char *cmd; + char ch = PUSH_ITEM; + int ret; + int i; + struct request_item *item; + struct packet *reply; + struct { const char *cmd; - char ch = PUSH_ITEM; - int ret; - int i; - struct request_item *item; - struct packet *reply; - struct { - const char *cmd; - int (*request_handler)(struct tcb *tcb, struct packet *packet, struct request_item **item); - } cmd_table[] = { - { - .cmd = "request,file", - .request_handler = request_file_handler, - }, - { - .cmd = "request,pixmap", - .request_handler = request_pixmap_handler, - }, - { - .cmd = "request,shm", - .request_handler = request_shm_handler, - }, - { - .cmd = NULL, - .request_handler = NULL, - }, - }; - - if (!packet) { - DbgPrint("TCB %p is disconnected\n", tcb); - return DBOX_STATUS_ERROR_NONE; - } + int (*request_handler)(struct tcb *tcb, struct packet *packet, struct request_item **item); + } cmd_table[] = { + { + .cmd = "request,file", + .request_handler = request_file_handler, + }, + { + .cmd = "request,pixmap", + .request_handler = request_pixmap_handler, + }, + { + .cmd = "request,shm", + .request_handler = request_shm_handler, + }, + { + .cmd = NULL, + .request_handler = NULL, + }, + }; + + if (!packet) { + DbgPrint("TCB %p is disconnected\n", tcb); + return DBOX_STATUS_ERROR_NONE; + } - cmd = packet_command(packet); - if (!cmd) { - ErrPrint("Invalid packet. cmd is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + cmd = packet_command(packet); + if (!cmd) { + ErrPrint("Invalid packet. cmd is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (packet_type(packet)) { + switch (packet_type(packet)) { case PACKET_REQ: - for (i = 0; cmd_table[i].cmd; i++) { - /*! - * Protocol sequence - * FILE REQUEST COMMAND (Client -> Server) - * REPLY FOR REQUEST (Client <- Server) - * PUSH FILE (Client <- Server) - * - * Client & Server must has to keep this communication sequence. - */ - if (strcmp(cmd, cmd_table[i].cmd)) { - continue; - } - - item = NULL; - ret = cmd_table[i].request_handler(tcb, packet, &item); - - reply = packet_create_reply(packet, "i", ret); - if (!reply) { - ErrPrint("Failed to create a reply packet\n"); - break; - } - - if (service_common_unicast_packet(tcb, reply) < 0) { - ErrPrint("Unable to send reply packet\n"); - } - - packet_destroy(reply); - - /*! - * \note - * After send the reply packet, file push thread can sending a file - */ - if (ret != DBOX_STATUS_ERROR_NONE || !item) { - break; - } - - CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); - s_info.request_list = eina_list_append(s_info.request_list, item); - CRITICAL_SECTION_END(&s_info.request_list_lock); - - ret = write(s_info.request_pipe[PIPE_WRITE], &ch, sizeof(ch)); - if (ret < 0) { - ErrPrint("write: %s\n", strerror(errno)); - - CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); - s_info.request_list = eina_list_remove(s_info.request_list, item); - CRITICAL_SECTION_END(&s_info.request_list_lock); - - destroy_request_item(item); - /*! - * \note for the client - * In this case, the client can waiting files forever. - * So the client must has to wait only a few seconds. - * If the client could not get the any data in that time, - * it should cancel the waiting. - */ - } + for (i = 0; cmd_table[i].cmd; i++) { + /*! + * Protocol sequence + * FILE REQUEST COMMAND (Client -> Server) + * REPLY FOR REQUEST (Client <- Server) + * PUSH FILE (Client <- Server) + * + * Client & Server must has to keep this communication sequence. + */ + if (strcmp(cmd, cmd_table[i].cmd)) { + continue; + } + + item = NULL; + ret = cmd_table[i].request_handler(tcb, packet, &item); + + reply = packet_create_reply(packet, "i", ret); + if (!reply) { + ErrPrint("Failed to create a reply packet\n"); + break; } - break; + if (service_common_unicast_packet(tcb, reply) < 0) { + ErrPrint("Unable to send reply packet\n"); + } + + packet_destroy(reply); + + /*! + * \note + * After send the reply packet, file push thread can sending a file + */ + if (ret != DBOX_STATUS_ERROR_NONE || !item) { + break; + } + + CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); + s_info.request_list = eina_list_append(s_info.request_list, item); + CRITICAL_SECTION_END(&s_info.request_list_lock); + + ret = write(s_info.request_pipe[PIPE_WRITE], &ch, sizeof(ch)); + if (ret < 0) { + ErrPrint("write: %s\n", strerror(errno)); + + CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); + s_info.request_list = eina_list_remove(s_info.request_list, item); + CRITICAL_SECTION_END(&s_info.request_list_lock); + + destroy_request_item(item); + /*! + * \note for the client + * In this case, the client can waiting files forever. + * So the client must has to wait only a few seconds. + * If the client could not get the any data in that time, + * it should cancel the waiting. + */ + } + } + + break; case PACKET_REQ_NOACK: case PACKET_ACK: - /* File service has no this case, it is passive service type */ - ErrPrint("Invalid packet.\n"); - break; + /* File service has no this case, it is passive service type */ + ErrPrint("Invalid packet.\n"); + break; default: - break; - } + break; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static int send_file(int handle, const struct request_item *item) { - struct burst_head *head; - struct burst_data *body; - int pktsz; - int flen; - off_t fsize; - int fd; - int ret = 0; - - /* TODO: push a file to the client */ - fd = open(item->data.filename, O_RDONLY); - if (fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - return -EIO; - } - - flen = strlen(item->data.filename); - if (flen == 0) { - ret = -EINVAL; - goto errout; - } - - pktsz = sizeof(*head) + flen + 1; - - head = malloc(pktsz); - if (!head) { - ErrPrint("heap: %s\n", strerror(errno)); - ret = -ENOMEM; - goto errout; - } - - fsize = lseek(fd, 0L, SEEK_END); - if (fsize == (off_t)-1) { - ErrPrint("heap: %s\n", strerror(errno)); - DbgFree(head); - ret = -EIO; - goto errout; + struct burst_head *head; + struct burst_data *body; + int pktsz; + int flen; + off_t fsize; + int fd; + int ret = 0; + + /* TODO: push a file to the client */ + fd = open(item->data.filename, O_RDONLY); + if (fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + return -EIO; + } + + flen = strlen(item->data.filename); + if (flen == 0) { + ret = -EINVAL; + goto errout; + } + + pktsz = sizeof(*head) + flen + 1; + + head = malloc(pktsz); + if (!head) { + ErrPrint("heap: %s\n", strerror(errno)); + ret = -ENOMEM; + goto errout; + } + + fsize = lseek(fd, 0L, SEEK_END); + if (fsize == (off_t)-1) { + ErrPrint("heap: %s\n", strerror(errno)); + DbgFree(head); + ret = -EIO; + goto errout; + } + + head->flen = flen; + head->size = fsize; + strcpy(head->fname, item->data.filename); + + /* Anytime we can fail to send packet */ + ret = com_core_send(handle, (void *)head, pktsz, 2.0f); + DbgFree(head); + if (ret < 0) { + ret = -EFAULT; + goto errout; + } + + if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) { + ErrPrint("seek: %s\n", strerror(errno)); + + body = malloc(sizeof(*body)); + if (!body) { + ErrPrint("Heap: %s\n", strerror(errno)); + return -ENOMEM; } - head->flen = flen; - head->size = fsize; - strcpy(head->fname, item->data.filename); + body->size = -1; + ret = com_core_send(handle, (void *)body, sizeof(*body), 2.0f); + DbgFree(body); - /* Anytime we can fail to send packet */ - ret = com_core_send(handle, (void *)head, pktsz, 2.0f); - DbgFree(head); if (ret < 0) { - ret = -EFAULT; - goto errout; + ret = -EFAULT; + } else { + ret = -EIO; } - if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) { - ErrPrint("seek: %s\n", strerror(errno)); - - body = malloc(sizeof(*body)); - if (!body) { - ErrPrint("Heap: %s\n", strerror(errno)); - return -ENOMEM; - } - - body->size = -1; - ret = com_core_send(handle, (void *)body, sizeof(*body), 2.0f); - DbgFree(body); + goto errout; + } - if (ret < 0) { - ret = -EFAULT; - } else { - ret = -EIO; - } + body = malloc(PKT_CHUNKSZ + sizeof(*body)); + if (!body) { + ErrPrint("heap: %s\n", strerror(errno)); + goto errout; + } - goto errout; + /* Burst pushing. */ + while (fsize > 0) { + if (fsize > PKT_CHUNKSZ) { + body->size = PKT_CHUNKSZ; + } else { + body->size = fsize; } - body = malloc(PKT_CHUNKSZ + sizeof(*body)); - if (!body) { - ErrPrint("heap: %s\n", strerror(errno)); - goto errout; + ret = read(fd, body->data, body->size); + if (ret < 0) { + ErrPrint("read: %s\n", strerror(errno)); + ret = -EIO; + break; } - /* Burst pushing. */ - while (fsize > 0) { - if (fsize > PKT_CHUNKSZ) { - body->size = PKT_CHUNKSZ; - } else { - body->size = fsize; - } + body->size = ret; + fsize -= ret; + pktsz = sizeof(*body) + body->size; - ret = read(fd, body->data, body->size); - if (ret < 0) { - ErrPrint("read: %s\n", strerror(errno)); - ret = -EIO; - break; - } - - body->size = ret; - fsize -= ret; - pktsz = sizeof(*body) + body->size; - - /* Send BODY */ - ret = com_core_send(handle, (void *)body, pktsz, 2.0f); - if (ret != pktsz) { - ret = -EFAULT; - break; - } + /* Send BODY */ + ret = com_core_send(handle, (void *)body, pktsz, 2.0f); + if (ret != pktsz) { + ret = -EFAULT; + break; } + } - /* Send EOF */ - body->size = -1; - ret = com_core_send(handle, (void *)body, sizeof(*body), 2.0f); - if (ret < 0) { - ret = -EFAULT; - } + /* Send EOF */ + body->size = -1; + ret = com_core_send(handle, (void *)body, sizeof(*body), 2.0f); + if (ret < 0) { + ret = -EFAULT; + } - DbgFree(body); + DbgFree(body); errout: - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } - return ret; + return ret; } static int send_buffer(int handle, const struct request_item *item) { - dynamicbox_fb_t buffer; - struct burst_head *head; - struct burst_data *body; - char *data; - int pktsz; - int ret; - int size; - int offset; - int type; - - if (item->type == REQUEST_TYPE_SHM) { - type = DBOX_FB_TYPE_SHM; - } else { - type = DBOX_FB_TYPE_PIXMAP; - } + dynamicbox_fb_t buffer; + struct burst_head *head; + struct burst_data *body; + char *data; + int pktsz; + int ret; + int size; + int offset; + int type; + + if (item->type == REQUEST_TYPE_SHM) { + type = DBOX_FB_TYPE_SHM; + } else { + type = DBOX_FB_TYPE_PIXMAP; + } + + buffer = buffer_handler_raw_open(type, (void *)item->data.shm); + if (!buffer) { + return -EINVAL; + } + + pktsz = sizeof(*head); + + head = malloc(pktsz); + if (!head) { + ErrPrint("Heap: %s\n", strerror(errno)); + (void)buffer_handler_raw_close(buffer); + return -ENOMEM; + } - buffer = buffer_handler_raw_open(type, (void *)item->data.shm); - if (!buffer) { - return -EINVAL; - } + size = head->size = buffer_handler_raw_size(buffer); + head->flen = 0; - pktsz = sizeof(*head); + /* Anytime we can fail to send packet */ + ret = com_core_send(handle, (void *)head, pktsz, 2.0f); + DbgFree(head); + if (ret < 0) { + ret = -EFAULT; + goto errout; + } - head = malloc(pktsz); - if (!head) { - ErrPrint("Heap: %s\n", strerror(errno)); - (void)buffer_handler_raw_close(buffer); - return -ENOMEM; - } + body = malloc(sizeof(*body) + PKT_CHUNKSZ); + if (!body) { + ret = -ENOMEM; + goto errout; + } - size = head->size = buffer_handler_raw_size(buffer); - head->flen = 0; + data = (char *)buffer_handler_raw_data(buffer); + offset = 0; + while (offset < size) { + body->size = size - offset; - /* Anytime we can fail to send packet */ - ret = com_core_send(handle, (void *)head, pktsz, 2.0f); - DbgFree(head); - if (ret < 0) { - ret = -EFAULT; - goto errout; - } - - body = malloc(sizeof(*body) + PKT_CHUNKSZ); - if (!body) { - ret = -ENOMEM; - goto errout; + if (body->size > PKT_CHUNKSZ) { + body->size = PKT_CHUNKSZ; } - data = (char *)buffer_handler_raw_data(buffer); - offset = 0; - while (offset < size) { - body->size = size - offset; + memcpy(body->data, data, body->size); + pktsz = sizeof(*body) + body->size; - if (body->size > PKT_CHUNKSZ) { - body->size = PKT_CHUNKSZ; - } - - memcpy(body->data, data, body->size); - pktsz = sizeof(*body) + body->size; - - ret = com_core_send(handle, (void *)body, pktsz, 2.0f); - if (ret < 0) { - ret = -EFAULT; - break; - } - - offset += body->size; + ret = com_core_send(handle, (void *)body, pktsz, 2.0f); + if (ret < 0) { + ret = -EFAULT; + break; } - DbgFree(body); + offset += body->size; + } + + DbgFree(body); errout: - (void)buffer_handler_raw_close(buffer); - return ret; + (void)buffer_handler_raw_close(buffer); + return ret; } static void *push_main(void *data) { - fd_set set; - int ret; - char ch; - struct request_item *item; - int conn_fd; - send_data_func_t send_data[] = { - send_file, - send_buffer, - send_buffer, - }; - - while (1) { - FD_ZERO(&set); - FD_SET(s_info.request_pipe[PIPE_READ], &set); - - ret = select(s_info.request_pipe[PIPE_READ] + 1, &set, NULL, NULL, NULL); - if (ret < 0) { - ret = -errno; - if (errno == EINTR) { - ErrPrint("INTERRUPTED\n"); - ret = 0; - continue; - } - ErrPrint("Error: %s\n", strerror(errno)); - break; - } else if (ret == 0) { - ErrPrint("Timeout\n"); - ret = -ETIMEDOUT; - break; - } - - if (!FD_ISSET(s_info.request_pipe[PIPE_READ], &set)) { - DbgPrint("Unknown data\n"); - ret = -EINVAL; - break; - } + fd_set set; + int ret; + char ch; + struct request_item *item; + int conn_fd; + send_data_func_t send_data[] = { + send_file, + send_buffer, + send_buffer, + }; + + while (1) { + FD_ZERO(&set); + FD_SET(s_info.request_pipe[PIPE_READ], &set); + + ret = select(s_info.request_pipe[PIPE_READ] + 1, &set, NULL, NULL, NULL); + if (ret < 0) { + ret = -errno; + if (errno == EINTR) { + ErrPrint("INTERRUPTED\n"); + ret = 0; + continue; + } + ErrPrint("Error: %s\n", strerror(errno)); + break; + } else if (ret == 0) { + ErrPrint("Timeout\n"); + ret = -ETIMEDOUT; + break; + } - ret = read(s_info.request_pipe[PIPE_READ], &ch, sizeof(ch)); - if (ret != sizeof(ch)) { - ErrPrint("read: %s\n", strerror(errno)); - ret = -EFAULT; - break; - } + if (!FD_ISSET(s_info.request_pipe[PIPE_READ], &set)) { + DbgPrint("Unknown data\n"); + ret = -EINVAL; + break; + } - if (ch == PUSH_EXIT) { - DbgPrint("Thread is terminating\n"); - ret = -ECANCELED; - break; - } + ret = read(s_info.request_pipe[PIPE_READ], &ch, sizeof(ch)); + if (ret != sizeof(ch)) { + ErrPrint("read: %s\n", strerror(errno)); + ret = -EFAULT; + break; + } - CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); - item = eina_list_nth(s_info.request_list, 0); - s_info.request_list = eina_list_remove(s_info.request_list, item); - CRITICAL_SECTION_END(&s_info.request_list_lock); + if (ch == PUSH_EXIT) { + DbgPrint("Thread is terminating\n"); + ret = -ECANCELED; + break; + } - if (!item) { - ErrPrint("Request item is not valid\n"); - continue; - } + CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); + item = eina_list_nth(s_info.request_list, 0); + s_info.request_list = eina_list_remove(s_info.request_list, item); + CRITICAL_SECTION_END(&s_info.request_list_lock); - /* Validate the TCB? */ - conn_fd = tcb_is_valid(s_info.svc_ctx, item->tcb); - if (conn_fd < 0) { - ErrPrint("TCB is not valid\n"); - destroy_request_item(item); - continue; - } + if (!item) { + ErrPrint("Request item is not valid\n"); + continue; + } - /* - * \note - * From now, we cannot believe the conn_fd. - * It can be closed any time. - * Even though we using it. - */ - if (item->type < REQUEST_TYPE_MAX && item->type >= 0) { - (void)send_data[item->type](conn_fd, item); - } else { - ErrPrint("Invalid type\n"); - } + /* Validate the TCB? */ + conn_fd = tcb_is_valid(s_info.svc_ctx, item->tcb); + if (conn_fd < 0) { + ErrPrint("TCB is not valid\n"); + destroy_request_item(item); + continue; + } - destroy_request_item(item); + /* + * \note + * From now, we cannot believe the conn_fd. + * It can be closed any time. + * Even though we using it. + */ + if (item->type < REQUEST_TYPE_MAX && item->type >= 0) { + (void)send_data[item->type](conn_fd, item); + } else { + ErrPrint("Invalid type\n"); } - return (void *)ret; + destroy_request_item(item); + } + + return (void *)ret; } /* MAIN THREAD */ int file_service_init(void) { - int status; + int status; - if (s_info.svc_ctx) { - ErrPrint("Already initialized\n"); - return DBOX_STATUS_ERROR_ALREADY; - } + if (s_info.svc_ctx) { + ErrPrint("Already initialized\n"); + return DBOX_STATUS_ERROR_ALREADY; + } - if (pipe2(s_info.request_pipe, O_CLOEXEC) < 0) { - ErrPrint("pipe: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } + if (pipe2(s_info.request_pipe, O_CLOEXEC) < 0) { + ErrPrint("pipe: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } - status = pthread_mutex_init(&s_info.request_list_lock, NULL); - if (status != 0) { - ErrPrint("Failed to create lock: %s\n", strerror(status)); - CLOSE_PIPE(s_info.request_pipe); - return DBOX_STATUS_ERROR_FAULT; - } - - s_info.svc_ctx = service_common_create(FILE_SERVICE_ADDR, service_thread_main, NULL); - if (!s_info.svc_ctx) { - ErrPrint("Unable to activate service thread\n"); + status = pthread_mutex_init(&s_info.request_list_lock, NULL); + if (status != 0) { + ErrPrint("Failed to create lock: %s\n", strerror(status)); + CLOSE_PIPE(s_info.request_pipe); + return DBOX_STATUS_ERROR_FAULT; + } - status = pthread_mutex_destroy(&s_info.request_list_lock); - if (status != 0) { - ErrPrint("Destroy lock: %s\n", strerror(status)); - } + s_info.svc_ctx = service_common_create(FILE_SERVICE_ADDR, service_thread_main, NULL); + if (!s_info.svc_ctx) { + ErrPrint("Unable to activate service thread\n"); - CLOSE_PIPE(s_info.request_pipe); - return DBOX_STATUS_ERROR_FAULT; + status = pthread_mutex_destroy(&s_info.request_list_lock); + if (status != 0) { + ErrPrint("Destroy lock: %s\n", strerror(status)); } - status = pthread_create(&s_info.push_thid, NULL, push_main, NULL); - if (status != 0) { - ErrPrint("Failed to create a push service: %s\n", strerror(status)); + CLOSE_PIPE(s_info.request_pipe); + return DBOX_STATUS_ERROR_FAULT; + } - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; + status = pthread_create(&s_info.push_thid, NULL, push_main, NULL); + if (status != 0) { + ErrPrint("Failed to create a push service: %s\n", strerror(status)); - status = pthread_mutex_destroy(&s_info.request_list_lock); - if (status != 0) { - ErrPrint("Destroy lock: %s\n", strerror(status)); - } + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; - CLOSE_PIPE(s_info.request_pipe); - return DBOX_STATUS_ERROR_FAULT; + status = pthread_mutex_destroy(&s_info.request_list_lock); + if (status != 0) { + ErrPrint("Destroy lock: %s\n", strerror(status)); } - /*! - * \note - * Remote service doesn't need to set the additional SMAK label. - */ + CLOSE_PIPE(s_info.request_pipe); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("Successfully initiated\n"); - return DBOX_STATUS_ERROR_NONE; + /*! + * \note + * Remote service doesn't need to set the additional SMAK label. + */ + + DbgPrint("Successfully initiated\n"); + return DBOX_STATUS_ERROR_NONE; } /* MAIN THREAD */ int file_service_fini(void) { - struct request_item *item; - int status; - char ch; - void *retval; - - if (!s_info.svc_ctx) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - ch = PUSH_EXIT; - status = write(s_info.request_pipe[PIPE_WRITE], &ch, sizeof(ch)); - if (status != sizeof(ch)) { - ErrPrint("write: %s\n", strerror(errno)); - /* Forcely terminate the thread */ - status = pthread_cancel(s_info.push_thid); - if (status != 0) { - ErrPrint("cancel: %s\n", strerror(status)); - } - } - - status = pthread_join(s_info.push_thid, &retval); + struct request_item *item; + int status; + char ch; + void *retval; + + if (!s_info.svc_ctx) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ch = PUSH_EXIT; + status = write(s_info.request_pipe[PIPE_WRITE], &ch, sizeof(ch)); + if (status != sizeof(ch)) { + ErrPrint("write: %s\n", strerror(errno)); + /* Forcely terminate the thread */ + status = pthread_cancel(s_info.push_thid); if (status != 0) { - ErrPrint("join: %s\n", strerror(status)); + ErrPrint("cancel: %s\n", strerror(status)); } + } - CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); - EINA_LIST_FREE(s_info.request_list, item) { - destroy_request_item(item); - } - CRITICAL_SECTION_END(&s_info.request_list_lock); + status = pthread_join(s_info.push_thid, &retval); + if (status != 0) { + ErrPrint("join: %s\n", strerror(status)); + } - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; + CRITICAL_SECTION_BEGIN(&s_info.request_list_lock); + EINA_LIST_FREE(s_info.request_list, item) { + destroy_request_item(item); + } + CRITICAL_SECTION_END(&s_info.request_list_lock); - status = pthread_mutex_destroy(&s_info.request_list_lock); - if (status != 0) { - ErrPrint("destroy mutex: %s\n", strerror(status)); - } + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; - CLOSE_PIPE(s_info.request_pipe); + status = pthread_mutex_destroy(&s_info.request_list_lock); + if (status != 0) { + ErrPrint("destroy mutex: %s\n", strerror(status)); + } - DbgPrint("Successfully Finalized\n"); - return DBOX_STATUS_ERROR_NONE; + CLOSE_PIPE(s_info.request_pipe); + + DbgPrint("Successfully Finalized\n"); + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/group.c b/src/group.c index 21627cf..d75a3ed 100644 --- a/src/group.c +++ b/src/group.c @@ -32,858 +32,858 @@ int errno; static struct info { - Eina_List *cluster_list; + Eina_List *cluster_list; } s_info = { - .cluster_list = NULL, + .cluster_list = NULL, }; struct cluster { - char *name; - Eina_List *category_list; + char *name; + Eina_List *category_list; }; struct category { - char *name; - struct cluster *cluster; - Eina_List *info_list; /* list of instances of the struct inst_info */ + char *name; + struct cluster *cluster; + Eina_List *info_list; /* list of instances of the struct inst_info */ }; struct context_info { - char *pkgname; - struct category *category; - Eina_List *context_list; /* context item list */ + char *pkgname; + struct category *category; + Eina_List *context_list; /* context item list */ }; struct context_item_data { - char *tag; - void *data; + char *tag; + void *data; }; struct context_item { - char *ctx_item; - struct context_info *info; - Eina_List *option_list; - Eina_List *data_list; + char *ctx_item; + struct context_info *info; + Eina_List *option_list; + Eina_List *data_list; }; struct context_option { - struct context_item *item; - char *key; - char *value; + struct context_item *item; + char *key; + char *value; }; HAPI struct context_info *group_create_context_info(struct category *category, const char *pkgname) { - struct context_info *info; + struct context_info *info; - info = calloc(1, sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + info = calloc(1, sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - info->pkgname = strdup(pkgname); - if (!info->pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info); - return NULL; - } + info->pkgname = strdup(pkgname); + if (!info->pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info); + return NULL; + } - info->category = category; - category->info_list = eina_list_append(category->info_list, info); - return info; + info->category = category; + category->info_list = eina_list_append(category->info_list, info); + return info; } static inline void del_options(struct context_item *item) { - struct context_option *option; + struct context_option *option; - EINA_LIST_FREE(item->option_list, option) { - DbgFree(option->key); - DbgFree(option->value); - DbgFree(option); - } + EINA_LIST_FREE(item->option_list, option) { + DbgFree(option->key); + DbgFree(option->value); + DbgFree(option); + } } static inline void del_context_item(struct context_info *info) { - struct context_item *item; + struct context_item *item; - EINA_LIST_FREE(info->context_list, item) { - del_options(item); - DbgFree(item->ctx_item); - DbgFree(item); - } + EINA_LIST_FREE(info->context_list, item) { + del_options(item); + DbgFree(item->ctx_item); + DbgFree(item); + } } HAPI struct context_item *group_add_context_item(struct context_info *info, const char *ctx_item) { - struct context_item *item; + struct context_item *item; - item = calloc(1, sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + item = calloc(1, sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - item->ctx_item = strdup(ctx_item); - if (!item->ctx_item) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item); - return NULL; - } + item->ctx_item = strdup(ctx_item); + if (!item->ctx_item) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item); + return NULL; + } - item->info = info; - info->context_list = eina_list_append(info->context_list, item); - return item; + item->info = info; + info->context_list = eina_list_append(info->context_list, item); + return item; } HAPI int group_add_option(struct context_item *item, const char *key, const char *value) { - struct context_option *option; + struct context_option *option; - option = calloc(1, sizeof(*option)); - if (!option) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + option = calloc(1, sizeof(*option)); + if (!option) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - option->key = strdup(key); - if (!option->key) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(option); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + option->key = strdup(key); + if (!option->key) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(option); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - option->value = strdup(value); - if (!option->value) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(option->key); - DbgFree(option); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + option->value = strdup(value); + if (!option->value) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(option->key); + DbgFree(option); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - option->item = item; - item->option_list = eina_list_append(item->option_list, option); - return DBOX_STATUS_ERROR_NONE; + option->item = item; + item->option_list = eina_list_append(item->option_list, option); + return DBOX_STATUS_ERROR_NONE; } HAPI int group_destroy_context_info(struct context_info *info) { - struct category *category; + struct category *category; - category = info->category; - if (!category) { - ErrPrint("No category found\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + category = info->category; + if (!category) { + ErrPrint("No category found\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - category->info_list = eina_list_remove(category->info_list, info); + category->info_list = eina_list_remove(category->info_list, info); - del_context_item(info); - DbgFree(info->pkgname); - DbgFree(info); - return DBOX_STATUS_ERROR_NONE; + del_context_item(info); + DbgFree(info->pkgname); + DbgFree(info); + return DBOX_STATUS_ERROR_NONE; } HAPI struct cluster *group_create_cluster(const char *name) { - struct cluster *cluster; + struct cluster *cluster; - cluster = malloc(sizeof(*cluster)); - if (!cluster) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + cluster = malloc(sizeof(*cluster)); + if (!cluster) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - cluster->name = strdup(name); - if (!cluster->name) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(cluster); - return NULL; - } + cluster->name = strdup(name); + if (!cluster->name) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(cluster); + return NULL; + } - cluster->category_list = NULL; + cluster->category_list = NULL; - s_info.cluster_list = eina_list_append(s_info.cluster_list, cluster); - return cluster; + s_info.cluster_list = eina_list_append(s_info.cluster_list, cluster); + return cluster; } HAPI struct cluster *group_find_cluster(const char *name) { - Eina_List *l; - struct cluster *cluster; + Eina_List *l; + struct cluster *cluster; - EINA_LIST_FOREACH(s_info.cluster_list, l, cluster) { - if (!strcasecmp(cluster->name, name)) { - return cluster; - } + EINA_LIST_FOREACH(s_info.cluster_list, l, cluster) { + if (!strcasecmp(cluster->name, name)) { + return cluster; } + } - return NULL; + return NULL; } HAPI struct category *group_create_category(struct cluster *cluster, const char *name) { - struct category *category; + struct category *category; - category = malloc(sizeof(*category)); - if (!category) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + category = malloc(sizeof(*category)); + if (!category) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - category->name = strdup(name); - if (!category->name) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(category); - return NULL; - } + category->name = strdup(name); + if (!category->name) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(category); + return NULL; + } - category->cluster = cluster; - category->info_list = NULL; + category->cluster = cluster; + category->info_list = NULL; - cluster->category_list = eina_list_append(cluster->category_list, category); - return category; + cluster->category_list = eina_list_append(cluster->category_list, category); + return category; } static inline void destroy_cluster(struct cluster *cluster) { - struct category *category; - Eina_List *l; - Eina_List *n; + struct category *category; + Eina_List *l; + Eina_List *n; - EINA_LIST_FOREACH_SAFE(cluster->category_list, l, n, category) { - group_destroy_category(category); - } + EINA_LIST_FOREACH_SAFE(cluster->category_list, l, n, category) { + group_destroy_category(category); + } - DbgFree(cluster->name); - DbgFree(cluster); + DbgFree(cluster->name); + DbgFree(cluster); } HAPI int group_destroy_cluster(struct cluster *cluster) { - Eina_List *l; - Eina_List *n; - struct cluster *item; + Eina_List *l; + Eina_List *n; + struct cluster *item; - EINA_LIST_FOREACH_SAFE(s_info.cluster_list, l, n, item) { - if (item == cluster) { - s_info.cluster_list = eina_list_remove_list(s_info.cluster_list, l); - destroy_cluster(cluster); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.cluster_list, l, n, item) { + if (item == cluster) { + s_info.cluster_list = eina_list_remove_list(s_info.cluster_list, l); + destroy_cluster(cluster); + return DBOX_STATUS_ERROR_NONE; } + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } static inline void destroy_category(struct category *category) { - Eina_List *l; - Eina_List *n; - struct context_info *info; + Eina_List *l; + Eina_List *n; + struct context_info *info; - EINA_LIST_FOREACH_SAFE(category->info_list, l, n, info) { - group_destroy_context_info(info); - } + EINA_LIST_FOREACH_SAFE(category->info_list, l, n, info) { + group_destroy_context_info(info); + } - DbgFree(category->name); - DbgFree(category); + DbgFree(category->name); + DbgFree(category); } HAPI int group_destroy_category(struct category *category) { - struct cluster *cluster; + struct cluster *cluster; - cluster = category->cluster; - if (cluster) { - cluster->category_list = eina_list_remove(cluster->category_list, category); - } + cluster = category->cluster; + if (cluster) { + cluster->category_list = eina_list_remove(cluster->category_list, category); + } - destroy_category(category); - return DBOX_STATUS_ERROR_NONE; + destroy_category(category); + return DBOX_STATUS_ERROR_NONE; } HAPI struct category *group_find_category(struct cluster *cluster, const char *name) { - struct category *category; - Eina_List *l; + struct category *category; + Eina_List *l; - EINA_LIST_FOREACH(cluster->category_list, l, category) { - if (!strcasecmp(category->name, name)) { - return category; - } + EINA_LIST_FOREACH(cluster->category_list, l, category) { + if (!strcasecmp(category->name, name)) { + return category; } + } - return NULL; + return NULL; } HAPI Eina_List * const group_context_info_list(struct category *category) { - return category->info_list; + return category->info_list; } HAPI Eina_List *const group_context_item_list(struct context_info *info) { - return info->context_list; + return info->context_list; } HAPI Eina_List *const group_context_option_list(struct context_item *item) { - return item->option_list; + return item->option_list; } HAPI Eina_List *const group_cluster_list(void) { - return s_info.cluster_list; + return s_info.cluster_list; } HAPI Eina_List * const group_category_list(struct cluster *cluster) { - return cluster->category_list; + return cluster->category_list; } HAPI struct context_info * const group_context_info_from_item(struct context_item *item) { - return item->info; + return item->info; } HAPI struct category * const group_category_from_context_info(struct context_info *info) { - return info->category; + return info->category; } HAPI const char * const group_pkgname_from_context_info(struct context_info *info) { - return info->pkgname; + return info->pkgname; } HAPI const char * const group_option_item_key(struct context_option *option) { - return option->key; + return option->key; } HAPI const char * const group_option_item_value(struct context_option *option) { - return option->value; + return option->value; } HAPI const char * const group_context_item(struct context_item *item) { - return item->ctx_item; + return item->ctx_item; } HAPI int group_context_item_add_data(struct context_item *item, const char *tag, void *data) { - struct context_item_data *tmp; + struct context_item_data *tmp; - tmp = malloc(sizeof(*tmp)); - if (!tmp) { - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = malloc(sizeof(*tmp)); + if (!tmp) { + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - tmp->tag = strdup(tag); - if (!tmp->tag) { - DbgFree(tmp); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp->tag = strdup(tag); + if (!tmp->tag) { + DbgFree(tmp); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - tmp->data = data; - item->data_list = eina_list_append(item->data_list, tmp); - return DBOX_STATUS_ERROR_NONE; + tmp->data = data; + item->data_list = eina_list_append(item->data_list, tmp); + return DBOX_STATUS_ERROR_NONE; } HAPI void *group_context_item_data(struct context_item *item, const char *tag) { - struct context_item_data *tmp; - Eina_List *l; + struct context_item_data *tmp; + Eina_List *l; - EINA_LIST_FOREACH(item->data_list, l, tmp) { - if (!strcmp(tmp->tag, tag)) { - return tmp->data; - } + EINA_LIST_FOREACH(item->data_list, l, tmp) { + if (!strcmp(tmp->tag, tag)) { + return tmp->data; } + } - return NULL; + return NULL; } HAPI void *group_context_item_del_data(struct context_item *item, const char *tag) { - struct context_item_data *tmp; - Eina_List *l; - Eina_List *n; + struct context_item_data *tmp; + Eina_List *l; + Eina_List *n; - EINA_LIST_FOREACH_SAFE(item->data_list, l, n, tmp) { - if (!strcmp(tmp->tag, tag)) { - void *data; + EINA_LIST_FOREACH_SAFE(item->data_list, l, n, tmp) { + if (!strcmp(tmp->tag, tag)) { + void *data; - item->data_list = eina_list_remove(item->data_list, tmp); + item->data_list = eina_list_remove(item->data_list, tmp); - data = tmp->data; + data = tmp->data; - DbgFree(tmp->tag); - DbgFree(tmp); + DbgFree(tmp->tag); + DbgFree(tmp); - return data; - } + return data; } + } - return NULL; + return NULL; } HAPI const char * const group_category_name(struct category *category) { - return category ? category->name : NULL; + return category ? category->name : NULL; } HAPI const char * const group_cluster_name(struct cluster *cluster) { - return cluster ? cluster->name : NULL; + return cluster ? cluster->name : NULL; } HAPI const char *group_cluster_name_by_category(struct category *category) { - return !category ? NULL : (category->cluster ? category->cluster->name : NULL); + return !category ? NULL : (category->cluster ? category->cluster->name : NULL); } static inline char *get_token(char *ptr, int *len) { - char *name; - int _len; + char *name; + int _len; - if (*len == 0) { - ErrPrint("Start brace but len = 0\n"); - return NULL; - } + if (*len == 0) { + ErrPrint("Start brace but len = 0\n"); + return NULL; + } - _len = *len; + _len = *len; - while (_len > 0 && isspace(ptr[_len])) { - _len--; - } + while (_len > 0 && isspace(ptr[_len])) { + _len--; + } - if (_len == 0) { - ErrPrint("Token has no string\n"); - return NULL; - } + if (_len == 0) { + ErrPrint("Token has no string\n"); + return NULL; + } - name = malloc(_len + 1); - if (!name) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + name = malloc(_len + 1); + if (!name) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - strncpy(name, ptr - *len, _len); - name[_len] = '\0'; + strncpy(name, ptr - *len, _len); + name[_len] = '\0'; - *len = _len; - return name; + *len = _len; + return name; } HAPI int group_add_dynamicbox(const char *group, const char *pkgname) { - struct cluster *cluster; - struct category *category; - struct context_info *info = NULL; - struct context_item *item = NULL; - char *key; - char *name; - char *ptr; - int len; - int is_open = 0; - enum { - CLUSTER, - CATEGORY, - CONTEXT_ITEM, - CONTEXT_OPTION_KEY, - CONTEXT_OPTION_VALUE, - CONTEXT_ERROR = 0xFFFFFFFF - } state; - - state = CLUSTER; - - ptr = (char *)group; - len = 0; - key = NULL; - - /* Skip the first space characters */ - while (*ptr && isspace(*ptr)) ptr++; - - cluster = NULL; - while (*ptr) { - if (*ptr == '{') { - name = get_token(ptr, &len); - if (!name) { - ErrPrint("Failed to get token\n"); - return DBOX_STATUS_ERROR_FAULT; - } - /* cluster{category{context{key=value,key=value},context{key=value}}} */ - /* cluster{category} */ - - switch (state) { - case CLUSTER: - cluster = group_find_cluster(name); - if (!cluster) { - cluster = group_create_cluster(name); - } - - if (!cluster) { - ErrPrint("Failed to get cluster\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CATEGORY; - break; - - case CATEGORY: - category = group_find_category(cluster, name); - if (!category) { - category = group_create_category(cluster, name); - } - - if (!category) { - ErrPrint("Failed to get category\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - info = group_create_context_info(category, pkgname); - if (!info) { - ErrPrint("Failed to create ctx info\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CONTEXT_ITEM; - break; - - case CONTEXT_ITEM: - item = group_add_context_item(info, name); - if (!item) { - ErrPrint("Failed to create a context item\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CONTEXT_OPTION_KEY; - break; - - case CONTEXT_OPTION_KEY: - case CONTEXT_OPTION_VALUE: - default: - ErrPrint("Invalid state\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } + struct cluster *cluster; + struct category *category; + struct context_info *info = NULL; + struct context_item *item = NULL; + char *key; + char *name; + char *ptr; + int len; + int is_open = 0; + enum { + CLUSTER, + CATEGORY, + CONTEXT_ITEM, + CONTEXT_OPTION_KEY, + CONTEXT_OPTION_VALUE, + CONTEXT_ERROR = 0xFFFFFFFF + } state; + + state = CLUSTER; + + ptr = (char *)group; + len = 0; + key = NULL; + + /* Skip the first space characters */ + while (*ptr && isspace(*ptr)) ptr++; + + cluster = NULL; + while (*ptr) { + if (*ptr == '{') { + name = get_token(ptr, &len); + if (!name) { + ErrPrint("Failed to get token\n"); + return DBOX_STATUS_ERROR_FAULT; + } + /* cluster{category{context{key=value,key=value},context{key=value}}} */ + /* cluster{category} */ + + switch (state) { + case CLUSTER: + cluster = group_find_cluster(name); + if (!cluster) { + cluster = group_create_cluster(name); + } + + if (!cluster) { + ErrPrint("Failed to get cluster\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CATEGORY; + break; + case CATEGORY: + category = group_find_category(cluster, name); + if (!category) { + category = group_create_category(cluster, name); + } + + if (!category) { + ErrPrint("Failed to get category\n"); DbgFree(name); - is_open++; - len = 0; - ptr++; - while (*ptr && isspace(*ptr)) ptr++; - continue; - } else if (*ptr == ',') { - name = get_token(ptr, &len); - if (!name) { - ErrPrint("Failed to get token (len:%d)\n", len); - len = 0; - ptr++; - while (*ptr && isspace(*ptr)) ptr++; - continue; - } + return DBOX_STATUS_ERROR_FAULT; + } - switch (state) { - case CLUSTER: - if (is_open != 0) { - ErrPrint("Invalid state\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - cluster = group_find_cluster(name); - if (!cluster) { - cluster = group_create_cluster(name); - } - - if (!cluster) { - ErrPrint("Failed to get cluster\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CATEGORY; - break; - - case CATEGORY: - if (is_open != 1) { - ErrPrint("Invalid state\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - category = group_find_category(cluster, name); - if (!category) { - category = group_create_category(cluster, name); - } - - if (!category) { - ErrPrint("Failed to get category\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - info = group_create_context_info(category, pkgname); - if (!info) { - ErrPrint("Failed to create ctx info\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CONTEXT_ITEM; - break; - case CONTEXT_ITEM: - if (is_open == 1) { - category = group_find_category(cluster, name); - if (!category) { - category = group_create_category(cluster, name); - } - - if (!category) { - ErrPrint("Failed to get category\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - info = group_create_context_info(category, pkgname); - if (!info) { - ErrPrint("Failed to create ctx info\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - } else if (is_open == 2) { - item = group_add_context_item(info, name); - if (!item) { - ErrPrint("Failed to create a context item\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - state = CONTEXT_OPTION_KEY; - } else { - ErrPrint("Invalid state\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - break; - case CONTEXT_OPTION_VALUE: - if (is_open != 3) { - ErrPrint("Invalid state\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - if (group_add_option(item, key, name) < 0) { - ErrPrint("Failed to add a new option: %s - %s\n", key, name); - } - - DbgFree(key); - key = NULL; - - state = CONTEXT_OPTION_KEY; - break; - case CONTEXT_OPTION_KEY: - default: - ErrPrint("Invalid state (%s)\n", name); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } + info = group_create_context_info(category, pkgname); + if (!info) { + ErrPrint("Failed to create ctx info\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CONTEXT_ITEM; + break; + + case CONTEXT_ITEM: + item = group_add_context_item(info, name); + if (!item) { + ErrPrint("Failed to create a context item\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CONTEXT_OPTION_KEY; + break; + + case CONTEXT_OPTION_KEY: + case CONTEXT_OPTION_VALUE: + default: + ErrPrint("Invalid state\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + DbgFree(name); + is_open++; + len = 0; + ptr++; + while (*ptr && isspace(*ptr)) ptr++; + continue; + } else if (*ptr == ',') { + name = get_token(ptr, &len); + if (!name) { + ErrPrint("Failed to get token (len:%d)\n", len); + len = 0; + ptr++; + while (*ptr && isspace(*ptr)) ptr++; + continue; + } + + switch (state) { + case CLUSTER: + if (is_open != 0) { + ErrPrint("Invalid state\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + cluster = group_find_cluster(name); + if (!cluster) { + cluster = group_create_cluster(name); + } + + if (!cluster) { + ErrPrint("Failed to get cluster\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CATEGORY; + break; + + case CATEGORY: + if (is_open != 1) { + ErrPrint("Invalid state\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + category = group_find_category(cluster, name); + if (!category) { + category = group_create_category(cluster, name); + } + + if (!category) { + ErrPrint("Failed to get category\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + info = group_create_context_info(category, pkgname); + if (!info) { + ErrPrint("Failed to create ctx info\n"); DbgFree(name); - len = 0; - ptr++; - while (*ptr && isspace(*ptr)) ptr++; - continue; - } else if (*ptr == '=') { - if (is_open != 3 || state != CONTEXT_OPTION_KEY) { - ErrPrint("Invalid state\n"); - return DBOX_STATUS_ERROR_FAULT; + return DBOX_STATUS_ERROR_FAULT; + } + + state = CONTEXT_ITEM; + break; + case CONTEXT_ITEM: + if (is_open == 1) { + category = group_find_category(cluster, name); + if (!category) { + category = group_create_category(cluster, name); } - key = get_token(ptr, &len); - if (!key) { - ErrPrint("Failed to get token\n"); - return DBOX_STATUS_ERROR_FAULT; + if (!category) { + ErrPrint("Failed to get category\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; } - state = CONTEXT_OPTION_VALUE; - len = 0; - ptr++; - while (*ptr && isspace(*ptr)) ptr++; - continue; - } else if (*ptr == '}') { - if (is_open <= 0) { - ErrPrint("Invalid state\n"); - return DBOX_STATUS_ERROR_FAULT; + info = group_create_context_info(category, pkgname); + if (!info) { + ErrPrint("Failed to create ctx info\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + } else if (is_open == 2) { + item = group_add_context_item(info, name); + if (!item) { + ErrPrint("Failed to create a context item\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; } + state = CONTEXT_OPTION_KEY; + } else { + ErrPrint("Invalid state\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } - name = get_token(ptr, &len); - if (!name) { - ErrPrint("Failed to get token, len:%d\n", len); - is_open--; - len = 0; - ptr++; - while (*ptr && isspace(*ptr)) ptr++; - continue; + break; + case CONTEXT_OPTION_VALUE: + if (is_open != 3) { + ErrPrint("Invalid state\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + if (group_add_option(item, key, name) < 0) { + ErrPrint("Failed to add a new option: %s - %s\n", key, name); + } + + DbgFree(key); + key = NULL; + + state = CONTEXT_OPTION_KEY; + break; + case CONTEXT_OPTION_KEY: + default: + ErrPrint("Invalid state (%s)\n", name); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + DbgFree(name); + len = 0; + ptr++; + while (*ptr && isspace(*ptr)) ptr++; + continue; + } else if (*ptr == '=') { + if (is_open != 3 || state != CONTEXT_OPTION_KEY) { + ErrPrint("Invalid state\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + key = get_token(ptr, &len); + if (!key) { + ErrPrint("Failed to get token\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CONTEXT_OPTION_VALUE; + len = 0; + ptr++; + while (*ptr && isspace(*ptr)) ptr++; + continue; + } else if (*ptr == '}') { + if (is_open <= 0) { + ErrPrint("Invalid state\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + name = get_token(ptr, &len); + if (!name) { + ErrPrint("Failed to get token, len:%d\n", len); + is_open--; + len = 0; + ptr++; + while (*ptr && isspace(*ptr)) ptr++; + continue; + } + + switch (state) { + case CATEGORY: + category = group_find_category(cluster, name); + if (!category) { + category = group_create_category(cluster, name); + } + + if (!category) { + ErrPrint("Failed to get category\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + info = group_create_context_info(category, pkgname); + if (!info) { + ErrPrint("Failed to create ctx info\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CLUSTER; + break; + case CONTEXT_ITEM: + if (is_open == 1) { + category = group_find_category(cluster, name); + if (!category) { + category = group_create_category(cluster, name); } - switch (state) { - case CATEGORY: - category = group_find_category(cluster, name); - if (!category) { - category = group_create_category(cluster, name); - } - - if (!category) { - ErrPrint("Failed to get category\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - info = group_create_context_info(category, pkgname); - if (!info) { - ErrPrint("Failed to create ctx info\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CLUSTER; - break; - case CONTEXT_ITEM: - if (is_open == 1) { - category = group_find_category(cluster, name); - if (!category) { - category = group_create_category(cluster, name); - } - - if (!category) { - ErrPrint("Failed to get category\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - info = group_create_context_info(category, pkgname); - if (!info) { - ErrPrint("Failed to create ctx info\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - state = CLUSTER; - } else if (is_open == 2) { - state = CATEGORY; - } else { - ErrPrint("Invalid state\n"); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - break; - case CONTEXT_OPTION_VALUE: - if (is_open != 2) { - ErrPrint("Invalid state (%s)\n", name); - DbgFree(name); - return DBOX_STATUS_ERROR_FAULT; - } - - if (group_add_option(item, key, name) < 0) { - ErrPrint("Failed to add a new option: %s - %s\n", key, name); - } - - DbgFree(key); - key = NULL; - - state = CONTEXT_ITEM; - break; - case CONTEXT_OPTION_KEY: - case CLUSTER: - default: - ErrPrint("Invalid state (%s)\n", name); - break; + if (!category) { + ErrPrint("Failed to get category\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; } + info = group_create_context_info(category, pkgname); + if (!info) { + ErrPrint("Failed to create ctx info\n"); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } + + state = CLUSTER; + } else if (is_open == 2) { + state = CATEGORY; + } else { + ErrPrint("Invalid state\n"); DbgFree(name); - is_open--; - len = 0; - ptr++; - while (*ptr && isspace(*ptr)) ptr++; - continue; - } + return DBOX_STATUS_ERROR_FAULT; + } + break; + case CONTEXT_OPTION_VALUE: + if (is_open != 2) { + ErrPrint("Invalid state (%s)\n", name); + DbgFree(name); + return DBOX_STATUS_ERROR_FAULT; + } - len++; - ptr++; - } + if (group_add_option(item, key, name) < 0) { + ErrPrint("Failed to add a new option: %s - %s\n", key, name); + } - /* If some cases, the key is not released, try release it, doesn't need to check NULL */ - DbgFree(key); + DbgFree(key); + key = NULL; - if (state != CLUSTER) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + state = CONTEXT_ITEM; + break; + case CONTEXT_OPTION_KEY: + case CLUSTER: + default: + ErrPrint("Invalid state (%s)\n", name); + break; + } + + DbgFree(name); + is_open--; + len = 0; + ptr++; + while (*ptr && isspace(*ptr)) ptr++; + continue; } - return DBOX_STATUS_ERROR_NONE; + len++; + ptr++; + } + + /* If some cases, the key is not released, try release it, doesn't need to check NULL */ + DbgFree(key); + + if (state != CLUSTER) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int group_del_dynamicbox(const char *pkgname) { - Eina_List *l; - Eina_List *n; - Eina_List *s_l; - Eina_List *s_n; - Eina_List *i_l; - Eina_List *i_n; - struct cluster *cluster; - struct category *category; - struct context_info *info; - - EINA_LIST_FOREACH_SAFE(s_info.cluster_list, l, n, cluster) { - EINA_LIST_FOREACH_SAFE(cluster->category_list, s_l, s_n, category) { - EINA_LIST_FOREACH_SAFE(category->info_list, i_l, i_n, info) { - if (!strcmp(pkgname, info->pkgname)) { - group_destroy_context_info(info); - } - } - - if (!category->info_list) { - group_destroy_category(category); - } + Eina_List *l; + Eina_List *n; + Eina_List *s_l; + Eina_List *s_n; + Eina_List *i_l; + Eina_List *i_n; + struct cluster *cluster; + struct category *category; + struct context_info *info; + + EINA_LIST_FOREACH_SAFE(s_info.cluster_list, l, n, cluster) { + EINA_LIST_FOREACH_SAFE(cluster->category_list, s_l, s_n, category) { + EINA_LIST_FOREACH_SAFE(category->info_list, i_l, i_n, info) { + if (!strcmp(pkgname, info->pkgname)) { + group_destroy_context_info(info); } + } - if (!cluster->category_list) { - group_destroy_cluster(cluster); - } + if (!category->info_list) { + group_destroy_category(category); + } } - return DBOX_STATUS_ERROR_NONE; + if (!cluster->category_list) { + group_destroy_cluster(cluster); + } + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int group_init(void) { - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int group_fini(void) { - struct cluster *cluster; - struct category *category; + struct cluster *cluster; + struct category *category; - EINA_LIST_FREE(s_info.cluster_list, cluster) { + EINA_LIST_FREE(s_info.cluster_list, cluster) { - EINA_LIST_FREE(cluster->category_list, category) { - destroy_category(category); - } - - destroy_cluster(cluster); + EINA_LIST_FREE(cluster->category_list, category) { + destroy_category(category); } - return DBOX_STATUS_ERROR_NONE; + + destroy_cluster(cluster); + } + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/io.c b/src/io.c index aeb0503..e87fa28 100644 --- a/src/io.c +++ b/src/io.c @@ -48,853 +48,853 @@ int errno; #define MAX_PKGNAME 512 static struct { - sqlite3 *handle; + sqlite3 *handle; } s_info = { - .handle = NULL, + .handle = NULL, }; static int load_abi_table(void) { - FILE *fp; - int ch; - int idx = 0; - int tag_id = 0; - enum { - INIT = 0x0, - GROUP = 0x1, - TAG = 0x02, - VALUE = 0x03, - ERROR = 0x05 - } state; - enum { - PKGNAME = 0x0, - }; - static const char *field[] = { - "package", - NULL, - }; - const char *ptr = NULL; - - char group[MAX_ABI + 1]; - char pkgname[MAX_PKGNAME + 1]; - - fp = fopen("/usr/share/"PACKAGE"/abi.ini", "rt"); - if (!fp) { - return DBOX_STATUS_ERROR_IO_ERROR; - } - - state = INIT; - while ((ch = getc(fp)) != EOF && state != ERROR) { - switch (state) { - case INIT: + FILE *fp; + int ch; + int idx = 0; + int tag_id = 0; + enum { + INIT = 0x0, + GROUP = 0x1, + TAG = 0x02, + VALUE = 0x03, + ERROR = 0x05 + } state; + enum { + PKGNAME = 0x0, + }; + static const char *field[] = { + "package", + NULL, + }; + const char *ptr = NULL; + + char group[MAX_ABI + 1]; + char pkgname[MAX_PKGNAME + 1]; + + fp = fopen("/usr/share/"PACKAGE"/abi.ini", "rt"); + if (!fp) { + return DBOX_STATUS_ERROR_IO_ERROR; + } + + state = INIT; + while ((ch = getc(fp)) != EOF && state != ERROR) { + switch (state) { + case INIT: + if (isspace(ch)) { + continue; + } + if (ch == '[') { + state = GROUP; + idx = 0; + } else { + state = ERROR; + } + break; + case GROUP: + if (ch == ']') { + if (idx == 0) { + state = ERROR; + } else { + group[idx] = '\0'; + state = TAG; + idx = 0; + ptr = NULL; + } + } else if (idx < MAX_ABI) { + group[idx++] = ch; + } else { + ErrPrint("Overflow\n"); + state = ERROR; + } + break; + case TAG: + if (ptr == NULL) { + if (idx == 0) { if (isspace(ch)) { - continue; + continue; } + + /* New group started */ if (ch == '[') { - state = GROUP; - idx = 0; - } else { - state = ERROR; - } - break; - case GROUP: - if (ch == ']') { - if (idx == 0) { - state = ERROR; - } else { - group[idx] = '\0'; - state = TAG; - idx = 0; - ptr = NULL; - } - } else if (idx < MAX_ABI) { - group[idx++] = ch; - } else { - ErrPrint("Overflow\n"); - state = ERROR; - } - break; - case TAG: - if (ptr == NULL) { - if (idx == 0) { - if (isspace(ch)) { - continue; - } - - /* New group started */ - if (ch == '[') { - ungetc(ch, fp); - state = INIT; - continue; - } - } - - ptr = field[idx]; + ungetc(ch, fp); + state = INIT; + continue; } + } - if (ptr == NULL) { - ErrPrint("unknown tag\n"); - state = ERROR; - continue; - } + ptr = field[idx]; + } - if (*ptr == '\0' && ch == '=') { - /* MATCHED */ - state = VALUE; - tag_id = idx; - idx = 0; - ptr = NULL; - } else if (*ptr == ch) { - ptr++; - } else { - ungetc(ch, fp); - ptr--; - while (ptr >= field[idx]) { - ungetc(*ptr, fp); - ptr--; - } - ptr = NULL; - idx++; - } - break; - case VALUE: - switch (tag_id) { - case PKGNAME: - if (idx == 0) { /* LTRIM */ - if (isspace(ch)) { - continue; - } - - pkgname[idx] = ch; - idx++; - } else if (isspace(ch)) { - int ret; - pkgname[idx] = '\0'; - - ret = abi_add_entry(group, pkgname); - if (ret != 0) { - ErrPrint("Failed to add %s for %s\n", pkgname, group); - } - - state = TAG; - idx = 0; - } else if (idx < MAX_PKGNAME) { - pkgname[idx] = ch; - idx++; - } else { - ErrPrint("Overflow\n"); - state = ERROR; - } - break; - default: - break; - } - break; - case ERROR: - default: - break; + if (ptr == NULL) { + ErrPrint("unknown tag\n"); + state = ERROR; + continue; } - } - if (state == VALUE) { + if (*ptr == '\0' && ch == '=') { + /* MATCHED */ + state = VALUE; + tag_id = idx; + idx = 0; + ptr = NULL; + } else if (*ptr == ch) { + ptr++; + } else { + ungetc(ch, fp); + ptr--; + while (ptr >= field[idx]) { + ungetc(*ptr, fp); + ptr--; + } + ptr = NULL; + idx++; + } + break; + case VALUE: switch (tag_id) { - case PKGNAME: - if (idx) { - int ret; - pkgname[idx] = '\0'; - ret = abi_add_entry(group, pkgname); - if (ret != 0) { - ErrPrint("Failed to add %s for %s\n", pkgname, group); - } + case PKGNAME: + if (idx == 0) { /* LTRIM */ + if (isspace(ch)) { + continue; + } + + pkgname[idx] = ch; + idx++; + } else if (isspace(ch)) { + int ret; + pkgname[idx] = '\0'; + + ret = abi_add_entry(group, pkgname); + if (ret != 0) { + ErrPrint("Failed to add %s for %s\n", pkgname, group); + } + + state = TAG; + idx = 0; + } else if (idx < MAX_PKGNAME) { + pkgname[idx] = ch; + idx++; + } else { + ErrPrint("Overflow\n"); + state = ERROR; } break; - default: + default: break; } + break; + case ERROR: + default: + break; + } + } + + if (state == VALUE) { + switch (tag_id) { + case PKGNAME: + if (idx) { + int ret; + pkgname[idx] = '\0'; + ret = abi_add_entry(group, pkgname); + if (ret != 0) { + ErrPrint("Failed to add %s for %s\n", pkgname, group); + } + } + break; + default: + break; } + } - if (fclose(fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_NONE; + if (fclose(fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_NONE; } static inline int build_client_info(struct pkg_info *info) { - static const char *dml = "SELECT auto_launch, gbar_size FROM client WHERE pkgid = ?"; - sqlite3_stmt *stmt; - int width; - int height; - int ret; - const char *tmp; - - ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - ret = sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Failed to bind a pkgname %s\n", package_name(info)); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + static const char *dml = "SELECT auto_launch, gbar_size FROM client WHERE pkgid = ?"; + sqlite3_stmt *stmt; + int width; + int height; + int ret; + const char *tmp; + + ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + ret = sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + ErrPrint("Failed to bind a pkgname %s\n", package_name(info)); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (sqlite3_step(stmt) != SQLITE_ROW) { - ErrPrint("%s has no records (%s)\n", package_name(info), sqlite3_errmsg(s_info.handle)); - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (sqlite3_step(stmt) != SQLITE_ROW) { + ErrPrint("%s has no records (%s)\n", package_name(info), sqlite3_errmsg(s_info.handle)); + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - package_set_auto_launch(info, (const char *)sqlite3_column_text(stmt, 0)); + package_set_auto_launch(info, (const char *)sqlite3_column_text(stmt, 0)); - tmp = (const char *)sqlite3_column_text(stmt, 1); - if (tmp && strlen(tmp)) { - if (sscanf(tmp, "%dx%d", &width, &height) != 2) { - ErrPrint("Failed to get GBAR width and Height (%s)\n", tmp); - } else { - package_set_gbar_width(info, width); - package_set_gbar_height(info, height); - } + tmp = (const char *)sqlite3_column_text(stmt, 1); + if (tmp && strlen(tmp)) { + if (sscanf(tmp, "%dx%d", &width, &height) != 2) { + ErrPrint("Failed to get GBAR width and Height (%s)\n", tmp); + } else { + package_set_gbar_width(info, width); + package_set_gbar_height(info, height); } + } - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_NONE; + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_NONE; } static inline int build_provider_info(struct pkg_info *info) { - static const char *dml = "SELECT provider.network, provider.abi, provider.secured, provider.box_type, provider.box_src, provider.box_group, provider.gbar_type, provider.gbar_src, provider.gbar_group, provider.libexec, provider.timeout, provider.period, provider.script, provider.pinup, pkgmap.appid FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?"; - sqlite3_stmt *stmt; - int ret; - const char *tmp; - const char *appid; + static const char *dml = "SELECT provider.network, provider.abi, provider.secured, provider.box_type, provider.box_src, provider.box_group, provider.gbar_type, provider.gbar_src, provider.gbar_group, provider.libexec, provider.timeout, provider.period, provider.script, provider.pinup, pkgmap.appid FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?"; + sqlite3_stmt *stmt; + int ret; + const char *tmp; + const char *appid; + + ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + if (sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT) != SQLITE_OK) { + ErrPrint("Failed to bind a pkgname(%s) - %s\n", package_name(info), sqlite3_errmsg(s_info.handle)); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (sqlite3_bind_text(stmt, 2, package_name(info), -1, SQLITE_TRANSIENT) != SQLITE_OK) { + ErrPrint("Failed to bind a pkgname(%s) - %s\n", package_name(info), sqlite3_errmsg(s_info.handle)); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT) != SQLITE_OK) { - ErrPrint("Failed to bind a pkgname(%s) - %s\n", package_name(info), sqlite3_errmsg(s_info.handle)); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (sqlite3_step(stmt) != SQLITE_ROW) { + ErrPrint("%s has no record(%s)\n", package_name(info), sqlite3_errmsg(s_info.handle)); + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (sqlite3_bind_text(stmt, 2, package_name(info), -1, SQLITE_TRANSIENT) != SQLITE_OK) { - ErrPrint("Failed to bind a pkgname(%s) - %s\n", package_name(info), sqlite3_errmsg(s_info.handle)); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + appid = (const char *)sqlite3_column_text(stmt, 14); + if (!appid || !strlen(appid)) { + ErrPrint("Failed to execute the DML for %s\n", package_name(info)); + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (sqlite3_step(stmt) != SQLITE_ROW) { - ErrPrint("%s has no record(%s)\n", package_name(info), sqlite3_errmsg(s_info.handle)); - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + package_set_network(info, sqlite3_column_int(stmt, 0)); + package_set_secured(info, sqlite3_column_int(stmt, 2)); - appid = (const char *)sqlite3_column_text(stmt, 14); - if (!appid || !strlen(appid)) { - ErrPrint("Failed to execute the DML for %s\n", package_name(info)); - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + tmp = (const char *)sqlite3_column_text(stmt, 1); + if (tmp && strlen(tmp)) { + package_set_abi(info, tmp); + } - package_set_network(info, sqlite3_column_int(stmt, 0)); - package_set_secured(info, sqlite3_column_int(stmt, 2)); + package_set_dbox_type(info, sqlite3_column_int(stmt, 3)); + tmp = (const char *)sqlite3_column_text(stmt, 4); + if (tmp && strlen(tmp)) { + package_set_dbox_path(info, tmp); - tmp = (const char *)sqlite3_column_text(stmt, 1); + tmp = (const char *)sqlite3_column_text(stmt, 5); if (tmp && strlen(tmp)) { - package_set_abi(info, tmp); + package_set_dbox_group(info, tmp); } + } - package_set_dbox_type(info, sqlite3_column_int(stmt, 3)); - tmp = (const char *)sqlite3_column_text(stmt, 4); - if (tmp && strlen(tmp)) { - package_set_dbox_path(info, tmp); + package_set_gbar_type(info, sqlite3_column_int(stmt, 6)); + tmp = (const char *)sqlite3_column_text(stmt, 7); + if (tmp && strlen(tmp)) { + package_set_gbar_path(info, tmp); - tmp = (const char *)sqlite3_column_text(stmt, 5); - if (tmp && strlen(tmp)) { - package_set_dbox_group(info, tmp); - } - } - - package_set_gbar_type(info, sqlite3_column_int(stmt, 6)); - tmp = (const char *)sqlite3_column_text(stmt, 7); + tmp = (const char *)sqlite3_column_text(stmt, 8); if (tmp && strlen(tmp)) { - package_set_gbar_path(info, tmp); - - tmp = (const char *)sqlite3_column_text(stmt, 8); - if (tmp && strlen(tmp)) { - package_set_gbar_group(info, tmp); - } + package_set_gbar_group(info, tmp); } + } - tmp = (const char *)sqlite3_column_text(stmt, 9); - if (tmp && strlen(tmp)) { - package_set_libexec(info, tmp); - } + tmp = (const char *)sqlite3_column_text(stmt, 9); + if (tmp && strlen(tmp)) { + package_set_libexec(info, tmp); + } - package_set_timeout(info, sqlite3_column_int(stmt, 10)); + package_set_timeout(info, sqlite3_column_int(stmt, 10)); - tmp = (const char *)sqlite3_column_text(stmt, 11); - if (tmp && strlen(tmp)) { - package_set_period(info, atof(tmp)); - } + tmp = (const char *)sqlite3_column_text(stmt, 11); + if (tmp && strlen(tmp)) { + package_set_period(info, atof(tmp)); + } - tmp = (const char *)sqlite3_column_text(stmt, 12); - if (tmp && strlen(tmp)) { - package_set_script(info, tmp); - } + tmp = (const char *)sqlite3_column_text(stmt, 12); + if (tmp && strlen(tmp)) { + package_set_script(info, tmp); + } - package_set_pinup(info, sqlite3_column_int(stmt, 13)); + package_set_pinup(info, sqlite3_column_int(stmt, 13)); - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_NONE; + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_NONE; } static inline int build_box_size_info(struct pkg_info *info) { - static const char *dml = "SELECT size_type FROM box_size WHERE pkgid = ?"; - sqlite3_stmt *stmt; - int ret; - unsigned int size_type; - unsigned int size_list; - - ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } + static const char *dml = "SELECT size_type FROM box_size WHERE pkgid = ?"; + sqlite3_stmt *stmt; + int ret; + unsigned int size_type; + unsigned int size_list; + + ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + if (sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT) != SQLITE_OK) { + ErrPrint("Failed to bind a pkgname(%s) - %s\n", package_name(info), sqlite3_errmsg(s_info.handle)); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT) != SQLITE_OK) { - ErrPrint("Failed to bind a pkgname(%s) - %s\n", package_name(info), sqlite3_errmsg(s_info.handle)); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } + size_list = 0; + while (sqlite3_step(stmt) == SQLITE_ROW) { + size_type = sqlite3_column_int(stmt, 0); + size_list |= size_type; + } - size_list = 0; - while (sqlite3_step(stmt) == SQLITE_ROW) { - size_type = sqlite3_column_int(stmt, 0); - size_list |= size_type; - } + package_set_size_list(info, size_list); - package_set_size_list(info, size_list); - - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_NONE; + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_NONE; } static inline int load_context_option(struct context_item *item, int id) { - static const char *dml = "SELECT key, value FROM option WHERE option_id = ?"; - sqlite3_stmt *stmt; - const char *key; - const char *value; - int ret; - - ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - ret = sqlite3_bind_int(stmt, 1, id); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - ret = DBOX_STATUS_ERROR_IO_ERROR; - goto out; - } - - ret = DBOX_STATUS_ERROR_NOT_EXIST; - while (sqlite3_step(stmt) == SQLITE_ROW) { - key = (const char *)sqlite3_column_text(stmt, 0); - if (!key || !strlen(key)) { - ErrPrint("KEY is nil\n"); - continue; - } - - value = (const char *)sqlite3_column_text(stmt, 1); - if (!value || !strlen(value)) { - ErrPrint("VALUE is nil\n"); - continue; - } - - ret = group_add_option(item, key, value); - if (ret < 0) { - break; - } + static const char *dml = "SELECT key, value FROM option WHERE option_id = ?"; + sqlite3_stmt *stmt; + const char *key; + const char *value; + int ret; + + ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + ret = sqlite3_bind_int(stmt, 1, id); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + ret = DBOX_STATUS_ERROR_IO_ERROR; + goto out; + } + + ret = DBOX_STATUS_ERROR_NOT_EXIST; + while (sqlite3_step(stmt) == SQLITE_ROW) { + key = (const char *)sqlite3_column_text(stmt, 0); + if (!key || !strlen(key)) { + ErrPrint("KEY is nil\n"); + continue; + } + + value = (const char *)sqlite3_column_text(stmt, 1); + if (!value || !strlen(value)) { + ErrPrint("VALUE is nil\n"); + continue; + } + + ret = group_add_option(item, key, value); + if (ret < 0) { + break; } + } out: - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return ret; + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return ret; } static inline int load_context_item(struct context_info *info, int id) { - static const char *dml = "SELECT ctx_item, option_id FROM groupmap WHERE id = ?"; - struct context_item *item; - sqlite3_stmt *stmt; - const char *ctx_item; - int option_id; - int ret; - - ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - ret = sqlite3_bind_int(stmt, 1, id); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - ret = DBOX_STATUS_ERROR_IO_ERROR; - goto out; - } - - ret = DBOX_STATUS_ERROR_NOT_EXIST; - while (sqlite3_step(stmt) == SQLITE_ROW) { - ctx_item = (const char *)sqlite3_column_text(stmt, 0); - option_id = sqlite3_column_int(stmt, 1); - - item = group_add_context_item(info, ctx_item); - if (!item) { - ErrPrint("Failed to add a new context item\n"); - ret = DBOX_STATUS_ERROR_FAULT; - break; - } - - ret = load_context_option(item, option_id); - if (ret < 0) { - break; - } + static const char *dml = "SELECT ctx_item, option_id FROM groupmap WHERE id = ?"; + struct context_item *item; + sqlite3_stmt *stmt; + const char *ctx_item; + int option_id; + int ret; + + ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + ret = sqlite3_bind_int(stmt, 1, id); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + ret = DBOX_STATUS_ERROR_IO_ERROR; + goto out; + } + + ret = DBOX_STATUS_ERROR_NOT_EXIST; + while (sqlite3_step(stmt) == SQLITE_ROW) { + ctx_item = (const char *)sqlite3_column_text(stmt, 0); + option_id = sqlite3_column_int(stmt, 1); + + item = group_add_context_item(info, ctx_item); + if (!item) { + ErrPrint("Failed to add a new context item\n"); + ret = DBOX_STATUS_ERROR_FAULT; + break; + } + + ret = load_context_option(item, option_id); + if (ret < 0) { + break; } + } out: - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return ret; + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return ret; } static inline int build_group_info(struct pkg_info *info) { - static const char *dml = "SELECT id, cluster, category FROM groupinfo WHERE pkgid = ?"; - sqlite3_stmt *stmt; - int ret; - int id; - const char *cluster_name; - const char *category_name; - struct cluster *cluster; - struct category *category; - struct context_info *ctx_info; - - ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - ret = sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Failed to bind a package name(%s)\n", package_name(info)); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - id = sqlite3_column_int(stmt, 0); - cluster_name = (const char *)sqlite3_column_text(stmt, 1); - if (!cluster_name || !strlen(cluster_name)) { - DbgPrint("Cluster name is not valid\n"); - continue; - } - - category_name = (const char *)sqlite3_column_text(stmt, 2); - if (!category_name || !strlen(category_name)) { - DbgPrint("Category name is not valid\n"); - continue; - } - - cluster = group_find_cluster(cluster_name); - if (!cluster) { - cluster = group_create_cluster(cluster_name); - if (!cluster) { - ErrPrint("Failed to create a cluster(%s)\n", cluster_name); - continue; - } - } - - category = group_find_category(cluster, category_name); - if (!category) { - category = group_create_category(cluster, category_name); - if (!category) { - ErrPrint("Failed to create a category(%s)\n", category_name); - continue; - } + static const char *dml = "SELECT id, cluster, category FROM groupinfo WHERE pkgid = ?"; + sqlite3_stmt *stmt; + int ret; + int id; + const char *cluster_name; + const char *category_name; + struct cluster *cluster; + struct category *category; + struct context_info *ctx_info; + + ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + ret = sqlite3_bind_text(stmt, 1, package_name(info), -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + ErrPrint("Failed to bind a package name(%s)\n", package_name(info)); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + id = sqlite3_column_int(stmt, 0); + cluster_name = (const char *)sqlite3_column_text(stmt, 1); + if (!cluster_name || !strlen(cluster_name)) { + DbgPrint("Cluster name is not valid\n"); + continue; + } + + category_name = (const char *)sqlite3_column_text(stmt, 2); + if (!category_name || !strlen(category_name)) { + DbgPrint("Category name is not valid\n"); + continue; + } + + cluster = group_find_cluster(cluster_name); + if (!cluster) { + cluster = group_create_cluster(cluster_name); + if (!cluster) { + ErrPrint("Failed to create a cluster(%s)\n", cluster_name); + continue; + } + } + + category = group_find_category(cluster, category_name); + if (!category) { + category = group_create_category(cluster, category_name); + if (!category) { + ErrPrint("Failed to create a category(%s)\n", category_name); + continue; + } + } + + /*! + * \TODO + * Step 1. Get the list of the context item from the DB using 'id' + * {context_item, option_id} + * Step 2. Get the list of the options from the DB using option_id + * key, value + */ + ctx_info = group_create_context_info(category, package_name(info)); + if (ctx_info) { + ret = load_context_item(ctx_info, id); + if (ret < 0) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST) { + DbgPrint("Has no specific context info\n"); + } else { + DbgPrint("Context info is not valid\n"); + group_destroy_context_info(ctx_info); + ctx_info = NULL; } + } - /*! - * \TODO - * Step 1. Get the list of the context item from the DB using 'id' - * {context_item, option_id} - * Step 2. Get the list of the options from the DB using option_id - * key, value - */ - ctx_info = group_create_context_info(category, package_name(info)); - if (ctx_info) { - ret = load_context_item(ctx_info, id); - if (ret < 0) { - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST) { - DbgPrint("Has no specific context info\n"); - } else { - DbgPrint("Context info is not valid\n"); - group_destroy_context_info(ctx_info); - ctx_info = NULL; - } - } - - if (ctx_info) { - package_add_ctx_info(info, ctx_info); - } - } + if (ctx_info) { + package_add_ctx_info(info, ctx_info); + } } + } - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_NONE; + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_NONE; } HAPI int io_is_exists(const char *lbid) { - sqlite3_stmt *stmt; - int ret; - - if (!s_info.handle) { - ErrPrint("DB is not ready\n"); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - ret = sqlite3_prepare_v2(s_info.handle, "SELECT COUNT(pkgid) FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - ret = DBOX_STATUS_ERROR_IO_ERROR; - goto out; - } - - if (sqlite3_step(stmt) != SQLITE_ROW) { - ErrPrint("%s has no record (%s)\n", lbid, sqlite3_errmsg(s_info.handle)); - ret = DBOX_STATUS_ERROR_IO_ERROR; - goto out; - } - - ret = sqlite3_column_int(stmt, 0); + sqlite3_stmt *stmt; + int ret; + + if (!s_info.handle) { + ErrPrint("DB is not ready\n"); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + ret = sqlite3_prepare_v2(s_info.handle, "SELECT COUNT(pkgid) FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + ret = DBOX_STATUS_ERROR_IO_ERROR; + goto out; + } + + if (sqlite3_step(stmt) != SQLITE_ROW) { + ErrPrint("%s has no record (%s)\n", lbid, sqlite3_errmsg(s_info.handle)); + ret = DBOX_STATUS_ERROR_IO_ERROR; + goto out; + } + + ret = sqlite3_column_int(stmt, 0); out: - sqlite3_reset(stmt); - sqlite3_finalize(stmt); - return ret; + sqlite3_reset(stmt); + sqlite3_finalize(stmt); + return ret; } HAPI char *io_dynamicbox_pkgname(const char *pkgname) { - sqlite3_stmt *stmt; - char *pkgid; - char *tmp; - int ret; - - pkgid = NULL; - - if (!s_info.handle) { - ErrPrint("DB is not ready\n"); - return NULL; - } - - ret = sqlite3_prepare_v2(s_info.handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return NULL; - } - - ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - if (sqlite3_step(stmt) != SQLITE_ROW) { - ErrPrint("%s has no record (%s)\n", pkgname, sqlite3_errmsg(s_info.handle)); - goto out; - } - - tmp = (char *)sqlite3_column_text(stmt, 0); - if (tmp && strlen(tmp)) { - pkgid = strdup(tmp); - if (!pkgid) { - ErrPrint("Heap: %s\n", strerror(errno)); - } - } + sqlite3_stmt *stmt; + char *pkgid; + char *tmp; + int ret; + + pkgid = NULL; + + if (!s_info.handle) { + ErrPrint("DB is not ready\n"); + return NULL; + } + + ret = sqlite3_prepare_v2(s_info.handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return NULL; + } + + ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + goto out; + } + + ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + goto out; + } + + if (sqlite3_step(stmt) != SQLITE_ROW) { + ErrPrint("%s has no record (%s)\n", pkgname, sqlite3_errmsg(s_info.handle)); + goto out; + } + + tmp = (char *)sqlite3_column_text(stmt, 0); + if (tmp && strlen(tmp)) { + pkgid = strdup(tmp); + if (!pkgid) { + ErrPrint("Heap: %s\n", strerror(errno)); + } + } out: - sqlite3_reset(stmt); - sqlite3_finalize(stmt); - return pkgid; + sqlite3_reset(stmt); + sqlite3_finalize(stmt); + return pkgid; } HAPI int io_crawling_dynamicboxes(int (*cb)(const char *pkgid, const char *lbid, int prime, void *data), void *data) { - DIR *dir; + DIR *dir; - if (!s_info.handle) { - ErrPrint("DB is not ready\n"); + if (!s_info.handle) { + ErrPrint("DB is not ready\n"); + } else { + int ret; + sqlite3_stmt *stmt; + + ret = sqlite3_prepare_v2(s_info.handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); } else { - int ret; - sqlite3_stmt *stmt; + const char *lbid; + const char *pkgid; + int prime; + + while (sqlite3_step(stmt) == SQLITE_ROW) { + pkgid = (const char *)sqlite3_column_text(stmt, 0); + if (!pkgid || !strlen(pkgid)) { + continue; + } - ret = sqlite3_prepare_v2(s_info.handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - } else { - const char *lbid; - const char *pkgid; - int prime; - - while (sqlite3_step(stmt) == SQLITE_ROW) { - pkgid = (const char *)sqlite3_column_text(stmt, 0); - if (!pkgid || !strlen(pkgid)) { - continue; - } - - lbid = (const char *)sqlite3_column_text(stmt, 1); - if (!lbid || !strlen(lbid)) { - continue; - } - - prime = (int)sqlite3_column_int(stmt, 1); - - if (cb(pkgid, lbid, prime, data) < 0) { - sqlite3_reset(stmt); - sqlite3_finalize(stmt); - return DBOX_STATUS_ERROR_CANCEL; - } - } + lbid = (const char *)sqlite3_column_text(stmt, 1); + if (!lbid || !strlen(lbid)) { + continue; + } + + prime = (int)sqlite3_column_int(stmt, 1); - sqlite3_reset(stmt); - sqlite3_finalize(stmt); + if (cb(pkgid, lbid, prime, data) < 0) { + sqlite3_reset(stmt); + sqlite3_finalize(stmt); + return DBOX_STATUS_ERROR_CANCEL; } + } + + sqlite3_reset(stmt); + sqlite3_finalize(stmt); } + } - dir = opendir(DYNAMICBOX_CONF_ROOT_PATH); - if (!dir) { - ErrPrint("Error: %s\n", strerror(errno)); - } else { - struct dirent *ent; + dir = opendir(DYNAMICBOX_CONF_ROOT_PATH); + if (!dir) { + ErrPrint("Error: %s\n", strerror(errno)); + } else { + struct dirent *ent; - while ((ent = readdir(dir))) { - if (ent->d_name[0] == '.') { - continue; - } - - if (cb(ent->d_name, ent->d_name, -2, data) < 0) { - if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_CANCEL; - } - } + while ((ent = readdir(dir))) { + if (ent->d_name[0] == '.') { + continue; + } + if (cb(ent->d_name, ent->d_name, -2, data) < 0) { if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); + ErrPrint("closedir: %s\n", strerror(errno)); } + return DBOX_STATUS_ERROR_CANCEL; + } } - return DBOX_STATUS_ERROR_NONE; + if (closedir(dir) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int io_update_dynamicbox_package(const char *pkgid, int (*cb)(const char *pkgid, const char *lbid, int prime, void *data), void *data) { - sqlite3_stmt *stmt; - char *lbid; - int prime; - int ret; + sqlite3_stmt *stmt; + char *lbid; + int prime; + int ret; - if (!cb || !pkgid) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!cb || !pkgid) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!s_info.handle) { - ErrPrint("DB is not ready\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - ret = sqlite3_prepare_v2(s_info.handle, "SELECT pkgid, prime FROM pkgmap WHERE appid = ?", -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - return DBOX_STATUS_ERROR_FAULT; - } + if (!s_info.handle) { + ErrPrint("DB is not ready\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + ret = sqlite3_prepare_v2(s_info.handle, "SELECT pkgid, prime FROM pkgmap WHERE appid = ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + return DBOX_STATUS_ERROR_FAULT; + } - ret = 0; - while (sqlite3_step(stmt) == SQLITE_ROW) { - lbid = (char *)sqlite3_column_text(stmt, 0); - if (!lbid || !strlen(lbid)) { - continue; - } + ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + ErrPrint("Error: %s\n", sqlite3_errmsg(s_info.handle)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - prime = sqlite3_column_int(stmt, 1); + ret = 0; + while (sqlite3_step(stmt) == SQLITE_ROW) { + lbid = (char *)sqlite3_column_text(stmt, 0); + if (!lbid || !strlen(lbid)) { + continue; + } - if (cb(pkgid, lbid, prime, data) < 0) { - DbgPrint("Callback canceled\n"); - break; - } + prime = sqlite3_column_int(stmt, 1); - ret++; + if (cb(pkgid, lbid, prime, data) < 0) { + DbgPrint("Callback canceled\n"); + break; } + + ret++; + } out: - sqlite3_reset(stmt); - sqlite3_finalize(stmt); - return ret; + sqlite3_reset(stmt); + sqlite3_finalize(stmt); + return ret; } HAPI int io_load_package_db(struct pkg_info *info) { - int ret; + int ret; - if (!s_info.handle) { - ErrPrint("DB is not ready\n"); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (!s_info.handle) { + ErrPrint("DB is not ready\n"); + return DBOX_STATUS_ERROR_IO_ERROR; + } - ret = build_provider_info(info); - if (ret < 0) { - return ret; - } + ret = build_provider_info(info); + if (ret < 0) { + return ret; + } - ret = build_client_info(info); - if (ret < 0) { - return ret; - } + ret = build_client_info(info); + if (ret < 0) { + return ret; + } - ret = build_box_size_info(info); - if (ret < 0) { - return ret; - } + ret = build_box_size_info(info); + if (ret < 0) { + return ret; + } - ret = build_group_info(info); - if (ret < 0) { - return ret; - } + ret = build_group_info(info); + if (ret < 0) { + return ret; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline int db_init(void) { - int ret; - struct stat stat; + int ret; + struct stat stat; - ret = db_util_open_with_options(DYNAMICBOX_CONF_DBFILE, &s_info.handle, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Failed to open a DB\n"); - return DBOX_STATUS_ERROR_IO_ERROR; - } + ret = db_util_open_with_options(DYNAMICBOX_CONF_DBFILE, &s_info.handle, SQLITE_OPEN_READONLY, NULL); + if (ret != SQLITE_OK) { + ErrPrint("Failed to open a DB\n"); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (lstat(DYNAMICBOX_CONF_DBFILE, &stat) < 0) { - db_util_close(s_info.handle); - s_info.handle = NULL; - ErrPrint("%s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (lstat(DYNAMICBOX_CONF_DBFILE, &stat) < 0) { + db_util_close(s_info.handle); + s_info.handle = NULL; + ErrPrint("%s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; + } - if (!S_ISREG(stat.st_mode)) { - ErrPrint("Invalid file\n"); - db_util_close(s_info.handle); - s_info.handle = NULL; - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!S_ISREG(stat.st_mode)) { + ErrPrint("Invalid file\n"); + db_util_close(s_info.handle); + s_info.handle = NULL; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (stat.st_size <= 0) { - DbgPrint("Size is %d (But use this ;)\n", stat.st_size); - } + if (stat.st_size <= 0) { + DbgPrint("Size is %d (But use this ;)\n", stat.st_size); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline int db_fini(void) { - if (!s_info.handle) { - return DBOX_STATUS_ERROR_NONE; - } + if (!s_info.handle) { + return DBOX_STATUS_ERROR_NONE; + } - db_util_close(s_info.handle); - s_info.handle = NULL; + db_util_close(s_info.handle); + s_info.handle = NULL; - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int io_init(void) { - int ret; + int ret; - ret = db_init(); - if (ret < 0) { - DbgPrint("DB initialized: %d\n", ret); - } + ret = db_init(); + if (ret < 0) { + DbgPrint("DB initialized: %d\n", ret); + } - ret = load_abi_table(); - if (ret < 0) { - DbgPrint("ABI table is loaded: %d\n", ret); - } + ret = load_abi_table(); + if (ret < 0) { + DbgPrint("ABI table is loaded: %d\n", ret); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int io_fini(void) { - int ret; + int ret; - abi_del_all(); + abi_del_all(); - ret = db_fini(); - if (ret < 0) { - DbgPrint("DB finalized: %d\n", ret); - } - return DBOX_STATUS_ERROR_NONE; + ret = db_fini(); + if (ret < 0) { + DbgPrint("DB finalized: %d\n", ret); + } + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/liveinfo.c b/src/liveinfo.c index cba5b95..a0ec213 100644 --- a/src/liveinfo.c +++ b/src/liveinfo.c @@ -36,188 +36,188 @@ int errno; static struct info { - Eina_List *info_list; + Eina_List *info_list; } s_info = { - .info_list = NULL, + .info_list = NULL, }; struct liveinfo { - FILE *fp; - char fifo_name[60]; - pid_t pid; - int handle; - void *data; + FILE *fp; + char fifo_name[60]; + pid_t pid; + int handle; + void *data; }; HAPI int liveinfo_init(void) { - return 0; + return 0; } HAPI void liveinfo_fini(void) { - struct liveinfo *info; - - EINA_LIST_FREE(s_info.info_list, info) { - if (fclose(info->fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } - if (unlink(info->fifo_name) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } - DbgFree(info); + struct liveinfo *info; + + EINA_LIST_FREE(s_info.info_list, info) { + if (fclose(info->fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); + } + if (unlink(info->fifo_name) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); } + DbgFree(info); + } } static inline int valid_requestor(pid_t pid) { - char cmdline[60]; /* strlen("/proc/%d/cmdline") + 30 */ - struct stat target; - struct stat src; + char cmdline[60]; /* strlen("/proc/%d/cmdline") + 30 */ + struct stat target; + struct stat src; - snprintf(cmdline, sizeof(cmdline), "/proc/%d/exe", pid); + snprintf(cmdline, sizeof(cmdline), "/proc/%d/exe", pid); - DbgPrint("Open cmdline: %s (%d)\n", cmdline, pid); + DbgPrint("Open cmdline: %s (%d)\n", cmdline, pid); - if (stat(cmdline, &target) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return 0; - } + if (stat(cmdline, &target) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return 0; + } - if (stat("/opt/usr/devel/usr/bin/liveinfo", &src) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return 0; - } + if (stat("/opt/usr/devel/usr/bin/liveinfo", &src) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return 0; + } - if (target.st_ino == src.st_ino) { - return 1; - } + if (target.st_ino == src.st_ino) { + return 1; + } - if (stat("/opt/usr/devel/usr/bin/dbox-mgr", &src) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return 0; - } + if (stat("/opt/usr/devel/usr/bin/dbox-mgr", &src) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return 0; + } - return target.st_ino == src.st_ino; + return target.st_ino == src.st_ino; } HAPI void liveinfo_set_data(struct liveinfo *info, void *data) { - info->data = data; + info->data = data; } HAPI void *liveinfo_data(struct liveinfo *info) { - return info->data; + return info->data; } HAPI struct liveinfo *liveinfo_create(pid_t pid, int handle) { - struct liveinfo *info; + struct liveinfo *info; - if (!valid_requestor(pid)) { - ErrPrint("Invalid requestor\n"); - return NULL; - } + if (!valid_requestor(pid)) { + ErrPrint("Invalid requestor\n"); + return NULL; + } - info = calloc(1, sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + info = calloc(1, sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - snprintf(info->fifo_name, sizeof(info->fifo_name), "/tmp/.live_info.%lf", util_timestamp()); - if (mkfifo(info->fifo_name, 0644) < 0) { - ErrPrint("mkfifo: %s\n", strerror(errno)); - if (unlink(info->fifo_name) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } - DbgFree(info); - return NULL; + snprintf(info->fifo_name, sizeof(info->fifo_name), "/tmp/.live_info.%lf", util_timestamp()); + if (mkfifo(info->fifo_name, 0644) < 0) { + ErrPrint("mkfifo: %s\n", strerror(errno)); + if (unlink(info->fifo_name) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); } + DbgFree(info); + return NULL; + } - info->fp = NULL; - info->pid = pid; - info->handle = handle; + info->fp = NULL; + info->pid = pid; + info->handle = handle; - DbgPrint("Live info is successfully created\n"); - s_info.info_list = eina_list_append(s_info.info_list, info); - return info; + DbgPrint("Live info is successfully created\n"); + s_info.info_list = eina_list_append(s_info.info_list, info); + return info; } HAPI int liveinfo_open_fifo(struct liveinfo *info) { - DbgPrint("FIFO is created (%s)\n", info->fifo_name); - info->fp = fopen(info->fifo_name, "w"); - if (!info->fp) { - ErrPrint("open: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - return DBOX_STATUS_ERROR_NONE; + DbgPrint("FIFO is created (%s)\n", info->fifo_name); + info->fp = fopen(info->fifo_name, "w"); + if (!info->fp) { + ErrPrint("open: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + return DBOX_STATUS_ERROR_NONE; } HAPI void liveinfo_close_fifo(struct liveinfo *info) { - if (info->fp) { - if (fclose(info->fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } - info->fp = NULL; + if (info->fp) { + if (fclose(info->fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); } + info->fp = NULL; + } } HAPI void liveinfo_destroy(struct liveinfo *info) { - s_info.info_list = eina_list_remove(s_info.info_list, info); - liveinfo_close_fifo(info); - if (unlink(info->fifo_name) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } - DbgFree(info); + s_info.info_list = eina_list_remove(s_info.info_list, info); + liveinfo_close_fifo(info); + if (unlink(info->fifo_name) < 0) { + ErrPrint("unlink: %s\n", strerror(errno)); + } + DbgFree(info); } HAPI pid_t liveinfo_pid(struct liveinfo *info) { - return info ? info->pid : (pid_t)-1; + return info ? info->pid : (pid_t)-1; } HAPI const char *liveinfo_filename(struct liveinfo *info) { - return info ? info->fifo_name : NULL; + return info ? info->fifo_name : NULL; } HAPI FILE *liveinfo_fifo(struct liveinfo *info) { - return info ? info->fp : NULL; + return info ? info->fp : NULL; } HAPI struct liveinfo *liveinfo_find_by_pid(pid_t pid) { - Eina_List *l; - struct liveinfo *info; + Eina_List *l; + struct liveinfo *info; - EINA_LIST_FOREACH(s_info.info_list, l, info) { - if (info->pid == pid) { - return info; - } + EINA_LIST_FOREACH(s_info.info_list, l, info) { + if (info->pid == pid) { + return info; } + } - return NULL; + return NULL; } HAPI struct liveinfo *liveinfo_find_by_handle(int handle) { - Eina_List *l; - struct liveinfo *info; + Eina_List *l; + struct liveinfo *info; - EINA_LIST_FOREACH(s_info.info_list, l, info) { - if (info->handle == handle) { - return info; - } + EINA_LIST_FOREACH(s_info.info_list, l, info) { + if (info->handle == handle) { + return info; } + } - return NULL; + return NULL; } /* End of a file */ diff --git a/src/main.c b/src/main.c index e71894d..4bfdf45 100644 --- a/src/main.c +++ b/src/main.c @@ -70,382 +70,382 @@ FILE *__file_log_fp; static inline int app_create(void) { - int ret; - - if (access(DYNAMICBOX_CONF_LOG_PATH, R_OK | W_OK) != 0) { - if (mkdir(DYNAMICBOX_CONF_LOG_PATH, 0755) < 0) { - ErrPrint("Failed to create %s (%s)\n", DYNAMICBOX_CONF_LOG_PATH, strerror(errno)); - } - } - - /*! - * \note - * Dead signal handler has to be initialized before - * initate package or client (slave and client). - * - * Because while creating slaves for packages. - * It could be crashed before complete the initation stage. - * - * Then the dead callback should be invoked to handle it properly. - * - * To enable the dead signal handler, - * dead_init should be done before other components are initiated. - */ - ret = setting_init(); - if (ret < 0) { - DbgPrint("Setting initialized: %d\n", ret); - } + int ret; + + if (access(DYNAMICBOX_CONF_LOG_PATH, R_OK | W_OK) != 0) { + if (mkdir(DYNAMICBOX_CONF_LOG_PATH, 0755) < 0) { + ErrPrint("Failed to create %s (%s)\n", DYNAMICBOX_CONF_LOG_PATH, strerror(errno)); + } + } + + /*! + * \note + * Dead signal handler has to be initialized before + * initate package or client (slave and client). + * + * Because while creating slaves for packages. + * It could be crashed before complete the initation stage. + * + * Then the dead callback should be invoked to handle it properly. + * + * To enable the dead signal handler, + * dead_init should be done before other components are initiated. + */ + ret = setting_init(); + if (ret < 0) { + DbgPrint("Setting initialized: %d\n", ret); + } #if defined(HAVE_LIVEBOX) - ret = client_init(); - if (ret < 0) { - DbgPrint("Client initialized: %d\n", ret); - } - - ret = dead_init(); - if (ret < 0) { - DbgPrint("Dead callback is registered: %d\n", ret); - } - - ret = group_init(); - if (ret < 0) { - DbgPrint("group init: %d\n", ret); - } - - ret = io_init(); - if (ret < 0) { - DbgPrint("Init I/O: %d\n", ret); - } - - ret = package_init(); - if (ret < 0) { - DbgPrint("pkgmgr initialized: %d\n", ret); - } - - instance_init(); - - ret = xmonitor_init(); - if (ret < 0) { - DbgPrint("XMonitor init is done: %d\n", ret); - } - - ret = buffer_handler_init(); - if (ret < 0) { - DbgPrint("Buffer handler init is done: %d\n", ret); - } - - /*! - * \note - * After initiate all other sub-systtems, - * Enable the server socket. - */ - ret = server_init(); - if (ret < 0) { - DbgPrint("Server initialized: %d\n", ret); - } - - event_init(); - - script_init(); - - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_FILE)) { - file_service_init(); - } - - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_UTILITY)) { - utility_service_init(); - } + ret = client_init(); + if (ret < 0) { + DbgPrint("Client initialized: %d\n", ret); + } + + ret = dead_init(); + if (ret < 0) { + DbgPrint("Dead callback is registered: %d\n", ret); + } + + ret = group_init(); + if (ret < 0) { + DbgPrint("group init: %d\n", ret); + } + + ret = io_init(); + if (ret < 0) { + DbgPrint("Init I/O: %d\n", ret); + } + + ret = package_init(); + if (ret < 0) { + DbgPrint("pkgmgr initialized: %d\n", ret); + } + + instance_init(); + + ret = xmonitor_init(); + if (ret < 0) { + DbgPrint("XMonitor init is done: %d\n", ret); + } + + ret = buffer_handler_init(); + if (ret < 0) { + DbgPrint("Buffer handler init is done: %d\n", ret); + } + + /*! + * \note + * After initiate all other sub-systtems, + * Enable the server socket. + */ + ret = server_init(); + if (ret < 0) { + DbgPrint("Server initialized: %d\n", ret); + } + + event_init(); + + script_init(); + + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_FILE)) { + file_service_init(); + } + + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_UTILITY)) { + utility_service_init(); + } #endif - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_SHORTCUT)) { - shortcut_service_init(); - } + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_SHORTCUT)) { + shortcut_service_init(); + } - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_NOTIFICATION)) { - notification_service_init(); - } + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_NOTIFICATION)) { + notification_service_init(); + } - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_BADGE)) { - badge_service_init(); - } + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_BADGE)) { + badge_service_init(); + } - return 0; + return 0; } static inline int app_terminate(void) { - int ret; + int ret; - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_BADGE)) { - ret = badge_service_fini(); - if (ret < 0) { - DbgPrint("badge: %d\n", ret); - } + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_BADGE)) { + ret = badge_service_fini(); + if (ret < 0) { + DbgPrint("badge: %d\n", ret); } + } - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_NOTIFICATION)) { - ret = notification_service_fini(); - if (ret < 0) { - DbgPrint("noti: %d\n", ret); - } + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_NOTIFICATION)) { + ret = notification_service_fini(); + if (ret < 0) { + DbgPrint("noti: %d\n", ret); } + } - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_SHORTCUT)) { - ret = shortcut_service_fini(); - if (ret < 0) { - DbgPrint("shortcut: %d\n", ret); - } + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_SHORTCUT)) { + ret = shortcut_service_fini(); + if (ret < 0) { + DbgPrint("shortcut: %d\n", ret); } + } #if defined(HAVE_LIVEBOX) - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_FILE)) { - ret = file_service_fini(); - if (ret < 0) { - DbgPrint("Finalize the file service: %d\n", ret); - } - } - - ret = server_fini(); + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_FILE)) { + ret = file_service_fini(); if (ret < 0) { - DbgPrint("Finalize server: %d\n", ret); + DbgPrint("Finalize the file service: %d\n", ret); } + } - ret = dead_fini(); - if (ret < 0) { - DbgPrint("dead signal handler finalized: %d\n", ret); - } + ret = server_fini(); + if (ret < 0) { + DbgPrint("Finalize server: %d\n", ret); + } - if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_UTILITY)) { - ret = utility_service_fini(); - if (ret < 0) { - DbgPrint("utility: %d\n", ret); - } - } + ret = dead_fini(); + if (ret < 0) { + DbgPrint("dead signal handler finalized: %d\n", ret); + } - ret = event_fini(); + if (util_service_is_enabled(DYNAMICBOX_CONF_SERVICE_UTILITY)) { + ret = utility_service_fini(); if (ret < 0) { - DbgPrint("event: %d\n", ret); + DbgPrint("utility: %d\n", ret); } + } - ret = setting_fini(); - if (ret < 0) { - DbgPrint("Finalize setting : %d\n", ret); - } + ret = event_fini(); + if (ret < 0) { + DbgPrint("event: %d\n", ret); + } - ret = instance_fini(); - if (ret < 0) { - DbgPrint("Finalizing instances: %d\n", ret); - } + ret = setting_fini(); + if (ret < 0) { + DbgPrint("Finalize setting : %d\n", ret); + } - ret = package_fini(); - if (ret < 0) { - DbgPrint("Finalize package info: %d\n", ret); - } + ret = instance_fini(); + if (ret < 0) { + DbgPrint("Finalizing instances: %d\n", ret); + } - ret = script_fini(); - if (ret < 0) { - DbgPrint("script: %d\n", ret); - } + ret = package_fini(); + if (ret < 0) { + DbgPrint("Finalize package info: %d\n", ret); + } - ret = buffer_handler_fini(); - if (ret < 0) { - DbgPrint("buffer handler: %d\n", ret); - } + ret = script_fini(); + if (ret < 0) { + DbgPrint("script: %d\n", ret); + } - xmonitor_fini(); + ret = buffer_handler_fini(); + if (ret < 0) { + DbgPrint("buffer handler: %d\n", ret); + } - client_fini(); + xmonitor_fini(); - ret = io_fini(); - if (ret < 0) { - DbgPrint("IO finalized: %d\n", ret); - } + client_fini(); - ret = group_fini(); - if (ret < 0) { - DbgPrint("Group finalized: %d\n", ret); - } + ret = io_fini(); + if (ret < 0) { + DbgPrint("IO finalized: %d\n", ret); + } + + ret = group_fini(); + if (ret < 0) { + DbgPrint("Group finalized: %d\n", ret); + } #endif - DbgPrint("Terminated\n"); - return 0; + DbgPrint("Terminated\n"); + return 0; } static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler) { - struct signalfd_siginfo fdsi; - ssize_t size; - int fd; - - fd = ecore_main_fd_handler_fd_get(handler); - if (fd < 0) { - ErrPrint("Unable to get FD\n"); - ecore_main_fd_handler_del(handler); - return ECORE_CALLBACK_CANCEL; - } + struct signalfd_siginfo fdsi; + ssize_t size; + int fd; - size = read(fd, &fdsi, sizeof(fdsi)); - if (size != sizeof(fdsi)) { - ErrPrint("Unable to get siginfo: %s\n", strerror(errno)); - ecore_main_fd_handler_del(handler); - return ECORE_CALLBACK_CANCEL; - } + fd = ecore_main_fd_handler_fd_get(handler); + if (fd < 0) { + ErrPrint("Unable to get FD\n"); + ecore_main_fd_handler_del(handler); + return ECORE_CALLBACK_CANCEL; + } - if (fdsi.ssi_signo == SIGTERM) { - int cfd; + size = read(fd, &fdsi, sizeof(fdsi)); + if (size != sizeof(fdsi)) { + ErrPrint("Unable to get siginfo: %s\n", strerror(errno)); + ecore_main_fd_handler_del(handler); + return ECORE_CALLBACK_CANCEL; + } - CRITICAL_LOG("Terminated(SIGTERM)\n"); + if (fdsi.ssi_signo == SIGTERM) { + int cfd; - cfd = creat("/tmp/.stop.provider", 0644); - if (cfd < 0 || close(cfd) < 0) { - ErrPrint("stop.provider: %s\n", strerror(errno)); - } + CRITICAL_LOG("Terminated(SIGTERM)\n"); - vconf_set_bool(VCONFKEY_MASTER_STARTED, 0); - //exit(0); - ecore_main_loop_quit(); - } else if (fdsi.ssi_signo == SIGUSR1) { - /*! - * Turn off auto-reactivation - * Terminate all slaves - */ + cfd = creat("/tmp/.stop.provider", 0644); + if (cfd < 0 || close(cfd) < 0) { + ErrPrint("stop.provider: %s\n", strerror(errno)); + } + + vconf_set_bool(VCONFKEY_MASTER_STARTED, 0); + //exit(0); + ecore_main_loop_quit(); + } else if (fdsi.ssi_signo == SIGUSR1) { + /*! + * Turn off auto-reactivation + * Terminate all slaves + */ #if defined(HAVE_LIVEBOX) - CRITICAL_LOG("USRS1, Deactivate ALL\n"); - slave_deactivate_all(0, 1, 1); + CRITICAL_LOG("USRS1, Deactivate ALL\n"); + slave_deactivate_all(0, 1, 1); #endif - } else if (fdsi.ssi_signo == SIGUSR2) { - /*! - * Turn on auto-reactivation - * Launch all slaves again - */ + } else if (fdsi.ssi_signo == SIGUSR2) { + /*! + * Turn on auto-reactivation + * Launch all slaves again + */ #if defined(HAVE_LIVEBOX) - CRITICAL_LOG("USR2, Activate ALL\n"); - slave_activate_all(); + CRITICAL_LOG("USR2, Activate ALL\n"); + slave_activate_all(); #endif - } else { - CRITICAL_LOG("Unknown SIG[%d] received\n", fdsi.ssi_signo); - } + } else { + CRITICAL_LOG("Unknown SIG[%d] received\n", fdsi.ssi_signo); + } - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; } int main(int argc, char *argv[]) { - int ret; - int restart_count = 0; - sigset_t mask; - Ecore_Fd_Handler *signal_handler = NULL; + int ret; + int restart_count = 0; + sigset_t mask; + Ecore_Fd_Handler *signal_handler = NULL; #if defined(FLOG) - __file_log_fp = fopen(TMP_LOG_FILE, "w+t"); - if (!__file_log_fp) { - __file_log_fp = fdopen(1, "w+t"); - } + __file_log_fp = fopen(TMP_LOG_FILE, "w+t"); + if (!__file_log_fp) { + __file_log_fp = fdopen(1, "w+t"); + } #endif - /* appcore_agent_terminate */ - if (ecore_init() <= 0) { - return -EFAULT; - } - - if (util_screen_init() <= 0) { - ecore_shutdown(); - return -EFAULT; - } - - dynamicbox_conf_init(); - dynamicbox_conf_load(); + /* appcore_agent_terminate */ + if (ecore_init() <= 0) { + return -EFAULT; + } - /*! - * How could we care this return values? - * Is there any way to print something on the screen? - */ - ret = critical_log_init(util_basename(argv[0])); - if (ret < 0) { - ErrPrint("Failed to init the critical log\n"); - } - - /*! - * \note - * Clear old contents files before start the master provider. - */ - (void)util_unlink_files(DYNAMICBOX_CONF_ALWAYS_PATH); - (void)util_unlink_files(DYNAMICBOX_CONF_READER_PATH); - (void)util_unlink_files(DYNAMICBOX_CONF_IMAGE_PATH); - (void)util_unlink_files(DYNAMICBOX_CONF_LOG_PATH); - - if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) < DYNAMICBOX_CONF_MINIMUM_SPACE) { - util_remove_emergency_disk(); - util_prepare_emergency_disk(); - } - - util_setup_log_disk(); - - sigemptyset(&mask); - - ret = sigaddset(&mask, SIGTERM); - if (ret < 0) { - CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno)); - } - - ret = sigaddset(&mask, SIGUSR1); - if (ret < 0) { - CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno)); - } - - ret = sigaddset(&mask, SIGUSR2); - if (ret < 0) { - CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno)); - } - - ret = sigprocmask(SIG_BLOCK, &mask, NULL); - if (ret < 0) { - CRITICAL_LOG("Failed to mask the SIGTERM: %s\n", strerror(errno)); - } - - ret = signalfd(-1, &mask, 0); - if (ret < 0) { - CRITICAL_LOG("Failed to initiate the signalfd: %s\n", strerror(errno)); - } else { - signal_handler = ecore_main_fd_handler_add(ret, ECORE_FD_READ, signal_cb, NULL, NULL, NULL); - CRITICAL_LOG("Signal handler initiated: %d\n", ret); - } - - ecore_app_args_set(argc, (const char **)argv); + if (util_screen_init() <= 0) { + ecore_shutdown(); + return -EFAULT; + } + + dynamicbox_conf_init(); + dynamicbox_conf_load(); + + /*! + * How could we care this return values? + * Is there any way to print something on the screen? + */ + ret = critical_log_init(util_basename(argv[0])); + if (ret < 0) { + ErrPrint("Failed to init the critical log\n"); + } + + /*! + * \note + * Clear old contents files before start the master provider. + */ + (void)util_unlink_files(DYNAMICBOX_CONF_ALWAYS_PATH); + (void)util_unlink_files(DYNAMICBOX_CONF_READER_PATH); + (void)util_unlink_files(DYNAMICBOX_CONF_IMAGE_PATH); + (void)util_unlink_files(DYNAMICBOX_CONF_LOG_PATH); + + if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) < DYNAMICBOX_CONF_MINIMUM_SPACE) { + util_remove_emergency_disk(); + util_prepare_emergency_disk(); + } + + util_setup_log_disk(); + + sigemptyset(&mask); + + ret = sigaddset(&mask, SIGTERM); + if (ret < 0) { + CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno)); + } + + ret = sigaddset(&mask, SIGUSR1); + if (ret < 0) { + CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno)); + } + + ret = sigaddset(&mask, SIGUSR2); + if (ret < 0) { + CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno)); + } + + ret = sigprocmask(SIG_BLOCK, &mask, NULL); + if (ret < 0) { + CRITICAL_LOG("Failed to mask the SIGTERM: %s\n", strerror(errno)); + } + + ret = signalfd(-1, &mask, 0); + if (ret < 0) { + CRITICAL_LOG("Failed to initiate the signalfd: %s\n", strerror(errno)); + } else { + signal_handler = ecore_main_fd_handler_add(ret, ECORE_FD_READ, signal_cb, NULL, NULL, NULL); + CRITICAL_LOG("Signal handler initiated: %d\n", ret); + } + + ecore_app_args_set(argc, (const char **)argv); #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) - g_type_init(); + g_type_init(); #endif - app_create(); + app_create(); - vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count); - restart_count++; - vconf_set_int(VCONFKEY_MASTER_RESTART_COUNT, restart_count); + vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count); + restart_count++; + vconf_set_int(VCONFKEY_MASTER_RESTART_COUNT, restart_count); - vconf_set_bool(VCONFKEY_MASTER_STARTED, 1); - ecore_main_loop_begin(); - vconf_set_bool(VCONFKEY_MASTER_STARTED, 0); + vconf_set_bool(VCONFKEY_MASTER_STARTED, 1); + ecore_main_loop_begin(); + vconf_set_bool(VCONFKEY_MASTER_STARTED, 0); - app_terminate(); + app_terminate(); - util_screen_fini(); + util_screen_fini(); - if (signal_handler) { - ecore_main_fd_handler_del(signal_handler); - } + if (signal_handler) { + ecore_main_fd_handler_del(signal_handler); + } - ecore_shutdown(); - critical_log_fini(); + ecore_shutdown(); + critical_log_fini(); #if defined(FLOG) - if (__file_log_fp) { - fclose(__file_log_fp); - } + if (__file_log_fp) { + fclose(__file_log_fp); + } #endif - dynamicbox_conf_reset(); - return 0; + dynamicbox_conf_reset(); + return 0; } /* End of a file */ diff --git a/src/notification_service.c b/src/notification_service.c index e14ca90..fa0e82b 100644 --- a/src/notification_service.c +++ b/src/notification_service.c @@ -45,65 +45,65 @@ #endif static struct info { - Eina_List *context_list; - struct service_context *svc_ctx; + Eina_List *context_list; + struct service_context *svc_ctx; } s_info = { - .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ - .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ + .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ + .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ }; struct context { - struct tcb *tcb; - double seq; + struct tcb *tcb; + double seq; }; struct noti_service { - const char *cmd; - void (*handler)(struct tcb *tcb, struct packet *packet, void *data); - const char *rule; - const char *access; - void (*handler_access_error)(struct tcb *tcb, struct packet *packet); + const char *cmd; + void (*handler)(struct tcb *tcb, struct packet *packet, void *data); + const char *rule; + const char *access; + void (*handler_access_error)(struct tcb *tcb, struct packet *packet); }; static inline char *_string_get(char *string) { - if (string == NULL) { - return NULL; - } - if (string[0] == '\0') { - return NULL; - } - - return string; + if (string == NULL) { + return NULL; + } + if (string[0] == '\0') { + return NULL; + } + + return string; } /*! * FUNCTIONS to create packets */ static inline int _priv_id_get_from_list(int num_data, int *list, int index) { - if (index < num_data) { - return *(list + index); - } else { - return -1; - } + if (index < num_data) { + return *(list + index); + } else { + return -1; + } } static inline struct packet *_packet_create_with_list(int op_num, int *list, int start_index) { - return packet_create( - "del_noti_multiple", - "iiiiiiiiiii", - ((op_num - start_index) > NOTIFICATION_DEL_PACKET_UNIT) ? NOTIFICATION_DEL_PACKET_UNIT : op_num - start_index, - _priv_id_get_from_list(op_num, list, start_index), - _priv_id_get_from_list(op_num, list, start_index + 1), - _priv_id_get_from_list(op_num, list, start_index + 2), - _priv_id_get_from_list(op_num, list, start_index + 3), - _priv_id_get_from_list(op_num, list, start_index + 4), - _priv_id_get_from_list(op_num, list, start_index + 5), - _priv_id_get_from_list(op_num, list, start_index + 6), - _priv_id_get_from_list(op_num, list, start_index + 7), - _priv_id_get_from_list(op_num, list, start_index + 8), - _priv_id_get_from_list(op_num, list, start_index + 9) - ); + return packet_create( + "del_noti_multiple", + "iiiiiiiiiii", + ((op_num - start_index) > NOTIFICATION_DEL_PACKET_UNIT) ? NOTIFICATION_DEL_PACKET_UNIT : op_num - start_index, + _priv_id_get_from_list(op_num, list, start_index), + _priv_id_get_from_list(op_num, list, start_index + 1), + _priv_id_get_from_list(op_num, list, start_index + 2), + _priv_id_get_from_list(op_num, list, start_index + 3), + _priv_id_get_from_list(op_num, list, start_index + 4), + _priv_id_get_from_list(op_num, list, start_index + 5), + _priv_id_get_from_list(op_num, list, start_index + 6), + _priv_id_get_from_list(op_num, list, start_index + 7), + _priv_id_get_from_list(op_num, list, start_index + 8), + _priv_id_get_from_list(op_num, list, start_index + 9) + ); } /*! @@ -111,396 +111,396 @@ static inline struct packet *_packet_create_with_list(int op_num, int *list, int */ static void _handler_insert_noti(struct tcb *tcb, struct packet *packet, notification_h noti, void *data) { - int ret = 0, ret_p = 0; - int priv_id = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - - ret = notification_noti_insert(noti); - notification_get_id(noti, NULL, &priv_id); - DbgPrint("priv_id: [%d]\n", priv_id); - packet_reply = packet_create_reply(packet, "ii", ret, priv_id); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet: %d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } - - if (ret != NOTIFICATION_ERROR_NONE) { - ErrPrint("failed to insert a notification: %d\n", ret); - return ; - } - - packet_service = notification_ipc_make_packet_from_noti(noti, "add_noti", 2); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("failed to create a multicats packet\n"); - } + int ret = 0, ret_p = 0; + int priv_id = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + + ret = notification_noti_insert(noti); + notification_get_id(noti, NULL, &priv_id); + DbgPrint("priv_id: [%d]\n", priv_id); + packet_reply = packet_create_reply(packet, "ii", ret, priv_id); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet: %d\n", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } + + if (ret != NOTIFICATION_ERROR_NONE) { + ErrPrint("failed to insert a notification: %d\n", ret); + return ; + } + + packet_service = notification_ipc_make_packet_from_noti(noti, "add_noti", 2); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("failed to send a multicast packet: %d\n", ret_p); + } + packet_destroy(packet_service); + } else { + ErrPrint("failed to create a multicats packet\n"); + } } /*static void _handler_insert(struct tcb *tcb, struct packet *packet, void *data) // not used -{ - notification_h noti = NULL; - - noti = notification_create(NOTIFICATION_TYPE_NOTI); - if (noti != NULL) { - if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { - _handler_insert_noti(tcb, packet, noti, data); - } else { - ErrPrint("Failed to create the packet"); - } - notification_free(noti); - } -}*/ + { + notification_h noti = NULL; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if (noti != NULL) { + if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { + _handler_insert_noti(tcb, packet, noti, data); + } else { + ErrPrint("Failed to create the packet"); + } + notification_free(noti); + } + }*/ static void _handler_update_noti(struct tcb *tcb, struct packet *packet, notification_h noti, void *data) { - int ret = 0, ret_p = 0; - int priv_id = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - - ret = notification_noti_update(noti); - - notification_get_id(noti, NULL, &priv_id); - DbgPrint("priv_id: [%d]\n", priv_id); - packet_reply = packet_create_reply(packet, "ii", ret, priv_id); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } - - if (ret != NOTIFICATION_ERROR_NONE) { - ErrPrint("failed to update a notification:%d\n", ret); - return ; - } - - packet_service = notification_ipc_make_packet_from_noti(noti, "update_noti", 2); - if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } - packet_destroy(packet_service); - } + int ret = 0, ret_p = 0; + int priv_id = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + + ret = notification_noti_update(noti); + + notification_get_id(noti, NULL, &priv_id); + DbgPrint("priv_id: [%d]\n", priv_id); + packet_reply = packet_create_reply(packet, "ii", ret, priv_id); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } + + if (ret != NOTIFICATION_ERROR_NONE) { + ErrPrint("failed to update a notification:%d\n", ret); + return ; + } + + packet_service = notification_ipc_make_packet_from_noti(noti, "update_noti", 2); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("failed to send a multicast packet: %d\n", ret_p); + } + packet_destroy(packet_service); + } } static void _handler_update(struct tcb *tcb, struct packet *packet, void *data) { - notification_h noti = NULL; + notification_h noti = NULL; - noti = notification_create(NOTIFICATION_TYPE_NOTI); - if (noti != NULL) { - if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { - _handler_update_noti(tcb, packet, noti, data); - } else { - ErrPrint("Failed to create the packet"); - } - notification_free(noti); + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if (noti != NULL) { + if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { + _handler_update_noti(tcb, packet, noti, data); + } else { + ErrPrint("Failed to create the packet"); } + notification_free(noti); + } } static void _handler_check_noti_by_tag(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0; - notification_h noti = NULL; - - noti = notification_create(NOTIFICATION_TYPE_NOTI); - if (noti != NULL) { - if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { - ret = notification_noti_check_tag(noti); - if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID) { - _handler_insert_noti(tcb, packet, noti, data); - } else if (ret == NOTIFICATION_ERROR_ALREADY_EXIST_ID) { - _handler_update_noti(tcb, packet, noti, data); - } - } - notification_free(noti); - } + int ret = 0; + notification_h noti = NULL; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if (noti != NULL) { + if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { + ret = notification_noti_check_tag(noti); + if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID) { + _handler_insert_noti(tcb, packet, noti, data); + } else if (ret == NOTIFICATION_ERROR_ALREADY_EXIST_ID) { + _handler_update_noti(tcb, packet, noti, data); + } + } + notification_free(noti); + } } static void _handler_load_noti_by_tag(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - char* tag; - char* pkgname; - struct packet *packet_reply = NULL; - notification_h noti = NULL; - - noti = notification_create(NOTIFICATION_TYPE_NOTI); - if (noti != NULL) { - if (packet_get(packet, "ss", &pkgname, &tag) == 2) { - ret = notification_noti_get_by_tag(noti, pkgname, tag); - packet_reply = notification_ipc_make_reply_packet_from_noti(noti, packet); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet: %d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } - - if (ret != NOTIFICATION_ERROR_NONE) { - ErrPrint("failed to load_noti_by_tag : %d\n", ret); - notification_free(noti); - return ; - } - } else { - ErrPrint("Failed to create the packet"); + int ret = 0, ret_p = 0; + char* tag; + char* pkgname; + struct packet *packet_reply = NULL; + notification_h noti = NULL; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if (noti != NULL) { + if (packet_get(packet, "ss", &pkgname, &tag) == 2) { + ret = notification_noti_get_by_tag(noti, pkgname, tag); + packet_reply = notification_ipc_make_reply_packet_from_noti(noti, packet); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet: %d\n", ret_p); } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } + + if (ret != NOTIFICATION_ERROR_NONE) { + ErrPrint("failed to load_noti_by_tag : %d\n", ret); notification_free(noti); + return ; + } + } else { + ErrPrint("Failed to create the packet"); } + notification_free(noti); + } } static void _handler_refresh(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0; - struct packet *packet_reply = NULL; + int ret = 0; + struct packet *packet_reply = NULL; + + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } + + if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("failed to send a multicast packet:%d\n", ret); + } +} + +static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void *data) +{ + int num_changes = 0; + int ret = 0, ret_p = 0; + int priv_id = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + + if (packet_get(packet, "si", &pkgname, &priv_id) == 2) { + pkgname = _string_get(pkgname); + + ret = notification_noti_delete_by_priv_id_get_changes(pkgname, priv_id, &num_changes); - packet_reply = packet_create_reply(packet, "i", ret); + DbgPrint("priv_id: [%d] num_delete:%d\n", priv_id, num_changes); + packet_reply = packet_create_reply(packet, "ii", ret, priv_id); if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret); - } - packet_destroy(packet_reply); + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); } else { - ErrPrint("failed to create a reply packet\n"); + ErrPrint("failed to create a reply packet\n"); } - if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet:%d\n", ret); + if (ret != NOTIFICATION_ERROR_NONE || num_changes <= 0) { + ErrPrint("failed to delete a notification:%d %d\n", ret, num_changes); + return ; } + + packet_service = packet_create("del_noti_single", "ii", 1, priv_id); + if (packet_service != NULL) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("failed to send a multicast packet: %d\n", ret_p); + } + packet_destroy(packet_service); + } + } else { + ErrPrint("Failed to get data from the packet"); + } } -static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void *data) +static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, void *data) { - int num_changes = 0; - int ret = 0, ret_p = 0; - int priv_id = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - - if (packet_get(packet, "si", &pkgname, &priv_id) == 2) { - pkgname = _string_get(pkgname); - - ret = notification_noti_delete_by_priv_id_get_changes(pkgname, priv_id, &num_changes); - - DbgPrint("priv_id: [%d] num_delete:%d\n", priv_id, num_changes); - packet_reply = packet_create_reply(packet, "ii", ret, priv_id); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + struct packet *packet_service = NULL; + char *pkgname = NULL; + notification_type_e type = 0; + int num_deleted = 0; + int *list_deleted = NULL; + + if (packet_get(packet, "si", &pkgname, &type) == 2) { + pkgname = _string_get(pkgname); + DbgPrint("pkgname: [%s] type: [%d]\n", pkgname, type); + + ret = notification_noti_delete_all(type, pkgname, &num_deleted, &list_deleted); + DbgPrint("ret: [%d] num_deleted: [%d]\n", ret, num_deleted); + + packet_reply = packet_create_reply(packet, "ii", ret, num_deleted); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } + + if (ret != NOTIFICATION_ERROR_NONE) { + ErrPrint("failed to delete notifications:%d\n", ret); + if (list_deleted != NULL) { + DbgFree(list_deleted); + } + return ; + } + + if (num_deleted > 0) { + if (num_deleted <= NOTIFICATION_DEL_PACKET_UNIT) { + packet_service = _packet_create_with_list(num_deleted, list_deleted, 0); + + if (packet_service) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("failed to send a multicast packet: %d\n", ret_p); + } + packet_destroy(packet_service); } else { - ErrPrint("failed to create a reply packet\n"); + ErrPrint("failed to create a multicast packet\n"); } + } else { + int set = 0; + int set_total = num_deleted / NOTIFICATION_DEL_PACKET_UNIT; - if (ret != NOTIFICATION_ERROR_NONE || num_changes <= 0) { - ErrPrint("failed to delete a notification:%d %d\n", ret, num_changes); - return ; - } + for (set = 0; set <= set_total; set++) { + packet_service = _packet_create_with_list(num_deleted, + list_deleted, set * NOTIFICATION_DEL_PACKET_UNIT); - packet_service = packet_create("del_noti_single", "ii", 1, priv_id); - if (packet_service != NULL) { + if (packet_service) { if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet: %d\n", ret_p); + ErrPrint("failed to send a multicast packet:%d\n", ret_p); } packet_destroy(packet_service); + } else { + ErrPrint("failed to create a multicast packet\n"); + } } - } else { - ErrPrint("Failed to get data from the packet"); + } + } + + if (list_deleted != NULL) { + DbgFree(list_deleted); + list_deleted = NULL; } + } else { + ErrPrint("Failed to get data from the packet"); + } } -static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, void *data) +static void _handler_noti_property_set(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - struct packet *packet_service = NULL; - char *pkgname = NULL; - notification_type_e type = 0; - int num_deleted = 0; - int *list_deleted = NULL; - - if (packet_get(packet, "si", &pkgname, &type) == 2) { - pkgname = _string_get(pkgname); - DbgPrint("pkgname: [%s] type: [%d]\n", pkgname, type); - - ret = notification_noti_delete_all(type, pkgname, &num_deleted, &list_deleted); - DbgPrint("ret: [%d] num_deleted: [%d]\n", ret, num_deleted); - - packet_reply = packet_create_reply(packet, "ii", ret, num_deleted); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + char *pkgname = NULL; + char *property = NULL; + char *value = NULL; - if (ret != NOTIFICATION_ERROR_NONE) { - ErrPrint("failed to delete notifications:%d\n", ret); - if (list_deleted != NULL) { - DbgFree(list_deleted); - } - return ; - } + if (packet_get(packet, "sss", &pkgname, &property, &value) == 3) { + pkgname = _string_get(pkgname); + property = _string_get(property); + value = _string_get(value); - if (num_deleted > 0) { - if (num_deleted <= NOTIFICATION_DEL_PACKET_UNIT) { - packet_service = _packet_create_with_list(num_deleted, list_deleted, 0); - - if (packet_service) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("failed to create a multicast packet\n"); - } - } else { - int set = 0; - int set_total = num_deleted / NOTIFICATION_DEL_PACKET_UNIT; - - for (set = 0; set <= set_total; set++) { - packet_service = _packet_create_with_list(num_deleted, - list_deleted, set * NOTIFICATION_DEL_PACKET_UNIT); - - if (packet_service) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet:%d\n", ret_p); - } - packet_destroy(packet_service); - } else { - ErrPrint("failed to create a multicast packet\n"); - } - } - } - } + ret = notification_setting_db_set(pkgname, property, value); - if (list_deleted != NULL) { - DbgFree(list_deleted); - list_deleted = NULL; - } + packet_reply = packet_create_reply(packet, "ii", ret, ret); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); } else { - ErrPrint("Failed to get data from the packet"); + ErrPrint("failed to create a reply packet\n"); } -} - -static void _handler_noti_property_set(struct tcb *tcb, struct packet *packet, void *data) -{ - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - char *pkgname = NULL; - char *property = NULL; - char *value = NULL; - - if (packet_get(packet, "sss", &pkgname, &property, &value) == 3) { - pkgname = _string_get(pkgname); - property = _string_get(property); - value = _string_get(value); - - ret = notification_setting_db_set(pkgname, property, value); - - packet_reply = packet_create_reply(packet, "ii", ret, ret); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } - if (ret != NOTIFICATION_ERROR_NONE) { - ErrPrint("failed to set noti property:%d\n", ret); - } - } else { - ErrPrint("Failed to get data from the packet"); + if (ret != NOTIFICATION_ERROR_NONE) { + ErrPrint("failed to set noti property:%d\n", ret); } + } else { + ErrPrint("Failed to get data from the packet"); + } } static void _handler_noti_property_get(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0, ret_p = 0; - struct packet *packet_reply = NULL; - char *pkgname = NULL; - char *property = NULL; - char *value = NULL; - - if (packet_get(packet, "sss", &pkgname, &property) == 2) { - pkgname = _string_get(pkgname); - property = _string_get(property); - - ret = notification_setting_db_get(pkgname, property, &value); - - packet_reply = packet_create_reply(packet, "is", ret, value); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); - } + int ret = 0, ret_p = 0; + struct packet *packet_reply = NULL; + char *pkgname = NULL; + char *property = NULL; + char *value = NULL; - if (value != NULL) { - DbgFree(value); - } + if (packet_get(packet, "sss", &pkgname, &property) == 2) { + pkgname = _string_get(pkgname); + property = _string_get(property); + + ret = notification_setting_db_get(pkgname, property, &value); + + packet_reply = packet_create_reply(packet, "is", ret, value); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); } + + if (value != NULL) { + DbgFree(value); + } + } } static void _handler_service_register(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0; - struct packet *packet_reply; + int ret = 0; + struct packet *packet_reply; - ret = tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); + ret = tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret); } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } } static void _handler_post_toast_message(struct tcb *tcb, struct packet *packet, void *data) { - int ret = 0; - struct packet *packet_reply = NULL; + int ret = 0; + struct packet *packet_reply = NULL; - packet_reply = packet_create_reply(packet, "i", ret); - if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("failed to send reply packet:%d\n", ret); - } - packet_destroy(packet_reply); - } else { - ErrPrint("failed to create a reply packet\n"); + packet_reply = packet_create_reply(packet, "i", ret); + if (packet_reply) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("failed to send reply packet:%d\n", ret); } + packet_destroy(packet_reply); + } else { + ErrPrint("failed to create a reply packet\n"); + } - if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) { - ErrPrint("failed to send a multicast packet:%d\n", ret); - } + if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) { + ErrPrint("failed to send a multicast packet:%d\n", ret); + } } @@ -509,65 +509,65 @@ static void _handler_post_toast_message(struct tcb *tcb, struct packet *packet, */ static void _permission_check_common(struct tcb *tcb, struct packet *packet) { - int ret_p = 0; - struct packet *packet_reply = NULL; - - packet_reply = packet_create_reply(packet, "ii", NOTIFICATION_ERROR_PERMISSION_DENIED, 0); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + int ret_p = 0; + struct packet *packet_reply = NULL; + + packet_reply = packet_create_reply(packet, "ii", NOTIFICATION_ERROR_PERMISSION_DENIED, 0); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } } static void _permission_check_refresh(struct tcb *tcb, struct packet *packet) { - int ret_p = 0; - struct packet *packet_reply = NULL; - - packet_reply = packet_create_reply(packet, "i", NOTIFICATION_ERROR_PERMISSION_DENIED); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + int ret_p = 0; + struct packet *packet_reply = NULL; + + packet_reply = packet_create_reply(packet, "i", NOTIFICATION_ERROR_PERMISSION_DENIED); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } } static void _permission_check_property_get(struct tcb *tcb, struct packet *packet) { - int ret_p = 0; - struct packet *packet_reply = NULL; - - packet_reply = packet_create_reply(packet, "is", NOTIFICATION_ERROR_PERMISSION_DENIED, NULL); - if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { - ErrPrint("Failed to send a reply packet:%d", ret_p); - } - packet_destroy(packet_reply); - } else { - ErrPrint("Failed to create a reply packet"); - } + int ret_p = 0; + struct packet *packet_reply = NULL; + + packet_reply = packet_create_reply(packet, "is", NOTIFICATION_ERROR_PERMISSION_DENIED, NULL); + if (packet_reply) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + ErrPrint("Failed to send a reply packet:%d", ret_p); + } + packet_destroy(packet_reply); + } else { + ErrPrint("Failed to create a reply packet"); + } } static int _persmission_check(int fd, struct noti_service *service) { - int ret; + int ret; - if (service->rule != NULL && service->access != NULL) { - ret = security_server_check_privilege_by_sockfd(fd, service->rule, service->access); - if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { - ErrPrint("SMACK:Access denied\n"); - return 0; - } + if (service->rule != NULL && service->access != NULL) { + ret = security_server_check_privilege_by_sockfd(fd, service->rule, service->access); + if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ErrPrint("SMACK:Access denied\n"); + return 0; } + } - return 1; + return 1; } /*! @@ -575,46 +575,46 @@ static int _persmission_check(int fd, struct noti_service *service) */ static void _notification_data_init(void) { - int property = 0; - int priv_id = 0; - char *noti_pkgname = NULL; - notification_h noti = NULL; - notification_list_h noti_list = NULL; - notification_list_h noti_list_head = NULL; - notification_type_e noti_type = NOTIFICATION_TYPE_NONE; - - notification_get_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); - noti_list_head = noti_list; - - while (noti_list != NULL) { - noti = notification_list_get_data(noti_list); - if (noti) { - notification_get_id(noti, NULL, &priv_id); - notification_get_pkgname(noti, ¬i_pkgname); - notification_get_property(noti, &property); - notification_get_type(noti, ¬i_type); - - if (noti_type == NOTIFICATION_TYPE_ONGOING - || property & NOTIFICATION_PROP_VOLATILE_DISPLAY) { - notification_noti_delete_by_priv_id(noti_pkgname, priv_id); - } - } - noti_list = notification_list_get_next(noti_list); - } - - if (noti_list_head != NULL) { - notification_free_list(noti_list_head); - } + int property = 0; + int priv_id = 0; + char *noti_pkgname = NULL; + notification_h noti = NULL; + notification_list_h noti_list = NULL; + notification_list_h noti_list_head = NULL; + notification_type_e noti_type = NOTIFICATION_TYPE_NONE; + + notification_get_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + noti_list_head = noti_list; + + while (noti_list != NULL) { + noti = notification_list_get_data(noti_list); + if (noti) { + notification_get_id(noti, NULL, &priv_id); + notification_get_pkgname(noti, ¬i_pkgname); + notification_get_property(noti, &property); + notification_get_type(noti, ¬i_type); + + if (noti_type == NOTIFICATION_TYPE_ONGOING + || property & NOTIFICATION_PROP_VOLATILE_DISPLAY) { + notification_noti_delete_by_priv_id(noti_pkgname, priv_id); + } + } + noti_list = notification_list_get_next(noti_list); + } + + if (noti_list_head != NULL) { + notification_free_list(noti_list_head); + } } static void _notification_init(void) { - int ret = -1; - int restart_count = 0; + int ret = -1; + int restart_count = 0; - ret = vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count); - if (ret == 0 && restart_count <= 1) { - _notification_data_init(); - } + ret = vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count); + if (ret == 0 && restart_count <= 1) { + _notification_data_init(); + } } /*! @@ -622,135 +622,135 @@ static void _notification_init(void) { */ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data) { - int i = 0; - const char *command; - - static struct noti_service service_req_table[] = { - { - .cmd = "add_noti", - .handler = _handler_check_noti_by_tag, - .rule = "data-provider-master::notification.client", - .access = "w", - .handler_access_error = _permission_check_common, - }, - { - .cmd = "update_noti", - .handler = _handler_update, - .rule = "data-provider-master::notification.client", - .access = "w", - .handler_access_error = _permission_check_common, - }, - { - .cmd = "load_noti_by_tag", - .handler = _handler_load_noti_by_tag, - .rule = "data-provider-master::notification.client", - .access = "r", - .handler_access_error = _permission_check_common, - }, - { - .cmd = "refresh_noti", - .handler = _handler_refresh, - .rule = "data-provider-master::notification.client", - .access = "w", - .handler_access_error = _permission_check_refresh, - }, - { - .cmd = "del_noti_single", - .handler = _handler_delete_single, - .rule = "data-provider-master::notification.client", - .access = "w", - .handler_access_error = _permission_check_common, - }, - { - .cmd = "del_noti_multiple", - .handler = _handler_delete_multiple, - .rule = "data-provider-master::notification.client", - .access = "w", - .handler_access_error = _permission_check_common, - }, - { - .cmd = "set_noti_property", - .handler = _handler_noti_property_set, - .rule = "data-provider-master::notification.client", - .access = "w", - .handler_access_error = _permission_check_common, - }, - { - .cmd = "get_noti_property", - .handler = _handler_noti_property_get, - .rule = "data-provider-master::notification.client", - .access = "r", - .handler_access_error = _permission_check_property_get, - }, - { - .cmd = "service_register", - .handler = _handler_service_register, - .rule = NULL, - .access = NULL, - .handler_access_error = NULL, - }, - { - .cmd = "post_toast", - .handler = _handler_post_toast_message, - .rule = NULL, - .access = NULL, - .handler_access_error = NULL, - }, - { - .cmd = NULL, - .handler = NULL, - .rule = NULL, - .access = NULL, - .handler_access_error = NULL, - }, - }; - - if (!packet) { - DbgPrint("TCB: %p is terminated\n", tcb); - return 0; - } + int i = 0; + const char *command; + + static struct noti_service service_req_table[] = { + { + .cmd = "add_noti", + .handler = _handler_check_noti_by_tag, + .rule = "data-provider-master::notification.client", + .access = "w", + .handler_access_error = _permission_check_common, + }, + { + .cmd = "update_noti", + .handler = _handler_update, + .rule = "data-provider-master::notification.client", + .access = "w", + .handler_access_error = _permission_check_common, + }, + { + .cmd = "load_noti_by_tag", + .handler = _handler_load_noti_by_tag, + .rule = "data-provider-master::notification.client", + .access = "r", + .handler_access_error = _permission_check_common, + }, + { + .cmd = "refresh_noti", + .handler = _handler_refresh, + .rule = "data-provider-master::notification.client", + .access = "w", + .handler_access_error = _permission_check_refresh, + }, + { + .cmd = "del_noti_single", + .handler = _handler_delete_single, + .rule = "data-provider-master::notification.client", + .access = "w", + .handler_access_error = _permission_check_common, + }, + { + .cmd = "del_noti_multiple", + .handler = _handler_delete_multiple, + .rule = "data-provider-master::notification.client", + .access = "w", + .handler_access_error = _permission_check_common, + }, + { + .cmd = "set_noti_property", + .handler = _handler_noti_property_set, + .rule = "data-provider-master::notification.client", + .access = "w", + .handler_access_error = _permission_check_common, + }, + { + .cmd = "get_noti_property", + .handler = _handler_noti_property_get, + .rule = "data-provider-master::notification.client", + .access = "r", + .handler_access_error = _permission_check_property_get, + }, + { + .cmd = "service_register", + .handler = _handler_service_register, + .rule = NULL, + .access = NULL, + .handler_access_error = NULL, + }, + { + .cmd = "post_toast", + .handler = _handler_post_toast_message, + .rule = NULL, + .access = NULL, + .handler_access_error = NULL, + }, + { + .cmd = NULL, + .handler = NULL, + .rule = NULL, + .access = NULL, + .handler_access_error = NULL, + }, + }; + + if (!packet) { + DbgPrint("TCB: %p is terminated\n", tcb); + return 0; + } - command = packet_command(packet); - if (!command) { - ErrPrint("Invalid command\n"); - return -EINVAL; - } + command = packet_command(packet); + if (!command) { + ErrPrint("Invalid command\n"); + return -EINVAL; + } - switch (packet_type(packet)) { + switch (packet_type(packet)) { case PACKET_REQ: - /* Need to send reply packet */ - DbgPrint("%p REQ: Command: [%s]\n", tcb, command); + /* Need to send reply packet */ + DbgPrint("%p REQ: Command: [%s]\n", tcb, command); - for (i = 0; service_req_table[i].cmd; i++) { - if (strcmp(service_req_table[i].cmd, command)) { - continue; - } - - if (_persmission_check(tcb_fd(tcb), &(service_req_table[i])) == 1) { - service_req_table[i].handler(tcb, packet, data); - } else { - if (service_req_table[i].handler_access_error != NULL) { - service_req_table[i].handler_access_error(tcb, packet); - } - } - break; + for (i = 0; service_req_table[i].cmd; i++) { + if (strcmp(service_req_table[i].cmd, command)) { + continue; } + if (_persmission_check(tcb_fd(tcb), &(service_req_table[i])) == 1) { + service_req_table[i].handler(tcb, packet, data); + } else { + if (service_req_table[i].handler_access_error != NULL) { + service_req_table[i].handler_access_error(tcb, packet); + } + } break; + } + + break; case PACKET_REQ_NOACK: - break; + break; case PACKET_ACK: - break; + break; default: - ErrPrint("Packet type is not valid[%s]\n", command); - return -EINVAL; - } - - /*! - * return value has no meanning, - * it will be printed by dlogutil. - */ - return 0; + ErrPrint("Packet type is not valid[%s]\n", command); + return -EINVAL; + } + + /*! + * return value has no meanning, + * it will be printed by dlogutil. + */ + return 0; } @@ -760,51 +760,51 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat */ HAPI int notification_service_init(void) { - if (s_info.svc_ctx) { - ErrPrint("Already initialized\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - _notification_init(); - - s_info.svc_ctx = service_common_create(NOTIFICATION_SOCKET, service_thread_main, NULL); - if (!s_info.svc_ctx) { - ErrPrint("Unable to activate service thread\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), NOTIFICATION_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } - } - - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), NOTIFICATION_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } - } - - DbgPrint("Successfully initiated\n"); - return DBOX_STATUS_ERROR_NONE; + if (s_info.svc_ctx) { + ErrPrint("Already initialized\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + _notification_init(); + + s_info.svc_ctx = service_common_create(NOTIFICATION_SOCKET, service_thread_main, NULL); + if (!s_info.svc_ctx) { + ErrPrint("Unable to activate service thread\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), NOTIFICATION_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; + } + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), NOTIFICATION_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; + } + } + + DbgPrint("Successfully initiated\n"); + return DBOX_STATUS_ERROR_NONE; } HAPI int notification_service_fini(void) { - if (!s_info.svc_ctx) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - DbgPrint("Successfully Finalized\n"); - return DBOX_STATUS_ERROR_NONE; + if (!s_info.svc_ctx) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + DbgPrint("Successfully Finalized\n"); + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/package.c b/src/package.c index 16da610..5b3ae32 100644 --- a/src/package.c +++ b/src/package.c @@ -50,9 +50,9 @@ int errno; struct fault_info { - double timestamp; - char *filename; - char *function; + double timestamp; + char *filename; + char *function; }; /*! @@ -60,999 +60,999 @@ struct fault_info { */ struct pkg_info { - char *pkgid; - char *dbox_id; - - struct { - enum dynamicbox_dbox_type type; - - union { - struct { - char *path; - char *group; - } script; - - struct { - /*!< Reserved for future use */ - } file; - - struct { - /*!< Reserved for future use */ - } text; - - struct { - /*!< Reserved for future use */ - } buffer; - } info; - - unsigned int size_list; - char *auto_launch; - int pinup; - int timeout; - double period; - char *libexec; - } dbox; - - struct { - enum dynamicbox_gbar_type type; - - union { - struct { - char *path; - char *group; - } script; - - struct { - /*!< Reserved for future use */ - } text; - - struct { - /*!< Reserved for future use */ - } buffer; - } info; - - unsigned int width; - unsigned int height; - } gbar; - - int network; - int secured; - char *script; /* script type: edje, ... */ - char *abi; - - int fault_count; - struct fault_info *fault_info; - - struct slave_node *slave; - int refcnt; - - Eina_List *inst_list; - Eina_List *ctx_list; - - int is_uninstalled; + char *pkgid; + char *dbox_id; + + struct { + enum dynamicbox_dbox_type type; + + union { + struct { + char *path; + char *group; + } script; + + struct { + /*!< Reserved for future use */ + } file; + + struct { + /*!< Reserved for future use */ + } text; + + struct { + /*!< Reserved for future use */ + } buffer; + } info; + + unsigned int size_list; + char *auto_launch; + int pinup; + int timeout; + double period; + char *libexec; + } dbox; + + struct { + enum dynamicbox_gbar_type type; + + union { + struct { + char *path; + char *group; + } script; + + struct { + /*!< Reserved for future use */ + } text; + + struct { + /*!< Reserved for future use */ + } buffer; + } info; + + unsigned int width; + unsigned int height; + } gbar; + + int network; + int secured; + char *script; /* script type: edje, ... */ + char *abi; + + int fault_count; + struct fault_info *fault_info; + + struct slave_node *slave; + int refcnt; + + Eina_List *inst_list; + Eina_List *ctx_list; + + int is_uninstalled; }; static struct { - Eina_List *pkg_list; + Eina_List *pkg_list; } s_info = { - .pkg_list = NULL, + .pkg_list = NULL, }; static int slave_activated_cb(struct slave_node *slave, void *data) { - struct pkg_info *info = data; - struct inst_info *inst; - Eina_List *l; - Eina_List *n; - int cnt; - int ret; + struct pkg_info *info = data; + struct inst_info *inst; + Eina_List *l; + Eina_List *n; + int cnt; + int ret; - if (!slave_need_to_reactivate_instances(slave)) { - DbgPrint("Do not need to reactivate instances\n"); - return 0; - } - - cnt = 0; - EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { - ret = instance_recover_state(inst); - if (!ret) { - continue; - } + if (!slave_need_to_reactivate_instances(slave)) { + DbgPrint("Do not need to reactivate instances\n"); + return 0; + } - instance_thaw_updator(inst); - cnt++; + cnt = 0; + EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { + ret = instance_recover_state(inst); + if (!ret) { + continue; } - DbgPrint("Recover state for %d instances of %s\n", cnt, package_name(info)); - return 0; + instance_thaw_updator(inst); + cnt++; + } + + DbgPrint("Recover state for %d instances of %s\n", cnt, package_name(info)); + return 0; } static int slave_fault_cb(struct slave_node *slave, void *data) { - Eina_List *l; - Eina_List *n; - struct inst_info *inst; - struct pkg_info *info = (struct pkg_info *)data; + Eina_List *l; + Eina_List *n; + struct inst_info *inst; + struct pkg_info *info = (struct pkg_info *)data; - if (package_is_fault(info)) { - ErrPrint("Already faulted package: %s\n", package_name(info)); - return 0; - } + if (package_is_fault(info)) { + ErrPrint("Already faulted package: %s\n", package_name(info)); + return 0; + } - (void)package_set_fault_info(info, util_timestamp(), slave_name(slave), __func__); - fault_broadcast_info(package_name(info), slave_name(slave), __func__); + (void)package_set_fault_info(info, util_timestamp(), slave_name(slave), __func__); + fault_broadcast_info(package_name(info), slave_name(slave), __func__); - DbgPrint("Slave critical fault - package: %s (by slave fault %s\n", package_name(info), slave_name(slave)); - EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { - DbgPrint("Destroy instance %p\n", inst); - instance_destroyed(inst, DBOX_STATUS_ERROR_FAULT); - } + DbgPrint("Slave critical fault - package: %s (by slave fault %s\n", package_name(info), slave_name(slave)); + EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { + DbgPrint("Destroy instance %p\n", inst); + instance_destroyed(inst, DBOX_STATUS_ERROR_FAULT); + } - return 0; + return 0; } static int slave_deactivated_cb(struct slave_node *slave, void *data) { - struct pkg_info *info = data; - struct inst_info *inst; - Eina_List *l; - Eina_List *n; - int cnt = 0; + struct pkg_info *info = data; + struct inst_info *inst; + Eina_List *l; + Eina_List *n; + int cnt = 0; - if (info->fault_info) { - EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { - instance_destroyed(inst, DBOX_STATUS_ERROR_FAULT); - } - } else { - EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { - cnt += instance_need_slave(inst); - /*! - * instance_deactivated will call the slave_unload_instance. - * if the loaded instance counter meets 0, - * the slave will be deactivated. - * so we should not call the instance activate function - * from here. - * - * activate slave when the slave is reactivated - */ - } + if (info->fault_info) { + EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { + instance_destroyed(inst, DBOX_STATUS_ERROR_FAULT); + } + } else { + EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { + cnt += instance_need_slave(inst); + /*! + * instance_deactivated will call the slave_unload_instance. + * if the loaded instance counter meets 0, + * the slave will be deactivated. + * so we should not call the instance activate function + * from here. + * + * activate slave when the slave is reactivated + */ } + } - return cnt ? SLAVE_NEED_TO_REACTIVATE : 0; + return cnt ? SLAVE_NEED_TO_REACTIVATE : 0; } static int xmonitor_paused_cb(void *data) { - struct pkg_info *info = (struct pkg_info *)data; - struct inst_info *inst; - Eina_List *l; + struct pkg_info *info = (struct pkg_info *)data; + struct inst_info *inst; + Eina_List *l; - if (slave_state(info->slave) != SLAVE_TERMINATED) { - return 0; - } + if (slave_state(info->slave) != SLAVE_TERMINATED) { + return 0; + } - EINA_LIST_FOREACH(info->inst_list, l, inst) { - instance_freeze_updator(inst); - } + EINA_LIST_FOREACH(info->inst_list, l, inst) { + instance_freeze_updator(inst); + } - return 0; + return 0; } static int xmonitor_resumed_cb(void *data) { - struct pkg_info *info = data; - struct inst_info *inst; - Eina_List *l; + struct pkg_info *info = data; + struct inst_info *inst; + Eina_List *l; - if (slave_state(info->slave) != SLAVE_TERMINATED) { - return 0; - } + if (slave_state(info->slave) != SLAVE_TERMINATED) { + return 0; + } - EINA_LIST_FOREACH(info->inst_list, l, inst) { - instance_thaw_updator(inst); - } + EINA_LIST_FOREACH(info->inst_list, l, inst) { + instance_thaw_updator(inst); + } - return 0; + return 0; } static int slave_paused_cb(struct slave_node *slave, void *data) { - struct pkg_info *info = (struct pkg_info *)data; - struct inst_info *inst; - Eina_List *l; + struct pkg_info *info = (struct pkg_info *)data; + struct inst_info *inst; + Eina_List *l; - EINA_LIST_FOREACH(info->inst_list, l, inst) { - instance_freeze_updator(inst); - } + EINA_LIST_FOREACH(info->inst_list, l, inst) { + instance_freeze_updator(inst); + } - return 0; + return 0; } static int slave_resumed_cb(struct slave_node *slave, void *data) { - struct pkg_info *info = (struct pkg_info *)data; - struct inst_info *inst; - Eina_List *l; + struct pkg_info *info = (struct pkg_info *)data; + struct inst_info *inst; + Eina_List *l; - EINA_LIST_FOREACH(info->inst_list, l, inst) { - instance_thaw_updator(inst); - } + EINA_LIST_FOREACH(info->inst_list, l, inst) { + instance_thaw_updator(inst); + } - return 0; + return 0; } static inline void destroy_package(struct pkg_info *info) { - eina_list_free(info->ctx_list); - /* This items will be deleted from group_del_dynamicbox */ - info->ctx_list = NULL; + eina_list_free(info->ctx_list); + /* This items will be deleted from group_del_dynamicbox */ + info->ctx_list = NULL; - group_del_dynamicbox(info->dbox_id); - package_clear_fault(info); + group_del_dynamicbox(info->dbox_id); + package_clear_fault(info); - s_info.pkg_list = eina_list_remove(s_info.pkg_list, info); + s_info.pkg_list = eina_list_remove(s_info.pkg_list, info); - if (info->dbox.type == DBOX_TYPE_SCRIPT) { - DbgFree(info->dbox.info.script.path); - DbgFree(info->dbox.info.script.group); - } + if (info->dbox.type == DBOX_TYPE_SCRIPT) { + DbgFree(info->dbox.info.script.path); + DbgFree(info->dbox.info.script.group); + } - if (info->gbar.type == GBAR_TYPE_SCRIPT) { - DbgFree(info->gbar.info.script.path); - DbgFree(info->gbar.info.script.group); - } + if (info->gbar.type == GBAR_TYPE_SCRIPT) { + DbgFree(info->gbar.info.script.path); + DbgFree(info->gbar.info.script.group); + } - DbgFree(info->script); - DbgFree(info->abi); - DbgFree(info->dbox_id); - DbgFree(info->dbox.libexec); - DbgFree(info->dbox.auto_launch); - DbgFree(info->pkgid); + DbgFree(info->script); + DbgFree(info->abi); + DbgFree(info->dbox_id); + DbgFree(info->dbox.libexec); + DbgFree(info->dbox.auto_launch); + DbgFree(info->pkgid); - DbgFree(info); + DbgFree(info); } static inline int load_conf(struct pkg_info *info) { - struct parser *parser; - const char *str; - const char *group; - - parser = parser_load(info->dbox_id); - if (!parser) { - info->dbox.size_list = 0x01; /* Default */ - - info->script = strdup(DYNAMICBOX_CONF_DEFAULT_SCRIPT); - if (!info->script) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + struct parser *parser; + const char *str; + const char *group; - info->abi = strdup(DYNAMICBOX_CONF_DEFAULT_ABI); - if (!info->abi) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info->script); - info->script = NULL; - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - info->gbar.width = DYNAMICBOX_CONF_BASE_W; - info->gbar.height = DYNAMICBOX_CONF_BASE_H >> 2; - info->dbox.pinup = 1; - return DBOX_STATUS_ERROR_NONE; - } - - info->dbox.type = DBOX_TYPE_FILE; - if (parser_text_dbox(parser)) { - info->dbox.type = DBOX_TYPE_TEXT; - } else if (parser_buffer_dbox(parser)) { - info->dbox.type = DBOX_TYPE_BUFFER; - } else { - str = parser_dbox_path(parser); - if (str) { - info->dbox.type = DBOX_TYPE_SCRIPT; - - info->dbox.info.script.path = strdup(str); - if (!info->dbox.info.script.path) { - ErrPrint("Heap: %s\n", strerror(errno)); - parser_unload(parser); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + parser = parser_load(info->dbox_id); + if (!parser) { + info->dbox.size_list = 0x01; /* Default */ - str = parser_dbox_group(parser); - if (str) { - info->dbox.info.script.group = strdup(str); - if (!info->dbox.info.script.group) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info->dbox.info.script.path); - parser_unload(parser); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - } + info->script = strdup(DYNAMICBOX_CONF_DEFAULT_SCRIPT); + if (!info->script) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; } - if (parser_text_gbar(parser)) { - info->gbar.type = GBAR_TYPE_TEXT; - } else if (parser_buffer_gbar(parser)) { - info->gbar.type = GBAR_TYPE_BUFFER; - } else { - str = parser_gbar_path(parser); - if (str) { - info->gbar.type = GBAR_TYPE_SCRIPT; - info->gbar.info.script.path = strdup(str); - if (!info->gbar.info.script.path) { - ErrPrint("Heap: %s\n", strerror(errno)); - if (info->dbox.type == DBOX_TYPE_SCRIPT) { - DbgFree(info->dbox.info.script.path); - DbgFree(info->dbox.info.script.group); - } - parser_unload(parser); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - str = parser_gbar_group(parser); - if (str) { - info->gbar.info.script.group = strdup(str); - if (!info->gbar.info.script.group) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info->gbar.info.script.path); - if (info->dbox.type == DBOX_TYPE_SCRIPT) { - DbgFree(info->dbox.info.script.path); - DbgFree(info->dbox.info.script.group); - } - parser_unload(parser); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - } + info->abi = strdup(DYNAMICBOX_CONF_DEFAULT_ABI); + if (!info->abi) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info->script); + info->script = NULL; + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; } - str = parser_script(parser); - str = str ? str : DYNAMICBOX_CONF_DEFAULT_SCRIPT; - info->script = strdup(str); - if (!info->script) { + info->gbar.width = DYNAMICBOX_CONF_BASE_W; + info->gbar.height = DYNAMICBOX_CONF_BASE_H >> 2; + info->dbox.pinup = 1; + return DBOX_STATUS_ERROR_NONE; + } + + info->dbox.type = DBOX_TYPE_FILE; + if (parser_text_dbox(parser)) { + info->dbox.type = DBOX_TYPE_TEXT; + } else if (parser_buffer_dbox(parser)) { + info->dbox.type = DBOX_TYPE_BUFFER; + } else { + str = parser_dbox_path(parser); + if (str) { + info->dbox.type = DBOX_TYPE_SCRIPT; + + info->dbox.info.script.path = strdup(str); + if (!info->dbox.info.script.path) { ErrPrint("Heap: %s\n", strerror(errno)); - if (info->gbar.type == GBAR_TYPE_SCRIPT) { - DbgFree(info->gbar.info.script.path); - DbgFree(info->gbar.info.script.group); + parser_unload(parser); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + str = parser_dbox_group(parser); + if (str) { + info->dbox.info.script.group = strdup(str); + if (!info->dbox.info.script.group) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info->dbox.info.script.path); + parser_unload(parser); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; } - + } + } + } + + if (parser_text_gbar(parser)) { + info->gbar.type = GBAR_TYPE_TEXT; + } else if (parser_buffer_gbar(parser)) { + info->gbar.type = GBAR_TYPE_BUFFER; + } else { + str = parser_gbar_path(parser); + if (str) { + info->gbar.type = GBAR_TYPE_SCRIPT; + info->gbar.info.script.path = strdup(str); + if (!info->gbar.info.script.path) { + ErrPrint("Heap: %s\n", strerror(errno)); if (info->dbox.type == DBOX_TYPE_SCRIPT) { - DbgFree(info->dbox.info.script.path); - DbgFree(info->dbox.info.script.group); + DbgFree(info->dbox.info.script.path); + DbgFree(info->dbox.info.script.group); } - parser_unload(parser); return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - str = parser_abi(parser); - str = str ? str : DYNAMICBOX_CONF_DEFAULT_ABI; - info->abi = strdup(str); - if (!info->abi) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info->script); - if (info->gbar.type == GBAR_TYPE_SCRIPT) { - DbgFree(info->gbar.info.script.path); - DbgFree(info->gbar.info.script.group); - } - - if (info->dbox.type == DBOX_TYPE_SCRIPT) { + } + + str = parser_gbar_group(parser); + if (str) { + info->gbar.info.script.group = strdup(str); + if (!info->gbar.info.script.group) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info->gbar.info.script.path); + if (info->dbox.type == DBOX_TYPE_SCRIPT) { DbgFree(info->dbox.info.script.path); DbgFree(info->dbox.info.script.group); + } + parser_unload(parser); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; } - parser_unload(parser); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } } + } - info->dbox.timeout = parser_timeout(parser); - info->network = parser_network(parser); + str = parser_script(parser); + str = str ? str : DYNAMICBOX_CONF_DEFAULT_SCRIPT; + info->script = strdup(str); + if (!info->script) { + ErrPrint("Heap: %s\n", strerror(errno)); + if (info->gbar.type == GBAR_TYPE_SCRIPT) { + DbgFree(info->gbar.info.script.path); + DbgFree(info->gbar.info.script.group); + } - info->dbox.period = parser_period(parser); - if (info->dbox.period < 0.0f) { - info->dbox.period = 0.0f; - } else if (info->dbox.period > 0.0f && info->dbox.period < DYNAMICBOX_CONF_MINIMUM_PERIOD) { - info->dbox.period = DYNAMICBOX_CONF_MINIMUM_PERIOD; + if (info->dbox.type == DBOX_TYPE_SCRIPT) { + DbgFree(info->dbox.info.script.path); + DbgFree(info->dbox.info.script.group); } - info->dbox.size_list = parser_size(parser); + parser_unload(parser); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + str = parser_abi(parser); + str = str ? str : DYNAMICBOX_CONF_DEFAULT_ABI; + info->abi = strdup(str); + if (!info->abi) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info->script); + if (info->gbar.type == GBAR_TYPE_SCRIPT) { + DbgFree(info->gbar.info.script.path); + DbgFree(info->gbar.info.script.group); + } - str = parser_auto_launch(parser); - str = str ? str : ""; - info->dbox.auto_launch = strdup(str); - if (!info->dbox.auto_launch) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(info->abi); - DbgFree(info->script); - if (info->gbar.type == GBAR_TYPE_SCRIPT) { - DbgFree(info->gbar.info.script.path); - DbgFree(info->gbar.info.script.group); - } + if (info->dbox.type == DBOX_TYPE_SCRIPT) { + DbgFree(info->dbox.info.script.path); + DbgFree(info->dbox.info.script.group); + } + parser_unload(parser); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->dbox.timeout = parser_timeout(parser); + info->network = parser_network(parser); + + info->dbox.period = parser_period(parser); + if (info->dbox.period < 0.0f) { + info->dbox.period = 0.0f; + } else if (info->dbox.period > 0.0f && info->dbox.period < DYNAMICBOX_CONF_MINIMUM_PERIOD) { + info->dbox.period = DYNAMICBOX_CONF_MINIMUM_PERIOD; + } + + info->dbox.size_list = parser_size(parser); + + str = parser_auto_launch(parser); + str = str ? str : ""; + info->dbox.auto_launch = strdup(str); + if (!info->dbox.auto_launch) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(info->abi); + DbgFree(info->script); + if (info->gbar.type == GBAR_TYPE_SCRIPT) { + DbgFree(info->gbar.info.script.path); + DbgFree(info->gbar.info.script.group); + } - if (info->dbox.type == DBOX_TYPE_SCRIPT) { - DbgFree(info->dbox.info.script.path); - DbgFree(info->dbox.info.script.group); - } - parser_unload(parser); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + if (info->dbox.type == DBOX_TYPE_SCRIPT) { + DbgFree(info->dbox.info.script.path); + DbgFree(info->dbox.info.script.group); } + parser_unload(parser); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - info->secured = parser_secured(parser); - info->dbox.pinup = parser_pinup(parser); + info->secured = parser_secured(parser); + info->dbox.pinup = parser_pinup(parser); - parser_get_gbar_size(parser, &info->gbar.width, &info->gbar.height); + parser_get_gbar_size(parser, &info->gbar.width, &info->gbar.height); - group = parser_group_str(parser); - if (group && group_add_dynamicbox(group, info->dbox_id) < 0) { - ErrPrint("Failed to build cluster tree for %s{%s}\n", info->dbox_id, group); - } + group = parser_group_str(parser); + if (group && group_add_dynamicbox(group, info->dbox_id) < 0) { + ErrPrint("Failed to build cluster tree for %s{%s}\n", info->dbox_id, group); + } - parser_unload(parser); - return DBOX_STATUS_ERROR_NONE; + parser_unload(parser); + return DBOX_STATUS_ERROR_NONE; } HAPI struct pkg_info *package_create(const char *pkgid, const char *dbox_id) { - struct pkg_info *pkginfo; + struct pkg_info *pkginfo; - pkginfo = calloc(1, sizeof(*pkginfo)); - if (!pkginfo) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + pkginfo = calloc(1, sizeof(*pkginfo)); + if (!pkginfo) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - pkginfo->pkgid = strdup(pkgid); - if (!pkginfo->pkgid) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(pkginfo); - return NULL; - } + pkginfo->pkgid = strdup(pkgid); + if (!pkginfo->pkgid) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(pkginfo); + return NULL; + } - pkginfo->dbox_id = io_dynamicbox_pkgname(dbox_id); + pkginfo->dbox_id = io_dynamicbox_pkgname(dbox_id); + if (!pkginfo->dbox_id) { + ErrPrint("Failed to get pkgname, fallback to fs checker\n"); + pkginfo->dbox_id = strdup(dbox_id); if (!pkginfo->dbox_id) { - ErrPrint("Failed to get pkgname, fallback to fs checker\n"); - pkginfo->dbox_id = strdup(dbox_id); - if (!pkginfo->dbox_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(pkginfo->pkgid); - DbgFree(pkginfo); - return NULL; - } + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(pkginfo->pkgid); + DbgFree(pkginfo); + return NULL; } + } - if (io_load_package_db(pkginfo) < 0) { - ErrPrint("Failed to load DB, fall back to conf file loader\n"); - if (load_conf(pkginfo) < 0) { - ErrPrint("Failed to initiate the conf file loader\n"); - DbgFree(pkginfo->dbox_id); - DbgFree(pkginfo->pkgid); - DbgFree(pkginfo); - return NULL; - } + if (io_load_package_db(pkginfo) < 0) { + ErrPrint("Failed to load DB, fall back to conf file loader\n"); + if (load_conf(pkginfo) < 0) { + ErrPrint("Failed to initiate the conf file loader\n"); + DbgFree(pkginfo->dbox_id); + DbgFree(pkginfo->pkgid); + DbgFree(pkginfo); + return NULL; } + } - package_ref(pkginfo); + package_ref(pkginfo); - s_info.pkg_list = eina_list_append(s_info.pkg_list, pkginfo); + s_info.pkg_list = eina_list_append(s_info.pkg_list, pkginfo); - return pkginfo; + return pkginfo; } HAPI int package_destroy(struct pkg_info *info) { - package_unref(info); - return DBOX_STATUS_ERROR_NONE; + package_unref(info); + return DBOX_STATUS_ERROR_NONE; } HAPI Eina_List *package_ctx_info(struct pkg_info *pkginfo) { - return pkginfo->ctx_list; + return pkginfo->ctx_list; } HAPI void package_add_ctx_info(struct pkg_info *pkginfo, struct context_info *info) { - pkginfo->ctx_list = eina_list_append(pkginfo->ctx_list, info); + pkginfo->ctx_list = eina_list_append(pkginfo->ctx_list, info); } HAPI void package_del_ctx_info(struct pkg_info *pkginfo, struct context_info *info) { - pkginfo->ctx_list = eina_list_remove(pkginfo->ctx_list, info); + pkginfo->ctx_list = eina_list_remove(pkginfo->ctx_list, info); } HAPI char *package_dbox_pkgname(const char *pkgname) { - char *dbox_id; + char *dbox_id; - dbox_id = io_dynamicbox_pkgname(pkgname); + dbox_id = io_dynamicbox_pkgname(pkgname); + if (!dbox_id) { + dbox_id = strdup(pkgname); if (!dbox_id) { - dbox_id = strdup(pkgname); - if (!dbox_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; } + } - return dbox_id; + return dbox_id; } HAPI int package_is_dbox_pkgname(const char *pkgname) { - char *dbox_id; - int ret; + char *dbox_id; + int ret; - dbox_id = package_dbox_pkgname(pkgname); - ret = !!dbox_id; - DbgFree(dbox_id); + dbox_id = package_dbox_pkgname(pkgname); + ret = !!dbox_id; + DbgFree(dbox_id); - return ret; + return ret; } HAPI struct pkg_info *package_find(const char *dbox_id) { - Eina_List *l; - struct pkg_info *info; + Eina_List *l; + struct pkg_info *info; - if (!dbox_id) { - return NULL; - } + if (!dbox_id) { + return NULL; + } - EINA_LIST_FOREACH(s_info.pkg_list, l, info) { - if (!strcmp(info->dbox_id, dbox_id)) { - return info; - } + EINA_LIST_FOREACH(s_info.pkg_list, l, info) { + if (!strcmp(info->dbox_id, dbox_id)) { + return info; } + } - return NULL; + return NULL; } HAPI struct inst_info *package_find_instance_by_id(const char *dbox_id, const char *id) { - Eina_List *l; - struct inst_info *inst; - struct pkg_info *info; + Eina_List *l; + struct inst_info *inst; + struct pkg_info *info; - info = package_find(dbox_id); - if (!info) { - ErrPrint("Package %s is not exists\n", dbox_id); - return NULL; - } + info = package_find(dbox_id); + if (!info) { + ErrPrint("Package %s is not exists\n", dbox_id); + return NULL; + } - EINA_LIST_FOREACH(info->inst_list, l, inst) { - if (!strcmp(instance_id(inst), id)) { - return inst; - } + EINA_LIST_FOREACH(info->inst_list, l, inst) { + if (!strcmp(instance_id(inst), id)) { + return inst; } + } - return NULL; + return NULL; } HAPI struct inst_info *package_find_instance_by_timestamp(const char *dbox_id, double timestamp) { - Eina_List *l; - struct inst_info *inst; - struct pkg_info *info; + Eina_List *l; + struct inst_info *inst; + struct pkg_info *info; - info = package_find(dbox_id); - if (!info) { - ErrPrint("Package %s is not exists\n", dbox_id); - return NULL; - } + info = package_find(dbox_id); + if (!info) { + ErrPrint("Package %s is not exists\n", dbox_id); + return NULL; + } - EINA_LIST_FOREACH(info->inst_list, l, inst) { - if (instance_timestamp(inst) == timestamp) { - return inst; - } + EINA_LIST_FOREACH(info->inst_list, l, inst) { + if (instance_timestamp(inst) == timestamp) { + return inst; } + } - return NULL; + return NULL; } HAPI int package_dump_fault_info(struct pkg_info *info) { - if (!info->fault_info) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + if (!info->fault_info) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - CRITICAL_LOG("=============\n"); - CRITICAL_LOG("faulted at %lf\n", info->fault_info->timestamp); - CRITICAL_LOG("Package: %s\n", info->dbox_id); - CRITICAL_LOG("Function: %s\n", info->fault_info->function); - CRITICAL_LOG("InstanceID: %s\n", info->fault_info->filename); - return DBOX_STATUS_ERROR_NONE; + CRITICAL_LOG("=============\n"); + CRITICAL_LOG("faulted at %lf\n", info->fault_info->timestamp); + CRITICAL_LOG("Package: %s\n", info->dbox_id); + CRITICAL_LOG("Function: %s\n", info->fault_info->function); + CRITICAL_LOG("InstanceID: %s\n", info->fault_info->filename); + return DBOX_STATUS_ERROR_NONE; } HAPI int package_get_fault_info(struct pkg_info *info, double *timestamp, const char **filename, const char **function) { - if (!info->fault_info) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + if (!info->fault_info) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - *timestamp = info->fault_info->timestamp; - *filename = info->fault_info->filename; - *function = info->fault_info->function; - return DBOX_STATUS_ERROR_NONE; + *timestamp = info->fault_info->timestamp; + *filename = info->fault_info->filename; + *function = info->fault_info->function; + return DBOX_STATUS_ERROR_NONE; } HAPI int package_set_fault_info(struct pkg_info *info, double timestamp, const char *filename, const char *function) { - struct fault_info *fault; + struct fault_info *fault; - package_clear_fault(info); + package_clear_fault(info); - fault = calloc(1, sizeof(*fault)); - if (!fault) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + fault = calloc(1, sizeof(*fault)); + if (!fault) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - fault->timestamp = timestamp; - if (!filename) { - filename = "unknown"; - } - if (!function) { - function = "unknown"; - } + fault->timestamp = timestamp; + if (!filename) { + filename = "unknown"; + } + if (!function) { + function = "unknown"; + } - fault->filename = strdup(filename); - if (!fault->filename) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(fault); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + fault->filename = strdup(filename); + if (!fault->filename) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(fault); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - fault->function = strdup(function); - if (!fault->function) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(fault->filename); - DbgFree(fault); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + fault->function = strdup(function); + if (!fault->function) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(fault->filename); + DbgFree(fault); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - info->fault_info = fault; - info->fault_count++; - return DBOX_STATUS_ERROR_NONE; + info->fault_info = fault; + info->fault_count++; + return DBOX_STATUS_ERROR_NONE; } HAPI int package_clear_fault(struct pkg_info *info) { - if (!info->fault_info) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - package_dump_fault_info(info); + if (!info->fault_info) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - DbgFree(info->fault_info->function); - DbgFree(info->fault_info->filename); - DbgFree(info->fault_info); - info->fault_info = NULL; - return DBOX_STATUS_ERROR_NONE; + package_dump_fault_info(info); + + DbgFree(info->fault_info->function); + DbgFree(info->fault_info->filename); + DbgFree(info->fault_info); + info->fault_info = NULL; + return DBOX_STATUS_ERROR_NONE; } HAPI const int const package_is_fault(const struct pkg_info *info) { - return !!info->fault_info; + return !!info->fault_info; } HAPI struct slave_node * const package_slave(const struct pkg_info *info) { - return info->slave; + return info->slave; } HAPI const int const package_timeout(const struct pkg_info *info) { - return info->dbox.timeout; + return info->dbox.timeout; } HAPI void package_set_timeout(struct pkg_info *info, int timeout) { - info->dbox.timeout = timeout; + info->dbox.timeout = timeout; } HAPI const double const package_period(const struct pkg_info *info) { - return info->dbox.period; + return info->dbox.period; } HAPI void package_set_period(struct pkg_info *info, double period) { - info->dbox.period = period; + info->dbox.period = period; } HAPI const int const package_secured(const struct pkg_info *info) { - return info->secured; + return info->secured; } HAPI void package_set_secured(struct pkg_info *info, int secured) { - info->secured = secured; + info->secured = secured; } HAPI const char * const package_script(const struct pkg_info *info) { - return info->script; + return info->script; } HAPI int package_set_script(struct pkg_info *info, const char *script) { - char *tmp; + char *tmp; - tmp = strdup(script); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = strdup(script); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->script); - info->script = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->script); + info->script = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI const char * const package_abi(const struct pkg_info *info) { - return info->abi; + return info->abi; } HAPI int package_set_abi(struct pkg_info *info, const char *abi) { - char *tmp; - tmp = strdup(abi); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + char *tmp; + tmp = strdup(abi); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->abi); - info->abi = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->abi); + info->abi = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI const char * const package_dbox_path(const struct pkg_info *info) { - if (info->dbox.type != DBOX_TYPE_SCRIPT) { - return NULL; - } + if (info->dbox.type != DBOX_TYPE_SCRIPT) { + return NULL; + } - return info->dbox.info.script.path; + return info->dbox.info.script.path; } HAPI int package_set_dbox_path(struct pkg_info *info, const char *path) { - char *tmp; + char *tmp; - if (info->dbox.type != DBOX_TYPE_SCRIPT) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (info->dbox.type != DBOX_TYPE_SCRIPT) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - tmp = strdup(path); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = strdup(path); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->dbox.info.script.path); - info->dbox.info.script.path = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->dbox.info.script.path); + info->dbox.info.script.path = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI const char * const package_dbox_group(const struct pkg_info *info) { - if (info->dbox.type != DBOX_TYPE_SCRIPT) { - return NULL; - } + if (info->dbox.type != DBOX_TYPE_SCRIPT) { + return NULL; + } - return info->dbox.info.script.group; + return info->dbox.info.script.group; } HAPI int package_set_dbox_group(struct pkg_info *info, const char *group) { - char *tmp; + char *tmp; - if (info->dbox.type != DBOX_TYPE_SCRIPT) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (info->dbox.type != DBOX_TYPE_SCRIPT) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - tmp = strdup(group); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = strdup(group); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->dbox.info.script.group); - info->dbox.info.script.group = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->dbox.info.script.group); + info->dbox.info.script.group = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI const char * const package_gbar_path(const struct pkg_info *info) { - if (info->gbar.type != GBAR_TYPE_SCRIPT) { - return NULL; - } + if (info->gbar.type != GBAR_TYPE_SCRIPT) { + return NULL; + } - return info->gbar.info.script.path; + return info->gbar.info.script.path; } HAPI int package_set_gbar_path(struct pkg_info *info, const char *path) { - char *tmp; + char *tmp; - if (info->gbar.type != GBAR_TYPE_SCRIPT) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (info->gbar.type != GBAR_TYPE_SCRIPT) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - tmp = strdup(path); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = strdup(path); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->gbar.info.script.path); - info->gbar.info.script.path = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->gbar.info.script.path); + info->gbar.info.script.path = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI const char * const package_gbar_group(const struct pkg_info *info) { - if (info->gbar.type != GBAR_TYPE_SCRIPT) { - return NULL; - } + if (info->gbar.type != GBAR_TYPE_SCRIPT) { + return NULL; + } - return info->gbar.info.script.group; + return info->gbar.info.script.group; } HAPI int package_set_gbar_group(struct pkg_info *info, const char *group) { - char *tmp; + char *tmp; - if (info->gbar.type != GBAR_TYPE_SCRIPT) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (info->gbar.type != GBAR_TYPE_SCRIPT) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - tmp = strdup(group); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = strdup(group); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->gbar.info.script.group); - info->gbar.info.script.group = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->gbar.info.script.group); + info->gbar.info.script.group = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI const int const package_pinup(const struct pkg_info *info) { - return info->dbox.pinup; + return info->dbox.pinup; } HAPI void package_set_pinup(struct pkg_info *info, int pinup) { - info->dbox.pinup = pinup; + info->dbox.pinup = pinup; } HAPI const char * const package_auto_launch(const struct pkg_info *info) { - return info->dbox.auto_launch; + return info->dbox.auto_launch; } HAPI void package_set_auto_launch(struct pkg_info *info, const char *auto_launch) { - if (!auto_launch) { - auto_launch = ""; - } + if (!auto_launch) { + auto_launch = ""; + } - info->dbox.auto_launch = strdup(auto_launch); - if (!info->dbox.auto_launch) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; - } + info->dbox.auto_launch = strdup(auto_launch); + if (!info->dbox.auto_launch) { + ErrPrint("Heap: %s\n", strerror(errno)); + return; + } } HAPI const unsigned int const package_size_list(const struct pkg_info *info) { - return info->dbox.size_list; + return info->dbox.size_list; } HAPI void package_set_size_list(struct pkg_info *info, unsigned int size_list) { - info->dbox.size_list = size_list; + info->dbox.size_list = size_list; } HAPI const int const package_gbar_width(const struct pkg_info *info) { - return info->gbar.width; + return info->gbar.width; } HAPI void package_set_gbar_width(struct pkg_info *info, int width) { - info->gbar.width = width; + info->gbar.width = width; } HAPI const int const package_gbar_height(const struct pkg_info *info) { - return info->gbar.height; + return info->gbar.height; } HAPI void package_set_gbar_height(struct pkg_info *info, int height) { - info->gbar.height = height; + info->gbar.height = height; } HAPI struct pkg_info * const package_ref(struct pkg_info *info) { - info->refcnt++; - return info; + info->refcnt++; + return info; } HAPI struct pkg_info * const package_unref(struct pkg_info *info) { - if (info->refcnt == 0) { - ErrPrint("Invalid request\n"); - return NULL; - } + if (info->refcnt == 0) { + ErrPrint("Invalid request\n"); + return NULL; + } - info->refcnt--; - if (info->refcnt == 0) { - destroy_package(info); - info = NULL; - } + info->refcnt--; + if (info->refcnt == 0) { + destroy_package(info); + info = NULL; + } - return info; + return info; } HAPI const int const package_refcnt(const struct pkg_info *info) { - return info->refcnt; + return info->refcnt; } HAPI const enum dynamicbox_dbox_type package_dbox_type(const struct pkg_info *info) { - return info ? info->dbox.type : DBOX_TYPE_NONE; + return info ? info->dbox.type : DBOX_TYPE_NONE; } HAPI void package_set_dbox_type(struct pkg_info *info, enum dynamicbox_dbox_type type) { - info->dbox.type = type; + info->dbox.type = type; } HAPI const char * const package_libexec(struct pkg_info *info) { - return info->dbox.libexec; + return info->dbox.libexec; } HAPI int package_set_libexec(struct pkg_info *info, const char *libexec) { - char *tmp; + char *tmp; - tmp = strdup(libexec); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + tmp = strdup(libexec); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(info->dbox.libexec); - info->dbox.libexec = tmp; - return DBOX_STATUS_ERROR_NONE; + DbgFree(info->dbox.libexec); + info->dbox.libexec = tmp; + return DBOX_STATUS_ERROR_NONE; } HAPI int package_network(struct pkg_info *info) { - return info->network; + return info->network; } HAPI void package_set_network(struct pkg_info *info, int network) { - info->network = network; + info->network = network; } HAPI const enum dynamicbox_gbar_type const package_gbar_type(const struct pkg_info *info) { - return info ? info->gbar.type : GBAR_TYPE_NONE; + return info ? info->gbar.type : GBAR_TYPE_NONE; } HAPI void package_set_gbar_type(struct pkg_info *info, enum dynamicbox_gbar_type type) { - info->gbar.type = type; + info->gbar.type = type; } /*! @@ -1062,390 +1062,390 @@ HAPI void package_set_gbar_type(struct pkg_info *info, enum dynamicbox_gbar_type */ static inline int assign_new_slave(const char *slave_pkgname, struct pkg_info *info) { - char *s_name; + char *s_name; - s_name = util_slavename(); - if (!s_name) { - ErrPrint("Failed to get a new slave name\n"); - return DBOX_STATUS_ERROR_FAULT; - } + s_name = util_slavename(); + if (!s_name) { + ErrPrint("Failed to get a new slave name\n"); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("New slave[%s] is assigned for %s (using %s / abi[%s])\n", s_name, info->dbox_id, slave_pkgname, info->abi); - info->slave = slave_create(s_name, info->secured, info->abi, slave_pkgname, info->network); + DbgPrint("New slave[%s] is assigned for %s (using %s / abi[%s])\n", s_name, info->dbox_id, slave_pkgname, info->abi); + info->slave = slave_create(s_name, info->secured, info->abi, slave_pkgname, info->network); - DbgFree(s_name); + DbgFree(s_name); - if (!info->slave) { - /*! - * \note - * package_destroy will try to remove "info" from the pkg_list. - * but we didn't add this to it yet. - * If the list method couldn't find an "info" from the list, - * it just do nothing so I'll leave this. - */ - return DBOX_STATUS_ERROR_FAULT; - } + if (!info->slave) { /*! * \note - * Slave is not activated yet. + * package_destroy will try to remove "info" from the pkg_list. + * but we didn't add this to it yet. + * If the list method couldn't find an "info" from the list, + * it just do nothing so I'll leave this. */ - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_FAULT; + } + /*! + * \note + * Slave is not activated yet. + */ + return DBOX_STATUS_ERROR_NONE; } HAPI int package_add_instance(struct pkg_info *info, struct inst_info *inst) { - if (!info->inst_list) { - char *slave_pkgname; + if (!info->inst_list) { + char *slave_pkgname; - slave_pkgname = slave_package_name(info->abi, info->dbox_id); - if (!slave_pkgname) { - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + slave_pkgname = slave_package_name(info->abi, info->dbox_id); + if (!slave_pkgname) { + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - info->slave = slave_find_available(slave_pkgname, info->abi, info->secured, info->network); - if (!info->slave) { - int ret; + info->slave = slave_find_available(slave_pkgname, info->abi, info->secured, info->network); + if (!info->slave) { + int ret; - ret = assign_new_slave(slave_pkgname, info); - DbgFree(slave_pkgname); - if (ret < 0) { - return ret; - } - } else { - DbgFree(slave_pkgname); - DbgPrint("Slave %s is used for %s\n", slave_name(info->slave), info->dbox_id); - } + ret = assign_new_slave(slave_pkgname, info); + DbgFree(slave_pkgname); + if (ret < 0) { + return ret; + } + } else { + DbgFree(slave_pkgname); + DbgPrint("Slave %s is used for %s\n", slave_name(info->slave), info->dbox_id); + } - (void)slave_ref(info->slave); - slave_load_package(info->slave); - (void)slave_event_callback_add(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info); - (void)slave_event_callback_add(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info); - (void)slave_event_callback_add(info->slave, SLAVE_EVENT_FAULT, slave_fault_cb, info); + (void)slave_ref(info->slave); + slave_load_package(info->slave); + (void)slave_event_callback_add(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info); + (void)slave_event_callback_add(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info); + (void)slave_event_callback_add(info->slave, SLAVE_EVENT_FAULT, slave_fault_cb, info); - if (info->secured) { - (void)slave_event_callback_add(info->slave, SLAVE_EVENT_PAUSE, slave_paused_cb, info); - (void)slave_event_callback_add(info->slave, SLAVE_EVENT_RESUME, slave_resumed_cb, info); + if (info->secured) { + (void)slave_event_callback_add(info->slave, SLAVE_EVENT_PAUSE, slave_paused_cb, info); + (void)slave_event_callback_add(info->slave, SLAVE_EVENT_RESUME, slave_resumed_cb, info); - /*! - * \note - * In case of the slave is terminated because of expired TTL timer, - * Master should freeze the all update time. - * But the callback should check the slave's state to prevent from duplicated freezing. - * - * This callback will freeze the timer only if a slave doesn't running. - */ - (void)xmonitor_add_event_callback(XMONITOR_PAUSED, xmonitor_paused_cb, info); - (void)xmonitor_add_event_callback(XMONITOR_RESUMED, xmonitor_resumed_cb, info); - } + /*! + * \note + * In case of the slave is terminated because of expired TTL timer, + * Master should freeze the all update time. + * But the callback should check the slave's state to prevent from duplicated freezing. + * + * This callback will freeze the timer only if a slave doesn't running. + */ + (void)xmonitor_add_event_callback(XMONITOR_PAUSED, xmonitor_paused_cb, info); + (void)xmonitor_add_event_callback(XMONITOR_RESUMED, xmonitor_resumed_cb, info); } + } - info->inst_list = eina_list_append(info->inst_list, inst); - return DBOX_STATUS_ERROR_NONE; + info->inst_list = eina_list_append(info->inst_list, inst); + return DBOX_STATUS_ERROR_NONE; } HAPI int package_del_instance(struct pkg_info *info, struct inst_info *inst) { - info->inst_list = eina_list_remove(info->inst_list, inst); + info->inst_list = eina_list_remove(info->inst_list, inst); - if (info->inst_list) { - return DBOX_STATUS_ERROR_NONE; - } - - if (info->slave) { - slave_unload_package(info->slave); + if (info->inst_list) { + return DBOX_STATUS_ERROR_NONE; + } - slave_event_callback_del(info->slave, SLAVE_EVENT_FAULT, slave_fault_cb, info); - slave_event_callback_del(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info); - slave_event_callback_del(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info); + if (info->slave) { + slave_unload_package(info->slave); - if (info->secured) { - slave_event_callback_del(info->slave, SLAVE_EVENT_PAUSE, slave_paused_cb, info); - slave_event_callback_del(info->slave, SLAVE_EVENT_RESUME, slave_resumed_cb, info); + slave_event_callback_del(info->slave, SLAVE_EVENT_FAULT, slave_fault_cb, info); + slave_event_callback_del(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info); + slave_event_callback_del(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info); - xmonitor_del_event_callback(XMONITOR_PAUSED, xmonitor_paused_cb, info); - xmonitor_del_event_callback(XMONITOR_RESUMED, xmonitor_resumed_cb, info); - } + if (info->secured) { + slave_event_callback_del(info->slave, SLAVE_EVENT_PAUSE, slave_paused_cb, info); + slave_event_callback_del(info->slave, SLAVE_EVENT_RESUME, slave_resumed_cb, info); - slave_unref(info->slave); - info->slave = NULL; + xmonitor_del_event_callback(XMONITOR_PAUSED, xmonitor_paused_cb, info); + xmonitor_del_event_callback(XMONITOR_RESUMED, xmonitor_resumed_cb, info); } - if (info->is_uninstalled) { - package_destroy(info); - } + slave_unref(info->slave); + info->slave = NULL; + } - return DBOX_STATUS_ERROR_NONE; + if (info->is_uninstalled) { + package_destroy(info); + } + + return DBOX_STATUS_ERROR_NONE; } HAPI Eina_List *package_instance_list(struct pkg_info *info) { - return info->inst_list; + return info->inst_list; } static int client_created_cb(struct client_node *client, void *data) { - struct pkg_info *info; - Eina_List *l; + struct pkg_info *info; + Eina_List *l; - struct inst_info *inst; - Eina_List *i_l; + struct inst_info *inst; + Eina_List *i_l; - EINA_LIST_FOREACH(s_info.pkg_list, l, info) { - if (info->fault_info) { - fault_unicast_info(client, info->dbox_id, info->fault_info->filename, info->fault_info->function); - continue; - } - - EINA_LIST_FOREACH(info->inst_list, i_l, inst) { - switch (instance_state(inst)) { - case INST_INIT: - /* Will be send a created event after the instance gets created event */ - break; - case INST_ACTIVATED: /*!< This instance is actiavted, and used */ - case INST_REQUEST_TO_REACTIVATE: /*!< This instance will be reactivated soon */ - case INST_REQUEST_TO_DESTROY: /*!< This instance will be destroy soon */ - if (instance_client(inst) == client) { - instance_unicast_created_event(inst, client); - } else if (instance_client(inst) == NULL) { - /*! - * \note - * Instances are lives in the system cluster/sub-cluster - */ - if (client_is_subscribed(client, instance_cluster(inst), instance_category(inst))) { - instance_unicast_created_event(inst, client); - DbgPrint("(Subscribed) Created package: %s\n", info->dbox_id); - } - } - - break; - default: - DbgPrint("%s(%s) is not activated (%d)\n", - package_name(info), instance_id(inst), instance_state(inst)); - break; + EINA_LIST_FOREACH(s_info.pkg_list, l, info) { + if (info->fault_info) { + fault_unicast_info(client, info->dbox_id, info->fault_info->filename, info->fault_info->function); + continue; + } + + EINA_LIST_FOREACH(info->inst_list, i_l, inst) { + switch (instance_state(inst)) { + case INST_INIT: + /* Will be send a created event after the instance gets created event */ + break; + case INST_ACTIVATED: /*!< This instance is actiavted, and used */ + case INST_REQUEST_TO_REACTIVATE: /*!< This instance will be reactivated soon */ + case INST_REQUEST_TO_DESTROY: /*!< This instance will be destroy soon */ + if (instance_client(inst) == client) { + instance_unicast_created_event(inst, client); + } else if (instance_client(inst) == NULL) { + /*! + * \note + * Instances are lives in the system cluster/sub-cluster + */ + if (client_is_subscribed(client, instance_cluster(inst), instance_category(inst))) { + instance_unicast_created_event(inst, client); + DbgPrint("(Subscribed) Created package: %s\n", info->dbox_id); } - } + } + + break; + default: + DbgPrint("%s(%s) is not activated (%d)\n", + package_name(info), instance_id(inst), instance_state(inst)); + break; + } } + } - return 0; + return 0; } static int io_uninstall_cb(const char *pkgid, const char *dbox_id, int prime, void *data) { - struct pkg_info *info; - Eina_List *l; - Eina_List *n; - struct inst_info *inst; - - DbgPrint("Package %s is uninstalled\n", dbox_id); - info = package_find(dbox_id); - if (!info) { - DbgPrint("%s is not yet loaded\n", dbox_id); - return 0; - } + struct pkg_info *info; + Eina_List *l; + Eina_List *n; + struct inst_info *inst; - info->is_uninstalled = 1; + DbgPrint("Package %s is uninstalled\n", dbox_id); + info = package_find(dbox_id); + if (!info) { + DbgPrint("%s is not yet loaded\n", dbox_id); + return 0; + } - /*! - * \NOTE - * Don't delete an item from the inst_list. - * destroy callback will use this list again. - * So, Don't touch it from here. - */ - if (info->inst_list) { - EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { - instance_destroy(inst, DBOX_DESTROY_TYPE_UNINSTALL); - } - } else { - package_destroy(info); + info->is_uninstalled = 1; + + /*! + * \NOTE + * Don't delete an item from the inst_list. + * destroy callback will use this list again. + * So, Don't touch it from here. + */ + if (info->inst_list) { + EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { + instance_destroy(inst, DBOX_DESTROY_TYPE_UNINSTALL); } + } else { + package_destroy(info); + } - return 0; + return 0; } static inline void reload_package_info(struct pkg_info *info) { - Eina_List *l; - Eina_List *n; - struct inst_info *inst; - unsigned int size_type; - int width; - int height; - double old_period; - - DbgPrint("Already exists, try to update it\n"); - - old_period = info->dbox.period; - - group_del_dynamicbox(info->dbox_id); - package_clear_fault(info); - - /*! - * \NOTE: - * Nested DB I/O - */ - io_load_package_db(info); - - /*! - * \note - * Without "is_uninstalled", the package will be kept - */ - EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { - width = instance_dbox_width(inst); - height = instance_dbox_height(inst); - size_type = dynamicbox_service_size_type(width, height); - if (info->dbox.size_list & size_type) { - if (instance_period(inst) == old_period) { - instance_reload_period(inst, package_period(info)); - } - instance_reload(inst, DBOX_DESTROY_TYPE_UPGRADE); - } else { - instance_destroy(inst, DBOX_DESTROY_TYPE_UNINSTALL); - } + Eina_List *l; + Eina_List *n; + struct inst_info *inst; + unsigned int size_type; + int width; + int height; + double old_period; + + DbgPrint("Already exists, try to update it\n"); + + old_period = info->dbox.period; + + group_del_dynamicbox(info->dbox_id); + package_clear_fault(info); + + /*! + * \NOTE: + * Nested DB I/O + */ + io_load_package_db(info); + + /*! + * \note + * Without "is_uninstalled", the package will be kept + */ + EINA_LIST_FOREACH_SAFE(info->inst_list, l, n, inst) { + width = instance_dbox_width(inst); + height = instance_dbox_height(inst); + size_type = dynamicbox_service_size_type(width, height); + if (info->dbox.size_list & size_type) { + if (instance_period(inst) == old_period) { + instance_reload_period(inst, package_period(info)); + } + instance_reload(inst, DBOX_DESTROY_TYPE_UPGRADE); + } else { + instance_destroy(inst, DBOX_DESTROY_TYPE_UNINSTALL); } + } } static int io_install_cb(const char *pkgid, const char *dbox_id, int prime, void *data) { - struct pkg_info *info; + struct pkg_info *info; - info = package_find(dbox_id); - if (info) { - /*! - * Already exists. skip to create this. - */ - return 0; - } + info = package_find(dbox_id); + if (info) { + /*! + * Already exists. skip to create this. + */ + return 0; + } - info = package_create(pkgid, dbox_id); - if (!info) { - ErrPrint("Failed to build an info %s\n", dbox_id); - } else { - DbgPrint("Dynamicbox %s is built\n", dbox_id); - } + info = package_create(pkgid, dbox_id); + if (!info) { + ErrPrint("Failed to build an info %s\n", dbox_id); + } else { + DbgPrint("Dynamicbox %s is built\n", dbox_id); + } - return 0; + return 0; } static int uninstall_cb(const char *pkgname, enum pkgmgr_status status, double value, void *data) { - Eina_List *l; - Eina_List *n; - struct pkg_info *info; + Eina_List *l; + Eina_List *n; + struct pkg_info *info; - if (status != PKGMGR_STATUS_END) { - return 0; - } + if (status != PKGMGR_STATUS_END) { + return 0; + } - EINA_LIST_FOREACH_SAFE(s_info.pkg_list, l, n, info) { - if (!strcmp(info->pkgid, pkgname)) { - io_uninstall_cb(pkgname, info->dbox_id, -1, NULL); - } + EINA_LIST_FOREACH_SAFE(s_info.pkg_list, l, n, info) { + if (!strcmp(info->pkgid, pkgname)) { + io_uninstall_cb(pkgname, info->dbox_id, -1, NULL); } + } - return 0; + return 0; } static int update_cb(const char *pkgname, enum pkgmgr_status status, double value, void *data) { - Eina_List *l; - Eina_List *n; - struct pkg_info *info; + Eina_List *l; + Eina_List *n; + struct pkg_info *info; - if (status != PKGMGR_STATUS_END) { - return 0; - } + if (status != PKGMGR_STATUS_END) { + return 0; + } - EINA_LIST_FOREACH_SAFE(s_info.pkg_list, l, n, info) { - if (!strcmp(info->pkgid, pkgname)) { - DbgPrint("Update dbox_id: %s\n", info->dbox_id); - if (io_is_exists(info->dbox_id) == 1) { - reload_package_info(info); - } else { - io_uninstall_cb(pkgname, info->dbox_id, -1, NULL); - } - } + EINA_LIST_FOREACH_SAFE(s_info.pkg_list, l, n, info) { + if (!strcmp(info->pkgid, pkgname)) { + DbgPrint("Update dbox_id: %s\n", info->dbox_id); + if (io_is_exists(info->dbox_id) == 1) { + reload_package_info(info); + } else { + io_uninstall_cb(pkgname, info->dbox_id, -1, NULL); + } } + } - (void)io_update_dynamicbox_package(pkgname, io_install_cb, NULL); - return 0; + (void)io_update_dynamicbox_package(pkgname, io_install_cb, NULL); + return 0; } static int crawling_dynamicboxes(const char *pkgid, const char *dbox_id, int prime, void *data) { - if (package_find(dbox_id)) { - ErrPrint("Information of %s is already built\n", dbox_id); - } else { - struct pkg_info *info; - info = package_create(pkgid, dbox_id); - if (info) { - DbgPrint("[%s] information is built prime(%d)\n", dbox_id, prime); - } + if (package_find(dbox_id)) { + ErrPrint("Information of %s is already built\n", dbox_id); + } else { + struct pkg_info *info; + info = package_create(pkgid, dbox_id); + if (info) { + DbgPrint("[%s] information is built prime(%d)\n", dbox_id, prime); } + } - return 0; + return 0; } HAPI int package_init(void) { - client_global_event_handler_add(CLIENT_GLOBAL_EVENT_CREATE, client_created_cb, NULL); - pkgmgr_init(); + client_global_event_handler_add(CLIENT_GLOBAL_EVENT_CREATE, client_created_cb, NULL); + pkgmgr_init(); - pkgmgr_add_event_callback(PKGMGR_EVENT_INSTALL, update_cb, NULL); - pkgmgr_add_event_callback(PKGMGR_EVENT_UNINSTALL, uninstall_cb, NULL); - pkgmgr_add_event_callback(PKGMGR_EVENT_UPDATE, update_cb, NULL); + pkgmgr_add_event_callback(PKGMGR_EVENT_INSTALL, update_cb, NULL); + pkgmgr_add_event_callback(PKGMGR_EVENT_UNINSTALL, uninstall_cb, NULL); + pkgmgr_add_event_callback(PKGMGR_EVENT_UPDATE, update_cb, NULL); - io_crawling_dynamicboxes(crawling_dynamicboxes, NULL); - return 0; + io_crawling_dynamicboxes(crawling_dynamicboxes, NULL); + return 0; } HAPI int package_fini(void) { - Eina_List *p_l; - Eina_List *p_n; - Eina_List *i_l; - Eina_List *i_n; - struct pkg_info *info; - struct inst_info *inst; - - pkgmgr_del_event_callback(PKGMGR_EVENT_INSTALL, update_cb, NULL); - pkgmgr_del_event_callback(PKGMGR_EVENT_UNINSTALL, uninstall_cb, NULL); - pkgmgr_del_event_callback(PKGMGR_EVENT_UPDATE, update_cb, NULL); - pkgmgr_fini(); - client_global_event_handler_del(CLIENT_GLOBAL_EVENT_CREATE, client_created_cb, NULL); - - EINA_LIST_FOREACH_SAFE(s_info.pkg_list, p_l, p_n, info) { - EINA_LIST_FOREACH_SAFE(info->inst_list, i_l, i_n, inst) { - instance_state_reset(inst); - instance_destroy(inst, DBOX_DESTROY_TYPE_TERMINATE); - } + Eina_List *p_l; + Eina_List *p_n; + Eina_List *i_l; + Eina_List *i_n; + struct pkg_info *info; + struct inst_info *inst; + + pkgmgr_del_event_callback(PKGMGR_EVENT_INSTALL, update_cb, NULL); + pkgmgr_del_event_callback(PKGMGR_EVENT_UNINSTALL, uninstall_cb, NULL); + pkgmgr_del_event_callback(PKGMGR_EVENT_UPDATE, update_cb, NULL); + pkgmgr_fini(); + client_global_event_handler_del(CLIENT_GLOBAL_EVENT_CREATE, client_created_cb, NULL); - package_destroy(info); + EINA_LIST_FOREACH_SAFE(s_info.pkg_list, p_l, p_n, info) { + EINA_LIST_FOREACH_SAFE(info->inst_list, i_l, i_n, inst) { + instance_state_reset(inst); + instance_destroy(inst, DBOX_DESTROY_TYPE_TERMINATE); } - return 0; + package_destroy(info); + } + + return 0; } HAPI const char *package_find_by_secured_slave(struct slave_node *slave) { - Eina_List *l; - struct pkg_info *info; + Eina_List *l; + struct pkg_info *info; - if (!slave_is_secured(slave)) { - return NULL; - } + if (!slave_is_secured(slave)) { + return NULL; + } - EINA_LIST_FOREACH(s_info.pkg_list, l, info) { - if (info->slave == slave) { - return info->dbox_id; - } + EINA_LIST_FOREACH(s_info.pkg_list, l, info) { + if (info->slave == slave) { + return info->dbox_id; } + } - return NULL; + return NULL; } HAPI const char * const package_name(const struct pkg_info *info) { - return info->dbox_id; + return info->dbox_id; } /*! @@ -1453,136 +1453,136 @@ HAPI const char * const package_name(const struct pkg_info *info) */ HAPI int package_alter_instances_to_client(struct client_node *client, enum alter_type alter) { - struct pkg_info *info; - Eina_List *l; - - struct inst_info *inst; - Eina_List *i_l; - - EINA_LIST_FOREACH(s_info.pkg_list, l, info) { - EINA_LIST_FOREACH(info->inst_list, i_l, inst) { - if (instance_client(inst)) { - continue; - } - - if (!client_is_subscribed(client, instance_cluster(inst), instance_category(inst))) { - continue; - } - - switch (instance_state(inst)) { - case INST_INIT: - case INST_REQUEST_TO_ACTIVATE: - /* Will be send a created event after the instance gets created event */ - switch (alter) { - case ALTER_CREATE: - if (!instance_has_client(inst, client)) { - instance_add_client(inst, client); - } - break; - case ALTER_DESTROY: - if (instance_has_client(inst, client)) { - instance_del_client(inst, client); - } - break; - default: - break; - } - break; - case INST_ACTIVATED: /*!< This instance is actiavted, and used */ - case INST_REQUEST_TO_REACTIVATE: /*!< This instance will be reactivated soon */ - case INST_REQUEST_TO_DESTROY: /*!< This instance will be destroy soon */ - /*! - * \note - * Instances are lives in the system cluster/sub-cluster - */ - switch (alter) { - case ALTER_CREATE: - if (!instance_has_client(inst, client)) { - instance_unicast_created_event(inst, client); - instance_add_client(inst, client); - DbgPrint("(Subscribed) Created package: %s\n", info->dbox_id); - } - break; - case ALTER_DESTROY: - if (instance_has_client(inst, client)) { - instance_unicast_deleted_event(inst, client, DBOX_STATUS_ERROR_NONE); - instance_del_client(inst, client); - } - break; - default: - break; - } - - break; + struct pkg_info *info; + Eina_List *l; + + struct inst_info *inst; + Eina_List *i_l; + + EINA_LIST_FOREACH(s_info.pkg_list, l, info) { + EINA_LIST_FOREACH(info->inst_list, i_l, inst) { + if (instance_client(inst)) { + continue; + } + + if (!client_is_subscribed(client, instance_cluster(inst), instance_category(inst))) { + continue; + } + + switch (instance_state(inst)) { + case INST_INIT: + case INST_REQUEST_TO_ACTIVATE: + /* Will be send a created event after the instance gets created event */ + switch (alter) { + case ALTER_CREATE: + if (!instance_has_client(inst, client)) { + instance_add_client(inst, client); + } + break; + case ALTER_DESTROY: + if (instance_has_client(inst, client)) { + instance_del_client(inst, client); + } + break; default: - DbgPrint("%s(%s) is not activated (%d)\n", - package_name(info), instance_id(inst), instance_state(inst)); - break; - } - } + break; + } + break; + case INST_ACTIVATED: /*!< This instance is actiavted, and used */ + case INST_REQUEST_TO_REACTIVATE: /*!< This instance will be reactivated soon */ + case INST_REQUEST_TO_DESTROY: /*!< This instance will be destroy soon */ + /*! + * \note + * Instances are lives in the system cluster/sub-cluster + */ + switch (alter) { + case ALTER_CREATE: + if (!instance_has_client(inst, client)) { + instance_unicast_created_event(inst, client); + instance_add_client(inst, client); + DbgPrint("(Subscribed) Created package: %s\n", info->dbox_id); + } + break; + case ALTER_DESTROY: + if (instance_has_client(inst, client)) { + instance_unicast_deleted_event(inst, client, DBOX_STATUS_ERROR_NONE); + instance_del_client(inst, client); + } + break; + default: + break; + } + + break; + default: + DbgPrint("%s(%s) is not activated (%d)\n", + package_name(info), instance_id(inst), instance_state(inst)); + break; + } } + } - return 0; + return 0; } HAPI const Eina_List *package_list(void) { - return s_info.pkg_list; + return s_info.pkg_list; } HAPI int const package_fault_count(struct pkg_info *info) { - return info ? info->fault_count : 0; + return info ? info->fault_count : 0; } HAPI int package_is_enabled(const char *appid) { - pkgmgrinfo_appinfo_h handle; - bool enabled; - int ret; + pkgmgrinfo_appinfo_h handle; + bool enabled; + int ret; - ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle); - if (ret != PMINFO_R_OK) { - ErrPrint("Failed to get info\n"); - return 0; - } + ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle); + if (ret != PMINFO_R_OK) { + ErrPrint("Failed to get info\n"); + return 0; + } - ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled); - if (ret != PMINFO_R_OK) { - ErrPrint("Failed to get info\n"); - enabled = false; - } + ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled); + if (ret != PMINFO_R_OK) { + ErrPrint("Failed to get info\n"); + enabled = false; + } - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return enabled == true; + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return enabled == true; } HAPI int package_faulted(struct pkg_info *pkg, int broadcast) { - Eina_List *l; - Eina_List *n; - struct slave_node *slave; - struct inst_info *inst; - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package has no slave?\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - /* Emulated fault routine */ - // (void)package_set_fault_info(pkg, util_timestamp(), slave_name(slave), __func__); - if (broadcast) { - fault_broadcast_info(package_name(pkg), slave_name(slave), __func__); - } - - DbgPrint("package: %s (forucely faulted %s)\n", package_name(pkg), slave_name(slave)); - EINA_LIST_FOREACH_SAFE(pkg->inst_list, l, n, inst) { - DbgPrint("Destroy instance %p\n", inst); - instance_destroy(inst, DBOX_DESTROY_TYPE_FAULT); - } - - return DBOX_STATUS_ERROR_NONE; + Eina_List *l; + Eina_List *n; + struct slave_node *slave; + struct inst_info *inst; + + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package has no slave?\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + /* Emulated fault routine */ + // (void)package_set_fault_info(pkg, util_timestamp(), slave_name(slave), __func__); + if (broadcast) { + fault_broadcast_info(package_name(pkg), slave_name(slave), __func__); + } + + DbgPrint("package: %s (forucely faulted %s)\n", package_name(pkg), slave_name(slave)); + EINA_LIST_FOREACH_SAFE(pkg->inst_list, l, n, inst) { + DbgPrint("Destroy instance %p\n", inst); + instance_destroy(inst, DBOX_DESTROY_TYPE_FAULT); + } + + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/parser.c b/src/parser.c index bf2b187..e8f7005 100644 --- a/src/parser.c +++ b/src/parser.c @@ -41,290 +41,290 @@ int errno; #endif struct parser { - char *filename; - double period; - int timeout; - int network; - char *auto_launch; - unsigned int size; - unsigned int gbar_width; - unsigned int gbar_height; - char *group; - int secured; - - char *gbar_path; - char *gbar_group; - - char *dbox_path; - char *dbox_group; - int pinup; - int text_gbar; - int text_lb; - int buffer_gbar; - int buffer_lb; - - char *abi; - - char *script; + char *filename; + double period; + int timeout; + int network; + char *auto_launch; + unsigned int size; + unsigned int gbar_width; + unsigned int gbar_height; + char *group; + int secured; + + char *gbar_path; + char *gbar_group; + + char *dbox_path; + char *dbox_group; + int pinup; + int text_gbar; + int text_lb; + int buffer_gbar; + int buffer_lb; + + char *abi; + + char *script; }; HAPI double parser_period(struct parser *handle) { - return handle->period; + return handle->period; } HAPI int parser_network(struct parser *handle) { - return handle->network; + return handle->network; } HAPI int parser_timeout(struct parser *handle) { - return handle->timeout; + return handle->timeout; } HAPI const char *parser_auto_launch(struct parser *handle) { - return handle->auto_launch; + return handle->auto_launch; } HAPI const char *parser_script(struct parser *handle) { - return handle->script; + return handle->script; } HAPI const char *parser_abi(struct parser *handle) { - return handle->abi; + return handle->abi; } HAPI unsigned int parser_size(struct parser *handle) { - return handle->size; + return handle->size; } HAPI const char *parser_dbox_path(struct parser *handle) { - return handle->dbox_path; + return handle->dbox_path; } HAPI const char *parser_dbox_group(struct parser *handle) { - return handle->dbox_group; + return handle->dbox_group; } HAPI const char *parser_gbar_path(struct parser *handle) { - return handle->gbar_path; + return handle->gbar_path; } HAPI const char *parser_gbar_group(struct parser *handle) { - return handle->gbar_group; + return handle->gbar_group; } HAPI const char *parser_group_str(struct parser *handle) { - return handle->group; + return handle->group; } HAPI int parser_secured(struct parser *handle) { - return handle->secured; + return handle->secured; } HAPI void parser_get_gbar_size(struct parser *handle, unsigned int *width, unsigned int *height) { - *width = handle->gbar_width; - *height = handle->gbar_height; + *width = handle->gbar_width; + *height = handle->gbar_height; } HAPI int parser_pinup(struct parser *handle) { - return handle->pinup; + return handle->pinup; } HAPI int parser_text_dbox(struct parser *handle) { - return handle->text_lb; + return handle->text_lb; } HAPI int parser_text_gbar(struct parser *handle) { - return handle->text_gbar; + return handle->text_gbar; } HAPI int parser_buffer_dbox(struct parser *handle) { - return handle->buffer_lb; + return handle->buffer_lb; } HAPI int parser_buffer_gbar(struct parser *handle) { - return handle->buffer_gbar; + return handle->buffer_gbar; } HAPI RETURN_TYPE parser_find(const char *pkgname) { - Eina_List *l; - struct parser *item; - char *filename; - int len; - int ret; + Eina_List *l; + struct parser *item; + char *filename; + int len; + int ret; - len = strlen(pkgname) * 2 + strlen(DYNAMICBOX_CONF_CONF_PATH); + len = strlen(pkgname) * 2 + strlen(DYNAMICBOX_CONF_CONF_PATH); - filename = malloc(len); - if (!filename) { - return (RETURN_TYPE)0; - } + filename = malloc(len); + if (!filename) { + return (RETURN_TYPE)0; + } - ret = snprintf(filename, len, DYNAMICBOX_CONF_CONF_PATH, pkgname, pkgname); - if (ret < 0) { - DbgFree(filename); - return (RETURN_TYPE)0; - } + ret = snprintf(filename, len, DYNAMICBOX_CONF_CONF_PATH, pkgname, pkgname); + if (ret < 0) { + DbgFree(filename); + return (RETURN_TYPE)0; + } - DbgPrint("Conf file %s for package %s\n", filename, pkgname); + DbgPrint("Conf file %s for package %s\n", filename, pkgname); - EINA_LIST_FOREACH(s_list, l, item) { - if (!strcmp(item->filename, filename)) { - DbgFree(filename); - return (RETURN_TYPE)item; - } + EINA_LIST_FOREACH(s_list, l, item) { + if (!strcmp(item->filename, filename)) { + DbgFree(filename); + return (RETURN_TYPE)item; } + } - DbgFree(filename); - return (RETURN_TYPE)0; + DbgFree(filename); + return (RETURN_TYPE)0; } static inline int parse_size(const char *buffer, unsigned int *size) { - register int i; - int w; - int h; - - enum { - START, - WIDTH, - DELIM, - HEIGHT, - ERROR, - STOP, - END - } state; - - *size = 0; - state = START; - i = 0; - w = 0; - h = 0; - - while (state != ERROR && state != END) { - switch (state) { - case START: - switch (buffer[i]) { - case '1'...'9': - state = WIDTH; - break; - case ' ': - case '\t': - case ';': - i++; - break; - case '\0': - state = END; - break; - default: - state = ERROR; - break; - } + register int i; + int w; + int h; + + enum { + START, + WIDTH, + DELIM, + HEIGHT, + ERROR, + STOP, + END + } state; + + *size = 0; + state = START; + i = 0; + w = 0; + h = 0; + + while (state != ERROR && state != END) { + switch (state) { + case START: + switch (buffer[i]) { + case '1'...'9': + state = WIDTH; break; - case WIDTH: - switch (buffer[i]) { - case '0'...'9': - w = (w * 10) + (buffer[i] - '0'); - i++; - break; - case 'x': - state = DELIM; - i++; - break; - default: - state = ERROR; - break; - } - + case ' ': + case '\t': + case ';': + i++; break; - case DELIM: - switch (buffer[i]) { - case '1'...'9': - state = HEIGHT; - break; - case ' ': - case '\t': - i++; - break; - default: - state = ERROR; - break; - } + case '\0': + state = END; break; - case HEIGHT: - switch (buffer[i]) { - case '0'...'9': - h = (h * 10) + (buffer[i] - '0'); - i++; - break; - case ';': - case '\0': - state = STOP; - break; - default: - state = ERROR; - break; - } + default: + state = ERROR; break; - case STOP: - if (w == 1 && h == 1) { - *size |= DBOX_SIZE_TYPE_1x1; - } else if (w == 2 && h == 1) { - *size |= DBOX_SIZE_TYPE_2x1; - } else if (w == 2 && h == 2) { - *size |= DBOX_SIZE_TYPE_2x2; - } else if (w == 4 && h == 1) { - *size |= DBOX_SIZE_TYPE_4x1; - } else if (w == 4 && h == 2) { - *size |= DBOX_SIZE_TYPE_4x2; - } else if (w == 4 && h == 3) { - *size |= DBOX_SIZE_TYPE_4x3; - } else if (w == 4 && h == 4) { - *size |= DBOX_SIZE_TYPE_4x4; - } else if (w == 21 && h == 21) { - *size |= DBOX_SIZE_TYPE_EASY_1x1; - } else if (w == 23 && h == 21) { - *size |= DBOX_SIZE_TYPE_EASY_3x1; - } else if (w == 23 && h == 23) { - *size |= DBOX_SIZE_TYPE_EASY_3x3; - } else { - ErrPrint("Invalid size type: %dx%d\n", w, h); - } - - if (buffer[i] == ';') { - state = START; - } else if (buffer[i] == '\0') { - state = END; - } + } + break; + case WIDTH: + switch (buffer[i]) { + case '0'...'9': + w = (w * 10) + (buffer[i] - '0'); + i++; + break; + case 'x': + state = DELIM; + i++; + break; + default: + state = ERROR; + break; + } - w = 0; - h = 0; + break; + case DELIM: + switch (buffer[i]) { + case '1'...'9': + state = HEIGHT; + break; + case ' ': + case '\t': + i++; + break; + default: + state = ERROR; + break; + } + break; + case HEIGHT: + switch (buffer[i]) { + case '0'...'9': + h = (h * 10) + (buffer[i] - '0'); + i++; + break; + case ';': + case '\0': + state = STOP; + break; + default: + state = ERROR; break; - default: - return -1; } + break; + case STOP: + if (w == 1 && h == 1) { + *size |= DBOX_SIZE_TYPE_1x1; + } else if (w == 2 && h == 1) { + *size |= DBOX_SIZE_TYPE_2x1; + } else if (w == 2 && h == 2) { + *size |= DBOX_SIZE_TYPE_2x2; + } else if (w == 4 && h == 1) { + *size |= DBOX_SIZE_TYPE_4x1; + } else if (w == 4 && h == 2) { + *size |= DBOX_SIZE_TYPE_4x2; + } else if (w == 4 && h == 3) { + *size |= DBOX_SIZE_TYPE_4x3; + } else if (w == 4 && h == 4) { + *size |= DBOX_SIZE_TYPE_4x4; + } else if (w == 21 && h == 21) { + *size |= DBOX_SIZE_TYPE_EASY_1x1; + } else if (w == 23 && h == 21) { + *size |= DBOX_SIZE_TYPE_EASY_3x1; + } else if (w == 23 && h == 23) { + *size |= DBOX_SIZE_TYPE_EASY_3x3; + } else { + ErrPrint("Invalid size type: %dx%d\n", w, h); + } + + if (buffer[i] == ';') { + state = START; + } else if (buffer[i] == '\0') { + state = END; + } + + w = 0; + h = 0; + break; + default: + return -1; } + } - return *size ? 0 : -1; + return *size ? 0 : -1; } /*! @@ -333,20 +333,20 @@ static inline int parse_size(const char *buffer, unsigned int *size) */ static inline const char *rtrim(char *buffer) { - int len; + int len; - len = strlen(buffer); - while (len > 0 && isspace(buffer[len - 1])) { - len--; - } + len = strlen(buffer); + while (len > 0 && isspace(buffer[len - 1])) { + len--; + } - if (len <= 0) { - return NULL; - } + if (len <= 0) { + return NULL; + } - buffer[len] = '\0'; + buffer[len] = '\0'; - return buffer; + return buffer; } /*! @@ -355,538 +355,538 @@ static inline const char *rtrim(char *buffer) */ static inline char *dup_rtrim(char *buffer) { - char *ret; + char *ret; - if (!rtrim(buffer)) { - return NULL; - } + if (!rtrim(buffer)) { + return NULL; + } - ret = strdup(buffer); - if (!ret) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + ret = strdup(buffer); + if (!ret) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - return ret; + return ret; } static void period_handler(struct parser *item, char *buffer) { - char *tmp = NULL; + char *tmp = NULL; - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->period = strtod(buffer, &tmp); + item->period = strtod(buffer, &tmp); } static void timeout_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->timeout = atoi(buffer); + item->timeout = atoi(buffer); } static void network_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->network = !!atoi(buffer); + item->network = !!atoi(buffer); } static void auto_launch_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->auto_launch = strdup(buffer); - if (!item->auto_launch) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; - } + item->auto_launch = strdup(buffer); + if (!item->auto_launch) { + ErrPrint("Heap: %s\n", strerror(errno)); + return; + } } static void size_handler(struct parser *item, char *buffer) { - if (parse_size(buffer, &item->size) == -1) { - ErrPrint("Failed to get size\n"); - item->size = 0x00000001; - } + if (parse_size(buffer, &item->size) == -1) { + ErrPrint("Failed to get size\n"); + item->size = 0x00000001; + } } static void gbar_size_handler(struct parser *item, char *buffer) { - if (sscanf(buffer, "%ux%u", &item->gbar_width, &item->gbar_height) != 2) { - ErrPrint("parse pd size\n"); - } + if (sscanf(buffer, "%ux%u", &item->gbar_width, &item->gbar_height) != 2) { + ErrPrint("parse pd size\n"); + } } static void text_dbox_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->text_lb = !!atoi(buffer); + item->text_lb = !!atoi(buffer); } static void abi_handler(struct parser *item, char *buffer) { - item->abi = dup_rtrim(buffer); + item->abi = dup_rtrim(buffer); } static void script_handler(struct parser *item, char *buffer) { - item->script = dup_rtrim(buffer); + item->script = dup_rtrim(buffer); } static void buffer_gbar_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->buffer_gbar = !!atoi(buffer); + item->buffer_gbar = !!atoi(buffer); } static void buffer_dbox_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->buffer_lb = !!atoi(buffer); + item->buffer_lb = !!atoi(buffer); } static void text_gbar_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->text_gbar = !!atoi(buffer); + item->text_gbar = !!atoi(buffer); } static void pinup_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->pinup = !!atoi(buffer); + item->pinup = !!atoi(buffer); } static void dbox_path_handler(struct parser *item, char *buffer) { - if (item->dbox_path) { - DbgFree(item->dbox_path); - } + if (item->dbox_path) { + DbgFree(item->dbox_path); + } - item->dbox_path = dup_rtrim(buffer); - if (!item->dbox_path) { - ErrPrint("Error: %s\n", strerror(errno)); - } + item->dbox_path = dup_rtrim(buffer); + if (!item->dbox_path) { + ErrPrint("Error: %s\n", strerror(errno)); + } } static void group_handler(struct parser *item, char *buffer) { - if (item->group) { - DbgFree(item->group); - } + if (item->group) { + DbgFree(item->group); + } - item->group = dup_rtrim(buffer); - if (!item->group) { - ErrPrint("Error: %s\n", strerror(errno)); - } + item->group = dup_rtrim(buffer); + if (!item->group) { + ErrPrint("Error: %s\n", strerror(errno)); + } } static void secured_handler(struct parser *item, char *buffer) { - if (!rtrim(buffer)) { - return; - } + if (!rtrim(buffer)) { + return; + } - item->secured = !!atoi(buffer); + item->secured = !!atoi(buffer); } static void dbox_group_handler(struct parser *item, char *buffer) { - if (item->dbox_group) { - DbgFree(item->dbox_group); - } + if (item->dbox_group) { + DbgFree(item->dbox_group); + } - item->dbox_group = dup_rtrim(buffer); - if (!item->dbox_group) { - ErrPrint("Error: %s\n", strerror(errno)); - } + item->dbox_group = dup_rtrim(buffer); + if (!item->dbox_group) { + ErrPrint("Error: %s\n", strerror(errno)); + } } static void gbar_path_handler(struct parser *item, char *buffer) { - if (item->gbar_path) { - DbgFree(item->gbar_path); - } + if (item->gbar_path) { + DbgFree(item->gbar_path); + } - item->gbar_path = dup_rtrim(buffer); - if (!item->gbar_path) { - ErrPrint("Error: %s\n", strerror(errno)); - } + item->gbar_path = dup_rtrim(buffer); + if (!item->gbar_path) { + ErrPrint("Error: %s\n", strerror(errno)); + } } static void gbar_group_handler(struct parser *item, char *buffer) { - if (item->gbar_group) { - DbgFree(item->gbar_group); - } + if (item->gbar_group) { + DbgFree(item->gbar_group); + } - item->gbar_group = dup_rtrim(buffer); - if (!item->gbar_group) { - ErrPrint("Error: %s\n", strerror(errno)); - } + item->gbar_group = dup_rtrim(buffer); + if (!item->gbar_group) { + ErrPrint("Error: %s\n", strerror(errno)); + } } HAPI struct parser *parser_load(const char *pkgname) { - struct parser *item; - FILE *fp; - int c; - enum state { - START, - SPACE, - TOKEN, - VALUE, - ERROR, - COMMENT, - END - } state; - int ch_idx; - int token_idx; - int buffer_idx; - int quote; - int len; - int linelen; - char buffer[256]; - static const struct token_parser { - const char *name; - void (*handler)(struct parser *, char *buffer); - } token_handler[] = { - { - .name = "period", - .handler = period_handler, - }, - { - .name = "timeout", - .handler = timeout_handler, - }, - { - .name = "network", - .handler = network_handler, - }, - { - .name = "auto_launch", - .handler = auto_launch_handler, - }, - { - .name = "size", - .handler = size_handler, - }, - { - .name = "group", - .handler = group_handler, - }, - { - .name = "secured", - .handler = secured_handler, - }, - { - .name = "dynamicbox_path", - .handler = dbox_path_handler, - }, - { - .name = "dynamicbox_group", - .handler = dbox_group_handler, - }, - { - .name = "gbar_path", - .handler = gbar_path_handler, - }, - { - .name = "gbar_group", - .handler = gbar_group_handler, - }, - { - .name = "gbar_size", - .handler = gbar_size_handler, - }, - { - .name = "pinup", - .handler = pinup_handler, - }, - { - .name = "text_dynamicbox", - .handler = text_dbox_handler, - }, - { - .name = "text_gbar", - .handler = text_gbar_handler, - }, - { - .name = "buffer_dynamicbox", - .handler = buffer_dbox_handler, - }, - { - .name = "buffer_gbar", - .handler = buffer_gbar_handler, - }, - { - .name = "script", - .handler = script_handler, - }, - { - .name = "abi", - .handler = abi_handler, - }, - { - .name = NULL, - .handler = NULL, - }, - }; - int ret; - - item = calloc(1, sizeof(*item)); - if (!item) { - return 0; - } - - /* live-, .conf */ - len = strlen(DYNAMICBOX_CONF_CONF_PATH) + strlen(pkgname) * 2; - item->filename = malloc(len); - if (!item->filename) { - ErrPrint("Error: %s\n", strerror(errno)); - DbgFree(item); - return 0; - } - - ret = snprintf(item->filename, len, DYNAMICBOX_CONF_CONF_PATH, pkgname, pkgname); - if (ret < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - DbgFree(item->filename); - DbgFree(item); - return 0; - } - - item->dbox_path = NULL; - item->dbox_group = NULL; - item->gbar_width = 0; - item->gbar_height = 0; - item->auto_launch = NULL; - item->size = 0x00000001; - item->group = NULL; - item->secured = 0; - item->pinup = 0; - - fp = fopen(item->filename, "rt"); - if (!fp) { - DbgFree(item->filename); - DbgFree(item); - return 0; - } + struct parser *item; + FILE *fp; + int c; + enum state { + START, + SPACE, + TOKEN, + VALUE, + ERROR, + COMMENT, + END + } state; + int ch_idx; + int token_idx; + int buffer_idx; + int quote; + int len; + int linelen; + char buffer[256]; + static const struct token_parser { + const char *name; + void (*handler)(struct parser *, char *buffer); + } token_handler[] = { + { + .name = "period", + .handler = period_handler, + }, + { + .name = "timeout", + .handler = timeout_handler, + }, + { + .name = "network", + .handler = network_handler, + }, + { + .name = "auto_launch", + .handler = auto_launch_handler, + }, + { + .name = "size", + .handler = size_handler, + }, + { + .name = "group", + .handler = group_handler, + }, + { + .name = "secured", + .handler = secured_handler, + }, + { + .name = "dynamicbox_path", + .handler = dbox_path_handler, + }, + { + .name = "dynamicbox_group", + .handler = dbox_group_handler, + }, + { + .name = "gbar_path", + .handler = gbar_path_handler, + }, + { + .name = "gbar_group", + .handler = gbar_group_handler, + }, + { + .name = "gbar_size", + .handler = gbar_size_handler, + }, + { + .name = "pinup", + .handler = pinup_handler, + }, + { + .name = "text_dynamicbox", + .handler = text_dbox_handler, + }, + { + .name = "text_gbar", + .handler = text_gbar_handler, + }, + { + .name = "buffer_dynamicbox", + .handler = buffer_dbox_handler, + }, + { + .name = "buffer_gbar", + .handler = buffer_gbar_handler, + }, + { + .name = "script", + .handler = script_handler, + }, + { + .name = "abi", + .handler = abi_handler, + }, + { + .name = NULL, + .handler = NULL, + }, + }; + int ret; + + item = calloc(1, sizeof(*item)); + if (!item) { + return 0; + } + + /* live-, .conf */ + len = strlen(DYNAMICBOX_CONF_CONF_PATH) + strlen(pkgname) * 2; + item->filename = malloc(len); + if (!item->filename) { + ErrPrint("Error: %s\n", strerror(errno)); + DbgFree(item); + return 0; + } - state = START; - ch_idx = 0; - token_idx = -1; - buffer_idx = 0; - quote = 0; - linelen = 0; - do { - c = getc(fp); - if ((c == EOF) && (state == VALUE)) { - state = END; + ret = snprintf(item->filename, len, DYNAMICBOX_CONF_CONF_PATH, pkgname, pkgname); + if (ret < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + DbgFree(item->filename); + DbgFree(item); + return 0; + } + + item->dbox_path = NULL; + item->dbox_group = NULL; + item->gbar_width = 0; + item->gbar_height = 0; + item->auto_launch = NULL; + item->size = 0x00000001; + item->group = NULL; + item->secured = 0; + item->pinup = 0; + + fp = fopen(item->filename, "rt"); + if (!fp) { + DbgFree(item->filename); + DbgFree(item); + return 0; + } + + state = START; + ch_idx = 0; + token_idx = -1; + buffer_idx = 0; + quote = 0; + linelen = 0; + do { + c = getc(fp); + if ((c == EOF) && (state == VALUE)) { + state = END; + } + + switch (state) { + case COMMENT: + if (c == CR || c == LF || c == EOF) { + buffer[buffer_idx] = '\0'; + + state = START; + token_idx = -1; + ch_idx = 0; + buffer_idx = 0; + linelen = -1; /* Will be ZERO by follwing increment code */ + quote = 0; + } else { + buffer[buffer_idx++] = c; + if (buffer_idx == (sizeof(buffer) - 1)) { + buffer[buffer_idx] = '\0'; + buffer_idx = 0; + } } - - switch (state) { - case COMMENT: - if (c == CR || c == LF || c == EOF) { - buffer[buffer_idx] = '\0'; - - state = START; - token_idx = -1; - ch_idx = 0; - buffer_idx = 0; - linelen = -1; /* Will be ZERO by follwing increment code */ - quote = 0; - } else { - buffer[buffer_idx++] = c; - if (buffer_idx == (sizeof(buffer) - 1)) { - buffer[buffer_idx] = '\0'; - buffer_idx = 0; - } - } - break; - case START: - if (linelen == 0 && c == '#') { - state = COMMENT; - } else if (isspace(c)) { - /* Ignore empty space */ - } else { - state = TOKEN; - ungetc(c, fp); - } - break; - case SPACE: - if (c == '=') { - state = VALUE; - } else if (!isspace(c)) { - state = ERROR; - } - break; - case VALUE: - if (c == '"') { - if (quote == 1) { - buffer[buffer_idx] = '\0'; - state = END; - } else if (buffer_idx != 0) { - buffer[buffer_idx++] = c; - if (buffer_idx >= sizeof(buffer)) { - state = ERROR; - } - } else { - quote = 1; - } - } else if (isspace(c)) { - if (buffer_idx == 0) { - /* Ignore */ - } else if (quote == 1) { - buffer[buffer_idx++] = c; - if (buffer_idx >= sizeof(buffer)) { - state = ERROR; - } - } else { - buffer[buffer_idx] = '\0'; - ungetc(c, fp); - state = END; - } - } else { - buffer[buffer_idx++] = c; - if (buffer_idx >= sizeof(buffer)) { - state = ERROR; - } + break; + case START: + if (linelen == 0 && c == '#') { + state = COMMENT; + } else if (isspace(c)) { + /* Ignore empty space */ + } else { + state = TOKEN; + ungetc(c, fp); + } + break; + case SPACE: + if (c == '=') { + state = VALUE; + } else if (!isspace(c)) { + state = ERROR; + } + break; + case VALUE: + if (c == '"') { + if (quote == 1) { + buffer[buffer_idx] = '\0'; + state = END; + } else if (buffer_idx != 0) { + buffer[buffer_idx++] = c; + if (buffer_idx >= sizeof(buffer)) { + state = ERROR; } - break; - case TOKEN: - if (c == '=') { - if (token_idx < 0) { - state = ERROR; - } else { - state = VALUE; - } - } else if (isspace(c)) { - if (token_idx < 0) { - break; - } - - if (token_handler[token_idx].name[ch_idx] != '\0') { - state = ERROR; - } else { - state = SPACE; - } - } else { - if (token_idx < 0) { - /* Now start to find a token! */ - token_idx = 0; - } - - if (token_handler[token_idx].name[ch_idx] == c) { - ch_idx++; - } else { - ungetc(c, fp); - while (ch_idx-- > 0) { - ungetc(token_handler[token_idx].name[ch_idx], fp); - } - - token_idx++; - - if (token_handler[token_idx].name == NULL) { - state = ERROR; - } else { - ch_idx = 0; - } - } + } else { + quote = 1; + } + } else if (isspace(c)) { + if (buffer_idx == 0) { + /* Ignore */ + } else if (quote == 1) { + buffer[buffer_idx++] = c; + if (buffer_idx >= sizeof(buffer)) { + state = ERROR; } + } else { + buffer[buffer_idx] = '\0'; + ungetc(c, fp); + state = END; + } + } else { + buffer[buffer_idx++] = c; + if (buffer_idx >= sizeof(buffer)) { + state = ERROR; + } + } + break; + case TOKEN: + if (c == '=') { + if (token_idx < 0) { + state = ERROR; + } else { + state = VALUE; + } + } else if (isspace(c)) { + if (token_idx < 0) { break; - case ERROR: - if (c == CR || c == LF || c == EOF) { - state = START; - token_idx = -1; - buffer_idx = 0; - ch_idx = 0; - linelen = -1; - quote = 0; + } + + if (token_handler[token_idx].name[ch_idx] != '\0') { + state = ERROR; + } else { + state = SPACE; + } + } else { + if (token_idx < 0) { + /* Now start to find a token! */ + token_idx = 0; + } + + if (token_handler[token_idx].name[ch_idx] == c) { + ch_idx++; + } else { + ungetc(c, fp); + while (ch_idx-- > 0) { + ungetc(token_handler[token_idx].name[ch_idx], fp); } - break; - case END: - if (c == LF || c == CR || c == EOF) { - state = START; - - /*! - * \NOTE - * Make the string terminator - */ - buffer[buffer_idx] = '\0'; - - if (token_idx >= 0 && token_handler[token_idx].handler) { - token_handler[token_idx].handler(item, buffer); - } - - token_idx = -1; - ch_idx = 0; - buffer_idx = 0; - linelen = -1; - quote = 0; - /* Finish */ - } else if (isspace(c)) { - /* ignore */ + + token_idx++; + + if (token_handler[token_idx].name == NULL) { + state = ERROR; } else { - state = ERROR; + ch_idx = 0; } - break; - default: - /* ?? */ - break; + } + } + break; + case ERROR: + if (c == CR || c == LF || c == EOF) { + state = START; + token_idx = -1; + buffer_idx = 0; + ch_idx = 0; + linelen = -1; + quote = 0; + } + break; + case END: + if (c == LF || c == CR || c == EOF) { + state = START; + + /*! + * \NOTE + * Make the string terminator + */ + buffer[buffer_idx] = '\0'; + + if (token_idx >= 0 && token_handler[token_idx].handler) { + token_handler[token_idx].handler(item, buffer); + } + + token_idx = -1; + ch_idx = 0; + buffer_idx = 0; + linelen = -1; + quote = 0; + /* Finish */ + } else if (isspace(c)) { + /* ignore */ + } else { + state = ERROR; } + break; + default: + /* ?? */ + break; + } - linelen++; - } while (c != EOF); + linelen++; + } while (c != EOF); - if (fclose(fp) != 0) { - ErrPrint("fclose: %s\n", strerror(errno)); - } + if (fclose(fp) != 0) { + ErrPrint("fclose: %s\n", strerror(errno)); + } - s_list = eina_list_append(s_list, item); - return item; + s_list = eina_list_append(s_list, item); + return item; } HAPI int parser_unload(struct parser *item) { - s_list = eina_list_remove(s_list, item); - - DbgFree(item->auto_launch); - DbgFree(item->abi); - DbgFree(item->script); - DbgFree(item->group); - DbgFree(item->gbar_group); - DbgFree(item->gbar_path); - DbgFree(item->dbox_group); - DbgFree(item->dbox_path); - DbgFree(item->filename); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; + s_list = eina_list_remove(s_list, item); + + DbgFree(item->auto_launch); + DbgFree(item->abi); + DbgFree(item->script); + DbgFree(item->group); + DbgFree(item->gbar_group); + DbgFree(item->gbar_path); + DbgFree(item->dbox_group); + DbgFree(item->dbox_path); + DbgFree(item->filename); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/pkgmgr.c b/src/pkgmgr.c index 5ad2672..394a08a 100644 --- a/src/pkgmgr.c +++ b/src/pkgmgr.c @@ -29,598 +29,598 @@ #include "conf.h" struct item { - char *pkgname; - char *icon; + char *pkgname; + char *icon; - enum pkgmgr_event_type type; - enum pkgmgr_status status; + enum pkgmgr_event_type type; + enum pkgmgr_status status; }; static struct { - pkgmgr_client *listen_pc; - Eina_List *item_list; - - Eina_List *install_event; - Eina_List *uninstall_event; - Eina_List *update_event; - Eina_List *download_event; - Eina_List *recover_event; + pkgmgr_client *listen_pc; + Eina_List *item_list; + + Eina_List *install_event; + Eina_List *uninstall_event; + Eina_List *update_event; + Eina_List *download_event; + Eina_List *recover_event; } s_info = { - .listen_pc = NULL, - .item_list = NULL, - - .install_event = NULL, - .uninstall_event = NULL, - .update_event = NULL, - .download_event = NULL, - .recover_event = NULL, + .listen_pc = NULL, + .item_list = NULL, + + .install_event = NULL, + .uninstall_event = NULL, + .update_event = NULL, + .download_event = NULL, + .recover_event = NULL, }; struct event_item { - int (*cb)(const char *pkgname, enum pkgmgr_status status, double value, void *data); - void *data; + int (*cb)(const char *pkgname, enum pkgmgr_status status, double value, void *data); + void *data; }; static inline void invoke_install_event_handler(const char *pkgname, enum pkgmgr_status status, double value) { - Eina_List *l; - struct event_item *item; + Eina_List *l; + struct event_item *item; - EINA_LIST_FOREACH(s_info.install_event, l, item) { - if (item->cb) { - item->cb(pkgname, status, value, item->data); - } + EINA_LIST_FOREACH(s_info.install_event, l, item) { + if (item->cb) { + item->cb(pkgname, status, value, item->data); } + } } static inline void invoke_uninstall_event_handler(const char *pkgname, enum pkgmgr_status status, double value) { - Eina_List *l; - struct event_item *item; + Eina_List *l; + struct event_item *item; - EINA_LIST_FOREACH(s_info.uninstall_event, l, item) { - if (item->cb) { - item->cb(pkgname, status, value, item->data); - } + EINA_LIST_FOREACH(s_info.uninstall_event, l, item) { + if (item->cb) { + item->cb(pkgname, status, value, item->data); } + } } static inline void invoke_update_event_handler(const char *pkgname, enum pkgmgr_status status, double value) { - Eina_List *l; - struct event_item *item; + Eina_List *l; + struct event_item *item; - EINA_LIST_FOREACH(s_info.update_event, l, item) { - if (item->cb) { - item->cb(pkgname, status, value, item->data); - } + EINA_LIST_FOREACH(s_info.update_event, l, item) { + if (item->cb) { + item->cb(pkgname, status, value, item->data); } + } } static inline void invoke_download_event_handler(const char *pkgname, enum pkgmgr_status status, double value) { - Eina_List *l; - struct event_item *item; + Eina_List *l; + struct event_item *item; - EINA_LIST_FOREACH(s_info.download_event, l, item) { - if (item->cb) { - item->cb(pkgname, status, value, item->data); - } + EINA_LIST_FOREACH(s_info.download_event, l, item) { + if (item->cb) { + item->cb(pkgname, status, value, item->data); } + } } static inline void invoke_recover_event_handler(const char *pkgname, enum pkgmgr_status status, double value) { - Eina_List *l; - struct event_item *item; + Eina_List *l; + struct event_item *item; - EINA_LIST_FOREACH(s_info.recover_event, l, item) { - if (item->cb) { - item->cb(pkgname, status, value, item->data); - } + EINA_LIST_FOREACH(s_info.recover_event, l, item) { + if (item->cb) { + item->cb(pkgname, status, value, item->data); } + } } static inline void invoke_callback(const char *pkgname, struct item *item, double value) { - switch (item->type) { + switch (item->type) { case PKGMGR_EVENT_DOWNLOAD: - invoke_download_event_handler(pkgname, item->status, value); - break; + invoke_download_event_handler(pkgname, item->status, value); + break; case PKGMGR_EVENT_UNINSTALL: - invoke_uninstall_event_handler(pkgname, item->status, value); - break; + invoke_uninstall_event_handler(pkgname, item->status, value); + break; case PKGMGR_EVENT_INSTALL: - invoke_install_event_handler(pkgname, item->status, value); - break; + invoke_install_event_handler(pkgname, item->status, value); + break; case PKGMGR_EVENT_UPDATE: - invoke_update_event_handler(pkgname, item->status, value); - break; + invoke_update_event_handler(pkgname, item->status, value); + break; case PKGMGR_EVENT_RECOVER: - invoke_recover_event_handler(pkgname, item->status, value); - break; + invoke_recover_event_handler(pkgname, item->status, value); + break; default: - ErrPrint("Unknown type: %d\n", item->type); - break; - } + ErrPrint("Unknown type: %d\n", item->type); + break; + } } static inline int is_valid_status(struct item *item, const char *status) { - const char *expected_status; + const char *expected_status; - switch (item->type) { + switch (item->type) { case PKGMGR_EVENT_DOWNLOAD: - expected_status = "download"; - break; + expected_status = "download"; + break; case PKGMGR_EVENT_UNINSTALL: - expected_status = "uninstall"; - break; + expected_status = "uninstall"; + break; case PKGMGR_EVENT_INSTALL: - expected_status = "install"; - break; + expected_status = "install"; + break; case PKGMGR_EVENT_UPDATE: - expected_status = "update"; - break; + expected_status = "update"; + break; case PKGMGR_EVENT_RECOVER: - expected_status = "recover"; - break; + expected_status = "recover"; + break; default: - return 0; - } + return 0; + } - return !strcasecmp(status, expected_status); + return !strcasecmp(status, expected_status); } static struct item *find_item(const char *pkgname) { - Eina_List *l; - struct item *item; - - if (!pkgname) { - ErrPrint("Package name is not valid\n"); - return NULL; - } + Eina_List *l; + struct item *item; - EINA_LIST_FOREACH(s_info.item_list, l, item) { - if (strcmp(item->pkgname, pkgname)) { - continue; - } + if (!pkgname) { + ErrPrint("Package name is not valid\n"); + return NULL; + } - return item; + EINA_LIST_FOREACH(s_info.item_list, l, item) { + if (strcmp(item->pkgname, pkgname)) { + continue; } - DbgPrint("Package %s is not found\n", pkgname); - return NULL; + return item; + } + + DbgPrint("Package %s is not found\n", pkgname); + return NULL; } static int start_cb(const char *pkgname, const char *val, void *data) { - struct item *item; - - DbgPrint("[%s] %s\n", pkgname, val); + struct item *item; - item = calloc(1, sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + DbgPrint("[%s] %s\n", pkgname, val); - item->pkgname = strdup(pkgname); - if (!item->pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(item); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = calloc(1, sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->status = PKGMGR_STATUS_START; - - if (!strcasecmp(val, "download")) { - item->type = PKGMGR_EVENT_DOWNLOAD; - } else if (!strcasecmp(val, "uninstall")) { - item->type = PKGMGR_EVENT_UNINSTALL; - } else if (!strcasecmp(val, "install")) { - item->type = PKGMGR_EVENT_INSTALL; - } else if (!strcasecmp(val, "update")) { - item->type = PKGMGR_EVENT_UPDATE; - } else if (!strcasecmp(val, "recover")) { - item->type = PKGMGR_EVENT_RECOVER; - } else { - DbgFree(item->pkgname); - DbgFree(item); - ErrPrint("Invalid val: %s\n", val); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + item->pkgname = strdup(pkgname); + if (!item->pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(item); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + item->status = PKGMGR_STATUS_START; + + if (!strcasecmp(val, "download")) { + item->type = PKGMGR_EVENT_DOWNLOAD; + } else if (!strcasecmp(val, "uninstall")) { + item->type = PKGMGR_EVENT_UNINSTALL; + } else if (!strcasecmp(val, "install")) { + item->type = PKGMGR_EVENT_INSTALL; + } else if (!strcasecmp(val, "update")) { + item->type = PKGMGR_EVENT_UPDATE; + } else if (!strcasecmp(val, "recover")) { + item->type = PKGMGR_EVENT_RECOVER; + } else { + DbgFree(item->pkgname); + DbgFree(item); + ErrPrint("Invalid val: %s\n", val); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - s_info.item_list = eina_list_append(s_info.item_list, item); + s_info.item_list = eina_list_append(s_info.item_list, item); - invoke_callback(pkgname, item, 0.0f); - return DBOX_STATUS_ERROR_NONE; + invoke_callback(pkgname, item, 0.0f); + return DBOX_STATUS_ERROR_NONE; } static int icon_path_cb(const char *pkgname, const char *val, void *data) { - struct item *item; + struct item *item; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + item = find_item(pkgname); + if (!item) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - if (item->icon) { - DbgFree(item->icon); - } + if (item->icon) { + DbgFree(item->icon); + } - item->icon = strdup(val); - if (!item->icon) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item->icon = strdup(val); + if (!item->icon) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static int command_cb(const char *pkgname, const char *val, void *data) { - struct item *item; + struct item *item; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + item = find_item(pkgname); + if (!item) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - if (!is_valid_status(item, val)) { - DbgPrint("Invalid status: %d, %s\n", item->type, val); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!is_valid_status(item, val)) { + DbgPrint("Invalid status: %d, %s\n", item->type, val); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - item->status = PKGMGR_STATUS_COMMAND; - invoke_callback(pkgname, item, 0.0f); - return DBOX_STATUS_ERROR_NONE; + item->status = PKGMGR_STATUS_COMMAND; + invoke_callback(pkgname, item, 0.0f); + return DBOX_STATUS_ERROR_NONE; } static int error_cb(const char *pkgname, const char *val, void *data) { - /* val = error */ - struct item *item; + /* val = error */ + struct item *item; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + item = find_item(pkgname); + if (!item) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - item->status = PKGMGR_STATUS_ERROR; - invoke_callback(pkgname, item, 0.0f); - return DBOX_STATUS_ERROR_NONE; + item->status = PKGMGR_STATUS_ERROR; + invoke_callback(pkgname, item, 0.0f); + return DBOX_STATUS_ERROR_NONE; } static int change_pkgname_cb(const char *pkgname, const char *val, void *data) { - struct item *item; - char *new_pkgname; + struct item *item; + char *new_pkgname; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + item = find_item(pkgname); + if (!item) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - new_pkgname = strdup(val); - if (!new_pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + new_pkgname = strdup(val); + if (!new_pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgFree(item->pkgname); - item->pkgname = new_pkgname; - return DBOX_STATUS_ERROR_NONE; + DbgFree(item->pkgname); + item->pkgname = new_pkgname; + return DBOX_STATUS_ERROR_NONE; } static int download_cb(const char *pkgname, const char *val, void *data) { - /* val = integer */ - struct item *item; - double value; + /* val = integer */ + struct item *item; + double value; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - DbgPrint("ITEM is not started from the start_cb\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + item = find_item(pkgname); + if (!item) { + DbgPrint("ITEM is not started from the start_cb\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (item->type != PKGMGR_EVENT_DOWNLOAD) { - DbgPrint("TYPE is not \"download\" : %d\n", item->type); - item->type = PKGMGR_EVENT_DOWNLOAD; - } + if (item->type != PKGMGR_EVENT_DOWNLOAD) { + DbgPrint("TYPE is not \"download\" : %d\n", item->type); + item->type = PKGMGR_EVENT_DOWNLOAD; + } - switch (item->status) { + switch (item->status) { case PKGMGR_STATUS_START: case PKGMGR_STATUS_COMMAND: - item->status = PKGMGR_STATUS_PROCESSING; + item->status = PKGMGR_STATUS_PROCESSING; case PKGMGR_STATUS_PROCESSING: - break; + break; default: - ErrPrint("Invalid state [%s, %s]\n", pkgname, val); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Invalid state [%s, %s]\n", pkgname, val); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (val) { - if (sscanf(val, "%lf", &value) != 1) { - value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - } else { - value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (val) { + if (sscanf(val, "%lf", &value) != 1) { + value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; } + } else { + value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - invoke_download_event_handler(pkgname, item->status, value); - return DBOX_STATUS_ERROR_NONE; + invoke_download_event_handler(pkgname, item->status, value); + return DBOX_STATUS_ERROR_NONE; } static int progress_cb(const char *pkgname, const char *val, void *data) { - /* val = integer */ - struct item *item; - double value; + /* val = integer */ + struct item *item; + double value; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - ErrPrint("ITEM is not started from the start_cb\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + item = find_item(pkgname); + if (!item) { + ErrPrint("ITEM is not started from the start_cb\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (item->status) { + switch (item->status) { case PKGMGR_STATUS_START: case PKGMGR_STATUS_COMMAND: - item->status = PKGMGR_STATUS_PROCESSING; + item->status = PKGMGR_STATUS_PROCESSING; case PKGMGR_STATUS_PROCESSING: - break; + break; default: - ErrPrint("Invalid state [%s, %s]\n", pkgname, val); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Invalid state [%s, %s]\n", pkgname, val); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (val) { - if (sscanf(val, "%lf", &value) != 1) { - value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - } else { - value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (val) { + if (sscanf(val, "%lf", &value) != 1) { + value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; } + } else { + value = (double)DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - invoke_callback(pkgname, item, value); - return DBOX_STATUS_ERROR_NONE; + invoke_callback(pkgname, item, value); + return DBOX_STATUS_ERROR_NONE; } static int end_cb(const char *pkgname, const char *val, void *data) { - struct item *item; + struct item *item; - DbgPrint("[%s] %s\n", pkgname, val); + DbgPrint("[%s] %s\n", pkgname, val); - item = find_item(pkgname); - if (!item) { - return DBOX_STATUS_ERROR_NOT_EXIST; - } + item = find_item(pkgname); + if (!item) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - item->status = !strcasecmp(val, "ok") ? PKGMGR_STATUS_END : PKGMGR_STATUS_ERROR; + item->status = !strcasecmp(val, "ok") ? PKGMGR_STATUS_END : PKGMGR_STATUS_ERROR; - invoke_callback(pkgname, item, 0.0f); + invoke_callback(pkgname, item, 0.0f); - s_info.item_list = eina_list_remove(s_info.item_list, item); - DbgFree(item->icon); - DbgFree(item->pkgname); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; + s_info.item_list = eina_list_remove(s_info.item_list, item); + DbgFree(item->icon); + DbgFree(item->pkgname); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } static struct pkgmgr_handler { - const char *key; - int (*func)(const char *package, const char *val, void *data); + const char *key; + int (*func)(const char *package, const char *val, void *data); } handler[] = { - { "install_percent", progress_cb }, - { "download_percent", download_cb }, - { "start", start_cb }, - { "end", end_cb }, - { "change_pkg_name", change_pkgname_cb }, - { "icon_path", icon_path_cb }, - { "command", command_cb }, - { "error", error_cb }, - { NULL, NULL }, + { "install_percent", progress_cb }, + { "download_percent", download_cb }, + { "start", start_cb }, + { "end", end_cb }, + { "change_pkg_name", change_pkgname_cb }, + { "icon_path", icon_path_cb }, + { "command", command_cb }, + { "error", error_cb }, + { NULL, NULL }, }; static int pkgmgr_cb(int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data) { - register int i; - int ret; + register int i; + int ret; - for (i = 0; handler[i].key; i++) { - if (strcasecmp(key, handler[i].key)) { - continue; - } + for (i = 0; handler[i].key; i++) { + if (strcasecmp(key, handler[i].key)) { + continue; + } - ret = handler[i].func(pkgname, val, data); - if (ret < 0) { - DbgPrint("REQ[%d] pkgname[%s], type[%s], key[%s], val[%s], ret = %d\n", - req_id, pkgname, type, key, val, ret); - } + ret = handler[i].func(pkgname, val, data); + if (ret < 0) { + DbgPrint("REQ[%d] pkgname[%s], type[%s], key[%s], val[%s], ret = %d\n", + req_id, pkgname, type, key, val, ret); } + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int pkgmgr_init(void) { - if (s_info.listen_pc) { - return DBOX_STATUS_ERROR_ALREADY; - } + if (s_info.listen_pc) { + return DBOX_STATUS_ERROR_ALREADY; + } - s_info.listen_pc = pkgmgr_client_new(PC_LISTENING); - if (!s_info.listen_pc) { - return DBOX_STATUS_ERROR_FAULT; - } + s_info.listen_pc = pkgmgr_client_new(PC_LISTENING); + if (!s_info.listen_pc) { + return DBOX_STATUS_ERROR_FAULT; + } - if (pkgmgr_client_listen_status(s_info.listen_pc, pkgmgr_cb, NULL) != PKGMGR_R_OK) { - return DBOX_STATUS_ERROR_FAULT; - } + if (pkgmgr_client_listen_status(s_info.listen_pc, pkgmgr_cb, NULL) != PKGMGR_R_OK) { + return DBOX_STATUS_ERROR_FAULT; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int pkgmgr_fini(void) { - struct event_item *item; - struct item *ctx; + struct event_item *item; + struct item *ctx; - if (!s_info.listen_pc) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!s_info.listen_pc) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (pkgmgr_client_free(s_info.listen_pc) != PKGMGR_R_OK) { - return DBOX_STATUS_ERROR_FAULT; - } + if (pkgmgr_client_free(s_info.listen_pc) != PKGMGR_R_OK) { + return DBOX_STATUS_ERROR_FAULT; + } - s_info.listen_pc = NULL; + s_info.listen_pc = NULL; - EINA_LIST_FREE(s_info.download_event, item) { - DbgFree(item); - } + EINA_LIST_FREE(s_info.download_event, item) { + DbgFree(item); + } - EINA_LIST_FREE(s_info.uninstall_event, item) { - DbgFree(item); - } + EINA_LIST_FREE(s_info.uninstall_event, item) { + DbgFree(item); + } - EINA_LIST_FREE(s_info.install_event, item) { - DbgFree(item); - } + EINA_LIST_FREE(s_info.install_event, item) { + DbgFree(item); + } - EINA_LIST_FREE(s_info.update_event, item) { - DbgFree(item); - } + EINA_LIST_FREE(s_info.update_event, item) { + DbgFree(item); + } - EINA_LIST_FREE(s_info.recover_event, item) { - DbgFree(item); - } + EINA_LIST_FREE(s_info.recover_event, item) { + DbgFree(item); + } - EINA_LIST_FREE(s_info.item_list, ctx) { - DbgFree(ctx->pkgname); - DbgFree(ctx->icon); - DbgFree(ctx); - } + EINA_LIST_FREE(s_info.item_list, ctx) { + DbgFree(ctx->pkgname); + DbgFree(ctx->icon); + DbgFree(ctx); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int pkgmgr_add_event_callback(enum pkgmgr_event_type type, int (*cb)(const char *pkgname, enum pkgmgr_status status, double value, void *data), void *data) { - struct event_item *item; + struct event_item *item; - item = calloc(1, sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = calloc(1, sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->cb = cb; - item->data = data; + item->cb = cb; + item->data = data; - switch (type) { + switch (type) { case PKGMGR_EVENT_DOWNLOAD: - s_info.download_event = eina_list_prepend(s_info.download_event, item); - break; + s_info.download_event = eina_list_prepend(s_info.download_event, item); + break; case PKGMGR_EVENT_UNINSTALL: - s_info.uninstall_event = eina_list_prepend(s_info.uninstall_event, item); - break; + s_info.uninstall_event = eina_list_prepend(s_info.uninstall_event, item); + break; case PKGMGR_EVENT_INSTALL: - s_info.install_event = eina_list_prepend(s_info.install_event, item); - break; + s_info.install_event = eina_list_prepend(s_info.install_event, item); + break; case PKGMGR_EVENT_UPDATE: - s_info.update_event = eina_list_prepend(s_info.update_event, item); - break; + s_info.update_event = eina_list_prepend(s_info.update_event, item); + break; case PKGMGR_EVENT_RECOVER: - s_info.recover_event = eina_list_prepend(s_info.recover_event, item); - break; + s_info.recover_event = eina_list_prepend(s_info.recover_event, item); + break; default: - DbgFree(item); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + DbgFree(item); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI void *pkgmgr_del_event_callback(enum pkgmgr_event_type type, int (*cb)(const char *pkgname, enum pkgmgr_status status, double value, void *data), void *data) { - struct event_item *item; - Eina_List *l; - void *cbdata = NULL; + struct event_item *item; + Eina_List *l; + void *cbdata = NULL; - switch (type) { + switch (type) { case PKGMGR_EVENT_DOWNLOAD: - EINA_LIST_FOREACH(s_info.download_event, l, item) { - if (item->cb == cb && item->data == data) { - s_info.download_event = eina_list_remove(s_info.download_event, item); - cbdata = item->data; - DbgFree(item); - break; - } + EINA_LIST_FOREACH(s_info.download_event, l, item) { + if (item->cb == cb && item->data == data) { + s_info.download_event = eina_list_remove(s_info.download_event, item); + cbdata = item->data; + DbgFree(item); + break; } - break; + } + break; case PKGMGR_EVENT_UNINSTALL: - EINA_LIST_FOREACH(s_info.uninstall_event, l, item) { - if (item->cb == cb && item->data == data) { - s_info.uninstall_event = eina_list_remove(s_info.uninstall_event, item); - cbdata = item->data; - DbgFree(item); - break; - } + EINA_LIST_FOREACH(s_info.uninstall_event, l, item) { + if (item->cb == cb && item->data == data) { + s_info.uninstall_event = eina_list_remove(s_info.uninstall_event, item); + cbdata = item->data; + DbgFree(item); + break; } - break; + } + break; case PKGMGR_EVENT_INSTALL: - EINA_LIST_FOREACH(s_info.install_event, l, item) { - if (item->cb == cb && item->data == data) { - s_info.install_event = eina_list_remove(s_info.install_event, item); - cbdata = item->data; - DbgFree(item); - break; - } + EINA_LIST_FOREACH(s_info.install_event, l, item) { + if (item->cb == cb && item->data == data) { + s_info.install_event = eina_list_remove(s_info.install_event, item); + cbdata = item->data; + DbgFree(item); + break; } - break; + } + break; case PKGMGR_EVENT_UPDATE: - EINA_LIST_FOREACH(s_info.update_event, l, item) { - if (item->cb == cb && item->data == data) { - s_info.update_event = eina_list_remove(s_info.update_event, item); - cbdata = item->data; - DbgFree(item); - break; - } + EINA_LIST_FOREACH(s_info.update_event, l, item) { + if (item->cb == cb && item->data == data) { + s_info.update_event = eina_list_remove(s_info.update_event, item); + cbdata = item->data; + DbgFree(item); + break; } - break; + } + break; case PKGMGR_EVENT_RECOVER: - EINA_LIST_FOREACH(s_info.recover_event, l, item) { - if (item->cb == cb && item->data == data) { - s_info.recover_event = eina_list_remove(s_info.recover_event, item); - cbdata = item->data; - DbgFree(item); - break; - } + EINA_LIST_FOREACH(s_info.recover_event, l, item) { + if (item->cb == cb && item->data == data) { + s_info.recover_event = eina_list_remove(s_info.recover_event, item); + cbdata = item->data; + DbgFree(item); + break; } - break; + } + break; default: - ErrPrint("Invalid type\n"); - break; - } + ErrPrint("Invalid type\n"); + break; + } - return cbdata; + return cbdata; } /* End of a file */ diff --git a/src/script_handler.c b/src/script_handler.c index cf9494c..6543777 100644 --- a/src/script_handler.c +++ b/src/script_handler.c @@ -51,362 +51,362 @@ #define INFO_CATEGORY "category" static const char *type_list[] = { - "access", - "access,operation", - "color", - "drag", - "image", - "info", - "script", - "signal", - "text", - NULL + "access", + "access,operation", + "color", + "drag", + "image", + "info", + "script", + "signal", + "text", + NULL }; static const char *field_list[] = { - "type", - "part", - "data", - "option", - "id", - "target", - "file", - NULL + "type", + "part", + "data", + "option", + "id", + "target", + "file", + NULL }; int errno; static struct info { - Eina_List *script_port_list; - enum dynamicbox_fb_type env_buf_type; + Eina_List *script_port_list; + enum dynamicbox_fb_type env_buf_type; } s_info = { - .script_port_list = NULL, - .env_buf_type = DBOX_FB_TYPE_FILE, + .script_port_list = NULL, + .env_buf_type = DBOX_FB_TYPE_FILE, }; struct script_port { - void *handle; - - const char *(*magic_id)(void); - int (*update_color)(void *handle, const char *id, const char *part, const char *rgba); - int (*update_text)(void *handle, const char *id, const char *part, const char *text); - int (*update_image)(void *handle, const char *id, const char *part, const char *path, const char *option); - int (*update_access)(void *handle, const char *id, const char *part, const char *text, const char *option); - int (*operate_access)(void *handle, const char *id, const char *part, const char *operation, const char *option); - int (*update_script)(void *handle, const char *src_id, const char *target_id, const char *part, const char *path, const char *option); - int (*update_signal)(void *handle, const char *id, const char *part, const char *signal); - int (*update_drag)(void *handle, const char *id, const char *part, double x, double y); - int (*update_size)(void *handle, const char *id, int w, int h); - int (*update_category)(void *handle, const char *id, const char *category); - int (*feed_event)(void *handle, int event_type, int x, int y, int down, unsigned int keycode, double timestamp); - - void *(*create)(void *buffer_info, const char *file, const char *option); - int (*destroy)(void *handle); - - int (*load)(void *handle, int (*render_pre)(void *buffer_info, void *data), int (*render_post)(void *buffer_info, void *data), void *data); - int (*unload)(void *handle); - - int (*init)(double scale, int premultiplied); - int (*fini)(void); + void *handle; + + const char *(*magic_id)(void); + int (*update_color)(void *handle, const char *id, const char *part, const char *rgba); + int (*update_text)(void *handle, const char *id, const char *part, const char *text); + int (*update_image)(void *handle, const char *id, const char *part, const char *path, const char *option); + int (*update_access)(void *handle, const char *id, const char *part, const char *text, const char *option); + int (*operate_access)(void *handle, const char *id, const char *part, const char *operation, const char *option); + int (*update_script)(void *handle, const char *src_id, const char *target_id, const char *part, const char *path, const char *option); + int (*update_signal)(void *handle, const char *id, const char *part, const char *signal); + int (*update_drag)(void *handle, const char *id, const char *part, double x, double y); + int (*update_size)(void *handle, const char *id, int w, int h); + int (*update_category)(void *handle, const char *id, const char *category); + int (*feed_event)(void *handle, int event_type, int x, int y, int down, unsigned int keycode, double timestamp); + + void *(*create)(void *buffer_info, const char *file, const char *option); + int (*destroy)(void *handle); + + int (*load)(void *handle, int (*render_pre)(void *buffer_info, void *data), int (*render_post)(void *buffer_info, void *data), void *data); + int (*unload)(void *handle); + + int (*init)(double scale, int premultiplied); + int (*fini)(void); }; enum block_type { - TYPE_ACCESS, - TYPE_ACCESS_OP, - TYPE_COLOR, - TYPE_DRAG, - TYPE_IMAGE, - TYPE_INFO, - TYPE_SCRIPT, - TYPE_SIGNAL, - TYPE_TEXT, - TYPE_MAX + TYPE_ACCESS, + TYPE_ACCESS_OP, + TYPE_COLOR, + TYPE_DRAG, + TYPE_IMAGE, + TYPE_INFO, + TYPE_SCRIPT, + TYPE_SIGNAL, + TYPE_TEXT, + TYPE_MAX }; enum field_type { - FIELD_TYPE, - FIELD_PART, - FIELD_DATA, - FIELD_OPTION, - FIELD_ID, - FIELD_TARGET, - FIELD_FILE + FIELD_TYPE, + FIELD_PART, + FIELD_DATA, + FIELD_OPTION, + FIELD_ID, + FIELD_TARGET, + FIELD_FILE }; struct block { - enum block_type type; - char *part; - char *data; - char *option; - char *id; - char *target; - char *file; - - /* Should be released */ - char *filebuf; - const char *filename; + enum block_type type; + char *part; + char *data; + char *option; + char *id; + char *target; + char *file; + + /* Should be released */ + char *filebuf; + const char *filename; }; struct script_info { - struct buffer_info *buffer_handle; - int loaded; + struct buffer_info *buffer_handle; + int loaded; - int w; - int h; + int w; + int h; - int x; - int y; - int down; + int x; + int y; + int down; - unsigned int keycode; + unsigned int keycode; - struct script_port *port; - void *port_data; + struct script_port *port; + void *port_data; - Eina_List *cached_blocks; + Eina_List *cached_blocks; }; static inline void consuming_parsed_block(struct inst_info *inst, int is_pd, struct block *block); static int load_all_ports(void) { - struct script_port *item; - struct dirent *ent; - DIR *dir; - char *path; - int pathlen; - - dir = opendir(DYNAMICBOX_CONF_SCRIPT_PORT_PATH); - if (!dir) { - ErrPrint("Error: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; + struct script_port *item; + struct dirent *ent; + DIR *dir; + char *path; + int pathlen; + + dir = opendir(DYNAMICBOX_CONF_SCRIPT_PORT_PATH); + if (!dir) { + ErrPrint("Error: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + while ((ent = readdir(dir))) { + if (ent->d_name[0] == '.') { + continue; + } + + pathlen = strlen(ent->d_name) + strlen(DYNAMICBOX_CONF_SCRIPT_PORT_PATH) + 1; + path = malloc(pathlen); + if (!path) { + ErrPrint("Heap: %s %d\n", strerror(errno), pathlen); + if (closedir(dir) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; } - while ((ent = readdir(dir))) { - if (ent->d_name[0] == '.') { - continue; - } - - pathlen = strlen(ent->d_name) + strlen(DYNAMICBOX_CONF_SCRIPT_PORT_PATH) + 1; - path = malloc(pathlen); - if (!path) { - ErrPrint("Heap: %s %d\n", strerror(errno), pathlen); - if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - snprintf(path, pathlen, "%s%s", DYNAMICBOX_CONF_SCRIPT_PORT_PATH, ent->d_name); - - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(path); - if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - DbgPrint("Open SCRIPT PORT: %s\n", path); - item->handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW | RTLD_DEEPBIND); - DbgFree(path); - if (!item->handle) { - ErrPrint("Error: %s\n", dlerror()); - DbgFree(item); - if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_FAULT; - } + snprintf(path, pathlen, "%s%s", DYNAMICBOX_CONF_SCRIPT_PORT_PATH, ent->d_name); - item->magic_id = dlsym(item->handle, "script_magic_id"); - if (!item->magic_id) { - goto errout; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(path); + if (closedir(dir) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - DbgPrint("SCRIPT PORT magic id: %s\n", item->magic_id()); + DbgPrint("Open SCRIPT PORT: %s\n", path); + item->handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW | RTLD_DEEPBIND); + DbgFree(path); + if (!item->handle) { + ErrPrint("Error: %s\n", dlerror()); + DbgFree(item); + if (closedir(dir) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_FAULT; + } - item->update_color = dlsym(item->handle, "script_update_color"); - if (!item->update_color) { - goto errout; - } + item->magic_id = dlsym(item->handle, "script_magic_id"); + if (!item->magic_id) { + goto errout; + } - item->update_text = dlsym(item->handle, "script_update_text"); - if (!item->update_text) { - goto errout; - } + DbgPrint("SCRIPT PORT magic id: %s\n", item->magic_id()); - item->update_image = dlsym(item->handle, "script_update_image"); - if (!item->update_image) { - goto errout; - } + item->update_color = dlsym(item->handle, "script_update_color"); + if (!item->update_color) { + goto errout; + } - item->update_access = dlsym(item->handle, "script_update_access"); - if (!item->update_access) { - goto errout; - } + item->update_text = dlsym(item->handle, "script_update_text"); + if (!item->update_text) { + goto errout; + } - item->operate_access = dlsym(item->handle, "script_operate_access"); - if (!item->operate_access) { - goto errout; - } + item->update_image = dlsym(item->handle, "script_update_image"); + if (!item->update_image) { + goto errout; + } - item->update_script = dlsym(item->handle, "script_update_script"); - if (!item->update_script) { - goto errout; - } + item->update_access = dlsym(item->handle, "script_update_access"); + if (!item->update_access) { + goto errout; + } - item->update_signal = dlsym(item->handle, "script_update_signal"); - if (!item->update_signal) { - goto errout; - } + item->operate_access = dlsym(item->handle, "script_operate_access"); + if (!item->operate_access) { + goto errout; + } - item->update_drag = dlsym(item->handle, "script_update_drag"); - if (!item->update_drag) { - goto errout; - } + item->update_script = dlsym(item->handle, "script_update_script"); + if (!item->update_script) { + goto errout; + } - item->update_size = dlsym(item->handle, "script_update_size"); - if (!item->update_size) { - goto errout; - } + item->update_signal = dlsym(item->handle, "script_update_signal"); + if (!item->update_signal) { + goto errout; + } - item->update_category = dlsym(item->handle, "script_update_category"); - if (!item->update_category) { - goto errout; - } + item->update_drag = dlsym(item->handle, "script_update_drag"); + if (!item->update_drag) { + goto errout; + } - item->create = dlsym(item->handle, "script_create"); - if (!item->create) { - goto errout; - } + item->update_size = dlsym(item->handle, "script_update_size"); + if (!item->update_size) { + goto errout; + } - item->destroy = dlsym(item->handle, "script_destroy"); - if (!item->destroy) { - goto errout; - } + item->update_category = dlsym(item->handle, "script_update_category"); + if (!item->update_category) { + goto errout; + } - item->load = dlsym(item->handle, "script_load"); - if (!item->load) { - goto errout; - } + item->create = dlsym(item->handle, "script_create"); + if (!item->create) { + goto errout; + } - item->unload = dlsym(item->handle, "script_unload"); - if (!item->unload) { - goto errout; - } + item->destroy = dlsym(item->handle, "script_destroy"); + if (!item->destroy) { + goto errout; + } - item->init = dlsym(item->handle, "script_init"); - if (!item->init) { - goto errout; - } + item->load = dlsym(item->handle, "script_load"); + if (!item->load) { + goto errout; + } - item->fini = dlsym(item->handle, "script_fini"); - if (!item->fini) { - goto errout; - } + item->unload = dlsym(item->handle, "script_unload"); + if (!item->unload) { + goto errout; + } - item->feed_event = dlsym(item->handle, "script_feed_event"); - if (!item->feed_event) { - goto errout; - } + item->init = dlsym(item->handle, "script_init"); + if (!item->init) { + goto errout; + } - if (item->init(DYNAMICBOX_CONF_SCALE_WIDTH_FACTOR, DYNAMICBOX_CONF_PREMULTIPLIED_COLOR) < 0) { - ErrPrint("Failed to initialize script engine\n"); - goto errout; - } + item->fini = dlsym(item->handle, "script_fini"); + if (!item->fini) { + goto errout; + } - s_info.script_port_list = eina_list_append(s_info.script_port_list, item); + item->feed_event = dlsym(item->handle, "script_feed_event"); + if (!item->feed_event) { + goto errout; } - if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); + if (item->init(DYNAMICBOX_CONF_SCALE_WIDTH_FACTOR, DYNAMICBOX_CONF_PREMULTIPLIED_COLOR) < 0) { + ErrPrint("Failed to initialize script engine\n"); + goto errout; } - return DBOX_STATUS_ERROR_NONE; + s_info.script_port_list = eina_list_append(s_info.script_port_list, item); + } + + if (closedir(dir) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + + return DBOX_STATUS_ERROR_NONE; errout: - ErrPrint("Error: %s\n", dlerror()); - if (dlclose(item->handle) != 0) { - ErrPrint("dlclose: %s\n", strerror(errno)); - } - DbgFree(item); - if (closedir(dir) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_FAULT; + ErrPrint("Error: %s\n", dlerror()); + if (dlclose(item->handle) != 0) { + ErrPrint("dlclose: %s\n", strerror(errno)); + } + DbgFree(item); + if (closedir(dir) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_FAULT; } static inline struct script_port *find_port(const char *magic_id) { - Eina_List *l; - struct script_port *item; + Eina_List *l; + struct script_port *item; - if (!s_info.script_port_list) { - int ret; + if (!s_info.script_port_list) { + int ret; - ret = load_all_ports(); - if (ret < 0) { - ErrPrint("load_all_ports: %d\n", ret); - } + ret = load_all_ports(); + if (ret < 0) { + ErrPrint("load_all_ports: %d\n", ret); } + } - EINA_LIST_FOREACH(s_info.script_port_list, l, item) { - if (!strcmp(item->magic_id(), magic_id)) { - return item; - } + EINA_LIST_FOREACH(s_info.script_port_list, l, item) { + if (!strcmp(item->magic_id(), magic_id)) { + return item; } + } - return NULL; + return NULL; } static inline void delete_block(struct block *block) { - DbgFree(block->filebuf); - DbgFree(block); + DbgFree(block->filebuf); + DbgFree(block); } static int render_post_cb(void *_buffer_handle, void *data) { - PERF_INIT(); - PERF_BEGIN(); - struct inst_info *inst; - struct buffer_info *buffer_handle = _buffer_handle; - struct script_info *info; - - inst = buffer_handler_instance(buffer_handle); - if (!inst) { - goto out; - } - - if (instance_state(inst) != INST_ACTIVATED) { - ErrPrint("Render post invoked but instance is not activated\n"); - PERF_MARK(__func__); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = instance_dbox_script(inst); - if (info && info == data) { - buffer_handler_flush(buffer_handle); - instance_dbox_updated_by_instance(inst, NULL, info->x, info->y, info->w, info->h); - PERF_MARK("lb,update"); - return DBOX_STATUS_ERROR_NONE; - } + PERF_INIT(); + PERF_BEGIN(); + struct inst_info *inst; + struct buffer_info *buffer_handle = _buffer_handle; + struct script_info *info; + + inst = buffer_handler_instance(buffer_handle); + if (!inst) { + goto out; + } + + if (instance_state(inst) != INST_ACTIVATED) { + ErrPrint("Render post invoked but instance is not activated\n"); + PERF_MARK(__func__); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + info = instance_dbox_script(inst); + if (info && info == data) { + buffer_handler_flush(buffer_handle); + instance_dbox_updated_by_instance(inst, NULL, info->x, info->y, info->w, info->h); + PERF_MARK("lb,update"); + return DBOX_STATUS_ERROR_NONE; + } - info = instance_gbar_script(inst); - if (info && info == data) { - buffer_handler_flush(buffer_handle); - instance_gbar_updated_by_instance(inst, NULL, info->x, info->y, info->w, info->h); - PERF_MARK("pd,update"); - return DBOX_STATUS_ERROR_NONE; - } + info = instance_gbar_script(inst); + if (info && info == data) { + buffer_handler_flush(buffer_handle); + instance_gbar_updated_by_instance(inst, NULL, info->x, info->y, info->w, info->h); + PERF_MARK("pd,update"); + return DBOX_STATUS_ERROR_NONE; + } out: - ErrPrint("Failed to sync\n"); - PERF_MARK(__func__); - return DBOX_STATUS_ERROR_FAULT; + ErrPrint("Failed to sync\n"); + PERF_MARK(__func__); + return DBOX_STATUS_ERROR_FAULT; } /*! @@ -415,1098 +415,1098 @@ out: */ EAPI int script_signal_emit(void *buffer_handle, const char *part, const char *signal, double sx, double sy, double ex, double ey) { - struct script_info *info; - struct inst_info *inst; - int w; - int h; - double fx; - double fy; - - if (!buffer_handle) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = buffer_handler_data(buffer_handle); - if (!info) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - inst = buffer_handler_instance(buffer_handle); - if (!inst) { - return DBOX_STATUS_ERROR_FAULT; - } + struct script_info *info; + struct inst_info *inst; + int w; + int h; + double fx; + double fy; + + if (!buffer_handle) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + info = buffer_handler_data(buffer_handle); + if (!info) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + inst = buffer_handler_instance(buffer_handle); + if (!inst) { + return DBOX_STATUS_ERROR_FAULT; + } - if (!signal || strlen(signal) == 0) { - signal = ""; - } + if (!signal || strlen(signal) == 0) { + signal = ""; + } - if (!part || strlen(part) == 0) { - part = ""; - } + if (!part || strlen(part) == 0) { + part = ""; + } - buffer_handler_get_size(buffer_handle, &w, &h); + buffer_handler_get_size(buffer_handle, &w, &h); - fx = (double)info->x / (double)w; - fy = (double)info->y / (double)h; + fx = (double)info->x / (double)w; + fy = (double)info->y / (double)h; - return instance_signal_emit(inst, signal, part, sx, sy, ex, ey, fx, fy, info->down); + return instance_signal_emit(inst, signal, part, sx, sy, ex, ey, fx, fy, info->down); } static inline void flushing_cached_block(struct script_info *info) { - struct block *block; - struct inst_info *inst; - int is_pd; - - inst = buffer_handler_instance(info->buffer_handle); - if (!inst) { - ErrPrint("Instance is not valid\n"); - EINA_LIST_FREE(info->cached_blocks, block) { - delete_block(block); - } - return; - } - - is_pd = instance_gbar_script(inst) == info; + struct block *block; + struct inst_info *inst; + int is_pd; + inst = buffer_handler_instance(info->buffer_handle); + if (!inst) { + ErrPrint("Instance is not valid\n"); EINA_LIST_FREE(info->cached_blocks, block) { - consuming_parsed_block(inst, is_pd, block); + delete_block(block); } + return; + } + + is_pd = instance_gbar_script(inst) == info; + + EINA_LIST_FREE(info->cached_blocks, block) { + consuming_parsed_block(inst, is_pd, block); + } } HAPI int script_handler_load(struct script_info *info, int is_pd) { - struct inst_info *inst; - - if (!info || !info->port) { - ErrPrint("Script handler is not created\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (info->loaded > 0) { - info->loaded++; - return DBOX_STATUS_ERROR_NONE; - } - - if (info->port->load(info->port_data, NULL, render_post_cb, info) < 0) { - ErrPrint("Unable to load the script\n"); - return DBOX_STATUS_ERROR_FAULT; - } + struct inst_info *inst; - info->loaded = 1; - flushing_cached_block(info); + if (!info || !info->port) { + ErrPrint("Script handler is not created\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - inst = buffer_handler_instance(info->buffer_handle); - if (inst) { - script_signal_emit(info->buffer_handle, instance_id(inst), - is_pd ? "gbar,show" : "dbox,show", 0.0f, 0.0f, 0.0f, 0.0f); - } - buffer_handler_flush(info->buffer_handle); + if (info->loaded > 0) { + info->loaded++; return DBOX_STATUS_ERROR_NONE; + } + + if (info->port->load(info->port_data, NULL, render_post_cb, info) < 0) { + ErrPrint("Unable to load the script\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + info->loaded = 1; + flushing_cached_block(info); + + inst = buffer_handler_instance(info->buffer_handle); + if (inst) { + script_signal_emit(info->buffer_handle, instance_id(inst), + is_pd ? "gbar,show" : "dbox,show", 0.0f, 0.0f, 0.0f, 0.0f); + } + buffer_handler_flush(info->buffer_handle); + return DBOX_STATUS_ERROR_NONE; } HAPI int script_handler_unload(struct script_info *info, int is_pd) { - struct inst_info *inst; + struct inst_info *inst; - if (!info || !info->port) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info || !info->port) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - info->loaded--; - if (info->loaded > 0) { - return DBOX_STATUS_ERROR_BUSY; - } + info->loaded--; + if (info->loaded > 0) { + return DBOX_STATUS_ERROR_BUSY; + } - if (info->loaded < 0) { - info->loaded = 0; - return DBOX_STATUS_ERROR_ALREADY; - } + if (info->loaded < 0) { + info->loaded = 0; + return DBOX_STATUS_ERROR_ALREADY; + } - inst = buffer_handler_instance(info->buffer_handle); - if (inst) { - script_signal_emit(info->buffer_handle, instance_id(inst), - is_pd ? "gbar,hide" : "dbox,hide", 0.0f, 0.0f, 0.0f, 0.0f); - } + inst = buffer_handler_instance(info->buffer_handle); + if (inst) { + script_signal_emit(info->buffer_handle, instance_id(inst), + is_pd ? "gbar,hide" : "dbox,hide", 0.0f, 0.0f, 0.0f, 0.0f); + } - if (info->port->unload(info->port_data) < 0) { - ErrPrint("Failed to unload script object. but go ahead\n"); - } + if (info->port->unload(info->port_data) < 0) { + ErrPrint("Failed to unload script object. but go ahead\n"); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI struct script_info *script_handler_create(struct inst_info *inst, const char *file, const char *option, int w, int h) { - struct script_info *info; + struct script_info *info; - DbgPrint("Create script: %s (%s) %dx%d\n", file, option, w, h); + DbgPrint("Create script: %s (%s) %dx%d\n", file, option, w, h); - if (!file) { - return NULL; - } + if (!file) { + return NULL; + } - info = calloc(1, sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + info = calloc(1, sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - info->buffer_handle = buffer_handler_create(inst, s_info.env_buf_type, w, h, DYNAMICBOX_CONF_DEFAULT_PIXELS); - if (!info->buffer_handle) { - /* buffer_handler_create will prints some log */ - DbgFree(info); - return NULL; - } + info->buffer_handle = buffer_handler_create(inst, s_info.env_buf_type, w, h, DYNAMICBOX_CONF_DEFAULT_PIXELS); + if (!info->buffer_handle) { + /* buffer_handler_create will prints some log */ + DbgFree(info); + return NULL; + } - (void)buffer_handler_set_data(info->buffer_handle, info); + (void)buffer_handler_set_data(info->buffer_handle, info); - info->port = find_port(package_script(instance_package(inst))); - if (!info->port) { - ErrPrint("Failed to find a proper port for [%s]%s\n", - instance_package(inst), package_script(instance_package(inst))); - buffer_handler_destroy(info->buffer_handle); - DbgFree(info); - return NULL; - } + info->port = find_port(package_script(instance_package(inst))); + if (!info->port) { + ErrPrint("Failed to find a proper port for [%s]%s\n", + instance_package(inst), package_script(instance_package(inst))); + buffer_handler_destroy(info->buffer_handle); + DbgFree(info); + return NULL; + } - info->port_data = info->port->create(info->buffer_handle, file, option); - if (!info->port_data) { - ErrPrint("Failed to create a port (%s - %s)\n", file, option); - buffer_handler_destroy(info->buffer_handle); - DbgFree(info); - return NULL; - } + info->port_data = info->port->create(info->buffer_handle, file, option); + if (!info->port_data) { + ErrPrint("Failed to create a port (%s - %s)\n", file, option); + buffer_handler_destroy(info->buffer_handle); + DbgFree(info); + return NULL; + } - return info; + return info; } HAPI int script_handler_destroy(struct script_info *info) { - struct block *block; - int ret; + struct block *block; + int ret; - if (!info || !info->port) { - ErrPrint("port is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info || !info->port) { + ErrPrint("port is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->loaded != 0) { - ErrPrint("Script handler is not unloaded\n"); - return DBOX_STATUS_ERROR_BUSY; - } + if (info->loaded != 0) { + ErrPrint("Script handler is not unloaded\n"); + return DBOX_STATUS_ERROR_BUSY; + } - ret = info->port->destroy(info->port_data); - if (ret < 0) { - ErrPrint("Failed to destroy port, but go ahead: %d\n", ret); - } + ret = info->port->destroy(info->port_data); + if (ret < 0) { + ErrPrint("Failed to destroy port, but go ahead: %d\n", ret); + } - (void)buffer_handler_destroy(info->buffer_handle); + (void)buffer_handler_destroy(info->buffer_handle); - EINA_LIST_FREE(info->cached_blocks, block) { - delete_block(block); - } + EINA_LIST_FREE(info->cached_blocks, block) { + delete_block(block); + } - DbgFree(info); - return DBOX_STATUS_ERROR_NONE; + DbgFree(info); + return DBOX_STATUS_ERROR_NONE; } HAPI int script_handler_is_loaded(struct script_info *info) { - return info ? info->loaded > 0 : 0; + return info ? info->loaded > 0 : 0; } HAPI struct buffer_info *script_handler_buffer_info(struct script_info *info) { - if (!info) { - return NULL; - } + if (!info) { + return NULL; + } - return info->buffer_handle; + return info->buffer_handle; } static int update_script_color(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - if (!block || !block->part || !block->data) { - ErrPrint("Block or part or data is not valid\n"); - PERF_MARK("color"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("color"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part || !block->data) { + ErrPrint("Block or part or data is not valid\n"); + PERF_MARK("color"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("color"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("color"); + return DBOX_STATUS_ERROR_FAULT; + } - ret = info->port->update_color(info->port_data, block->id, block->part, block->data); + if (!info->port) { + ErrPrint("info->port is NIL (%d, %s)\n", is_pd, instance_id(inst)); PERF_MARK("color"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ret = info->port->update_color(info->port_data, block->id, block->part, block->data); + PERF_MARK("color"); + return ret; } static int update_script_text(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; - - if (!block || !block->part || !block->data) { - ErrPrint("Block or part or data is not valid\n"); - PERF_MARK("text"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("text"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part || !block->data) { + ErrPrint("Block or part or data is not valid\n"); + PERF_MARK("text"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("text"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("text"); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("[%s] %s (%s)\n", block->id, block->part, block->data); - ret = info->port->update_text(info->port_data, block->id, block->part, block->data); - + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("text"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + DbgPrint("[%s] %s (%s)\n", block->id, block->part, block->data); + ret = info->port->update_text(info->port_data, block->id, block->part, block->data); + + PERF_MARK("text"); + return ret; } static int update_script_image(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; - - if (!block || !block->part) { - ErrPrint("Block or part is not valid\n"); - PERF_MARK("image"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("image"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part) { + ErrPrint("Block or part is not valid\n"); + PERF_MARK("image"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("image"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("image"); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("[%s] %s (%s)\n", block->id, block->part, block->data); - ret = info->port->update_image(info->port_data, block->id, block->part, block->data, block->option); + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("image"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + DbgPrint("[%s] %s (%s)\n", block->id, block->part, block->data); + ret = info->port->update_image(info->port_data, block->id, block->part, block->data, block->option); + PERF_MARK("image"); + return ret; } static int update_access(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - if (!block || !block->part) { - ErrPrint("Block or block->part is NIL\n"); - PERF_MARK("access"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("access"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part) { + ErrPrint("Block or block->part is NIL\n"); + PERF_MARK("access"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("access"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("access"); + return DBOX_STATUS_ERROR_FAULT; + } - ret = info->port->update_access(info->port_data, block->id, block->part, block->data, block->option); + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("access"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ret = info->port->update_access(info->port_data, block->id, block->part, block->data, block->option); + PERF_MARK("access"); + return ret; } static int operate_access(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; - - if (!block || !block->part) { - ErrPrint("Block or block->part is NIL\n"); - PERF_MARK("operate_access"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("operate_access"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part) { + ErrPrint("Block or block->part is NIL\n"); + PERF_MARK("operate_access"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("operate_access"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("operate_access"); + return DBOX_STATUS_ERROR_FAULT; + } - ret = info->port->operate_access(info->port_data, block->id, block->part, block->data, block->option); + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("operate_access"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ret = info->port->operate_access(info->port_data, block->id, block->part, block->data, block->option); + PERF_MARK("operate_access"); + return ret; } static int update_script_script(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - if (!block || !block->part) { - ErrPrint("Block or part is NIL\n"); - PERF_MARK("script"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("script"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part) { + ErrPrint("Block or part is NIL\n"); + PERF_MARK("script"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("script"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("script"); + return DBOX_STATUS_ERROR_FAULT; + } - ret = info->port->update_script(info->port_data, block->id, block->target, block->part, block->data, block->option); + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("script"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ret = info->port->update_script(info->port_data, block->id, block->target, block->part, block->data, block->option); + PERF_MARK("script"); + return ret; } static int update_script_signal(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - int ret; + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + int ret; - if (!block) { - ErrPrint("block is NIL\n"); - PERF_MARK("signal"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("signal"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block) { + ErrPrint("block is NIL\n"); + PERF_MARK("signal"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("signal"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("signal"); + return DBOX_STATUS_ERROR_FAULT; + } - ret = info->port->update_signal(info->port_data, block->id, block->part, block->data); + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("signal"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ret = info->port->update_signal(info->port_data, block->id, block->part, block->data); + PERF_MARK("signal"); + return ret; } static int update_script_drag(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - double dx, dy; - int ret; - - if (!block || !block->data || !block->part) { - ErrPrint("block or block->data or block->part is NIL\n"); - PERF_MARK("drag"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("drag"); - return DBOX_STATUS_ERROR_FAULT; - } + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; + double dx, dy; + int ret; + + if (!block || !block->data || !block->part) { + ErrPrint("block or block->data or block->part is NIL\n"); + PERF_MARK("drag"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) { - ErrPrint("Invalid format of data (DRAG data [%s])\n", block->data); - PERF_MARK("drag"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("drag"); + return DBOX_STATUS_ERROR_FAULT; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("drag"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) { + ErrPrint("Invalid format of data (DRAG data [%s])\n", block->data); + PERF_MARK("drag"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ret = info->port->update_drag(info->port_data, block->id, block->part, dx, dy); + if (!info->port) { + ErrPrint("info->port is NIL\n"); PERF_MARK("drag"); - return ret; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ret = info->port->update_drag(info->port_data, block->id, block->part, dx, dy); + PERF_MARK("drag"); + return ret; } static void update_size_for_script(struct script_info *info, struct inst_info *inst, int w, int h) { - /*! - * \note - * After update the buffer size, - * If it required to be unload and load. - * New size of buffer will be allocated - */ - buffer_handler_update_size(info->buffer_handle, w, h); - - if (info->port->update_size) { - (void)info->port->update_size(info->port_data, NULL, w, h); - } - - if (instance_dbox_script(inst) == info) { - instance_set_dbox_size(inst, w, h); - } else if (instance_gbar_script(inst) == info) { - instance_set_gbar_size(inst, w, h); - } else { - ErrPrint("Unknown script\n"); - } + /*! + * \note + * After update the buffer size, + * If it required to be unload and load. + * New size of buffer will be allocated + */ + buffer_handler_update_size(info->buffer_handle, w, h); + + if (info->port->update_size) { + (void)info->port->update_size(info->port_data, NULL, w, h); + } + + if (instance_dbox_script(inst) == info) { + instance_set_dbox_size(inst, w, h); + } else if (instance_gbar_script(inst) == info) { + instance_set_gbar_size(inst, w, h); + } else { + ErrPrint("Unknown script\n"); + } } HAPI int script_handler_resize(struct script_info *info, int w, int h) { - PERF_INIT(); - PERF_BEGIN(); - struct inst_info *inst; - - if (!info) { - ErrPrint("info[%p] resize is ignored\n", info); - PERF_MARK("resize"); - return DBOX_STATUS_ERROR_NONE; - } - - inst = buffer_handler_instance(info->buffer_handle); - if (!inst) { - ErrPrint("Instance is not valid\n"); - PERF_MARK("resize"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - update_size_for_script(info, inst, w, h); + PERF_INIT(); + PERF_BEGIN(); + struct inst_info *inst; + if (!info) { + ErrPrint("info[%p] resize is ignored\n", info); PERF_MARK("resize"); return DBOX_STATUS_ERROR_NONE; + } + + inst = buffer_handler_instance(info->buffer_handle); + if (!inst) { + ErrPrint("Instance is not valid\n"); + PERF_MARK("resize"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + update_size_for_script(info, inst, w, h); + + PERF_MARK("resize"); + return DBOX_STATUS_ERROR_NONE; } HAPI const char *script_handler_buffer_id(struct script_info *info) { - if (!info || !info->buffer_handle) { - ErrPrint("Invalid info\n"); - return ""; - } + if (!info || !info->buffer_handle) { + ErrPrint("Invalid info\n"); + return ""; + } - return buffer_handler_id(info->buffer_handle); + return buffer_handler_id(info->buffer_handle); } static int update_info(struct inst_info *inst, struct block *block, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - struct script_info *info; - - if (!block || !block->part || !block->data) { - ErrPrint("block or block->part or block->data is NIL\n"); - PERF_MARK("info"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + PERF_INIT(); + PERF_BEGIN(); + struct script_info *info; - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - PERF_MARK("info"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!block || !block->part || !block->data) { + ErrPrint("block or block->part or block->data is NIL\n"); + PERF_MARK("info"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!info->port) { - ErrPrint("info->port is NIL\n"); - PERF_MARK("info"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + PERF_MARK("info"); + return DBOX_STATUS_ERROR_FAULT; + } - if (!strcasecmp(block->part, INFO_SIZE)) { - int w, h; + if (!info->port) { + ErrPrint("info->port is NIL\n"); + PERF_MARK("info"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (sscanf(block->data, "%dx%d", &w, &h) != 2) { - ErrPrint("Invalid format for SIZE(%s)\n", block->data); - PERF_MARK("info"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!strcasecmp(block->part, INFO_SIZE)) { + int w, h; - if (!block->id) { - update_size_for_script(info, inst, w, h); - } else { - (void)info->port->update_size(info->port_data, block->id, w, h); - } - } else if (!strcasecmp(block->part, INFO_CATEGORY)) { - (void)info->port->update_category(info->port_data, block->id, block->data); + if (sscanf(block->data, "%dx%d", &w, &h) != 2) { + ErrPrint("Invalid format for SIZE(%s)\n", block->data); + PERF_MARK("info"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } - PERF_MARK("info"); - return DBOX_STATUS_ERROR_NONE; + if (!block->id) { + update_size_for_script(info, inst, w, h); + } else { + (void)info->port->update_size(info->port_data, block->id, w, h); + } + } else if (!strcasecmp(block->part, INFO_CATEGORY)) { + (void)info->port->update_category(info->port_data, block->id, block->data); + } + PERF_MARK("info"); + + return DBOX_STATUS_ERROR_NONE; } static inline void consuming_parsed_block(struct inst_info *inst, int is_pd, struct block *block) { - struct script_info *info; - typedef int (*update_function_t)(struct inst_info *inst, struct block *block, int is_pd); - update_function_t updators[] = { - update_access, - operate_access, - update_script_color, - update_script_drag, - update_script_image, - update_info, - update_script_script, - update_script_signal, - update_script_text, - NULL - }; - - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (!info) { - ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); - goto free_out; - } + struct script_info *info; + typedef int (*update_function_t)(struct inst_info *inst, struct block *block, int is_pd); + update_function_t updators[] = { + update_access, + operate_access, + update_script_color, + update_script_drag, + update_script_image, + update_info, + update_script_script, + update_script_signal, + update_script_text, + NULL + }; - if (script_handler_is_loaded(info)) { - if (block->type >= 0 || block->type < TYPE_MAX) { - (void)updators[block->type](inst, block, is_pd); - } else { - ErrPrint("Block type[%d] is not valid\n", block->type); - } + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (!info) { + ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst)); + goto free_out; + } + + if (script_handler_is_loaded(info)) { + if (block->type >= 0 || block->type < TYPE_MAX) { + (void)updators[block->type](inst, block, is_pd); } else { - info->cached_blocks = eina_list_append(info->cached_blocks, block); - DbgPrint("Block is cached (%p), %d, %s\n", block, eina_list_count(info->cached_blocks), instance_id(inst)); - return; + ErrPrint("Block type[%d] is not valid\n", block->type); } + } else { + info->cached_blocks = eina_list_append(info->cached_blocks, block); + DbgPrint("Block is cached (%p), %d, %s\n", block, eina_list_count(info->cached_blocks), instance_id(inst)); + return; + } free_out: - delete_block(block); + delete_block(block); } HAPI int script_init(void) { - if (!strcasecmp(DYNAMICBOX_CONF_PROVIDER_METHOD, "shm")) { - s_info.env_buf_type = DBOX_FB_TYPE_SHM; - } else if (!strcasecmp(DYNAMICBOX_CONF_PROVIDER_METHOD, "pixmap")) { - s_info.env_buf_type = DBOX_FB_TYPE_PIXMAP; - } + if (!strcasecmp(DYNAMICBOX_CONF_PROVIDER_METHOD, "shm")) { + s_info.env_buf_type = DBOX_FB_TYPE_SHM; + } else if (!strcasecmp(DYNAMICBOX_CONF_PROVIDER_METHOD, "pixmap")) { + s_info.env_buf_type = DBOX_FB_TYPE_PIXMAP; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int script_fini(void) { - struct script_port *item; - /*! - * \TODO: Release all handles - */ - EINA_LIST_FREE(s_info.script_port_list, item) { - item->fini(); - if (dlclose(item->handle) != 0) { - ErrPrint("dlclose: %s\n", strerror(errno)); - } - DbgFree(item); + struct script_port *item; + /*! + * \TODO: Release all handles + */ + EINA_LIST_FREE(s_info.script_port_list, item) { + item->fini(); + if (dlclose(item->handle) != 0) { + ErrPrint("dlclose: %s\n", strerror(errno)); } + DbgFree(item); + } - return 0; + return 0; } HAPI int script_handler_update_pointer(struct script_info *info, int x, int y, int down) { - if (!info) { - return DBOX_STATUS_ERROR_NONE; - } + if (!info) { + return DBOX_STATUS_ERROR_NONE; + } - info->x = x; - info->y = y; + info->x = x; + info->y = y; - if (down == 0) { - info->down = 0; - } else if (down == 1) { - info->down = 1; - } + if (down == 0) { + info->down = 0; + } else if (down == 1) { + info->down = 1; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int script_handler_update_keycode(struct script_info *info, unsigned int keycode) { - if (!info) { - return DBOX_STATUS_ERROR_NONE; - } + if (!info) { + return DBOX_STATUS_ERROR_NONE; + } - info->keycode = keycode; + info->keycode = keycode; - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int script_handler_feed_event(struct script_info *info, int event, double timestamp) { - int ret; + int ret; - if (!info->port) { - ErrPrint("info->port is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info->port) { + ErrPrint("info->port is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ret = info->port->feed_event(info->port_data, event, info->x, info->y, info->down, info->keycode, timestamp); - return ret; + ret = info->port->feed_event(info->port_data, event, info->x, info->y, info->down, info->keycode, timestamp); + return ret; } static inline char *load_file(const char *filename) { - char *filebuf = NULL; - int fd; - off_t filesize; - int ret; - size_t readsize = 0; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - return NULL; - } - - filesize = lseek(fd, 0L, SEEK_END); - if (filesize == (off_t)-1) { - ErrPrint("lseek: %s\n", strerror(errno)); - goto errout; - } + char *filebuf = NULL; + int fd; + off_t filesize; + int ret; + size_t readsize = 0; + + fd = open(filename, O_RDONLY); + if (fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + return NULL; + } + + filesize = lseek(fd, 0L, SEEK_END); + if (filesize == (off_t)-1) { + ErrPrint("lseek: %s\n", strerror(errno)); + goto errout; + } + + if (lseek(fd, 0L, SEEK_SET) < 0) { + ErrPrint("lseek: %s\n", strerror(errno)); + goto errout; + } + + filebuf = malloc(filesize + 1); + if (!filebuf) { + ErrPrint("malloc: %s\n", strerror(errno)); + goto errout; + } + + while (readsize < filesize) { + ret = read(fd, filebuf + readsize, (size_t)filesize - readsize); + if (ret < 0) { + if (errno == EINTR) { + DbgPrint("Read is interrupted\n"); + continue; + } - if (lseek(fd, 0L, SEEK_SET) < 0) { - ErrPrint("lseek: %s\n", strerror(errno)); - goto errout; + ErrPrint("read: %s\n", strerror(errno)); + free(filebuf); + filebuf = NULL; + break; } - filebuf = malloc(filesize + 1); - if (!filebuf) { - ErrPrint("malloc: %s\n", strerror(errno)); - goto errout; - } + readsize += ret; + } - while (readsize < filesize) { - ret = read(fd, filebuf + readsize, (size_t)filesize - readsize); - if (ret < 0) { - if (errno == EINTR) { - DbgPrint("Read is interrupted\n"); - continue; - } + if (filebuf) { + filebuf[readsize] = '\0'; + } - ErrPrint("read: %s\n", strerror(errno)); - free(filebuf); - filebuf = NULL; - break; - } - - readsize += ret; - } - - if (filebuf) { - filebuf[readsize] = '\0'; - } - - /*! - * \note - * Now, we are ready to parse the filebuf. - */ + /*! + * \note + * Now, we are ready to parse the filebuf. + */ errout: - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } - return filebuf; + return filebuf; } #if defined(_APPLY_SCRIPT_ASYNC_UPDATE) struct apply_data { - struct inst_info *inst; - Eina_List *block_list; - int is_pd; + struct inst_info *inst; + Eina_List *block_list; + int is_pd; }; static Eina_Bool apply_changes_cb(void *_data) { - struct apply_data *data = _data; - struct block *block; + struct apply_data *data = _data; + struct block *block; - block = eina_list_nth(data->block_list, 0); - data->block_list = eina_list_remove(data->block_list, block); - consuming_parsed_block(data->inst, data->is_pd, block); + block = eina_list_nth(data->block_list, 0); + data->block_list = eina_list_remove(data->block_list, block); + consuming_parsed_block(data->inst, data->is_pd, block); - if (!data->block_list) { - free(data); - return ECORE_CALLBACK_CANCEL; - } + if (!data->block_list) { + free(data); + return ECORE_CALLBACK_CANCEL; + } - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; } #endif HAPI int script_handler_parse_desc(struct inst_info *inst, const char *filename, int is_pd) { - PERF_INIT(); - PERF_BEGIN(); - int type_idx = 0; - int type_len = 0; - int field_idx = 0; - int field_len = 0; - char *filebuf; - char *fileptr; - char *ptr = NULL; - struct block *block = NULL; - Eina_List *block_list = NULL; - enum state { - BEGIN, - FIELD, - DATA, - END, - DONE, - ERROR, - } state; - - filebuf = load_file(filename); - if (!filebuf) { - return DBOX_STATUS_ERROR_IO_ERROR; - } - - fileptr = filebuf; - - state = BEGIN; - while (*fileptr && state != ERROR) { - switch (state) { - case BEGIN: - if (*fileptr == '{') { - block = calloc(1, sizeof(*block)); - if (!block) { - ErrPrint("calloc: %s\n", strerror(errno)); - state = ERROR; - continue; - } - state = FIELD; - ptr = NULL; + PERF_INIT(); + PERF_BEGIN(); + int type_idx = 0; + int type_len = 0; + int field_idx = 0; + int field_len = 0; + char *filebuf; + char *fileptr; + char *ptr = NULL; + struct block *block = NULL; + Eina_List *block_list = NULL; + enum state { + BEGIN, + FIELD, + DATA, + END, + DONE, + ERROR, + } state; + + filebuf = load_file(filename); + if (!filebuf) { + return DBOX_STATUS_ERROR_IO_ERROR; + } + + fileptr = filebuf; + + state = BEGIN; + while (*fileptr && state != ERROR) { + switch (state) { + case BEGIN: + if (*fileptr == '{') { + block = calloc(1, sizeof(*block)); + if (!block) { + ErrPrint("calloc: %s\n", strerror(errno)); + state = ERROR; + continue; + } + state = FIELD; + ptr = NULL; + } + break; + case FIELD: + if (isspace(*fileptr)) { + if (ptr != NULL) { + *fileptr = '\0'; + } + } else if (*fileptr == '=') { + *fileptr = '\0'; + ptr = NULL; + state = DATA; + } else if (ptr == NULL) { + ptr = fileptr; + field_idx = 0; + field_len = 0; + + while (field_list[field_idx]) { + if (field_list[field_idx][field_len] == *fileptr) { + break; } - break; - case FIELD: - if (isspace(*fileptr)) { - if (ptr != NULL) { - *fileptr = '\0'; - } - } else if (*fileptr == '=') { - *fileptr = '\0'; - ptr = NULL; - state = DATA; - } else if (ptr == NULL) { - ptr = fileptr; - field_idx = 0; - field_len = 0; - - while (field_list[field_idx]) { - if (field_list[field_idx][field_len] == *fileptr) { - break; - } - field_idx++; - } + field_idx++; + } - if (!field_list[field_idx]) { - ErrPrint("Invalid field\n"); - state = ERROR; - continue; - } + if (!field_list[field_idx]) { + ErrPrint("Invalid field\n"); + state = ERROR; + continue; + } - field_len++; - } else { - if (field_list[field_idx][field_len] != *fileptr) { - field_idx++; - while (field_list[field_idx]) { - if (!strncmp(field_list[field_idx], fileptr - field_len, field_len)) { - break; - } else { - field_idx++; - } - } - - if (!field_list[field_idx]) { - state = ERROR; - ErrPrint("field is not valid\n"); - continue; - } - } + field_len++; + } else { + if (field_list[field_idx][field_len] != *fileptr) { + field_idx++; + while (field_list[field_idx]) { + if (!strncmp(field_list[field_idx], fileptr - field_len, field_len)) { + break; + } else { + field_idx++; + } + } - field_len++; + if (!field_list[field_idx]) { + state = ERROR; + ErrPrint("field is not valid\n"); + continue; } - break; - case DATA: - switch (field_idx) { - case FIELD_TYPE: - if (ptr == NULL) { - if (isspace(*fileptr)) { - break; - } - - if (*fileptr == '\0') { - state = ERROR; - ErrPrint("Type is not valid\n"); - continue; - } - - ptr = fileptr; - type_idx = 0; - type_len = 0; - } + } - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } + field_len++; + } + break; + case DATA: + switch (field_idx) { + case FIELD_TYPE: + if (ptr == NULL) { + if (isspace(*fileptr)) { + break; + } - if (type_list[type_idx][type_len] != *fileptr) { - type_idx++; - while (type_list[type_idx]) { - if (!strncmp(type_list[type_idx], fileptr - type_len, type_len)) { - break; - } else { - type_idx++; - } - } - - if (!type_list[type_idx]) { - state = ERROR; - ErrPrint("type is not valid (%s)\n", fileptr - type_len); - continue; - } - } + if (*fileptr == '\0') { + state = ERROR; + ErrPrint("Type is not valid\n"); + continue; + } - if (!*fileptr) { - block->type = type_idx; - state = DONE; - ptr = NULL; - } + ptr = fileptr; + type_idx = 0; + type_len = 0; + } - type_len++; - break; - case FIELD_PART: - if (ptr == NULL) { - ptr = fileptr; - } + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; + if (type_list[type_idx][type_len] != *fileptr) { + type_idx++; + while (type_list[type_idx]) { + if (!strncmp(type_list[type_idx], fileptr - type_len, type_len)) { + break; + } else { + type_idx++; } + } - if (!*fileptr) { - block->part = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_DATA: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } + if (!type_list[type_idx]) { + state = ERROR; + ErrPrint("type is not valid (%s)\n", fileptr - type_len); + continue; + } + } - if (!*fileptr) { - block->data = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_OPTION: - if (ptr == NULL) { - ptr = fileptr; - } + if (!*fileptr) { + block->type = type_idx; + state = DONE; + ptr = NULL; + } - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } + type_len++; + break; + case FIELD_PART: + if (ptr == NULL) { + ptr = fileptr; + } - if (!*fileptr) { - block->option = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_ID: - if (ptr == NULL) { - ptr = fileptr; - } + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } + if (!*fileptr) { + block->part = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_DATA: + if (ptr == NULL) { + ptr = fileptr; + } - if (!*fileptr) { - block->id = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_TARGET: - if (ptr == NULL) { - ptr = fileptr; - } + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } + if (!*fileptr) { + block->data = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_OPTION: + if (ptr == NULL) { + ptr = fileptr; + } - if (!*fileptr) { - block->target = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_FILE: - if (ptr == NULL) { - ptr = fileptr; - } + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } + if (!*fileptr) { + block->option = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_ID: + if (ptr == NULL) { + ptr = fileptr; + } - if (!*fileptr) { - block->target = ptr; - state = DONE; - ptr = NULL; - } - default: - break; + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; } + if (!*fileptr) { + block->id = ptr; + state = DONE; + ptr = NULL; + } break; - case DONE: - if (isspace(*fileptr)) { - } else if (*fileptr == '}') { - state = BEGIN; - block->filename = filename; - block_list = eina_list_append(block_list, block); - block = NULL; - } else { - state = FIELD; - continue; + case FIELD_TARGET: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->target = ptr; + state = DONE; + ptr = NULL; } break; - case END: - default: + case FIELD_FILE: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->target = ptr; + state = DONE; + ptr = NULL; + } + default: break; } - fileptr++; + break; + case DONE: + if (isspace(*fileptr)) { + } else if (*fileptr == '}') { + state = BEGIN; + block->filename = filename; + block_list = eina_list_append(block_list, block); + block = NULL; + } else { + state = FIELD; + continue; + } + break; + case END: + default: + break; } - if (state != BEGIN) { - ErrPrint("State %d\n", state); - - free(filebuf); - free(block); + fileptr++; + } - EINA_LIST_FREE(block_list, block) { - free(block); - } + if (state != BEGIN) { + ErrPrint("State %d\n", state); - PERF_MARK("parser"); - return DBOX_STATUS_ERROR_FAULT; - } + free(filebuf); + free(block); - block = eina_list_data_get(eina_list_last(block_list)); - if (block) { - block->filebuf = filebuf; - } else { - ErrPrint("Last block is not exists (There is no parsed block)\n"); - free(filebuf); + EINA_LIST_FREE(block_list, block) { + free(block); } PERF_MARK("parser"); + return DBOX_STATUS_ERROR_FAULT; + } + + block = eina_list_data_get(eina_list_last(block_list)); + if (block) { + block->filebuf = filebuf; + } else { + ErrPrint("Last block is not exists (There is no parsed block)\n"); + free(filebuf); + } + + PERF_MARK("parser"); #if defined(_APPLY_SCRIPT_ASYNC_UPDATE) - struct apply_data *data; - - data = malloc(sizeof(*data)); - if (data) { - data->inst = inst; - data->is_pd = is_pd; - data->block_list = block_list; - if (!ecore_timer_add(0.001f, apply_changes_cb, data)) { - ErrPrint("Failed to add timer\n"); - free(data); - EINA_LIST_FREE(block_list, block) { - consuming_parsed_block(inst, is_pd, block); - } - } - } else { - ErrPrint("Heap: %s\n", strerror(errno)); - EINA_LIST_FREE(block_list, block) { - consuming_parsed_block(inst, is_pd, block); - } - } -#else - ErrPrint("Begin: Set content for EDJE object\n"); - EINA_LIST_FREE(block_list, block) { + struct apply_data *data; + + data = malloc(sizeof(*data)); + if (data) { + data->inst = inst; + data->is_pd = is_pd; + data->block_list = block_list; + if (!ecore_timer_add(0.001f, apply_changes_cb, data)) { + ErrPrint("Failed to add timer\n"); + free(data); + EINA_LIST_FREE(block_list, block) { consuming_parsed_block(inst, is_pd, block); + } } - ErrPrint("End: Set content for EDJE object\n"); - - /*! - * Doesn't need to force to render the contents. - struct script_info *info; - info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); - if (info && info->ee) { - ecore_evas_manual_render(info->ee); + } else { + ErrPrint("Heap: %s\n", strerror(errno)); + EINA_LIST_FREE(block_list, block) { + consuming_parsed_block(inst, is_pd, block); } - */ + } +#else + ErrPrint("Begin: Set content for EDJE object\n"); + EINA_LIST_FREE(block_list, block) { + consuming_parsed_block(inst, is_pd, block); + } + ErrPrint("End: Set content for EDJE object\n"); + + /*! + * Doesn't need to force to render the contents. + struct script_info *info; + info = is_pd ? instance_gbar_script(inst) : instance_dbox_script(inst); + if (info && info->ee) { + ecore_evas_manual_render(info->ee); + } + */ #endif - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/server.c b/src/server.c index 11166ab..9954caf 100644 --- a/src/server.c +++ b/src/server.c @@ -68,6877 +68,6929 @@ #define ACCESS_TYPE_OFF 3 static struct info { - int info_fd; - int client_fd; - int service_fd; - int slave_fd; - int remote_client_fd; + int info_fd; + int client_fd; + int service_fd; + int slave_fd; + int remote_client_fd; } s_info = { - .info_fd = -1, - .client_fd = -1, - .service_fd = -1, - .slave_fd = -1, - .remote_client_fd = -1, + .info_fd = -1, + .client_fd = -1, + .service_fd = -1, + .slave_fd = -1, + .remote_client_fd = -1, }; struct access_info { - int x; - int y; - int type; + int x; + int y; + int type; }; /* Share this with provider */ enum target_type { - TYPE_DBOX, - TYPE_GBAR, - TYPE_ERROR + TYPE_DBOX, + TYPE_GBAR, + TYPE_ERROR }; struct event_cbdata { - int status; - struct inst_info *inst; + int status; + struct inst_info *inst; }; struct deleted_item { - struct client_node *client; - struct inst_info *inst; + struct client_node *client; + struct inst_info *inst; }; static Eina_Bool lazy_key_status_cb(void *data) { - struct event_cbdata *cbdata = data; + struct event_cbdata *cbdata = data; - if (instance_unref(cbdata->inst)) { - instance_send_key_status(cbdata->inst, cbdata->status); - } else { - DbgPrint("Skip sending key status (%d)\n", cbdata->status); - } - /*! - * If instance_unref returns NULL, - * The instance is destroyed. it means, we don't need to send event to the viewer - */ - DbgFree(cbdata); - return ECORE_CALLBACK_CANCEL; + if (instance_unref(cbdata->inst)) { + instance_send_key_status(cbdata->inst, cbdata->status); + } else { + DbgPrint("Skip sending key status (%d)\n", cbdata->status); + } + /*! + * If instance_unref returns NULL, + * The instance is destroyed. it means, we don't need to send event to the viewer + */ + DbgFree(cbdata); + return ECORE_CALLBACK_CANCEL; } static Eina_Bool lazy_access_status_cb(void *data) { - struct event_cbdata *cbdata = data; + struct event_cbdata *cbdata = data; - if (instance_unref(cbdata->inst)) { - instance_send_access_status(cbdata->inst, cbdata->status); - } else { - DbgPrint("Skip sending access status (%d)\n", cbdata->status); - } - /*! - * If instance_unref returns NULL, - * The instance is destroyed. it means, we don't need to send event to the viewer - */ - DbgFree(cbdata); - return ECORE_CALLBACK_CANCEL; + if (instance_unref(cbdata->inst)) { + instance_send_access_status(cbdata->inst, cbdata->status); + } else { + DbgPrint("Skip sending access status (%d)\n", cbdata->status); + } + /*! + * If instance_unref returns NULL, + * The instance is destroyed. it means, we don't need to send event to the viewer + */ + DbgFree(cbdata); + return ECORE_CALLBACK_CANCEL; } int send_delayed_key_status(struct inst_info *inst, int ret) { - struct event_cbdata *cbdata; + struct event_cbdata *cbdata; - cbdata = malloc(sizeof(*cbdata)); - if (!cbdata) { - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } else { - cbdata->inst = instance_ref(inst); - cbdata->status = ret; + cbdata = malloc(sizeof(*cbdata)); + if (!cbdata) { + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } else { + cbdata->inst = instance_ref(inst); + cbdata->status = ret; - if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) { - (void)instance_unref(cbdata->inst); - DbgFree(cbdata); - ret = DBOX_STATUS_ERROR_FAULT; - } else { - ret = DBOX_STATUS_ERROR_NONE; - } + if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) { + (void)instance_unref(cbdata->inst); + DbgFree(cbdata); + ret = DBOX_STATUS_ERROR_FAULT; + } else { + ret = DBOX_STATUS_ERROR_NONE; } + } - return ret; + return ret; } int send_delayed_access_status(struct inst_info *inst, int ret) { - struct event_cbdata *cbdata; + struct event_cbdata *cbdata; - cbdata = malloc(sizeof(*cbdata)); - if (!cbdata) { - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } else { - cbdata->inst = instance_ref(inst); - cbdata->status = ret; + cbdata = malloc(sizeof(*cbdata)); + if (!cbdata) { + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } else { + cbdata->inst = instance_ref(inst); + cbdata->status = ret; - if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) { - (void)instance_unref(cbdata->inst); - DbgFree(cbdata); - ret = DBOX_STATUS_ERROR_FAULT; - } else { - ret = DBOX_STATUS_ERROR_NONE; - } + if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) { + (void)instance_unref(cbdata->inst); + DbgFree(cbdata); + ret = DBOX_STATUS_ERROR_FAULT; + } else { + ret = DBOX_STATUS_ERROR_NONE; } + } - return ret; + return ret; } static int forward_dbox_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet) { - struct buffer_info *buffer; - struct slave_node *slave; - int ret; + struct buffer_info *buffer; + struct slave_node *slave; + int ret; - buffer = instance_dbox_buffer(inst); - if (!buffer) { - ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + buffer = instance_dbox_buffer(inst); + if (!buffer) { + ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package[%s] has no slave\n", package_name(pkg)); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package[%s] has no slave\n", package_name(pkg)); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - packet_ref((struct packet *)packet); - ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0); + packet_ref((struct packet *)packet); + ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0); out: - return ret; + return ret; } static int forward_gbar_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet) { - struct buffer_info *buffer; - struct slave_node *slave; - int ret; + struct buffer_info *buffer; + struct slave_node *slave; + int ret; - buffer = instance_gbar_buffer(inst); - if (!buffer) { - ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + buffer = instance_gbar_buffer(inst); + if (!buffer) { + ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package[%s] has no slave\n", package_name(pkg)); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package[%s] has no slave\n", package_name(pkg)); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - packet_ref((struct packet *)packet); - ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0); + packet_ref((struct packet *)packet); + ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0); out: - return ret; + return ret; } static int forward_gbar_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, struct access_info *event) { - int ret; - struct buffer_info *buffer; - struct slave_node *slave; - struct packet *p; - - buffer = instance_gbar_buffer(inst); - if (!buffer) { - ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package[%s] has no slave\n", package_name(pkg)); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + int ret; + struct buffer_info *buffer; + struct slave_node *slave; + struct packet *p; + + buffer = instance_gbar_buffer(inst); + if (!buffer) { + ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package[%s] has no slave\n", package_name(pkg)); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type); - ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); + p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type); + ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); out: - return ret; + return ret; } static int forward_dbox_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, struct access_info *event) { - int ret; - struct buffer_info *buffer; - struct slave_node *slave; - struct packet *p; - - buffer = instance_dbox_buffer(inst); - if (!buffer) { - ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package[%s] has no slave\n", package_name(pkg)); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + int ret; + struct buffer_info *buffer; + struct slave_node *slave; + struct packet *p; + + buffer = instance_dbox_buffer(inst); + if (!buffer) { + ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package[%s] has no slave\n", package_name(pkg)); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type); - ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); + p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type); + ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); out: - return ret; + return ret; } static int forward_gbar_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode) { - int ret; - struct buffer_info *buffer; - struct slave_node *slave; - struct packet *p; - - buffer = instance_dbox_buffer(inst); - if (!buffer) { - ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package[%s] has no slave\n", package_name(pkg)); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + int ret; + struct buffer_info *buffer; + struct slave_node *slave; + struct packet *p; + + buffer = instance_dbox_buffer(inst); + if (!buffer) { + ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package[%s] has no slave\n", package_name(pkg)); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode); - ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); + p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode); + ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); out: - return ret; + return ret; } static int forward_dbox_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode) { - int ret; - struct buffer_info *buffer; - struct slave_node *slave; - struct packet *p; - - buffer = instance_dbox_buffer(inst); - if (!buffer) { - ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Package[%s] has no slave\n", package_name(pkg)); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + int ret; + struct buffer_info *buffer; + struct slave_node *slave; + struct packet *p; + + buffer = instance_dbox_buffer(inst); + if (!buffer) { + ErrPrint("Instance[%s] has no buffer\n", instance_id(inst)); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Package[%s] has no slave\n", package_name(pkg)); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode); - ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); + p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode); + ret = slave_rpc_request_only(slave, package_name(pkg), p, 0); out: - return ret; + return ret; } static int slave_fault_open_script_cb(struct slave_node *slave, void *data) { - Ecore_Timer *timer; + Ecore_Timer *timer; - (void)script_handler_unload(instance_gbar_script(data), 1); - (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT); - (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT); + (void)script_handler_unload(instance_gbar_script(data), 1); + (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT); + (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT); - timer = instance_del_data(data, LAZY_GBAR_OPEN_TAG); - if (timer) { - ecore_timer_del(timer); - } + timer = instance_del_data(data, LAZY_GBAR_OPEN_TAG); + if (timer) { + ecore_timer_del(timer); + } - (void)instance_unref(data); + (void)instance_unref(data); - return -1; /* remove this handler */ + return -1; /* remove this handler */ } static int slave_fault_open_buffer_cb(struct slave_node *slave, void *data) { - Ecore_Timer *timer; + Ecore_Timer *timer; - (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT); - (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT); + (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT); + (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT); - timer = instance_del_data(data, GBAR_OPEN_MONITOR_TAG); - if (timer) { - ecore_timer_del(timer); - } + timer = instance_del_data(data, GBAR_OPEN_MONITOR_TAG); + if (timer) { + ecore_timer_del(timer); + } - (void)instance_unref(data); + (void)instance_unref(data); - return -1; /* remove this handler */ + return -1; /* remove this handler */ } static int slave_fault_close_script_cb(struct slave_node *slave, void *data) { - Ecore_Timer *timer; + Ecore_Timer *timer; - (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT); + (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT); - timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG); - if (timer) { - ecore_timer_del(timer); - } + timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG); + if (timer) { + ecore_timer_del(timer); + } - (void)instance_unref(data); + (void)instance_unref(data); - return -1; /* remove this handler */ + return -1; /* remove this handler */ } static int slave_fault_close_buffer_cb(struct slave_node *slave, void *data) { - Ecore_Timer *timer; + Ecore_Timer *timer; - (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT); + (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT); - timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG); - if (!timer) { - timer = instance_del_data(data, GBAR_CLOSE_MONITOR_TAG); - } + timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG); + if (!timer) { + timer = instance_del_data(data, GBAR_CLOSE_MONITOR_TAG); + } - if (timer) { - ecore_timer_del(timer); - } + if (timer) { + ecore_timer_del(timer); + } - (void)instance_unref(data); + (void)instance_unref(data); - return -1; /* remove this handler */ + return -1; /* remove this handler */ } static int slave_fault_resize_buffer_cb(struct slave_node *slave, void *data) { - Ecore_Timer *timer; + Ecore_Timer *timer; - (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT); - (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT); + (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT); + (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT); - timer = instance_del_data(data, GBAR_RESIZE_MONITOR_TAG); - if (timer) { - ecore_timer_del(timer); - } + timer = instance_del_data(data, GBAR_RESIZE_MONITOR_TAG); + if (timer) { + ecore_timer_del(timer); + } - (void)instance_unref(data); + (void)instance_unref(data); - return -1; /* remove this handler */ + return -1; /* remove this handler */ } static int key_event_dbox_route_cb(enum event_state state, struct event_data *event_info, void *data) { - struct inst_info *inst = data; - const struct pkg_info *pkg; - struct slave_node *slave; - struct packet *packet; - unsigned int cmd; + struct inst_info *inst = data; + const struct pkg_info *pkg; + struct slave_node *slave; + struct packet *packet; + unsigned int cmd; - if (!inst) { - DbgPrint("Instance is deleted.\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!inst) { + DbgPrint("Instance is deleted.\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - pkg = instance_package(inst); - if (!pkg) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + pkg = instance_package(inst); + if (!pkg) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - slave = package_slave(pkg); - if (!slave) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + slave = package_slave(pkg); + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - cmd = CMD_DBOX_KEY_DOWN; - break; + cmd = CMD_DBOX_KEY_DOWN; + break; case EVENT_STATE_ACTIVATED: - cmd = CMD_DBOX_KEY_DOWN; - break; + cmd = CMD_DBOX_KEY_DOWN; + break; case EVENT_STATE_DEACTIVATE: - cmd = CMD_DBOX_KEY_UP; - break; + cmd = CMD_DBOX_KEY_UP; + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode); - if (!packet) { - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode); + if (!packet) { + return DBOX_STATUS_ERROR_FAULT; + } - return slave_rpc_request_only(slave, package_name(pkg), packet, 0); + return slave_rpc_request_only(slave, package_name(pkg), packet, 0); } static int mouse_event_dbox_route_cb(enum event_state state, struct event_data *event_info, void *data) { - struct inst_info *inst = data; - const struct pkg_info *pkg; - struct slave_node *slave; - struct packet *packet; - unsigned int cmd; + struct inst_info *inst = data; + const struct pkg_info *pkg; + struct slave_node *slave; + struct packet *packet; + unsigned int cmd; - if (!inst) { - DbgPrint("Instance is deleted.\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!inst) { + DbgPrint("Instance is deleted.\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - pkg = instance_package(inst); - if (!pkg) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + pkg = instance_package(inst); + if (!pkg) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - slave = package_slave(pkg); - if (!slave) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + slave = package_slave(pkg); + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - cmd = CMD_DBOX_MOUSE_DOWN; - break; + cmd = CMD_DBOX_MOUSE_DOWN; + break; case EVENT_STATE_ACTIVATED: - cmd = CMD_DBOX_MOUSE_MOVE; - break; + cmd = CMD_DBOX_MOUSE_MOVE; + break; case EVENT_STATE_DEACTIVATE: - cmd = CMD_DBOX_MOUSE_UP; - break; + cmd = CMD_DBOX_MOUSE_UP; + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y); - if (!packet) { - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y); + if (!packet) { + return DBOX_STATUS_ERROR_FAULT; + } - return slave_rpc_request_only(slave, package_name(pkg), packet, 0); + return slave_rpc_request_only(slave, package_name(pkg), packet, 0); } static int key_event_dbox_consume_cb(enum event_state state, struct event_data *event_info, void *data) { - struct script_info *script; - struct inst_info *inst = data; - const struct pkg_info *pkg; - double timestamp; + struct script_info *script; + struct inst_info *inst = data; + const struct pkg_info *pkg; + double timestamp; - pkg = instance_package(inst); - if (!pkg) { - return 0; - } + pkg = instance_package(inst); + if (!pkg) { + return 0; + } - script = instance_dbox_script(inst); - if (!script) { - return DBOX_STATUS_ERROR_FAULT; - } + script = instance_dbox_script(inst); + if (!script) { + return DBOX_STATUS_ERROR_FAULT; + } - timestamp = event_info->tv; + timestamp = event_info->tv; - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - script_handler_update_keycode(script, event_info->keycode); - (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); - break; + script_handler_update_keycode(script, event_info->keycode); + (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); + break; case EVENT_STATE_ACTIVATED: - script_handler_update_keycode(script, event_info->keycode); - (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); - break; + script_handler_update_keycode(script, event_info->keycode); + (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); + break; case EVENT_STATE_DEACTIVATE: - script_handler_update_keycode(script, event_info->keycode); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); - break; + script_handler_update_keycode(script, event_info->keycode); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); + break; default: - ErrPrint("Unknown event\n"); - break; - } + ErrPrint("Unknown event\n"); + break; + } - return 0; + return 0; } static int mouse_event_dbox_consume_cb(enum event_state state, struct event_data *event_info, void *data) { - struct script_info *script; - struct inst_info *inst = data; - const struct pkg_info *pkg; - double timestamp; + struct script_info *script; + struct inst_info *inst = data; + const struct pkg_info *pkg; + double timestamp; - pkg = instance_package(inst); - if (!pkg) { - return 0; - } + pkg = instance_package(inst); + if (!pkg) { + return 0; + } - script = instance_dbox_script(inst); - if (!script) { - return DBOX_STATUS_ERROR_FAULT; - } + script = instance_dbox_script(inst); + if (!script) { + return DBOX_STATUS_ERROR_FAULT; + } - timestamp = event_info->tv; + timestamp = event_info->tv; - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - script_handler_update_pointer(script, event_info->x, event_info->y, 1); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); - break; + script_handler_update_pointer(script, event_info->x, event_info->y, 1); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); + break; case EVENT_STATE_ACTIVATED: - script_handler_update_pointer(script, event_info->x, event_info->y, -1); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); - break; + script_handler_update_pointer(script, event_info->x, event_info->y, -1); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); + break; case EVENT_STATE_DEACTIVATE: - script_handler_update_pointer(script, event_info->x, event_info->y, 0); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); - break; + script_handler_update_pointer(script, event_info->x, event_info->y, 0); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); + break; default: - break; - } + break; + } - return 0; + return 0; } static int key_event_gbar_route_cb(enum event_state state, struct event_data *event_info, void *data) { - struct inst_info *inst = data; - const struct pkg_info *pkg; - struct slave_node *slave; - struct packet *packet; - unsigned int cmd; + struct inst_info *inst = data; + const struct pkg_info *pkg; + struct slave_node *slave; + struct packet *packet; + unsigned int cmd; - if (!inst) { - DbgPrint("Instance is deleted.\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!inst) { + DbgPrint("Instance is deleted.\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - pkg = instance_package(inst); - if (!pkg) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + pkg = instance_package(inst); + if (!pkg) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - slave = package_slave(pkg); - if (!slave) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + slave = package_slave(pkg); + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - cmd = CMD_GBAR_KEY_DOWN; - break; + cmd = CMD_GBAR_KEY_DOWN; + break; case EVENT_STATE_ACTIVATED: - cmd = CMD_GBAR_KEY_DOWN; - break; + cmd = CMD_GBAR_KEY_DOWN; + break; case EVENT_STATE_DEACTIVATE: - cmd = CMD_GBAR_KEY_UP; - break; + cmd = CMD_GBAR_KEY_UP; + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode); - if (!packet) { - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode); + if (!packet) { + return DBOX_STATUS_ERROR_FAULT; + } - return slave_rpc_request_only(slave, package_name(pkg), packet, 0); + return slave_rpc_request_only(slave, package_name(pkg), packet, 0); } static int mouse_event_gbar_route_cb(enum event_state state, struct event_data *event_info, void *data) { - struct inst_info *inst = data; - const struct pkg_info *pkg; - struct slave_node *slave; - struct packet *packet; - unsigned int cmd; + struct inst_info *inst = data; + const struct pkg_info *pkg; + struct slave_node *slave; + struct packet *packet; + unsigned int cmd; - if (!inst) { - DbgPrint("Instance is deleted.\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!inst) { + DbgPrint("Instance is deleted.\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - pkg = instance_package(inst); - if (!pkg) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + pkg = instance_package(inst); + if (!pkg) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - slave = package_slave(pkg); - if (!slave) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + slave = package_slave(pkg); + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - cmd = CMD_GBAR_MOUSE_DOWN; - break; + cmd = CMD_GBAR_MOUSE_DOWN; + break; case EVENT_STATE_ACTIVATED: - cmd = CMD_GBAR_MOUSE_MOVE; - break; + cmd = CMD_GBAR_MOUSE_MOVE; + break; case EVENT_STATE_DEACTIVATE: - cmd = CMD_GBAR_MOUSE_UP; - break; + cmd = CMD_GBAR_MOUSE_UP; + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y); - if (!packet) { - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y); + if (!packet) { + return DBOX_STATUS_ERROR_FAULT; + } - return slave_rpc_request_only(slave, package_name(pkg), packet, 0); + return slave_rpc_request_only(slave, package_name(pkg), packet, 0); } static int key_event_gbar_consume_cb(enum event_state state, struct event_data *event_info, void *data) { - struct script_info *script; - struct inst_info *inst = data; - const struct pkg_info *pkg; - double timestamp; + struct script_info *script; + struct inst_info *inst = data; + const struct pkg_info *pkg; + double timestamp; - pkg = instance_package(inst); - if (!pkg) { - return 0; - } + pkg = instance_package(inst); + if (!pkg) { + return 0; + } - script = instance_gbar_script(inst); - if (!script) { - return DBOX_STATUS_ERROR_FAULT; - } + script = instance_gbar_script(inst); + if (!script) { + return DBOX_STATUS_ERROR_FAULT; + } - timestamp = event_info->tv; + timestamp = event_info->tv; - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - script_handler_update_keycode(script, event_info->keycode); - (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); - break; + script_handler_update_keycode(script, event_info->keycode); + (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); + break; case EVENT_STATE_ACTIVATED: - script_handler_update_keycode(script, event_info->keycode); - (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); - break; + script_handler_update_keycode(script, event_info->keycode); + (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); + break; case EVENT_STATE_DEACTIVATE: - script_handler_update_keycode(script, event_info->keycode); - (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp); - break; + script_handler_update_keycode(script, event_info->keycode); + (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp); + break; default: - ErrPrint("Unknown event\n"); - break; - } + ErrPrint("Unknown event\n"); + break; + } - return 0; + return 0; } static int mouse_event_gbar_consume_cb(enum event_state state, struct event_data *event_info, void *data) { - struct script_info *script; - struct inst_info *inst = data; - const struct pkg_info *pkg; - double timestamp; + struct script_info *script; + struct inst_info *inst = data; + const struct pkg_info *pkg; + double timestamp; - pkg = instance_package(inst); - if (!pkg) { - return 0; - } + pkg = instance_package(inst); + if (!pkg) { + return 0; + } - script = instance_gbar_script(inst); - if (!script) { - return DBOX_STATUS_ERROR_FAULT; - } + script = instance_gbar_script(inst); + if (!script) { + return DBOX_STATUS_ERROR_FAULT; + } - timestamp = event_info->tv; + timestamp = event_info->tv; - switch (state) { + switch (state) { case EVENT_STATE_ACTIVATE: - script_handler_update_pointer(script, event_info->x, event_info->y, 1); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); - break; + script_handler_update_pointer(script, event_info->x, event_info->y, 1); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); + break; case EVENT_STATE_ACTIVATED: - script_handler_update_pointer(script, event_info->x, event_info->y, -1); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); - break; + script_handler_update_pointer(script, event_info->x, event_info->y, -1); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); + break; case EVENT_STATE_DEACTIVATE: - script_handler_update_pointer(script, event_info->x, event_info->y, 0); - (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); - break; + script_handler_update_pointer(script, event_info->x, event_info->y, 0); + (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); + break; default: - break; - } - return 0; + break; + } + return 0; } static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */ { - struct client_node *client; - struct packet *result; - const char *direct_addr; - double timestamp; - int ret; + struct client_node *client; + struct packet *result; + const char *direct_addr; + double timestamp; + int ret; + + client = client_find_by_rpc_handle(handle); + if (client) { + ErrPrint("Client is already exists %d\n", pid); + ret = DBOX_STATUS_ERROR_EXIST; + goto out; + } + + if (packet_get(packet, "ds", ×tamp, &direct_addr) != 2) { + ErrPrint("Invalid arguemnt\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = 0; + /*! + * \note + * client_create will invoke the client created callback + */ + client = client_create(pid, handle, direct_addr); + if (!client) { + ErrPrint("Failed to create a new client for %d\n", pid); + ret = DBOX_STATUS_ERROR_FAULT; + } - client = client_find_by_rpc_handle(handle); - if (client) { - ErrPrint("Client is already exists %d\n", pid); - ret = DBOX_STATUS_ERROR_EXIST; - goto out; - } +out: + result = packet_create_reply(packet, "ii", ret, DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - if (packet_get(packet, "ds", ×tamp, &direct_addr) != 2) { - ErrPrint("Invalid arguemnt\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = 0; - /*! - * \note - * client_create will invoke the client created callback - */ - client = client_create(pid, handle, direct_addr); - if (!client) { - ErrPrint("Failed to create a new client for %d\n", pid); - ret = DBOX_STATUS_ERROR_FAULT; - } - -out: - result = packet_create_reply(packet, "ii", ret, DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } - - return result; -} + return result; +} static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */ { - struct client_node *client; - struct packet *result; - int ret; + struct client_node *client; + struct packet *result; + int ret; - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } - client_destroy(client); - ret = 0; + client_destroy(client); + ret = 0; out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - return result; + return result; } static int validate_request(const char *pkgname, const char *id, struct inst_info **out_inst, const struct pkg_info **out_pkg) { - struct inst_info *inst; - const struct pkg_info *pkg; + struct inst_info *inst; + const struct pkg_info *pkg; - inst = package_find_instance_by_id(pkgname, id); - if (!inst) { - ErrPrint("Instance is not exists (%s)\n", id); - return DBOX_STATUS_ERROR_NOT_EXIST; - } + inst = package_find_instance_by_id(pkgname, id); + if (!inst) { + ErrPrint("Instance is not exists (%s)\n", id); + return DBOX_STATUS_ERROR_NOT_EXIST; + } - pkg = instance_package(inst); - if (!pkg) { - ErrPrint("System error - instance has no package?\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + pkg = instance_package(inst); + if (!pkg) { + ErrPrint("System error - instance has no package?\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (package_is_fault(pkg)) { - ErrPrint("Faulted package: %s\n", pkgname); - return DBOX_STATUS_ERROR_FAULT; - } + if (package_is_fault(pkg)) { + ErrPrint("Faulted package: %s\n", pkgname); + return DBOX_STATUS_ERROR_FAULT; + } - if (out_inst) { - *out_inst = inst; - } + if (out_inst) { + *out_inst = inst; + } - if (out_pkg) { - *out_pkg = pkg; - } + if (out_pkg) { + *out_pkg = pkg; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /*!< pid, pkgname, filename, event, timestamp, x, y, ret */ static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - const char *event; - double timestamp; - double x; - double y; - int ret; - struct inst_info *inst; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "sssddd", &pkgname, &id, &event, ×tamp, &x, &y); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - goto out; - } - - /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. - */ - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - (void)instance_clicked(inst, event, timestamp, x, y); - } + struct client_node *client; + const char *pkgname; + const char *id; + const char *event; + double timestamp; + double x; + double y; + int ret; + struct inst_info *inst; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "sssddd", &pkgname, &id, &event, ×tamp, &x, &y); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + (void)instance_clicked(inst, event, timestamp, x, y); + } out: - /*! \note No reply packet */ - return NULL; + /*! \note No reply packet */ + return NULL; } static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - int active_update; - const char *pkgname; - const char *id; - int ret; - struct inst_info *inst; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + struct packet *result; + struct client_node *client; + int active_update; + const char *pkgname; + const char *id; + int ret; + struct inst_info *inst; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ssi", &pkgname, &id, &active_update); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = packet_get(packet, "ssi", &pkgname, &id, &active_update); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - /*! - * \note - * Send change update mode request to a slave - */ - ret = instance_set_update_mode(inst, active_update); - } + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + /*! + * \note + * Send change update mode request to a slave + */ + ret = instance_set_update_mode(inst, active_update); + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - return result; + return result; } /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */ static struct packet *client_text_signal(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - const char *emission; - const char *source; - double sx; - double sy; - double ex; - double ey; - struct inst_info *inst = NULL; - int ret; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey); - if (ret != 8) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. - */ - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey); - } + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + const char *emission; + const char *source; + double sx; + double sy; + double ex; + double ey; + struct inst_info *inst = NULL; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey); + if (ret != 8) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey); + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - return result; + return result; } static Eina_Bool lazy_delete_cb(void *data) { - struct deleted_item *item = data; + struct deleted_item *item = data; - DbgPrint("Lazy delete callback called\n"); - /*! - * Before invoke this callback, the instance is able to already remove this client - * So check it again - */ - if (instance_has_client(item->inst, item->client)) { - (void)instance_unicast_deleted_event(item->inst, item->client, DBOX_STATUS_ERROR_NONE); - (void)instance_del_client(item->inst, item->client); - } + DbgPrint("Lazy delete callback called\n"); + /*! + * Before invoke this callback, the instance is able to already remove this client + * So check it again + */ + if (instance_has_client(item->inst, item->client)) { + (void)instance_unicast_deleted_event(item->inst, item->client, DBOX_STATUS_ERROR_NONE); + (void)instance_del_client(item->inst, item->client); + } - (void)client_unref(item->client); - (void)instance_unref(item->inst); - DbgFree(item); - return ECORE_CALLBACK_CANCEL; + (void)client_unref(item->client); + (void)instance_unref(item->inst); + DbgFree(item); + return ECORE_CALLBACK_CANCEL; } static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */ { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - struct inst_info *inst; - const struct pkg_info *pkg; - int ret; - int type; - double timestamp; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + struct inst_info *inst; + const struct pkg_info *pkg; + int ret; + int type; + double timestamp; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssid", &pkgname, &id, &type, ×tamp); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + /*! + * \note + * Below two types must has to be sync'd with dynamicbox-viewer + * + * DBOX_DELETE_PERMANENTLY = 0x01, + * DBOX_DELETE_TEMPORARY = 0x02, + * + */ + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + DbgPrint("Failed to find by id(%s), try to find it using timestamp(%lf)\n", id, timestamp); + inst = package_find_instance_by_timestamp(pkgname, timestamp); + if (!inst) { + goto out; } - ret = packet_get(packet, "ssid", &pkgname, &id, &type, ×tamp); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + pkg = instance_package(inst); + if (!pkg) { + ErrPrint("Package info is not valid: %s\n", id); + goto out; } - /*! - * \note - * Below two types must has to be sync'd with dynamicbox-viewer - * - * DBOX_DELETE_PERMANENTLY = 0x01, - * DBOX_DELETE_TEMPORARY = 0x02, - * - */ + } - /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. - */ - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - DbgPrint("Failed to find by id(%s), try to find it using timestamp(%lf)\n", id, timestamp); - inst = package_find_instance_by_timestamp(pkgname, timestamp); - if (!inst) { - goto out; - } + if (package_is_fault(pkg)) { + DbgPrint("Faulted package. will be deleted soon: %s\n", id); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - pkg = instance_package(inst); - if (!pkg) { - ErrPrint("Package info is not valid: %s\n", id); - goto out; - } - } + if (instance_client(inst) != client) { + if (instance_has_client(inst, client)) { + struct deleted_item *item; - if (package_is_fault(pkg)) { - DbgPrint("Faulted package. will be deleted soon: %s\n", id); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } else { + /*! + * \NOTE: + * Send DELETED EVENT to the client. + * after return from this function. + * + * Client will prepare the deleted event after get this function's return value. + * So We have to make a delay to send a deleted event. + */ + + item->client = client_ref(client); + item->inst = instance_ref(inst); - if (instance_client(inst) != client) { - if (instance_has_client(inst, client)) { - struct deleted_item *item; - - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } else { - /*! - * \NOTE: - * Send DELETED EVENT to the client. - * after return from this function. - * - * Client will prepare the deleted event after get this function's return value. - * So We have to make a delay to send a deleted event. - */ - - item->client = client_ref(client); - item->inst = instance_ref(inst); - - if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) { - ErrPrint("Failed to add a delayzed delete callback\n"); - (void)client_unref(client); - (void)instance_unref(inst); - DbgFree(item); - ret = DBOX_STATUS_ERROR_FAULT; - } else { - ret = DBOX_STATUS_ERROR_NONE; - } - } + if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) { + ErrPrint("Failed to add a delayzed delete callback\n"); + (void)client_unref(client); + (void)instance_unref(inst); + DbgFree(item); + ret = DBOX_STATUS_ERROR_FAULT; } else { - ErrPrint("Client has no permission\n"); - ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + ret = DBOX_STATUS_ERROR_NONE; } + } } else { - switch (type) { - case DBOX_DELETE_PERMANENTLY: - ret = instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT); - break; - case DBOX_DELETE_TEMPORARY: - ret = instance_destroy(inst, DBOX_DESTROY_TYPE_TEMPORARY); - break; - default: - break; - } + ErrPrint("Client has no permission\n"); + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + } + } else { + switch (type) { + case DBOX_DELETE_PERMANENTLY: + ret = instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT); + break; + case DBOX_DELETE_TEMPORARY: + ret = instance_destroy(inst, DBOX_DESTROY_TYPE_TEMPORARY); + break; + default: + break; } + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - return result; + return result; } static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */ { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - int w; - int h; - struct inst_info *inst = NULL; - int ret; + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + int w; + int h; + struct inst_info *inst = NULL; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname); + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_client(inst) != client) { + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + } else { + ret = instance_resize(inst, w, h); + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + return result; +} + +static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */ +{ + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *content; + const char *cluster; + const char *category; + double period; + double timestamp; + int ret; + struct pkg_info *info; + int width; + int height; + char *lbid; + char *mainappid; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height); + if (ret != 8) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n", + pid, timestamp, pkgname, content, cluster, category, period); + + lbid = package_dbox_pkgname(pkgname); + if (!lbid) { + ErrPrint("This %s has no dynamicbox package\n", pkgname); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname); + mainappid = dynamicbox_service_mainappid(lbid); + if (!package_is_enabled(mainappid)) { + DbgFree(mainappid); + DbgFree(lbid); + ret = DBOX_STATUS_ERROR_DISABLED; + goto out; + } + DbgFree(mainappid); + + info = package_find(lbid); + if (!info) { + char *pkgid; + pkgid = dynamicbox_service_package_id(lbid); + if (!pkgid) { + DbgFree(mainappid); + DbgFree(lbid); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + info = package_create(pkgid, lbid); + DbgFree(pkgid); + } + + if (!info) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (package_is_fault(info)) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) <= DYNAMICBOX_CONF_MINIMUM_SPACE) { + ErrPrint("Not enough space\n"); + ret = DBOX_STATUS_ERROR_NO_SPACE; + } else { + struct inst_info *inst; + + if (period > 0.0f && period < DYNAMICBOX_CONF_MINIMUM_PERIOD) { + period = DYNAMICBOX_CONF_MINIMUM_PERIOD; + } + inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height); /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. + * \note + * Using the "inst" without validate its value is at my disposal. ;) */ - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + ret = inst ? 0 : DBOX_STATUS_ERROR_FAULT; + } - if (instance_client(inst) != client) { - ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; - } else { - ret = instance_resize(inst, w, h); - } + DbgFree(lbid); out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - return result; + return result; } -static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */ +static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *content; - const char *cluster; - const char *category; - double period; - double timestamp; - int ret; - struct pkg_info *info; - int width; - int height; - char *lbid; - char *mainappid; + struct client_node *client; + const char *pkgname; + const char *id; + enum dynamicbox_visible_state state; + int ret; + struct inst_info *inst; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_client(inst) != client) { + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + } else { + ret = instance_set_visible_state(inst, state); + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } +out: + /*! \note No reply packet */ + return NULL; +} - ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height); - if (ret != 8) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } +static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */ +{ + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + double period; + int ret; + struct inst_info *inst = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssd", &pkgname, &id, &period); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period); + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_client(inst) != client) { + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + } else { + ret = instance_set_period(inst, period); + } - DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n", - pid, timestamp, pkgname, content, cluster, category, period); +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - lbid = package_dbox_pkgname(pkgname); - if (!lbid) { - ErrPrint("This %s has no dynamicbox package\n", pkgname); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + return result; +} - mainappid = dynamicbox_service_mainappid(lbid); - if (!package_is_enabled(mainappid)) { - DbgFree(mainappid); - DbgFree(lbid); - ret = DBOX_STATUS_ERROR_DISABLED; - goto out; - } - DbgFree(mainappid); +static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */ +{ + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + const char *cluster; + const char *category; + struct inst_info *inst = NULL; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category); + + /*! + * \NOTE: + * Trust the package name which are sent by the client. + * The package has to be a dynamicbox package name. + */ + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_client(inst) != client) { + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + } else { + ret = instance_change_group(inst, cluster, category); + } - info = package_find(lbid); - if (!info) { - char *pkgid; - pkgid = dynamicbox_service_package_id(lbid); - if (!pkgid) { - DbgFree(mainappid); - DbgFree(lbid); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - info = package_create(pkgid, lbid); - DbgFree(pkgid); - } + return result; +} - if (!info) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (package_is_fault(info)) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) <= DYNAMICBOX_CONF_MINIMUM_SPACE) { - ErrPrint("Not enough space\n"); - ret = DBOX_STATUS_ERROR_NO_SPACE; - } else { - struct inst_info *inst; +static struct packet *client_gbar_mouse_enter(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - if (period > 0.0f && period < DYNAMICBOX_CONF_MINIMUM_PERIOD) { - period = DYNAMICBOX_CONF_MINIMUM_PERIOD; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height); - /*! - * \note - * Using the "inst" without validate its value is at my disposal. ;) - */ - ret = inst ? 0 : DBOX_STATUS_ERROR_FAULT; + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - DbgFree(lbid); + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + /*! \note No reply packet */ + return NULL; +} - return result; -} - -static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_mouse_leave(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - enum dynamicbox_visible_state state; - int ret; - struct inst_info *inst; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. - */ - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (instance_client(inst) != client) { - ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; - } else { - ret = instance_set_visible_state(inst, state); - } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */ +static struct packet *client_gbar_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, id, width, height, timestamp, x, y, ret */ { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - double period; - int ret; - struct inst_info *inst = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ssd", &pkgname, &id, &period); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period); + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. - */ - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (instance_client(inst) != client) { - ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; - } else { - ret = instance_set_period(inst, period); - } + script_handler_update_pointer(script, x, y, 1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } - - return result; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */ +static struct packet *client_gbar_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - const char *cluster; - const char *category; - struct inst_info *inst = NULL; - int ret; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category); + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - /*! - * \NOTE: - * Trust the package name which are sent by the client. - * The package has to be a dynamicbox package name. - */ - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (instance_client(inst) != client) { - ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; - } else { - ret = instance_change_group(inst, cluster, category); - } + script_handler_update_pointer(script, x, y, 0); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } - - return result; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_gbar_mouse_enter(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_gbar_mouse_leave(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_gbar_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, id, width, height, timestamp, x, y, ret */ +static int inst_del_cb(struct inst_info *inst, void *data) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; + int ret; - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + /* + * If you deactivate the event thread, + * It will calls event callbacks. + * And the event callbacks will try to access the "inst" + */ + (void)event_deactivate(data, inst); - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + /* Reset callback data to prevent accessing inst from event callback */ + ret = event_reset_cbdata(data, inst, NULL); + DbgPrint("Instance delete callback called: %s (%d)\n", instance_id(inst), ret); - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(instance_package(inst)), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); + } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; + return -1; /* Delete this callback */ +} - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - script_handler_update_pointer(script, x, y, 1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +static struct packet *client_gbar_key_set(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = event_activate(0, 0, key_event_gbar_route_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb); + } + } + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + ret = event_activate(0, 0, key_event_gbar_consume_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb); + } + } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_gbar_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +static struct packet *client_gbar_key_unset(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = event_deactivate(key_event_gbar_route_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb); + } + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + ret = event_deactivate(key_event_gbar_consume_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb); + } + */ + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + return result; +} - script_handler_update_pointer(script, x, y, 0); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +static struct packet *client_dbox_key_set(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = event_activate(0, 0, key_event_dbox_route_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb); + } + } + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + ret = event_activate(0, 0, key_event_dbox_consume_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb); + } + } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_gbar_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +static struct packet *client_dbox_key_unset(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = event_deactivate(key_event_dbox_route_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb); + } + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + ret = event_deactivate(key_event_dbox_consume_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb); + } + */ + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static int inst_del_cb(struct inst_info *inst, void *data) -{ - int ret; - - /* - * If you deactivate the event thread, - * It will calls event callbacks. - * And the event callbacks will try to access the "inst" - */ - (void)event_deactivate(data, inst); - - /* Reset callback data to prevent accessing inst from event callback */ - ret = event_reset_cbdata(data, inst, NULL); - DbgPrint("Instance delete callback called: %s (%d)\n", instance_id(inst), ret); - - return -1; /* Delete this callback */ -} - - -static struct packet *client_gbar_key_set(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = event_activate(0, 0, key_event_gbar_route_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb); - } - } - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - ret = event_activate(0, 0, key_event_gbar_consume_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb); - } - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_key_unset(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = event_deactivate(key_event_gbar_route_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb); - } - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - ret = event_deactivate(key_event_gbar_consume_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb); - } - */ - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_dbox_key_set(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = event_activate(0, 0, key_event_dbox_route_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb); - } - } - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - ret = event_activate(0, 0, key_event_dbox_consume_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb); - } - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_dbox_key_unset(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = event_deactivate(key_event_dbox_route_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb); - } - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - ret = event_deactivate(key_event_dbox_consume_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb); - } - */ - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} + return result; +} static struct packet *client_dbox_mouse_set(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = event_activate(x, y, mouse_event_dbox_route_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb); - } - } - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - ret = event_activate(x, y, mouse_event_dbox_consume_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb); - } - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = event_activate(x, y, mouse_event_dbox_route_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb); + } + } + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + ret = event_activate(x, y, mouse_event_dbox_consume_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb); + } + } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - return NULL; + return NULL; } static struct packet *client_dbox_mouse_unset(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = event_deactivate(mouse_event_dbox_route_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = event_deactivate(mouse_event_dbox_route_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb); - } - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - ret = event_deactivate(mouse_event_dbox_consume_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb); - } - */ - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb); + } + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + ret = event_deactivate(mouse_event_dbox_consume_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb); + } + */ + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - return NULL; + return NULL; } static struct packet *client_gbar_mouse_set(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = event_activate(x, y, mouse_event_gbar_route_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb); - } - } - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - ret = event_activate(x, y, mouse_event_gbar_consume_cb, inst); - if (ret == DBOX_STATUS_ERROR_NONE) { - if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb) <= 0) { - instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb); - } - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - return NULL; -} - -static struct packet *client_dbox_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_on_hold(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_off_hold(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_gbar_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_gbar_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_gbar_mouse_on_hold(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_gbar_mouse_off_hold(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_event_packet(pkg, inst, packet); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_gbar_mouse_unset(pid_t pid, int handle, const struct packet *packet) -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = event_deactivate(mouse_event_gbar_route_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb); - } - */ - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - ret = event_deactivate(mouse_event_gbar_consume_cb, inst); - /* - * This delete callback will be removed when the instance will be destroyed. - if (ret == 0) { - instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb); - } - */ - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } -out: - return NULL; -} - -static struct packet *client_dbox_mouse_enter(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_leave(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, -1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, 1); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_dbox_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ -{ - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - int x; - int y; - struct inst_info *inst; - const struct pkg_info *pkg; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); - if (ret != 5) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_event_packet(pkg, inst, packet); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, x, y, 0); - script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); - ret = 0; - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - /*! \note No reply packet */ - return NULL; -} - -static struct packet *client_gbar_access_action(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_scroll(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_value_change(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_mouse(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_back(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_over(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_read(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_enable(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - int type; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE; - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, type, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_hl(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - int type; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - switch (event.type) { - case ACCESS_TYPE_CUR: - type = DBOX_SCRIPT_ACCESS_HIGHLIGHT; - break; - case ACCESS_TYPE_NEXT: - type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT; - break; - case ACCESS_TYPE_PREV: - type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV; - break; - case ACCESS_TYPE_OFF: - type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT; - break; - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, type, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; -} - -static struct packet *client_gbar_access_activate(pid_t pid, int handle, const struct packet *packet) -{ - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = event_activate(x, y, mouse_event_gbar_route_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb); + } + } + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + ret = event_activate(x, y, mouse_event_gbar_consume_cb, inst); + if (ret == DBOX_STATUS_ERROR_NONE) { + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON); + } + if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb) <= 0) { + instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb); + } + } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return result; +out: + return NULL; } -static struct packet *client_gbar_key_focus_in(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_gbar_key_focus_out(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_gbar_key_down(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_mouse_on_hold(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +out: + /*! \note No reply packet */ + return NULL; +} - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +static struct packet *client_dbox_mouse_off_hold(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - return result; + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + +out: + /*! \note No reply packet */ + return NULL; } -static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - double timestamp; - int ret; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is paused - manually reported\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "d", ×tamp); - if (ret != 1) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - if (DYNAMICBOX_CONF_USE_XMONITOR) { - DbgPrint("XMONITOR enabled. ignore client paused request\n"); - } else { - xmonitor_pause(client); + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + out: - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - double timestamp; - int ret; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "d", ×tamp); - if (ret != 1) { - ErrPrint("Invalid parameter\n"); - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - if (DYNAMICBOX_CONF_USE_XMONITOR) { - DbgPrint("XMONITOR enabled. ignore client resumed request\n"); - } else { - xmonitor_resume(client); + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + out: - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_gbar_key_up(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_mouse_on_hold(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - struct script_info *script; + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - script = instance_gbar_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +out: + /*! \note No reply packet */ + return NULL; +} - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +static struct packet *client_gbar_mouse_off_hold(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_event_packet(pkg, inst, packet); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - return result; + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + +out: + /*! \note No reply packet */ + return NULL; } -static struct packet *client_dbox_access_hl(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_mouse_unset(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = event_deactivate(mouse_event_gbar_route_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } - - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb); + } + */ + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + ret = event_deactivate(mouse_event_gbar_consume_cb, inst); + if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) { + (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF); } + /* + * This delete callback will be removed when the instance will be destroyed. + if (ret == 0) { + instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb); + } + */ + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } +out: + return NULL; +} - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - int type; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +static struct packet *client_dbox_mouse_enter(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - switch (event.type) { - case ACCESS_TYPE_CUR: - type = DBOX_SCRIPT_ACCESS_HIGHLIGHT; - break; - case ACCESS_TYPE_NEXT: - type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT; - break; - case ACCESS_TYPE_PREV: - type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV; - break; - case ACCESS_TYPE_OFF: - type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT; - break; - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, type, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - return result; + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + +out: + /*! \note No reply packet */ + return NULL; } -static struct packet *client_dbox_access_action(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_mouse_leave(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + script_handler_update_pointer(script, x, y, -1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } - - return result; + /*! \note No reply packet */ + return NULL; } -static struct packet *client_dbox_access_scroll(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; + script_handler_update_pointer(script, x, y, 1); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +out: + /*! \note No reply packet */ + return NULL; +} - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +static struct packet *client_dbox_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + int x; + int y; + struct inst_info *inst; + const struct pkg_info *pkg; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y); + if (ret != 5) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_event_packet(pkg, inst, packet); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - return result; + script_handler_update_pointer(script, x, y, 0); + script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp); + ret = 0; + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + +out: + /*! \note No reply packet */ + return NULL; } -static struct packet *client_dbox_access_value_change(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_action(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_access_mouse(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_scroll(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_access_back(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_value_change(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_access_over(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_mouse(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_access_read(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_back(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } - - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_access_enable(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_over(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - struct access_info event; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exist\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - /*! - * Enen if it fails to send packet, - * The packet will be unref'd - * So we don't need to check the ret value. - */ - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - int type; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE; - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, type, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_access_activate(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_read(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - struct access_info event; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); - if (ret != 6) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ErrPrint("Instance has no script\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - script_handler_update_pointer(script, event.x, event.y, event.type); - ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp); - if (ret >= 0) { - ret = send_delayed_access_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_key_down(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_enable(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + int type; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; - - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE; - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, type, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_key_focus_in(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_access_hl(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + int type; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); + switch (event.type) { + case ACCESS_TYPE_CUR: + type = DBOX_SCRIPT_ACCESS_HIGHLIGHT; + break; + case ACCESS_TYPE_NEXT: + type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT; + break; + case ACCESS_TYPE_PREV: + type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV; + break; + case ACCESS_TYPE_OFF: + type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT; + break; + default: ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; goto out; } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, type, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; + return result; +} - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } +static struct packet *client_gbar_access_activate(pid_t pid, int handle, const struct packet *packet) +{ + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return result; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_dbox_key_focus_out(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_key_focus_in(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + return result; +} - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; +static struct packet *client_gbar_key_focus_out(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return result; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_dbox_key_up(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_key_down(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - const char *pkgname; - const char *id; - int ret; - double timestamp; - unsigned int keycode; - struct inst_info *inst; - const struct pkg_info *pkg; - struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); - } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { - struct script_info *script; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - script = instance_dbox_script(inst); - if (!script) { - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + return result; +} - script_handler_update_keycode(script, keycode); - ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp); - if (ret >= 0) { - ret = send_delayed_key_status(inst, ret); - } - } else { - ErrPrint("Unsupported package\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + double timestamp; + int ret; -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is paused - manually reported\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } - return result; + ret = packet_get(packet, "d", ×tamp); + if (ret != 1) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + if (DYNAMICBOX_CONF_USE_XMONITOR) { + DbgPrint("XMONITOR enabled. ignore client paused request\n"); + } else { + xmonitor_pause(client); + } + +out: + return NULL; } -static int release_pixmap_cb(struct client_node *client, void *canvas) +static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet) { - DbgPrint("Forcely unref the \"buffer\"\n"); - buffer_handler_pixmap_unref(canvas); - return -1; /* Delete this callback */ -} + struct client_node *client; + double timestamp; + int ret; + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + goto out; + } -static struct packet *client_dbox_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ -{ - struct packet *result; - const char *pkgname; - const char *id; - struct client_node *client; - struct inst_info *inst; - int ret; - int pixmap = 0; - void *buf_ptr; - struct buffer_info *buffer; - int idx; + ret = packet_get(packet, "d", ×tamp); + if (ret != 1) { + ErrPrint("Invalid parameter\n"); + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (DYNAMICBOX_CONF_USE_XMONITOR) { + DbgPrint("XMONITOR enabled. ignore client resumed request\n"); + } else { + xmonitor_resume(client); + } - ret = packet_get(packet, "ssi", &pkgname, &id, &idx); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } +out: + return NULL; +} - if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) { - DbgPrint("Index is not valid: %d\n", idx); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } +static struct packet *client_gbar_key_up(pid_t pid, int handle, const struct packet *packet) +{ + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - buffer = instance_dbox_extra_buffer(inst, idx); - if (!buffer) { - ErrPrint("Extra buffer for %d is not available\n", idx); - goto out; - } + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + struct script_info *script; - buf_ptr = buffer_handler_pixmap_ref(buffer); - if (!buf_ptr) { - ErrPrint("Failed to ref pixmap\n"); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; + script = instance_gbar_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); - if (ret < 0) { - ErrPrint("Failed to add a new client deactivate callback\n"); - buffer_handler_pixmap_unref(buf_ptr); - } else { - pixmap = buffer_handler_pixmap(buffer); - ret = DBOX_STATUS_ERROR_NONE; + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "ii", pixmap, ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +static struct packet *client_dbox_access_hl(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - const char *pkgname; - const char *id; - struct client_node *client; - struct inst_info *inst; - int ret; - int pixmap = 0; - void *buf_ptr; - struct buffer_info *buffer; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + int type; + + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Parameter is not matched\n"); + switch (event.type) { + case ACCESS_TYPE_CUR: + type = DBOX_SCRIPT_ACCESS_HIGHLIGHT; + break; + case ACCESS_TYPE_NEXT: + type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT; + break; + case ACCESS_TYPE_PREV: + type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV; + break; + case ACCESS_TYPE_OFF: + type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT; + break; + default: ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; goto out; } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, type, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - buffer = instance_dbox_buffer(inst); - if (!buffer) { - struct script_info *script_info; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - script_info = instance_dbox_script(inst); - if (!script_info) { - ErrPrint("Unable to get DBOX buffer: %s\n", id); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + return result; +} - buffer = script_handler_buffer_info(script_info); - if (!buffer) { - ErrPrint("Unable to get buffer_info: %s\n", id); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - } +static struct packet *client_dbox_access_action(pid_t pid, int handle, const struct packet *packet) +{ + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - buf_ptr = buffer_handler_pixmap_ref(buffer); - if (!buf_ptr) { - ErrPrint("Failed to ref pixmap\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); - if (ret < 0) { - ErrPrint("Failed to add a new client deactivate callback\n"); - buffer_handler_pixmap_unref(buf_ptr); - } else { - pixmap = buffer_handler_pixmap(buffer); - ret = DBOX_STATUS_ERROR_NONE; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "ii", pixmap, ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_dbox_release_pixmap(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_access_scroll(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - struct client_node *client; - int pixmap; - void *buf_ptr; - int ret; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - goto out; - } + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = validate_request(pkgname, id, NULL, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - DbgPrint("It seems that the instance is already deleted: %s\n", id); - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - buf_ptr = buffer_handler_pixmap_find(pixmap); - if (!buf_ptr) { - ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap); - goto out; + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) { - buffer_handler_pixmap_unref(buf_ptr); + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /** - * @note No reply packet - */ - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_gbar_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +static struct packet *client_dbox_access_value_change(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - const char *pkgname; - const char *id; - struct client_node *client; - struct inst_info *inst; - int ret; - int pixmap = 0; - void *buf_ptr; - struct buffer_info *buffer; - int idx; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - ErrPrint("Client %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "ssi", &pkgname, &id, &idx); - if (ret != 3) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - ErrPrint("Parameter is not matched\n"); - goto out; - } - - if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - buffer = instance_gbar_extra_buffer(inst, idx); - if (!buffer) { - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - buf_ptr = buffer_handler_pixmap_ref(buffer); - if (!buf_ptr) { - ErrPrint("Failed to ref pixmap\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); - if (ret < 0) { - ErrPrint("Failed to add a new client deactivate callback\n"); - buffer_handler_pixmap_unref(buf_ptr); - } else { - pixmap = buffer_handler_pixmap(buffer); - ret = DBOX_STATUS_ERROR_NONE; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "ii", pixmap, ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_gbar_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +static struct packet *client_dbox_access_mouse(pid_t pid, int handle, const struct packet *packet) { - struct packet *result; - const char *pkgname; - const char *id; - struct client_node *client; - struct inst_info *inst; - int ret; - int pixmap = 0; - void *buf_ptr; - struct buffer_info *buffer; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - ErrPrint("Client %d is not exists\n", pid); - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - ErrPrint("Parameter is not matched\n"); - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) { - ret = DBOX_STATUS_ERROR_BUSY; - goto out; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - buffer = instance_gbar_buffer(inst); - if (!buffer) { - struct script_info *script_info; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - script_info = instance_gbar_script(inst); - if (!script_info) { - ErrPrint("Unable to get DBOX buffer: %s\n", id); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } + return result; +} - buffer = script_handler_buffer_info(script_info); - if (!buffer) { - ErrPrint("Unable to get buffer_info: %s\n", id); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - } +static struct packet *client_dbox_access_back(pid_t pid, int handle, const struct packet *packet) +{ + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - buf_ptr = buffer_handler_pixmap_ref(buffer); - if (!buf_ptr) { - ErrPrint("Failed to ref pixmap\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); - if (ret < 0) { - ErrPrint("Failed to add a new client deactivate callback\n"); - buffer_handler_pixmap_unref(buf_ptr); - } else { - pixmap = buffer_handler_pixmap(buffer); - ret = DBOX_STATUS_ERROR_NONE; + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "ii", pixmap, ret); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_gbar_release_pixmap(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_dbox_access_over(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - struct client_node *client; - int pixmap; - void *buf_ptr; - int ret; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - goto out; - } + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = validate_request(pkgname, id, NULL, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - DbgPrint("It seems that the instance is already deleted: %s\n", id); - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - buf_ptr = buffer_handler_pixmap_find(pixmap); - if (!buf_ptr) { - ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap); - goto out; + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) { - buffer_handler_pixmap_unref(buf_ptr); + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */ +static struct packet *client_dbox_access_read(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - int pinup; - int ret; - struct inst_info *inst; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - pinup = 0; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssi", &pkgname, &id, &pinup); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - pinup = 0; - goto out; + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - ret = instance_set_pinup(inst, pinup); + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static Eina_Bool lazy_gbar_created_cb(void *inst) +static struct packet *client_dbox_access_enable(pid_t pid, int handle, const struct packet *packet) { - struct pkg_info *pkg; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + struct access_info event; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exist\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - if (!instance_del_data(inst, LAZY_GBAR_OPEN_TAG)) { - ErrPrint("lazy,pd,open is already deleted.\n"); - return ECORE_CALLBACK_CANCEL; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - pkg = instance_package(inst); - if (pkg) { - struct slave_node *slave; + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + /*! + * Enen if it fails to send packet, + * The packet will be unref'd + * So we don't need to check the ret value. + */ + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + int type; - slave = package_slave(pkg); - if (slave) { - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst); - } + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - /*! - * After unref instance first, - * if the instance is not destroyed, try to notify the created GBAR event to the client. - */ - if (instance_unref(inst)) { - int ret; - ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_NONE); - if (ret < 0) { - DbgPrint("Send GBAR Create event (%d) to client\n", ret); - } + type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE; + + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, type, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return ECORE_CALLBACK_CANCEL; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static Eina_Bool lazy_gbar_destroyed_cb(void *inst) +static struct packet *client_dbox_access_activate(pid_t pid, int handle, const struct packet *packet) { - struct pkg_info *pkg; - struct slave_node *slave; + struct packet *result; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + struct access_info event; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type); + if (ret != 6) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - if (!instance_del_data(inst, LAZY_GBAR_CLOSE_TAG)) { - ErrPrint("lazy,pd,close is already deleted.\n"); - return ECORE_CALLBACK_CANCEL; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - pkg = instance_package(inst); - if (pkg) { - slave = package_slave(pkg); - if (slave) { - if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - DbgPrint("Delete script type close callback\n"); - (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst); - } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - DbgPrint("Delete buffer type close callback\n"); - (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst); - } - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ErrPrint("Instance has no script\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (instance_unref(inst)) { - int ret; - - /*! - * If the instance is not deleted, we should send pd-destroy event from here. - */ - ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE); - if (ret < 0) { - ErrPrint("Failed sending GBAR Destroy event (%d)\n", ret); - } + script_handler_update_pointer(script, event.x, event.y, event.type); + ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp); + if (ret >= 0) { + ret = send_delayed_access_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return ECORE_CALLBACK_CANCEL; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_gbar_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */ +static struct packet *client_dbox_key_down(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - struct inst_info *inst; - const struct pkg_info *pkg; - const char *pkgname; - const char *id; - double x = 0.0f; - double y = 0.0f; - int ret; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y); - if (ret != 4) { - ErrPrint("Parameter is not correct\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - instance_slave_set_gbar_pos(inst, x, y); - ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0); - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - int ix; - int iy; - - instance_slave_set_gbar_pos(inst, x, y); - ix = x * instance_gbar_width(inst); - iy = y * instance_gbar_height(inst); - script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0); - ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0); - } else { - ErrPrint("Invalid GBAR type\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + out: - DbgPrint("Update GBAR position: %d\n", ret); - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static Eina_Bool gbar_open_monitor_cb(void *inst) +static struct packet *client_dbox_key_focus_in(pid_t pid, int handle, const struct packet *packet) { - struct pkg_info *pkg; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - pkg = instance_package(inst); - if (pkg) { - struct slave_node *slave; + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - slave = package_slave(pkg); - if (slave) { - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst); - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; + + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT); - (void)instance_client_gbar_created(inst, DBOX_STATUS_ERROR_TIMEOUT); - (void)instance_del_data(inst, GBAR_OPEN_MONITOR_TAG); - (void)instance_unref(inst); - ErrPrint("GBAR Open request is timed-out (%lf)\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT); - return ECORE_CALLBACK_CANCEL; + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); + } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static Eina_Bool gbar_close_monitor_cb(void *inst) +static struct packet *client_dbox_key_focus_out(pid_t pid, int handle, const struct packet *packet) { - struct pkg_info *pkg; - - pkg = instance_package(inst); - if (pkg) { - struct slave_node *slave; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - slave = package_slave(pkg); - if (slave) { - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst); - } - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT); - (void)instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG); - (void)instance_unref(inst); - ErrPrint("GBAR Close request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT); - return ECORE_CALLBACK_CANCEL; -} + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; -static Eina_Bool gbar_resize_monitor_cb(void *inst) -{ - struct pkg_info *pkg; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - pkg = instance_package(inst); - if (pkg) { - struct slave_node *slave; - slave = package_slave(pkg); - if (slave) { - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst); - } + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT); - (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT); - (void)instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG); - (void)instance_unref(inst); - ErrPrint("GBAR Resize request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT); - return ECORE_CALLBACK_CANCEL; +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } -static struct packet *client_create_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */ +static struct packet *client_dbox_key_up(pid_t pid, int handle, const struct packet *packet) { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - int ret; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - Ecore_Timer *gbar_monitor; - double x; - double y; + struct client_node *client; + const char *pkgname; + const char *id; + int ret; + double timestamp; + unsigned int keycode; + struct inst_info *inst; + const struct pkg_info *pkg; + struct packet *result; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - DbgPrint("PERF_DBOX\n"); + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode); + } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) { + struct script_info *script; - ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y); - if (ret != 4) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + script = instance_dbox_script(inst); + if (!script) { + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script_handler_update_keycode(script, keycode); + ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp); + if (ret >= 0) { + ret = send_delayed_key_status(inst, ret); } + } else { + ErrPrint("Unsupported package\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (instance_gbar_owner(inst)) { - ErrPrint("GBAR is already owned\n"); - ret = DBOX_STATUS_ERROR_ALREADY; - } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_BUFFER) { - gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG); - if (gbar_monitor) { - ecore_timer_del(gbar_monitor); - /* This timer attribute will be deleted */ - lazy_gbar_destroyed_cb(inst); - } - - if (instance_get_data(inst, GBAR_OPEN_MONITOR_TAG)) { - DbgPrint("GBAR Open request is already processed\n"); - ret = DBOX_STATUS_ERROR_ALREADY; - goto out; - } +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - if (instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) { - DbgPrint("GBAR Close request is already in process\n"); - ret = DBOX_STATUS_ERROR_BUSY; - goto out; - } + return result; +} - if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) { - DbgPrint("GBAR resize request is already in process\n"); - ret = DBOX_STATUS_ERROR_BUSY; - goto out; - } +static int release_pixmap_cb(struct client_node *client, void *canvas) +{ + DbgPrint("Forcely unref the \"buffer\"\n"); + buffer_handler_pixmap_unref(canvas); + return -1; /* Delete this callback */ +} - instance_slave_set_gbar_pos(inst, x, y); - /*! - * \note - * Send request to the slave. - * The SLAVE must has to repsonse this via "release_buffer" method. - */ - ret = instance_slave_open_gbar(inst, client); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - ret = instance_signal_emit(inst, "gbar,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0); - if (ret != DBOX_STATUS_ERROR_NONE) { - int tmp_ret; - - tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT); - if (tmp_ret < 0) { - ErrPrint("Unable to send script event for openning GBAR [%s], %d\n", pkgname, tmp_ret); - } - } else { - gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_open_monitor_cb, instance_ref(inst)); - if (!gbar_monitor) { - (void)instance_unref(inst); - ErrPrint("Failed to create a timer for GBAR Open monitor\n"); - } else { - struct slave_node *slave; - - (void)instance_set_data(inst, GBAR_OPEN_MONITOR_TAG, gbar_monitor); - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Failed to get slave(%s)\n", pkgname); - goto out; - } - - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to add fault handler: %s\n"); - } - } - } - } else { - ErrPrint("Unable to send request for openning GBAR [%s]\n", pkgname); - } - /*! - * \note - * GBAR craeted event will be send by the acquire_buffer function. - * Because the slave will make request the acquire_buffer to - * render the GBAR - * - * instance_client_gbar_created(inst); - */ - } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_SCRIPT) { - int ix; - int iy; - - gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG); - if (gbar_monitor) { - ecore_timer_del(gbar_monitor); - /* lazy,pd,close will be deleted */ - lazy_gbar_destroyed_cb(inst); - } +static struct packet *client_dbox_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +{ + struct packet *result; + const char *pkgname; + const char *id; + struct client_node *client; + struct inst_info *inst; + int ret; + int pixmap = 0; + void *buf_ptr; + struct buffer_info *buffer; + int idx; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - /*! - * \note - * ret value should be cared but in this case, - * we ignore this for this moment, so we have to handle this error later. - * - * if ret is less than 0, the slave has some problem. - * but the script mode doesn't need slave for rendering default view of GBAR - * so we can hanle it later. - */ - instance_slave_set_gbar_pos(inst, x, y); - ix = x * instance_gbar_width(inst); - iy = y * instance_gbar_height(inst); - - script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0); - - ret = instance_slave_open_gbar(inst, client); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - ret = script_handler_load(instance_gbar_script(inst), 1); - - /*! - * \note - * Send the GBAR created event to the clients, - */ - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - - /*! - * \note - * But the created event has to be send afte return - * from this function or the viewer couldn't care - * the event correctly. - */ - inst = instance_ref(inst); /* To guarantee the inst */ - - /*! - * \note - * At here, we don't need to rememeber the timer object. - * Even if the timer callback is called, after the instance is destroyed. - * lazy_gbar_created_cb will decrease the instance refcnt first. - * At that time, if the instance is released, the timer callback will do nothing. - * - * 13-05-28 - * I change my mind. There is no requirements to keep the timer handler. - * But I just add it to the tagged-data of the instance. - * Just reserve for future-use. - */ - gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_created_cb, inst); - if (!gbar_monitor) { - ret = script_handler_unload(instance_gbar_script(inst), 1); - ErrPrint("Unload script: %d\n", ret); - - ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); - ErrPrint("Close GBAR %d\n", ret); - - inst = instance_unref(inst); - if (!inst) { - DbgPrint("Instance destroyed\n"); - } - - ErrPrint("Instance: %s\n", pkgname); - - ret = DBOX_STATUS_ERROR_FAULT; - } else { - struct slave_node *slave; - - (void)instance_set_data(inst, LAZY_GBAR_OPEN_TAG, gbar_monitor); - - slave = package_slave(pkg); - if (!slave) { - ErrPrint("Failed to get slave: %s\n", pkgname); - goto out; - } - - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to add fault callback: %s\n", pkgname); - } - } - } else { - int tmp_ret; - tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT); - if (tmp_ret < 0) { - ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret); - } - } - } else { - ErrPrint("Unable open GBAR(%s): %d\n", pkgname, ret); - } - } else { - ErrPrint("Invalid GBAR TYPE\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ret = packet_get(packet, "ssi", &pkgname, &id, &idx); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) { + DbgPrint("Index is not valid: %d\n", idx); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + buffer = instance_dbox_extra_buffer(inst, idx); + if (!buffer) { + ErrPrint("Extra buffer for %d is not available\n", idx); + goto out; + } + + buf_ptr = buffer_handler_pixmap_ref(buffer); + if (!buf_ptr) { + ErrPrint("Failed to ref pixmap\n"); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); + if (ret < 0) { + ErrPrint("Failed to add a new client deactivate callback\n"); + buffer_handler_pixmap_unref(buf_ptr); + } else { + pixmap = buffer_handler_pixmap(buffer); + ret = DBOX_STATUS_ERROR_NONE; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "ii", pixmap, ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_destroy_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */ +static struct packet *client_dbox_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct client_node *client; - struct packet *result; - const char *pkgname; - const char *id; - int ret; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - Ecore_Timer *gbar_monitor; - struct slave_node *slave; + struct packet *result; + const char *pkgname; + const char *id; + struct client_node *client; + struct inst_info *inst; + int ret; + int pixmap = 0; + void *buf_ptr; + struct buffer_info *buffer; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - DbgPrint("PERF_DBOX\n"); + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + buffer = instance_dbox_buffer(inst); + if (!buffer) { + struct script_info *script_info; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + script_info = instance_dbox_script(inst); + if (!script_info) { + ErrPrint("Unable to get DBOX buffer: %s\n", id); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } - slave = package_slave(pkg); - if (!slave) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + buffer = script_handler_buffer_info(script_info); + if (!buffer) { + ErrPrint("Unable to get buffer_info: %s\n", id); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + } + + buf_ptr = buffer_handler_pixmap_ref(buffer); + if (!buf_ptr) { + ErrPrint("Failed to ref pixmap\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); + if (ret < 0) { + ErrPrint("Failed to add a new client deactivate callback\n"); + buffer_handler_pixmap_unref(buf_ptr); + } else { + pixmap = buffer_handler_pixmap(buffer); + ret = DBOX_STATUS_ERROR_NONE; + } - if (instance_gbar_owner(inst) != client) { - if (instance_gbar_owner(inst) == NULL) { - ErrPrint("GBAR looks already closed\n"); - ret = DBOX_STATUS_ERROR_ALREADY; - } else { - ErrPrint("GBAR owner mimatched\n"); - ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; - } - } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - DbgPrint("Buffer type GBAR\n"); - gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG); - if (gbar_monitor) { - ErrPrint("GBAR Open request is found. cancel it [%s]\n", pkgname); - - if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) < 0) { - DbgPrint("Failed to delete a deactivate callback\n"); - } - - /*! - * \note - * We should return negative value - * Or we have to send "destroyed" event to the client. - * If we didn't send destroyed event after return SUCCESS from here, - * The client will permanently waiting destroyed event. - * Because they understand that the destroy request is successfully processed. - */ - ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_CANCEL); - if (ret < 0) { - ErrPrint("GBAR client create event: %d\n", ret); - } - - ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE); - if (ret < 0) { - ErrPrint("GBAR client destroy event: %d\n", ret); - } - - ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0); - if (ret < 0) { - ErrPrint("GBAR close signal emit failed: %d\n", ret); - } - - ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); - if (ret < 0) { - ErrPrint("GBAR close request failed: %d\n", ret); - } - - ecore_timer_del(gbar_monitor); - inst = instance_unref(inst); - if (!inst) { - DbgPrint("Instance is deleted\n"); - } - } else if (instance_get_data(inst, LAZY_GBAR_CLOSE_TAG) || instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) { - DbgPrint("Close monitor is already fired\n"); - ret = DBOX_STATUS_ERROR_ALREADY; - } else { - int resize_aborted = 0; - - gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG); - if (gbar_monitor) { - ErrPrint("GBAR Resize request is found. clear it [%s]\n", pkgname); - if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) < 0) { - DbgPrint("Failed to delete a deactivate callback\n"); - } - - ecore_timer_del(gbar_monitor); - - inst = instance_unref(inst); - if (!inst) { - DbgPrint("Instance is destroyed while resizing\n"); - goto out; - } - - resize_aborted = 1; - } - - ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0); - if (ret < 0) { - ErrPrint("GBAR close signal emit failed: %d\n", ret); - } - - ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); - if (ret < 0) { - ErrPrint("GBAR close request failed: %d\n", ret); - } else if (resize_aborted) { - gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst)); - if (!gbar_monitor) { - ErrPrint("Failed to create a timer: %s\n", pkgname); - inst = instance_unref(inst); - if (!inst) { - DbgPrint("Instance is deleted\n"); - } - } else { - DbgPrint("Resize is aborted\n"); - (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor); - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) { - ErrPrint("Failed to add a slave event callback\n"); - } - } - } else { - gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_close_monitor_cb, instance_ref(inst)); - if (!gbar_monitor) { - ErrPrint("Failed to add pd close monitor\n"); - inst = instance_unref(inst); - if (!inst) { - ErrPrint("Instance is deleted while closing GBAR\n"); - } - } else { - DbgPrint("Add close monitor\n"); - (void)instance_set_data(inst, GBAR_CLOSE_MONITOR_TAG, gbar_monitor); - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) { - ErrPrint("Failed to add SLAVE EVENT callback\n"); - } - } - } - - /*! - * \note - * release_buffer will be called by the slave after this routine. - * It will send the "gbar_destroyed" event to the client - * - * instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE); - * - * Or the "gbar_close_monitor_cb" or "lazy_gbar_destroyed_cb" will be called. - */ - } - } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { - DbgPrint("Script TYPE GBAR\n"); - gbar_monitor = instance_get_data(inst, LAZY_GBAR_OPEN_TAG); - if (gbar_monitor) { - ecore_timer_del(gbar_monitor); - (void)lazy_gbar_created_cb(inst); - } +out: + result = packet_create_reply(packet, "ii", pixmap, ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - ret = script_handler_unload(instance_gbar_script(inst), 1); - if (ret < 0) { - ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret); - } + return result; +} - /*! - * \note - * Send request to the slave. - * The SLAVE must has to repsonse this via "release_buffer" method. - */ - ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); - if (ret < 0) { - ErrPrint("Unable to close the GBAR: %s, %d\n", pkgname, ret); - } +static struct packet *client_dbox_release_pixmap(pid_t pid, int handle, const struct packet *packet) +{ + const char *pkgname; + const char *id; + struct client_node *client; + int pixmap; + void *buf_ptr; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, NULL, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + DbgPrint("It seems that the instance is already deleted: %s\n", id); + } + + buf_ptr = buffer_handler_pixmap_find(pixmap); + if (!buf_ptr) { + ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap); + goto out; + } + + if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) { + buffer_handler_pixmap_unref(buf_ptr); + } - /*! - * \note - * Send the destroyed GBAR event to the client - */ - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - /*! - * \note - * 13-05-28 - * I've changed my mind. There is no requirements to keep the timer handler. - * But I just add it to the tagged-data of the instance. - * Just reserve for future-use. - */ - DbgPrint("Add lazy GBAR destroy timer\n"); - gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst)); - if (!gbar_monitor) { - ErrPrint("Failed to create a timer: %s\n", pkgname); - inst = instance_unref(inst); - if (!inst) { - DbgPrint("instance is deleted\n"); - } - } else { - (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor); - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst) < 0) { - ErrPrint("Failed to add a event callback for slave\n"); - } - } - } - } else { - ErrPrint("Invalid GBAR TYPE\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +out: + /** + * @note No reply packet + */ + return NULL; +} + +static struct packet *client_gbar_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ +{ + struct packet *result; + const char *pkgname; + const char *id; + struct client_node *client; + struct inst_info *inst; + int ret; + int pixmap = 0; + void *buf_ptr; + struct buffer_info *buffer; + int idx; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ErrPrint("Client %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &idx); + if (ret != 3) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ErrPrint("Parameter is not matched\n"); + goto out; + } + + if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + buffer = instance_gbar_extra_buffer(inst, idx); + if (!buffer) { + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + buf_ptr = buffer_handler_pixmap_ref(buffer); + if (!buf_ptr) { + ErrPrint("Failed to ref pixmap\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); + if (ret < 0) { + ErrPrint("Failed to add a new client deactivate callback\n"); + buffer_handler_pixmap_unref(buf_ptr); + } else { + pixmap = buffer_handler_pixmap(buffer); + ret = DBOX_STATUS_ERROR_NONE; + } out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "ii", pixmap, ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */ +static struct packet *client_gbar_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ { - struct client_node *client; - struct packet *result; - const char *pkgname; - int ret; - struct pkg_info *info; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - pkgname = ""; - goto out; - } + struct packet *result; + const char *pkgname; + const char *id; + struct client_node *client; + struct inst_info *inst; + int ret; + int pixmap = 0; + void *buf_ptr; + struct buffer_info *buffer; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ErrPrint("Client %d is not exists\n", pid); + goto out; + } - ret = packet_get(packet, "s", &pkgname); - if (ret != 1) { - ErrPrint("Parameter is not matched\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - pkgname = ""; - goto out; - } + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ErrPrint("Parameter is not matched\n"); + goto out; + } - DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname); + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - /*! - * \NOTE: - * Validate the dynamicbox package name. - */ - if (!package_is_dbox_pkgname(pkgname)) { - ErrPrint("%s is not a valid dynamicbox package\n", pkgname); - pkgname = ""; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) { + ret = DBOX_STATUS_ERROR_BUSY; + goto out; + } - info = package_find(pkgname); - if (!info) { - ret = DBOX_STATUS_ERROR_NOT_EXIST; - } else { - ret = package_clear_fault(info); + buffer = instance_gbar_buffer(inst); + if (!buffer) { + struct script_info *script_info; + + script_info = instance_gbar_script(inst); + if (!script_info) { + ErrPrint("Unable to get DBOX buffer: %s\n", id); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } + buffer = script_handler_buffer_info(script_info); + if (!buffer) { + ErrPrint("Unable to get buffer_info: %s\n", id); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + } + + buf_ptr = buffer_handler_pixmap_ref(buffer); + if (!buf_ptr) { + ErrPrint("Failed to ref pixmap\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + + ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr); + if (ret < 0) { + ErrPrint("Failed to add a new client deactivate callback\n"); + buffer_handler_pixmap_unref(buf_ptr); + } else { + pixmap = buffer_handler_pixmap(buffer); + ret = DBOX_STATUS_ERROR_NONE; + } + out: - result = packet_create_reply(packet, "is", ret, pkgname); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "ii", pixmap, ret); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } -static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_gbar_release_pixmap(pid_t pid, int handle, const struct packet *packet) { - const char *cluster; - const char *category; - struct client_node *client; - int ret; - - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + const char *pkgname; + const char *id; + struct client_node *client; + int pixmap; + void *buf_ptr; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, NULL, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + DbgPrint("It seems that the instance is already deleted: %s\n", id); + } + + buf_ptr = buffer_handler_pixmap_find(pixmap); + if (!buf_ptr) { + ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap); + goto out; + } + + if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) { + buffer_handler_pixmap_unref(buf_ptr); + } - ret = packet_get(packet, "ss", &cluster, &category); - if (ret != 2) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } +out: + /*! \note No reply packet */ + return NULL; +} - DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category); - if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { - ErrPrint("Invalid cluster name\n"); - goto out; - } +static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */ +{ + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + int pinup; + int ret; + struct inst_info *inst; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + pinup = 0; + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &pinup); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + pinup = 0; + goto out; + } - /*! - * \todo - * SUBSCRIBE cluster & sub-cluster for a client. - */ - ret = client_subscribe(client, cluster, category); - if (ret == 0) { - package_alter_instances_to_client(client, ALTER_CREATE); - } + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + ret = instance_set_pinup(inst, pinup); + } out: - /*! \note No reply packet */ - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } + + return result; } -static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet) +static Eina_Bool lazy_gbar_created_cb(void *inst) { - const char *cluster; - struct client_node *client; - struct packet *result; - int ret; + struct pkg_info *pkg; - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; + if (!instance_del_data(inst, LAZY_GBAR_OPEN_TAG)) { + ErrPrint("lazy,pd,open is already deleted.\n"); + return ECORE_CALLBACK_CANCEL; + } + + pkg = instance_package(inst); + if (pkg) { + struct slave_node *slave; + + slave = package_slave(pkg); + if (slave) { + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst); } + } - ret = packet_get(packet, "s", &cluster); - if (ret != 1) { - ErrPrint("Invalid parameters\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + /*! + * After unref instance first, + * if the instance is not destroyed, try to notify the created GBAR event to the client. + */ + if (instance_unref(inst)) { + int ret; + ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_NONE); + if (ret < 0) { + DbgPrint("Send GBAR Create event (%d) to client\n", ret); } + } - DbgPrint("pid[%d] cluster[%s]\n", pid, cluster); + return ECORE_CALLBACK_CANCEL; +} - if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { - ErrPrint("Invalid cluster: %s\n", cluster); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } +static Eina_Bool lazy_gbar_destroyed_cb(void *inst) +{ + struct pkg_info *pkg; + struct slave_node *slave; + + if (!instance_del_data(inst, LAZY_GBAR_CLOSE_TAG)) { + ErrPrint("lazy,pd,close is already deleted.\n"); + return ECORE_CALLBACK_CANCEL; + } + + pkg = instance_package(inst); + if (pkg) { + slave = package_slave(pkg); + if (slave) { + if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + DbgPrint("Delete script type close callback\n"); + (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst); + } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + DbgPrint("Delete buffer type close callback\n"); + (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst); + } + } + } + + if (instance_unref(inst)) { + int ret; /*! - * \todo + * If the instance is not deleted, we should send pd-destroy event from here. */ - ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED; - -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); + ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE); + if (ret < 0) { + ErrPrint("Failed sending GBAR Destroy event (%d)\n", ret); } + } - return result; + return ECORE_CALLBACK_CANCEL; } -static inline int update_pkg_cb(struct category *category, const char *pkgname, int force) +static struct packet *client_gbar_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */ { - const char *c_name; - const char *s_name; - - c_name = group_cluster_name_by_category(category); - s_name = group_category_name(category); - - if (!c_name || !s_name || !pkgname) { - ErrPrint("Name is not valid\n"); - return EXIT_FAILURE; - } + struct client_node *client; + struct inst_info *inst; + const struct pkg_info *pkg; + const char *pkgname; + const char *id; + double x = 0.0f; + double y = 0.0f; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y); + if (ret != 4) { + ErrPrint("Parameter is not correct\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + instance_slave_set_gbar_pos(inst, x, y); + ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0); + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + int ix; + int iy; + + instance_slave_set_gbar_pos(inst, x, y); + ix = x * instance_gbar_width(inst); + iy = y * instance_gbar_height(inst); + script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0); + ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0); + } else { + ErrPrint("Invalid GBAR type\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } +out: + DbgPrint("Update GBAR position: %d\n", ret); + return NULL; +} - DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name); - slave_rpc_request_update(pkgname, "", c_name, s_name, NULL, force); +static Eina_Bool gbar_open_monitor_cb(void *inst) +{ + struct pkg_info *pkg; - /* Just try to create a new package */ - if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) > DYNAMICBOX_CONF_MINIMUM_SPACE) { - double timestamp; - struct inst_info *inst; + pkg = instance_package(inst); + if (pkg) { + struct slave_node *slave; - timestamp = util_timestamp(); - /*! - * \NOTE - * Don't need to check the subscribed clients. - * Because this callback is called by the requests of clients. - * It means. some clients wants to handle this instances ;) - */ - inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DYNAMICBOX_CONF_DEFAULT_PERIOD, 0, 0); - if (!inst) { - ErrPrint("Failed to create a new instance\n"); - } + slave = package_slave(pkg); + if (slave) { + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst); } + } - return EXIT_SUCCESS; + (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT); + (void)instance_client_gbar_created(inst, DBOX_STATUS_ERROR_TIMEOUT); + (void)instance_del_data(inst, GBAR_OPEN_MONITOR_TAG); + (void)instance_unref(inst); + ErrPrint("GBAR Open request is timed-out (%lf)\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT); + return ECORE_CALLBACK_CANCEL; } -static struct packet *client_update(pid_t pid, int handle, const struct packet *packet) +static Eina_Bool gbar_close_monitor_cb(void *inst) { - struct inst_info *inst; - struct client_node *client; - const char *pkgname; - const char *id; - int force; - int ret; + struct pkg_info *pkg; - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Cilent %d is not exists\n", pid); - goto out; - } + pkg = instance_package(inst); + if (pkg) { + struct slave_node *slave; - ret = packet_get(packet, "ssi", &pkgname, &id, &force); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - goto out; + slave = package_slave(pkg); + if (slave) { + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst); } + } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT); + (void)instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG); + (void)instance_unref(inst); + ErrPrint("GBAR Close request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT); + return ECORE_CALLBACK_CANCEL; +} - if (instance_client(inst) != client) { - /* PERMISSIONS */ - ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid); - } else { - slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst), NULL, force); +static Eina_Bool gbar_resize_monitor_cb(void *inst) +{ + struct pkg_info *pkg; + + pkg = instance_package(inst); + if (pkg) { + struct slave_node *slave; + slave = package_slave(pkg); + if (slave) { + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst); } + } -out: - /*! \note No reply packet */ - return NULL; + (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT); + (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT); + (void)instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG); + (void)instance_unref(inst); + ErrPrint("GBAR Resize request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT); + return ECORE_CALLBACK_CANCEL; } -static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_create_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */ { - const char *cluster_id; - const char *category_id; - struct client_node *client; - int ret; - struct cluster *cluster; - struct category *category; - struct context_info *info; - Eina_List *info_list; - Eina_List *l; - int force; + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + int ret; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + Ecore_Timer *gbar_monitor; + double x; + double y; + + DbgPrint("PERF_DBOX\n"); + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y); + if (ret != 4) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Cilent %d is not exists\n", pid); - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = packet_get(packet, "ssi", &cluster_id, &category_id, &force); - if (ret != 3) { - ErrPrint("Invalid parameter\n"); - goto out; + if (instance_gbar_owner(inst)) { + ErrPrint("GBAR is already owned\n"); + ret = DBOX_STATUS_ERROR_ALREADY; + } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_BUFFER) { + gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG); + if (gbar_monitor) { + ecore_timer_del(gbar_monitor); + /* This timer attribute will be deleted */ + lazy_gbar_destroyed_cb(inst); } - DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id); - - if (!strlen(cluster_id) || !strcasecmp(cluster_id, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { - ErrPrint("Invalid cluster name: %s\n", cluster_id); - goto out; + if (instance_get_data(inst, GBAR_OPEN_MONITOR_TAG)) { + DbgPrint("GBAR Open request is already processed\n"); + ret = DBOX_STATUS_ERROR_ALREADY; + goto out; } - cluster = group_find_cluster(cluster_id); - if (!cluster) { - ErrPrint("Cluster [%s] is not registered\n", cluster_id); - goto out; + if (instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) { + DbgPrint("GBAR Close request is already in process\n"); + ret = DBOX_STATUS_ERROR_BUSY; + goto out; } - category = group_find_category(cluster, category_id); - if (!category) { - ErrPrint("Category [%s] is not registered\n", category_id); - goto out; + if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) { + DbgPrint("GBAR resize request is already in process\n"); + ret = DBOX_STATUS_ERROR_BUSY; + goto out; } - info_list = group_context_info_list(category); - EINA_LIST_FOREACH(info_list, l, info) { - update_pkg_cb(category, group_pkgname_from_context_info(info), force); - } + instance_slave_set_gbar_pos(inst, x, y); + /*! + * \note + * Send request to the slave. + * The SLAVE must has to repsonse this via "release_buffer" method. + */ + ret = instance_slave_open_gbar(inst, client); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + ret = instance_signal_emit(inst, "gbar,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0); + if (ret != DBOX_STATUS_ERROR_NONE) { + int tmp_ret; -out: - /*! \note No reply packet */ - return NULL; -} + tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT); + if (tmp_ret < 0) { + ErrPrint("Unable to send script event for openning GBAR [%s], %d\n", pkgname, tmp_ret); + } + } else { + gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_open_monitor_cb, instance_ref(inst)); + if (!gbar_monitor) { + (void)instance_unref(inst); + ErrPrint("Failed to create a timer for GBAR Open monitor\n"); + } else { + struct slave_node *slave; -static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet) -{ - const char *cluster; - const char *category; - struct client_node *client; - struct packet *result; - int ret; + (void)instance_set_data(inst, GBAR_OPEN_MONITOR_TAG, gbar_monitor); - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Failed to get slave(%s)\n", pkgname); + goto out; + } - ret = packet_get(packet, "ss", &cluster, &category); - if (ret != 2) { - ErrPrint("Invalid paramenters\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to add fault handler: %s\n"); + } + } + } + } else { + ErrPrint("Unable to send request for openning GBAR [%s]\n", pkgname); } - DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category); - if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { - ErrPrint("Invalid cluster: %s\n", cluster); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + /*! + * \note + * GBAR craeted event will be send by the acquire_buffer function. + * Because the slave will make request the acquire_buffer to + * render the GBAR + * + * instance_client_gbar_created(inst); + */ + } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_SCRIPT) { + int ix; + int iy; + + gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG); + if (gbar_monitor) { + ecore_timer_del(gbar_monitor); + /* lazy,pd,close will be deleted */ + lazy_gbar_destroyed_cb(inst); } /*! - * \todo + * \note + * ret value should be cared but in this case, + * we ignore this for this moment, so we have to handle this error later. + * + * if ret is less than 0, the slave has some problem. + * but the script mode doesn't need slave for rendering default view of GBAR + * so we can hanle it later. */ - ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED; + instance_slave_set_gbar_pos(inst, x, y); + ix = x * instance_gbar_width(inst); + iy = y * instance_gbar_height(inst); -out: - result = packet_create_reply(packet, "i", ret); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0); - return result; -} + ret = instance_slave_open_gbar(inst, client); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + ret = script_handler_load(instance_gbar_script(inst), 1); -static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet) -{ - const char *cluster; - const char *category; - struct client_node *client; - int ret; + /*! + * \note + * Send the GBAR created event to the clients, + */ + if (ret == (int)DBOX_STATUS_ERROR_NONE) { - client = client_find_by_rpc_handle(handle); - if (!client) { - ErrPrint("Client %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + /*! + * \note + * But the created event has to be send afte return + * from this function or the viewer couldn't care + * the event correctly. + */ + inst = instance_ref(inst); /* To guarantee the inst */ - ret = packet_get(packet, "ss", &cluster, &category); - if (ret != 2) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + /*! + * \note + * At here, we don't need to rememeber the timer object. + * Even if the timer callback is called, after the instance is destroyed. + * lazy_gbar_created_cb will decrease the instance refcnt first. + * At that time, if the instance is released, the timer callback will do nothing. + * + * 13-05-28 + * I change my mind. There is no requirements to keep the timer handler. + * But I just add it to the tagged-data of the instance. + * Just reserve for future-use. + */ + gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_created_cb, inst); + if (!gbar_monitor) { + ret = script_handler_unload(instance_gbar_script(inst), 1); + ErrPrint("Unload script: %d\n", ret); - DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category); + ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); + ErrPrint("Close GBAR %d\n", ret); - if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { - ErrPrint("Invalid cluster name: %s\n", cluster); - goto out; - } + inst = instance_unref(inst); + if (!inst) { + DbgPrint("Instance destroyed\n"); + } - /*! - * \todo - * UNSUBSCRIBE cluster & sub-cluster for a client. - */ - ret = client_unsubscribe(client, cluster, category); - if (ret == 0) { - package_alter_instances_to_client(client, ALTER_DESTROY); + ErrPrint("Instance: %s\n", pkgname); + + ret = DBOX_STATUS_ERROR_FAULT; + } else { + struct slave_node *slave; + + (void)instance_set_data(inst, LAZY_GBAR_OPEN_TAG, gbar_monitor); + + slave = package_slave(pkg); + if (!slave) { + ErrPrint("Failed to get slave: %s\n", pkgname); + goto out; + } + + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to add fault callback: %s\n", pkgname); + } + } + } else { + int tmp_ret; + tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT); + if (tmp_ret < 0) { + ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret); + } + } + } else { + ErrPrint("Unable open GBAR(%s): %d\n", pkgname, ret); } + } else { + ErrPrint("Invalid GBAR TYPE\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - /*! \note No reply packet */ - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } + + return result; } -static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */ +static struct packet *client_destroy_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */ { - struct slave_node *slave; - const char *slavename; - int ret; - - ret = packet_get(packet, "s", &slavename); - if (ret != 1) { - ErrPrint("Parameter is not matched\n"); - goto out; - } + struct client_node *client; + struct packet *result; + const char *pkgname; + const char *id; + int ret; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + Ecore_Timer *gbar_monitor; + struct slave_node *slave; + + DbgPrint("PERF_DBOX\n"); + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid); + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - slave = slave_find_by_name(slavename); + slave = package_slave(pkg); + if (!slave) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - if (!slave) { /* Try again to find a slave using pid */ - slave = slave_find_by_pid(pid); - } + if (instance_gbar_owner(inst) != client) { + if (instance_gbar_owner(inst) == NULL) { + ErrPrint("GBAR looks already closed\n"); + ret = DBOX_STATUS_ERROR_ALREADY; + } else { + ErrPrint("GBAR owner mimatched\n"); + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + } + } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + DbgPrint("Buffer type GBAR\n"); + gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG); + if (gbar_monitor) { + ErrPrint("GBAR Open request is found. cancel it [%s]\n", pkgname); + + if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) < 0) { + DbgPrint("Failed to delete a deactivate callback\n"); + } + + /*! + * \note + * We should return negative value + * Or we have to send "destroyed" event to the client. + * If we didn't send destroyed event after return SUCCESS from here, + * The client will permanently waiting destroyed event. + * Because they understand that the destroy request is successfully processed. + */ + ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_CANCEL); + if (ret < 0) { + ErrPrint("GBAR client create event: %d\n", ret); + } + + ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE); + if (ret < 0) { + ErrPrint("GBAR client destroy event: %d\n", ret); + } + + ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0); + if (ret < 0) { + ErrPrint("GBAR close signal emit failed: %d\n", ret); + } + + ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); + if (ret < 0) { + ErrPrint("GBAR close request failed: %d\n", ret); + } + + ecore_timer_del(gbar_monitor); + inst = instance_unref(inst); + if (!inst) { + DbgPrint("Instance is deleted\n"); + } + } else if (instance_get_data(inst, LAZY_GBAR_CLOSE_TAG) || instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) { + DbgPrint("Close monitor is already fired\n"); + ret = DBOX_STATUS_ERROR_ALREADY; + } else { + int resize_aborted = 0; - if (!slave) { - if (DYNAMICBOX_CONF_DEBUG_MODE || g_conf.debug_mode) { - char pkgname[pathconf("/", _PC_PATH_MAX)]; - const char *abi; - - if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) { - ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename); - slave = slave_find_by_name(slavename); - pkgname[0] = '\0'; /* Reset the pkgname */ - } else { - slave = slave_find_by_pkgname(pkgname); - } - - if (!slave) { - abi = abi_find_by_pkgname(pkgname); - if (!abi) { - abi = DYNAMICBOX_CONF_DEFAULT_ABI; - DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi); - } - - slave = slave_create(slavename, 1, abi, pkgname, 0); - if (!slave) { - ErrPrint("Failed to create a new slave for %s\n", slavename); - goto out; - } - - DbgPrint("New slave is created (net: 0)\n"); - } else { - DbgPrint("Registered slave is replaced with this new one\n"); - abi = slave_abi(slave); - if (!abi) { - ErrPrint("ABI is not valid: %s\n", slavename); - abi = DYNAMICBOX_CONF_DEFAULT_ABI; - } - } - - slave_set_pid(slave, pid); - DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename); - } else { - ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename); - goto out; + gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG); + if (gbar_monitor) { + ErrPrint("GBAR Resize request is found. clear it [%s]\n", pkgname); + if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) < 0) { + DbgPrint("Failed to delete a deactivate callback\n"); } - } else { - if (slave_pid(slave) != pid) { - if (slave_pid(slave) > 0) { - CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave)); - if (pid > 0) { - ret = aul_terminate_pid(pid); - CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret); - } - goto out; - } - CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid); - slave_set_pid(slave, pid); + + ecore_timer_del(gbar_monitor); + + inst = instance_unref(inst); + if (!inst) { + DbgPrint("Instance is destroyed while resizing\n"); + goto out; } + + resize_aborted = 1; + } + + ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0); + if (ret < 0) { + ErrPrint("GBAR close signal emit failed: %d\n", ret); + } + + ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); + if (ret < 0) { + ErrPrint("GBAR close request failed: %d\n", ret); + } else if (resize_aborted) { + gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst)); + if (!gbar_monitor) { + ErrPrint("Failed to create a timer: %s\n", pkgname); + inst = instance_unref(inst); + if (!inst) { + DbgPrint("Instance is deleted\n"); + } + } else { + DbgPrint("Resize is aborted\n"); + (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor); + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) { + ErrPrint("Failed to add a slave event callback\n"); + } + } + } else { + gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_close_monitor_cb, instance_ref(inst)); + if (!gbar_monitor) { + ErrPrint("Failed to add pd close monitor\n"); + inst = instance_unref(inst); + if (!inst) { + ErrPrint("Instance is deleted while closing GBAR\n"); + } + } else { + DbgPrint("Add close monitor\n"); + (void)instance_set_data(inst, GBAR_CLOSE_MONITOR_TAG, gbar_monitor); + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) { + ErrPrint("Failed to add SLAVE EVENT callback\n"); + } + } + } + + /*! + * \note + * release_buffer will be called by the slave after this routine. + * It will send the "gbar_destroyed" event to the client + * + * instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE); + * + * Or the "gbar_close_monitor_cb" or "lazy_gbar_destroyed_cb" will be called. + */ + } + } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) { + DbgPrint("Script TYPE GBAR\n"); + gbar_monitor = instance_get_data(inst, LAZY_GBAR_OPEN_TAG); + if (gbar_monitor) { + ecore_timer_del(gbar_monitor); + (void)lazy_gbar_created_cb(inst); + } + + ret = script_handler_unload(instance_gbar_script(inst), 1); + if (ret < 0) { + ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret); + } + + /*! + * \note + * Send request to the slave. + * The SLAVE must has to repsonse this via "release_buffer" method. + */ + ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL); + if (ret < 0) { + ErrPrint("Unable to close the GBAR: %s, %d\n", pkgname, ret); } /*! * \note - * After updating handle, - * slave activated callback will be called. + * Send the destroyed GBAR event to the client */ - slave_rpc_update_handle(slave, handle); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + /*! + * \note + * 13-05-28 + * I've changed my mind. There is no requirements to keep the timer handler. + * But I just add it to the tagged-data of the instance. + * Just reserve for future-use. + */ + DbgPrint("Add lazy GBAR destroy timer\n"); + gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst)); + if (!gbar_monitor) { + ErrPrint("Failed to create a timer: %s\n", pkgname); + inst = instance_unref(inst); + if (!inst) { + DbgPrint("instance is deleted\n"); + } + } else { + (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor); + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst) < 0) { + ErrPrint("Failed to add a event callback for slave\n"); + } + } + } + } else { + ErrPrint("Invalid GBAR TYPE\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } + + return result; } -static struct packet *slave_ctrl(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */ { - struct slave_node *slave; - int ctrl; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + struct client_node *client; + struct packet *result; + const char *pkgname; + int ret; + struct pkg_info *info; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + pkgname = ""; + goto out; + } + + ret = packet_get(packet, "s", &pkgname); + if (ret != 1) { + ErrPrint("Parameter is not matched\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + pkgname = ""; + goto out; + } + + DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname); + + /*! + * \NOTE: + * Validate the dynamicbox package name. + */ + if (!package_is_dbox_pkgname(pkgname)) { + ErrPrint("%s is not a valid dynamicbox package\n", pkgname); + pkgname = ""; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "i", &ctrl); - if (ret != 1) { - ErrPrint("Parameter is not matched\n"); - } else { - slave_set_control_option(slave, ctrl); - } + info = package_find(pkgname); + if (!info) { + ret = DBOX_STATUS_ERROR_NOT_EXIST; + } else { + ret = package_clear_fault(info); + } out: - return NULL; + result = packet_create_reply(packet, "is", ret, pkgname); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } + + return result; } -static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */ +static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - const char *slavename; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "s", &slavename); - if (ret != 1) { - ErrPrint("Parameter is not matched\n"); - } else { - slave_rpc_ping(slave); - } + const char *cluster; + const char *category; + struct client_node *client; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ss", &cluster, &category); + if (ret != 2) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category); + if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { + ErrPrint("Invalid cluster name\n"); + goto out; + } + + /*! + * \todo + * SUBSCRIBE cluster & sub-cluster for a client. + */ + ret = client_subscribe(client, cluster, category); + if (ret == 0) { + package_alter_instances_to_client(client, ALTER_CREATE); + } out: - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct pkg_info *pkg; - const char *pkgname; - const char *id; - const char *func; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + const char *cluster; + struct client_node *client; + struct packet *result; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "s", &cluster); + if (ret != 1) { + ErrPrint("Invalid parameters\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "sss", &pkgname, &id, &func); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - goto out; - } + DbgPrint("pid[%d] cluster[%s]\n", pid, cluster); - ret = fault_info_set(slave, pkgname, id, func); - DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret); + if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { + ErrPrint("Invalid cluster: %s\n", cluster); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - pkg = package_find(pkgname); - if (!pkg) { - ErrPrint("There is no package info found: %s\n", pkgname); - } else { - package_faulted(pkg, 0); - } + /*! + * \todo + */ + ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED; out: - return NULL; + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } + + return result; } -static struct packet *slave_dbox_update_begin(pid_t pid, int handle, const struct packet *packet) +static inline int update_pkg_cb(struct category *category, const char *pkgname, int force) { - struct slave_node *slave; + const char *c_name; + const char *s_name; + + c_name = group_cluster_name_by_category(category); + s_name = group_category_name(category); + + if (!c_name || !s_name || !pkgname) { + ErrPrint("Name is not valid\n"); + return EXIT_FAILURE; + } + + DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name); + slave_rpc_request_update(pkgname, "", c_name, s_name, NULL, force); + + /* Just try to create a new package */ + if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) > DYNAMICBOX_CONF_MINIMUM_SPACE) { + double timestamp; struct inst_info *inst; - const struct pkg_info *pkg; - const char *pkgname; - const char *id; - double priority; - const char *content; - const char *title; - int ret; - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; + timestamp = util_timestamp(); + /*! + * \NOTE + * Don't need to check the subscribed clients. + * Because this callback is called by the requests of clients. + * It means. some clients wants to handle this instances ;) + */ + inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DYNAMICBOX_CONF_DEFAULT_PERIOD, 0, 0); + if (!inst) { + ErrPrint("Failed to create a new instance\n"); } + } - ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title); - if (ret != 5) { - ErrPrint("Invalid parameters\n"); - goto out; - } + return EXIT_SUCCESS; +} - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } +static struct packet *client_update(pid_t pid, int handle, const struct packet *packet) +{ + struct inst_info *inst; + struct client_node *client; + const char *pkgname; + const char *id; + int force; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Cilent %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &force); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_client(inst) != client) { + /* PERMISSIONS */ + ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid); + } else { + slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst), NULL, force); + } - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; - } +out: + /*! \note No reply packet */ + return NULL; +} - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = instance_dbox_update_begin(inst, priority, content, title); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - slave_freeze_ttl(slave); - } - } else { - ErrPrint("Invalid request[%s]\n", id); - } +static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet) +{ + const char *cluster_id; + const char *category_id; + struct client_node *client; + int ret; + struct cluster *cluster; + struct category *category; + struct context_info *info; + Eina_List *info_list; + Eina_List *l; + int force; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Cilent %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &cluster_id, &category_id, &force); + if (ret != 3) { + ErrPrint("Invalid parameter\n"); + goto out; + } + + DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id); + + if (!strlen(cluster_id) || !strcasecmp(cluster_id, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { + ErrPrint("Invalid cluster name: %s\n", cluster_id); + goto out; + } + + cluster = group_find_cluster(cluster_id); + if (!cluster) { + ErrPrint("Cluster [%s] is not registered\n", cluster_id); + goto out; + } + + category = group_find_category(cluster, category_id); + if (!category) { + ErrPrint("Category [%s] is not registered\n", category_id); + goto out; + } + + info_list = group_context_info_list(category); + EINA_LIST_FOREACH(info_list, l, info) { + update_pkg_cb(category, group_pkgname_from_context_info(info), force); + } out: - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *slave_dbox_update_end(pid_t pid, int handle, const struct packet *packet) +static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct inst_info *inst; - const struct pkg_info *pkg; - const char *pkgname; - const char *id; - int ret; + const char *cluster; + const char *category; + struct client_node *client; + struct packet *result; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ss", &cluster, &category); + if (ret != 2) { + ErrPrint("Invalid paramenters\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category); + if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { + ErrPrint("Invalid cluster: %s\n", cluster); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Invalid parameters\n"); - goto out; - } + /*! + * \todo + */ + ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED; - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } +out: + result = packet_create_reply(packet, "i", ret); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; - } + return result; +} - if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - ret = instance_dbox_update_end(inst); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - slave_thaw_ttl(slave); - } - } else { - ErrPrint("Invalid request[%s]\n", id); - } +static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet) +{ + const char *cluster; + const char *category; + struct client_node *client; + int ret; + + client = client_find_by_rpc_handle(handle); + if (!client) { + ErrPrint("Client %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + ret = packet_get(packet, "ss", &cluster, &category); + if (ret != 2) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category); + + if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) { + ErrPrint("Invalid cluster name: %s\n", cluster); + goto out; + } + + /*! + * \todo + * UNSUBSCRIBE cluster & sub-cluster for a client. + */ + ret = client_unsubscribe(client, cluster, category); + if (ret == 0) { + package_alter_instances_to_client(client, ALTER_DESTROY); + } out: - return NULL; + /*! \note No reply packet */ + return NULL; } -static struct packet *slave_gbar_update_begin(pid_t pid, int handle, const struct packet *packet) +static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */ { - struct slave_node *slave; - const struct pkg_info *pkg; - struct inst_info *inst; - const char *pkgname; - const char *id; - int ret; + struct slave_node *slave; + const char *slavename; + int ret; - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + ret = packet_get(packet, "s", &slavename); + if (ret != 1) { + ErrPrint("Parameter is not matched\n"); + goto out; + } - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Invalid parameters\n"); - goto out; - } + DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid); - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + slave = slave_find_by_name(slavename); - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + if (!slave) { /* Try again to find a slave using pid */ + slave = slave_find_by_pid(pid); + } + + if (!slave) { + if (DYNAMICBOX_CONF_DEBUG_MODE || g_conf.debug_mode) { + char pkgname[pathconf("/", _PC_PATH_MAX)]; + const char *abi; + + if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) { + ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename); + slave = slave_find_by_name(slavename); + pkgname[0] = '\0'; /* Reset the pkgname */ + } else { + slave = slave_find_by_pkgname(pkgname); + } + + if (!slave) { + abi = abi_find_by_pkgname(pkgname); + if (!abi) { + abi = DYNAMICBOX_CONF_DEFAULT_ABI; + DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi); + } + + slave = slave_create(slavename, 1, abi, pkgname, 0); + if (!slave) { + ErrPrint("Failed to create a new slave for %s\n", slavename); + goto out; + } + + DbgPrint("New slave is created (net: 0)\n"); + } else { + DbgPrint("Registered slave is replaced with this new one\n"); + abi = slave_abi(slave); + if (!abi) { + ErrPrint("ABI is not valid: %s\n", slavename); + abi = DYNAMICBOX_CONF_DEFAULT_ABI; + } + } + + slave_set_pid(slave, pid); + DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename); + } else { + ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename); + goto out; + } + } else { + if (slave_pid(slave) != pid) { + if (slave_pid(slave) > 0) { + CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave)); + if (pid > 0) { + ret = aul_terminate_pid(pid); + CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret); + } goto out; + } + CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid); + slave_set_pid(slave, pid); } + } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - (void)instance_gbar_update_begin(inst); - } else { - ErrPrint("Invalid request[%s]\n", id); - } + /*! + * \note + * After updating handle, + * slave activated callback will be called. + */ + slave_rpc_update_handle(slave, handle); out: - return NULL; + return NULL; } -static struct packet *slave_key_status(pid_t pid, int handle, const struct packet *packet) +static struct packet *slave_ctrl(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct inst_info *inst; - const char *pkgname; - const char *id; - int status; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + struct slave_node *slave; + int ctrl; + int ret; - ret = packet_get(packet, "ssi", &pkgname, &id, &status); - if (ret != 3) { - ErrPrint("Invalid parameters\n"); - goto out; - } + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - } else { - (void)instance_forward_packet(inst, packet_ref((struct packet *)packet)); - } - } + ret = packet_get(packet, "i", &ctrl); + if (ret != 1) { + ErrPrint("Parameter is not matched\n"); + } else { + slave_set_control_option(slave, ctrl); + } out: - return NULL; + return NULL; } -static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet) +static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */ { - struct slave_node *slave; - struct inst_info *inst; - const char *pkgname; - const char *id; - int status; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + struct slave_node *slave; + const char *slavename; + int ret; - ret = packet_get(packet, "ssi", &pkgname, &id, &status); - if (ret != 3) { - ErrPrint("Invalid parameters\n"); - goto out; - } + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - } else { - (void)instance_forward_packet(inst, packet_ref((struct packet *)packet)); - } - } + ret = packet_get(packet, "s", &slavename); + if (ret != 1) { + ErrPrint("Parameter is not matched\n"); + } else { + slave_rpc_ping(slave); + } out: - return NULL; + return NULL; } -static struct packet *slave_close_gbar(pid_t pid, int handle, const struct packet *packet) +static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct inst_info *inst; - const char *pkgname; - const char *id; - int status; - int ret; + struct slave_node *slave; + struct pkg_info *pkg; + const char *pkgname; + const char *id; + const char *func; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "sss", &pkgname, &id, &func); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = fault_info_set(slave, pkgname, id, func); + DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret); + + pkg = package_find(pkgname); + if (!pkg) { + ErrPrint("There is no package info found: %s\n", pkgname); + } else { + package_faulted(pkg, 0); + } - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } +out: + return NULL; +} - ret = packet_get(packet, "ssi", &pkgname, &id, &status); - if (ret != 3) { - ErrPrint("Invalid parameters\n"); - goto out; +static struct packet *slave_dbox_update_begin(pid_t pid, int handle, const struct packet *packet) +{ + struct slave_node *slave; + struct inst_info *inst; + const struct pkg_info *pkg; + const char *pkgname; + const char *id; + double priority; + const char *content; + const char *title; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title); + if (ret != 5) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = instance_dbox_update_begin(inst, priority, content, title); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + slave_freeze_ttl(slave); } + } else { + ErrPrint("Invalid request[%s]\n", id); + } + +out: + return NULL; +} - ret = validate_request(pkgname, id, &inst, NULL); +static struct packet *slave_dbox_update_end(pid_t pid, int handle, const struct packet *packet) +{ + struct slave_node *slave; + struct inst_info *inst; + const struct pkg_info *pkg; + const char *pkgname; + const char *id; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + ret = instance_dbox_update_end(inst); if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - } else { - (void)instance_forward_packet(inst, packet_ref((struct packet *)packet)); - } + slave_thaw_ttl(slave); } + } else { + ErrPrint("Invalid request[%s]\n", id); + } out: - return NULL; + return NULL; } -static struct packet *slave_gbar_update_end(pid_t pid, int handle, const struct packet *packet) +static struct packet *slave_gbar_update_begin(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - const struct pkg_info *pkg; - struct inst_info *inst; - const char *pkgname; - const char *id; - int ret; + struct slave_node *slave; + const struct pkg_info *pkg; + struct inst_info *inst; + const char *pkgname; + const char *id; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + (void)instance_gbar_update_begin(inst); + } else { + ErrPrint("Invalid request[%s]\n", id); + } - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } +out: + return NULL; +} - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Invalid parameters\n"); - goto out; +static struct packet *slave_key_status(pid_t pid, int handle, const struct packet *packet) +{ + struct slave_node *slave; + struct inst_info *inst; + const char *pkgname; + const char *id; + int status; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &status); + if (ret != 3) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + } else { + (void)instance_forward_packet(inst, packet_ref((struct packet *)packet)); } + } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } +out: + return NULL; +} +static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet) +{ + struct slave_node *slave; + struct inst_info *inst; + const char *pkgname; + const char *id; + int status; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &status); + if (ret != 3) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + } else { + (void)instance_forward_packet(inst, packet_ref((struct packet *)packet)); } + } - if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - (void)instance_gbar_update_end(inst); +out: + return NULL; +} + +static struct packet *slave_close_gbar(pid_t pid, int handle, const struct packet *packet) +{ + struct slave_node *slave; + struct inst_info *inst; + const char *pkgname; + const char *id; + int status; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &status); + if (ret != 3) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); } else { - ErrPrint("Invalid request[%s]\n", id); + (void)instance_forward_packet(inst, packet_ref((struct packet *)packet)); } + } out: - return NULL; + return NULL; } -static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */ +static struct packet *slave_gbar_update_end(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - const char *pkgname; - const char *id; - const char *func; - int ret; + struct slave_node *slave; + const struct pkg_info *pkg; + struct inst_info *inst; + const char *pkgname; + const char *id; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + (void)instance_gbar_update_end(inst); + } else { + ErrPrint("Invalid request[%s]\n", id); + } + +out: + return NULL; +} - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } +static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */ +{ + struct slave_node *slave; + const char *pkgname; + const char *id; + const char *func; + int ret; - ret = packet_get(packet, "sss", &pkgname, &id, &func); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - goto out; - } + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } - ret = fault_func_call(slave, pkgname, id, func); - slave_give_more_ttl(slave); + ret = packet_get(packet, "sss", &pkgname, &id, &func); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = fault_func_call(slave, pkgname, id, func); + slave_give_more_ttl(slave); out: - return NULL; + return NULL; } static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */ { - struct slave_node *slave; - const char *pkgname; - const char *id; - const char *func; - int ret; + struct slave_node *slave; + const char *pkgname; + const char *id; + const char *func; + int ret; - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } - ret = packet_get(packet, "sss", &pkgname, &id, &func); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - goto out; - } + ret = packet_get(packet, "sss", &pkgname, &id, &func); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + goto out; + } - ret = fault_func_ret(slave, pkgname, id, func); - slave_give_more_ttl(slave); + ret = fault_func_ret(slave, pkgname, id, func); + slave_give_more_ttl(slave); out: - return NULL; + return NULL; } static struct packet *slave_extra_info(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - const char *pkgname; - const char *id; - const char *content_info; - const char *title; - const char *icon; - const char *name; - double priority; - int ret; - struct inst_info *inst; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "ssssssd", &pkgname, &id, &content_info, &title, &icon, &name, &priority); - if (ret != 7) { - ErrPrint("Parameter is not matchd\n"); - goto out; + struct slave_node *slave; + const char *pkgname; + const char *id; + const char *content_info; + const char *title; + const char *icon; + const char *name; + double priority; + int ret; + struct inst_info *inst; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssssssd", &pkgname, &id, &content_info, &title, &icon, &name, &priority); + if (ret != 7) { + ErrPrint("Parameter is not matchd\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; - } - - instance_set_dbox_info(inst, priority, content_info, title); - instance_set_alt_info(inst, icon, name); - instance_extra_info_updated_by_instance(inst); - slave_give_more_ttl(slave); - } + instance_set_dbox_info(inst, priority, content_info, title); + instance_set_alt_info(inst, icon, name); + instance_extra_info_updated_by_instance(inst); + slave_give_more_ttl(slave); + } out: - return NULL; + return NULL; } static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, ret */ { - struct slave_node *slave; - const char *pkgname; - const char *safe_filename; - const char *id; - int w; - int h; - int x; - int y; - int ret; - struct inst_info *inst; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "sssiiii", &pkgname, &id, &safe_filename, &x, &y, &w, &h); - if (ret != 7) { - ErrPrint("Parameter is not matched\n"); - goto out; + struct slave_node *slave; + const char *pkgname; + const char *safe_filename; + const char *id; + int w; + int h; + int x; + int y; + int ret; + struct inst_info *inst; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "sssiiii", &pkgname, &id, &safe_filename, &x, &y, &w, &h); + if (ret != 7) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; } - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; + switch (package_dbox_type(instance_package(inst))) { + case DBOX_TYPE_SCRIPT: + script_handler_resize(instance_dbox_script(inst), w, h); + if (safe_filename) { + (void)script_handler_parse_desc(inst, safe_filename, 0); + } else { + safe_filename = util_uri_to_path(id); + (void)script_handler_parse_desc(inst, safe_filename, 0); } - switch (package_dbox_type(instance_package(inst))) { - case DBOX_TYPE_SCRIPT: - script_handler_resize(instance_dbox_script(inst), w, h); - if (safe_filename) { - (void)script_handler_parse_desc(inst, safe_filename, 0); - } else { - safe_filename = util_uri_to_path(id); - (void)script_handler_parse_desc(inst, safe_filename, 0); - } - - if (unlink(safe_filename) < 0) { - ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename); - } - break; - case DBOX_TYPE_BUFFER: - default: - /*! - * \check - * text format (inst) - */ - instance_dbox_updated_by_instance(inst, safe_filename, x, y, w, h); - break; + if (unlink(safe_filename) < 0) { + ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename); } - - slave_give_more_ttl(slave); + break; + case DBOX_TYPE_BUFFER: + default: + /*! + * \check + * text format (inst) + */ + instance_dbox_updated_by_instance(inst, safe_filename, x, y, w, h); + break; } + slave_give_more_ttl(slave); + } + out: - return NULL; + return NULL; } static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct inst_info *inst; - const char *pkgname; - const char *id; - int seize; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "ssi", &pkgname, &id, &seize); - if (ret != 3) { - ErrPrint("Parameter is not matched\n"); - goto out; - } - - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - } else { - (void)instance_hold_scroll(inst, seize); - } + struct slave_node *slave; + struct inst_info *inst; + const char *pkgname; + const char *id; + int seize; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssi", &pkgname, &id, &seize); + if (ret != 3) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + } else { + (void)instance_hold_scroll(inst, seize); } + } out: - return NULL; + return NULL; } static struct packet *slave_extra_updated(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - const char *pkgname; - const char *id; - int idx; - int x; - int y; - int w; - int h; - int ret; - int is_gbar; - struct inst_info *inst; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "ssiiiiii", &pkgname, &id, &is_gbar, &idx, &x, &y, &w, &h); - if (ret != 8) { - ErrPrint("Parameter is not matched\n"); - goto out; - } - - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; - } - - (void)instance_extra_updated_by_instance(inst, is_gbar, idx, x, y, w, h); + struct slave_node *slave; + const char *pkgname; + const char *id; + int idx; + int x; + int y; + int w; + int h; + int ret; + int is_gbar; + struct inst_info *inst; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ssiiiiii", &pkgname, &id, &is_gbar, &idx, &x, &y, &w, &h); + if (ret != 8) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + (void)instance_extra_updated_by_instance(inst, is_gbar, idx, x, y, w, h); out: - return NULL; + return NULL; } static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */ { - struct slave_node *slave; - const char *pkgname; - const char *id; - const char *descfile; - int x; - int y; - int w; - int h; - int ret; - struct inst_info *inst; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "sssiiii", &pkgname, &id, &descfile, &x, &y, &w, &h); - if (ret != 7) { - ErrPrint("Parameter is not matched\n"); - goto out; - } - - ret = validate_request(pkgname, id, &inst, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } - - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; - } - - switch (package_gbar_type(instance_package(inst))) { + struct slave_node *slave; + const char *pkgname; + const char *id; + const char *descfile; + int x; + int y; + int w; + int h; + int ret; + struct inst_info *inst; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "sssiiii", &pkgname, &id, &descfile, &x, &y, &w, &h); + if (ret != 7) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + switch (package_gbar_type(instance_package(inst))) { case GBAR_TYPE_SCRIPT: - DbgPrint("%s updated (%s)\n", instance_id(inst), descfile); - if (script_handler_is_loaded(instance_gbar_script(inst))) { - (void)script_handler_parse_desc(inst, descfile, 1); - } - break; + DbgPrint("%s updated (%s)\n", instance_id(inst), descfile); + if (script_handler_is_loaded(instance_gbar_script(inst))) { + (void)script_handler_parse_desc(inst, descfile, 1); + } + break; case GBAR_TYPE_TEXT: - instance_set_gbar_size(inst, 0, 0); + instance_set_gbar_size(inst, 0, 0); case GBAR_TYPE_BUFFER: - instance_gbar_updated(pkgname, id, descfile, x, y, w, h); - break; + instance_gbar_updated(pkgname, id, descfile, x, y, w, h); + break; default: - DbgPrint("Ignore updated DESC(%s)\n", pkgname); - break; - } + DbgPrint("Ignore updated DESC(%s)\n", pkgname); + break; + } out: - return NULL; + return NULL; } static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */ { - struct slave_node *slave; - const char *pkgname; - const char *id; - int ret; - struct inst_info *inst; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - goto out; - } - - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Parameter is not matched\n"); - goto out; - } - - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - ret = instance_destroyed(inst, DBOX_STATUS_ERROR_NONE); - } + struct slave_node *slave; + const char *pkgname; + const char *id; + int ret; + struct inst_info *inst; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + goto out; + } + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Parameter is not matched\n"); + goto out; + } + + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + ret = instance_destroyed(inst, DBOX_STATUS_ERROR_NONE); + } out: - return NULL; + return NULL; } /*! @@ -6946,504 +6998,504 @@ out: */ static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */ { - enum target_type target; - const char *pkgname; - const char *id; - int w; - int h; - int pixel_size; - struct packet *result; - struct slave_node *slave; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - int ret; + enum target_type target; + const char *pkgname; + const char *id; + int w; + int h; + int pixel_size; + struct packet *result; + struct slave_node *slave; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Failed to find a slave\n"); + id = ""; + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Failed to find a slave\n"); - id = ""; - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size); + if (ret != 6) { + ErrPrint("Invalid argument\n"); + id = ""; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size); - if (ret != 6) { - ErrPrint("Invalid argument\n"); - id = ""; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + id = ""; - ret = validate_request(pkgname, id, &inst, &pkg); - id = ""; + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; - } + if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + struct buffer_info *info; - if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - struct buffer_info *info; - - info = instance_dbox_buffer(inst); - if (!info) { - if (!instance_create_dbox_buffer(inst, pixel_size)) { - ErrPrint("Failed to create a DBOX buffer\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - info = instance_dbox_buffer(inst); - if (!info) { - ErrPrint("DBOX buffer is not valid\n"); - /*! - * \NOTE - * ret value should not be changed. - */ - goto out; - } - } + info = instance_dbox_buffer(inst); + if (!info) { + if (!instance_create_dbox_buffer(inst, pixel_size)) { + ErrPrint("Failed to create a DBOX buffer\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - ret = buffer_handler_resize(info, w, h); - ret = buffer_handler_load(info); - if (ret == 0) { - instance_set_dbox_size(inst, w, h); - instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE); - id = buffer_handler_id(info); - } else { - ErrPrint("Failed to load a buffer(%d)\n", ret); - } - } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - struct buffer_info *info; - Ecore_Timer *gbar_monitor; - int is_resize; + info = instance_dbox_buffer(inst); + if (!info) { + ErrPrint("DBOX buffer is not valid\n"); + /*! + * \NOTE + * ret value should not be changed. + */ + goto out; + } + } - is_resize = 0; - gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG); - if (!gbar_monitor) { - gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG); - is_resize = !!gbar_monitor; - if (!is_resize) { - /* Invalid request. Reject this */ - ErrPrint("Invalid request\n"); - goto out; - } - - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst); - } else { - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst); - } + ret = buffer_handler_resize(info, w, h); + ret = buffer_handler_load(info); + if (ret == 0) { + instance_set_dbox_size(inst, w, h); + instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE); + id = buffer_handler_id(info); + } else { + ErrPrint("Failed to load a buffer(%d)\n", ret); + } + } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + struct buffer_info *info; + Ecore_Timer *gbar_monitor; + int is_resize; + + is_resize = 0; + gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG); + if (!gbar_monitor) { + gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG); + is_resize = !!gbar_monitor; + if (!is_resize) { + /* Invalid request. Reject this */ + ErrPrint("Invalid request\n"); + goto out; + } - ecore_timer_del(gbar_monitor); - inst = instance_unref(inst); - if (!inst) { - ErrPrint("Instance refcnt is ZERO: %s\n", pkgname); - goto out; - } + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst); + } else { + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst); + } - info = instance_gbar_buffer(inst); - if (!info) { - if (!instance_create_gbar_buffer(inst, pixel_size)) { - ErrPrint("Failed to create a GBAR buffer\n"); - ret = DBOX_STATUS_ERROR_FAULT; - instance_client_gbar_created(inst, ret); - goto out; - } - - info = instance_gbar_buffer(inst); - if (!info) { - ErrPrint("GBAR buffer is not valid\n"); - /*! - * \NOTE - * ret value should not be changed. - */ - instance_client_gbar_created(inst, ret); - goto out; - } - } + ecore_timer_del(gbar_monitor); + inst = instance_unref(inst); + if (!inst) { + ErrPrint("Instance refcnt is ZERO: %s\n", pkgname); + goto out; + } - ret = buffer_handler_resize(info, w, h); - ret = buffer_handler_load(info); - if (ret == 0) { - instance_set_gbar_size(inst, w, h); - id = buffer_handler_id(info); - } else { - ErrPrint("Failed to load a buffer (%d)\n", ret); - } + info = instance_gbar_buffer(inst); + if (!info) { + if (!instance_create_gbar_buffer(inst, pixel_size)) { + ErrPrint("Failed to create a GBAR buffer\n"); + ret = DBOX_STATUS_ERROR_FAULT; + instance_client_gbar_created(inst, ret); + goto out; + } + info = instance_gbar_buffer(inst); + if (!info) { + ErrPrint("GBAR buffer is not valid\n"); /*! - * Send the GBAR created event to the client + * \NOTE + * ret value should not be changed. */ - if (!is_resize) { - instance_client_gbar_created(inst, ret); - } + instance_client_gbar_created(inst, ret); + goto out; + } } -out: - result = packet_create_reply(packet, "is", ret, id); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); + ret = buffer_handler_resize(info, w, h); + ret = buffer_handler_load(info); + if (ret == 0) { + instance_set_gbar_size(inst, w, h); + id = buffer_handler_id(info); + } else { + ErrPrint("Failed to load a buffer (%d)\n", ret); } - return result; + /*! + * Send the GBAR created event to the client + */ + if (!is_resize) { + instance_client_gbar_created(inst, ret); + } + } + +out: + result = packet_create_reply(packet, "is", ret, id); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } + + return result; } static struct packet *slave_acquire_extra_buffer(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct inst_info *inst; - struct packet *result; - const struct pkg_info *pkg; - const char *pkgname; - const char *id; - int pixel_size; - int target; - int idx; - int ret; - int w; - int h; + struct slave_node *slave; + struct inst_info *inst; + struct packet *result; + const struct pkg_info *pkg; + const char *pkgname; + const char *id; + int pixel_size; + int target; + int idx; + int ret; + int w; + int h; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Slave %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + id = ""; + goto out; + } - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - id = ""; + ret = packet_get(packet, "issiiii", &target, &pkgname, &id, &w, &h, &pixel_size, &idx); + if (ret != 7) { + ErrPrint("Invalid parameters\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + id = ""; + goto out; + } + + ret = validate_request(pkgname, id, &inst, &pkg); + id = ""; + + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } + + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + struct buffer_info *info; + + info = instance_dbox_extra_buffer(inst, idx); + if (!info) { + if (!instance_create_dbox_extra_buffer(inst, pixel_size, idx)) { + ErrPrint("Failed to create a DBOX buffer\n"); + ret = DBOX_STATUS_ERROR_FAULT; goto out; - } + } - ret = packet_get(packet, "issiiii", &target, &pkgname, &id, &w, &h, &pixel_size, &idx); - if (ret != 7) { - ErrPrint("Invalid parameters\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - id = ""; + info = instance_dbox_extra_buffer(inst, idx); + if (!info) { + ErrPrint("DBOX extra buffer is not valid\n"); + /*! + * \NOTE + * ret value should not be changed. + */ goto out; + } } - ret = validate_request(pkgname, id, &inst, &pkg); - id = ""; - - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + ret = buffer_handler_resize(info, w, h); + ret = buffer_handler_load(info); + if (ret == 0) { + /** + * @todo + * Send the extra buffer info to the viewer. + * Then the viewer will try to acquire extra pixmap(aka, resource id) information + */ + id = buffer_handler_id(info); + DbgPrint("Extra buffer is loaded: %s\n", id); + (void)instance_client_dbox_extra_buffer_created(inst, idx); + } else { + ErrPrint("Failed to load a buffer(%d)\n", ret); } + } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + struct buffer_info *info; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + info = instance_gbar_extra_buffer(inst, idx); + if (!info) { + if (!instance_create_gbar_extra_buffer(inst, pixel_size, idx)) { + ErrPrint("Failed to create a GBAR buffer\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + info = instance_gbar_extra_buffer(inst, idx); + if (!info) { + ErrPrint("GBAR buffer is not valid\n"); + /*! + * \NOTE + * ret value should not be changed. + */ goto out; + } } - if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - struct buffer_info *info; - - info = instance_dbox_extra_buffer(inst, idx); - if (!info) { - if (!instance_create_dbox_extra_buffer(inst, pixel_size, idx)) { - ErrPrint("Failed to create a DBOX buffer\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - info = instance_dbox_extra_buffer(inst, idx); - if (!info) { - ErrPrint("DBOX extra buffer is not valid\n"); - /*! - * \NOTE - * ret value should not be changed. - */ - goto out; - } - } - - ret = buffer_handler_resize(info, w, h); - ret = buffer_handler_load(info); - if (ret == 0) { - /** - * @todo - * Send the extra buffer info to the viewer. - * Then the viewer will try to acquire extra pixmap(aka, resource id) information - */ - id = buffer_handler_id(info); - DbgPrint("Extra buffer is loaded: %s\n", id); - (void)instance_client_dbox_extra_buffer_created(inst, idx); - } else { - ErrPrint("Failed to load a buffer(%d)\n", ret); - } - } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - struct buffer_info *info; - - info = instance_gbar_extra_buffer(inst, idx); - if (!info) { - if (!instance_create_gbar_extra_buffer(inst, pixel_size, idx)) { - ErrPrint("Failed to create a GBAR buffer\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - - info = instance_gbar_extra_buffer(inst, idx); - if (!info) { - ErrPrint("GBAR buffer is not valid\n"); - /*! - * \NOTE - * ret value should not be changed. - */ - goto out; - } - } - - ret = buffer_handler_resize(info, w, h); - ret = buffer_handler_load(info); - if (ret == 0) { - id = buffer_handler_id(info); - /** - * @todo - * Send the extra buffer acquired event to the viewer - */ - DbgPrint("Extra buffer is loaded: %s\n", id); - (void)instance_client_gbar_extra_buffer_created(inst, idx); - } else { - ErrPrint("Failed to load a buffer (%d)\n", ret); - } + ret = buffer_handler_resize(info, w, h); + ret = buffer_handler_load(info); + if (ret == 0) { + id = buffer_handler_id(info); + /** + * @todo + * Send the extra buffer acquired event to the viewer + */ + DbgPrint("Extra buffer is loaded: %s\n", id); + (void)instance_client_gbar_extra_buffer_created(inst, idx); + } else { + ErrPrint("Failed to load a buffer (%d)\n", ret); } + } out: - result = packet_create_reply(packet, "is", ret, id); - if (!result) { - ErrPrint("Failed to create a reply packet\n"); - } + result = packet_create_reply(packet, "is", ret, id); + if (!result) { + ErrPrint("Failed to create a reply packet\n"); + } - return result; + return result; } static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet) { - struct slave_node *slave; - struct packet *result; - enum target_type type; - const char *pkgname; - const char *id; - int w; - int h; - struct inst_info *inst = NULL; - const struct pkg_info *pkg = NULL; - int ret; + struct slave_node *slave; + struct packet *result; + enum target_type type; + const char *pkgname; + const char *id; + int w; + int h; + struct inst_info *inst = NULL; + const struct pkg_info *pkg = NULL; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Failed to find a slave\n"); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + id = ""; + goto out; + } - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Failed to find a slave\n"); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - id = ""; - goto out; - } + ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h); + if (ret != 5) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + id = ""; + goto out; + } - ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h); - if (ret != 5) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - id = ""; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + id = ""; - ret = validate_request(pkgname, id, &inst, &pkg); - id = ""; + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + /*! + * \note + * Reset "id", It will be re-used from here + */ + + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + goto out; + } + + if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + struct buffer_info *info; + + info = instance_dbox_buffer(inst); + if (!info) { + goto out; } - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ret = buffer_handler_resize(info, w, h); /*! * \note - * Reset "id", It will be re-used from here + * id is resued for newly assigned ID */ - - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - goto out; + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + id = buffer_handler_id(info); + instance_set_dbox_size(inst, w, h); + instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE); } + } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + struct buffer_info *info; - if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - struct buffer_info *info; - - info = instance_dbox_buffer(inst); - if (!info) { - goto out; - } - - ret = buffer_handler_resize(info, w, h); - /*! - * \note - * id is resued for newly assigned ID - */ - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - id = buffer_handler_id(info); - instance_set_dbox_size(inst, w, h); - instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE); - } - } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - struct buffer_info *info; - - info = instance_gbar_buffer(inst); - if (!info) { - goto out; - } + info = instance_gbar_buffer(inst); + if (!info) { + goto out; + } - ret = buffer_handler_resize(info, w, h); - /*! - * \note - * id is resued for newly assigned ID - */ - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - id = buffer_handler_id(info); - instance_set_gbar_size(inst, w, h); - } + ret = buffer_handler_resize(info, w, h); + /*! + * \note + * id is resued for newly assigned ID + */ + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + id = buffer_handler_id(info); + instance_set_gbar_size(inst, w, h); } + } out: - result = packet_create_reply(packet, "is", ret, id); - if (!result) { - ErrPrint("Failed to create a packet\n"); - } + result = packet_create_reply(packet, "is", ret, id); + if (!result) { + ErrPrint("Failed to create a packet\n"); + } - return result; + return result; } static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet) { - enum target_type type; - const char *pkgname; - const char *id; - struct packet *result; - struct slave_node *slave; - struct inst_info *inst; - const struct pkg_info *pkg; - int ret; - - slave = slave_find_by_pid(pid); - if (!slave) { - ErrPrint("Failed to find a slave\n"); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; - } + enum target_type type; + const char *pkgname; + const char *id; + struct packet *result; + struct slave_node *slave; + struct inst_info *inst; + const struct pkg_info *pkg; + int ret; + + slave = slave_find_by_pid(pid); + if (!slave) { + ErrPrint("Failed to find a slave\n"); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; + } + + if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) { + ErrPrint("Inavlid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } - if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) { - ErrPrint("Inavlid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } + ret = validate_request(pkgname, id, &inst, &pkg); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto out; + } - ret = validate_request(pkgname, id, &inst, &pkg); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; - } + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { + struct buffer_info *info; - if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - struct buffer_info *info; + info = instance_dbox_buffer(inst); + ret = buffer_handler_unload(info); + } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { + struct buffer_info *info; + Ecore_Timer *gbar_monitor; - info = instance_dbox_buffer(inst); - ret = buffer_handler_unload(info); - } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - struct buffer_info *info; - Ecore_Timer *gbar_monitor; - - gbar_monitor = instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG); - if (!gbar_monitor && !package_is_fault(pkg)) { - ErrPrint("Slave requests to release a buffer\n"); - /** - * @note - * In this case just keep going to release buffer, - * Even if a user(client) doesn't wants to destroy the GBAR. - * - * If the slave tries to destroy GBAR buffer, it should be - * released and reported to the client about its status. - * - * Even if the pd is destroyed by timeout handler, - * instance_client_gbar_destroyed function will be ignored - * by pd.need_to_send_close_event flag. - * which will be checked by instance_client_gbar_destroyed function. - */ - - /** - * @note - * provider can try to resize the buffer size. - * in that case, it will release the buffer first. - * Then even though the client doesn't request to close the GBAR, - * the provider can release it. - * If we send the close event to the client, - * The client will not able to allocate GBAR again. - * In this case, add the pd,monitor again. from here. - * to wait the re-allocate buffer. - * If the client doesn't request buffer reallocation, - * Treat it as a fault. and close the GBAR. - */ - info = instance_gbar_buffer(inst); - ret = buffer_handler_unload(info); - - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_resize_monitor_cb, instance_ref(inst)); - if (!gbar_monitor) { - ErrPrint("Failed to create a timer for GBAR Open monitor\n"); - inst = instance_unref(inst); - if (!inst) { - DbgPrint("Instance is deleted\n"); - } - } else { - (void)instance_set_data(inst, GBAR_RESIZE_MONITOR_TAG, gbar_monitor); - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to add event handler: %s\n", pkgname); - } - } - } + gbar_monitor = instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG); + if (!gbar_monitor && !package_is_fault(pkg)) { + ErrPrint("Slave requests to release a buffer\n"); + /** + * @note + * In this case just keep going to release buffer, + * Even if a user(client) doesn't wants to destroy the GBAR. + * + * If the slave tries to destroy GBAR buffer, it should be + * released and reported to the client about its status. + * + * Even if the pd is destroyed by timeout handler, + * instance_client_gbar_destroyed function will be ignored + * by pd.need_to_send_close_event flag. + * which will be checked by instance_client_gbar_destroyed function. + */ + + /** + * @note + * provider can try to resize the buffer size. + * in that case, it will release the buffer first. + * Then even though the client doesn't request to close the GBAR, + * the provider can release it. + * If we send the close event to the client, + * The client will not able to allocate GBAR again. + * In this case, add the pd,monitor again. from here. + * to wait the re-allocate buffer. + * If the client doesn't request buffer reallocation, + * Treat it as a fault. and close the GBAR. + */ + info = instance_gbar_buffer(inst); + ret = buffer_handler_unload(info); + + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_resize_monitor_cb, instance_ref(inst)); + if (!gbar_monitor) { + ErrPrint("Failed to create a timer for GBAR Open monitor\n"); + inst = instance_unref(inst); + if (!inst) { + DbgPrint("Instance is deleted\n"); + } } else { - if (gbar_monitor) { - /** - * @note - * If the instance has gbar_monitor, the pd close requested from client via client_destroy_gbar. - */ - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst); - ecore_timer_del(gbar_monitor); - - inst = instance_unref(inst); - if (!inst) { - ErrPrint("Instance is released: %s\n", pkgname); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - } /* else { - @note - This case means that the package is faulted so the service provider tries to release the buffer - */ - - info = instance_gbar_buffer(inst); - ret = buffer_handler_unload(info); - - /** - * @note - * Send the GBAR destroyed event to the client - */ - instance_client_gbar_destroyed(inst, ret); + (void)instance_set_data(inst, GBAR_RESIZE_MONITOR_TAG, gbar_monitor); + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to add event handler: %s\n", pkgname); + } + } + } + } else { + if (gbar_monitor) { + /** + * @note + * If the instance has gbar_monitor, the pd close requested from client via client_destroy_gbar. + */ + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst); + ecore_timer_del(gbar_monitor); + + inst = instance_unref(inst); + if (!inst) { + ErrPrint("Instance is released: %s\n", pkgname); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; } + } /* else { + @note + This case means that the package is faulted so the service provider tries to release the buffer + */ + + info = instance_gbar_buffer(inst); + ret = buffer_handler_unload(info); + + /** + * @note + * Send the GBAR destroyed event to the client + */ + instance_client_gbar_destroyed(inst, ret); + } } out: result = packet_create_reply(packet, "i", ret); if (!result) { - ErrPrint("Failed to create a packet\n"); + ErrPrint("Failed to create a packet\n"); } return result; -} + } -static struct packet *slave_release_extra_buffer(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *slave_release_extra_buffer(pid_t pid, int handle, const struct packet *packet) + { struct slave_node *slave; struct packet *result; const char *id; @@ -7457,47 +7509,47 @@ static struct packet *slave_release_extra_buffer(pid_t pid, int handle, const st slave = slave_find_by_pid(pid); if (!slave) { - ErrPrint("Slave %d is not exists\n", pid); - ret = DBOX_STATUS_ERROR_NOT_EXIST; - goto out; + ErrPrint("Slave %d is not exists\n", pid); + ret = DBOX_STATUS_ERROR_NOT_EXIST; + goto out; } if (packet_get(packet, "issi", &type, &pkgname, &id, &idx) != 4) { - ErrPrint("Inavlid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Inavlid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } ret = validate_request(pkgname, id, &inst, &pkg); if (ret != DBOX_STATUS_ERROR_NONE) { - goto out; + goto out; } ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) { - info = instance_dbox_extra_buffer(inst, idx); - (void)instance_client_dbox_extra_buffer_destroyed(inst, idx); + info = instance_dbox_extra_buffer(inst, idx); + (void)instance_client_dbox_extra_buffer_destroyed(inst, idx); } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) { - info = instance_gbar_extra_buffer(inst, idx); - (void)instance_client_gbar_extra_buffer_destroyed(inst, idx); + info = instance_gbar_extra_buffer(inst, idx); + (void)instance_client_gbar_extra_buffer_destroyed(inst, idx); } if (info) { - ret = buffer_handler_unload(info); + ret = buffer_handler_unload(info); } out: result = packet_create_reply(packet, "i", ret); if (!result) { - ErrPrint("Failed to create a reply packet\n"); + ErrPrint("Failed to create a reply packet\n"); } return result; -} + } -static struct packet *service_instance_count(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *service_instance_count(pid_t pid, int handle, const struct packet *packet) + { struct packet *result; struct pkg_info *pkg; double timestamp; @@ -7513,50 +7565,50 @@ static struct packet *service_instance_count(pid_t pid, int handle, const struct ret = packet_get(packet, "sssd", &pkgname, &cluster, &category, ×tamp); if (ret != 4) { - ErrPrint("Invalid packet\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Invalid packet\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } pkg_list = (Eina_List *)package_list(); ret = 0; EINA_LIST_FOREACH(pkg_list, l, pkg) { - if (pkgname && pkgname[0]) { - if (strcmp(package_name(pkg), pkgname)) { - continue; - } + if (pkgname && pkgname[0]) { + if (strcmp(package_name(pkg), pkgname)) { + continue; } + } - inst_list = package_instance_list(pkg); - EINA_LIST_FOREACH(inst_list, inst_l, inst) { - if (cluster && cluster[0]) { - if (strcmp(instance_cluster(inst), cluster)) { - continue; - } - } - - if (category && category[0]) { - if (strcmp(instance_category(inst), category)) { - continue; - } - } - - ret++; + inst_list = package_instance_list(pkg); + EINA_LIST_FOREACH(inst_list, inst_l, inst) { + if (cluster && cluster[0]) { + if (strcmp(instance_cluster(inst), cluster)) { + continue; + } + } + + if (category && category[0]) { + if (strcmp(instance_category(inst), category)) { + continue; + } } + + ret++; + } } out: result = packet_create_reply(packet, "i", ret); if (!result) { - ErrPrint("Failed to create a packet\n"); + ErrPrint("Failed to create a packet\n"); } return result; -} + } -static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet) + { struct inst_info *inst; struct packet *result; const char *pkgname; @@ -7566,56 +7618,56 @@ static struct packet *service_change_period(pid_t pid, int handle, const struct ret = packet_get(packet, "ssd", &pkgname, &id, &period); if (ret != 3) { - ErrPrint("Invalid packet\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Invalid packet\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } if (!strlen(id)) { - struct pkg_info *pkg; + struct pkg_info *pkg; - pkg = package_find(pkgname); - if (!pkg) { - ret = DBOX_STATUS_ERROR_NOT_EXIST; - } else if (package_is_fault(pkg)) { - ret = DBOX_STATUS_ERROR_FAULT; - } else { - Eina_List *inst_list; - Eina_List *l; - - inst_list = package_instance_list(pkg); - EINA_LIST_FOREACH(inst_list, l, inst) { - ret = instance_set_period(inst, period); - if (ret < 0) { - ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period); - } - } + pkg = package_find(pkgname); + if (!pkg) { + ret = DBOX_STATUS_ERROR_NOT_EXIST; + } else if (package_is_fault(pkg)) { + ret = DBOX_STATUS_ERROR_FAULT; + } else { + Eina_List *inst_list; + Eina_List *l; + + inst_list = package_instance_list(pkg); + EINA_LIST_FOREACH(inst_list, l, inst) { + ret = instance_set_period(inst, period); + if (ret < 0) { + ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period); + } } + } } else { - ret = validate_request(pkgname, id, &inst, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - if (instance_state(inst) == INST_DESTROYED) { - ErrPrint("Package[%s] instance is already destroyed\n", pkgname); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ret = instance_set_period(inst, period); + ret = validate_request(pkgname, id, &inst, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + if (instance_state(inst) == INST_DESTROYED) { + ErrPrint("Package[%s] instance is already destroyed\n", pkgname); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } + + ret = instance_set_period(inst, period); + } } DbgPrint("Change the update period: %s, %lf : %d\n", pkgname, period, ret); out: result = packet_create_reply(packet, "i", ret); if (!result) { - ErrPrint("Failed to create a packet\n"); + ErrPrint("Failed to create a packet\n"); } return result; -} + } -static struct packet *service_update(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *service_update(pid_t pid, int handle, const struct packet *packet) + { Eina_List *inst_list; struct pkg_info *pkg; struct packet *result; @@ -7630,54 +7682,54 @@ static struct packet *service_update(pid_t pid, int handle, const struct packet ret = packet_get(packet, "sssssi", &pkgname, &id, &cluster, &category, &content, &force); if (ret != 6) { - ErrPrint("Invalid Packet\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Invalid Packet\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } lbid = package_dbox_pkgname(pkgname); if (!lbid) { - ErrPrint("Invalid package %s\n", pkgname); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Invalid package %s\n", pkgname); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } pkg = package_find(lbid); if (!pkg) { - ret = DBOX_STATUS_ERROR_NOT_EXIST; - DbgFree(lbid); - goto out; + ret = DBOX_STATUS_ERROR_NOT_EXIST; + DbgFree(lbid); + goto out; } if (package_is_fault(pkg)) { - ret = DBOX_STATUS_ERROR_FAULT; - DbgFree(lbid); - goto out; + ret = DBOX_STATUS_ERROR_FAULT; + DbgFree(lbid); + goto out; } inst_list = package_instance_list(pkg); if (!eina_list_count(inst_list)) { - ret = DBOX_STATUS_ERROR_NOT_EXIST; - DbgFree(lbid); - goto out; + ret = DBOX_STATUS_ERROR_NOT_EXIST; + DbgFree(lbid); + goto out; } if (id && strlen(id)) { - Eina_List *l; - struct inst_info *inst; + Eina_List *l; + struct inst_info *inst; - ret = DBOX_STATUS_ERROR_NOT_EXIST; - EINA_LIST_FOREACH(inst_list, l, inst) { - if (!strcmp(instance_id(inst), id)) { - ret = DBOX_STATUS_ERROR_NONE; - break; - } + ret = DBOX_STATUS_ERROR_NOT_EXIST; + EINA_LIST_FOREACH(inst_list, l, inst) { + if (!strcmp(instance_id(inst), id)) { + ret = DBOX_STATUS_ERROR_NONE; + break; } + } - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST) { - DbgFree(lbid); - goto out; - } + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST) { + DbgFree(lbid); + goto out; + } } /*! @@ -7691,14 +7743,14 @@ static struct packet *service_update(pid_t pid, int handle, const struct packet out: result = packet_create_reply(packet, "i", ret); if (!result) { - ErrPrint("Failed to create a packet\n"); + ErrPrint("Failed to create a packet\n"); } return result; -} + } -static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet) + { struct liveinfo *info; struct packet *result; int ret; @@ -7708,18 +7760,18 @@ static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet DbgPrint("Request arrived from %d\n", pid); if (packet_get(packet, "d", ×tamp) != 1) { - ErrPrint("Invalid packet\n"); - fifo_name = ""; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Invalid packet\n"); + fifo_name = ""; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } info = liveinfo_create(pid, handle); if (!info) { - ErrPrint("Failed to create a liveinfo object\n"); - fifo_name = ""; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; + ErrPrint("Failed to create a liveinfo object\n"); + fifo_name = ""; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; } ret = 0; @@ -7729,14 +7781,14 @@ static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet out: result = packet_create_reply(packet, "si", fifo_name, ret); if (!result) { - ErrPrint("Failed to create a result packet\n"); + ErrPrint("Failed to create a result packet\n"); } return result; -} + } -static Eina_Bool lazy_slave_list_cb(void *info) -{ + static Eina_Bool lazy_slave_list_cb(void *info) + { FILE *fp; Eina_List *list; Eina_List *l; @@ -7745,71 +7797,71 @@ static Eina_Bool lazy_slave_list_cb(void *info) liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - liveinfo_close_fifo(info); - return ECORE_CALLBACK_CANCEL; + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; } list = (Eina_List *)slave_list(); EINA_LIST_FOREACH(list, l, slave) { - fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n", - slave_pid(slave), - slave_name(slave), - slave_pkgname(slave), - slave_abi(slave), - slave_is_secured(slave), - slave_refcnt(slave), - slave_fault_count(slave), - slave_state_string(slave), - slave_loaded_instance(slave), - slave_loaded_package(slave), - slave_ttl(slave) - ); + fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n", + slave_pid(slave), + slave_name(slave), + slave_pkgname(slave), + slave_abi(slave), + slave_is_secured(slave), + slave_refcnt(slave), + slave_fault_count(slave), + slave_state_string(slave), + slave_loaded_instance(slave), + slave_loaded_package(slave), + slave_ttl(slave) + ); } fprintf(fp, "EOD\n"); liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet) + { struct liveinfo *info; double timestamp; if (packet_get(packet, "d", ×tamp) != 1) { - ErrPrint("Invalid argument\n"); - goto out; + ErrPrint("Invalid argument\n"); + goto out; } info = liveinfo_find_by_pid(pid); if (!info) { - ErrPrint("Invalid request\n"); - goto out; + ErrPrint("Invalid request\n"); + goto out; } lazy_slave_list_cb(info); out: return NULL; -} + } -static inline const char *visible_state_string(enum dynamicbox_visible_state state) -{ + static inline const char *visible_state_string(enum dynamicbox_visible_state state) + { switch (state) { - case DBOX_SHOW: + case DBOX_SHOW: return "Show"; - case DBOX_HIDE: + case DBOX_HIDE: return "Hide"; - case DBOX_HIDE_WITH_PAUSE: + case DBOX_HIDE_WITH_PAUSE: return "Paused"; - default: + default: break; } return "Unknown"; -} + } -static Eina_Bool inst_list_cb(void *info) -{ + static Eina_Bool inst_list_cb(void *info) + { FILE *fp; char *pkgname; struct pkg_info *pkg; @@ -7819,42 +7871,42 @@ static Eina_Bool inst_list_cb(void *info) pkgname = liveinfo_data(info); if (!pkgname) { - return ECORE_CALLBACK_CANCEL; + return ECORE_CALLBACK_CANCEL; } liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - ErrPrint("Invalid fp\n"); - liveinfo_close_fifo(info); - free(pkgname); - return ECORE_CALLBACK_CANCEL; + ErrPrint("Invalid fp\n"); + liveinfo_close_fifo(info); + free(pkgname); + return ECORE_CALLBACK_CANCEL; } if (!package_is_dbox_pkgname(pkgname)) { - ErrPrint("Invalid package name\n"); - free(pkgname); - goto close_out; + ErrPrint("Invalid package name\n"); + free(pkgname); + goto close_out; } pkg = package_find(pkgname); free(pkgname); if (!pkg) { - ErrPrint("Package is not exists\n"); - goto close_out; + ErrPrint("Package is not exists\n"); + goto close_out; } inst_list = package_instance_list(pkg); EINA_LIST_FOREACH(inst_list, l, inst) { - fprintf(fp, "%s %s %s %s %lf %s %d %d\n", - instance_id(inst), - buffer_handler_id(instance_dbox_buffer(inst)), - instance_cluster(inst), - instance_category(inst), - instance_period(inst), - visible_state_string(instance_visible_state(inst)), - instance_dbox_width(inst), - instance_dbox_height(inst)); + fprintf(fp, "%s %s %s %s %lf %s %d %d\n", + instance_id(inst), + buffer_handler_id(instance_dbox_buffer(inst)), + instance_cluster(inst), + instance_category(inst), + instance_period(inst), + visible_state_string(instance_visible_state(inst)), + instance_dbox_width(inst), + instance_dbox_height(inst)); } close_out: @@ -7862,29 +7914,29 @@ close_out: liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet) + { const char *pkgname; char *dup_pkgname; struct liveinfo *info; if (packet_get(packet, "s", &pkgname) != 1) { - ErrPrint("Invalid argument\n"); - goto out; + ErrPrint("Invalid argument\n"); + goto out; } info = liveinfo_find_by_pid(pid); if (!info) { - ErrPrint("Invalid request\n"); - goto out; + ErrPrint("Invalid request\n"); + goto out; } dup_pkgname = strdup(pkgname); if (!dup_pkgname) { - ErrPrint("Invalid request\n"); - goto out; + ErrPrint("Invalid request\n"); + goto out; } liveinfo_set_data(info, dup_pkgname); @@ -7892,10 +7944,10 @@ static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct pac out: return NULL; -} + } -static Eina_Bool pkg_list_cb(void *info) -{ + static Eina_Bool pkg_list_cb(void *info) + { FILE *fp; Eina_List *l; Eina_List *list; @@ -7908,201 +7960,201 @@ static Eina_Bool pkg_list_cb(void *info) liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - DbgPrint("Failed to open a pipe\n"); - liveinfo_close_fifo(info); - return ECORE_CALLBACK_CANCEL; + DbgPrint("Failed to open a pipe\n"); + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; } list = (Eina_List *)package_list(); EINA_LIST_FOREACH(list, l, pkg) { - slave = package_slave(pkg); - - if (slave) { - slavename = slave_name(slave); - pid = slave_pid(slave); - } else { - pid = (pid_t)-1; - slavename = ""; - } - - inst_list = (Eina_List *)package_instance_list(pkg); - fprintf(fp, "%d %s %s %s %d %d %d\n", - pid, - strlen(slavename) ? slavename : "(none)", - package_name(pkg), - package_abi(pkg), - package_refcnt(pkg), - package_fault_count(pkg), - eina_list_count(inst_list) - ); - DbgPrint("%d %s %s %s %d %d %d\n", - pid, - strlen(slavename) ? slavename : "(none)", - package_name(pkg), - package_abi(pkg), - package_refcnt(pkg), - package_fault_count(pkg), - eina_list_count(inst_list) - ); + slave = package_slave(pkg); + + if (slave) { + slavename = slave_name(slave); + pid = slave_pid(slave); + } else { + pid = (pid_t)-1; + slavename = ""; + } + + inst_list = (Eina_List *)package_instance_list(pkg); + fprintf(fp, "%d %s %s %s %d %d %d\n", + pid, + strlen(slavename) ? slavename : "(none)", + package_name(pkg), + package_abi(pkg), + package_refcnt(pkg), + package_fault_count(pkg), + eina_list_count(inst_list) + ); + DbgPrint("%d %s %s %s %d %d %d\n", + pid, + strlen(slavename) ? slavename : "(none)", + package_name(pkg), + package_abi(pkg), + package_refcnt(pkg), + package_fault_count(pkg), + eina_list_count(inst_list) + ); } fprintf(fp, "EOD\n"); DbgPrint("EOD\n"); liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet) + { struct liveinfo *info; double timestamp; if (packet_get(packet, "d", ×tamp) != 1) { - ErrPrint("Invalid argument\n"); - goto out; + ErrPrint("Invalid argument\n"); + goto out; } DbgPrint("Package List: %lf\n", timestamp); info = liveinfo_find_by_pid(pid); if (!info) { - ErrPrint("Invalid request\n"); - goto out; + ErrPrint("Invalid request\n"); + goto out; } pkg_list_cb(info); out: return NULL; -} + } -static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet) + { return NULL; -} + } -static Eina_Bool pkg_ctrl_rmpack_cb(void *info) -{ + static Eina_Bool pkg_ctrl_rmpack_cb(void *info) + { FILE *fp; liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - liveinfo_close_fifo(info); - return ECORE_CALLBACK_CANCEL; + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; } fprintf(fp, "%d\n", ENOSYS); fprintf(fp, "EOD\n"); liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static Eina_Bool pkg_ctrl_rminst_cb(void *info) -{ + static Eina_Bool pkg_ctrl_rminst_cb(void *info) + { FILE *fp; liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - liveinfo_close_fifo(info); - return ECORE_CALLBACK_CANCEL; + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; } fprintf(fp, "%d\n", (int)liveinfo_data(info)); fprintf(fp, "EOD\n"); liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static Eina_Bool pkg_ctrl_faultinst_cb(void *info) -{ + static Eina_Bool pkg_ctrl_faultinst_cb(void *info) + { FILE *fp; liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - liveinfo_close_fifo(info); - return ECORE_CALLBACK_CANCEL; + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; } fprintf(fp, "%d\n", (int)liveinfo_data(info)); fprintf(fp, "EOD\n"); liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet) + { struct liveinfo *info; char *cmd; char *pkgname; char *id; if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) { - ErrPrint("Invalid argument\n"); - goto out; + ErrPrint("Invalid argument\n"); + goto out; } info = liveinfo_find_by_pid(pid); if (!info) { - ErrPrint("Invalid request\n"); - goto out; + ErrPrint("Invalid request\n"); + goto out; } if (!strcmp(cmd, "rmpack")) { - pkg_ctrl_rmpack_cb(info); + pkg_ctrl_rmpack_cb(info); } else if (!strcmp(cmd, "rminst")) { - struct inst_info *inst; - inst = package_find_instance_by_id(pkgname, id); - if (!inst) { - liveinfo_set_data(info, (void *)ENOENT); - } else { - (void)instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT); - liveinfo_set_data(info, (void *)0); - } - - pkg_ctrl_rminst_cb(info); + struct inst_info *inst; + inst = package_find_instance_by_id(pkgname, id); + if (!inst) { + liveinfo_set_data(info, (void *)ENOENT); + } else { + (void)instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT); + liveinfo_set_data(info, (void *)0); + } + + pkg_ctrl_rminst_cb(info); } else if (!strcmp(cmd, "faultinst")) { - struct inst_info *inst; - inst = package_find_instance_by_id(pkgname, id); - if (!inst) { - liveinfo_set_data(info, (void *)ENOENT); + struct inst_info *inst; + inst = package_find_instance_by_id(pkgname, id); + if (!inst) { + liveinfo_set_data(info, (void *)ENOENT); + } else { + struct pkg_info *pkg; + + pkg = instance_package(inst); + if (!pkg) { + liveinfo_set_data(info, (void *)EFAULT); } else { - struct pkg_info *pkg; - - pkg = instance_package(inst); - if (!pkg) { - liveinfo_set_data(info, (void *)EFAULT); - } else { - (void)package_faulted(pkg, 1); - liveinfo_set_data(info, (void *)0); - } + (void)package_faulted(pkg, 1); + liveinfo_set_data(info, (void *)0); } + } - pkg_ctrl_faultinst_cb(info); + pkg_ctrl_faultinst_cb(info); } out: return NULL; -} + } -static Eina_Bool master_ctrl_cb(void *info) -{ + static Eina_Bool master_ctrl_cb(void *info) + { FILE *fp; liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { - liveinfo_close_fifo(info); - return ECORE_CALLBACK_CANCEL; + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; } fprintf(fp, "%d\nEOD\n", (int)liveinfo_data(info)); liveinfo_close_fifo(info); return ECORE_CALLBACK_CANCEL; -} + } -static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet) -{ + static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet) + { struct liveinfo *info; char *cmd; char *var; @@ -8110,28 +8162,28 @@ static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct p int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; if (packet_get(packet, "sss", &cmd, &var, &val) != 3) { - ErrPrint("Invalid argument\n"); - goto out; + ErrPrint("Invalid argument\n"); + goto out; } info = liveinfo_find_by_pid(pid); if (!info) { - ErrPrint("Invalid request\n"); - goto out; + ErrPrint("Invalid request\n"); + goto out; } if (!strcasecmp(var, "debug")) { - if (!strcasecmp(cmd, "set")) { - g_conf.debug_mode = !strcasecmp(val, "on"); - } else if (!strcasecmp(cmd, "get")) { - } - ret = g_conf.debug_mode; + if (!strcasecmp(cmd, "set")) { + g_conf.debug_mode = !strcasecmp(val, "on"); + } else if (!strcasecmp(cmd, "get")) { + } + ret = g_conf.debug_mode; } else if (!strcasecmp(var, "slave_max_load")) { - if (!strcasecmp(cmd, "set")) { - g_conf.slave_max_load = atoi(val); - } else if (!strcasecmp(cmd, "get")) { - } - ret = g_conf.slave_max_load; + if (!strcasecmp(cmd, "set")) { + g_conf.slave_max_load = atoi(val); + } else if (!strcasecmp(cmd, "get")) { + } + ret = g_conf.slave_max_load; } liveinfo_set_data(info, (void *)ret); @@ -8139,553 +8191,553 @@ static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct p out: return NULL; -} + } -static struct method s_info_table[] = { + static struct method s_info_table[] = { { - .cmd = CMD_STR_INFO_HELLO, - .handler = liveinfo_hello, + .cmd = CMD_STR_INFO_HELLO, + .handler = liveinfo_hello, }, { - .cmd = CMD_STR_INFO_SLAVE_LIST, - .handler = liveinfo_slave_list, + .cmd = CMD_STR_INFO_SLAVE_LIST, + .handler = liveinfo_slave_list, }, { - .cmd = CMD_STR_INFO_PKG_LIST, - .handler = liveinfo_pkg_list, + .cmd = CMD_STR_INFO_PKG_LIST, + .handler = liveinfo_pkg_list, }, { - .cmd = CMD_STR_INFO_INST_LIST, - .handler = liveinfo_inst_list, + .cmd = CMD_STR_INFO_INST_LIST, + .handler = liveinfo_inst_list, }, { - .cmd = CMD_STR_INFO_SLAVE_CTRL, - .handler = liveinfo_slave_ctrl, + .cmd = CMD_STR_INFO_SLAVE_CTRL, + .handler = liveinfo_slave_ctrl, }, { - .cmd = CMD_STR_INFO_PKG_CTRL, - .handler = liveinfo_pkg_ctrl, + .cmd = CMD_STR_INFO_PKG_CTRL, + .handler = liveinfo_pkg_ctrl, }, { - .cmd = CMD_STR_INFO_MASTER_CTRL, - .handler = liveinfo_master_ctrl, + .cmd = CMD_STR_INFO_MASTER_CTRL, + .handler = liveinfo_master_ctrl, }, { - .cmd = NULL, - .handler = NULL, + .cmd = NULL, + .handler = NULL, }, -}; + }; -static struct method s_client_table[] = { + static struct method s_client_table[] = { { - .cmd = CMD_STR_GBAR_MOUSE_MOVE, - .handler = client_gbar_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_GBAR_MOUSE_MOVE, + .handler = client_gbar_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_DBOX_MOUSE_MOVE, - .handler = client_dbox_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_DBOX_MOUSE_MOVE, + .handler = client_dbox_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_GBAR_MOUSE_DOWN, - .handler = client_gbar_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_GBAR_MOUSE_DOWN, + .handler = client_gbar_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_GBAR_MOUSE_UP, - .handler = client_gbar_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_GBAR_MOUSE_UP, + .handler = client_gbar_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_DBOX_MOUSE_DOWN, - .handler = client_dbox_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_DBOX_MOUSE_DOWN, + .handler = client_dbox_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_DBOX_MOUSE_UP, - .handler = client_dbox_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_DBOX_MOUSE_UP, + .handler = client_dbox_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_GBAR_MOUSE_ENTER, - .handler = client_gbar_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_GBAR_MOUSE_ENTER, + .handler = client_gbar_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_GBAR_MOUSE_LEAVE, - .handler = client_gbar_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_GBAR_MOUSE_LEAVE, + .handler = client_gbar_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_DBOX_MOUSE_ENTER, - .handler = client_dbox_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_DBOX_MOUSE_ENTER, + .handler = client_dbox_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_DBOX_MOUSE_LEAVE, - .handler = client_dbox_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ + .cmd = CMD_STR_DBOX_MOUSE_LEAVE, + .handler = client_dbox_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_DBOX_MOUSE_ON_SCROLL, - .handler = client_dbox_mouse_on_scroll, + .cmd = CMD_STR_DBOX_MOUSE_ON_SCROLL, + .handler = client_dbox_mouse_on_scroll, }, { - .cmd = CMD_STR_DBOX_MOUSE_OFF_SCROLL, - .handler = client_dbox_mouse_off_scroll, + .cmd = CMD_STR_DBOX_MOUSE_OFF_SCROLL, + .handler = client_dbox_mouse_off_scroll, }, { - .cmd = CMD_STR_GBAR_MOUSE_ON_SCROLL, - .handler = client_gbar_mouse_on_scroll, + .cmd = CMD_STR_GBAR_MOUSE_ON_SCROLL, + .handler = client_gbar_mouse_on_scroll, }, { - .cmd = CMD_STR_GBAR_MOUSE_OFF_SCROLL, - .handler = client_gbar_mouse_off_scroll, + .cmd = CMD_STR_GBAR_MOUSE_OFF_SCROLL, + .handler = client_gbar_mouse_off_scroll, }, { - .cmd = CMD_STR_DBOX_MOUSE_ON_HOLD, - .handler = client_dbox_mouse_on_hold, + .cmd = CMD_STR_DBOX_MOUSE_ON_HOLD, + .handler = client_dbox_mouse_on_hold, }, { - .cmd = CMD_STR_DBOX_MOUSE_OFF_HOLD, - .handler = client_dbox_mouse_off_hold, + .cmd = CMD_STR_DBOX_MOUSE_OFF_HOLD, + .handler = client_dbox_mouse_off_hold, }, { - .cmd = CMD_STR_GBAR_MOUSE_ON_HOLD, - .handler = client_gbar_mouse_on_hold, + .cmd = CMD_STR_GBAR_MOUSE_ON_HOLD, + .handler = client_gbar_mouse_on_hold, }, { - .cmd = CMD_STR_GBAR_MOUSE_OFF_HOLD, - .handler = client_gbar_mouse_off_hold, + .cmd = CMD_STR_GBAR_MOUSE_OFF_HOLD, + .handler = client_gbar_mouse_off_hold, }, { - .cmd = CMD_STR_CLICKED, - .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */ + .cmd = CMD_STR_CLICKED, + .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */ }, { - .cmd = CMD_STR_TEXT_SIGNAL, - .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */ + .cmd = CMD_STR_TEXT_SIGNAL, + .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */ }, { - .cmd = CMD_STR_DELETE, - .handler = client_delete, /* pid, pkgname, filename, ret */ + .cmd = CMD_STR_DELETE, + .handler = client_delete, /* pid, pkgname, filename, ret */ }, { - .cmd = CMD_STR_RESIZE, - .handler = client_resize, /* pid, pkgname, filename, w, h, ret */ + .cmd = CMD_STR_RESIZE, + .handler = client_resize, /* pid, pkgname, filename, w, h, ret */ }, { - .cmd = CMD_STR_NEW, - .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */ + .cmd = CMD_STR_NEW, + .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */ }, { - .cmd = CMD_STR_SET_PERIOD, - .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */ + .cmd = CMD_STR_SET_PERIOD, + .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */ }, { - .cmd = CMD_STR_CHANGE_GROUP, - .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */ + .cmd = CMD_STR_CHANGE_GROUP, + .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */ }, { - .cmd = CMD_STR_GBAR_MOVE, - .handler = client_gbar_move, /* pkgname, id, x, y */ + .cmd = CMD_STR_GBAR_MOVE, + .handler = client_gbar_move, /* pkgname, id, x, y */ }, { - .cmd = CMD_STR_GBAR_ACCESS_HL, - .handler = client_gbar_access_hl, + .cmd = CMD_STR_GBAR_ACCESS_HL, + .handler = client_gbar_access_hl, }, { - .cmd = CMD_STR_GBAR_ACCESS_ACTIVATE, - .handler = client_gbar_access_activate, + .cmd = CMD_STR_GBAR_ACCESS_ACTIVATE, + .handler = client_gbar_access_activate, }, { - .cmd = CMD_STR_GBAR_ACCESS_ACTION, - .handler = client_gbar_access_action, + .cmd = CMD_STR_GBAR_ACCESS_ACTION, + .handler = client_gbar_access_action, }, { - .cmd = CMD_STR_GBAR_ACCESS_SCROLL, - .handler = client_gbar_access_scroll, + .cmd = CMD_STR_GBAR_ACCESS_SCROLL, + .handler = client_gbar_access_scroll, }, { - .cmd = CMD_STR_GBAR_ACCESS_VALUE_CHANGE, - .handler = client_gbar_access_value_change, + .cmd = CMD_STR_GBAR_ACCESS_VALUE_CHANGE, + .handler = client_gbar_access_value_change, }, { - .cmd = CMD_STR_GBAR_ACCESS_MOUSE, - .handler = client_gbar_access_mouse, + .cmd = CMD_STR_GBAR_ACCESS_MOUSE, + .handler = client_gbar_access_mouse, }, { - .cmd = CMD_STR_GBAR_ACCESS_BACK, - .handler = client_gbar_access_back, + .cmd = CMD_STR_GBAR_ACCESS_BACK, + .handler = client_gbar_access_back, }, { - .cmd = CMD_STR_GBAR_ACCESS_OVER, - .handler = client_gbar_access_over, + .cmd = CMD_STR_GBAR_ACCESS_OVER, + .handler = client_gbar_access_over, }, { - .cmd = CMD_STR_GBAR_ACCESS_READ, - .handler = client_gbar_access_read, + .cmd = CMD_STR_GBAR_ACCESS_READ, + .handler = client_gbar_access_read, }, { - .cmd = CMD_STR_GBAR_ACCESS_ENABLE, - .handler = client_gbar_access_enable, + .cmd = CMD_STR_GBAR_ACCESS_ENABLE, + .handler = client_gbar_access_enable, }, { - .cmd = CMD_STR_DBOX_ACCESS_HL, - .handler = client_dbox_access_hl, + .cmd = CMD_STR_DBOX_ACCESS_HL, + .handler = client_dbox_access_hl, }, { - .cmd = CMD_STR_DBOX_ACCESS_ACTIVATE, - .handler = client_dbox_access_activate, + .cmd = CMD_STR_DBOX_ACCESS_ACTIVATE, + .handler = client_dbox_access_activate, }, { - .cmd = CMD_STR_DBOX_ACCESS_ACTION, - .handler = client_dbox_access_action, + .cmd = CMD_STR_DBOX_ACCESS_ACTION, + .handler = client_dbox_access_action, }, { - .cmd = CMD_STR_DBOX_ACCESS_SCROLL, - .handler = client_dbox_access_scroll, + .cmd = CMD_STR_DBOX_ACCESS_SCROLL, + .handler = client_dbox_access_scroll, }, { - .cmd = CMD_STR_DBOX_ACCESS_VALUE_CHANGE, - .handler = client_dbox_access_value_change, + .cmd = CMD_STR_DBOX_ACCESS_VALUE_CHANGE, + .handler = client_dbox_access_value_change, }, { - .cmd = CMD_STR_DBOX_ACCESS_MOUSE, - .handler = client_dbox_access_mouse, + .cmd = CMD_STR_DBOX_ACCESS_MOUSE, + .handler = client_dbox_access_mouse, }, { - .cmd = CMD_STR_DBOX_ACCESS_BACK, - .handler = client_dbox_access_back, + .cmd = CMD_STR_DBOX_ACCESS_BACK, + .handler = client_dbox_access_back, }, { - .cmd = CMD_STR_DBOX_ACCESS_OVER, - .handler = client_dbox_access_over, + .cmd = CMD_STR_DBOX_ACCESS_OVER, + .handler = client_dbox_access_over, }, { - .cmd = CMD_STR_DBOX_ACCESS_READ, - .handler = client_dbox_access_read, + .cmd = CMD_STR_DBOX_ACCESS_READ, + .handler = client_dbox_access_read, }, { - .cmd = CMD_STR_DBOX_ACCESS_ENABLE, - .handler = client_dbox_access_enable, + .cmd = CMD_STR_DBOX_ACCESS_ENABLE, + .handler = client_dbox_access_enable, }, { - .cmd = CMD_STR_DBOX_KEY_DOWN, - .handler = client_dbox_key_down, + .cmd = CMD_STR_DBOX_KEY_DOWN, + .handler = client_dbox_key_down, }, { - .cmd = CMD_STR_DBOX_KEY_UP, - .handler = client_dbox_key_up, + .cmd = CMD_STR_DBOX_KEY_UP, + .handler = client_dbox_key_up, }, { - .cmd = CMD_STR_DBOX_KEY_FOCUS_IN, - .handler = client_dbox_key_focus_in, + .cmd = CMD_STR_DBOX_KEY_FOCUS_IN, + .handler = client_dbox_key_focus_in, }, { - .cmd = CMD_STR_DBOX_KEY_FOCUS_OUT, - .handler = client_dbox_key_focus_out, + .cmd = CMD_STR_DBOX_KEY_FOCUS_OUT, + .handler = client_dbox_key_focus_out, }, { - .cmd = CMD_STR_GBAR_KEY_DOWN, - .handler = client_gbar_key_down, + .cmd = CMD_STR_GBAR_KEY_DOWN, + .handler = client_gbar_key_down, }, { - .cmd = CMD_STR_GBAR_KEY_UP, - .handler = client_gbar_key_up, + .cmd = CMD_STR_GBAR_KEY_UP, + .handler = client_gbar_key_up, }, { - .cmd = CMD_STR_GBAR_KEY_FOCUS_IN, - .handler = client_gbar_key_focus_in, + .cmd = CMD_STR_GBAR_KEY_FOCUS_IN, + .handler = client_gbar_key_focus_in, }, { - .cmd = CMD_STR_GBAR_KEY_FOCUS_OUT, - .handler = client_gbar_key_focus_out, + .cmd = CMD_STR_GBAR_KEY_FOCUS_OUT, + .handler = client_gbar_key_focus_out, }, { - .cmd = CMD_STR_UPDATE_MODE, - .handler = client_update_mode, + .cmd = CMD_STR_UPDATE_MODE, + .handler = client_update_mode, }, // Cut HERE. Above list must be sync'd with provider list. { - .cmd = CMD_STR_DBOX_MOUSE_SET, - .handler = client_dbox_mouse_set, + .cmd = CMD_STR_DBOX_MOUSE_SET, + .handler = client_dbox_mouse_set, }, { - .cmd = CMD_STR_DBOX_MOUSE_UNSET, - .handler = client_dbox_mouse_unset, + .cmd = CMD_STR_DBOX_MOUSE_UNSET, + .handler = client_dbox_mouse_unset, }, { - .cmd = CMD_STR_GBAR_MOUSE_SET, - .handler = client_gbar_mouse_set, + .cmd = CMD_STR_GBAR_MOUSE_SET, + .handler = client_gbar_mouse_set, }, { - .cmd = CMD_STR_GBAR_MOUSE_UNSET, - .handler = client_gbar_mouse_unset, + .cmd = CMD_STR_GBAR_MOUSE_UNSET, + .handler = client_gbar_mouse_unset, }, { - .cmd = CMD_STR_CHANGE_VISIBILITY, - .handler = client_change_visibility, + .cmd = CMD_STR_CHANGE_VISIBILITY, + .handler = client_change_visibility, }, { - .cmd = CMD_STR_DBOX_ACQUIRE_PIXMAP, - .handler = client_dbox_acquire_pixmap, + .cmd = CMD_STR_DBOX_ACQUIRE_PIXMAP, + .handler = client_dbox_acquire_pixmap, }, { - .cmd = CMD_STR_DBOX_RELEASE_PIXMAP, - .handler = client_dbox_release_pixmap, + .cmd = CMD_STR_DBOX_RELEASE_PIXMAP, + .handler = client_dbox_release_pixmap, }, { - .cmd = CMD_STR_GBAR_ACQUIRE_PIXMAP, - .handler = client_gbar_acquire_pixmap, + .cmd = CMD_STR_GBAR_ACQUIRE_PIXMAP, + .handler = client_gbar_acquire_pixmap, }, { - .cmd = CMD_STR_GBAR_RELEASE_PIXMAP, - .handler = client_gbar_release_pixmap, + .cmd = CMD_STR_GBAR_RELEASE_PIXMAP, + .handler = client_gbar_release_pixmap, }, { - .cmd = CMD_STR_ACQUIRE, - .handler = client_acquire, /*!< pid, ret */ + .cmd = CMD_STR_ACQUIRE, + .handler = client_acquire, /*!< pid, ret */ }, { - .cmd = CMD_STR_RELEASE, - .handler = cilent_release, /*!< pid, ret */ + .cmd = CMD_STR_RELEASE, + .handler = cilent_release, /*!< pid, ret */ }, { - .cmd = CMD_STR_PINUP_CHANGED, - .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */ + .cmd = CMD_STR_PINUP_CHANGED, + .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */ }, { - .cmd = CMD_STR_CREATE_GBAR, - .handler = client_create_gbar, /* pid, pkgname, filename, ret */ + .cmd = CMD_STR_CREATE_GBAR, + .handler = client_create_gbar, /* pid, pkgname, filename, ret */ }, { - .cmd = CMD_STR_DESTROY_GBAR, - .handler = client_destroy_gbar, /* pid, pkgname, filename, ret */ + .cmd = CMD_STR_DESTROY_GBAR, + .handler = client_destroy_gbar, /* pid, pkgname, filename, ret */ }, { - .cmd = CMD_STR_ACTIVATE_PACKAGE, - .handler = client_activate_package, /* pid, pkgname, ret */ + .cmd = CMD_STR_ACTIVATE_PACKAGE, + .handler = client_activate_package, /* pid, pkgname, ret */ }, { - .cmd = CMD_STR_SUBSCRIBE, /* pid, cluster, sub-cluster */ - .handler = client_subscribed, + .cmd = CMD_STR_SUBSCRIBE, /* pid, cluster, sub-cluster */ + .handler = client_subscribed, }, { - .cmd = CMD_STR_UNSUBSCRIBE, /* pid, cluster, sub-cluster */ - .handler = client_unsubscribed, + .cmd = CMD_STR_UNSUBSCRIBE, /* pid, cluster, sub-cluster */ + .handler = client_unsubscribed, }, { - .cmd = CMD_STR_DELETE_CLUSTER, - .handler = client_delete_cluster, + .cmd = CMD_STR_DELETE_CLUSTER, + .handler = client_delete_cluster, }, { - .cmd = CMD_STR_DELETE_CATEGORY, - .handler = client_delete_category, + .cmd = CMD_STR_DELETE_CATEGORY, + .handler = client_delete_category, }, { - .cmd = CMD_STR_REFRESH_GROUP, - .handler = client_refresh_group, + .cmd = CMD_STR_REFRESH_GROUP, + .handler = client_refresh_group, }, { - .cmd = CMD_STR_UPDATE, - .handler = client_update, + .cmd = CMD_STR_UPDATE, + .handler = client_update, }, { - .cmd = CMD_STR_DBOX_KEY_SET, - .handler = client_dbox_key_set, + .cmd = CMD_STR_DBOX_KEY_SET, + .handler = client_dbox_key_set, }, { - .cmd = CMD_STR_DBOX_KEY_UNSET, - .handler = client_dbox_key_unset, + .cmd = CMD_STR_DBOX_KEY_UNSET, + .handler = client_dbox_key_unset, }, { - .cmd = CMD_STR_GBAR_KEY_SET, - .handler = client_gbar_key_set, + .cmd = CMD_STR_GBAR_KEY_SET, + .handler = client_gbar_key_set, }, { - .cmd = CMD_STR_GBAR_KEY_UNSET, - .handler = client_gbar_key_unset, + .cmd = CMD_STR_GBAR_KEY_UNSET, + .handler = client_gbar_key_unset, }, { - .cmd = CMD_STR_CLIENT_PAUSED, - .handler = client_pause_request, + .cmd = CMD_STR_CLIENT_PAUSED, + .handler = client_pause_request, }, { - .cmd = CMD_STR_CLIENT_RESUMED, - .handler = client_resume_request, + .cmd = CMD_STR_CLIENT_RESUMED, + .handler = client_resume_request, }, { - .cmd = CMD_STR_DBOX_ACQUIRE_XPIXMAP, - .handler = client_dbox_acquire_xpixmap, + .cmd = CMD_STR_DBOX_ACQUIRE_XPIXMAP, + .handler = client_dbox_acquire_xpixmap, }, { - .cmd = CMD_STR_GBAR_ACQUIRE_XPIXMAP, - .handler = client_gbar_acquire_xpixmap, + .cmd = CMD_STR_GBAR_ACQUIRE_XPIXMAP, + .handler = client_gbar_acquire_xpixmap, }, { - .cmd = NULL, - .handler = NULL, + .cmd = NULL, + .handler = NULL, }, -}; + }; -static struct method s_service_table[] = { + static struct method s_service_table[] = { { - .cmd = CMD_STR_SERVICE_UPDATE, - .handler = service_update, + .cmd = CMD_STR_SERVICE_UPDATE, + .handler = service_update, }, { - .cmd = CMD_STR_SERVICE_CHANGE_PERIOD, - .handler = service_change_period, + .cmd = CMD_STR_SERVICE_CHANGE_PERIOD, + .handler = service_change_period, }, { - .cmd = CMD_STR_SERVICE_INST_CNT, - .handler = service_instance_count, + .cmd = CMD_STR_SERVICE_INST_CNT, + .handler = service_instance_count, }, { - .cmd = NULL, - .handler = NULL, + .cmd = NULL, + .handler = NULL, }, -}; + }; -static struct method s_slave_table[] = { + static struct method s_slave_table[] = { { - .cmd = CMD_STR_UPDATED, - .handler = slave_updated, /* slave_name, pkgname, filename, width, height, ret */ + .cmd = CMD_STR_UPDATED, + .handler = slave_updated, /* slave_name, pkgname, filename, width, height, ret */ }, { - .cmd = CMD_STR_DESC_UPDATED, - .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */ + .cmd = CMD_STR_DESC_UPDATED, + .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */ }, { - .cmd = CMD_STR_EXTRA_UPDATED, - .handler = slave_extra_updated, + .cmd = CMD_STR_EXTRA_UPDATED, + .handler = slave_extra_updated, }, { - .cmd = CMD_STR_EXTRA_INFO, - .handler = slave_extra_info, /* slave_name, pkgname, filename, priority, content_info, title, icon, name */ + .cmd = CMD_STR_EXTRA_INFO, + .handler = slave_extra_info, /* slave_name, pkgname, filename, priority, content_info, title, icon, name */ }, { - .cmd = CMD_STR_DELETED, - .handler = slave_deleted, /* slave_name, pkgname, filename, ret */ + .cmd = CMD_STR_DELETED, + .handler = slave_deleted, /* slave_name, pkgname, filename, ret */ }, { - .cmd = CMD_STR_FAULTED, - .handler = slave_faulted, /* slave_name, pkgname, id, funcname */ + .cmd = CMD_STR_FAULTED, + .handler = slave_faulted, /* slave_name, pkgname, id, funcname */ }, { - .cmd = CMD_STR_SCROLL, - .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */ + .cmd = CMD_STR_SCROLL, + .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */ }, { - .cmd = CMD_STR_DBOX_UPDATE_BEGIN, - .handler = slave_dbox_update_begin, + .cmd = CMD_STR_DBOX_UPDATE_BEGIN, + .handler = slave_dbox_update_begin, }, { - .cmd = CMD_STR_DBOX_UPDATE_END, - .handler = slave_dbox_update_end, + .cmd = CMD_STR_DBOX_UPDATE_END, + .handler = slave_dbox_update_end, }, { - .cmd = CMD_STR_GBAR_UPDATE_BEGIN, - .handler = slave_gbar_update_begin, + .cmd = CMD_STR_GBAR_UPDATE_BEGIN, + .handler = slave_gbar_update_begin, }, { - .cmd = CMD_STR_GBAR_UPDATE_END, - .handler = slave_gbar_update_end, + .cmd = CMD_STR_GBAR_UPDATE_END, + .handler = slave_gbar_update_end, }, { - .cmd = CMD_STR_ACCESS_STATUS, - .handler = slave_access_status, + .cmd = CMD_STR_ACCESS_STATUS, + .handler = slave_access_status, }, { - .cmd = CMD_STR_KEY_STATUS, - .handler = slave_key_status, + .cmd = CMD_STR_KEY_STATUS, + .handler = slave_key_status, }, { - .cmd = CMD_STR_CLOSE_GBAR, - .handler = slave_close_gbar, + .cmd = CMD_STR_CLOSE_GBAR, + .handler = slave_close_gbar, }, { - .cmd = CMD_STR_CALL, - .handler = slave_call, /* slave_name, pkgname, filename, function, ret */ + .cmd = CMD_STR_CALL, + .handler = slave_call, /* slave_name, pkgname, filename, function, ret */ }, { - .cmd = CMD_STR_RET, - .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */ + .cmd = CMD_STR_RET, + .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */ }, { - .cmd = CMD_STR_ACQUIRE_BUFFER, - .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */ + .cmd = CMD_STR_ACQUIRE_BUFFER, + .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */ }, { - .cmd = CMD_STR_RESIZE_BUFFER, - .handler = slave_resize_buffer, + .cmd = CMD_STR_RESIZE_BUFFER, + .handler = slave_resize_buffer, }, { - .cmd = CMD_STR_RELEASE_BUFFER, - .handler = slave_release_buffer, /* slave_name, id - ret */ + .cmd = CMD_STR_RELEASE_BUFFER, + .handler = slave_release_buffer, /* slave_name, id - ret */ }, { - .cmd = CMD_STR_HELLO, - .handler = slave_hello, /* slave_name, ret */ + .cmd = CMD_STR_HELLO, + .handler = slave_hello, /* slave_name, ret */ }, { - .cmd = CMD_STR_PING, - .handler = slave_ping, /* slave_name, ret */ + .cmd = CMD_STR_PING, + .handler = slave_ping, /* slave_name, ret */ }, { - .cmd = CMD_STR_CTRL, - .handler = slave_ctrl, /* control bits */ + .cmd = CMD_STR_CTRL, + .handler = slave_ctrl, /* control bits */ }, { - .cmd = CMD_STR_ACQUIRE_XBUFFER, - .handler = slave_acquire_extra_buffer, + .cmd = CMD_STR_ACQUIRE_XBUFFER, + .handler = slave_acquire_extra_buffer, }, { - .cmd = CMD_STR_RELEASE_XBUFFER, - .handler = slave_release_extra_buffer, + .cmd = CMD_STR_RELEASE_XBUFFER, + .handler = slave_release_extra_buffer, }, { - .cmd = NULL, - .handler = NULL, + .cmd = NULL, + .handler = NULL, }, -}; + }; -HAPI int server_init(void) -{ + HAPI int server_init(void) + { com_core_packet_use_thread(DYNAMICBOX_CONF_COM_CORE_THREAD); if (unlink(INFO_SOCKET) < 0) { - ErrPrint("info socket: %s\n", strerror(errno)); + ErrPrint("info socket: %s\n", strerror(errno)); } if (unlink(SLAVE_SOCKET) < 0) { - ErrPrint("slave socket: %s\n", strerror(errno)); + ErrPrint("slave socket: %s\n", strerror(errno)); } if (unlink(CLIENT_SOCKET) < 0) { - ErrPrint("client socket: %s\n", strerror(errno)); + ErrPrint("client socket: %s\n", strerror(errno)); } if (unlink(SERVICE_SOCKET) < 0) { - ErrPrint("service socket: %s\n", strerror(errno)); + ErrPrint("service socket: %s\n", strerror(errno)); } s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table); if (s_info.info_fd < 0) { - ErrPrint("Failed to create a info socket\n"); + ErrPrint("Failed to create a info socket\n"); } s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table); if (s_info.slave_fd < 0) { - ErrPrint("Failed to create a slave socket\n"); + ErrPrint("Failed to create a slave socket\n"); } s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table); if (s_info.client_fd < 0) { - ErrPrint("Failed to create a client socket\n"); + ErrPrint("Failed to create a client socket\n"); } /*! @@ -8695,61 +8747,61 @@ HAPI int server_init(void) */ s_info.remote_client_fd = com_core_packet_server_init("remote://:"CLIENT_PORT, s_client_table); if (s_info.client_fd < 0) { - ErrPrint("Failed to create a remote client socket\n"); + ErrPrint("Failed to create a remote client socket\n"); } s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table); if (s_info.service_fd < 0) { - ErrPrint("Faild to create a service socket\n"); + ErrPrint("Faild to create a service socket\n"); } if (chmod(INFO_SOCKET, 0600) < 0) { - ErrPrint("info socket: %s\n", strerror(errno)); + ErrPrint("info socket: %s\n", strerror(errno)); } if (chmod(SLAVE_SOCKET, 0666) < 0) { - ErrPrint("slave socket: %s\n", strerror(errno)); + ErrPrint("slave socket: %s\n", strerror(errno)); } if (chmod(CLIENT_SOCKET, 0666) < 0) { - ErrPrint("client socket: %s\n", strerror(errno)); + ErrPrint("client socket: %s\n", strerror(errno)); } if (chmod(SERVICE_SOCKET, 0666) < 0) { - ErrPrint("service socket: %s\n", strerror(errno)); + ErrPrint("service socket: %s\n", strerror(errno)); } return 0; -} + } -HAPI int server_fini(void) -{ + HAPI int server_fini(void) + { if (s_info.info_fd > 0) { - com_core_packet_server_fini(s_info.info_fd); - s_info.info_fd = -1; + com_core_packet_server_fini(s_info.info_fd); + s_info.info_fd = -1; } if (s_info.slave_fd > 0) { - com_core_packet_server_fini(s_info.slave_fd); - s_info.slave_fd = -1; + com_core_packet_server_fini(s_info.slave_fd); + s_info.slave_fd = -1; } if (s_info.client_fd > 0) { - com_core_packet_server_fini(s_info.client_fd); - s_info.client_fd = -1; + com_core_packet_server_fini(s_info.client_fd); + s_info.client_fd = -1; } if (s_info.remote_client_fd > 0) { - com_core_packet_server_fini(s_info.remote_client_fd); - s_info.remote_client_fd = -1; + com_core_packet_server_fini(s_info.remote_client_fd); + s_info.remote_client_fd = -1; } if (s_info.service_fd > 0) { - com_core_packet_server_fini(s_info.service_fd); - s_info.service_fd = -1; + com_core_packet_server_fini(s_info.service_fd); + s_info.service_fd = -1; } return 0; -} + } -/* End of a file */ + /* End of a file */ diff --git a/src/service_common.c b/src/service_common.c index c553abc..6fd0909 100644 --- a/src/service_common.c +++ b/src/service_common.c @@ -47,24 +47,24 @@ int errno; struct service_event_item { - enum { - SERVICE_EVENT_TIMER - } type; - - union { - struct { - int fd; - } timer; - } info; - - int (*event_cb)(struct service_context *svc_cx, void *data); - void *cbdata; + enum { + SERVICE_EVENT_TIMER + } type; + + union { + struct { + int fd; + } timer; + } info; + + int (*event_cb)(struct service_context *svc_cx, void *data); + void *cbdata; }; struct tcb_event_cbdata { - struct tcb *tcb; - void (*cb)(struct service_context *svc_ctx, struct tcb *tcb, void *data); - void *data; + struct tcb *tcb; + void (*cb)(struct service_context *svc_ctx, struct tcb *tcb, void *data); + void *data; }; /*! @@ -72,29 +72,29 @@ struct tcb_event_cbdata { * Server information and global (only in this file-scope) variables are defined */ struct service_context { - pthread_t server_thid; /*!< Server thread Id */ - int fd; /*!< Server socket handle */ + pthread_t server_thid; /*!< Server thread Id */ + int fd; /*!< Server socket handle */ - Eina_List *tcb_list; /*!< TCB list, list of every thread for client connections */ - pthread_mutex_t tcb_list_lock; + Eina_List *tcb_list; /*!< TCB list, list of every thread for client connections */ + pthread_mutex_t tcb_list_lock; - Eina_List *packet_list; - pthread_mutex_t packet_list_lock; - int evt_pipe[PIPE_MAX]; - int tcb_pipe[PIPE_MAX]; + Eina_List *packet_list; + pthread_mutex_t packet_list_lock; + int evt_pipe[PIPE_MAX]; + int tcb_pipe[PIPE_MAX]; - int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data); - void *service_thread_data; + int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data); + void *service_thread_data; - Eina_List *event_list; + Eina_List *event_list; - Eina_List *tcb_create_cb_list; - Eina_List *tcb_destroy_cb_list; + Eina_List *tcb_create_cb_list; + Eina_List *tcb_destroy_cb_list; }; struct packet_info { - struct tcb *tcb; - struct packet *packet; + struct tcb *tcb; + struct packet *packet; }; /*! @@ -104,12 +104,12 @@ struct packet_info { * When a new client is comming to us, this TCB block will be allocated and initialized. */ struct tcb { /* Thread controll block */ - struct service_context *svc_ctx; - pthread_t thid; /*!< Thread Id */ - int fd; /*!< Connection handle */ - enum tcb_type type; - int ctrl_pipe[PIPE_MAX]; - pid_t pid; /*!< Keep the PID of client, if the client is remote one, this will be -1 */ + struct service_context *svc_ctx; + pthread_t thid; /*!< Thread Id */ + int fd; /*!< Connection handle */ + enum tcb_type type; + int ctrl_pipe[PIPE_MAX]; + pid_t pid; /*!< Keep the PID of client, if the client is remote one, this will be -1 */ }; /*! @@ -119,227 +119,227 @@ struct tcb { /* Thread controll block */ */ static void *client_packet_pump_main(void *data) { - struct tcb *tcb = data; - struct service_context *svc_ctx = tcb->svc_ctx; - struct packet *packet = NULL; - fd_set set; - char *ptr = NULL; - int size = 0; - int packet_offset = 0; - int recv_offset = 0; - long ret; - int fd; - char evt_ch = EVT_CH; - enum { - RECV_INIT, - RECV_HEADER, - RECV_PAYLOAD, - RECV_DONE, - } recv_state; - struct packet_info *packet_info; - Eina_List *l; - - ret = 0; - recv_state = RECV_INIT; + struct tcb *tcb = data; + struct service_context *svc_ctx = tcb->svc_ctx; + struct packet *packet = NULL; + fd_set set; + char *ptr = NULL; + int size = 0; + int packet_offset = 0; + int recv_offset = 0; + long ret; + int fd; + char evt_ch = EVT_CH; + enum { + RECV_INIT, + RECV_HEADER, + RECV_PAYLOAD, + RECV_DONE, + } recv_state; + struct packet_info *packet_info; + Eina_List *l; + + ret = 0; + recv_state = RECV_INIT; + /*! + * \note + * To escape from the switch statement, we use this ret value + */ + while (ret == 0) { + FD_ZERO(&set); + FD_SET(tcb->fd, &set); + FD_SET(tcb->ctrl_pipe[PIPE_READ], &set); + fd = tcb->fd > tcb->ctrl_pipe[PIPE_READ] ? tcb->fd : tcb->ctrl_pipe[PIPE_READ]; + ret = select(fd + 1, &set, NULL, NULL, NULL); + if (ret < 0) { + ret = -errno; + if (errno == EINTR) { + ErrPrint("INTERRUPTED\n"); + ret = 0; + continue; + } + ErrPrint("Error: %s\n", strerror(errno)); + DbgFree(ptr); + ptr = NULL; + break; + } else if (ret == 0) { + ErrPrint("Timeout\n"); + ret = -ETIMEDOUT; + DbgFree(ptr); + ptr = NULL; + break; + } + + if (FD_ISSET(tcb->ctrl_pipe[PIPE_READ], &set)) { + DbgPrint("Thread is canceled\n"); + ret = -ECANCELED; + DbgFree(ptr); + ptr = NULL; + break; + } + + if (!FD_ISSET(tcb->fd, &set)) { + ErrPrint("Unexpected handler is toggled\n"); + ret = -EINVAL; + DbgFree(ptr); + ptr = NULL; + break; + } + /*! - * \note - * To escape from the switch statement, we use this ret value + * \TODO + * Service!!! Receive packet & route packet */ - while (ret == 0) { - FD_ZERO(&set); - FD_SET(tcb->fd, &set); - FD_SET(tcb->ctrl_pipe[PIPE_READ], &set); - fd = tcb->fd > tcb->ctrl_pipe[PIPE_READ] ? tcb->fd : tcb->ctrl_pipe[PIPE_READ]; - ret = select(fd + 1, &set, NULL, NULL, NULL); - if (ret < 0) { - ret = -errno; - if (errno == EINTR) { - ErrPrint("INTERRUPTED\n"); - ret = 0; - continue; - } - ErrPrint("Error: %s\n", strerror(errno)); - DbgFree(ptr); - ptr = NULL; - break; - } else if (ret == 0) { - ErrPrint("Timeout\n"); - ret = -ETIMEDOUT; - DbgFree(ptr); - ptr = NULL; - break; + switch (recv_state) { + case RECV_INIT: + size = packet_header_size(); + packet_offset = 0; + recv_offset = 0; + packet = NULL; + ptr = malloc(size); + if (!ptr) { + ErrPrint("Heap: %s\n", strerror(errno)); + ret = -ENOMEM; + break; } - - if (FD_ISSET(tcb->ctrl_pipe[PIPE_READ], &set)) { - DbgPrint("Thread is canceled\n"); + recv_state = RECV_HEADER; + /* Go through, don't break from here */ + case RECV_HEADER: + ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); + if (ret <= 0) { + if (ret == 0) { ret = -ECANCELED; - DbgFree(ptr); - ptr = NULL; - break; + } + DbgFree(ptr); + ptr = NULL; + break; } - if (!FD_ISSET(tcb->fd, &set)) { - ErrPrint("Unexpected handler is toggled\n"); - ret = -EINVAL; - DbgFree(ptr); - ptr = NULL; + recv_offset += ret; + ret = 0; + + if (recv_offset == size) { + packet = packet_build(packet, packet_offset, ptr, size); + DbgFree(ptr); + ptr = NULL; + if (!packet) { + ret = -EFAULT; break; - } + } - /*! - * \TODO - * Service!!! Receive packet & route packet - */ - switch (recv_state) { - case RECV_INIT: - size = packet_header_size(); - packet_offset = 0; + packet_offset += recv_offset; + + size = packet_payload_size(packet); + if (size <= 0) { + recv_state = RECV_DONE; recv_offset = 0; - packet = NULL; - ptr = malloc(size); - if (!ptr) { - ErrPrint("Heap: %s\n", strerror(errno)); - ret = -ENOMEM; - break; - } - recv_state = RECV_HEADER; - /* Go through, don't break from here */ - case RECV_HEADER: - ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); - if (ret <= 0) { - if (ret == 0) { - ret = -ECANCELED; - } - DbgFree(ptr); - ptr = NULL; - break; - } - - recv_offset += ret; - ret = 0; - - if (recv_offset == size) { - packet = packet_build(packet, packet_offset, ptr, size); - DbgFree(ptr); - ptr = NULL; - if (!packet) { - ret = -EFAULT; - break; - } - - packet_offset += recv_offset; - - size = packet_payload_size(packet); - if (size <= 0) { - recv_state = RECV_DONE; - recv_offset = 0; - break; - } - - recv_state = RECV_PAYLOAD; - recv_offset = 0; - - ptr = malloc(size); - if (!ptr) { - ErrPrint("Heap: %s\n", strerror(errno)); - ret = -ENOMEM; - } - } - break; - case RECV_PAYLOAD: - ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); - if (ret <= 0) { - if (ret == 0) { - ret = -ECANCELED; - } - DbgFree(ptr); - ptr = NULL; - break; - } - - recv_offset += ret; - ret = 0; - - if (recv_offset == size) { - packet = packet_build(packet, packet_offset, ptr, size); - DbgFree(ptr); - ptr = NULL; - if (!packet) { - ret = -EFAULT; - break; - } - - packet_offset += recv_offset; - - recv_state = RECV_DONE; - recv_offset = 0; - } - break; - case RECV_DONE: - default: - /* Dead code */ break; - } + } + + recv_state = RECV_PAYLOAD; + recv_offset = 0; - if (recv_state == RECV_DONE) { - /*! - * Push this packet to the packet list with TCB - * Then the service main function will get this. - */ - packet_info = malloc(sizeof(*packet_info)); - if (!packet_info) { - ret = -errno; - ErrPrint("Heap: %s\n", strerror(errno)); - packet_destroy(packet); - break; - } - - packet_info->packet = packet; - packet_info->tcb = tcb; - - CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); - svc_ctx->packet_list = eina_list_append(svc_ctx->packet_list, packet_info); - CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); - - if (write(svc_ctx->evt_pipe[PIPE_WRITE], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) { - ret = -errno; - ErrPrint("Unable to write a pipe: %s\n", strerror(errno)); - CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); - svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); - CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); - - packet_destroy(packet); - DbgFree(packet_info); - ErrPrint("Terminate thread: %p\n", tcb); - break; - } else { - DbgPrint("Packet received: %d bytes\n", packet_offset); - recv_state = RECV_INIT; - } - - /* Take a breathe */ - pthread_yield(); + ptr = malloc(size); + if (!ptr) { + ErrPrint("Heap: %s\n", strerror(errno)); + ret = -ENOMEM; + } + } + break; + case RECV_PAYLOAD: + ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); + if (ret <= 0) { + if (ret == 0) { + ret = -ECANCELED; + } + DbgFree(ptr); + ptr = NULL; + break; } - } - CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); - EINA_LIST_FOREACH(svc_ctx->packet_list, l, packet_info) { - if (packet_info->tcb == tcb) { - DbgPrint("Reset ptr of the TCB[%p] in the list of packet info\n", tcb); - packet_info->tcb = NULL; + recv_offset += ret; + ret = 0; + + if (recv_offset == size) { + packet = packet_build(packet, packet_offset, ptr, size); + DbgFree(ptr); + ptr = NULL; + if (!packet) { + ret = -EFAULT; + break; + } + + packet_offset += recv_offset; + + recv_state = RECV_DONE; + recv_offset = 0; } + break; + case RECV_DONE: + default: + /* Dead code */ + break; } - CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); - /*! - * \note - * Emit a signal to collect this TCB from the SERVER THREAD. - */ - if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) { - ErrPrint("Unable to write pipe: %s\n", strerror(errno)); + if (recv_state == RECV_DONE) { + /*! + * Push this packet to the packet list with TCB + * Then the service main function will get this. + */ + packet_info = malloc(sizeof(*packet_info)); + if (!packet_info) { + ret = -errno; + ErrPrint("Heap: %s\n", strerror(errno)); + packet_destroy(packet); + break; + } + + packet_info->packet = packet; + packet_info->tcb = tcb; + + CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); + svc_ctx->packet_list = eina_list_append(svc_ctx->packet_list, packet_info); + CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); + + if (write(svc_ctx->evt_pipe[PIPE_WRITE], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) { + ret = -errno; + ErrPrint("Unable to write a pipe: %s\n", strerror(errno)); + CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); + svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); + CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); + + packet_destroy(packet); + DbgFree(packet_info); + ErrPrint("Terminate thread: %p\n", tcb); + break; + } else { + DbgPrint("Packet received: %d bytes\n", packet_offset); + recv_state = RECV_INIT; + } + + /* Take a breathe */ + pthread_yield(); } + } - return (void *)ret; + CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); + EINA_LIST_FOREACH(svc_ctx->packet_list, l, packet_info) { + if (packet_info->tcb == tcb) { + DbgPrint("Reset ptr of the TCB[%p] in the list of packet info\n", tcb); + packet_info->tcb = NULL; + } + } + CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); + + /*! + * \note + * Emit a signal to collect this TCB from the SERVER THREAD. + */ + if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) { + ErrPrint("Unable to write pipe: %s\n", strerror(errno)); + } + + return (void *)ret; } /*! @@ -348,34 +348,34 @@ static void *client_packet_pump_main(void *data) */ HAPI int service_register_tcb_callback(struct service_context *svc_ctx, struct tcb *tcb, enum tcb_event_type event, void (*cb)(struct service_context *svc_ctx, struct tcb *tcb, void *data), void *data) { - struct tcb_event_cbdata *cbdata; + struct tcb_event_cbdata *cbdata; - cbdata = malloc(sizeof(*cbdata)); - if (!cbdata) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + cbdata = malloc(sizeof(*cbdata)); + if (!cbdata) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - cbdata->tcb = tcb; - cbdata->cb = cb; - cbdata->data = data; + cbdata->tcb = tcb; + cbdata->cb = cb; + cbdata->data = data; - switch (event) { + switch (event) { case TCB_EVENT_CREATE: - if (tcb) { - DbgPrint("To catch the create event of TCB does not requires \"tcb\" handle\n"); - } - svc_ctx->tcb_create_cb_list = eina_list_append(svc_ctx->tcb_create_cb_list, cbdata); - break; + if (tcb) { + DbgPrint("To catch the create event of TCB does not requires \"tcb\" handle\n"); + } + svc_ctx->tcb_create_cb_list = eina_list_append(svc_ctx->tcb_create_cb_list, cbdata); + break; case TCB_EVENT_DESTROY: - svc_ctx->tcb_destroy_cb_list = eina_list_append(svc_ctx->tcb_destroy_cb_list, cbdata); - break; + svc_ctx->tcb_destroy_cb_list = eina_list_append(svc_ctx->tcb_destroy_cb_list, cbdata); + break; default: - DbgFree(cbdata); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + DbgFree(cbdata); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /*! @@ -384,33 +384,33 @@ HAPI int service_register_tcb_callback(struct service_context *svc_ctx, struct t */ HAPI int service_unregister_tcb_callback(struct service_context *svc_ctx, struct tcb *tcb, enum tcb_event_type event, void (*cb)(struct service_context *svc_ctx, struct tcb *tcb, void *data), void *data) { - struct tcb_event_cbdata *cbdata; - Eina_List *l; + struct tcb_event_cbdata *cbdata; + Eina_List *l; - switch (event) { + switch (event) { case TCB_EVENT_CREATE: - EINA_LIST_FOREACH(svc_ctx->tcb_create_cb_list, l, cbdata) { - if (cbdata->tcb == tcb && cbdata->cb == cb && cbdata->data == data) { - svc_ctx->tcb_create_cb_list = eina_list_remove(svc_ctx->tcb_create_cb_list, cbdata); - DbgFree(cbdata); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH(svc_ctx->tcb_create_cb_list, l, cbdata) { + if (cbdata->tcb == tcb && cbdata->cb == cb && cbdata->data == data) { + svc_ctx->tcb_create_cb_list = eina_list_remove(svc_ctx->tcb_create_cb_list, cbdata); + DbgFree(cbdata); + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case TCB_EVENT_DESTROY: - EINA_LIST_FOREACH(svc_ctx->tcb_destroy_cb_list, l, cbdata) { - if (cbdata->tcb == tcb && cbdata->cb == cb && cbdata->data == data) { - svc_ctx->tcb_destroy_cb_list = eina_list_remove(svc_ctx->tcb_destroy_cb_list, cbdata); - DbgFree(cbdata); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH(svc_ctx->tcb_destroy_cb_list, l, cbdata) { + if (cbdata->tcb == tcb && cbdata->cb == cb && cbdata->data == data) { + svc_ctx->tcb_destroy_cb_list = eina_list_remove(svc_ctx->tcb_destroy_cb_list, cbdata); + DbgFree(cbdata); + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } /*! @@ -419,55 +419,55 @@ HAPI int service_unregister_tcb_callback(struct service_context *svc_ctx, struct */ static inline struct tcb *tcb_create(struct service_context *svc_ctx, int fd) { - struct tcb *tcb; - int status; - struct tcb_event_cbdata *cbdata; - Eina_List *l; - Eina_List *n; - - tcb = malloc(sizeof(*tcb)); - if (!tcb) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - if (pipe2(tcb->ctrl_pipe, O_CLOEXEC) < 0) { - ErrPrint("pipe2: %s\n", strerror(errno)); - DbgFree(tcb); - return NULL; - } - - tcb->fd = fd; - tcb->svc_ctx = svc_ctx; - tcb->type = TCB_CLIENT_TYPE_APP; - tcb->pid = -1; - - DbgPrint("Create a new service thread [%d]\n", fd); - status = pthread_create(&tcb->thid, NULL, client_packet_pump_main, tcb); - if (status != 0) { - ErrPrint("Unable to create a new thread: %s\n", strerror(status)); - CLOSE_PIPE(tcb->ctrl_pipe); - DbgFree(tcb); - return NULL; + struct tcb *tcb; + int status; + struct tcb_event_cbdata *cbdata; + Eina_List *l; + Eina_List *n; + + tcb = malloc(sizeof(*tcb)); + if (!tcb) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + if (pipe2(tcb->ctrl_pipe, O_CLOEXEC) < 0) { + ErrPrint("pipe2: %s\n", strerror(errno)); + DbgFree(tcb); + return NULL; + } + + tcb->fd = fd; + tcb->svc_ctx = svc_ctx; + tcb->type = TCB_CLIENT_TYPE_APP; + tcb->pid = -1; + + DbgPrint("Create a new service thread [%d]\n", fd); + status = pthread_create(&tcb->thid, NULL, client_packet_pump_main, tcb); + if (status != 0) { + ErrPrint("Unable to create a new thread: %s\n", strerror(status)); + CLOSE_PIPE(tcb->ctrl_pipe); + DbgFree(tcb); + return NULL; + } + + CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock); + svc_ctx->tcb_list = eina_list_append(svc_ctx->tcb_list, tcb); + CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock); + + EINA_LIST_FOREACH_SAFE(svc_ctx->tcb_create_cb_list, l, n, cbdata) { + if (!cbdata->cb) { + /* ASSERT */ + ErrPrint("invalid CB\n"); + svc_ctx->tcb_create_cb_list = eina_list_remove(svc_ctx->tcb_create_cb_list, cbdata); + DbgFree(cbdata); + continue; } - CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock); - svc_ctx->tcb_list = eina_list_append(svc_ctx->tcb_list, tcb); - CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock); - - EINA_LIST_FOREACH_SAFE(svc_ctx->tcb_create_cb_list, l, n, cbdata) { - if (!cbdata->cb) { - /* ASSERT */ - ErrPrint("invalid CB\n"); - svc_ctx->tcb_create_cb_list = eina_list_remove(svc_ctx->tcb_create_cb_list, cbdata); - DbgFree(cbdata); - continue; - } - - cbdata->cb(svc_ctx, tcb, cbdata->data); - } + cbdata->cb(svc_ctx, tcb, cbdata->data); + } - return tcb; + return tcb; } /*! @@ -476,131 +476,131 @@ static inline struct tcb *tcb_create(struct service_context *svc_ctx, int fd) */ static inline void tcb_teminate_all(struct service_context *svc_ctx) { - struct tcb *tcb; - void *ret; - int status; - char ch = EVT_END_CH; - - /*! - * We don't need to make critical section on here. - * If we call this after terminate the server thread first. - * Then there is no other thread to access tcb_list. - */ - EINA_LIST_FREE(svc_ctx->tcb_list, tcb) { - /*! - * ASSERT(tcb->fd >= 0); - */ - if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) { - ErrPrint("write: %s\n", strerror(errno)); - } - - status = pthread_join(tcb->thid, &ret); - if (status != 0) { - ErrPrint("Unable to join a thread: %s\n", strerror(status)); - } else { - DbgPrint("Thread returns: %p\n", ret); - } - - secure_socket_destroy_handle(tcb->fd); - - CLOSE_PIPE(tcb->ctrl_pipe); - DbgFree(tcb); - } -} - -/*! - * \note - * SERVER THREAD - */ -static inline void tcb_destroy(struct service_context *svc_ctx, struct tcb *tcb) -{ - void *ret; - int status; - char ch = EVT_END_CH; - struct tcb_event_cbdata *cbdata; - Eina_List *l; - Eina_List *n; - - EINA_LIST_FOREACH_SAFE(svc_ctx->tcb_destroy_cb_list, l, n, cbdata) { - if (!cbdata->cb) { - /* ASSERT */ - ErrPrint("invalid CB\n"); - svc_ctx->tcb_destroy_cb_list = eina_list_remove(svc_ctx->tcb_destroy_cb_list, cbdata); - DbgFree(cbdata); - continue; - } - - if (cbdata->tcb != tcb) { - continue; - } - - cbdata->cb(svc_ctx, tcb, cbdata->data); - - if (eina_list_data_find(svc_ctx->tcb_destroy_cb_list, cbdata)) { - svc_ctx->tcb_destroy_cb_list = eina_list_remove(svc_ctx->tcb_destroy_cb_list, cbdata); - DbgFree(cbdata); - } - } - - CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock); - svc_ctx->tcb_list = eina_list_remove(svc_ctx->tcb_list, tcb); - CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock); + struct tcb *tcb; + void *ret; + int status; + char ch = EVT_END_CH; + + /*! + * We don't need to make critical section on here. + * If we call this after terminate the server thread first. + * Then there is no other thread to access tcb_list. + */ + EINA_LIST_FREE(svc_ctx->tcb_list, tcb) { /*! * ASSERT(tcb->fd >= 0); - * Close the connection, and then collecting the return value of thread */ if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) { - ErrPrint("write: %s\n", strerror(errno)); + ErrPrint("write: %s\n", strerror(errno)); } status = pthread_join(tcb->thid, &ret); if (status != 0) { - ErrPrint("Unable to join a thread: %s\n", strerror(status)); + ErrPrint("Unable to join a thread: %s\n", strerror(status)); } else { - DbgPrint("Thread returns: %p\n", ret); + DbgPrint("Thread returns: %p\n", ret); } secure_socket_destroy_handle(tcb->fd); CLOSE_PIPE(tcb->ctrl_pipe); DbgFree(tcb); + } } /*! * \note * SERVER THREAD */ -static inline int update_fdset(struct service_context *svc_ctx, fd_set *set) +static inline void tcb_destroy(struct service_context *svc_ctx, struct tcb *tcb) { - Eina_List *l; - struct service_event_item *item; - int fd = 0; - - FD_ZERO(set); - - FD_SET(svc_ctx->fd, set); - fd = svc_ctx->fd; + void *ret; + int status; + char ch = EVT_END_CH; + struct tcb_event_cbdata *cbdata; + Eina_List *l; + Eina_List *n; + + EINA_LIST_FOREACH_SAFE(svc_ctx->tcb_destroy_cb_list, l, n, cbdata) { + if (!cbdata->cb) { + /* ASSERT */ + ErrPrint("invalid CB\n"); + svc_ctx->tcb_destroy_cb_list = eina_list_remove(svc_ctx->tcb_destroy_cb_list, cbdata); + DbgFree(cbdata); + continue; + } - FD_SET(svc_ctx->tcb_pipe[PIPE_READ], set); - if (svc_ctx->tcb_pipe[PIPE_READ] > fd) { - fd = svc_ctx->tcb_pipe[PIPE_READ]; + if (cbdata->tcb != tcb) { + continue; } - FD_SET(svc_ctx->evt_pipe[PIPE_READ], set); - if (svc_ctx->evt_pipe[PIPE_READ] > fd) { - fd = svc_ctx->evt_pipe[PIPE_READ]; + cbdata->cb(svc_ctx, tcb, cbdata->data); + + if (eina_list_data_find(svc_ctx->tcb_destroy_cb_list, cbdata)) { + svc_ctx->tcb_destroy_cb_list = eina_list_remove(svc_ctx->tcb_destroy_cb_list, cbdata); + DbgFree(cbdata); } + } + + CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock); + svc_ctx->tcb_list = eina_list_remove(svc_ctx->tcb_list, tcb); + CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock); + /*! + * ASSERT(tcb->fd >= 0); + * Close the connection, and then collecting the return value of thread + */ + if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) { + ErrPrint("write: %s\n", strerror(errno)); + } + + status = pthread_join(tcb->thid, &ret); + if (status != 0) { + ErrPrint("Unable to join a thread: %s\n", strerror(status)); + } else { + DbgPrint("Thread returns: %p\n", ret); + } + + secure_socket_destroy_handle(tcb->fd); + + CLOSE_PIPE(tcb->ctrl_pipe); + DbgFree(tcb); +} - EINA_LIST_FOREACH(svc_ctx->event_list, l, item) { - if (item->type == SERVICE_EVENT_TIMER) { - FD_SET(item->info.timer.fd, set); - if (fd < item->info.timer.fd) { - fd = item->info.timer.fd; - } - } +/*! + * \note + * SERVER THREAD + */ +static inline int update_fdset(struct service_context *svc_ctx, fd_set *set) +{ + Eina_List *l; + struct service_event_item *item; + int fd = 0; + + FD_ZERO(set); + + FD_SET(svc_ctx->fd, set); + fd = svc_ctx->fd; + + FD_SET(svc_ctx->tcb_pipe[PIPE_READ], set); + if (svc_ctx->tcb_pipe[PIPE_READ] > fd) { + fd = svc_ctx->tcb_pipe[PIPE_READ]; + } + + FD_SET(svc_ctx->evt_pipe[PIPE_READ], set); + if (svc_ctx->evt_pipe[PIPE_READ] > fd) { + fd = svc_ctx->evt_pipe[PIPE_READ]; + } + + EINA_LIST_FOREACH(svc_ctx->event_list, l, item) { + if (item->type == SERVICE_EVENT_TIMER) { + FD_SET(item->info.timer.fd, set); + if (fd < item->info.timer.fd) { + fd = item->info.timer.fd; + } } + } - return fd + 1; + return fd + 1; } /*! @@ -609,42 +609,42 @@ static inline int update_fdset(struct service_context *svc_ctx, fd_set *set) */ static inline void processing_timer_event(struct service_context *svc_ctx, fd_set *set) { - uint64_t expired_count; - Eina_List *l; - Eina_List *n; - struct service_event_item *item; - - EINA_LIST_FOREACH_SAFE(svc_ctx->event_list, l, n, item) { - switch (item->type) { - case SERVICE_EVENT_TIMER: - if (!FD_ISSET(item->info.timer.fd, set)) { - break; - } - - if (read(item->info.timer.fd, &expired_count, sizeof(expired_count)) == sizeof(expired_count)) { - DbgPrint("Expired %d times\n", expired_count); - if (item->event_cb(svc_ctx, item->cbdata) >= 0) { - break; - } - } else { - ErrPrint("read: %s\n", strerror(errno)); - } - - if (!eina_list_data_find(svc_ctx->event_list, item)) { - break; - } - - svc_ctx->event_list = eina_list_remove(svc_ctx->event_list, item); - if (close(item->info.timer.fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - DbgFree(item); - break; - default: - ErrPrint("Unknown event: %d\n", item->type); + uint64_t expired_count; + Eina_List *l; + Eina_List *n; + struct service_event_item *item; + + EINA_LIST_FOREACH_SAFE(svc_ctx->event_list, l, n, item) { + switch (item->type) { + case SERVICE_EVENT_TIMER: + if (!FD_ISSET(item->info.timer.fd, set)) { + break; + } + + if (read(item->info.timer.fd, &expired_count, sizeof(expired_count)) == sizeof(expired_count)) { + DbgPrint("Expired %d times\n", expired_count); + if (item->event_cb(svc_ctx, item->cbdata) >= 0) { break; + } + } else { + ErrPrint("read: %s\n", strerror(errno)); } + + if (!eina_list_data_find(svc_ctx->event_list, item)) { + break; + } + + svc_ctx->event_list = eina_list_remove(svc_ctx->event_list, item); + if (close(item->info.timer.fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + DbgFree(item); + break; + default: + ErrPrint("Unknown event: %d\n", item->type); + break; } + } } /*! @@ -656,169 +656,169 @@ static inline void processing_timer_event(struct service_context *svc_ctx, fd_se */ static void *server_main(void *data) { - struct service_context *svc_ctx = data; - fd_set set; - fd_set except_set; - long ret; - int client_fd; - struct tcb *tcb; - int fd; - char evt_ch; - struct packet_info *packet_info; - - DbgPrint("Server thread is activated\n"); - while (1) { - fd = update_fdset(svc_ctx, &set); - memcpy(&except_set, &set, sizeof(set)); - - ret = select(fd, &set, NULL, &except_set, NULL); - if (ret < 0) { - ret = -errno; - if (errno == EINTR) { - DbgPrint("INTERRUPTED\n"); - continue; - } - ErrPrint("Error: %s\n", strerror(errno)); - break; - } else if (ret == 0) { - ErrPrint("Timeout\n"); - ret = -ETIMEDOUT; - break; - } + struct service_context *svc_ctx = data; + fd_set set; + fd_set except_set; + long ret; + int client_fd; + struct tcb *tcb; + int fd; + char evt_ch; + struct packet_info *packet_info; + + DbgPrint("Server thread is activated\n"); + while (1) { + fd = update_fdset(svc_ctx, &set); + memcpy(&except_set, &set, sizeof(set)); + + ret = select(fd, &set, NULL, &except_set, NULL); + if (ret < 0) { + ret = -errno; + if (errno == EINTR) { + DbgPrint("INTERRUPTED\n"); + continue; + } + ErrPrint("Error: %s\n", strerror(errno)); + break; + } else if (ret == 0) { + ErrPrint("Timeout\n"); + ret = -ETIMEDOUT; + break; + } - if (FD_ISSET(svc_ctx->fd, &set)) { - client_fd = secure_socket_get_connection_handle(svc_ctx->fd); - if (client_fd < 0) { - ErrPrint("Failed to establish a new connection [%d]\n", svc_ctx->fd); - ret = -EFAULT; - break; - } - - tcb = tcb_create(svc_ctx, client_fd); - if (!tcb) { - ErrPrint("Failed to create a new TCB: %d (%d)\n", client_fd, svc_ctx->fd); - secure_socket_destroy_handle(client_fd); - } - } + if (FD_ISSET(svc_ctx->fd, &set)) { + client_fd = secure_socket_get_connection_handle(svc_ctx->fd); + if (client_fd < 0) { + ErrPrint("Failed to establish a new connection [%d]\n", svc_ctx->fd); + ret = -EFAULT; + break; + } - if (FD_ISSET(svc_ctx->evt_pipe[PIPE_READ], &set)) { - if (read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) { - ErrPrint("Unable to read pipe: %s\n", strerror(errno)); - ret = -EFAULT; - break; - } - - CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); - packet_info = eina_list_nth(svc_ctx->packet_list, 0); - svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); - CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); - - if (packet_info) { - /*! - * \CRITICAL - * What happens if the client thread is terminated, so the packet_info->tcb is deleted - * while processing svc_ctx->service_thread_main? - */ - ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); - if (ret < 0) { - ErrPrint("Service thread returns: %d\n", ret); - } - - packet_destroy(packet_info->packet); - DbgFree(packet_info); - } - - /* Take a breathe */ - pthread_yield(); - } + tcb = tcb_create(svc_ctx, client_fd); + if (!tcb) { + ErrPrint("Failed to create a new TCB: %d (%d)\n", client_fd, svc_ctx->fd); + secure_socket_destroy_handle(client_fd); + } + } + + if (FD_ISSET(svc_ctx->evt_pipe[PIPE_READ], &set)) { + if (read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) { + ErrPrint("Unable to read pipe: %s\n", strerror(errno)); + ret = -EFAULT; + break; + } - processing_timer_event(svc_ctx, &set); + CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); + packet_info = eina_list_nth(svc_ctx->packet_list, 0); + svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); + CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); + if (packet_info) { /*! - * \note - * Destroying TCB should be processed at last. + * \CRITICAL + * What happens if the client thread is terminated, so the packet_info->tcb is deleted + * while processing svc_ctx->service_thread_main? */ - if (FD_ISSET(svc_ctx->tcb_pipe[PIPE_READ], &set)) { - Eina_List *lockfree_packet_list; - Eina_List *l; - Eina_List *n; - - if (read(svc_ctx->tcb_pipe[PIPE_READ], &tcb, sizeof(tcb)) != sizeof(tcb)) { - ErrPrint("Unable to read pipe: %s\n", strerror(errno)); - ret = -EFAULT; - break; - } - - if (!tcb) { - ErrPrint("Terminate service thread\n"); - ret = -ECANCELED; - break; - } - - lockfree_packet_list = NULL; - CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); - EINA_LIST_FOREACH_SAFE(svc_ctx->packet_list, l, n, packet_info) { - if (packet_info->tcb != tcb) { - continue; - } - - svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); - lockfree_packet_list = eina_list_append(lockfree_packet_list, packet_info); - } - CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); - - EINA_LIST_FREE(lockfree_packet_list, packet_info) { - ret = read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)); - DbgPrint("Flushing filtered pipe: %d (%c)\n", ret, evt_ch); - ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); - if (ret < 0) { - ErrPrint("Service thread returns: %d\n", ret); - } - packet_destroy(packet_info->packet); - DbgFree(packet_info); - } - - /*! - * \note - * Invoke the service thread main, to notify the termination of a TCB - */ - ret = svc_ctx->service_thread_main(tcb, NULL, svc_ctx->service_thread_data); - - /*! - * at this time, the client thread can access this tcb. - * how can I protect this TCB from deletion without disturbing the server thread? - */ - tcb_destroy(svc_ctx, tcb); + ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); + if (ret < 0) { + ErrPrint("Service thread returns: %d\n", ret); } - /* If there is no such triggered FD? */ + packet_destroy(packet_info->packet); + DbgFree(packet_info); + } + + /* Take a breathe */ + pthread_yield(); } + processing_timer_event(svc_ctx, &set); + /*! - * Consuming all pended packets before terminates server thread. - * - * If the server thread is terminated, we should flush all pended packets. - * And we should services them. - * While processing this routine, the mutex is locked. - * So every other client thread will be slowed down, sequently, every clients can meet problems. - * But in case of termination of server thread, there could be systemetic problem. - * This only should be happenes while terminating the master daemon process. + * \note + * Destroying TCB should be processed at last. */ - CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); - EINA_LIST_FREE(svc_ctx->packet_list, packet_info) { + if (FD_ISSET(svc_ctx->tcb_pipe[PIPE_READ], &set)) { + Eina_List *lockfree_packet_list; + Eina_List *l; + Eina_List *n; + + if (read(svc_ctx->tcb_pipe[PIPE_READ], &tcb, sizeof(tcb)) != sizeof(tcb)) { + ErrPrint("Unable to read pipe: %s\n", strerror(errno)); + ret = -EFAULT; + break; + } + + if (!tcb) { + ErrPrint("Terminate service thread\n"); + ret = -ECANCELED; + break; + } + + lockfree_packet_list = NULL; + CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); + EINA_LIST_FOREACH_SAFE(svc_ctx->packet_list, l, n, packet_info) { + if (packet_info->tcb != tcb) { + continue; + } + + svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); + lockfree_packet_list = eina_list_append(lockfree_packet_list, packet_info); + } + CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); + + EINA_LIST_FREE(lockfree_packet_list, packet_info) { ret = read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)); - DbgPrint("Flushing pipe: %d (%c)\n", ret, evt_ch); + DbgPrint("Flushing filtered pipe: %d (%c)\n", ret, evt_ch); ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); if (ret < 0) { - ErrPrint("Service thread returns: %d\n", ret); + ErrPrint("Service thread returns: %d\n", ret); } packet_destroy(packet_info->packet); DbgFree(packet_info); + } + + /*! + * \note + * Invoke the service thread main, to notify the termination of a TCB + */ + ret = svc_ctx->service_thread_main(tcb, NULL, svc_ctx->service_thread_data); + + /*! + * at this time, the client thread can access this tcb. + * how can I protect this TCB from deletion without disturbing the server thread? + */ + tcb_destroy(svc_ctx, tcb); } - CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); - tcb_teminate_all(svc_ctx); - return (void *)ret; + /* If there is no such triggered FD? */ + } + + /*! + * Consuming all pended packets before terminates server thread. + * + * If the server thread is terminated, we should flush all pended packets. + * And we should services them. + * While processing this routine, the mutex is locked. + * So every other client thread will be slowed down, sequently, every clients can meet problems. + * But in case of termination of server thread, there could be systemetic problem. + * This only should be happenes while terminating the master daemon process. + */ + CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); + EINA_LIST_FREE(svc_ctx->packet_list, packet_info) { + ret = read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)); + DbgPrint("Flushing pipe: %d (%c)\n", ret, evt_ch); + ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); + if (ret < 0) { + ErrPrint("Service thread returns: %d\n", ret); + } + packet_destroy(packet_info->packet); + DbgFree(packet_info); + } + CRITICAL_SECTION_END(&svc_ctx->packet_list_lock); + + tcb_teminate_all(svc_ctx); + return (void *)ret; } /*! @@ -827,97 +827,97 @@ static void *server_main(void *data) */ HAPI struct service_context *service_common_create(const char *addr, int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data), void *data) { - int status; - struct service_context *svc_ctx; + int status; + struct service_context *svc_ctx; - if (!service_thread_main || !addr) { - ErrPrint("Invalid argument\n"); - return NULL; - } + if (!service_thread_main || !addr) { + ErrPrint("Invalid argument\n"); + return NULL; + } - if (strncmp(addr, COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { - int offset = 0; + if (strncmp(addr, COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { + int offset = 0; - offset = strlen(COM_CORE_LOCAL_SCHEME); - if (strncmp(addr, COM_CORE_LOCAL_SCHEME, offset)) { - offset = 0; - } - - if (unlink(addr + offset) < 0) { - ErrPrint("[%s] - %s\n", addr, strerror(errno)); - } + offset = strlen(COM_CORE_LOCAL_SCHEME); + if (strncmp(addr, COM_CORE_LOCAL_SCHEME, offset)) { + offset = 0; } - svc_ctx = calloc(1, sizeof(*svc_ctx)); - if (!svc_ctx) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; + if (unlink(addr + offset) < 0) { + ErrPrint("[%s] - %s\n", addr, strerror(errno)); } + } - svc_ctx->fd = secure_socket_create_server(addr); - if (svc_ctx->fd < 0) { - DbgFree(svc_ctx); - return NULL; - } + svc_ctx = calloc(1, sizeof(*svc_ctx)); + if (!svc_ctx) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - svc_ctx->service_thread_main = service_thread_main; - svc_ctx->service_thread_data = data; + svc_ctx->fd = secure_socket_create_server(addr); + if (svc_ctx->fd < 0) { + DbgFree(svc_ctx); + return NULL; + } - if (fcntl(svc_ctx->fd, F_SETFD, FD_CLOEXEC) < 0) { - ErrPrint("fcntl: %s\n", strerror(errno)); - } + svc_ctx->service_thread_main = service_thread_main; + svc_ctx->service_thread_data = data; - if (fcntl(svc_ctx->fd, F_SETFL, O_NONBLOCK) < 0) { - ErrPrint("fcntl: %s\n", strerror(errno)); - } + if (fcntl(svc_ctx->fd, F_SETFD, FD_CLOEXEC) < 0) { + ErrPrint("fcntl: %s\n", strerror(errno)); + } - if (pipe2(svc_ctx->evt_pipe, O_CLOEXEC) < 0) { - ErrPrint("pipe: %d\n", strerror(errno)); - secure_socket_destroy_handle(svc_ctx->fd); - DbgFree(svc_ctx); - return NULL; - } + if (fcntl(svc_ctx->fd, F_SETFL, O_NONBLOCK) < 0) { + ErrPrint("fcntl: %s\n", strerror(errno)); + } - if (pipe2(svc_ctx->tcb_pipe, O_CLOEXEC) < 0) { - ErrPrint("pipe: %s\n", strerror(errno)); - CLOSE_PIPE(svc_ctx->evt_pipe); - secure_socket_destroy_handle(svc_ctx->fd); - DbgFree(svc_ctx); - return NULL; - } + if (pipe2(svc_ctx->evt_pipe, O_CLOEXEC) < 0) { + ErrPrint("pipe: %d\n", strerror(errno)); + secure_socket_destroy_handle(svc_ctx->fd); + DbgFree(svc_ctx); + return NULL; + } - status = pthread_mutex_init(&svc_ctx->packet_list_lock, NULL); - if (status != 0) { - ErrPrint("Unable to create a mutex: %s\n", strerror(status)); - CLOSE_PIPE(svc_ctx->evt_pipe); - CLOSE_PIPE(svc_ctx->tcb_pipe); - secure_socket_destroy_handle(svc_ctx->fd); - DbgFree(svc_ctx); - return NULL; - } + if (pipe2(svc_ctx->tcb_pipe, O_CLOEXEC) < 0) { + ErrPrint("pipe: %s\n", strerror(errno)); + CLOSE_PIPE(svc_ctx->evt_pipe); + secure_socket_destroy_handle(svc_ctx->fd); + DbgFree(svc_ctx); + return NULL; + } - DbgPrint("Creating server thread\n"); - status = pthread_create(&svc_ctx->server_thid, NULL, server_main, svc_ctx); + status = pthread_mutex_init(&svc_ctx->packet_list_lock, NULL); + if (status != 0) { + ErrPrint("Unable to create a mutex: %s\n", strerror(status)); + CLOSE_PIPE(svc_ctx->evt_pipe); + CLOSE_PIPE(svc_ctx->tcb_pipe); + secure_socket_destroy_handle(svc_ctx->fd); + DbgFree(svc_ctx); + return NULL; + } + + DbgPrint("Creating server thread\n"); + status = pthread_create(&svc_ctx->server_thid, NULL, server_main, svc_ctx); + if (status != 0) { + ErrPrint("Unable to create a thread for shortcut service: %s\n", strerror(status)); + status = pthread_mutex_destroy(&svc_ctx->packet_list_lock); if (status != 0) { - ErrPrint("Unable to create a thread for shortcut service: %s\n", strerror(status)); - status = pthread_mutex_destroy(&svc_ctx->packet_list_lock); - if (status != 0) { - ErrPrint("Error: %s\n", strerror(status)); - } - CLOSE_PIPE(svc_ctx->evt_pipe); - CLOSE_PIPE(svc_ctx->tcb_pipe); - secure_socket_destroy_handle(svc_ctx->fd); - DbgFree(svc_ctx); - return NULL; + ErrPrint("Error: %s\n", strerror(status)); } + CLOSE_PIPE(svc_ctx->evt_pipe); + CLOSE_PIPE(svc_ctx->tcb_pipe); + secure_socket_destroy_handle(svc_ctx->fd); + DbgFree(svc_ctx); + return NULL; + } - /*! - * \note - * To give a chance to run for server thread. - */ - pthread_yield(); + /*! + * \note + * To give a chance to run for server thread. + */ + pthread_yield(); - return svc_ctx; + return svc_ctx; } /*! @@ -926,39 +926,39 @@ HAPI struct service_context *service_common_create(const char *addr, int (*servi */ HAPI int service_common_destroy(struct service_context *svc_ctx) { - int status = 0; - void *ret; - - if (!svc_ctx) { - return -EINVAL; - } - - /*! - * \note - * Terminate server thread - */ - if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &status, sizeof(status)) != sizeof(status)) { - ErrPrint("Failed to write: %s\n", strerror(errno)); - } - - status = pthread_join(svc_ctx->server_thid, &ret); - if (status != 0) { - ErrPrint("Join: %s\n", strerror(status)); - } else { - DbgPrint("Thread returns: %p\n", ret); - } - - secure_socket_destroy_handle(svc_ctx->fd); - - status = pthread_mutex_destroy(&svc_ctx->packet_list_lock); - if (status != 0) { - ErrPrint("Unable to destroy a mutex: %s\n", strerror(status)); - } - - CLOSE_PIPE(svc_ctx->evt_pipe); - CLOSE_PIPE(svc_ctx->tcb_pipe); - DbgFree(svc_ctx); - return 0; + int status = 0; + void *ret; + + if (!svc_ctx) { + return -EINVAL; + } + + /*! + * \note + * Terminate server thread + */ + if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &status, sizeof(status)) != sizeof(status)) { + ErrPrint("Failed to write: %s\n", strerror(errno)); + } + + status = pthread_join(svc_ctx->server_thid, &ret); + if (status != 0) { + ErrPrint("Join: %s\n", strerror(status)); + } else { + DbgPrint("Thread returns: %p\n", ret); + } + + secure_socket_destroy_handle(svc_ctx->fd); + + status = pthread_mutex_destroy(&svc_ctx->packet_list_lock); + if (status != 0) { + ErrPrint("Unable to destroy a mutex: %s\n", strerror(status)); + } + + CLOSE_PIPE(svc_ctx->evt_pipe); + CLOSE_PIPE(svc_ctx->tcb_pipe); + DbgFree(svc_ctx); + return 0; } /*! @@ -967,20 +967,20 @@ HAPI int service_common_destroy(struct service_context *svc_ctx) */ HAPI int tcb_is_valid(struct service_context *svc_ctx, struct tcb *tcb) { - Eina_List *l; - struct tcb *tmp; - int ret = -ENOENT; - - CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock); - EINA_LIST_FOREACH(svc_ctx->tcb_list, l, tmp) { - if (tmp == tcb /* && tcb->svc_ctx == svc_ctx */) { - ret = tcb->fd; - break; - } + Eina_List *l; + struct tcb *tmp; + int ret = -ENOENT; + + CRITICAL_SECTION_BEGIN(&svc_ctx->tcb_list_lock); + EINA_LIST_FOREACH(svc_ctx->tcb_list, l, tmp) { + if (tmp == tcb /* && tcb->svc_ctx == svc_ctx */) { + ret = tcb->fd; + break; } - CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock); + } + CRITICAL_SECTION_END(&svc_ctx->tcb_list_lock); - return ret; + return ret; } /*! @@ -989,11 +989,11 @@ HAPI int tcb_is_valid(struct service_context *svc_ctx, struct tcb *tcb) */ HAPI int tcb_pid(struct tcb *tcb) { - if (!tcb) { - return -1; - } + if (!tcb) { + return -1; + } - return tcb->pid; + return tcb->pid; } /*! @@ -1002,11 +1002,11 @@ HAPI int tcb_pid(struct tcb *tcb) */ HAPI int tcb_fd(struct tcb *tcb) { - if (!tcb) { - return -EINVAL; - } + if (!tcb) { + return -EINVAL; + } - return tcb->fd; + return tcb->fd; } /*! @@ -1015,11 +1015,11 @@ HAPI int tcb_fd(struct tcb *tcb) */ HAPI int tcb_client_type(struct tcb *tcb) { - if (!tcb) { - return -EINVAL; - } + if (!tcb) { + return -EINVAL; + } - return tcb->type; + return tcb->type; } /*! @@ -1028,13 +1028,13 @@ HAPI int tcb_client_type(struct tcb *tcb) */ HAPI int tcb_client_type_set(struct tcb *tcb, enum tcb_type type) { - if (!tcb) { - return -EINVAL; - } + if (!tcb) { + return -EINVAL; + } - DbgPrint("TCB[%p] Client type is changed to %d from %d\n", tcb, type, tcb->type); - tcb->type = type; - return 0; + DbgPrint("TCB[%p] Client type is changed to %d from %d\n", tcb, type, tcb->type); + tcb->type = type; + return 0; } /*! @@ -1043,11 +1043,11 @@ HAPI int tcb_client_type_set(struct tcb *tcb, enum tcb_type type) */ HAPI struct service_context *tcb_svc_ctx(struct tcb *tcb) { - if (!tcb) { - return NULL; - } + if (!tcb) { + return NULL; + } - return tcb->svc_ctx; + return tcb->svc_ctx; } /*! @@ -1056,13 +1056,13 @@ HAPI struct service_context *tcb_svc_ctx(struct tcb *tcb) */ HAPI int service_common_unicast_packet(struct tcb *tcb, struct packet *packet) { - if (!tcb || !packet) { - DbgPrint("Invalid unicast: tcb[%p], packet[%p]\n", tcb, packet); - return -EINVAL; - } + if (!tcb || !packet) { + DbgPrint("Invalid unicast: tcb[%p], packet[%p]\n", tcb, packet); + return -EINVAL; + } - DbgPrint("Unicast packet\n"); - return com_core_send(tcb->fd, (void *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT); + DbgPrint("Unicast packet\n"); + return com_core_send(tcb->fd, (void *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT); } /*! @@ -1071,37 +1071,37 @@ HAPI int service_common_unicast_packet(struct tcb *tcb, struct packet *packet) */ HAPI int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, int type) { - Eina_List *l; - struct tcb *target; - struct service_context *svc_ctx; - int ret; - - if (!tcb || !packet) { - DbgPrint("Invalid multicast: tcb[%p], packet[%p]\n", tcb, packet); - return -EINVAL; + Eina_List *l; + struct tcb *target; + struct service_context *svc_ctx; + int ret; + + if (!tcb || !packet) { + DbgPrint("Invalid multicast: tcb[%p], packet[%p]\n", tcb, packet); + return -EINVAL; + } + + svc_ctx = tcb->svc_ctx; + + DbgPrint("Multicasting packets\n"); + + /*! + * \note + * Does not need to make a critical section from here. + */ + EINA_LIST_FOREACH(svc_ctx->tcb_list, l, target) { + if (target == tcb || target->type != type) { + DbgPrint("Skip target: %p(%d) == %p/%d\n", target, target->type, tcb, type); + continue; } - svc_ctx = tcb->svc_ctx; - - DbgPrint("Multicasting packets\n"); - - /*! - * \note - * Does not need to make a critical section from here. - */ - EINA_LIST_FOREACH(svc_ctx->tcb_list, l, target) { - if (target == tcb || target->type != type) { - DbgPrint("Skip target: %p(%d) == %p/%d\n", target, target->type, tcb, type); - continue; - } - - ret = com_core_send(target->fd, (void *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT); - if (ret < 0) { - ErrPrint("Failed to send packet: %d\n", ret); - } + ret = com_core_send(target->fd, (void *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT); + if (ret < 0) { + ErrPrint("Failed to send packet: %d\n", ret); } - DbgPrint("Finish to multicast packet\n"); - return 0; + } + DbgPrint("Finish to multicast packet\n"); + return 0; } /*! @@ -1110,59 +1110,59 @@ HAPI int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, */ HAPI struct service_event_item *service_common_add_timer(struct service_context *svc_ctx, double timer, int (*timer_cb)(struct service_context *svc_cx, void *data), void *data) { - struct service_event_item *item; - - item = calloc(1, sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - item->type = SERVICE_EVENT_TIMER; - item->info.timer.fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); - if (item->info.timer.fd < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - DbgFree(item); - return NULL; - } + struct service_event_item *item; + + item = calloc(1, sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + item->type = SERVICE_EVENT_TIMER; + item->info.timer.fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); + if (item->info.timer.fd < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + DbgFree(item); + return NULL; + } - if (service_common_update_timer(item, timer) < 0) { - if (close(item->info.timer.fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - DbgFree(item); - return NULL; + if (service_common_update_timer(item, timer) < 0) { + if (close(item->info.timer.fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } + DbgFree(item); + return NULL; + } - item->event_cb = timer_cb; - item->cbdata = data; + item->event_cb = timer_cb; + item->cbdata = data; - svc_ctx->event_list = eina_list_append(svc_ctx->event_list, item); - return item; + svc_ctx->event_list = eina_list_append(svc_ctx->event_list, item); + return item; } HAPI int service_common_update_timer(struct service_event_item *item, double timer) { - struct itimerspec spec; + struct itimerspec spec; - spec.it_interval.tv_sec = (time_t)timer; - spec.it_interval.tv_nsec = (timer - spec.it_interval.tv_sec) * 1000000000; + spec.it_interval.tv_sec = (time_t)timer; + spec.it_interval.tv_nsec = (timer - spec.it_interval.tv_sec) * 1000000000; - if (clock_gettime(CLOCK_MONOTONIC, &spec.it_value) < 0) { - ErrPrint("clock_gettime: %s\n", strerror(errno)); - return -EFAULT; - } + if (clock_gettime(CLOCK_MONOTONIC, &spec.it_value) < 0) { + ErrPrint("clock_gettime: %s\n", strerror(errno)); + return -EFAULT; + } - spec.it_value.tv_sec += spec.it_interval.tv_sec; - spec.it_value.tv_nsec += spec.it_interval.tv_nsec; + spec.it_value.tv_sec += spec.it_interval.tv_sec; + spec.it_value.tv_nsec += spec.it_interval.tv_nsec; - if (timerfd_settime(item->info.timer.fd, TFD_TIMER_ABSTIME, &spec, NULL) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return -EFAULT; - } + if (timerfd_settime(item->info.timer.fd, TFD_TIMER_ABSTIME, &spec, NULL) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return -EFAULT; + } - DbgPrint("Armed interval: %u %u\n", spec.it_interval.tv_sec, spec.it_interval.tv_nsec); - return 0; + DbgPrint("Armed interval: %u %u\n", spec.it_interval.tv_sec, spec.it_interval.tv_nsec); + return 0; } /*! @@ -1171,23 +1171,23 @@ HAPI int service_common_update_timer(struct service_event_item *item, double tim */ HAPI int service_common_del_timer(struct service_context *svc_ctx, struct service_event_item *item) { - if (!eina_list_data_find(svc_ctx->event_list, item)) { - ErrPrint("Invalid event item\n"); - return -EINVAL; - } - - svc_ctx->event_list = eina_list_remove(svc_ctx->event_list, item); - - if (close(item->info.timer.fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - DbgFree(item); - return 0; + if (!eina_list_data_find(svc_ctx->event_list, item)) { + ErrPrint("Invalid event item\n"); + return -EINVAL; + } + + svc_ctx->event_list = eina_list_remove(svc_ctx->event_list, item); + + if (close(item->info.timer.fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + DbgFree(item); + return 0; } HAPI int service_common_fd(struct service_context *ctx) { - return ctx->fd; + return ctx->fd; } /* End of a file */ diff --git a/src/setting.c b/src/setting.c index 4af52c2..aae0d80 100644 --- a/src/setting.c +++ b/src/setting.c @@ -52,195 +52,195 @@ int errno; static struct { - int deactivated; + int deactivated; } s_info = { - .deactivated = 0, + .deactivated = 0, }; static void lcd_state_cb(keynode_t *node, void *user_data) { - if (!node) { - return; - } + if (!node) { + return; + } - xmonitor_handle_state_changes(); + xmonitor_handle_state_changes(); } HAPI int setting_is_lcd_off(void) { - int state; + int state; - if (!DYNAMICBOX_CONF_CHECK_LCD) { - /* Always turned on */ - return 0; - } + if (!DYNAMICBOX_CONF_CHECK_LCD) { + /* Always turned on */ + return 0; + } - if (vconf_get_int(VCONFKEY_PM_STATE, &state) != 0) { - ErrPrint("Idle lock state is not valid\n"); - state = VCONFKEY_PM_STATE_NORMAL; /* UNLOCK */ - } + if (vconf_get_int(VCONFKEY_PM_STATE, &state) != 0) { + ErrPrint("Idle lock state is not valid\n"); + state = VCONFKEY_PM_STATE_NORMAL; /* UNLOCK */ + } - ErrPrint("State: %d, (%d:lcdoff, %d:sleep)\n", state, VCONFKEY_PM_STATE_LCDOFF, VCONFKEY_PM_STATE_SLEEP); - return state == VCONFKEY_PM_STATE_LCDOFF || state == VCONFKEY_PM_STATE_SLEEP; + ErrPrint("State: %d, (%d:lcdoff, %d:sleep)\n", state, VCONFKEY_PM_STATE_LCDOFF, VCONFKEY_PM_STATE_SLEEP); + return state == VCONFKEY_PM_STATE_LCDOFF || state == VCONFKEY_PM_STATE_SLEEP; } static void power_off_cb(keynode_t *node, void *user_data) { - int val; - CRITICAL_LOG("Terminated(vconf)\n"); - - if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) { - ErrPrint("Failed to get power off status (%d)\n", val); - return; - } - - if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) { - DbgPrint("Power off requested: Ignored\n"); - } else { - ErrPrint("Unknown power state: %d\n", val); - } + int val; + CRITICAL_LOG("Terminated(vconf)\n"); + + if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) { + ErrPrint("Failed to get power off status (%d)\n", val); + return; + } + + if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) { + DbgPrint("Power off requested: Ignored\n"); + } else { + ErrPrint("Unknown power state: %d\n", val); + } } static void region_changed_cb(keynode_t *node, void *user_data) { - char *region; - char *r; - - region = vconf_get_str(VCONFKEY_REGIONFORMAT); - if (!region) { - return; - } - - setenv("LC_CTYPE", region, 1); - setenv("LC_NUMERIC", region, 1); - setenv("LC_TIME", region, 1); - setenv("LC_COLLATE", region, 1); - setenv("LC_MONETARY", region, 1); - setenv("LC_PAPER", region, 1); - setenv("LC_NAME", region, 1); - setenv("LC_ADDRESS", region, 1); - setenv("LC_TELEPHONE", region, 1); - setenv("LC_MEASUREMENT", region, 1); - setenv("LC_IDENTIFICATION", region, 1); - - r = setlocale(LC_ALL, ""); - if (r == NULL) { - ErrPrint("Failed to change region\n"); - } - - DbgFree(region); + char *region; + char *r; + + region = vconf_get_str(VCONFKEY_REGIONFORMAT); + if (!region) { + return; + } + + setenv("LC_CTYPE", region, 1); + setenv("LC_NUMERIC", region, 1); + setenv("LC_TIME", region, 1); + setenv("LC_COLLATE", region, 1); + setenv("LC_MONETARY", region, 1); + setenv("LC_PAPER", region, 1); + setenv("LC_NAME", region, 1); + setenv("LC_ADDRESS", region, 1); + setenv("LC_TELEPHONE", region, 1); + setenv("LC_MEASUREMENT", region, 1); + setenv("LC_IDENTIFICATION", region, 1); + + r = setlocale(LC_ALL, ""); + if (r == NULL) { + ErrPrint("Failed to change region\n"); + } + + DbgFree(region); } static void lang_changed_cb(keynode_t *node, void *user_data) { - char *lang; - char *r; + char *lang; + char *r; - lang = vconf_get_str(VCONFKEY_LANGSET); - if (!lang) { - return; - } + lang = vconf_get_str(VCONFKEY_LANGSET); + if (!lang) { + return; + } - setenv("LANG", lang, 1); - setenv("LC_MESSAGES", lang, 1); + setenv("LANG", lang, 1); + setenv("LC_MESSAGES", lang, 1); - r = setlocale(LC_ALL, ""); - if (!r) { - ErrPrint("Failed to change locale\n"); - } + r = setlocale(LC_ALL, ""); + if (!r) { + ErrPrint("Failed to change locale\n"); + } - DbgPrint("Locale: %s\n", setlocale(LC_ALL, NULL)); - DbgFree(lang); + DbgPrint("Locale: %s\n", setlocale(LC_ALL, NULL)); + DbgFree(lang); } static void low_mem_cb(keynode_t *node, void *user_data) { - int val; - - val = vconf_keynode_get_int(node); - - if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) { - CRITICAL_LOG("Low memory: level %d\n", val); - if (s_info.deactivated == 0) { - s_info.deactivated = 1; - //slave_deactivate_all(0, 1, 0); - malloc_trim(0); - ErrPrint("Fall into the low mem status\n"); - } - } else { - CRITICAL_LOG("Normal memory: level %d\n", val); - if (s_info.deactivated == 1) { - s_info.deactivated = 0; - //slave_activate_all(); - ErrPrint("Recover from the low mem status\n"); - } - } + int val; + + val = vconf_keynode_get_int(node); + + if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) { + CRITICAL_LOG("Low memory: level %d\n", val); + if (s_info.deactivated == 0) { + s_info.deactivated = 1; + //slave_deactivate_all(0, 1, 0); + malloc_trim(0); + ErrPrint("Fall into the low mem status\n"); + } + } else { + CRITICAL_LOG("Normal memory: level %d\n", val); + if (s_info.deactivated == 1) { + s_info.deactivated = 0; + //slave_activate_all(); + ErrPrint("Recover from the low mem status\n"); + } + } } HAPI int setting_init(void) { - int ret; - - ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_cb, NULL); - if (ret < 0) { - ErrPrint("Failed to add vconf for lock state: %d\n", ret); - } - - ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb, NULL); - if (ret < 0) { - ErrPrint("Failed to add vconf for power state: %d \n", ret); - } - - ret = vconf_notify_key_changed(VCONFKEY_LANGSET, lang_changed_cb, NULL); - if (ret < 0) { - ErrPrint("Failed to add vconf for lang change: %d\n", ret); - } - - ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb, NULL); - if (ret < 0) { - ErrPrint("Failed to add vconf for region change: %d\n", ret); - } - - ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb, NULL); - if (ret < 0) { - ErrPrint("Failed to add vconf for low mem monitor: %d\n", ret); - } - - lang_changed_cb(NULL, NULL); - region_changed_cb(NULL, NULL); - return ret; + int ret; + + ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_cb, NULL); + if (ret < 0) { + ErrPrint("Failed to add vconf for lock state: %d\n", ret); + } + + ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb, NULL); + if (ret < 0) { + ErrPrint("Failed to add vconf for power state: %d \n", ret); + } + + ret = vconf_notify_key_changed(VCONFKEY_LANGSET, lang_changed_cb, NULL); + if (ret < 0) { + ErrPrint("Failed to add vconf for lang change: %d\n", ret); + } + + ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb, NULL); + if (ret < 0) { + ErrPrint("Failed to add vconf for region change: %d\n", ret); + } + + ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb, NULL); + if (ret < 0) { + ErrPrint("Failed to add vconf for low mem monitor: %d\n", ret); + } + + lang_changed_cb(NULL, NULL); + region_changed_cb(NULL, NULL); + return ret; } HAPI int setting_fini(void) { - int ret; - - ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb); - if (ret < 0) { - ErrPrint("Failed to ignore vconf key (%d)\n", ret); - } - - ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb); - if (ret < 0) { - ErrPrint("Failed to ignore vconf key (%d)\n", ret); - } - - ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb); - if (ret < 0) { - ErrPrint("Failed to ignore vconf key (%d)\n", ret); - } - - ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb); - if (ret < 0) { - ErrPrint("Failed to ignore vconf key (%d)\n", ret); - } - - ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb); - if (ret < 0) { - ErrPrint("Failed to ignore vconf key (%d)\n", ret); - } - - return ret; + int ret; + + ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb); + if (ret < 0) { + ErrPrint("Failed to ignore vconf key (%d)\n", ret); + } + + ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb); + if (ret < 0) { + ErrPrint("Failed to ignore vconf key (%d)\n", ret); + } + + ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb); + if (ret < 0) { + ErrPrint("Failed to ignore vconf key (%d)\n", ret); + } + + ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb); + if (ret < 0) { + ErrPrint("Failed to ignore vconf key (%d)\n", ret); + } + + ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb); + if (ret < 0) { + ErrPrint("Failed to ignore vconf key (%d)\n", ret); + } + + return ret; } /* End of a file */ diff --git a/src/shortcut_service.c b/src/shortcut_service.c index 419cc69..bffc1ee 100644 --- a/src/shortcut_service.c +++ b/src/shortcut_service.c @@ -37,16 +37,16 @@ #include "conf.h" static struct info { - Eina_List *context_list; - struct service_context *svc_ctx; + Eina_List *context_list; + struct service_context *svc_ctx; } s_info = { - .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ - .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ + .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ + .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ }; struct context { - struct tcb *tcb; - double seq; + struct tcb *tcb; + double seq; }; /*! @@ -54,19 +54,19 @@ struct context { */ static inline int put_reply_context(struct tcb *tcb, double seq) { - struct context *ctx; + struct context *ctx; - ctx = malloc(sizeof(*ctx)); - if (!ctx) { - ErrPrint("Heap: %s\n", strerror(errno)); - return -ENOMEM; - } + ctx = malloc(sizeof(*ctx)); + if (!ctx) { + ErrPrint("Heap: %s\n", strerror(errno)); + return -ENOMEM; + } - ctx->tcb = tcb; - ctx->seq = seq; /* Could we this sequence value is uniq? */ + ctx->tcb = tcb; + ctx->seq = seq; /* Could we this sequence value is uniq? */ - s_info.context_list = eina_list_append(s_info.context_list, ctx); - return 0; + s_info.context_list = eina_list_append(s_info.context_list, ctx); + return 0; } /*! @@ -74,41 +74,41 @@ static inline int put_reply_context(struct tcb *tcb, double seq) */ static inline struct tcb *get_reply_context(double seq) { - Eina_List *l; - Eina_List *n; - struct context *ctx; - struct tcb *tcb; - - tcb = NULL; - EINA_LIST_FOREACH_SAFE(s_info.context_list, l, n, ctx) { - if (ctx->seq != seq) { - continue; - } - - s_info.context_list = eina_list_remove(s_info.context_list, ctx); - tcb = ctx->tcb; - DbgFree(ctx); - break; + Eina_List *l; + Eina_List *n; + struct context *ctx; + struct tcb *tcb; + + tcb = NULL; + EINA_LIST_FOREACH_SAFE(s_info.context_list, l, n, ctx) { + if (ctx->seq != seq) { + continue; } - return tcb; + s_info.context_list = eina_list_remove(s_info.context_list, ctx); + tcb = ctx->tcb; + DbgFree(ctx); + break; + } + + return tcb; } static void send_reply_packet(struct tcb *tcb, struct packet *packet, int ret) { - struct packet *reply_packet; + struct packet *reply_packet; - reply_packet = packet_create_reply(packet, "i", ret); - if (!reply_packet) { - ErrPrint("Failed to create a packet\n"); - return; - } + reply_packet = packet_create_reply(packet, "i", ret); + if (!reply_packet) { + ErrPrint("Failed to create a packet\n"); + return; + } - if (service_common_unicast_packet(tcb, reply_packet) < 0) { - ErrPrint("Unable to send reply packet\n"); - } + if (service_common_unicast_packet(tcb, reply_packet) < 0) { + ErrPrint("Unable to send reply packet\n"); + } - packet_destroy(reply_packet); + packet_destroy(reply_packet); } /*! @@ -116,88 +116,88 @@ static void send_reply_packet(struct tcb *tcb, struct packet *packet, int ret) */ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data) { - const char *command; - int ret; + const char *command; + int ret; - if (!packet) { - DbgPrint("TCB: %p is terminated (NIL packet)\n", tcb); - return 0; - } + if (!packet) { + DbgPrint("TCB: %p is terminated (NIL packet)\n", tcb); + return 0; + } - command = packet_command(packet); - if (!command) { - ErrPrint("Invalid command\n"); - return -EINVAL; - } + command = packet_command(packet); + if (!command) { + ErrPrint("Invalid command\n"); + return -EINVAL; + } - switch (packet_type(packet)) { + switch (packet_type(packet)) { case PACKET_REQ: - /* Need to send reply packet */ - DbgPrint("%p REQ: Command: [%s]\n", tcb, command); - if (!strcmp(command, "add_livebox") || !strcmp(command, "rm_livebox")) { - ret = security_server_check_privilege_by_sockfd(tcb_fd(tcb), "data-provider-master::shortcut.livebox", "w"); - if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { - ErrPrint("SMACK:Access denied\n"); - send_reply_packet(tcb, packet, SHORTCUT_ERROR_PERMISSION_DENIED); - break; - } - - } else if (!strcmp(command, "add_shortcut") || !strcmp(command, "rm_shortcut")) { - ret = security_server_check_privilege_by_sockfd(tcb_fd(tcb), "data-provider-master::shortcut.shortcut", "w"); - if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { - ErrPrint("SMACK:Access denied\n"); - send_reply_packet(tcb, packet, SHORTCUT_ERROR_PERMISSION_DENIED); - break; - } + /* Need to send reply packet */ + DbgPrint("%p REQ: Command: [%s]\n", tcb, command); + if (!strcmp(command, "add_livebox") || !strcmp(command, "rm_livebox")) { + ret = security_server_check_privilege_by_sockfd(tcb_fd(tcb), "data-provider-master::shortcut.livebox", "w"); + if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ErrPrint("SMACK:Access denied\n"); + send_reply_packet(tcb, packet, SHORTCUT_ERROR_PERMISSION_DENIED); + break; } - if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) { - ErrPrint("Unable to send service request packet\n"); - } else { - (void)put_reply_context(tcb, packet_seq(packet)); + } else if (!strcmp(command, "add_shortcut") || !strcmp(command, "rm_shortcut")) { + ret = security_server_check_privilege_by_sockfd(tcb_fd(tcb), "data-provider-master::shortcut.shortcut", "w"); + if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ErrPrint("SMACK:Access denied\n"); + send_reply_packet(tcb, packet, SHORTCUT_ERROR_PERMISSION_DENIED); + break; } - break; + } + + if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) { + ErrPrint("Unable to send service request packet\n"); + } else { + (void)put_reply_context(tcb, packet_seq(packet)); + } + break; case PACKET_REQ_NOACK: - /* Doesn't need to send reply packet */ - DbgPrint("%p REQ_NOACK: Command: [%s]\n", tcb, command); - if (!strcmp(command, "service_register")) { - tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); - break; - } - - if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) { - ErrPrint("Unable to send service reuqest packet\n"); - } + /* Doesn't need to send reply packet */ + DbgPrint("%p REQ_NOACK: Command: [%s]\n", tcb, command); + if (!strcmp(command, "service_register")) { + tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); break; - case PACKET_ACK: - /* Okay, client(or app) send a reply packet to us. */ - DbgPrint("%p ACK: Command: [%s]\n", tcb, command); - tcb = get_reply_context(packet_seq(packet)); - if (!tcb) { - ErrPrint("There is no proper context\n"); - break; - } + } - if (tcb_is_valid(s_info.svc_ctx, tcb) < 0) { - ErrPrint("TCB is not valid (already disconnected?)\n"); - break; - } + if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) { + ErrPrint("Unable to send service reuqest packet\n"); + } + break; + case PACKET_ACK: + /* Okay, client(or app) send a reply packet to us. */ + DbgPrint("%p ACK: Command: [%s]\n", tcb, command); + tcb = get_reply_context(packet_seq(packet)); + if (!tcb) { + ErrPrint("There is no proper context\n"); + break; + } - if (service_common_unicast_packet(tcb, packet) < 0) { - ErrPrint("Unable to send reply packet\n"); - } + if (tcb_is_valid(s_info.svc_ctx, tcb) < 0) { + ErrPrint("TCB is not valid (already disconnected?)\n"); break; - default: - ErrPrint("Packet type is not valid[%s]\n", command); - return -EINVAL; - } + } - /*! - * return value has no meanning, - * it will be printed by dlogutil. - */ - return 0; + if (service_common_unicast_packet(tcb, packet) < 0) { + ErrPrint("Unable to send reply packet\n"); + } + break; + default: + ErrPrint("Packet type is not valid[%s]\n", command); + return -EINVAL; + } + + /*! + * return value has no meanning, + * it will be printed by dlogutil. + */ + return 0; } @@ -208,49 +208,49 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat HAPI int shortcut_service_init(void) { - if (s_info.svc_ctx) { - ErrPrint("Already initialized\n"); - return DBOX_STATUS_ERROR_ALREADY; + if (s_info.svc_ctx) { + ErrPrint("Already initialized\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + s_info.svc_ctx = service_common_create(SHORTCUT_SOCKET, service_thread_main, NULL); + if (!s_info.svc_ctx) { + ErrPrint("Unable to activate service thread\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), SHORTCUT_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; } - - s_info.svc_ctx = service_common_create(SHORTCUT_SOCKET, service_thread_main, NULL); - if (!s_info.svc_ctx) { - ErrPrint("Unable to activate service thread\n"); - return DBOX_STATUS_ERROR_FAULT; + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), SHORTCUT_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; } + } - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), SHORTCUT_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } - } - - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), SHORTCUT_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } - } - - DbgPrint("Successfully initiated\n"); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("Successfully initiated\n"); + return DBOX_STATUS_ERROR_NONE; } HAPI int shortcut_service_fini(void) { - if (!s_info.svc_ctx) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - DbgPrint("Successfully Finalized\n"); - return DBOX_STATUS_ERROR_NONE; + if (!s_info.svc_ctx) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + DbgPrint("Successfully Finalized\n"); + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/slave_life.c b/src/slave_life.c index f82307b..ac47a79 100644 --- a/src/slave_life.c +++ b/src/slave_life.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -53,317 +54,317 @@ int errno; struct slave_node { - char *name; - char *abi; - char *pkgname; - int secured; /* Only A package(dynamicbox) is loaded for security requirements */ - int refcnt; - int fault_count; - int critical_fault_count; - enum slave_state state; - int network; - - int loaded_instance; - int loaded_package; - - int reactivate_instances; - int reactivate_slave; - - pid_t pid; - - enum event_process { - SLAVE_EVENT_PROCESS_IDLE = 0x00, - SLAVE_EVENT_PROCESS_ACTIVATE = 0x01, - SLAVE_EVENT_PROCESS_DEACTIVATE = 0x02, - SLAVE_EVENT_PROCESS_DELETE = 0x04, - SLAVE_EVENT_PROCESS_FAULT = 0x08, - SLAVE_EVENT_PROCESS_PAUSE = 0x10, - SLAVE_EVENT_PROCESS_RESUME = 0x20 - } in_event_process; - Eina_List *event_activate_list; - Eina_List *event_deactivate_list; - Eina_List *event_delete_list; - Eina_List *event_fault_list; - Eina_List *event_pause_list; - Eina_List *event_resume_list; - - Eina_List *data_list; - - Ecore_Timer *ttl_timer; /*!< Time to live */ - Ecore_Timer *activate_timer; /*!< Waiting hello packet for this time */ - Ecore_Timer *relaunch_timer; /*!< Try to relaunch service app */ - Ecore_Timer *terminate_timer; /*!< Waiting this timer before terminate the service provider */ - int relaunch_count; - - int ctrl_option; + char *name; + char *abi; + char *pkgname; + int secured; /* Only A package(dynamicbox) is loaded for security requirements */ + int refcnt; + int fault_count; + int critical_fault_count; + enum slave_state state; + int network; + + int loaded_instance; + int loaded_package; + + int reactivate_instances; + int reactivate_slave; + + pid_t pid; + + enum event_process { + SLAVE_EVENT_PROCESS_IDLE = 0x00, + SLAVE_EVENT_PROCESS_ACTIVATE = 0x01, + SLAVE_EVENT_PROCESS_DEACTIVATE = 0x02, + SLAVE_EVENT_PROCESS_DELETE = 0x04, + SLAVE_EVENT_PROCESS_FAULT = 0x08, + SLAVE_EVENT_PROCESS_PAUSE = 0x10, + SLAVE_EVENT_PROCESS_RESUME = 0x20 + } in_event_process; + Eina_List *event_activate_list; + Eina_List *event_deactivate_list; + Eina_List *event_delete_list; + Eina_List *event_fault_list; + Eina_List *event_pause_list; + Eina_List *event_resume_list; + + Eina_List *data_list; + + Ecore_Timer *ttl_timer; /*!< Time to live */ + Ecore_Timer *activate_timer; /*!< Waiting hello packet for this time */ + Ecore_Timer *relaunch_timer; /*!< Try to relaunch service app */ + Ecore_Timer *terminate_timer; /*!< Waiting this timer before terminate the service provider */ + int relaunch_count; + + int ctrl_option; #if defined(_USE_ECORE_TIME_GET) - double activated_at; + double activated_at; #else - struct timeval activated_at; + struct timeval activated_at; #endif }; struct event { - struct slave_node *slave; + struct slave_node *slave; - int (*evt_cb)(struct slave_node *, void *); - void *cbdata; - int deleted; + int (*evt_cb)(struct slave_node *, void *); + void *cbdata; + int deleted; }; struct priv_data { - char *tag; - void *data; + char *tag; + void *data; }; static struct { - Eina_List *slave_list; - int deactivate_all_refcnt; + Eina_List *slave_list; + int deactivate_all_refcnt; } s_info = { - .slave_list = NULL, - .deactivate_all_refcnt = 0, + .slave_list = NULL, + .deactivate_all_refcnt = 0, }; static Eina_Bool slave_ttl_cb(void *data) { - struct slave_node *slave = (struct slave_node *)data; + struct slave_node *slave = (struct slave_node *)data; - /*! - * \note - * ttl_timer must has to be set to NULL before deactivate the slave - * It will be used for making decision of the expired TTL timer or the fault of a dynamicbox. - */ - slave->ttl_timer = NULL; + /*! + * \note + * ttl_timer must has to be set to NULL before deactivate the slave + * It will be used for making decision of the expired TTL timer or the fault of a dynamicbox. + */ + slave->ttl_timer = NULL; - slave_set_reactivation(slave, 0); - slave_set_reactivate_instances(slave, 1); + slave_set_reactivation(slave, 0); + slave_set_reactivate_instances(slave, 1); - slave = slave_deactivate(slave, 1); - if (!slave) { - DbgPrint("Slave is deleted\n"); - } + slave = slave_deactivate(slave, 1); + if (!slave) { + DbgPrint("Slave is deleted\n"); + } - /*! To recover all instances state it is activated again */ - return ECORE_CALLBACK_CANCEL; + /*! To recover all instances state it is activated again */ + return ECORE_CALLBACK_CANCEL; } static inline int xmonitor_pause_cb(void *data) { - slave_pause(data); - return DBOX_STATUS_ERROR_NONE; + slave_pause(data); + return DBOX_STATUS_ERROR_NONE; } static inline int xmonitor_resume_cb(void *data) { - slave_resume(data); - return DBOX_STATUS_ERROR_NONE; + slave_resume(data); + return DBOX_STATUS_ERROR_NONE; } static inline struct slave_node *create_slave_node(const char *name, int is_secured, const char *abi, const char *pkgname, int network) { - struct slave_node *slave; + struct slave_node *slave; - slave = calloc(1, sizeof(*slave)); - if (!slave) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + slave = calloc(1, sizeof(*slave)); + if (!slave) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - slave->name = strdup(name); - if (!slave->name) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(slave); - return NULL; - } + slave->name = strdup(name); + if (!slave->name) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(slave); + return NULL; + } - slave->abi = strdup(abi); - if (!slave->abi) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(slave->name); - DbgFree(slave); - return NULL; - } + slave->abi = strdup(abi); + if (!slave->abi) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(slave->name); + DbgFree(slave); + return NULL; + } - slave->pkgname = strdup(pkgname); - if (!slave->pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(slave->abi); - DbgFree(slave->name); - DbgFree(slave); - return NULL; - } + slave->pkgname = strdup(pkgname); + if (!slave->pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(slave->abi); + DbgFree(slave->name); + DbgFree(slave); + return NULL; + } - slave->secured = is_secured; - slave->pid = (pid_t)-1; - slave->state = SLAVE_TERMINATED; - slave->network = network; - slave->relaunch_count = DYNAMICBOX_CONF_SLAVE_RELAUNCH_COUNT; + slave->secured = is_secured; + slave->pid = (pid_t)-1; + slave->state = SLAVE_TERMINATED; + slave->network = network; + slave->relaunch_count = DYNAMICBOX_CONF_SLAVE_RELAUNCH_COUNT; - xmonitor_add_event_callback(XMONITOR_PAUSED, xmonitor_pause_cb, slave); - xmonitor_add_event_callback(XMONITOR_RESUMED, xmonitor_resume_cb, slave); + xmonitor_add_event_callback(XMONITOR_PAUSED, xmonitor_pause_cb, slave); + xmonitor_add_event_callback(XMONITOR_RESUMED, xmonitor_resume_cb, slave); - s_info.slave_list = eina_list_append(s_info.slave_list, slave); - return slave; + s_info.slave_list = eina_list_append(s_info.slave_list, slave); + return slave; } static inline void invoke_delete_cb(struct slave_node *slave) { - Eina_List *l; - Eina_List *n; - struct event *event; + Eina_List *l; + Eina_List *n; + struct event *event; - slave->in_event_process |= SLAVE_EVENT_PROCESS_DELETE; - EINA_LIST_FOREACH_SAFE(slave->event_delete_list, l, n, event) { - if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { - slave->event_delete_list = eina_list_remove(slave->event_delete_list, event); - DbgFree(event); - } + slave->in_event_process |= SLAVE_EVENT_PROCESS_DELETE; + EINA_LIST_FOREACH_SAFE(slave->event_delete_list, l, n, event) { + if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { + slave->event_delete_list = eina_list_remove(slave->event_delete_list, event); + DbgFree(event); } - slave->in_event_process &= ~SLAVE_EVENT_PROCESS_DELETE; + } + slave->in_event_process &= ~SLAVE_EVENT_PROCESS_DELETE; } static inline void destroy_slave_node(struct slave_node *slave) { - struct event *event; - struct priv_data *priv; + struct event *event; + struct priv_data *priv; - if (slave_pid(slave) != (pid_t)-1) { - ErrPrint("Slave is not deactivated\n"); - return; - } + if (slave_pid(slave) != (pid_t)-1) { + ErrPrint("Slave is not deactivated\n"); + return; + } - xmonitor_del_event_callback(XMONITOR_PAUSED, xmonitor_pause_cb, slave); - xmonitor_del_event_callback(XMONITOR_RESUMED, xmonitor_resume_cb, slave); + xmonitor_del_event_callback(XMONITOR_PAUSED, xmonitor_pause_cb, slave); + xmonitor_del_event_callback(XMONITOR_RESUMED, xmonitor_resume_cb, slave); - invoke_delete_cb(slave); - slave_rpc_fini(slave); /*!< Finalize the RPC after handling all delete callbacks */ + invoke_delete_cb(slave); + slave_rpc_fini(slave); /*!< Finalize the RPC after handling all delete callbacks */ - EINA_LIST_FREE(slave->event_delete_list, event) { - DbgFree(event); - } + EINA_LIST_FREE(slave->event_delete_list, event) { + DbgFree(event); + } - EINA_LIST_FREE(slave->event_activate_list, event) { - DbgFree(event); - } + EINA_LIST_FREE(slave->event_activate_list, event) { + DbgFree(event); + } - EINA_LIST_FREE(slave->event_deactivate_list, event) { - DbgFree(event); - } + EINA_LIST_FREE(slave->event_deactivate_list, event) { + DbgFree(event); + } - EINA_LIST_FREE(slave->event_fault_list, event) { - DbgFree(event); - } + EINA_LIST_FREE(slave->event_fault_list, event) { + DbgFree(event); + } - EINA_LIST_FREE(slave->data_list, priv) { - DbgFree(priv->tag); - DbgFree(priv); - } + EINA_LIST_FREE(slave->data_list, priv) { + DbgFree(priv->tag); + DbgFree(priv); + } - s_info.slave_list = eina_list_remove(s_info.slave_list, slave); + s_info.slave_list = eina_list_remove(s_info.slave_list, slave); - if (slave->ttl_timer) { - ecore_timer_del(slave->ttl_timer); - } + if (slave->ttl_timer) { + ecore_timer_del(slave->ttl_timer); + } - if (slave->activate_timer) { - ecore_timer_del(slave->activate_timer); - } + if (slave->activate_timer) { + ecore_timer_del(slave->activate_timer); + } - if (slave->relaunch_timer) { - ecore_timer_del(slave->relaunch_timer); - } + if (slave->relaunch_timer) { + ecore_timer_del(slave->relaunch_timer); + } - DbgFree(slave->abi); - DbgFree(slave->name); - DbgFree(slave->pkgname); - DbgFree(slave); - return; + DbgFree(slave->abi); + DbgFree(slave->name); + DbgFree(slave->pkgname); + DbgFree(slave); + return; } static inline struct slave_node *find_slave(const char *name) { - struct slave_node *slave; - Eina_List *l; + struct slave_node *slave; + Eina_List *l; - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - if (!strcmp(slave->name, name)) { - return slave; - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + if (!strcmp(slave->name, name)) { + return slave; } - - return NULL; + } + + return NULL; } HAPI int slave_expired_ttl(struct slave_node *slave) { - if (!slave) { - return 0; - } + if (!slave) { + return 0; + } - if (!slave->secured) { - return 0; - } + if (!slave->secured) { + return 0; + } - return !!slave->ttl_timer; + return !!slave->ttl_timer; } HAPI struct slave_node *slave_ref(struct slave_node *slave) { - if (!slave) { - return NULL; - } + if (!slave) { + return NULL; + } - slave->refcnt++; - return slave; + slave->refcnt++; + return slave; } HAPI struct slave_node *slave_unref(struct slave_node *slave) { - if (!slave) { - return NULL; - } + if (!slave) { + return NULL; + } - if (slave->refcnt == 0) { - ErrPrint("Slave refcnt is not valid\n"); - return NULL; - } + if (slave->refcnt == 0) { + ErrPrint("Slave refcnt is not valid\n"); + return NULL; + } - slave->refcnt--; - if (slave->refcnt == 0) { - destroy_slave_node(slave); - slave = NULL; - } + slave->refcnt--; + if (slave->refcnt == 0) { + destroy_slave_node(slave); + slave = NULL; + } - return slave; + return slave; } HAPI const int const slave_refcnt(struct slave_node *slave) { - return slave->refcnt; + return slave->refcnt; } HAPI struct slave_node *slave_create(const char *name, int is_secured, const char *abi, const char *pkgname, int network) { - struct slave_node *slave; + struct slave_node *slave; - slave = find_slave(name); - if (slave) { - if (slave->secured != is_secured) { - ErrPrint("Exists slave and creating slave's security flag is not matched\n"); - } - return slave; + slave = find_slave(name); + if (slave) { + if (slave->secured != is_secured) { + ErrPrint("Exists slave and creating slave's security flag is not matched\n"); } + return slave; + } - slave = create_slave_node(name, is_secured, abi, pkgname, network); - if (!slave) { - return NULL; - } + slave = create_slave_node(name, is_secured, abi, pkgname, network); + if (!slave) { + return NULL; + } - slave_ref(slave); - slave_rpc_init(slave); + slave_ref(slave); + slave_rpc_init(slave); - return slave; + return slave; } /*! @@ -373,1393 +374,1437 @@ HAPI struct slave_node *slave_create(const char *name, int is_secured, const cha */ HAPI void slave_destroy(struct slave_node *slave) { - slave_unref(slave); + slave_unref(slave); } static inline void invoke_fault_cb(struct slave_node *slave) { - Eina_List *l; - Eina_List *n; - struct event *event; + Eina_List *l; + Eina_List *n; + struct event *event; - slave->in_event_process |= SLAVE_EVENT_PROCESS_FAULT; - EINA_LIST_FOREACH_SAFE(slave->event_fault_list, l, n, event) { - if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { - slave->event_fault_list = eina_list_remove(slave->event_fault_list, event); - DbgFree(event); - } + slave->in_event_process |= SLAVE_EVENT_PROCESS_FAULT; + EINA_LIST_FOREACH_SAFE(slave->event_fault_list, l, n, event) { + if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { + slave->event_fault_list = eina_list_remove(slave->event_fault_list, event); + DbgFree(event); } - slave->in_event_process &= ~SLAVE_EVENT_PROCESS_FAULT; + } + slave->in_event_process &= ~SLAVE_EVENT_PROCESS_FAULT; } static inline void invoke_activate_cb(struct slave_node *slave) { - Eina_List *l; - Eina_List *n; - struct event *event; + Eina_List *l; + Eina_List *n; + struct event *event; - slave->in_event_process |= SLAVE_EVENT_PROCESS_ACTIVATE; - EINA_LIST_FOREACH_SAFE(slave->event_activate_list, l, n, event) { - if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { - slave->event_activate_list = eina_list_remove(slave->event_activate_list, event); - DbgFree(event); - } + slave->in_event_process |= SLAVE_EVENT_PROCESS_ACTIVATE; + EINA_LIST_FOREACH_SAFE(slave->event_activate_list, l, n, event) { + if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { + slave->event_activate_list = eina_list_remove(slave->event_activate_list, event); + DbgFree(event); } - slave->in_event_process &= ~SLAVE_EVENT_PROCESS_ACTIVATE; + } + slave->in_event_process &= ~SLAVE_EVENT_PROCESS_ACTIVATE; } static Eina_Bool activate_timer_cb(void *data) { - struct slave_node *slave = data; + struct slave_node *slave = data; - if (slave->relaunch_timer) { - ecore_timer_del(slave->relaunch_timer); - slave->relaunch_timer = NULL; - } + if (slave->relaunch_timer) { + ecore_timer_del(slave->relaunch_timer); + slave->relaunch_timer = NULL; + } - slave->fault_count++; - invoke_fault_cb(slave); + slave->fault_count++; + invoke_fault_cb(slave); - slave_set_reactivation(slave, 0); - slave_set_reactivate_instances(slave, 0); + slave_set_reactivation(slave, 0); + slave_set_reactivate_instances(slave, 0); - slave->activate_timer = NULL; - if (slave_pid(slave) > 0) { - int ret; - DbgPrint("Try to terminate PID: %d\n", slave_pid(slave)); - ret = aul_terminate_pid(slave_pid(slave)); - if (ret < 0) { - ErrPrint("Terminate failed, pid %d (reason: %d)\n", slave_pid(slave), ret); - } + slave->activate_timer = NULL; + if (slave_pid(slave) > 0) { + int ret; + DbgPrint("Try to terminate PID: %d\n", slave_pid(slave)); + ret = aul_terminate_pid(slave_pid(slave)); + if (ret < 0) { + ErrPrint("Terminate failed, pid %d (reason: %d)\n", slave_pid(slave), ret); } + } - CRITICAL_LOG("Slave is not activated in %lf sec (slave: %s)\n", DYNAMICBOX_CONF_SLAVE_ACTIVATE_TIME, slave_name(slave)); - slave = slave_deactivated(slave); - return ECORE_CALLBACK_CANCEL; + CRITICAL_LOG("Slave is not activated in %lf sec (slave: %s)\n", DYNAMICBOX_CONF_SLAVE_ACTIVATE_TIME, slave_name(slave)); + slave = slave_deactivated(slave); + return ECORE_CALLBACK_CANCEL; } static inline void invoke_slave_fault_handler(struct slave_node *slave) { - slave->fault_count++; - invoke_fault_cb(slave); + slave->fault_count++; + invoke_fault_cb(slave); - slave_set_reactivation(slave, 0); - slave_set_reactivate_instances(slave, 0); + slave_set_reactivation(slave, 0); + slave_set_reactivate_instances(slave, 0); - if (slave_pid(slave) > 0) { - if ((slave->ctrl_option & PROVIDER_CTRL_MANUAL_TERMINATION) == PROVIDER_CTRL_MANUAL_TERMINATION) { - DbgPrint("Manual termination is turned on\n"); - (void)slave_rpc_disconnect(slave); - } else { - int ret; - DbgPrint("Try to terminate PID: %d\n", slave_pid(slave)); - ret = aul_terminate_pid(slave_pid(slave)); - if (ret < 0) { - ErrPrint("Terminate failed, pid %d (reason: %d)\n", slave_pid(slave), ret); - } - } + if (slave_pid(slave) > 0) { + if ((slave->ctrl_option & PROVIDER_CTRL_MANUAL_TERMINATION) == PROVIDER_CTRL_MANUAL_TERMINATION) { + DbgPrint("Manual termination is turned on\n"); + (void)slave_rpc_disconnect(slave); + } else { + int ret; + DbgPrint("Try to terminate PID: %d\n", slave_pid(slave)); + ret = aul_terminate_pid(slave_pid(slave)); + if (ret < 0) { + ErrPrint("Terminate failed, pid %d (reason: %d)\n", slave_pid(slave), ret); + } } + } - slave->state = SLAVE_TERMINATED; + slave->state = SLAVE_TERMINATED; } static Eina_Bool relaunch_timer_cb(void *data) { - struct slave_node *slave = data; - int ret = ECORE_CALLBACK_CANCEL; - - if (!slave->activate_timer) { - ErrPrint("Activate timer is not valid\n"); - slave->relaunch_timer = NULL; - - invoke_slave_fault_handler(slave); - } else if (!slave->relaunch_count) { - ErrPrint("Relaunch count is exhahausted\n"); - ecore_timer_del(slave->activate_timer); - slave->activate_timer = NULL; - - slave->relaunch_timer = NULL; - invoke_slave_fault_handler(slave); - } else { - bundle *param; + struct slave_node *slave = data; + int ret = ECORE_CALLBACK_CANCEL; - param = bundle_create(); - if (!param) { - ErrPrint("Failed to create a bundle\n"); + if (!slave->activate_timer) { + ErrPrint("Activate timer is not valid\n"); + slave->relaunch_timer = NULL; - ecore_timer_del(slave->activate_timer); - slave->activate_timer = NULL; - - slave->relaunch_timer = NULL; + invoke_slave_fault_handler(slave); + } else if (!slave->relaunch_count) { + ErrPrint("Relaunch count is exhahausted\n"); + ecore_timer_del(slave->activate_timer); + slave->activate_timer = NULL; - invoke_slave_fault_handler(slave); - } else { - bundle_add(param, BUNDLE_SLAVE_SVC_OP_TYPE, APP_CONTROL_OPERATION_MAIN); - bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_NAME, slave_name(slave)); - bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_SECURED, slave->secured ? "true" : "false"); - bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_ABI, slave->abi); - - slave->pid = (pid_t)aul_launch_app(slave_pkgname(slave), param); - - bundle_free(param); - - switch (slave->pid) { - case AUL_R_EHIDDENFORGUEST: /**< App hidden for guest mode */ - case AUL_R_ENOLAUNCHPAD: /**< no launchpad */ - case AUL_R_EILLACC: /**< Illegal Access */ - case AUL_R_EINVAL: /**< Invalid argument */ - case AUL_R_ENOINIT: /**< AUL handler NOT initialized */ - case AUL_R_ERROR: /**< General error */ - CRITICAL_LOG("Failed to launch a new slave %s (%d)\n", slave_name(slave), slave->pid); - slave->pid = (pid_t)-1; - ecore_timer_del(slave->activate_timer); - slave->activate_timer = NULL; - - slave->relaunch_timer = NULL; - - invoke_slave_fault_handler(slave); - /* Waiting app-launch result */ - break; - case AUL_R_ETIMEOUT: /**< Timeout */ - case AUL_R_ECOMM: /**< Comunication Error */ - case AUL_R_ETERMINATING: /**< application terminating */ - case AUL_R_ECANCELED: /**< Operation canceled */ - slave->relaunch_count--; - - CRITICAL_LOG("Try relaunch again %s (%d), %d\n", slave_name(slave), slave->pid, slave->relaunch_count); - slave->pid = (pid_t)-1; - ret = ECORE_CALLBACK_RENEW; - ecore_timer_reset(slave->activate_timer); - /* Try again after a few secs later */ - break; - case AUL_R_LOCAL: /**< Launch by himself */ - case AUL_R_OK: /**< General success */ - default: - DbgPrint("Slave %s is launched with %d as %s\n", slave_pkgname(slave), slave->pid, slave_name(slave)); - slave->relaunch_timer = NULL; - ecore_timer_reset(slave->activate_timer); - break; - } - } + slave->relaunch_timer = NULL; + invoke_slave_fault_handler(slave); + } else { + bundle *param; - } + param = bundle_create(); + if (!param) { + ErrPrint("Failed to create a bundle\n"); - return ret; -} + ecore_timer_del(slave->activate_timer); + slave->activate_timer = NULL; -HAPI int slave_activate(struct slave_node *slave) -{ - /*! - * \note - * This check code can be replaced with the slave->state check code - * If the slave data has the PID, it means, it is activated - * Even if it is in the termiating sequence, it will have the PID - * before terminated at last. - * So we can use this simple code for checking the slave's last state. - * about it is alive? or not. - */ - if (slave_pid(slave) != (pid_t)-1) { - if (slave->terminate_timer) { - DbgPrint("Clear terminate timer. to reuse (%d)\n", slave->pid); - ecore_timer_del(slave->terminate_timer); - slave->terminate_timer = NULL; - } else if (slave_state(slave) == SLAVE_REQUEST_TO_TERMINATE || slave_state(slave) == SLAVE_REQUEST_TO_DISCONNECT) { - slave_set_reactivation(slave, 1); - } - return DBOX_STATUS_ERROR_ALREADY; - } else if (slave_state(slave) == SLAVE_REQUEST_TO_LAUNCH) { - DbgPrint("Slave is already launched: but the AUL is timed out\n"); - return DBOX_STATUS_ERROR_ALREADY; - } + slave->relaunch_timer = NULL; - if (DYNAMICBOX_CONF_DEBUG_MODE || g_conf.debug_mode) { - DbgPrint("Debug Mode enabled. name[%s] secured[%d] abi[%s]\n", slave_name(slave), slave->secured, slave->abi); + invoke_slave_fault_handler(slave); } else { - bundle *param; - - slave->relaunch_count = DYNAMICBOX_CONF_SLAVE_RELAUNCH_COUNT; - - param = bundle_create(); - if (!param) { - ErrPrint("Failed to create a bundle\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - bundle_add(param, BUNDLE_SLAVE_SVC_OP_TYPE, APP_CONTROL_OPERATION_MAIN); - bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_NAME, slave_name(slave)); - bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_SECURED, slave->secured ? "true" : "false"); - bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_ABI, slave->abi); + bundle_add(param, BUNDLE_SLAVE_SVC_OP_TYPE, APP_CONTROL_OPERATION_MAIN); + bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_NAME, slave_name(slave)); + bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_SECURED, slave->secured ? "true" : "false"); + bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_ABI, slave->abi); - slave->pid = (pid_t)aul_launch_app(slave_pkgname(slave), param); + slave->pid = (pid_t)aul_launch_app(slave_pkgname(slave), param); - bundle_free(param); + bundle_free(param); - switch (slave->pid) { + switch (slave->pid) { case AUL_R_EHIDDENFORGUEST: /**< App hidden for guest mode */ case AUL_R_ENOLAUNCHPAD: /**< no launchpad */ case AUL_R_EILLACC: /**< Illegal Access */ case AUL_R_EINVAL: /**< Invalid argument */ case AUL_R_ENOINIT: /**< AUL handler NOT initialized */ case AUL_R_ERROR: /**< General error */ - CRITICAL_LOG("Failed to launch a new slave %s (%d)\n", slave_name(slave), slave->pid); - slave->pid = (pid_t)-1; - /* Waiting app-launch result */ - break; + CRITICAL_LOG("Failed to launch a new slave %s (%d)\n", slave_name(slave), slave->pid); + slave->pid = (pid_t)-1; + ecore_timer_del(slave->activate_timer); + slave->activate_timer = NULL; + + slave->relaunch_timer = NULL; + + invoke_slave_fault_handler(slave); + /* Waiting app-launch result */ + break; + case AUL_R_ETIMEOUT: /**< Timeout */ case AUL_R_ECOMM: /**< Comunication Error */ case AUL_R_ETERMINATING: /**< application terminating */ case AUL_R_ECANCELED: /**< Operation canceled */ - case AUL_R_ETIMEOUT: /**< Timeout */ - CRITICAL_LOG("Try relaunch this soon %s (%d)\n", slave_name(slave), slave->pid); - slave->relaunch_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_RELAUNCH_TIME, relaunch_timer_cb, slave); - if (!slave->relaunch_timer) { - CRITICAL_LOG("Failed to register a relaunch timer (%s)\n", slave_name(slave)); - slave->pid = (pid_t)-1; - return DBOX_STATUS_ERROR_FAULT; - } - /* Try again after a few secs later */ - break; + slave->relaunch_count--; + + CRITICAL_LOG("Try relaunch again %s (%d), %d\n", slave_name(slave), slave->pid, slave->relaunch_count); + slave->pid = (pid_t)-1; + ret = ECORE_CALLBACK_RENEW; + ecore_timer_reset(slave->activate_timer); + /* Try again after a few secs later */ + break; case AUL_R_LOCAL: /**< Launch by himself */ case AUL_R_OK: /**< General success */ default: - DbgPrint("Slave %s is launched with %d as %s\n", slave_pkgname(slave), slave->pid, slave_name(slave)); - break; - } + DbgPrint("Slave %s is launched with %d as %s\n", slave_pkgname(slave), slave->pid, slave_name(slave)); + slave->relaunch_timer = NULL; + ecore_timer_reset(slave->activate_timer); + break; + } + } + + } + + return ret; +} + +HAPI int slave_activate(struct slave_node *slave) +{ + /*! + * \note + * This check code can be replaced with the slave->state check code + * If the slave data has the PID, it means, it is activated + * Even if it is in the termiating sequence, it will have the PID + * before terminated at last. + * So we can use this simple code for checking the slave's last state. + * about it is alive? or not. + */ + if (slave_pid(slave) != (pid_t)-1) { + if (slave->terminate_timer) { + DbgPrint("Clear terminate timer. to reuse (%d)\n", slave->pid); + ecore_timer_del(slave->terminate_timer); + slave->terminate_timer = NULL; + } else if (slave_state(slave) == SLAVE_REQUEST_TO_TERMINATE || slave_state(slave) == SLAVE_REQUEST_TO_DISCONNECT) { + slave_set_reactivation(slave, 1); + } + return DBOX_STATUS_ERROR_ALREADY; + } else if (slave_state(slave) == SLAVE_REQUEST_TO_LAUNCH) { + DbgPrint("Slave is already launched: but the AUL is timed out\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + if (DYNAMICBOX_CONF_DEBUG_MODE || g_conf.debug_mode) { + DbgPrint("Debug Mode enabled. name[%s] secured[%d] abi[%s]\n", slave_name(slave), slave->secured, slave->abi); + } else { + bundle *param; + + slave->relaunch_count = DYNAMICBOX_CONF_SLAVE_RELAUNCH_COUNT; + + param = bundle_create(); + if (!param) { + ErrPrint("Failed to create a bundle\n"); + return DBOX_STATUS_ERROR_FAULT; + } - slave->activate_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_ACTIVATE_TIME, activate_timer_cb, slave); - if (!slave->activate_timer) { - ErrPrint("Failed to register an activate timer\n"); + bundle_add(param, BUNDLE_SLAVE_SVC_OP_TYPE, APP_CONTROL_OPERATION_MAIN); + bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_NAME, slave_name(slave)); + bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_SECURED, slave->secured ? "true" : "false"); + bundle_add(param, DYNAMICBOX_CONF_BUNDLE_SLAVE_ABI, slave->abi); + + slave->pid = (pid_t)aul_launch_app(slave_pkgname(slave), param); + + bundle_free(param); + + switch (slave->pid) { + case AUL_R_EHIDDENFORGUEST: /**< App hidden for guest mode */ + case AUL_R_ENOLAUNCHPAD: /**< no launchpad */ + case AUL_R_EILLACC: /**< Illegal Access */ + case AUL_R_EINVAL: /**< Invalid argument */ + case AUL_R_ENOINIT: /**< AUL handler NOT initialized */ + case AUL_R_ERROR: /**< General error */ + CRITICAL_LOG("Failed to launch a new slave %s (%d)\n", slave_name(slave), slave->pid); + slave->pid = (pid_t)-1; + /* Waiting app-launch result */ + break; + case AUL_R_ECOMM: /**< Comunication Error */ + case AUL_R_ETERMINATING: /**< application terminating */ + case AUL_R_ECANCELED: /**< Operation canceled */ + case AUL_R_ETIMEOUT: /**< Timeout */ + CRITICAL_LOG("Try relaunch this soon %s (%d)\n", slave_name(slave), slave->pid); + slave->relaunch_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_RELAUNCH_TIME, relaunch_timer_cb, slave); + if (!slave->relaunch_timer) { + CRITICAL_LOG("Failed to register a relaunch timer (%s)\n", slave_name(slave)); + slave->pid = (pid_t)-1; + return DBOX_STATUS_ERROR_FAULT; } + /* Try again after a few secs later */ + break; + case AUL_R_LOCAL: /**< Launch by himself */ + case AUL_R_OK: /**< General success */ + default: + DbgPrint("Slave %s is launched with %d as %s\n", slave_pkgname(slave), slave->pid, slave_name(slave)); + break; } - slave->state = SLAVE_REQUEST_TO_LAUNCH; - /*! - * \note - * Increase the refcnt of a slave, - * To prevent from making an orphan(slave). - */ - (void)slave_ref(slave); + slave->activate_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_ACTIVATE_TIME, activate_timer_cb, slave); + if (!slave->activate_timer) { + ErrPrint("Failed to register an activate timer\n"); + } + } + + slave->state = SLAVE_REQUEST_TO_LAUNCH; + /*! + * \note + * Increase the refcnt of a slave, + * To prevent from making an orphan(slave). + */ + (void)slave_ref(slave); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_give_more_ttl(struct slave_node *slave) { - double delay; + double delay; - if (!slave->secured || !slave->ttl_timer) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!slave->secured || !slave->ttl_timer) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - delay = DYNAMICBOX_CONF_SLAVE_TTL - ecore_timer_pending_get(slave->ttl_timer); - ecore_timer_delay(slave->ttl_timer, delay); - return DBOX_STATUS_ERROR_NONE; + delay = DYNAMICBOX_CONF_SLAVE_TTL - ecore_timer_pending_get(slave->ttl_timer); + ecore_timer_delay(slave->ttl_timer, delay); + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_freeze_ttl(struct slave_node *slave) { - if (!slave->secured || !slave->ttl_timer) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!slave->secured || !slave->ttl_timer) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ecore_timer_freeze(slave->ttl_timer); - return DBOX_STATUS_ERROR_NONE; + ecore_timer_freeze(slave->ttl_timer); + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_thaw_ttl(struct slave_node *slave) { - double delay; + double delay; - if (!slave->secured || !slave->ttl_timer) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!slave->secured || !slave->ttl_timer) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ecore_timer_thaw(slave->ttl_timer); + ecore_timer_thaw(slave->ttl_timer); - delay = DYNAMICBOX_CONF_SLAVE_TTL - ecore_timer_pending_get(slave->ttl_timer); - ecore_timer_delay(slave->ttl_timer, delay); - return DBOX_STATUS_ERROR_NONE; + delay = DYNAMICBOX_CONF_SLAVE_TTL - ecore_timer_pending_get(slave->ttl_timer); + ecore_timer_delay(slave->ttl_timer, delay); + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_activated(struct slave_node *slave) { - slave->state = SLAVE_RESUMED; + slave->state = SLAVE_RESUMED; - if (xmonitor_is_paused()) { - slave_pause(slave); - } + if (xmonitor_is_paused()) { + slave_pause(slave); + } - if (slave->secured == 1 && DYNAMICBOX_CONF_SLAVE_TTL > 0.0f) { - DbgPrint("Slave deactivation timer is added (%s - %lf)\n", slave_name(slave), DYNAMICBOX_CONF_SLAVE_TTL); - slave->ttl_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_TTL, slave_ttl_cb, slave); - if (!slave->ttl_timer) { - ErrPrint("Failed to create a TTL timer\n"); - } + if (slave->secured == 1 && DYNAMICBOX_CONF_SLAVE_TTL > 0.0f) { + DbgPrint("Slave deactivation timer is added (%s - %lf)\n", slave_name(slave), DYNAMICBOX_CONF_SLAVE_TTL); + slave->ttl_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_TTL, slave_ttl_cb, slave); + if (!slave->ttl_timer) { + ErrPrint("Failed to create a TTL timer\n"); } + } - invoke_activate_cb(slave); + invoke_activate_cb(slave); - slave_set_reactivation(slave, 0); - slave_set_reactivate_instances(slave, 0); + slave_set_reactivation(slave, 0); + slave_set_reactivate_instances(slave, 0); #if defined(_USE_ECORE_TIME_GET) - slave->activated_at = ecore_time_get(); + slave->activated_at = ecore_time_get(); #else - if (gettimeofday(&slave->activated_at, NULL) < 0) { - ErrPrint("Failed to get time of day: %s\n", strerror(errno)); - slave->activated_at.tv_sec = 0; - slave->activated_at.tv_usec = 0; - } + if (gettimeofday(&slave->activated_at, NULL) < 0) { + ErrPrint("Failed to get time of day: %s\n", strerror(errno)); + slave->activated_at.tv_sec = 0; + slave->activated_at.tv_usec = 0; + } #endif - if (slave->activate_timer) { - ecore_timer_del(slave->activate_timer); - slave->activate_timer = NULL; - } + if (slave->activate_timer) { + ecore_timer_del(slave->activate_timer); + slave->activate_timer = NULL; + } - if (slave->relaunch_timer) { - ecore_timer_del(slave->relaunch_timer); - slave->relaunch_timer = NULL; - } + if (slave->relaunch_timer) { + ecore_timer_del(slave->relaunch_timer); + slave->relaunch_timer = NULL; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline int invoke_deactivate_cb(struct slave_node *slave) { - Eina_List *l; - Eina_List *n; - struct event *event; - int ret; - int reactivate = 0; + Eina_List *l; + Eina_List *n; + struct event *event; + int ret; + int reactivate = 0; - slave->in_event_process |= SLAVE_EVENT_PROCESS_DEACTIVATE; + slave->in_event_process |= SLAVE_EVENT_PROCESS_DEACTIVATE; - EINA_LIST_FOREACH_SAFE(slave->event_deactivate_list, l, n, event) { - if (event->deleted) { - slave->event_deactivate_list = eina_list_remove(slave->event_deactivate_list, event); - DbgFree(event); - continue; - } + EINA_LIST_FOREACH_SAFE(slave->event_deactivate_list, l, n, event) { + if (event->deleted) { + slave->event_deactivate_list = eina_list_remove(slave->event_deactivate_list, event); + DbgFree(event); + continue; + } - ret = event->evt_cb(event->slave, event->cbdata); - if (ret < 0 || event->deleted) { - slave->event_deactivate_list = eina_list_remove(slave->event_deactivate_list, event); - DbgFree(event); - } + ret = event->evt_cb(event->slave, event->cbdata); + if (ret < 0 || event->deleted) { + slave->event_deactivate_list = eina_list_remove(slave->event_deactivate_list, event); + DbgFree(event); + } - if (ret == SLAVE_NEED_TO_REACTIVATE) { - reactivate++; - } + if (ret == SLAVE_NEED_TO_REACTIVATE) { + reactivate++; } + } - slave->in_event_process &= ~SLAVE_EVENT_PROCESS_DEACTIVATE; + slave->in_event_process &= ~SLAVE_EVENT_PROCESS_DEACTIVATE; - return reactivate; + return reactivate; } static Eina_Bool terminate_timer_cb(void *data) { - struct slave_node *slave = data; - int ret; + struct slave_node *slave = data; + int ret; - /*! - * \todo - * check the return value of the aul_terminate_pid - */ - slave->state = SLAVE_REQUEST_TO_TERMINATE; - slave->terminate_timer = NULL; + /*! + * \todo + * check the return value of the aul_terminate_pid + */ + slave->state = SLAVE_REQUEST_TO_TERMINATE; + slave->terminate_timer = NULL; - DbgPrint("Terminate slave: %d (%s)\n", slave_pid(slave), slave_name(slave)); - ret = aul_terminate_pid(slave->pid); - if (ret < 0) { - ErrPrint("Terminate slave(%s) failed. pid %d (%d)\n", slave_name(slave), slave_pid(slave), ret); - slave = slave_deactivated(slave); - if (slave == NULL) { - DbgPrint("Slave is deleted\n"); - } + DbgPrint("Terminate slave: %d (%s)\n", slave_pid(slave), slave_name(slave)); + ret = aul_terminate_pid(slave->pid); + if (ret < 0) { + ErrPrint("Terminate slave(%s) failed. pid %d (%d)\n", slave_name(slave), slave_pid(slave), ret); + slave = slave_deactivated(slave); + if (slave == NULL) { + DbgPrint("Slave is deleted\n"); } + } - return ECORE_CALLBACK_CANCEL; + return ECORE_CALLBACK_CANCEL; } HAPI struct slave_node *slave_deactivate(struct slave_node *slave, int no_timer) { - int ret; + int ret; - if (!slave_is_activated(slave)) { - ErrPrint("Slave is already deactivated\n"); - if (slave_loaded_instance(slave) == 0) { - /*! - * \note - * If a slave has no more instances, - * Destroy it - */ - slave = slave_unref(slave); - } - return slave; + if (!slave_is_activated(slave)) { + ErrPrint("Slave is already deactivated\n"); + if (slave_loaded_instance(slave) == 0) { + /*! + * \note + * If a slave has no more instances, + * Destroy it + */ + slave = slave_unref(slave); } + return slave; + } - if (slave_pid(slave) <= 0) { - return slave; - } + if (slave_pid(slave) <= 0) { + return slave; + } - if ((slave->ctrl_option & PROVIDER_CTRL_MANUAL_TERMINATION) == PROVIDER_CTRL_MANUAL_TERMINATION) { - /*! - * \note - * In this case, - * The provider requests MANUAL TERMINATION control option. - * Master will not send terminate request in this case, the provider should be terminated by itself. - */ - DbgPrint("Manual termination is turned on\n"); - slave->state = SLAVE_REQUEST_TO_DISCONNECT; - (void)slave_rpc_disconnect(slave); - } else if (slave->terminate_timer) { - ErrPrint("Terminate timer is already fired (%d)\n", slave->pid); - } else if (!no_timer && !slave->secured) { - DbgPrint("Fire the terminate timer: %d\n", slave->pid); - slave->terminate_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_ACTIVATE_TIME, terminate_timer_cb, slave); - if (!slave->terminate_timer) { - /*! - * \note - * Normally, Call the terminate_timer_cb directly from here - * But in this case. if the aul_terminate_pid failed, Call the slave_deactivated function directly. - * Then the "slave" pointer can be changed. To trace it, Copy the body of terminate_timer_cb to here. - */ - ErrPrint("Failed to add a new timer for terminating\n"); - DbgPrint("Terminate slave: %d (%s)\n", slave_pid(slave), slave_name(slave)); - /*! - * \todo - * check the return value of the aul_terminate_pid - */ - slave->state = SLAVE_REQUEST_TO_TERMINATE; - - ret = aul_terminate_pid(slave->pid); - if (ret < 0) { - ErrPrint("Terminate slave(%s) failed. pid %d (%d)\n", slave_name(slave), slave_pid(slave), ret); - slave = slave_deactivated(slave); - } - } - } else { - /*! - * \todo - * check the return value of the aul_terminate_pid - */ - slave->state = SLAVE_REQUEST_TO_TERMINATE; + if ((slave->ctrl_option & PROVIDER_CTRL_MANUAL_TERMINATION) == PROVIDER_CTRL_MANUAL_TERMINATION) { + /*! + * \note + * In this case, + * The provider requests MANUAL TERMINATION control option. + * Master will not send terminate request in this case, the provider should be terminated by itself. + */ + DbgPrint("Manual termination is turned on\n"); + slave->state = SLAVE_REQUEST_TO_DISCONNECT; + (void)slave_rpc_disconnect(slave); + } else if (slave->terminate_timer) { + ErrPrint("Terminate timer is already fired (%d)\n", slave->pid); + } else if (!no_timer && !slave->secured) { + DbgPrint("Fire the terminate timer: %d\n", slave->pid); + slave->terminate_timer = ecore_timer_add(DYNAMICBOX_CONF_SLAVE_ACTIVATE_TIME, terminate_timer_cb, slave); + if (!slave->terminate_timer) { + /*! + * \note + * Normally, Call the terminate_timer_cb directly from here + * But in this case. if the aul_terminate_pid failed, Call the slave_deactivated function directly. + * Then the "slave" pointer can be changed. To trace it, Copy the body of terminate_timer_cb to here. + */ + ErrPrint("Failed to add a new timer for terminating\n"); + DbgPrint("Terminate slave: %d (%s)\n", slave_pid(slave), slave_name(slave)); + /*! + * \todo + * check the return value of the aul_terminate_pid + */ + slave->state = SLAVE_REQUEST_TO_TERMINATE; + + ret = aul_terminate_pid(slave->pid); + if (ret < 0) { + ErrPrint("Terminate slave(%s) failed. pid %d (%d)\n", slave_name(slave), slave_pid(slave), ret); + slave = slave_deactivated(slave); + } + } + } else { + /*! + * \todo + * check the return value of the aul_terminate_pid + */ + slave->state = SLAVE_REQUEST_TO_TERMINATE; - DbgPrint("Terminate slave: %d (%s)\n", slave_pid(slave), slave_name(slave)); - ret = aul_terminate_pid(slave->pid); - if (ret < 0) { - ErrPrint("Terminate slave(%s) failed. pid %d (%d)\n", slave_name(slave), slave_pid(slave), ret); - slave = slave_deactivated(slave); - } + DbgPrint("Terminate slave: %d (%s)\n", slave_pid(slave), slave_name(slave)); + ret = aul_terminate_pid(slave->pid); + if (ret < 0) { + ErrPrint("Terminate slave(%s) failed. pid %d (%d)\n", slave_name(slave), slave_pid(slave), ret); + slave = slave_deactivated(slave); } + } - return slave; + return slave; } HAPI struct slave_node *slave_deactivated(struct slave_node *slave) { - int reactivate; + int reactivate; - slave->pid = (pid_t)-1; - slave->state = SLAVE_TERMINATED; + slave->pid = (pid_t)-1; + slave->state = SLAVE_TERMINATED; - if (slave->ttl_timer) { - ecore_timer_del(slave->ttl_timer); - slave->ttl_timer = NULL; - } + if (slave->ttl_timer) { + ecore_timer_del(slave->ttl_timer); + slave->ttl_timer = NULL; + } - if (slave->activate_timer) { - ecore_timer_del(slave->activate_timer); - slave->activate_timer = NULL; - } + if (slave->activate_timer) { + ecore_timer_del(slave->activate_timer); + slave->activate_timer = NULL; + } - if (slave->relaunch_timer) { - ecore_timer_del(slave->relaunch_timer); - slave->relaunch_timer = NULL; - } + if (slave->relaunch_timer) { + ecore_timer_del(slave->relaunch_timer); + slave->relaunch_timer = NULL; + } - if (slave->terminate_timer) { - ecore_timer_del(slave->terminate_timer); - slave->terminate_timer = NULL; - } + if (slave->terminate_timer) { + ecore_timer_del(slave->terminate_timer); + slave->terminate_timer = NULL; + } - reactivate = invoke_deactivate_cb(slave); + reactivate = invoke_deactivate_cb(slave); - slave = slave_unref(slave); - if (!slave) { - DbgPrint("SLAVE object is destroyed\n"); - return slave; - } + slave = slave_unref(slave); + if (!slave) { + DbgPrint("SLAVE object is destroyed\n"); + return slave; + } - if ((slave->ctrl_option & PROVIDER_CTRL_MANUAL_REACTIVATION) == PROVIDER_CTRL_MANUAL_REACTIVATION) { - /*! - * \note - * In this case, the provider(Slave) should be reactivated by itself or user. - * The master will not reactivate it automatically. - */ - DbgPrint("Manual reactivate option is turned on\n"); - } else if (reactivate && slave_need_to_reactivate(slave)) { - int ret; - - DbgPrint("Need to reactivate a slave\n"); - ret = slave_activate(slave); - if (ret < 0 && ret != DBOX_STATUS_ERROR_ALREADY) { - ErrPrint("Failed to reactivate a slave\n"); - } - } else if (slave_loaded_instance(slave) == 0) { - /*! - * \note - * If a slave has no more instances, - * Destroy it - */ - slave = slave_unref(slave); + if ((slave->ctrl_option & PROVIDER_CTRL_MANUAL_REACTIVATION) == PROVIDER_CTRL_MANUAL_REACTIVATION) { + /*! + * \note + * In this case, the provider(Slave) should be reactivated by itself or user. + * The master will not reactivate it automatically. + */ + DbgPrint("Manual reactivate option is turned on\n"); + } else if (reactivate && slave_need_to_reactivate(slave)) { + int ret; + + DbgPrint("Need to reactivate a slave\n"); + ret = slave_activate(slave); + if (ret < 0 && ret != DBOX_STATUS_ERROR_ALREADY) { + ErrPrint("Failed to reactivate a slave\n"); } + } else if (slave_loaded_instance(slave) == 0) { + /*! + * \note + * If a slave has no more instances, + * Destroy it + */ + slave = slave_unref(slave); + } - return slave; + return slave; } HAPI struct slave_node *slave_deactivated_by_fault(struct slave_node *slave) { - int ret; - int reactivate = 1; - int reactivate_instances = 1; - int max_load; + int ret; + int reactivate = 1; + int reactivate_instances = 1; + int max_load; - if (g_conf.slave_max_load < 0) { - max_load = DYNAMICBOX_CONF_SLAVE_MAX_LOAD; - } else { - max_load = g_conf.slave_max_load; - } + if (g_conf.slave_max_load < 0) { + max_load = DYNAMICBOX_CONF_SLAVE_MAX_LOAD; + } else { + max_load = g_conf.slave_max_load; + } - if (!slave_is_activated(slave)) { - DbgPrint("Deactivating in progress\n"); - if (slave_loaded_instance(slave) == 0) { - slave = slave_unref(slave); - } - - return slave; + if (!slave_is_activated(slave)) { + DbgPrint("Deactivating in progress\n"); + if (slave_loaded_instance(slave) == 0) { + slave = slave_unref(slave); } - slave->fault_count++; + return slave; + } - (void)fault_check_pkgs(slave); + slave->fault_count++; - if (slave_pid(slave) > 0) { - DbgPrint("Try to terminate PID: %d\n", slave_pid(slave)); - ret = aul_terminate_pid(slave_pid(slave)); - if (ret < 0) { - ErrPrint("Terminate failed, pid %d\n", slave_pid(slave)); - } + (void)fault_check_pkgs(slave); + + if (slave_pid(slave) > 0) { + DbgPrint("Try to terminate PID: %d\n", slave_pid(slave)); + ret = aul_terminate_pid(slave_pid(slave)); + if (ret < 0) { + ErrPrint("Terminate failed, pid %d\n", slave_pid(slave)); } + } #if defined(_USE_ECORE_TIME_GET) - double faulted_at; - - faulted_at = ecore_time_get(); - if (faulted_at - slave->activated_at < DYNAMICBOX_CONF_MINIMUM_REACTIVATION_TIME) { - slave->critical_fault_count++; - - if (!slave_loaded_instance(slave) || slave->critical_fault_count >= max_load) { - ErrPrint("Reactivation time is too fast and frequently occurred - Stop to auto reactivation\n"); - reactivate = 0; - reactivate_instances = 0; - slave->critical_fault_count = 0; - /*! - * \note - * Fault callback can access the slave information. - */ - invoke_fault_cb(slave); - } else { - slave->critical_fault_count = 0; - } + double faulted_at; + + faulted_at = ecore_time_get(); + if (faulted_at - slave->activated_at < DYNAMICBOX_CONF_MINIMUM_REACTIVATION_TIME) { + slave->critical_fault_count++; + + if (!slave_loaded_instance(slave) || slave->critical_fault_count >= max_load) { + ErrPrint("Reactivation time is too fast and frequently occurred - Stop to auto reactivation\n"); + reactivate = 0; + reactivate_instances = 0; + slave->critical_fault_count = 0; + /*! + * \note + * Fault callback can access the slave information. + */ + invoke_fault_cb(slave); + } else { + slave->critical_fault_count = 0; } + } #else - struct timeval faulted_at; - - if (gettimeofday(&faulted_at, NULL) == 0) { - struct timeval rtv; - - timersub(&faulted_at, &slave->activated_at, &rtv); - if (rtv.tv_sec < DYNAMICBOX_CONF_MINIMUM_REACTIVATION_TIME) { - slave->critical_fault_count++; - if (!slave_loaded_instance(slave) || slave->critical_fault_count >= max_load) { - ErrPrint("Reactivation time is too fast and frequently occurred - Stop to auto reactivation\n"); - reactivate = 0; - reactivate_instances = 0; - slave->critical_fault_count = 0; - /*! - * \note - * Fault callback can access the slave information. - */ - invoke_fault_cb(slave); - } - } else { - slave->critical_fault_count = 0; - } + struct timeval faulted_at; + + if (gettimeofday(&faulted_at, NULL) == 0) { + struct timeval rtv; + + timersub(&faulted_at, &slave->activated_at, &rtv); + if (rtv.tv_sec < DYNAMICBOX_CONF_MINIMUM_REACTIVATION_TIME) { + slave->critical_fault_count++; + if (!slave_loaded_instance(slave) || slave->critical_fault_count >= max_load) { + ErrPrint("Reactivation time is too fast and frequently occurred - Stop to auto reactivation\n"); + reactivate = 0; + reactivate_instances = 0; + slave->critical_fault_count = 0; + /*! + * \note + * Fault callback can access the slave information. + */ + invoke_fault_cb(slave); + } } else { - ErrPrint("Failed to get time of day: %s\n", strerror(errno)); + slave->critical_fault_count = 0; } + } else { + ErrPrint("Failed to get time of day: %s\n", strerror(errno)); + } #endif - slave_set_reactivation(slave, reactivate); - slave_set_reactivate_instances(slave, reactivate_instances); + slave_set_reactivation(slave, reactivate); + slave_set_reactivate_instances(slave, reactivate_instances); - slave = slave_deactivated(slave); - return slave; + slave = slave_deactivated(slave); + return slave; } HAPI const int const slave_is_activated(struct slave_node *slave) { - switch (slave->state) { + switch (slave->state) { case SLAVE_REQUEST_TO_TERMINATE: case SLAVE_TERMINATED: - return 0; + return 0; case SLAVE_REQUEST_TO_DISCONNECT: - /* This case should be treated as an activated state. - * To send the last request to the provider. - */ + /* This case should be treated as an activated state. + * To send the last request to the provider. + */ case SLAVE_REQUEST_TO_LAUNCH: - /* Not yet launched. but the slave incurred an unexpected error */ + /* Not yet launched. but the slave incurred an unexpected error */ case SLAVE_REQUEST_TO_PAUSE: case SLAVE_REQUEST_TO_RESUME: case SLAVE_PAUSED: case SLAVE_RESUMED: - return 1; + return 1; default: - return slave->pid != (pid_t)-1; - } + return slave->pid != (pid_t)-1; + } - /* Could not be reach to here */ - return 0; + /* Could not be reach to here */ + return 0; } HAPI int slave_event_callback_add(struct slave_node *slave, enum slave_event event, int (*cb)(struct slave_node *, void *), void *data) { - struct event *ev; - - ev = calloc(1, sizeof(*ev)); - if (!ev) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - ev->slave = slave; - ev->cbdata = data; - ev->evt_cb = cb; - - /*! - * \note - * Use the eina_list_prepend API. - * To keep the sequence of a callback invocation. - * - * Here is an example sequence. - * - * slave_event_callback_add(CALLBACK_01); - * slave_event_callback_add(CALLBACK_02); - * slave_event_callback_add(CALLBACK_03); - * - * Then the invoke_event_callback function will call the CALLBACKS as below sequence - * - * invoke_CALLBACK_03 - * invoke_CALLBACK_02 - * invoke_CALLBACK_01 - */ - - switch (event) { + struct event *ev; + + ev = calloc(1, sizeof(*ev)); + if (!ev) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + ev->slave = slave; + ev->cbdata = data; + ev->evt_cb = cb; + + /*! + * \note + * Use the eina_list_prepend API. + * To keep the sequence of a callback invocation. + * + * Here is an example sequence. + * + * slave_event_callback_add(CALLBACK_01); + * slave_event_callback_add(CALLBACK_02); + * slave_event_callback_add(CALLBACK_03); + * + * Then the invoke_event_callback function will call the CALLBACKS as below sequence + * + * invoke_CALLBACK_03 + * invoke_CALLBACK_02 + * invoke_CALLBACK_01 + */ + + switch (event) { case SLAVE_EVENT_ACTIVATE: - slave->event_activate_list = eina_list_prepend(slave->event_activate_list, ev); - break; + slave->event_activate_list = eina_list_prepend(slave->event_activate_list, ev); + break; case SLAVE_EVENT_DELETE: - slave->event_delete_list = eina_list_prepend(slave->event_delete_list, ev); - break; + slave->event_delete_list = eina_list_prepend(slave->event_delete_list, ev); + break; case SLAVE_EVENT_DEACTIVATE: - slave->event_deactivate_list = eina_list_prepend(slave->event_deactivate_list, ev); - break; + slave->event_deactivate_list = eina_list_prepend(slave->event_deactivate_list, ev); + break; case SLAVE_EVENT_PAUSE: - slave->event_pause_list = eina_list_prepend(slave->event_pause_list, ev); - break; + slave->event_pause_list = eina_list_prepend(slave->event_pause_list, ev); + break; case SLAVE_EVENT_RESUME: - slave->event_resume_list = eina_list_prepend(slave->event_resume_list, ev); - break; + slave->event_resume_list = eina_list_prepend(slave->event_resume_list, ev); + break; case SLAVE_EVENT_FAULT: - slave->event_fault_list = eina_list_prepend(slave->event_fault_list, ev); - break; + slave->event_fault_list = eina_list_prepend(slave->event_fault_list, ev); + break; default: - DbgFree(ev); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + DbgFree(ev); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_event_callback_del(struct slave_node *slave, enum slave_event event, int (*cb)(struct slave_node *, void *), void *data) { - struct event *ev; - Eina_List *l; - Eina_List *n; + struct event *ev; + Eina_List *l; + Eina_List *n; - switch (event) { + switch (event) { case SLAVE_EVENT_DEACTIVATE: - EINA_LIST_FOREACH_SAFE(slave->event_deactivate_list, l, n, ev) { - if (ev->evt_cb == cb && ev->cbdata == data) { - if (slave->in_event_process & SLAVE_EVENT_PROCESS_DEACTIVATE) { - ev->deleted = 1; - } else { - slave->event_deactivate_list = eina_list_remove(slave->event_deactivate_list, ev); - DbgFree(ev); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(slave->event_deactivate_list, l, n, ev) { + if (ev->evt_cb == cb && ev->cbdata == data) { + if (slave->in_event_process & SLAVE_EVENT_PROCESS_DEACTIVATE) { + ev->deleted = 1; + } else { + slave->event_deactivate_list = eina_list_remove(slave->event_deactivate_list, ev); + DbgFree(ev); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case SLAVE_EVENT_DELETE: - EINA_LIST_FOREACH_SAFE(slave->event_delete_list, l, n, ev) { - if (ev->evt_cb == cb && ev->cbdata == data) { - if (slave->in_event_process & SLAVE_EVENT_PROCESS_DELETE) { - ev->deleted = 1; - } else { - slave->event_delete_list = eina_list_remove(slave->event_delete_list, ev); - DbgFree(ev); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(slave->event_delete_list, l, n, ev) { + if (ev->evt_cb == cb && ev->cbdata == data) { + if (slave->in_event_process & SLAVE_EVENT_PROCESS_DELETE) { + ev->deleted = 1; + } else { + slave->event_delete_list = eina_list_remove(slave->event_delete_list, ev); + DbgFree(ev); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case SLAVE_EVENT_ACTIVATE: - EINA_LIST_FOREACH_SAFE(slave->event_activate_list, l, n, ev) { - if (ev->evt_cb == cb && ev->cbdata == data) { - if (slave->in_event_process & SLAVE_EVENT_PROCESS_ACTIVATE) { - ev->deleted = 1; - } else { - slave->event_activate_list = eina_list_remove(slave->event_activate_list, ev); - DbgFree(ev); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(slave->event_activate_list, l, n, ev) { + if (ev->evt_cb == cb && ev->cbdata == data) { + if (slave->in_event_process & SLAVE_EVENT_PROCESS_ACTIVATE) { + ev->deleted = 1; + } else { + slave->event_activate_list = eina_list_remove(slave->event_activate_list, ev); + DbgFree(ev); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case SLAVE_EVENT_PAUSE: - EINA_LIST_FOREACH_SAFE(slave->event_pause_list, l, n, ev) { - if (ev->evt_cb == cb && ev->cbdata == data) { - if (slave->in_event_process & SLAVE_EVENT_PROCESS_PAUSE) { - ev->deleted = 1; - } else { - slave->event_pause_list = eina_list_remove(slave->event_pause_list, ev); - DbgFree(ev); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(slave->event_pause_list, l, n, ev) { + if (ev->evt_cb == cb && ev->cbdata == data) { + if (slave->in_event_process & SLAVE_EVENT_PROCESS_PAUSE) { + ev->deleted = 1; + } else { + slave->event_pause_list = eina_list_remove(slave->event_pause_list, ev); + DbgFree(ev); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case SLAVE_EVENT_RESUME: - EINA_LIST_FOREACH_SAFE(slave->event_resume_list, l, n, ev) { - if (ev->evt_cb == cb && ev->cbdata == data) { - if (slave->in_event_process & SLAVE_EVENT_PROCESS_RESUME) { - ev->deleted = 1; - } else { - slave->event_resume_list = eina_list_remove(slave->event_resume_list, ev); - DbgFree(ev); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(slave->event_resume_list, l, n, ev) { + if (ev->evt_cb == cb && ev->cbdata == data) { + if (slave->in_event_process & SLAVE_EVENT_PROCESS_RESUME) { + ev->deleted = 1; + } else { + slave->event_resume_list = eina_list_remove(slave->event_resume_list, ev); + DbgFree(ev); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case SLAVE_EVENT_FAULT: - EINA_LIST_FOREACH_SAFE(slave->event_fault_list, l, n, ev) { - if (ev->evt_cb == cb && ev->cbdata == data) { - if (slave->in_event_process & SLAVE_EVENT_PROCESS_FAULT) { - ev->deleted = 1; - } else { - slave->event_fault_list = eina_list_remove(slave->event_fault_list, ev); - DbgFree(ev); - } - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(slave->event_fault_list, l, n, ev) { + if (ev->evt_cb == cb && ev->cbdata == data) { + if (slave->in_event_process & SLAVE_EVENT_PROCESS_FAULT) { + ev->deleted = 1; + } else { + slave->event_fault_list = eina_list_remove(slave->event_fault_list, ev); + DbgFree(ev); + } + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int slave_set_data(struct slave_node *slave, const char *tag, void *data) { - struct priv_data *priv; + struct priv_data *priv; - priv = calloc(1, sizeof(*priv)); - if (!priv) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + priv = calloc(1, sizeof(*priv)); + if (!priv) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - priv->tag = strdup(tag); - if (!priv->tag) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(priv); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + priv->tag = strdup(tag); + if (!priv->tag) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(priv); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - priv->data = data; - slave->data_list = eina_list_append(slave->data_list, priv); - return DBOX_STATUS_ERROR_NONE; + priv->data = data; + slave->data_list = eina_list_append(slave->data_list, priv); + return DBOX_STATUS_ERROR_NONE; } HAPI void *slave_del_data(struct slave_node *slave, const char *tag) { - struct priv_data *priv; - void *data; - Eina_List *l; - Eina_List *n; + struct priv_data *priv; + void *data; + Eina_List *l; + Eina_List *n; - EINA_LIST_FOREACH_SAFE(slave->data_list, l, n, priv) { - if (!strcmp(priv->tag, tag)) { - slave->data_list = eina_list_remove(slave->data_list, priv); + EINA_LIST_FOREACH_SAFE(slave->data_list, l, n, priv) { + if (!strcmp(priv->tag, tag)) { + slave->data_list = eina_list_remove(slave->data_list, priv); - data = priv->data; - DbgFree(priv->tag); - DbgFree(priv); - return data; - } + data = priv->data; + DbgFree(priv->tag); + DbgFree(priv); + return data; } + } - return NULL; + return NULL; } HAPI void *slave_data(struct slave_node *slave, const char *tag) { - struct priv_data *priv; - Eina_List *l; + struct priv_data *priv; + Eina_List *l; - EINA_LIST_FOREACH(slave->data_list, l, priv) { - if (!strcmp(priv->tag, tag)) { - return priv->data; - } + EINA_LIST_FOREACH(slave->data_list, l, priv) { + if (!strcmp(priv->tag, tag)) { + return priv->data; } + } - return NULL; + return NULL; } HAPI struct slave_node *slave_find_by_pid(pid_t pid) { - Eina_List *l; - struct slave_node *slave; + Eina_List *l; + struct slave_node *slave; - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - if (slave_pid(slave) == pid) { - return slave; - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + if (slave_pid(slave) == pid) { + return slave; } + } - return NULL; + return NULL; } HAPI struct slave_node *slave_find_by_name(const char *name) { - Eina_List *l; - struct slave_node *slave; + Eina_List *l; + struct slave_node *slave; - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - if (!strcmp(slave_name(slave), name)) { - return slave; - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + if (!strcmp(slave_name(slave), name)) { + return slave; } + } - return NULL; + return NULL; } HAPI struct slave_node *slave_find_available(const char *slave_pkgname, const char *abi, int secured, int network) { - Eina_List *l; - struct slave_node *slave; + Eina_List *l; + struct slave_node *slave; - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - if (slave->secured != secured) { - continue; - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + if (slave->secured != secured) { + continue; + } - if ((slave->state == SLAVE_REQUEST_TO_TERMINATE || slave->state == SLAVE_REQUEST_TO_DISCONNECT) && slave->loaded_instance == 0) { - /*! - * \note - * If a slave is in request_to_terminate state, - * and the slave object has no more intances, - * the slave object will be deleted soon. - * so we cannot reuse it. - * - * This object is not usable. - */ - continue; - } + if ((slave->state == SLAVE_REQUEST_TO_TERMINATE || slave->state == SLAVE_REQUEST_TO_DISCONNECT) && slave->loaded_instance == 0) { + /*! + * \note + * If a slave is in request_to_terminate state, + * and the slave object has no more intances, + * the slave object will be deleted soon. + * so we cannot reuse it. + * + * This object is not usable. + */ + continue; + } - if (strcasecmp(slave->abi, abi)) { - continue; - } + if (strcasecmp(slave->abi, abi)) { + continue; + } - if (strcasecmp(slave->pkgname, slave_pkgname)) { - continue; + if (strcasecmp(slave->pkgname, slave_pkgname)) { + continue; + } + + if (slave->secured) { + if (slave->loaded_package == 0) { + DbgPrint("Found secured slave - has no instances (%s)\n", slave_name(slave)); + return slave; + } + } else if (slave->network == network) { + DbgPrint("slave[%s] loaded_package[%d] net: [%d]\n", slave_name(slave), slave->loaded_package, slave->network); + if (!strcasecmp(abi, DYNAMICBOX_CONF_DEFAULT_ABI)) { + int max_load; + if (g_conf.slave_max_load < 0) { + max_load = DYNAMICBOX_CONF_SLAVE_MAX_LOAD; + } else { + max_load = g_conf.slave_max_load; } - if (slave->secured) { - if (slave->loaded_package == 0) { - DbgPrint("Found secured slave - has no instances (%s)\n", slave_name(slave)); - return slave; - } - } else if (slave->network == network) { - DbgPrint("slave[%s] loaded_package[%d] net: [%d]\n", slave_name(slave), slave->loaded_package, slave->network); - if (!strcasecmp(abi, DYNAMICBOX_CONF_DEFAULT_ABI)) { - int max_load; - if (g_conf.slave_max_load < 0) { - max_load = DYNAMICBOX_CONF_SLAVE_MAX_LOAD; - } else { - max_load = g_conf.slave_max_load; - } - - if (slave->loaded_package < max_load) { - return slave; - } - } else { - return slave; - } + if (slave->loaded_package < max_load) { + return slave; } + } else { + return slave; + } } + } - return NULL; + return NULL; } HAPI struct slave_node *slave_find_by_pkgname(const char *pkgname) { - Eina_List *l; - struct slave_node *slave; + Eina_List *l; + struct slave_node *slave; - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - if (!strcmp(slave_pkgname(slave), pkgname)) { - if (slave_pid(slave) == (pid_t)-1) { - return slave; - } - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + if (!strcmp(slave_pkgname(slave), pkgname)) { + if (slave_pid(slave) == (pid_t)-1) { + return slave; + } } + } - return NULL; + return NULL; } HAPI struct slave_node *slave_find_by_rpc_handle(int handle) { - Eina_List *l; - struct slave_node *slave; + Eina_List *l; + struct slave_node *slave; - if (handle <= 0) { - ErrPrint("Invalid RPC handle: %d\n", handle); - return NULL; - } + if (handle <= 0) { + ErrPrint("Invalid RPC handle: %d\n", handle); + return NULL; + } - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - if (slave_rpc_handle(slave) == handle) { - return slave; - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + if (slave_rpc_handle(slave) == handle) { + return slave; } + } - /* Not found */ - return NULL; + /* Not found */ + return NULL; } HAPI char *slave_package_name(const char *abi, const char *lbid) { - char *s_pkgname; - const char *tmp; + char *s_pkgname; + const char *tmp; - tmp = abi_find_slave(abi); - if (!tmp) { - ErrPrint("Failed to find a proper pkgname of a slave\n"); - return NULL; - } + tmp = abi_find_slave(abi); + if (!tmp) { + ErrPrint("Failed to find a proper pkgname of a slave\n"); + return NULL; + } - s_pkgname = util_replace_string(tmp, DYNAMICBOX_CONF_REPLACE_TAG_APPID, lbid); + s_pkgname = util_replace_string(tmp, DYNAMICBOX_CONF_REPLACE_TAG_APPID, lbid); + if (!s_pkgname) { + DbgPrint("Failed to get replaced string\n"); + s_pkgname = strdup(tmp); if (!s_pkgname) { - DbgPrint("Failed to get replaced string\n"); - s_pkgname = strdup(tmp); - if (!s_pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; } + } - return s_pkgname; + return s_pkgname; } HAPI void slave_load_package(struct slave_node *slave) { - slave->loaded_package++; + slave->loaded_package++; } HAPI void slave_unload_package(struct slave_node *slave) { - if (!slave || slave->loaded_package == 0) { - ErrPrint("Slave loaded package is not correct\n"); - return; - } - - slave->loaded_package--; + if (!slave || slave->loaded_package == 0) { + ErrPrint("Slave loaded package is not correct\n"); + return; + } + + slave->loaded_package--; } HAPI void slave_load_instance(struct slave_node *slave) { - slave->loaded_instance++; - DbgPrint("Instance: (%d)%d\n", slave_pid(slave), slave->loaded_instance); + slave->loaded_instance++; + DbgPrint("Instance: (%d)%d\n", slave_pid(slave), slave->loaded_instance); } HAPI int const slave_loaded_instance(struct slave_node *slave) { - return slave->loaded_instance; + return slave->loaded_instance; } HAPI int const slave_loaded_package(struct slave_node *slave) { - return slave->loaded_package; + return slave->loaded_package; } HAPI struct slave_node *slave_unload_instance(struct slave_node *slave) { - if (!slave || slave->loaded_instance == 0) { - ErrPrint("Slave loaded instance is not correct\n"); - return slave; - } + if (!slave || slave->loaded_instance == 0) { + ErrPrint("Slave loaded instance is not correct\n"); + return slave; + } - slave->loaded_instance--; - DbgPrint("Instance: (%d)%d\n", slave_pid(slave), slave->loaded_instance); - if (slave->loaded_instance == 0 && slave_is_activated(slave)) { - slave_set_reactivation(slave, 0); - slave_set_reactivate_instances(slave, 0); + slave->loaded_instance--; + DbgPrint("Instance: (%d)%d\n", slave_pid(slave), slave->loaded_instance); + if (slave->loaded_instance == 0 && slave_is_activated(slave)) { + slave_set_reactivation(slave, 0); + slave_set_reactivate_instances(slave, 0); - slave = slave_deactivate(slave, 0); - } + slave = slave_deactivate(slave, 0); + } - return slave; + return slave; } HAPI const int const slave_is_secured(const struct slave_node *slave) { - return slave->secured; + return slave->secured; } HAPI const char * const slave_name(const struct slave_node *slave) { - return slave->name; + return slave->name; } HAPI const char * const slave_abi(const struct slave_node *slave) { - return slave->abi; + return slave->abi; } HAPI const pid_t const slave_pid(const struct slave_node *slave) { - return slave->pid; + return slave->pid; } HAPI int slave_set_pid(struct slave_node *slave, pid_t pid) { - if (!slave) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - DbgPrint("Slave PID is updated to %d from %d\n", pid, slave_pid(slave)); + DbgPrint("Slave PID is updated to %d from %d\n", pid, slave_pid(slave)); - slave->pid = pid; - return DBOX_STATUS_ERROR_NONE; + slave->pid = pid; + return DBOX_STATUS_ERROR_NONE; } static inline void invoke_resumed_cb(struct slave_node *slave) { - Eina_List *l; - Eina_List *n; - struct event *event; + Eina_List *l; + Eina_List *n; + struct event *event; - slave->in_event_process |= SLAVE_EVENT_PROCESS_RESUME; - EINA_LIST_FOREACH_SAFE(slave->event_resume_list, l, n, event) { - if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { - slave->event_resume_list = eina_list_remove(slave->event_resume_list, event); - DbgFree(event); - } + slave->in_event_process |= SLAVE_EVENT_PROCESS_RESUME; + EINA_LIST_FOREACH_SAFE(slave->event_resume_list, l, n, event) { + if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { + slave->event_resume_list = eina_list_remove(slave->event_resume_list, event); + DbgFree(event); } - slave->in_event_process &= ~SLAVE_EVENT_PROCESS_RESUME; + } + slave->in_event_process &= ~SLAVE_EVENT_PROCESS_RESUME; } static void resume_cb(struct slave_node *slave, const struct packet *packet, void *data) { - int ret; + int ret; - if (slave->state == SLAVE_REQUEST_TO_TERMINATE || slave->state == SLAVE_REQUEST_TO_DISCONNECT) { - DbgPrint("Slave is terminating now. ignore resume result\n"); - return; - } + if (slave->state == SLAVE_REQUEST_TO_TERMINATE || slave->state == SLAVE_REQUEST_TO_DISCONNECT) { + DbgPrint("Slave is terminating now. ignore resume result\n"); + return; + } - if (!packet) { - ErrPrint("Failed to change the state of the slave\n"); - slave->state = SLAVE_PAUSED; - return; - } + if (!packet) { + ErrPrint("Failed to change the state of the slave\n"); + slave->state = SLAVE_PAUSED; + return; + } - if (packet_get(packet, "i", &ret) != 1) { - ErrPrint("Invalid parameter\n"); - return; - } + if (packet_get(packet, "i", &ret) != 1) { + ErrPrint("Invalid parameter\n"); + return; + } - if (ret == 0) { - slave->state = SLAVE_RESUMED; - slave_rpc_ping_thaw(slave); - invoke_resumed_cb(slave); - } + if (ret == 0) { + slave->state = SLAVE_RESUMED; + slave_rpc_ping_thaw(slave); + invoke_resumed_cb(slave); + } } static inline void invoke_paused_cb(struct slave_node *slave) { - Eina_List *l; - Eina_List *n; - struct event *event; + Eina_List *l; + Eina_List *n; + struct event *event; - slave->in_event_process |= SLAVE_EVENT_PROCESS_PAUSE; - EINA_LIST_FOREACH_SAFE(slave->event_pause_list, l, n, event) { - if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { - slave->event_pause_list = eina_list_remove(slave->event_pause_list, event); - DbgFree(event); - } + slave->in_event_process |= SLAVE_EVENT_PROCESS_PAUSE; + EINA_LIST_FOREACH_SAFE(slave->event_pause_list, l, n, event) { + if (event->deleted || event->evt_cb(event->slave, event->cbdata) < 0 || event->deleted) { + slave->event_pause_list = eina_list_remove(slave->event_pause_list, event); + DbgFree(event); } - slave->in_event_process &= ~SLAVE_EVENT_PROCESS_PAUSE; + } + slave->in_event_process &= ~SLAVE_EVENT_PROCESS_PAUSE; } static void pause_cb(struct slave_node *slave, const struct packet *packet, void *data) { - int ret; + int ret; - if (slave->state == SLAVE_REQUEST_TO_TERMINATE || slave->state == SLAVE_REQUEST_TO_DISCONNECT) { - DbgPrint("Slave is terminating now. ignore pause result\n"); - return; - } + if (slave->state == SLAVE_REQUEST_TO_TERMINATE || slave->state == SLAVE_REQUEST_TO_DISCONNECT) { + DbgPrint("Slave is terminating now. ignore pause result\n"); + return; + } - if (!packet) { - ErrPrint("Failed to change the state of the slave\n"); - slave->state = SLAVE_RESUMED; - return; - } + if (!packet) { + ErrPrint("Failed to change the state of the slave\n"); + slave->state = SLAVE_RESUMED; + return; + } - if (packet_get(packet, "i", &ret) != 1) { - ErrPrint("Invalid parameter\n"); - return; - } + if (packet_get(packet, "i", &ret) != 1) { + ErrPrint("Invalid parameter\n"); + return; + } - if (ret == 0) { - slave->state = SLAVE_PAUSED; - slave_rpc_ping_freeze(slave); - invoke_paused_cb(slave); - } + if (ret == 0) { + slave->state = SLAVE_PAUSED; + slave_rpc_ping_freeze(slave); + invoke_paused_cb(slave); + } } HAPI int slave_resume(struct slave_node *slave) { - double timestamp; - struct packet *packet; - unsigned int cmd = CMD_RESUME; + double timestamp; + struct packet *packet; + unsigned int cmd = CMD_RESUME; - switch (slave->state) { + switch (slave->state) { case SLAVE_REQUEST_TO_DISCONNECT: case SLAVE_REQUEST_TO_LAUNCH: case SLAVE_REQUEST_TO_TERMINATE: case SLAVE_TERMINATED: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; case SLAVE_RESUMED: case SLAVE_REQUEST_TO_RESUME: - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; default: - break; - } + break; + } - timestamp = util_timestamp(); + timestamp = util_timestamp(); - packet = packet_create((const char *)&cmd, "d", timestamp); - if (!packet) { - ErrPrint("Failed to prepare param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "d", timestamp); + if (!packet) { + ErrPrint("Failed to prepare param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - slave->state = SLAVE_REQUEST_TO_RESUME; - return slave_rpc_async_request(slave, NULL, packet, resume_cb, NULL, 0); + slave->state = SLAVE_REQUEST_TO_RESUME; + return slave_rpc_async_request(slave, NULL, packet, resume_cb, NULL, 0); } HAPI int slave_pause(struct slave_node *slave) { - double timestamp; - struct packet *packet; - unsigned int cmd = CMD_PAUSE; + double timestamp; + struct packet *packet; + unsigned int cmd = CMD_PAUSE; - switch (slave->state) { + switch (slave->state) { case SLAVE_REQUEST_TO_DISCONNECT: case SLAVE_REQUEST_TO_LAUNCH: case SLAVE_REQUEST_TO_TERMINATE: case SLAVE_TERMINATED: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; case SLAVE_PAUSED: case SLAVE_REQUEST_TO_PAUSE: - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; default: - break; - } + break; + } - timestamp = util_timestamp(); + timestamp = util_timestamp(); - packet = packet_create((const char *)&cmd, "d", timestamp); - if (!packet) { - ErrPrint("Failed to prepare param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "d", timestamp); + if (!packet) { + ErrPrint("Failed to prepare param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - slave->state = SLAVE_REQUEST_TO_PAUSE; - return slave_rpc_async_request(slave, NULL, packet, pause_cb, NULL, 0); + slave->state = SLAVE_REQUEST_TO_PAUSE; + return slave_rpc_async_request(slave, NULL, packet, pause_cb, NULL, 0); } HAPI const char *slave_pkgname(const struct slave_node *slave) { - return slave ? slave->pkgname : NULL; + return slave ? slave->pkgname : NULL; } HAPI enum slave_state slave_state(const struct slave_node *slave) { - return slave ? slave->state : SLAVE_ERROR; + return slave ? slave->state : SLAVE_ERROR; } HAPI const char *slave_state_string(const struct slave_node *slave) { - switch (slave->state) { + switch (slave->state) { case SLAVE_REQUEST_TO_DISCONNECT: - return "RequestToDisconnect"; + return "RequestToDisconnect"; case SLAVE_REQUEST_TO_LAUNCH: - return "RequestToLaunch"; + return "RequestToLaunch"; case SLAVE_REQUEST_TO_TERMINATE: - return "RequestToTerminate"; + return "RequestToTerminate"; case SLAVE_TERMINATED: - return "Terminated"; + return "Terminated"; case SLAVE_REQUEST_TO_PAUSE: - return "RequestToPause"; + return "RequestToPause"; case SLAVE_REQUEST_TO_RESUME: - return "RequestToResume"; + return "RequestToResume"; case SLAVE_PAUSED: - return "Paused"; + return "Paused"; case SLAVE_RESUMED: - return "Resumed"; + return "Resumed"; case SLAVE_ERROR: - return "Error"; + return "Error"; default: - break; - } + break; + } - return "Unknown"; + return "Unknown"; } HAPI const void *slave_list(void) { - return s_info.slave_list; + return s_info.slave_list; } HAPI int const slave_fault_count(const struct slave_node *slave) { - return slave->fault_count; + return slave->fault_count; } HAPI double const slave_ttl(const struct slave_node *slave) { - if (!slave->ttl_timer) { - return 0.0f; - } + if (!slave->ttl_timer) { + return 0.0f; + } - return ecore_timer_pending_get(slave->ttl_timer); + return ecore_timer_pending_get(slave->ttl_timer); } HAPI void slave_set_reactivate_instances(struct slave_node *slave, int reactivate) { - slave->reactivate_instances = reactivate; + slave->reactivate_instances = reactivate; } HAPI int slave_need_to_reactivate_instances(struct slave_node *slave) { - return slave->reactivate_instances; + return slave->reactivate_instances; } HAPI void slave_set_reactivation(struct slave_node *slave, int flag) { - slave->reactivate_slave = flag; + slave->reactivate_slave = flag; } HAPI int slave_need_to_reactivate(struct slave_node *slave) { - return slave->reactivate_slave; + return slave->reactivate_slave; } HAPI int slave_network(const struct slave_node *slave) { - return slave->network; + return slave->network; } HAPI void slave_set_network(struct slave_node *slave, int network) { - slave->network = network; + slave->network = network; } HAPI int slave_deactivate_all(int reactivate, int reactivate_instances, int no_timer) { - Eina_List *l; - Eina_List *n; - struct slave_node *slave; - int cnt = 0; - - s_info.deactivate_all_refcnt++; - if (s_info.deactivate_all_refcnt > 1) { - return 0; - } - DbgPrint("Deactivate all\n"); + Eina_List *l; + Eina_List *n; + struct slave_node *slave; + int cnt = 0; - EINA_LIST_FOREACH_SAFE(s_info.slave_list, l, n, slave) { - slave_set_reactivate_instances(slave, reactivate_instances); - slave_set_reactivation(slave, reactivate); + s_info.deactivate_all_refcnt++; + if (s_info.deactivate_all_refcnt > 1) { + return 0; + } + DbgPrint("Deactivate all\n"); - if (!slave_deactivate(slave, no_timer)) { - s_info.slave_list = eina_list_remove(s_info.slave_list, slave); - } + EINA_LIST_FOREACH_SAFE(s_info.slave_list, l, n, slave) { + slave_set_reactivate_instances(slave, reactivate_instances); + slave_set_reactivation(slave, reactivate); - cnt++; + if (!slave_deactivate(slave, no_timer)) { + s_info.slave_list = eina_list_remove(s_info.slave_list, slave); } - return cnt; + cnt++; + } + + return cnt; } HAPI int slave_activate_all(void) { - Eina_List *l; - struct slave_node *slave; - int cnt = 0; + Eina_List *l; + struct slave_node *slave; + int cnt = 0; - s_info.deactivate_all_refcnt--; - if (s_info.deactivate_all_refcnt > 0) { - return 0; - } - DbgPrint("Activate all\n"); + s_info.deactivate_all_refcnt--; + if (s_info.deactivate_all_refcnt > 0) { + return 0; + } + DbgPrint("Activate all\n"); - EINA_LIST_FOREACH(s_info.slave_list, l, slave) { - slave_activate(slave); - cnt++; - } + EINA_LIST_FOREACH(s_info.slave_list, l, slave) { + slave_activate(slave); + cnt++; + } - return cnt; + return cnt; } HAPI void slave_set_control_option(struct slave_node *slave, int ctrl) { - slave->ctrl_option = ctrl; + slave->ctrl_option = ctrl; } HAPI int slave_control_option(struct slave_node *slave) { - return slave->ctrl_option; + return slave->ctrl_option; +} + +HAPI int slave_set_priority(struct slave_node *slave, int priority) +{ + pid_t pid; + + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + pid = slave_pid(slave); + if (pid < 0) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (setpriority(PRIO_PROCESS, slave_pid(slave), priority) < 0) { + ErrPrint("setpriority: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } + + return DBOX_STATUS_ERROR_NONE; +} + +HAPI int slave_priority(struct slave_node *slave) +{ + pid_t pid; + int priority; + + if (!slave) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + pid = slave_pid(slave); + if (pid < 0) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + priority = getpriority(PRIO_PROCESS, pid); + if (priority < 0) { + ErrPrint("getpriority: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } + + return priority; } /* End of a file */ diff --git a/src/slave_rpc.c b/src/slave_rpc.c index 555b595..143daae 100644 --- a/src/slave_rpc.c +++ b/src/slave_rpc.c @@ -43,32 +43,32 @@ #include "conf.h" struct slave_rpc { - Ecore_Timer *pong_timer; - int handle; + Ecore_Timer *pong_timer; + int handle; - unsigned long ping_count; - unsigned long next_ping_count; - Eina_List *pending_list; + unsigned long ping_count; + unsigned long next_ping_count; + Eina_List *pending_list; }; struct command { - /* create_command, destroy_command will care these varaibles */ - char *pkgname; - struct packet *packet; - struct slave_node *slave; - int ttl; /* If it fails to handle this, destroy this */ - - /* Don't need to care these data */ - void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *cbdata); - void *cbdata; + /* create_command, destroy_command will care these varaibles */ + char *pkgname; + struct packet *packet; + struct slave_node *slave; + int ttl; /* If it fails to handle this, destroy this */ + + /* Don't need to care these data */ + void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *cbdata); + void *cbdata; }; static struct info { - Eina_List *command_list; - Ecore_Timer *command_consuming_timer; + Eina_List *command_list; + Ecore_Timer *command_consuming_timer; } s_info = { - .command_list = NULL, - .command_consuming_timer = NULL, + .command_list = NULL, + .command_consuming_timer = NULL, }; #define DEFAULT_CMD_TTL 3 @@ -77,631 +77,631 @@ static void prepend_command(struct command *command); static inline struct command *create_command(struct slave_node *slave, const char *pkgname, struct packet *packet) { - struct command *command; + struct command *command; - command = calloc(1, sizeof(*command)); - if (!command) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + command = calloc(1, sizeof(*command)); + if (!command) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - if (pkgname) { - command->pkgname = strdup(pkgname); - if (!command->pkgname) { - ErrPrint("Heap: %s\n", strerror(errno)); - DbgFree(command); - return NULL; - } + if (pkgname) { + command->pkgname = strdup(pkgname); + if (!command->pkgname) { + ErrPrint("Heap: %s\n", strerror(errno)); + DbgFree(command); + return NULL; } + } - command->slave = slave_ref(slave); /*!< To prevent from destroying of the slave while communicating with the slave */ - command->packet = packet_ref(packet); - command->ttl = DEFAULT_CMD_TTL; + command->slave = slave_ref(slave); /*!< To prevent from destroying of the slave while communicating with the slave */ + command->packet = packet_ref(packet); + command->ttl = DEFAULT_CMD_TTL; - return command; + return command; } static inline void destroy_command(struct command *command) { - slave_unref(command->slave); - packet_unref(command->packet); - DbgFree(command->pkgname); - DbgFree(command); + slave_unref(command->slave); + packet_unref(command->packet); + DbgFree(command->pkgname); + DbgFree(command); } static inline struct command *pop_command(void) { - struct command *command; + struct command *command; - command = eina_list_nth(s_info.command_list, 0); - if (!command) { - return NULL; - } + command = eina_list_nth(s_info.command_list, 0); + if (!command) { + return NULL; + } - s_info.command_list = eina_list_remove(s_info.command_list, command); - return command; + s_info.command_list = eina_list_remove(s_info.command_list, command); + return command; } static int slave_async_cb(pid_t pid, int handle, const struct packet *packet, void *data) { - struct command *command = data; + struct command *command = data; - if (!command) { - ErrPrint("Command is NIL\n"); - return DBOX_STATUS_ERROR_NONE; + if (!command) { + ErrPrint("Command is NIL\n"); + return DBOX_STATUS_ERROR_NONE; + } + + /*! + * \note + * command->packet is not valid from here. + */ + if (!slave_is_activated(command->slave)) { + ErrPrint("Slave is not activated (accidently dead)\n"); + if (command->ret_cb) { + command->ret_cb(command->slave, packet, command->cbdata); } + goto out; + } - /*! - * \note - * command->packet is not valid from here. - */ - if (!slave_is_activated(command->slave)) { - ErrPrint("Slave is not activated (accidently dead)\n"); - if (command->ret_cb) { - command->ret_cb(command->slave, packet, command->cbdata); - } - goto out; + if (!packet) { + DbgPrint("packet == NULL\n"); + if (command->ret_cb) { + command->ret_cb(command->slave, packet, command->cbdata); } - if (!packet) { - DbgPrint("packet == NULL\n"); - if (command->ret_cb) { - command->ret_cb(command->slave, packet, command->cbdata); - } + /* + * \NOTE + * Slave will be deactivated from dead monitor if it lost its connections. + * So we don't need to care it again from here. - /* - * \NOTE - * Slave will be deactivated from dead monitor if it lost its connections. - * So we don't need to care it again from here. + command->slave = slave_deactivated_by_fault(command->slave); - command->slave = slave_deactivated_by_fault(command->slave); - - */ - goto out; - } + */ + goto out; + } - if (command->ret_cb) { - command->ret_cb(command->slave, packet, command->cbdata); - } + if (command->ret_cb) { + command->ret_cb(command->slave, packet, command->cbdata); + } out: - destroy_command(command); - return DBOX_STATUS_ERROR_NONE; + destroy_command(command); + return DBOX_STATUS_ERROR_NONE; } static Eina_Bool command_consumer_cb(void *data) { - struct command *command; - struct slave_rpc *rpc; + struct command *command; + struct slave_rpc *rpc; - command = pop_command(); - if (!command) { - s_info.command_consuming_timer = NULL; - return ECORE_CALLBACK_CANCEL; - } - - if (!slave_is_activated(command->slave)) { - ErrPrint("Slave is not activated: %s(%d)\n", - slave_name(command->slave), slave_pid(command->slave)); - goto errout; - } - - if (command->pkgname) { - struct pkg_info *info; - - info = package_find(command->pkgname); - if (info && package_is_fault(info)) { - ErrPrint("info: %p (%s) is fault package\n", info, command->pkgname); - // goto errout; - } - } + command = pop_command(); + if (!command) { + s_info.command_consuming_timer = NULL; + return ECORE_CALLBACK_CANCEL; + } - rpc = slave_data(command->slave, "rpc"); - if (!rpc || rpc->handle < 0) { - ErrPrint("Slave has no rpc info\n"); - goto errout; - } + if (!slave_is_activated(command->slave)) { + ErrPrint("Slave is not activated: %s(%d)\n", + slave_name(command->slave), slave_pid(command->slave)); + goto errout; + } - if (packet_type(command->packet) == PACKET_REQ_NOACK) { - if (com_core_packet_send_only(rpc->handle, command->packet) == 0) { - /* Keep a slave alive, while processing events */ - slave_give_more_ttl(command->slave); - destroy_command(command); - return ECORE_CALLBACK_RENEW; - } - } else if (packet_type(command->packet) == PACKET_REQ) { - if (com_core_packet_async_send(rpc->handle, command->packet, 0.0f, slave_async_cb, command) == 0) { - /* Keep a slave alive, while processing events */ - slave_give_more_ttl(command->slave); - return ECORE_CALLBACK_RENEW; - } - } + if (command->pkgname) { + struct pkg_info *info; - /*! - * \WARN - * What happens at here? - * We are failed to send a packet!!! - * Let's try to send this again - */ - /*! - * \todo - * Do we need to handle this error? - * Close current connection and make new one? - * how about pended command lists? - */ - DbgPrint("Packet type: %d\n", packet_type(command->packet)); - DbgPrint("Packet: %p\n", command->packet); - DbgPrint("Handle: %d\n", rpc->handle); - DbgPrint("PID: %d\n", slave_pid(command->slave)); - DbgPrint("Name: %s\n", slave_name(command->slave)); - DbgPrint("Package: %s\n", command->pkgname); - command->ttl--; - if (command->ttl == 0) { - DbgPrint("Discard packet (%d)\n", command->ttl); - destroy_command(command); - } else { - DbgPrint("Send again (%d)\n", command->ttl); - prepend_command(command); - } - return ECORE_CALLBACK_RENEW; + info = package_find(command->pkgname); + if (info && package_is_fault(info)) { + ErrPrint("info: %p (%s) is fault package\n", info, command->pkgname); + // goto errout; + } + } + + rpc = slave_data(command->slave, "rpc"); + if (!rpc || rpc->handle < 0) { + ErrPrint("Slave has no rpc info\n"); + goto errout; + } + + if (packet_type(command->packet) == PACKET_REQ_NOACK) { + if (com_core_packet_send_only(rpc->handle, command->packet) == 0) { + /* Keep a slave alive, while processing events */ + slave_give_more_ttl(command->slave); + destroy_command(command); + return ECORE_CALLBACK_RENEW; + } + } else if (packet_type(command->packet) == PACKET_REQ) { + if (com_core_packet_async_send(rpc->handle, command->packet, 0.0f, slave_async_cb, command) == 0) { + /* Keep a slave alive, while processing events */ + slave_give_more_ttl(command->slave); + return ECORE_CALLBACK_RENEW; + } + } + + /*! + * \WARN + * What happens at here? + * We are failed to send a packet!!! + * Let's try to send this again + */ + /*! + * \todo + * Do we need to handle this error? + * Close current connection and make new one? + * how about pended command lists? + */ + DbgPrint("Packet type: %d\n", packet_type(command->packet)); + DbgPrint("Packet: %p\n", command->packet); + DbgPrint("Handle: %d\n", rpc->handle); + DbgPrint("PID: %d\n", slave_pid(command->slave)); + DbgPrint("Name: %s\n", slave_name(command->slave)); + DbgPrint("Package: %s\n", command->pkgname); + command->ttl--; + if (command->ttl == 0) { + DbgPrint("Discard packet (%d)\n", command->ttl); + destroy_command(command); + } else { + DbgPrint("Send again (%d)\n", command->ttl); + prepend_command(command); + } + return ECORE_CALLBACK_RENEW; errout: - if (command->ret_cb) { - command->ret_cb(command->slave, NULL, command->cbdata); - } + if (command->ret_cb) { + command->ret_cb(command->slave, NULL, command->cbdata); + } - destroy_command(command); - return ECORE_CALLBACK_RENEW; + destroy_command(command); + return ECORE_CALLBACK_RENEW; } static void prepend_command(struct command *command) { - s_info.command_list = eina_list_prepend(s_info.command_list, command); + s_info.command_list = eina_list_prepend(s_info.command_list, command); - if (s_info.command_consuming_timer) { - return; - } + if (s_info.command_consuming_timer) { + return; + } - s_info.command_consuming_timer = ecore_timer_add(DYNAMICBOX_CONF_PACKET_TIME, command_consumer_cb, NULL); - if (!s_info.command_consuming_timer) { - ErrPrint("Failed to add command consumer\n"); - s_info.command_list = eina_list_remove(s_info.command_list, command); - destroy_command(command); - } + s_info.command_consuming_timer = ecore_timer_add(DYNAMICBOX_CONF_PACKET_TIME, command_consumer_cb, NULL); + if (!s_info.command_consuming_timer) { + ErrPrint("Failed to add command consumer\n"); + s_info.command_list = eina_list_remove(s_info.command_list, command); + destroy_command(command); + } } static void push_command(struct command *command) { - s_info.command_list = eina_list_append(s_info.command_list, command); + s_info.command_list = eina_list_append(s_info.command_list, command); - if (s_info.command_consuming_timer) { - return; - } + if (s_info.command_consuming_timer) { + return; + } - s_info.command_consuming_timer = ecore_timer_add(DYNAMICBOX_CONF_PACKET_TIME, command_consumer_cb, NULL); - if (!s_info.command_consuming_timer) { - ErrPrint("Failed to add command consumer\n"); - s_info.command_list = eina_list_remove(s_info.command_list, command); - destroy_command(command); - } + s_info.command_consuming_timer = ecore_timer_add(DYNAMICBOX_CONF_PACKET_TIME, command_consumer_cb, NULL); + if (!s_info.command_consuming_timer) { + ErrPrint("Failed to add command consumer\n"); + s_info.command_list = eina_list_remove(s_info.command_list, command); + destroy_command(command); + } } static int slave_deactivate_cb(struct slave_node *slave, void *data) { - struct slave_rpc *rpc; - struct command *command; - Eina_List *l; - Eina_List *n; - - rpc = slave_data(slave, "rpc"); - if (!rpc) { - /*! - * \note - * Return negative value will remove this callback from the event list of the slave - */ - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (rpc->pong_timer) { - ecore_timer_del(rpc->pong_timer); - rpc->pong_timer = NULL; - } else { - ErrPrint("slave has no pong timer\n"); - } - - if (rpc->handle < 0) { - EINA_LIST_FREE(rpc->pending_list, command) { - assert(command->slave == slave); - if (command->ret_cb) { - command->ret_cb(command->slave, NULL, command->cbdata); - } - destroy_command(command); - } - } else { - EINA_LIST_FOREACH_SAFE(s_info.command_list, l, n, command) { - if (command->slave == slave) { - s_info.command_list = eina_list_remove(s_info.command_list, command); - if (command->ret_cb) { - command->ret_cb(command->slave, NULL, command->cbdata); - } - destroy_command(command); - } - } - } + struct slave_rpc *rpc; + struct command *command; + Eina_List *l; + Eina_List *n; + rpc = slave_data(slave, "rpc"); + if (!rpc) { /*! * \note - * Reset handle + * Return negative value will remove this callback from the event list of the slave */ - DbgPrint("Reset handle for %d (%d)\n", slave_pid(slave), rpc->handle); - rpc->handle = -1; + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - /*! - * \todo - * Make statistics table - */ - rpc->ping_count = 0; - rpc->next_ping_count = 1; - return DBOX_STATUS_ERROR_NONE; + if (rpc->pong_timer) { + ecore_timer_del(rpc->pong_timer); + rpc->pong_timer = NULL; + } else { + ErrPrint("slave has no pong timer\n"); + } + + if (rpc->handle < 0) { + EINA_LIST_FREE(rpc->pending_list, command) { + assert(command->slave == slave); + if (command->ret_cb) { + command->ret_cb(command->slave, NULL, command->cbdata); + } + destroy_command(command); + } + } else { + EINA_LIST_FOREACH_SAFE(s_info.command_list, l, n, command) { + if (command->slave == slave) { + s_info.command_list = eina_list_remove(s_info.command_list, command); + if (command->ret_cb) { + command->ret_cb(command->slave, NULL, command->cbdata); + } + destroy_command(command); + } + } + } + + /*! + * \note + * Reset handle + */ + DbgPrint("Reset handle for %d (%d)\n", slave_pid(slave), rpc->handle); + rpc->handle = -1; + + /*! + * \todo + * Make statistics table + */ + rpc->ping_count = 0; + rpc->next_ping_count = 1; + return DBOX_STATUS_ERROR_NONE; } static Eina_Bool ping_timeout_cb(void *data) { - struct slave_rpc *rpc; - struct slave_node *slave = data; - - rpc = slave_data(slave, "rpc"); - if (!rpc) { - ErrPrint("Slave RPC is not valid (%s)\n", slave_name(slave)); - return ECORE_CALLBACK_CANCEL; - } - - /*! - * \note - * Clear the pong_timer - */ - rpc->pong_timer = NULL; + struct slave_rpc *rpc; + struct slave_node *slave = data; - if (!slave_is_activated(slave)) { - ErrPrint("Slave is not activated (%s)\n", slave_name(slave)); - return ECORE_CALLBACK_CANCEL; - } + rpc = slave_data(slave, "rpc"); + if (!rpc) { + ErrPrint("Slave RPC is not valid (%s)\n", slave_name(slave)); + return ECORE_CALLBACK_CANCEL; + } - /*! - * Dead callback will handling this - */ - DbgPrint("Slave PING TIMEOUT: %s(%d) : %p\n", slave_name(slave), slave_pid(slave), slave); - slave = slave_deactivated_by_fault(slave); - if (!slave) { - DbgPrint("Slave is deleted\n"); - } + /*! + * \note + * Clear the pong_timer + */ + rpc->pong_timer = NULL; + if (!slave_is_activated(slave)) { + ErrPrint("Slave is not activated (%s)\n", slave_name(slave)); return ECORE_CALLBACK_CANCEL; + } + + /*! + * Dead callback will handling this + */ + DbgPrint("Slave PING TIMEOUT: %s(%d) : %p\n", slave_name(slave), slave_pid(slave), slave); + slave = slave_deactivated_by_fault(slave); + if (!slave) { + DbgPrint("Slave is deleted\n"); + } + + return ECORE_CALLBACK_CANCEL; } HAPI int slave_rpc_async_request(struct slave_node *slave, const char *pkgname, struct packet *packet, void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *data), void *data, int urgent) { - struct command *command; - struct slave_rpc *rpc; + struct command *command; + struct slave_rpc *rpc; - command = create_command(slave, pkgname, packet); - if (!command) { - ErrPrint("Failed to create command\n"); + command = create_command(slave, pkgname, packet); + if (!command) { + ErrPrint("Failed to create command\n"); - if (ret_cb) { - ret_cb(slave, NULL, data); - } - - packet_unref(packet); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + if (ret_cb) { + ret_cb(slave, NULL, data); } - command->ret_cb = ret_cb; - command->cbdata = data; packet_unref(packet); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - rpc = slave_data(slave, "rpc"); - if (!rpc) { - ErrPrint("Slave has no RPC\n"); - if (ret_cb) { - ret_cb(slave, NULL, data); - } - destroy_command(command); - return DBOX_STATUS_ERROR_FAULT; - } + command->ret_cb = ret_cb; + command->cbdata = data; + packet_unref(packet); - if (rpc->handle < 0) { - DbgPrint("RPC handle is not ready to use it\n"); - if (((slave_control_option(slave) & PROVIDER_CTRL_MANUAL_REACTIVATION) == PROVIDER_CTRL_MANUAL_REACTIVATION || slave_is_secured(slave)) - && !slave_is_activated(slave)) - { - int ret; - DbgPrint("Activate slave forcely\n"); - ret = slave_activate(slave); - if (ret < 0 && ret != DBOX_STATUS_ERROR_ALREADY) { - - if (ret_cb) { - ret_cb(slave, NULL, data); - } - - destroy_command(command); - return ret; - } - } + rpc = slave_data(slave, "rpc"); + if (!rpc) { + ErrPrint("Slave has no RPC\n"); + if (ret_cb) { + ret_cb(slave, NULL, data); + } + destroy_command(command); + return DBOX_STATUS_ERROR_FAULT; + } + + if (rpc->handle < 0) { + DbgPrint("RPC handle is not ready to use it\n"); + if (((slave_control_option(slave) & PROVIDER_CTRL_MANUAL_REACTIVATION) == PROVIDER_CTRL_MANUAL_REACTIVATION || slave_is_secured(slave)) + && !slave_is_activated(slave)) + { + int ret; + DbgPrint("Activate slave forcely\n"); + ret = slave_activate(slave); + if (ret < 0 && ret != DBOX_STATUS_ERROR_ALREADY) { - if (urgent) { - rpc->pending_list = eina_list_prepend(rpc->pending_list, command); - } else { - rpc->pending_list = eina_list_append(rpc->pending_list, command); + if (ret_cb) { + ret_cb(slave, NULL, data); } - return DBOX_STATUS_ERROR_NONE; + destroy_command(command); + return ret; + } } if (urgent) { - prepend_command(command); + rpc->pending_list = eina_list_prepend(rpc->pending_list, command); } else { - push_command(command); + rpc->pending_list = eina_list_append(rpc->pending_list, command); } return DBOX_STATUS_ERROR_NONE; + } + + if (urgent) { + prepend_command(command); + } else { + push_command(command); + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_request_only(struct slave_node *slave, const char *pkgname, struct packet *packet, int urgent) { - struct command *command; - struct slave_rpc *rpc; - - command = create_command(slave, pkgname, packet); - if (!command) { - ErrPrint("Failed to create a command\n"); - packet_unref(packet); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + struct command *command; + struct slave_rpc *rpc; - command->ret_cb = NULL; - command->cbdata = NULL; + command = create_command(slave, pkgname, packet); + if (!command) { + ErrPrint("Failed to create a command\n"); packet_unref(packet); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - rpc = slave_data(slave, "rpc"); - if (!rpc) { - ErrPrint("Slave has no RPC\n"); - destroy_command(command); - return DBOX_STATUS_ERROR_FAULT; - } - - if (rpc->handle < 0) { - DbgPrint("RPC handle is not ready to use it\n"); - if (((slave_control_option(slave) & PROVIDER_CTRL_MANUAL_REACTIVATION) == PROVIDER_CTRL_MANUAL_REACTIVATION || slave_is_secured(slave)) - && !slave_is_activated(slave)) - { - int ret; - - DbgPrint("Activate slave forcely\n"); - ret = slave_activate(slave); - if (ret < 0 && ret != DBOX_STATUS_ERROR_ALREADY) { - destroy_command(command); - return ret; - } - } + command->ret_cb = NULL; + command->cbdata = NULL; + packet_unref(packet); - if (urgent) { - rpc->pending_list = eina_list_prepend(rpc->pending_list, command); - } else { - rpc->pending_list = eina_list_append(rpc->pending_list, command); - } - - return DBOX_STATUS_ERROR_NONE; + rpc = slave_data(slave, "rpc"); + if (!rpc) { + ErrPrint("Slave has no RPC\n"); + destroy_command(command); + return DBOX_STATUS_ERROR_FAULT; + } + + if (rpc->handle < 0) { + DbgPrint("RPC handle is not ready to use it\n"); + if (((slave_control_option(slave) & PROVIDER_CTRL_MANUAL_REACTIVATION) == PROVIDER_CTRL_MANUAL_REACTIVATION || slave_is_secured(slave)) + && !slave_is_activated(slave)) + { + int ret; + + DbgPrint("Activate slave forcely\n"); + ret = slave_activate(slave); + if (ret < 0 && ret != DBOX_STATUS_ERROR_ALREADY) { + destroy_command(command); + return ret; + } } if (urgent) { - prepend_command(command); + rpc->pending_list = eina_list_prepend(rpc->pending_list, command); } else { - push_command(command); + rpc->pending_list = eina_list_append(rpc->pending_list, command); } return DBOX_STATUS_ERROR_NONE; + } + + if (urgent) { + prepend_command(command); + } else { + push_command(command); + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_update_handle(struct slave_node *slave, int handle) { - struct slave_rpc *rpc; - struct command *command; - - rpc = slave_data(slave, "rpc"); - if (!rpc) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - DbgPrint("SLAVE: New handle assigned for %d, %d\n", slave_pid(slave), handle); - rpc->handle = handle; - if (rpc->pong_timer) { - ecore_timer_del(rpc->pong_timer); - } - - rpc->pong_timer = ecore_timer_add(DYNAMICBOX_CONF_DEFAULT_PING_TIME, ping_timeout_cb, slave); - if (!rpc->pong_timer) { - ErrPrint("Failed to add ping timer\n"); - } - - /*! - * \note - * slave_activated will call the activated callback. - * activated callback will try to recover the normal instances state. - * so the reset_fault should be called after slave_activated function. - */ - slave_activated(slave); - - EINA_LIST_FREE(rpc->pending_list, command) { - push_command(command); - } - - return DBOX_STATUS_ERROR_NONE; + struct slave_rpc *rpc; + struct command *command; + + rpc = slave_data(slave, "rpc"); + if (!rpc) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + DbgPrint("SLAVE: New handle assigned for %d, %d\n", slave_pid(slave), handle); + rpc->handle = handle; + if (rpc->pong_timer) { + ecore_timer_del(rpc->pong_timer); + } + + rpc->pong_timer = ecore_timer_add(DYNAMICBOX_CONF_DEFAULT_PING_TIME, ping_timeout_cb, slave); + if (!rpc->pong_timer) { + ErrPrint("Failed to add ping timer\n"); + } + + /*! + * \note + * slave_activated will call the activated callback. + * activated callback will try to recover the normal instances state. + * so the reset_fault should be called after slave_activated function. + */ + slave_activated(slave); + + EINA_LIST_FREE(rpc->pending_list, command) { + push_command(command); + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_init(struct slave_node *slave) { - struct slave_rpc *rpc; + struct slave_rpc *rpc; - rpc = calloc(1, sizeof(*rpc)); - if (!rpc) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + rpc = calloc(1, sizeof(*rpc)); + if (!rpc) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - if (slave_set_data(slave, "rpc", rpc) < 0) { - DbgFree(rpc); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + if (slave_set_data(slave, "rpc", rpc) < 0) { + DbgFree(rpc); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_deactivate_cb, NULL) < 0) { - ErrPrint("Failed to add event callback\n"); - } + if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_deactivate_cb, NULL) < 0) { + ErrPrint("Failed to add event callback\n"); + } - rpc->ping_count = 0; - rpc->next_ping_count = 1; - rpc->handle = -1; + rpc->ping_count = 0; + rpc->next_ping_count = 1; + rpc->handle = -1; - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_fini(struct slave_node *slave) { - struct slave_rpc *rpc; + struct slave_rpc *rpc; - rpc = slave_del_data(slave, "rpc"); - if (!rpc) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + rpc = slave_del_data(slave, "rpc"); + if (!rpc) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_deactivate_cb, NULL); + slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_deactivate_cb, NULL); - if (rpc->pong_timer) { - ecore_timer_del(rpc->pong_timer); - } + if (rpc->pong_timer) { + ecore_timer_del(rpc->pong_timer); + } - DbgFree(rpc); - return DBOX_STATUS_ERROR_NONE; + DbgFree(rpc); + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_ping(struct slave_node *slave) { - struct slave_rpc *rpc; - - rpc = slave_data(slave, "rpc"); - if (!rpc) { - ErrPrint("Slave RPC is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!slave_is_activated(slave)) { - ErrPrint("Slave is not activated\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - rpc->ping_count++; - if (rpc->ping_count != rpc->next_ping_count) { - ErrPrint("Ping count is not correct\n"); - rpc->next_ping_count = rpc->ping_count; - } - rpc->next_ping_count++; - - ecore_timer_reset(rpc->pong_timer); - return DBOX_STATUS_ERROR_NONE; + struct slave_rpc *rpc; + + rpc = slave_data(slave, "rpc"); + if (!rpc) { + ErrPrint("Slave RPC is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!slave_is_activated(slave)) { + ErrPrint("Slave is not activated\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + rpc->ping_count++; + if (rpc->ping_count != rpc->next_ping_count) { + ErrPrint("Ping count is not correct\n"); + rpc->next_ping_count = rpc->ping_count; + } + rpc->next_ping_count++; + + ecore_timer_reset(rpc->pong_timer); + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_ping_freeze(struct slave_node *slave) { - struct slave_rpc *rpc; + struct slave_rpc *rpc; - rpc = slave_data(slave, "rpc"); - if (!rpc) { - ErrPrint("Slave RPC is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + rpc = slave_data(slave, "rpc"); + if (!rpc) { + ErrPrint("Slave RPC is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!slave_is_activated(slave)) { - ErrPrint("Slave is not activated\n"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!slave_is_activated(slave)) { + ErrPrint("Slave is not activated\n"); + return DBOX_STATUS_ERROR_FAULT; + } - ecore_timer_freeze(rpc->pong_timer); - return DBOX_STATUS_ERROR_NONE; + ecore_timer_freeze(rpc->pong_timer); + return DBOX_STATUS_ERROR_NONE; } HAPI int slave_rpc_ping_thaw(struct slave_node *slave) { - struct slave_rpc *rpc; + struct slave_rpc *rpc; - rpc = slave_data(slave, "rpc"); - if (!rpc) { - ErrPrint("Slave RPC is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + rpc = slave_data(slave, "rpc"); + if (!rpc) { + ErrPrint("Slave RPC is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!slave_is_activated(slave)) { - ErrPrint("Slave is not activated\n"); - return DBOX_STATUS_ERROR_FAULT; - } + if (!slave_is_activated(slave)) { + ErrPrint("Slave is not activated\n"); + return DBOX_STATUS_ERROR_FAULT; + } - ecore_timer_thaw(rpc->pong_timer); - return DBOX_STATUS_ERROR_NONE; + ecore_timer_thaw(rpc->pong_timer); + return DBOX_STATUS_ERROR_NONE; } HAPI void slave_rpc_request_update(const char *pkgname, const char *id, const char *cluster, const char *category, const char *content, int force) { - struct slave_node *slave; - struct pkg_info *info; - struct packet *packet; - unsigned int cmd = CMD_UPDATE_CONTENT; - - info = package_find(pkgname); - if (!info) { - ErrPrint("Failed to find a package\n"); - return; - } - - slave = package_slave(info); - if (!slave) { - ErrPrint("Failed to find a slave for %s\n", pkgname); - return; - } - - packet = packet_create_noack((const char *)&cmd, "sssssi", pkgname, id, cluster, category, content, force); - if (!packet) { - ErrPrint("Failed to create a new param\n"); - return; - } - - (void)slave_rpc_request_only(slave, pkgname, packet, 0); + struct slave_node *slave; + struct pkg_info *info; + struct packet *packet; + unsigned int cmd = CMD_UPDATE_CONTENT; + + info = package_find(pkgname); + if (!info) { + ErrPrint("Failed to find a package\n"); + return; + } + + slave = package_slave(info); + if (!slave) { + ErrPrint("Failed to find a slave for %s\n", pkgname); + return; + } + + packet = packet_create_noack((const char *)&cmd, "sssssi", pkgname, id, cluster, category, content, force); + if (!packet) { + ErrPrint("Failed to create a new param\n"); + return; + } + + (void)slave_rpc_request_only(slave, pkgname, packet, 0); } HAPI int slave_rpc_handle(struct slave_node *slave) { - struct slave_rpc *rpc; + struct slave_rpc *rpc; - rpc = slave_data(slave, "rpc"); - if (!rpc) { - DbgPrint("Slave RPC is not initiated\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + rpc = slave_data(slave, "rpc"); + if (!rpc) { + DbgPrint("Slave RPC is not initiated\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return rpc->handle; + return rpc->handle; } HAPI int slave_rpc_disconnect(struct slave_node *slave) { - struct packet *packet; - unsigned int cmd = CMD_DISCONNECT; + struct packet *packet; + unsigned int cmd = CMD_DISCONNECT; - packet = packet_create_noack((const char *)&cmd, "d", util_timestamp()); - if (!packet) { - ErrPrint("Failed to create a packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "d", util_timestamp()); + if (!packet) { + ErrPrint("Failed to create a packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("Send disconnection request packet\n"); - return slave_rpc_request_only(slave, NULL, packet, 0); + DbgPrint("Send disconnection request packet\n"); + return slave_rpc_request_only(slave, NULL, packet, 0); } /* End of a file */ diff --git a/src/util.c b/src/util.c index f9c356e..ecac445 100644 --- a/src/util.c +++ b/src/util.c @@ -46,109 +46,109 @@ #include "conf.h" static struct info { - int emergency_mounted; + int emergency_mounted; } s_info = { - .emergency_mounted = 0, + .emergency_mounted = 0, }; int errno; HAPI unsigned long util_string_hash(const char *str) { - unsigned long ret = 0; + unsigned long ret = 0; - while (*str) { - ret += (unsigned long)(*str++); - } + while (*str) { + ret += (unsigned long)(*str++); + } - ret %= 371773; - return ret; + ret %= 371773; + return ret; } HAPI double util_timestamp(void) { #if defined(_USE_ECORE_TIME_GET) - return ecore_time_get(); + return ecore_time_get(); #else - struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) { - static unsigned long internal_count = 0; - ErrPrint("failed to get time of day: %s\n", strerror(errno)); - tv.tv_sec = internal_count++; - tv.tv_usec = 0; - } - - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; + struct timeval tv; + if (gettimeofday(&tv, NULL) < 0) { + static unsigned long internal_count = 0; + ErrPrint("failed to get time of day: %s\n", strerror(errno)); + tv.tv_sec = internal_count++; + tv.tv_usec = 0; + } + + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; #endif } HAPI int util_check_ext(const char *filename, const char *check_ptr) { - int name_len; - - name_len = strlen(filename); - while (--name_len >= 0 && *check_ptr) { - if (filename[name_len] != *check_ptr) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + int name_len; - check_ptr ++; + name_len = strlen(filename); + while (--name_len >= 0 && *check_ptr) { + if (filename[name_len] != *check_ptr) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } - return DBOX_STATUS_ERROR_NONE; + check_ptr ++; + } + + return DBOX_STATUS_ERROR_NONE; } HAPI int util_unlink(const char *filename) { - char *descfile; - int desclen; - int ret; - - if (!filename) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - desclen = strlen(filename) + 6; /* .desc */ - descfile = malloc(desclen); - if (!descfile) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - ret = snprintf(descfile, desclen, "%s.desc", filename); - if (ret < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - DbgFree(descfile); - return DBOX_STATUS_ERROR_FAULT; - } - - (void)unlink(descfile); + char *descfile; + int desclen; + int ret; + + if (!filename) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + desclen = strlen(filename) + 6; /* .desc */ + descfile = malloc(desclen); + if (!descfile) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + ret = snprintf(descfile, desclen, "%s.desc", filename); + if (ret < 0) { + ErrPrint("Error: %s\n", strerror(errno)); DbgFree(descfile); - (void)unlink(filename); + return DBOX_STATUS_ERROR_FAULT; + } + + (void)unlink(descfile); + DbgFree(descfile); + (void)unlink(filename); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI char *util_slavename(void) { - char slavename[BUFSIZ]; - static unsigned long idx = 0; + char slavename[BUFSIZ]; + static unsigned long idx = 0; - snprintf(slavename, sizeof(slavename), "%lu_%lf", idx++, util_timestamp()); - return strdup(slavename); + snprintf(slavename, sizeof(slavename), "%lu_%lf", idx++, util_timestamp()); + return strdup(slavename); } HAPI const char *util_basename(const char *name) { - int length; - length = name ? strlen(name) : 0; - if (!length) { - return "."; - } + int length; + length = name ? strlen(name) : 0; + if (!length) { + return "."; + } - while (--length > 0 && name[length] != '/'); + while (--length > 0 && name[length] != '/'); - return length <= 0 ? name : (name + length + (name[length] == '/')); + return length <= 0 ? name : (name + length + (name[length] == '/')); } /*! @@ -156,512 +156,512 @@ HAPI const char *util_basename(const char *name) */ HAPI unsigned long long util_free_space(const char *path) { - struct statvfs st; - unsigned long long space; - - if (statvfs(path, &st) < 0) { - ErrPrint("statvfs: %s\n", strerror(errno)); - return 0lu; - } - - space = (unsigned long long)st.f_bsize * (unsigned long long)st.f_bavail; - DbgPrint("Available size: %llu, f_bsize: %lu, f_bavail: %lu\n", space, st.f_bsize, st.f_bavail); - /*! - * \note - * Must have to check the overflow - */ - - return space; + struct statvfs st; + unsigned long long space; + + if (statvfs(path, &st) < 0) { + ErrPrint("statvfs: %s\n", strerror(errno)); + return 0lu; + } + + space = (unsigned long long)st.f_bsize * (unsigned long long)st.f_bavail; + DbgPrint("Available size: %llu, f_bsize: %lu, f_bavail: %lu\n", space, st.f_bsize, st.f_bavail); + /*! + * \note + * Must have to check the overflow + */ + + return space; } static inline char *extend_heap(char *buffer, int *sz, int incsz) { - char *tmp; + char *tmp; - *sz += incsz; - tmp = realloc(buffer, *sz); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + *sz += incsz; + tmp = realloc(buffer, *sz); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - return tmp; + return tmp; } HAPI char *util_replace_string(const char *src, const char *pattern, const char *replace) { - const char *ptr; - char *tmp; - char *ret = NULL; - int idx = 0; - int out_idx; - int out_sz; - enum { - STATE_START, - STATE_FIND, - STATE_CHECK, - STATE_END - } state; - - if (!src || !pattern) { - return NULL; - } - - out_sz = strlen(src); - ret = strdup(src); - if (!ret) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - out_idx = 0; - for (state = STATE_START, ptr = src; state != STATE_END; ptr++) { - switch (state) { - case STATE_START: - if (*ptr == '\0') { - state = STATE_END; - } else if (!isblank(*ptr)) { - state = STATE_FIND; - ptr--; + const char *ptr; + char *tmp; + char *ret = NULL; + int idx = 0; + int out_idx; + int out_sz; + enum { + STATE_START, + STATE_FIND, + STATE_CHECK, + STATE_END + } state; + + if (!src || !pattern) { + return NULL; + } + + out_sz = strlen(src); + ret = strdup(src); + if (!ret) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + out_idx = 0; + for (state = STATE_START, ptr = src; state != STATE_END; ptr++) { + switch (state) { + case STATE_START: + if (*ptr == '\0') { + state = STATE_END; + } else if (!isblank(*ptr)) { + state = STATE_FIND; + ptr--; + } + break; + case STATE_FIND: + if (*ptr == '\0') { + state = STATE_END; + } else if (*ptr == *pattern) { + state = STATE_CHECK; + ptr--; + idx = 0; + } else { + ret[out_idx] = *ptr; + out_idx++; + if (out_idx == out_sz) { + tmp = extend_heap(ret, &out_sz, strlen(replace) + 1); + if (!tmp) { + DbgFree(ret); + return NULL; } - break; - case STATE_FIND: - if (*ptr == '\0') { - state = STATE_END; - } else if (*ptr == *pattern) { - state = STATE_CHECK; - ptr--; - idx = 0; - } else { - ret[out_idx] = *ptr; - out_idx++; - if (out_idx == out_sz) { - tmp = extend_heap(ret, &out_sz, strlen(replace) + 1); - if (!tmp) { - DbgFree(ret); - return NULL; - } - ret = tmp; - } + ret = tmp; + } + } + break; + case STATE_CHECK: + if (!pattern[idx]) { + /*! + * If there is no space for copying the replacement, + * Extend size of the return buffer. + */ + if (out_sz - out_idx < strlen(replace) + 1) { + tmp = extend_heap(ret, &out_sz, strlen(replace) + 1); + if (!tmp) { + DbgFree(ret); + return NULL; } - break; - case STATE_CHECK: - if (!pattern[idx]) { - /*! - * If there is no space for copying the replacement, - * Extend size of the return buffer. - */ - if (out_sz - out_idx < strlen(replace) + 1) { - tmp = extend_heap(ret, &out_sz, strlen(replace) + 1); - if (!tmp) { - DbgFree(ret); - return NULL; - } - ret = tmp; - } - - strcpy(ret + out_idx, replace); - out_idx += strlen(replace); - - state = STATE_FIND; - ptr--; - } else if (*ptr != pattern[idx]) { - ptr -= idx; - - /* Copy the first matched character */ - ret[out_idx] = *ptr; - out_idx++; - if (out_idx == out_sz) { - tmp = extend_heap(ret, &out_sz, strlen(replace) + 1); - if (!tmp) { - DbgFree(ret); - return NULL; - } - - ret = tmp; - } - - state = STATE_FIND; - } else { - idx++; + ret = tmp; + } + + strcpy(ret + out_idx, replace); + out_idx += strlen(replace); + + state = STATE_FIND; + ptr--; + } else if (*ptr != pattern[idx]) { + ptr -= idx; + + /* Copy the first matched character */ + ret[out_idx] = *ptr; + out_idx++; + if (out_idx == out_sz) { + tmp = extend_heap(ret, &out_sz, strlen(replace) + 1); + if (!tmp) { + DbgFree(ret); + return NULL; } - break; - default: - break; + + ret = tmp; + } + + state = STATE_FIND; + } else { + idx++; } + break; + default: + break; } + } - return ret; + return ret; } HAPI const char *util_uri_to_path(const char *uri) { - int len; + int len; - len = strlen(SCHEMA_FILE); - if (strncasecmp(uri, SCHEMA_FILE, len)) { - return NULL; - } + len = strlen(SCHEMA_FILE); + if (strncasecmp(uri, SCHEMA_FILE, len)) { + return NULL; + } - return uri + len; + return uri + len; } HAPI double util_time_delay_for_compensation(double period) { - unsigned long long curtime; - unsigned long long _period; - unsigned long long remain; - struct timeval tv; - double ret; - - if (period == 0.0f) { - DbgPrint("Period is ZERO\n"); - return 0.0f; - } - - if (gettimeofday(&tv, NULL) < 0){ - ErrPrint("gettimeofday: %s\n", strerror(errno)); - return period; - } - - curtime = (unsigned long long)tv.tv_sec * 1000000llu + (unsigned long long)tv.tv_usec; - - _period = (unsigned long long)(period * (double)1000000); - if (_period == 0llu) { - ErrPrint("%lf <> %llu\n", period, _period); - return period; - } - - remain = curtime % _period; - - ret = (double)remain / (double)1000000; - return period - ret; + unsigned long long curtime; + unsigned long long _period; + unsigned long long remain; + struct timeval tv; + double ret; + + if (period == 0.0f) { + DbgPrint("Period is ZERO\n"); + return 0.0f; + } + + if (gettimeofday(&tv, NULL) < 0){ + ErrPrint("gettimeofday: %s\n", strerror(errno)); + return period; + } + + curtime = (unsigned long long)tv.tv_sec * 1000000llu + (unsigned long long)tv.tv_usec; + + _period = (unsigned long long)(period * (double)1000000); + if (_period == 0llu) { + ErrPrint("%lf <> %llu\n", period, _period); + return period; + } + + remain = curtime % _period; + + ret = (double)remain / (double)1000000; + return period - ret; } HAPI void *util_timer_add(double interval, Eina_Bool (*cb)(void *data), void *data) { - Ecore_Timer *timer; - double delay; + Ecore_Timer *timer; + double delay; - timer = ecore_timer_add(interval, cb, data); - if (!timer) { - return NULL; - } + timer = ecore_timer_add(interval, cb, data); + if (!timer) { + return NULL; + } - delay = util_time_delay_for_compensation(interval) - interval; - ecore_timer_delay(timer, delay); - DbgPrint("Compensate timer: %lf\n", delay); + delay = util_time_delay_for_compensation(interval) - interval; + ecore_timer_delay(timer, delay); + DbgPrint("Compensate timer: %lf\n", delay); - return timer; + return timer; } HAPI void util_timer_interval_set(void *timer, double interval) { - double delay; - ecore_timer_interval_set(timer, interval); + double delay; + ecore_timer_interval_set(timer, interval); - delay = util_time_delay_for_compensation(interval) - interval; - ecore_timer_delay(timer, delay); + delay = util_time_delay_for_compensation(interval) - interval; + ecore_timer_delay(timer, delay); } HAPI int util_unlink_files(const char *folder) { - struct stat info; - DIR *handle; - struct dirent *entry; - char *abspath; - int len; - - if (lstat(folder, &info) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; - } + struct stat info; + DIR *handle; + struct dirent *entry; + char *abspath; + int len; - if (!S_ISDIR(info.st_mode)) { - ErrPrint("Error: %s is not a folder", folder); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - handle = opendir(folder); - if (!handle) { - ErrPrint("Error: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (lstat(folder, &info) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; + } - while ((entry = readdir(handle))) { - if (!strcmp(entry->d_name, ".")) { - continue; - } + if (!S_ISDIR(info.st_mode)) { + ErrPrint("Error: %s is not a folder", folder); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!strcmp(entry->d_name, "..")) { - continue; - } + handle = opendir(folder); + if (!handle) { + ErrPrint("Error: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_IO_ERROR; + } - len = strlen(folder) + strlen(entry->d_name) + 3; - abspath = calloc(1, len); - if (!abspath) { - ErrPrint("Heap: %s\n", strerror(errno)); - continue; - } - snprintf(abspath, len - 1, "%s/%s", folder, entry->d_name); + while ((entry = readdir(handle))) { + if (!strcmp(entry->d_name, ".")) { + continue; + } - if (unlink(abspath) < 0) { - DbgPrint("unlink: %s\n", strerror(errno)); - } + if (!strcmp(entry->d_name, "..")) { + continue; + } - DbgFree(abspath); + len = strlen(folder) + strlen(entry->d_name) + 3; + abspath = calloc(1, len); + if (!abspath) { + ErrPrint("Heap: %s\n", strerror(errno)); + continue; } + snprintf(abspath, len - 1, "%s/%s", folder, entry->d_name); - if (closedir(handle) < 0) { - ErrPrint("closedir: %s\n", strerror(errno)); + if (unlink(abspath) < 0) { + DbgPrint("unlink: %s\n", strerror(errno)); } - return DBOX_STATUS_ERROR_NONE; + + DbgFree(abspath); + } + + if (closedir(handle) < 0) { + ErrPrint("closedir: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_NONE; } HAPI void util_remove_emergency_disk(void) { - int ret; - ret = umount(DYNAMICBOX_CONF_IMAGE_PATH); - if (ret < 0) { - ErrPrint("umount: %s\n", strerror(errno)); - } - - DbgPrint("Try to unmount[%s] %d\n", DYNAMICBOX_CONF_IMAGE_PATH, ret); - s_info.emergency_mounted = 0; + int ret; + ret = umount(DYNAMICBOX_CONF_IMAGE_PATH); + if (ret < 0) { + ErrPrint("umount: %s\n", strerror(errno)); + } + + DbgPrint("Try to unmount[%s] %d\n", DYNAMICBOX_CONF_IMAGE_PATH, ret); + s_info.emergency_mounted = 0; } HAPI void util_prepare_emergency_disk(void) { - char *buf; - char *source = NULL; - char *type = NULL; - char *option = NULL; - char *ptr; - char *rollback_ptr; - int tag_idx; - int idx; - int len; - int ret; - static const char *tag[] = { - "source", - "type", - "option", - NULL, - }; - enum tag_type { - TAG_SOURCE, - TAG_TYPE, - TAG_OPTION, - TAG_ERROR - }; - - buf = strdup(DYNAMICBOX_CONF_EMERGENCY_DISK); - if (!buf) { - ErrPrint("Failed to prepare emergency disk info\n"); - return; - } + char *buf; + char *source = NULL; + char *type = NULL; + char *option = NULL; + char *ptr; + char *rollback_ptr; + int tag_idx; + int idx; + int len; + int ret; + static const char *tag[] = { + "source", + "type", + "option", + NULL, + }; + enum tag_type { + TAG_SOURCE, + TAG_TYPE, + TAG_OPTION, + TAG_ERROR + }; + + buf = strdup(DYNAMICBOX_CONF_EMERGENCY_DISK); + if (!buf) { + ErrPrint("Failed to prepare emergency disk info\n"); + return; + } + + rollback_ptr = ptr = buf; + idx = 0; + tag_idx = 0; + len = strlen(ptr); + + while (tag[tag_idx] != NULL && ptr != (buf + len)) { + if (tag[tag_idx][idx] == '\0') { + if (*ptr == '=' || isblank(*ptr)) { + switch (tag_idx) { + case TAG_SOURCE: + if (source) { + ErrPrint("source[%s] is overrided\n", source); + } - rollback_ptr = ptr = buf; - idx = 0; - tag_idx = 0; - len = strlen(ptr); - - while (tag[tag_idx] != NULL && ptr != (buf + len)) { - if (tag[tag_idx][idx] == '\0') { - if (*ptr == '=' || isblank(*ptr)) { - switch (tag_idx) { - case TAG_SOURCE: - if (source) { - ErrPrint("source[%s] is overrided\n", source); - } - - while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) { - ptr++; - } - - source = ptr; - while (*ptr != '\0' && *ptr != ';') { - ptr++; - } - - if (*source == '\0') { - type = NULL; - } - - *ptr = '\0'; - rollback_ptr = ptr + 1; - idx = 0; - break; - case TAG_TYPE: - if (type) { - ErrPrint("type[%s] is overrided\n", type); - } - - while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) { - ptr++; - } - - type = ptr; - while (*ptr != '\0' && *ptr != ';') { - ptr++; - } - - if (*type == '\0') { - type = NULL; - } - - *ptr = '\0'; - rollback_ptr = ptr + 1; - idx = 0; - break; - case TAG_OPTION: - if (option) { - ErrPrint("option[%s] is overrided\n", option); - } - - while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) { - ptr++; - } - - option = ptr; - while (*ptr != '\0' && *ptr != ';') { - ptr++; - } - - if (*option == '\0') { - option = NULL; - } - - *ptr = '\0'; - rollback_ptr = ptr + 1; - idx = 0; - break; - default: - break; - } - } else { - ptr = rollback_ptr; - tag_idx++; - idx = 0; + while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) { + ptr++; } - } else if (tag[tag_idx][idx] != *ptr) { - ptr = rollback_ptr; - tag_idx++; + + source = ptr; + while (*ptr != '\0' && *ptr != ';') { + ptr++; + } + + if (*source == '\0') { + type = NULL; + } + + *ptr = '\0'; + rollback_ptr = ptr + 1; idx = 0; - } else { - ptr++; - idx++; - } // tag - } + break; + case TAG_TYPE: + if (type) { + ErrPrint("type[%s] is overrided\n", type); + } - DbgPrint("source[%s] type[%s] option[%s]\n", source, type, option); + while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) { + ptr++; + } - ret = mount(source, DYNAMICBOX_CONF_IMAGE_PATH, type, MS_NOSUID | MS_NOEXEC, option); - DbgFree(buf); - if (ret < 0) { - ErrPrint("Failed to mount: %s\n", strerror(errno)); - return; - } + type = ptr; + while (*ptr != '\0' && *ptr != ';') { + ptr++; + } + + if (*type == '\0') { + type = NULL; + } + + *ptr = '\0'; + rollback_ptr = ptr + 1; + idx = 0; + break; + case TAG_OPTION: + if (option) { + ErrPrint("option[%s] is overrided\n", option); + } + + while ((*ptr != '\0' && *ptr != ';') && (*ptr == '=' || isblank(*ptr))) { + ptr++; + } + + option = ptr; + while (*ptr != '\0' && *ptr != ';') { + ptr++; + } + + if (*option == '\0') { + option = NULL; + } + + *ptr = '\0'; + rollback_ptr = ptr + 1; + idx = 0; + break; + default: + break; + } + } else { + ptr = rollback_ptr; + tag_idx++; + idx = 0; + } + } else if (tag[tag_idx][idx] != *ptr) { + ptr = rollback_ptr; + tag_idx++; + idx = 0; + } else { + ptr++; + idx++; + } // tag + } - ErrPrint("Disk space is not enough, use the tmpfs. Currently required minimum space is %lu bytes\n", DYNAMICBOX_CONF_MINIMUM_SPACE); - if (chmod(DYNAMICBOX_CONF_IMAGE_PATH, 0750) < 0) { - ErrPrint("chmod: %s\n", strerror(errno)); + DbgPrint("source[%s] type[%s] option[%s]\n", source, type, option); + + ret = mount(source, DYNAMICBOX_CONF_IMAGE_PATH, type, MS_NOSUID | MS_NOEXEC, option); + DbgFree(buf); + if (ret < 0) { + ErrPrint("Failed to mount: %s\n", strerror(errno)); + return; + } + + ErrPrint("Disk space is not enough, use the tmpfs. Currently required minimum space is %lu bytes\n", DYNAMICBOX_CONF_MINIMUM_SPACE); + if (chmod(DYNAMICBOX_CONF_IMAGE_PATH, 0750) < 0) { + ErrPrint("chmod: %s\n", strerror(errno)); + } + + if (chown(DYNAMICBOX_CONF_IMAGE_PATH, 5000, 5000) < 0) { + ErrPrint("chown: %s\n", strerror(errno)); + } + + ret = smack_setlabel(DYNAMICBOX_CONF_IMAGE_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); + if (ret != 0) { + ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_IMAGE_PATH, ret); + } else { + ret = smack_setlabel(DYNAMICBOX_CONF_IMAGE_PATH, "1", SMACK_LABEL_TRANSMUTE); + DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_IMAGE_PATH, ret); + } + + if (mkdir(DYNAMICBOX_CONF_ALWAYS_PATH, 0755) < 0) { + ErrPrint("mkdir: (%s) %s\n", DYNAMICBOX_CONF_ALWAYS_PATH, strerror(errno)); + } else { + if (chmod(DYNAMICBOX_CONF_ALWAYS_PATH, 0750) < 0) { + ErrPrint("chmod: %s\n", strerror(errno)); } - if (chown(DYNAMICBOX_CONF_IMAGE_PATH, 5000, 5000) < 0) { - ErrPrint("chown: %s\n", strerror(errno)); + if (chown(DYNAMICBOX_CONF_ALWAYS_PATH, 5000, 5000) < 0) { + ErrPrint("chown: %s\n", strerror(errno)); } - ret = smack_setlabel(DYNAMICBOX_CONF_IMAGE_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); + ret = smack_setlabel(DYNAMICBOX_CONF_ALWAYS_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); if (ret != 0) { - ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_IMAGE_PATH, ret); + ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_ALWAYS_PATH, ret); } else { - ret = smack_setlabel(DYNAMICBOX_CONF_IMAGE_PATH, "1", SMACK_LABEL_TRANSMUTE); - DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_IMAGE_PATH, ret); + ret = smack_setlabel(DYNAMICBOX_CONF_ALWAYS_PATH, "1", SMACK_LABEL_TRANSMUTE); + DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_ALWAYS_PATH, ret); } + } - if (mkdir(DYNAMICBOX_CONF_ALWAYS_PATH, 0755) < 0) { - ErrPrint("mkdir: (%s) %s\n", DYNAMICBOX_CONF_ALWAYS_PATH, strerror(errno)); - } else { - if (chmod(DYNAMICBOX_CONF_ALWAYS_PATH, 0750) < 0) { - ErrPrint("chmod: %s\n", strerror(errno)); - } - - if (chown(DYNAMICBOX_CONF_ALWAYS_PATH, 5000, 5000) < 0) { - ErrPrint("chown: %s\n", strerror(errno)); - } + if (mkdir(DYNAMICBOX_CONF_READER_PATH, 0755) < 0) { + ErrPrint("mkdir: (%s) %s\n", DYNAMICBOX_CONF_READER_PATH, strerror(errno)); + } else { + if (chmod(DYNAMICBOX_CONF_READER_PATH, 0750) < 0) { + ErrPrint("chmod: %s\n", strerror(errno)); + } - ret = smack_setlabel(DYNAMICBOX_CONF_ALWAYS_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); - if (ret != 0) { - ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_ALWAYS_PATH, ret); - } else { - ret = smack_setlabel(DYNAMICBOX_CONF_ALWAYS_PATH, "1", SMACK_LABEL_TRANSMUTE); - DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_ALWAYS_PATH, ret); - } + if (chown(DYNAMICBOX_CONF_READER_PATH, 5000, 5000) < 0) { + ErrPrint("chown: %s\n", strerror(errno)); } - if (mkdir(DYNAMICBOX_CONF_READER_PATH, 0755) < 0) { - ErrPrint("mkdir: (%s) %s\n", DYNAMICBOX_CONF_READER_PATH, strerror(errno)); + ret = smack_setlabel(DYNAMICBOX_CONF_READER_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); + if (ret != 0) { + ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_READER_PATH, ret); } else { - if (chmod(DYNAMICBOX_CONF_READER_PATH, 0750) < 0) { - ErrPrint("chmod: %s\n", strerror(errno)); - } - - if (chown(DYNAMICBOX_CONF_READER_PATH, 5000, 5000) < 0) { - ErrPrint("chown: %s\n", strerror(errno)); - } - - ret = smack_setlabel(DYNAMICBOX_CONF_READER_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); - if (ret != 0) { - ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_READER_PATH, ret); - } else { - ret = smack_setlabel(DYNAMICBOX_CONF_READER_PATH, "1", SMACK_LABEL_TRANSMUTE); - DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_READER_PATH, ret); - } + ret = smack_setlabel(DYNAMICBOX_CONF_READER_PATH, "1", SMACK_LABEL_TRANSMUTE); + DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_READER_PATH, ret); } + } - s_info.emergency_mounted = 1; + s_info.emergency_mounted = 1; } HAPI int util_emergency_disk_is_mounted(void) { - return s_info.emergency_mounted; + return s_info.emergency_mounted; } HAPI void util_setup_log_disk(void) { - int ret; + int ret; - if (access(DYNAMICBOX_CONF_LOG_PATH, R_OK | W_OK | X_OK) == 0) { - DbgPrint("[%s] is already accessible\n", DYNAMICBOX_CONF_LOG_PATH); - return; - } + if (access(DYNAMICBOX_CONF_LOG_PATH, R_OK | W_OK | X_OK) == 0) { + DbgPrint("[%s] is already accessible\n", DYNAMICBOX_CONF_LOG_PATH); + return; + } - DbgPrint("Initiate the critical log folder [%s]\n", DYNAMICBOX_CONF_LOG_PATH); - if (mkdir(DYNAMICBOX_CONF_LOG_PATH, 0755) < 0) { - ErrPrint("mkdir: %s\n", strerror(errno)); - } else { - if (chmod(DYNAMICBOX_CONF_LOG_PATH, 0750) < 0) { - ErrPrint("chmod: %s\n", strerror(errno)); - } + DbgPrint("Initiate the critical log folder [%s]\n", DYNAMICBOX_CONF_LOG_PATH); + if (mkdir(DYNAMICBOX_CONF_LOG_PATH, 0755) < 0) { + ErrPrint("mkdir: %s\n", strerror(errno)); + } else { + if (chmod(DYNAMICBOX_CONF_LOG_PATH, 0750) < 0) { + ErrPrint("chmod: %s\n", strerror(errno)); + } - if (chown(DYNAMICBOX_CONF_LOG_PATH, 5000, 5000) < 0) { - ErrPrint("chown: %s\n", strerror(errno)); - } + if (chown(DYNAMICBOX_CONF_LOG_PATH, 5000, 5000) < 0) { + ErrPrint("chown: %s\n", strerror(errno)); + } - ret = smack_setlabel(DYNAMICBOX_CONF_LOG_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); - if (ret != 0) { - ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_LOG_PATH, ret); - } else { - ret = smack_setlabel(DYNAMICBOX_CONF_LOG_PATH, "1", SMACK_LABEL_TRANSMUTE); - DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_LOG_PATH, ret); - } + ret = smack_setlabel(DYNAMICBOX_CONF_LOG_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); + if (ret != 0) { + ErrPrint("Failed to set SMACK for %s (%d)\n", DYNAMICBOX_CONF_LOG_PATH, ret); + } else { + ret = smack_setlabel(DYNAMICBOX_CONF_LOG_PATH, "1", SMACK_LABEL_TRANSMUTE); + DbgPrint("[%s] is successfully created (t: %d)\n", DYNAMICBOX_CONF_LOG_PATH, ret); } + } } HAPI int util_service_is_enabled(const char *tag) { - return !!strcasestr(DYNAMICBOX_CONF_SERVICES, tag); + return !!strcasestr(DYNAMICBOX_CONF_SERVICES, tag); } /* End of a file */ diff --git a/src/util_wayland.c b/src/util_wayland.c index 4e4db7d..053e4c1 100644 --- a/src/util_wayland.c +++ b/src/util_wayland.c @@ -8,19 +8,19 @@ int util_screen_size_get(int *width, int *height) { - *width = 0; - *height = 0; - return DBOX_STATUS_ERROR_NOT_IMPLEMENTED; + *width = 0; + *height = 0; + return DBOX_STATUS_ERROR_NOT_IMPLEMENTED; } int util_screen_init(void) { - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } int util_screen_fini(void) { - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/util_x11.c b/src/util_x11.c index a05fefc..ff1ffaf 100644 --- a/src/util_x11.c +++ b/src/util_x11.c @@ -10,31 +10,31 @@ #include "debug.h" static struct info { - int initialized; + int initialized; } s_info = { - .initialized = 0, + .initialized = 0, }; int util_screen_size_get(int *width, int *height) { - if (!s_info.initialized) { - ErrPrint("Not initialized\n"); - return DBOX_STATUS_ERROR_FAULT; - } - ecore_x_window_size_get(0, width, height); - return DBOX_STATUS_ERROR_NONE; + if (!s_info.initialized) { + ErrPrint("Not initialized\n"); + return DBOX_STATUS_ERROR_FAULT; + } + ecore_x_window_size_get(0, width, height); + return DBOX_STATUS_ERROR_NONE; } int util_screen_init(void) { - s_info.initialized = 1; - return ecore_x_init(NULL); + s_info.initialized = 1; + return ecore_x_init(NULL); } int util_screen_fini(void) { - s_info.initialized = 0; - return ecore_x_shutdown(); + s_info.initialized = 0; + return ecore_x_shutdown(); } /* End of a file */ diff --git a/src/utility_service.c b/src/utility_service.c index 143a186..a20322e 100644 --- a/src/utility_service.c +++ b/src/utility_service.c @@ -45,406 +45,406 @@ #endif static struct info { - Eina_List *pending_list; - Eina_List *context_list; - struct service_context *svc_ctx; + Eina_List *pending_list; + Eina_List *context_list; + struct service_context *svc_ctx; - struct tcb *svc_daemon; - int svc_daemon_is_launched; - int svc_daemon_pid; + struct tcb *svc_daemon; + int svc_daemon_is_launched; + int svc_daemon_pid; - struct service_event_item *launch_timer; - struct service_event_item *delay_launcher; - struct service_event_item *ttl_timer; + struct service_event_item *launch_timer; + struct service_event_item *delay_launcher; + struct service_event_item *ttl_timer; } s_info = { - .pending_list = NULL, - .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ - .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ + .pending_list = NULL, + .context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */ + .svc_ctx = NULL, /*!< \WARN: This is only used for MAIN THREAD */ - .svc_daemon = NULL, - .svc_daemon_is_launched = 0, - .svc_daemon_pid = -1, + .svc_daemon = NULL, + .svc_daemon_is_launched = 0, + .svc_daemon_pid = -1, - .launch_timer = NULL, - .delay_launcher = NULL, - .ttl_timer = NULL, + .launch_timer = NULL, + .delay_launcher = NULL, + .ttl_timer = NULL, }; struct pending_item { - struct tcb *tcb; - struct packet *packet; + struct tcb *tcb; + struct packet *packet; }; struct context { - struct tcb *tcb; - double seq; + struct tcb *tcb; + double seq; }; static int lazy_launcher_cb(struct service_context *svc_ctx, void *data); static int put_reply_tcb(struct tcb *tcb, double seq) { - struct context *ctx; + struct context *ctx; - ctx = malloc(sizeof(*ctx)); - if (!ctx) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + ctx = malloc(sizeof(*ctx)); + if (!ctx) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - ctx->tcb = tcb; - ctx->seq = seq; + ctx->tcb = tcb; + ctx->seq = seq; - s_info.context_list = eina_list_append(s_info.context_list, ctx); + s_info.context_list = eina_list_append(s_info.context_list, ctx); - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static inline struct tcb *get_reply_tcb(double seq) { - Eina_List *l; - Eina_List *n; - struct context *ctx; - struct tcb *tcb; - - EINA_LIST_FOREACH_SAFE(s_info.context_list, l, n, ctx) { - if (ctx->seq != seq) { - continue; - } - - s_info.context_list = eina_list_remove(s_info.context_list, ctx); - tcb = ctx->tcb; - DbgFree(ctx); - return tcb; + Eina_List *l; + Eina_List *n; + struct context *ctx; + struct tcb *tcb; + + EINA_LIST_FOREACH_SAFE(s_info.context_list, l, n, ctx) { + if (ctx->seq != seq) { + continue; } - return NULL; + s_info.context_list = eina_list_remove(s_info.context_list, ctx); + tcb = ctx->tcb; + DbgFree(ctx); + return tcb; + } + + return NULL; } static inline int flush_pended_request(void) { - /*! - * Flush all pended requests - */ - struct pending_item *item; - int ret; - - EINA_LIST_FREE(s_info.pending_list, item) { - if (tcb_is_valid(s_info.svc_ctx, s_info.svc_daemon) >= 0) { - ret = service_common_unicast_packet(s_info.svc_daemon, item->packet); - } else { - ret = -EFAULT; - } + /*! + * Flush all pended requests + */ + struct pending_item *item; + int ret; + + EINA_LIST_FREE(s_info.pending_list, item) { + if (tcb_is_valid(s_info.svc_ctx, s_info.svc_daemon) >= 0) { + ret = service_common_unicast_packet(s_info.svc_daemon, item->packet); + } else { + ret = -EFAULT; + } - if (ret < 0) { - if (tcb_is_valid(s_info.svc_ctx, item->tcb) >= 0) { - struct packet *reply; - reply = packet_create_reply(item->packet, "i", ret); - if (service_common_unicast_packet(item->tcb, reply) < 0) { - ErrPrint("Unable to send packet\n"); - } - packet_destroy(reply); - } - } else { - put_reply_tcb(item->tcb, packet_seq(item->packet)); + if (ret < 0) { + if (tcb_is_valid(s_info.svc_ctx, item->tcb) >= 0) { + struct packet *reply; + reply = packet_create_reply(item->packet, "i", ret); + if (service_common_unicast_packet(item->tcb, reply) < 0) { + ErrPrint("Unable to send packet\n"); } - packet_unref(item->packet); - DbgFree(item); + packet_destroy(reply); + } + } else { + put_reply_tcb(item->tcb, packet_seq(item->packet)); } + packet_unref(item->packet); + DbgFree(item); + } - return 0; + return 0; } static inline int put_pended_request(struct tcb *tcb, struct packet *packet) { - struct pending_item *item; - - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - item->tcb = tcb; - item->packet = packet_ref(packet); - if (!item->packet) { - DbgFree(item); - ErrPrint("Unable to ref packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - s_info.pending_list = eina_list_append(s_info.pending_list, item); - return 0; + struct pending_item *item; + + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + item->tcb = tcb; + item->packet = packet_ref(packet); + if (!item->packet) { + DbgFree(item); + ErrPrint("Unable to ref packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + s_info.pending_list = eina_list_append(s_info.pending_list, item); + return 0; } static int launch_timeout_cb(struct service_context *svc_ctx, void *data) { - struct pending_item *item; - struct packet *reply; - - EINA_LIST_FREE(s_info.pending_list, item) { - if (tcb_is_valid(s_info.svc_ctx, item->tcb) >= 0) { - reply = packet_create_reply(item->packet, "i", -EFAULT); - if (!reply) { - ErrPrint("Unable to create a packet\n"); - } else { - int ret; - - ret = service_common_unicast_packet(item->tcb, reply); - if (ret < 0) { - ErrPrint("Failed to send reply packet: %d\n", ret); - } - - packet_destroy(reply); - } - } else { - ErrPrint("TCB is already terminated\n"); + struct pending_item *item; + struct packet *reply; + + EINA_LIST_FREE(s_info.pending_list, item) { + if (tcb_is_valid(s_info.svc_ctx, item->tcb) >= 0) { + reply = packet_create_reply(item->packet, "i", -EFAULT); + if (!reply) { + ErrPrint("Unable to create a packet\n"); + } else { + int ret; + + ret = service_common_unicast_packet(item->tcb, reply); + if (ret < 0) { + ErrPrint("Failed to send reply packet: %d\n", ret); } - packet_unref(item->packet); - DbgFree(item); + packet_destroy(reply); + } + } else { + ErrPrint("TCB is already terminated\n"); } - s_info.launch_timer = NULL; - s_info.svc_daemon_is_launched = 0; - s_info.svc_daemon_pid = -1; - return -ECANCELED; /* Delete this timer */ + packet_unref(item->packet); + DbgFree(item); + } + + s_info.launch_timer = NULL; + s_info.svc_daemon_is_launched = 0; + s_info.svc_daemon_pid = -1; + return -ECANCELED; /* Delete this timer */ } static int launch_svc(struct service_context *svc_ctx) { - pid_t pid; - int ret = DBOX_STATUS_ERROR_NONE; + pid_t pid; + int ret = DBOX_STATUS_ERROR_NONE; - pid = aul_launch_app(SVC_PKG, NULL); - switch (pid) { + pid = aul_launch_app(SVC_PKG, NULL); + switch (pid) { case AUL_R_EHIDDENFORGUEST: /**< App hidden for guest mode */ case AUL_R_ENOLAUNCHPAD: /**< no launchpad */ case AUL_R_EILLACC: /**< Illegal Access */ case AUL_R_EINVAL: /**< Invalid argument */ case AUL_R_ENOINIT: /**< AUL handler NOT initialized */ case AUL_R_ERROR: /**< General error */ - ErrPrint("Failed to launch an app: %s(%d)\n", SVC_PKG, pid); - ret = DBOX_STATUS_ERROR_FAULT; - break; + ErrPrint("Failed to launch an app: %s(%d)\n", SVC_PKG, pid); + ret = DBOX_STATUS_ERROR_FAULT; + break; case AUL_R_ETIMEOUT: /**< Timeout */ case AUL_R_ECOMM: /**< Comunication Error */ case AUL_R_ETERMINATING: /**< application terminating */ case AUL_R_ECANCELED: /**< Operation canceled */ - /* Need time to launch app again */ - ErrPrint("Terminating now, try to launch this after few sec later: %s(%d)\n", SVC_PKG, pid); - s_info.svc_daemon_is_launched = 1; - s_info.delay_launcher = service_common_add_timer(svc_ctx, LAUNCH_TIMEOUT, lazy_launcher_cb, NULL); - if (!s_info.delay_launcher) { - ErrPrint("Unable to add delay launcher\n"); - ret = DBOX_STATUS_ERROR_FAULT; - } - break; + /* Need time to launch app again */ + ErrPrint("Terminating now, try to launch this after few sec later: %s(%d)\n", SVC_PKG, pid); + s_info.svc_daemon_is_launched = 1; + s_info.delay_launcher = service_common_add_timer(svc_ctx, LAUNCH_TIMEOUT, lazy_launcher_cb, NULL); + if (!s_info.delay_launcher) { + ErrPrint("Unable to add delay launcher\n"); + ret = DBOX_STATUS_ERROR_FAULT; + } + break; case AUL_R_LOCAL: /**< Launch by himself */ case AUL_R_OK: /**< General success */ default: - DbgPrint("Launched: %s(%d)\n", SVC_PKG, pid); - s_info.svc_daemon_is_launched = 1; - s_info.svc_daemon_pid = pid; - s_info.launch_timer = service_common_add_timer(svc_ctx, LAUNCH_TIMEOUT, launch_timeout_cb, NULL); - if (!s_info.launch_timer) { - ErrPrint("Unable to create launch timer\n"); - } - } - - return ret; + DbgPrint("Launched: %s(%d)\n", SVC_PKG, pid); + s_info.svc_daemon_is_launched = 1; + s_info.svc_daemon_pid = pid; + s_info.launch_timer = service_common_add_timer(svc_ctx, LAUNCH_TIMEOUT, launch_timeout_cb, NULL); + if (!s_info.launch_timer) { + ErrPrint("Unable to create launch timer\n"); + } + } + + return ret; } static int lazy_launcher_cb(struct service_context *svc_ctx, void *data) { - s_info.delay_launcher = NULL; + s_info.delay_launcher = NULL; - (void)launch_svc(svc_ctx); - return -ECANCELED; + (void)launch_svc(svc_ctx); + return -ECANCELED; } static int ttl_timer_cb(struct service_context *svc_ctx, void *data) { - DbgPrint("TTL Timer is expired: PID(%d)\n", s_info.svc_daemon_pid); - (void)aul_terminate_pid(s_info.svc_daemon_pid); - - s_info.ttl_timer = NULL; - s_info.svc_daemon_is_launched = 0; - s_info.svc_daemon_pid = -1; - s_info.svc_daemon = NULL; - return -ECANCELED; + DbgPrint("TTL Timer is expired: PID(%d)\n", s_info.svc_daemon_pid); + (void)aul_terminate_pid(s_info.svc_daemon_pid); + + s_info.ttl_timer = NULL; + s_info.svc_daemon_is_launched = 0; + s_info.svc_daemon_pid = -1; + s_info.svc_daemon = NULL; + return -ECANCELED; } static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data) { - struct packet *reply; - const char *cmd; - int ret; + struct packet *reply; + const char *cmd; + int ret; + + if (!packet) { + DbgPrint("TCB %p is terminated (NIL packet), %d\n", tcb, s_info.svc_daemon_pid); + + if (tcb == s_info.svc_daemon) { + s_info.svc_daemon = NULL; + s_info.svc_daemon_is_launched = 0; + s_info.svc_daemon_pid = -1; + + if (s_info.ttl_timer) { + service_common_del_timer(tcb_svc_ctx(tcb), s_info.ttl_timer); + s_info.ttl_timer = NULL; + } + } - if (!packet) { - DbgPrint("TCB %p is terminated (NIL packet), %d\n", tcb, s_info.svc_daemon_pid); + return DBOX_STATUS_ERROR_NONE; + } - if (tcb == s_info.svc_daemon) { - s_info.svc_daemon = NULL; - s_info.svc_daemon_is_launched = 0; - s_info.svc_daemon_pid = -1; + cmd = packet_command(packet); + if (!cmd) { + ErrPrint("Invalid packet\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (s_info.ttl_timer) { - service_common_del_timer(tcb_svc_ctx(tcb), s_info.ttl_timer); - s_info.ttl_timer = NULL; - } + switch (packet_type(packet)) { + case PACKET_REQ: + if (!s_info.svc_daemon_is_launched) { + ret = launch_svc(tcb_svc_ctx(tcb)); + if (ret != DBOX_STATUS_ERROR_NONE) { + goto reply_out; } + } - return DBOX_STATUS_ERROR_NONE; - } - - cmd = packet_command(packet); - if (!cmd) { - ErrPrint("Invalid packet\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - switch (packet_type(packet)) { - case PACKET_REQ: - if (!s_info.svc_daemon_is_launched) { - ret = launch_svc(tcb_svc_ctx(tcb)); - if (ret != DBOX_STATUS_ERROR_NONE) { - goto reply_out; - } + if (!s_info.svc_daemon) { + ret = put_pended_request(tcb, packet); + if (ret < 0) { + goto reply_out; + } + } else if (tcb_is_valid(s_info.svc_ctx, s_info.svc_daemon) >= 0) { + ret = service_common_unicast_packet(s_info.svc_daemon, packet); + if (ret <0) { + goto reply_out; } - if (!s_info.svc_daemon) { - ret = put_pended_request(tcb, packet); - if (ret < 0) { - goto reply_out; - } - } else if (tcb_is_valid(s_info.svc_ctx, s_info.svc_daemon) >= 0) { - ret = service_common_unicast_packet(s_info.svc_daemon, packet); - if (ret <0) { - goto reply_out; - } - - put_reply_tcb(tcb, packet_seq(packet)); - - if (s_info.ttl_timer && service_common_update_timer(s_info.ttl_timer, TTL_TIMEOUT) < 0) { - ErrPrint("Failed to update timer\n"); - } + put_reply_tcb(tcb, packet_seq(packet)); + + if (s_info.ttl_timer && service_common_update_timer(s_info.ttl_timer, TTL_TIMEOUT) < 0) { + ErrPrint("Failed to update timer\n"); } + } - break; + break; case PACKET_REQ_NOACK: - if (!strcmp(cmd, "service_register")) { - if (!s_info.svc_daemon_is_launched) { - ErrPrint("Service daemon is not launched. but something tries to register a service\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (s_info.svc_daemon) { - ErrPrint("Service daemon is already prepared\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (s_info.launch_timer) { - service_common_del_timer(tcb_svc_ctx(tcb), s_info.launch_timer); - s_info.launch_timer = NULL; - } - - s_info.ttl_timer = service_common_add_timer(tcb_svc_ctx(tcb), TTL_TIMEOUT, ttl_timer_cb, NULL); - if (!s_info.ttl_timer) { - ErrPrint("Failed to add TTL timer\n"); - if (s_info.svc_daemon_pid > 0) { - ret = aul_terminate_pid(s_info.svc_daemon_pid); - ErrPrint("Terminate: %d\n", ret); - s_info.svc_daemon_pid = -1; - } - s_info.svc_daemon_is_launched = 0; - return DBOX_STATUS_ERROR_FAULT; - } - DbgPrint("TTL Timer is added: %p\n", s_info.ttl_timer); - - s_info.svc_daemon = tcb; - flush_pended_request(); + if (!strcmp(cmd, "service_register")) { + if (!s_info.svc_daemon_is_launched) { + ErrPrint("Service daemon is not launched. but something tries to register a service\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } - break; - case PACKET_ACK: - tcb = get_reply_tcb(packet_seq(packet)); - if (!tcb) { - ErrPrint("Unable to find reply tcb\n"); - break; + + if (s_info.svc_daemon) { + ErrPrint("Service daemon is already prepared\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } - if (tcb_is_valid(s_info.svc_ctx, tcb) < 0) { - ErrPrint("TCB is not valid\n"); - break; + if (s_info.launch_timer) { + service_common_del_timer(tcb_svc_ctx(tcb), s_info.launch_timer); + s_info.launch_timer = NULL; } - ret = service_common_unicast_packet(tcb, packet); - if (ret < 0) { - ErrPrint("Unable to forward the reply packet\n"); + s_info.ttl_timer = service_common_add_timer(tcb_svc_ctx(tcb), TTL_TIMEOUT, ttl_timer_cb, NULL); + if (!s_info.ttl_timer) { + ErrPrint("Failed to add TTL timer\n"); + if (s_info.svc_daemon_pid > 0) { + ret = aul_terminate_pid(s_info.svc_daemon_pid); + ErrPrint("Terminate: %d\n", ret); + s_info.svc_daemon_pid = -1; + } + s_info.svc_daemon_is_launched = 0; + return DBOX_STATUS_ERROR_FAULT; } + DbgPrint("TTL Timer is added: %p\n", s_info.ttl_timer); + + s_info.svc_daemon = tcb; + flush_pended_request(); + } + break; + case PACKET_ACK: + tcb = get_reply_tcb(packet_seq(packet)); + if (!tcb) { + ErrPrint("Unable to find reply tcb\n"); + break; + } + + if (tcb_is_valid(s_info.svc_ctx, tcb) < 0) { + ErrPrint("TCB is not valid\n"); break; + } + + ret = service_common_unicast_packet(tcb, packet); + if (ret < 0) { + ErrPrint("Unable to forward the reply packet\n"); + } + break; default: - ErrPrint("Packet type is not valid[%s]\n", cmd); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Packet type is not valid[%s]\n", cmd); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; reply_out: - ErrPrint("Error: %d\n", ret); - reply = packet_create_reply(packet, "i", ret); - if (service_common_unicast_packet(tcb, reply) < 0) { - ErrPrint("Unable to send reply packet\n"); - } - packet_destroy(reply); - return ret; + ErrPrint("Error: %d\n", ret); + reply = packet_create_reply(packet, "i", ret); + if (service_common_unicast_packet(tcb, reply) < 0) { + ErrPrint("Unable to send reply packet\n"); + } + packet_destroy(reply); + return ret; } int utility_service_init(void) { - if (s_info.svc_ctx) { - ErrPrint("Already initialized\n"); - return DBOX_STATUS_ERROR_ALREADY; + if (s_info.svc_ctx) { + ErrPrint("Already initialized\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + s_info.svc_ctx = service_common_create(UTILITY_SOCKET, service_thread_main, NULL); + if (!s_info.svc_ctx) { + ErrPrint("Unable to activate service thread\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), UTILITY_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; } - - s_info.svc_ctx = service_common_create(UTILITY_SOCKET, service_thread_main, NULL); - if (!s_info.svc_ctx) { - ErrPrint("Unable to activate service thread\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), UTILITY_SMACK_LABEL, SMACK_LABEL_IPOUT) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } + } + + if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), UTILITY_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { + if (errno != EOPNOTSUPP) { + ErrPrint("Unable to set SMACK label(%d)\n", errno); + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + return DBOX_STATUS_ERROR_FAULT; } + } - if (smack_fsetlabel(service_common_fd(s_info.svc_ctx), UTILITY_SMACK_LABEL, SMACK_LABEL_IPIN) != 0) { - if (errno != EOPNOTSUPP) { - ErrPrint("Unable to set SMACK label(%d)\n", errno); - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - return DBOX_STATUS_ERROR_FAULT; - } - } - - DbgPrint("Successfully initiated\n"); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("Successfully initiated\n"); + return DBOX_STATUS_ERROR_NONE; } int utility_service_fini(void) { - if (!s_info.svc_ctx) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - service_common_destroy(s_info.svc_ctx); - s_info.svc_ctx = NULL; - DbgPrint("Successfully Finalized\n"); - return DBOX_STATUS_ERROR_NONE; + if (!s_info.svc_ctx) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + service_common_destroy(s_info.svc_ctx); + s_info.svc_ctx = NULL; + DbgPrint("Successfully Finalized\n"); + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/xmonitor.c b/src/xmonitor.c index bb820e3..2e240c0 100644 --- a/src/xmonitor.c +++ b/src/xmonitor.c @@ -46,446 +46,446 @@ int errno; struct event_item { - int (*cb)(void *user_data); - void *user_data; + int (*cb)(void *user_data); + void *user_data; }; static struct info { - Ecore_Event_Handler *create_handler; - Ecore_Event_Handler *destroy_handler; - Ecore_Event_Handler *client_handler; + Ecore_Event_Handler *create_handler; + Ecore_Event_Handler *destroy_handler; + Ecore_Event_Handler *client_handler; - Eina_List *pause_list; - Eina_List *resume_list; + Eina_List *pause_list; + Eina_List *resume_list; - int paused; + int paused; } s_info = { - .create_handler = NULL, - .destroy_handler = NULL, - .client_handler = NULL, + .create_handler = NULL, + .destroy_handler = NULL, + .client_handler = NULL, - .pause_list = NULL, - .resume_list = NULL, + .pause_list = NULL, + .resume_list = NULL, - .paused = 1, /*!< The provider is treated as paused process when it is launched */ + .paused = 1, /*!< The provider is treated as paused process when it is launched */ }; static inline void touch_paused_file(void) { - int fd; - fd = creat(DYNAMICBOX_CONF_PAUSED_FILE, 0644); - if (fd >= 0) { - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - } else { - ErrPrint("Create .live.paused: %s\n", strerror(errno)); + int fd; + fd = creat(DYNAMICBOX_CONF_PAUSED_FILE, 0644); + if (fd >= 0) { + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } + } else { + ErrPrint("Create .live.paused: %s\n", strerror(errno)); + } } static inline void remove_paused_file(void) { - if (unlink(DYNAMICBOX_CONF_PAUSED_FILE) < 0) { - ErrPrint("Unlink .live.paused: %s\n", strerror(errno)); - } + if (unlink(DYNAMICBOX_CONF_PAUSED_FILE) < 0) { + ErrPrint("Unlink .live.paused: %s\n", strerror(errno)); + } } static inline int get_pid(Ecore_X_Window win) { - int pid; - Ecore_X_Atom atom; - unsigned char *in_pid; - int num; - - atom = ecore_x_atom_get("X_CLIENT_PID"); - if (ecore_x_window_prop_property_get(win, atom, ECORE_X_ATOM_CARDINAL, - sizeof(int), &in_pid, &num) == EINA_FALSE) { - if (ecore_x_netwm_pid_get(win, &pid) == EINA_FALSE) { - ErrPrint("Failed to get PID from a window 0x%X\n", win); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - } else if (in_pid) { - pid = *(int *)in_pid; - DbgFree(in_pid); - } else { - ErrPrint("Failed to get PID\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + int pid; + Ecore_X_Atom atom; + unsigned char *in_pid; + int num; + + atom = ecore_x_atom_get("X_CLIENT_PID"); + if (ecore_x_window_prop_property_get(win, atom, ECORE_X_ATOM_CARDINAL, + sizeof(int), &in_pid, &num) == EINA_FALSE) { + if (ecore_x_netwm_pid_get(win, &pid) == EINA_FALSE) { + ErrPrint("Failed to get PID from a window 0x%X\n", win); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } - - return pid; + } else if (in_pid) { + pid = *(int *)in_pid; + DbgFree(in_pid); + } else { + ErrPrint("Failed to get PID\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + return pid; } static Eina_Bool create_cb(void *data, int type, void *event) { - Ecore_X_Event_Window_Create *info = event; - ecore_x_window_client_sniff(info->win); - return ECORE_CALLBACK_PASS_ON; + Ecore_X_Event_Window_Create *info = event; + ecore_x_window_client_sniff(info->win); + return ECORE_CALLBACK_PASS_ON; } static Eina_Bool destroy_cb(void *data, int type, void *event) { - // Ecore_X_Event_Window_Destroy *info = event; - return ECORE_CALLBACK_PASS_ON; + // Ecore_X_Event_Window_Destroy *info = event; + return ECORE_CALLBACK_PASS_ON; } HAPI void xmonitor_handle_state_changes(void) { - int paused; - Eina_List *l; - struct event_item *item; + int paused; + Eina_List *l; + struct event_item *item; - paused = client_is_all_paused() || setting_is_lcd_off(); - if (s_info.paused == paused) { - return; - } + paused = client_is_all_paused() || setting_is_lcd_off(); + if (s_info.paused == paused) { + return; + } - s_info.paused = paused; + s_info.paused = paused; - if (s_info.paused) { - EINA_LIST_FOREACH(s_info.pause_list, l, item) { - if (item->cb) { - item->cb(item->user_data); - } - } + if (s_info.paused) { + EINA_LIST_FOREACH(s_info.pause_list, l, item) { + if (item->cb) { + item->cb(item->user_data); + } + } - touch_paused_file(); + touch_paused_file(); - sqlite3_release_memory(DYNAMICBOX_CONF_SQLITE_FLUSH_MAX); - malloc_trim(0); - } else { - remove_paused_file(); + sqlite3_release_memory(DYNAMICBOX_CONF_SQLITE_FLUSH_MAX); + malloc_trim(0); + } else { + remove_paused_file(); - EINA_LIST_FOREACH(s_info.resume_list, l, item) { - if (item->cb) { - item->cb(item->user_data); - } - } + EINA_LIST_FOREACH(s_info.resume_list, l, item) { + if (item->cb) { + item->cb(item->user_data); + } } + } } HAPI int xmonitor_update_state(int target_pid) { - Ecore_X_Window win; - struct client_node *client; - int pid; + Ecore_X_Window win; + struct client_node *client; + int pid; - if (!DYNAMICBOX_CONF_USE_XMONITOR || target_pid < 0) { - return DBOX_STATUS_ERROR_NONE; - } + if (!DYNAMICBOX_CONF_USE_XMONITOR || target_pid < 0) { + return DBOX_STATUS_ERROR_NONE; + } - win = ecore_x_window_focus_get(); + win = ecore_x_window_focus_get(); - pid = get_pid(win); - if (pid <= 0) { - DbgPrint("Focused window has no PID %X\n", win); - client = client_find_by_pid(target_pid); - if (client) { - DbgPrint("Client window has no focus now\n"); - client_paused(client); - } - return DBOX_STATUS_ERROR_NOT_EXIST; + pid = get_pid(win); + if (pid <= 0) { + DbgPrint("Focused window has no PID %X\n", win); + client = client_find_by_pid(target_pid); + if (client) { + DbgPrint("Client window has no focus now\n"); + client_paused(client); } - - client = client_find_by_pid(pid); - if (!client) { - DbgPrint("Client %d is not registered yet\n", pid); - client = client_find_by_pid(target_pid); - if (client) { - DbgPrint("Client window has no focus now\n"); - client_paused(client); - } - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + return DBOX_STATUS_ERROR_NOT_EXIST; + } + + client = client_find_by_pid(pid); + if (!client) { + DbgPrint("Client %d is not registered yet\n", pid); + client = client_find_by_pid(target_pid); + if (client) { + DbgPrint("Client window has no focus now\n"); + client_paused(client); } + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (target_pid != pid) { - DbgPrint("Client is paused\n"); - client_paused(client); - } else { - DbgPrint("Client is resumed\n"); - client_resumed(client); - } + if (target_pid != pid) { + DbgPrint("Client is paused\n"); + client_paused(client); + } else { + DbgPrint("Client is resumed\n"); + client_resumed(client); + } - xmonitor_handle_state_changes(); - return DBOX_STATUS_ERROR_NONE; + xmonitor_handle_state_changes(); + return DBOX_STATUS_ERROR_NONE; } static Eina_Bool client_cb(void *data, int type, void *event) { - Ecore_X_Event_Client_Message *info = event; - struct client_node *client; - char *name; - int pid; - - pid = get_pid(info->win); - if (pid <= 0) { - return ECORE_CALLBACK_PASS_ON; - } + Ecore_X_Event_Client_Message *info = event; + struct client_node *client; + char *name; + int pid; - client = client_find_by_pid(pid); - if (!client) { - return ECORE_CALLBACK_PASS_ON; - } - - name = ecore_x_atom_name_get(info->message_type); - if (!name) { - return ECORE_CALLBACK_PASS_ON; - } + pid = get_pid(info->win); + if (pid <= 0) { + return ECORE_CALLBACK_PASS_ON; + } - if (!strcmp(name, "_X_ILLUME_DEACTIVATE_WINDOW")) { - xmonitor_pause(client); - } else if (!strcmp(name, "_X_ILLUME_ACTIVATE_WINDOW")) { - xmonitor_resume(client); - } else { - /* ignore event */ - } + client = client_find_by_pid(pid); + if (!client) { + return ECORE_CALLBACK_PASS_ON; + } - DbgFree(name); + name = ecore_x_atom_name_get(info->message_type); + if (!name) { return ECORE_CALLBACK_PASS_ON; + } + + if (!strcmp(name, "_X_ILLUME_DEACTIVATE_WINDOW")) { + xmonitor_pause(client); + } else if (!strcmp(name, "_X_ILLUME_ACTIVATE_WINDOW")) { + xmonitor_resume(client); + } else { + /* ignore event */ + } + + DbgFree(name); + return ECORE_CALLBACK_PASS_ON; } static inline void sniff_all_windows(void) { - Ecore_X_Window root; - Ecore_X_Window ret; - struct stack_item *new_item; - struct stack_item *item; - Eina_List *win_stack; - //int pid; - struct stack_item { - Ecore_X_Window *wins; - int nr_of_wins; - int i; - }; - - root = ecore_x_window_root_first_get(); - ecore_x_window_sniff(root); - - new_item = malloc(sizeof(*new_item)); - if (!new_item) { - ErrPrint("Error(%s)\n", strerror(errno)); - return; - } + Ecore_X_Window root; + Ecore_X_Window ret; + struct stack_item *new_item; + struct stack_item *item; + Eina_List *win_stack; + //int pid; + struct stack_item { + Ecore_X_Window *wins; + int nr_of_wins; + int i; + }; + + root = ecore_x_window_root_first_get(); + ecore_x_window_sniff(root); + + new_item = malloc(sizeof(*new_item)); + if (!new_item) { + ErrPrint("Error(%s)\n", strerror(errno)); + return; + } - new_item->nr_of_wins = 0; - new_item->wins = - ecore_x_window_children_get(root, &new_item->nr_of_wins); - new_item->i = 0; + new_item->nr_of_wins = 0; + new_item->wins = + ecore_x_window_children_get(root, &new_item->nr_of_wins); + new_item->i = 0; - win_stack = NULL; + win_stack = NULL; - if (new_item->wins) { - win_stack = eina_list_append(win_stack, new_item); - } else { - DbgFree(new_item); - } + if (new_item->wins) { + win_stack = eina_list_append(win_stack, new_item); + } else { + DbgFree(new_item); + } - while ((item = eina_list_nth(win_stack, 0))) { - win_stack = eina_list_remove(win_stack, item); + while ((item = eina_list_nth(win_stack, 0))) { + win_stack = eina_list_remove(win_stack, item); - if (!item->wins) { - DbgFree(item); - continue; - } + if (!item->wins) { + DbgFree(item); + continue; + } - while (item->i < item->nr_of_wins) { - ret = item->wins[item->i]; - - /* - * Now we don't need to care about visibility of window, - * just check whether it is registered or not. - * (ecore_x_window_visible_get(ret)) - */ - ecore_x_window_client_sniff(ret); - - new_item = malloc(sizeof(*new_item)); - if (!new_item) { - ErrPrint("Error %s\n", strerror(errno)); - item->i++; - continue; - } - - new_item->i = 0; - new_item->nr_of_wins = 0; - new_item->wins = - ecore_x_window_children_get(ret, - &new_item->nr_of_wins); - if (new_item->wins) { - win_stack = - eina_list_append(win_stack, new_item); - } else { - DbgFree(new_item); - } - - item->i++; - } + while (item->i < item->nr_of_wins) { + ret = item->wins[item->i]; + + /* + * Now we don't need to care about visibility of window, + * just check whether it is registered or not. + * (ecore_x_window_visible_get(ret)) + */ + ecore_x_window_client_sniff(ret); + + new_item = malloc(sizeof(*new_item)); + if (!new_item) { + ErrPrint("Error %s\n", strerror(errno)); + item->i++; + continue; + } + + new_item->i = 0; + new_item->nr_of_wins = 0; + new_item->wins = + ecore_x_window_children_get(ret, + &new_item->nr_of_wins); + if (new_item->wins) { + win_stack = + eina_list_append(win_stack, new_item); + } else { + DbgFree(new_item); + } - DbgFree(item->wins); - DbgFree(item); + item->i++; } - return; + DbgFree(item->wins); + DbgFree(item); + } + + return; } HAPI int xmonitor_pause(struct client_node *client) { - DbgPrint("%d is paused\n", client_pid(client)); - client_paused(client); - xmonitor_handle_state_changes(); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("%d is paused\n", client_pid(client)); + client_paused(client); + xmonitor_handle_state_changes(); + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_resume(struct client_node *client) { - DbgPrint("%d is resumed\n", client_pid(client)); - client_resumed(client); - xmonitor_handle_state_changes(); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("%d is resumed\n", client_pid(client)); + client_resumed(client); + xmonitor_handle_state_changes(); + return DBOX_STATUS_ERROR_NONE; } static inline void disable_xmonitor(void) { - ecore_event_handler_del(s_info.create_handler); - ecore_event_handler_del(s_info.destroy_handler); - ecore_event_handler_del(s_info.client_handler); + ecore_event_handler_del(s_info.create_handler); + ecore_event_handler_del(s_info.destroy_handler); + ecore_event_handler_del(s_info.client_handler); - s_info.create_handler = NULL; - s_info.destroy_handler = NULL; - s_info.client_handler = NULL; + s_info.create_handler = NULL; + s_info.destroy_handler = NULL; + s_info.client_handler = NULL; } static inline int enable_xmonitor(void) { - if (ecore_x_composite_query() == EINA_FALSE) { - DbgPrint("====> COMPOSITOR IS NOT ENABLED\n"); - } - - s_info.create_handler = - ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CREATE, - create_cb, NULL); - if (!s_info.create_handler) { - ErrPrint("Failed to add create event handler\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - s_info.destroy_handler = - ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY, - destroy_cb, NULL); - if (!s_info.destroy_handler) { - ErrPrint("Failed to add destroy event handler\n"); - ecore_event_handler_del(s_info.create_handler); - s_info.create_handler = NULL; - return DBOX_STATUS_ERROR_FAULT; - } - - s_info.client_handler = - ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, - client_cb, NULL); - if (!s_info.client_handler) { - ErrPrint("Failed to add focus out event handler\n"); - ecore_event_handler_del(s_info.create_handler); - ecore_event_handler_del(s_info.destroy_handler); - s_info.create_handler = NULL; - s_info.destroy_handler = NULL; - return DBOX_STATUS_ERROR_FAULT; - } + if (ecore_x_composite_query() == EINA_FALSE) { + DbgPrint("====> COMPOSITOR IS NOT ENABLED\n"); + } + + s_info.create_handler = + ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CREATE, + create_cb, NULL); + if (!s_info.create_handler) { + ErrPrint("Failed to add create event handler\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + s_info.destroy_handler = + ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY, + destroy_cb, NULL); + if (!s_info.destroy_handler) { + ErrPrint("Failed to add destroy event handler\n"); + ecore_event_handler_del(s_info.create_handler); + s_info.create_handler = NULL; + return DBOX_STATUS_ERROR_FAULT; + } + + s_info.client_handler = + ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, + client_cb, NULL); + if (!s_info.client_handler) { + ErrPrint("Failed to add focus out event handler\n"); + ecore_event_handler_del(s_info.create_handler); + ecore_event_handler_del(s_info.destroy_handler); + s_info.create_handler = NULL; + s_info.destroy_handler = NULL; + return DBOX_STATUS_ERROR_FAULT; + } - sniff_all_windows(); - return DBOX_STATUS_ERROR_NONE; + sniff_all_windows(); + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_init(void) { - if (DYNAMICBOX_CONF_USE_XMONITOR) { - int ret; - ret = enable_xmonitor(); - if (ret < 0) { - return ret; - } + if (DYNAMICBOX_CONF_USE_XMONITOR) { + int ret; + ret = enable_xmonitor(); + if (ret < 0) { + return ret; } + } - s_info.paused = client_is_all_paused() || setting_is_lcd_off(); - if (s_info.paused) { - touch_paused_file(); - } else { - remove_paused_file(); - } + s_info.paused = client_is_all_paused() || setting_is_lcd_off(); + if (s_info.paused) { + touch_paused_file(); + } else { + remove_paused_file(); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI void xmonitor_fini(void) { - if (DYNAMICBOX_CONF_USE_XMONITOR) { - disable_xmonitor(); - } + if (DYNAMICBOX_CONF_USE_XMONITOR) { + disable_xmonitor(); + } } HAPI int xmonitor_add_event_callback(enum xmonitor_event event, int (*cb)(void *user_data), void *user_data) { - struct event_item *item; + struct event_item *item; - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->cb = cb; - item->user_data = user_data; + item->cb = cb; + item->user_data = user_data; - switch (event) { + switch (event) { case XMONITOR_PAUSED: - s_info.pause_list = eina_list_prepend(s_info.pause_list, item); - break; + s_info.pause_list = eina_list_prepend(s_info.pause_list, item); + break; case XMONITOR_RESUMED: - s_info.resume_list = eina_list_prepend(s_info.resume_list, item); - break; + s_info.resume_list = eina_list_prepend(s_info.resume_list, item); + break; default: - ErrPrint("Invalid event type\n"); - DbgFree(item); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Invalid event type\n"); + DbgFree(item); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_del_event_callback(enum xmonitor_event event, int (*cb)(void *user_data), void *user_data) { - struct event_item *item; - Eina_List *l; - Eina_List *n; + struct event_item *item; + Eina_List *l; + Eina_List *n; - switch (event) { + switch (event) { case XMONITOR_PAUSED: - EINA_LIST_FOREACH_SAFE(s_info.pause_list, l, n, item) { - if (item->cb == cb && item->user_data == user_data) { - s_info.pause_list = eina_list_remove(s_info.pause_list, item); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.pause_list, l, n, item) { + if (item->cb == cb && item->user_data == user_data) { + s_info.pause_list = eina_list_remove(s_info.pause_list, item); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case XMONITOR_RESUMED: - EINA_LIST_FOREACH_SAFE(s_info.resume_list, l, n, item) { - if (item->cb == cb && item->user_data == user_data) { - s_info.resume_list = eina_list_remove(s_info.resume_list, item); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.resume_list, l, n, item) { + if (item->cb == cb && item->user_data == user_data) { + s_info.resume_list = eina_list_remove(s_info.resume_list, item); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; default: - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int xmonitor_is_paused(void) { - return s_info.paused; + return s_info.paused; } /* End of a file */ diff --git a/src/xmonitor_wayland.c b/src/xmonitor_wayland.c index 7f1604b..bfe8016 100644 --- a/src/xmonitor_wayland.c +++ b/src/xmonitor_wayland.c @@ -42,209 +42,209 @@ int errno; struct event_item { - int (*cb)(void *user_data); - void *user_data; + int (*cb)(void *user_data); + void *user_data; }; static struct info { - Ecore_Event_Handler *create_handler; - Ecore_Event_Handler *destroy_handler; - Ecore_Event_Handler *client_handler; + Ecore_Event_Handler *create_handler; + Ecore_Event_Handler *destroy_handler; + Ecore_Event_Handler *client_handler; - Eina_List *pause_list; - Eina_List *resume_list; + Eina_List *pause_list; + Eina_List *resume_list; - int paused; + int paused; } s_info = { - .create_handler = NULL, - .destroy_handler = NULL, - .client_handler = NULL, + .create_handler = NULL, + .destroy_handler = NULL, + .client_handler = NULL, - .pause_list = NULL, - .resume_list = NULL, + .pause_list = NULL, + .resume_list = NULL, - .paused = 1, /*!< The provider is treated as paused process when it is launched */ + .paused = 1, /*!< The provider is treated as paused process when it is launched */ }; static inline void touch_paused_file(void) { - int fd; - fd = creat(PAUSED_FILE, 0644); - if (fd >= 0) { - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - } else { - ErrPrint("Create .live.paused: %s\n", strerror(errno)); + int fd; + fd = creat(PAUSED_FILE, 0644); + if (fd >= 0) { + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); } + } else { + ErrPrint("Create .live.paused: %s\n", strerror(errno)); + } } static inline void remove_paused_file(void) { - if (unlink(PAUSED_FILE) < 0) { - ErrPrint("Unlink .live.paused: %s\n", strerror(errno)); - } + if (unlink(PAUSED_FILE) < 0) { + ErrPrint("Unlink .live.paused: %s\n", strerror(errno)); + } } HAPI void xmonitor_handle_state_changes(void) { - int paused; - Eina_List *l; - struct event_item *item; - - paused = client_is_all_paused() || setting_is_lcd_off(); - if (s_info.paused == paused) { - return; + int paused; + Eina_List *l; + struct event_item *item; + + paused = client_is_all_paused() || setting_is_lcd_off(); + if (s_info.paused == paused) { + return; + } + + s_info.paused = paused; + + if (s_info.paused) { + EINA_LIST_FOREACH(s_info.pause_list, l, item) { + if (item->cb) { + item->cb(item->user_data); + } } - s_info.paused = paused; - - if (s_info.paused) { - EINA_LIST_FOREACH(s_info.pause_list, l, item) { - if (item->cb) { - item->cb(item->user_data); - } - } - - touch_paused_file(); + touch_paused_file(); - sqlite3_release_memory(SQLITE_FLUSH_MAX); - malloc_trim(0); - } else { - remove_paused_file(); + sqlite3_release_memory(SQLITE_FLUSH_MAX); + malloc_trim(0); + } else { + remove_paused_file(); - EINA_LIST_FOREACH(s_info.resume_list, l, item) { - if (item->cb) { - item->cb(item->user_data); - } - } + EINA_LIST_FOREACH(s_info.resume_list, l, item) { + if (item->cb) { + item->cb(item->user_data); + } } + } } HAPI int xmonitor_update_state(int target_pid) { - struct client_node *client; - - if (!USE_XMONITOR || target_pid < 0) { - return DBOX_STATUS_ERROR_NONE; - } + struct client_node *client; - /*! - * \TODO - * Find the top(focuesd) window's PID - * Compare it with target_pid. - * If it is what we finding, call the - * xmonitor_pause or xmonitor_resume - */ - - xmonitor_handle_state_changes(); + if (!USE_XMONITOR || target_pid < 0) { return DBOX_STATUS_ERROR_NONE; + } + + /*! + * \TODO + * Find the top(focuesd) window's PID + * Compare it with target_pid. + * If it is what we finding, call the + * xmonitor_pause or xmonitor_resume + */ + + xmonitor_handle_state_changes(); + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_pause(struct client_node *client) { - DbgPrint("%d is paused\n", client_pid(client)); - client_paused(client); - xmonitor_handle_state_changes(); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("%d is paused\n", client_pid(client)); + client_paused(client); + xmonitor_handle_state_changes(); + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_resume(struct client_node *client) { - DbgPrint("%d is resumed\n", client_pid(client)); - client_resumed(client); - xmonitor_handle_state_changes(); - return DBOX_STATUS_ERROR_NONE; + DbgPrint("%d is resumed\n", client_pid(client)); + client_resumed(client); + xmonitor_handle_state_changes(); + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_init(void) { - if (USE_XMONITOR) { - return DBOX_STATUS_ERROR_NONE; - } + if (USE_XMONITOR) { + return DBOX_STATUS_ERROR_NONE; + } - s_info.paused = client_is_all_paused() || setting_is_lcd_off(); - if (s_info.paused) { - touch_paused_file(); - } else { - remove_paused_file(); - } + s_info.paused = client_is_all_paused() || setting_is_lcd_off(); + if (s_info.paused) { + touch_paused_file(); + } else { + remove_paused_file(); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI void xmonitor_fini(void) { - if (USE_XMONITOR) { - } + if (USE_XMONITOR) { + } } HAPI int xmonitor_add_event_callback(enum xmonitor_event event, int (*cb)(void *user_data), void *user_data) { - struct event_item *item; + struct event_item *item; - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->cb = cb; - item->user_data = user_data; + item->cb = cb; + item->user_data = user_data; - switch (event) { + switch (event) { case XMONITOR_PAUSED: - s_info.pause_list = eina_list_prepend(s_info.pause_list, item); - break; + s_info.pause_list = eina_list_prepend(s_info.pause_list, item); + break; case XMONITOR_RESUMED: - s_info.resume_list = eina_list_prepend(s_info.resume_list, item); - break; + s_info.resume_list = eina_list_prepend(s_info.resume_list, item); + break; default: - ErrPrint("Invalid event type\n"); - DbgFree(item); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Invalid event type\n"); + DbgFree(item); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } HAPI int xmonitor_del_event_callback(enum xmonitor_event event, int (*cb)(void *user_data), void *user_data) { - struct event_item *item; - Eina_List *l; - Eina_List *n; + struct event_item *item; + Eina_List *l; + Eina_List *n; - switch (event) { + switch (event) { case XMONITOR_PAUSED: - EINA_LIST_FOREACH_SAFE(s_info.pause_list, l, n, item) { - if (item->cb == cb && item->user_data == user_data) { - s_info.pause_list = eina_list_remove(s_info.pause_list, item); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.pause_list, l, n, item) { + if (item->cb == cb && item->user_data == user_data) { + s_info.pause_list = eina_list_remove(s_info.pause_list, item); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; case XMONITOR_RESUMED: - EINA_LIST_FOREACH_SAFE(s_info.resume_list, l, n, item) { - if (item->cb == cb && item->user_data == user_data) { - s_info.resume_list = eina_list_remove(s_info.resume_list, item); - DbgFree(item); - return DBOX_STATUS_ERROR_NONE; - } + EINA_LIST_FOREACH_SAFE(s_info.resume_list, l, n, item) { + if (item->cb == cb && item->user_data == user_data) { + s_info.resume_list = eina_list_remove(s_info.resume_list, item); + DbgFree(item); + return DBOX_STATUS_ERROR_NONE; } - break; + } + break; default: - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NOT_EXIST; + return DBOX_STATUS_ERROR_NOT_EXIST; } HAPI int xmonitor_is_paused(void) { - return s_info.paused; + return s_info.paused; } /* End of a file */ -- 2.7.4