From: Hwankyu Jhun Date: Tue, 21 Aug 2018 07:44:45 +0000 (+0900) Subject: Refactor aul launch X-Git-Tag: accepted/tizen/unified/20180827.071448~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47498c72cfb019c7931c56ce1367a3ecb38a8640;p=platform%2Fcore%2Fappfw%2Faul-1.git Refactor aul launch - Uses gio channel instead of gsource - Removes unused codes - Moves launch codes to aul_launch.c file Change-Id: I7908fcbcf83ce51bbf8569c9eb3c2a50e0b17183 Signed-off-by: Hwankyu Jhun --- diff --git a/include/aul_sock.h b/include/aul_sock.h index e305cf1..cee5e9d 100644 --- a/include/aul_sock.h +++ b/include/aul_sock.h @@ -118,3 +118,8 @@ int aul_sock_recv_result_with_fd(int fd); * This API in only for Appfw internally. */ int aul_sock_destroy_server(int fd); + +/** + * This API is only for Appfw internally. + */ +int aul_sock_send_result(int fd, int res); diff --git a/include/launch.h b/include/launch.h index 8cd5f83..d78a0eb 100644 --- a/include/launch.h +++ b/include/launch.h @@ -19,14 +19,9 @@ #include int aul_initialize(); -int aul_register_init_callback( - int (*aul_handler)(aul_type type, bundle *, void *), void *data); int aul_is_initialized(); -int aul_sock_handler(int fd); -int aul_make_bundle_from_argv(int argc, char **argv, bundle **kb); int aul_app_register_pid(const char *appid, int pid); -int app_start(bundle *kb); int app_send_cmd(int pid, int cmd, bundle *kb); int app_send_cmd_for_uid(int pid, uid_t uid, int cmd, bundle *kb); int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb); @@ -34,7 +29,6 @@ int app_send_cmd_to_launchpad(const char *pad_type, uid_t uid, int cmd, bundle * int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb); int app_request_to_launchpad_for_uid(int cmd, const char *pkgname, bundle *kb, uid_t uid); -int _app_start_res_prepare(bundle *kb); int app_result(int cmd, bundle *kb, int launched_pid); int aul_send_result(bundle *kb, int is_cancel); int aul_launch_app_with_result(const char *pkgname, bundle *kb, @@ -44,11 +38,11 @@ int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb, void (*cbfunc) (bundle *, int, void *), void *data, uid_t uid); int app_subapp_terminate_request(void); -int __call_aul_handler(aul_type type, bundle *kb); -gboolean __aul_glib_handler(gpointer data); int app_com_recv(bundle *b); int aul_launch_app_with_result_async(const char *appid, bundle *b, void (*callback)(bundle *, int, void *), void *data); int aul_launch_app_with_result_async_for_uid(const char *appid, bundle *b, void (*callback)(bundle *, int, void *), void *data, uid_t uid); +int aul_resume_local(void); +int aul_launch_fini(void); diff --git a/src/aul_launch.c b/src/aul_launch.c new file mode 100644 index 0000000..6fc0b4c --- /dev/null +++ b/src/aul_launch.c @@ -0,0 +1,463 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "aul_api.h" +#include "aul_cmd.h" +#include "aul_util.h" +#include "aul.h" +#include "aul_sock.h" +#include "launch.h" +#include "key.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +struct aul_request_s { + int cmd; + int clifd; + bundle *b; +}; + +typedef struct aul_request_s *aul_request_h; + +typedef void (*dispatcher)(aul_request_h req); + +typedef struct aul_handler_s { + aul_handler_fn callback; + void *user_data; +} aul_handler; + +typedef struct subapp_handler_s { + bool is_subapp; + subapp_fn callback; + void *user_data; +} subapp_handler; + +typedef struct data_control_provider_handler_s { + data_control_provider_handler_fn callback; +} data_control_provider_handler; + +typedef struct launch_context_s { + GIOChannel *io; + guint source; + aul_handler aul; + subapp_handler subapp; + data_control_provider_handler dcp; +} launch_context; + +static launch_context __context; + +static void __invoke_aul_handler(aul_type type, bundle *b) +{ + if (__context.aul.callback) + __context.aul.callback(type, b, __context.aul.user_data); +} + +static void __dispatch_app_start(aul_request_h req) +{ + const char *str; + + __invoke_aul_handler(AUL_START, req->b); + str = bundle_get_val(req->b, AUL_K_DATA_CONTROL_TYPE); + if (str && !strcmp(str, "CORE")) { + if (__context.dcp.callback) + __context.dcp.callback(req->b, 0, NULL); + } +} + +static void __dispatch_app_resume(aul_request_h req) +{ + __invoke_aul_handler(AUL_RESUME, NULL); +} + +static void __dispatch_app_term_by_pid(aul_request_h req) +{ + __invoke_aul_handler(AUL_TERMINATE, NULL); +} + +static void __dispatch_app_term_bgapp_by_pid(aul_request_h req) +{ + __invoke_aul_handler(AUL_TERMINATE_BGAPP, NULL); +} + +static void __dispatch_app_term_req_by_pid(aul_request_h req) +{ + if (__context.subapp.is_subapp) { + if (__context.subapp.callback) + __context.subapp.callback(__context.subapp.user_data); + } else { + __invoke_aul_handler(AUL_TERMINATE, NULL); + } +} + +static void __dispatch_app_result(aul_request_h req) +{ + const char *pid_str; + int pid = -1; + + pid_str = bundle_get_val(req->b, AUL_K_CALLEE_PID); + if (pid_str) + pid = atoi(pid_str); + + app_result(req->cmd, req->b, pid); +} + +static void __dispatch_app_key_event(aul_request_h req) +{ + app_key_event(req->b); +} + +static void __dispatch_app_pause_by_pid(aul_request_h req) +{ + __invoke_aul_handler(AUL_PAUSE, req->b); +} + +static void __dispatch_app_com_message(aul_request_h req) +{ + app_com_recv(req->b); +} + +static void __dispatch_app_wake(aul_request_h req) +{ + __invoke_aul_handler(AUL_WAKE, req->b); +} + +static void __dispatch_app_suspend(aul_request_h req) +{ + __invoke_aul_handler(AUL_SUSPEND, req->b); +} + +static void __dispatch_widget_get_content(aul_request_h req) +{ + const char *widget_id; + const char *instance_id; + const char *content_info; + int fds[2] = { 0, }; + int r; + + r = aul_sock_recv_reply_sock_fd(req->clifd, &fds, 1); + if (r < 0) { + _E("Failed to receive fds"); + return; + } + + widget_id = bundle_get_val(req->b, AUL_K_WIDGET_ID); + if (!widget_id) { + _E("Failed to get widget ID"); + aul_sock_send_raw_with_fd(fds[0], -EINVAL, 0, 0, + AUL_SOCK_NOREPLY); + return; + } + + instance_id = bundle_get_val(req->b, AUL_K_WIDGET_INSTANCE_ID); + if (!instance_id) { + _E("Failed to get instance ID"); + aul_sock_send_raw_with_fd(fds[0], -EINVAL, 0, 0, + AUL_SOCK_NOREPLY); + return; + } + + __invoke_aul_handler(AUL_WIDGET_CONTENT, req->b); + + content_info = bundle_get_val(req->b, AUL_K_WIDGET_CONTENT_INFO); + if (content_info) { + r = aul_sock_send_raw_with_fd(fds[0], 0, + (unsigned char *)content_info, + strlen(content_info) + 1, AUL_SOCK_NOREPLY); + } else { + r = aul_sock_send_raw_with_fd(fds[0], -ENOENT, + NULL, 0, AUL_SOCK_NOREPLY); + } + + if (r < 0) { + _E("Failed to send content info. fd(%d), result(%d)", + fds[0], r); + } +} + +static void __dispatch_app_update_requested(aul_request_h req) +{ + __invoke_aul_handler(AUL_UPDATE_REQUESTED, req->b); +} + +static void __dispatch_watchdog_ping(aul_request_h req) +{ + const char *start_time; + struct timeval tv; + + gettimeofday(&tv, NULL); + start_time = bundle_get_val(req->b, AUL_K_STARTTIME); + _W("[__WATCHDOG__] Start time: %s, response time: %ld/%ld", + start_time ? start_time : "Unknown", + tv.tv_sec, tv.tv_usec); +} + +static dispatcher __dispatcher[] = { + [APP_START] = __dispatch_app_start, + [APP_START_RES] = __dispatch_app_start, + [APP_START_ASYNC] = __dispatch_app_start, + [APP_START_RES_ASYNC] = __dispatch_app_start, + [APP_OPEN] = __dispatch_app_resume, + [APP_RESUME] = __dispatch_app_resume, + [APP_RESUME_BY_PID] = __dispatch_app_resume, + [APP_TERM_BY_PID] = __dispatch_app_term_by_pid, + [APP_TERM_BY_PID_ASYNC] = __dispatch_app_term_by_pid, + [APP_TERM_BY_PID_SYNC] = __dispatch_app_term_by_pid, + [APP_TERM_BGAPP_BY_PID] = __dispatch_app_term_bgapp_by_pid, + [APP_TERM_REQ_BY_PID] = __dispatch_app_term_req_by_pid, + [APP_RESULT] = __dispatch_app_result, + [APP_CANCEL] = __dispatch_app_result, + [APP_KEY_EVENT] = __dispatch_app_key_event, + [APP_PAUSE_BY_PID] = __dispatch_app_pause_by_pid, + [APP_COM_MESSAGE] = __dispatch_app_com_message, + [APP_WAKE] = __dispatch_app_wake, + [APP_SUSPEND] = __dispatch_app_suspend, + [WIDGET_GET_CONTENT] = __dispatch_widget_get_content, + [APP_UPDATE_REQUESTED] = __dispatch_app_update_requested, + [WATCHDOG_PING] = __dispatch_watchdog_ping, +}; + +static gboolean __aul_launch_handler(GIOChannel *io, GIOCondition condition, + gpointer data) +{ + int fd = g_io_channel_unix_get_fd(io); + struct aul_request_s req = { 0, }; + app_pkt_t *pkt; + bundle *b = NULL; + int clifd; + struct ucred cr; + int r; + + pkt = aul_sock_recv_pkt(fd, &clifd, &cr); + if (!pkt) { + _E("Failed to receive the packet"); + return G_SOURCE_CONTINUE; + } + + if (pkt->cmd != WIDGET_GET_CONTENT) { + if (pkt->opt & AUL_SOCK_NOREPLY) { + close(clifd); + clifd = -1; + } else { + r = aul_sock_send_result(clifd, 0); + if (r < 0) { + _E("Failed to send result. cmd(%s:%d)", + aul_cmd_convert_to_string(pkt->cmd), + pkt->cmd); + free(pkt); + return G_SOURCE_CONTINUE;; + } + } + } + + if (pkt->opt & AUL_SOCK_BUNDLE) { + b = bundle_decode(pkt->data, pkt->len); + if (!b) { + _E("Failed to decode the packet"); + free(pkt); + return G_SOURCE_CONTINUE; + } + } + + req.cmd = pkt->cmd; + req.clifd = clifd; + req.b = b; + + free(pkt); + + if (req.cmd >= APP_START && req.cmd < ARRAY_SIZE(__dispatcher) && + __dispatcher[req.cmd]) { + _W("Command(%s:%d)", + aul_cmd_convert_to_string(req.cmd), req.cmd); + __dispatcher[req.cmd](&req); + } else { + _E("Command(%s:%d) is not available", + aul_cmd_convert_to_string(req.cmd), req.cmd); + } + + if (req.b) + bundle_free(req.b); + + return G_SOURCE_CONTINUE; +} + +static void __finalize_context(void) +{ + if (__context.source) { + g_source_remove(__context.source); + __context.source = 0; + } + + if (__context.io) { + g_io_channel_unref(__context.io); + __context.io = NULL; + } +} + +static int __initialize_context(void) +{ + GIOCondition cond = G_IO_IN | G_IO_PRI | G_IO_HUP | G_IO_ERR; + int fd; + + fd = aul_initialize(); + if (fd < 0) { + _E("Failed to initialize aul"); + return fd; + } + + __context.io = g_io_channel_unix_new(fd); + if (!__context.io) { + _E("Failed to create gio channel"); + __finalize_context(); + return AUL_R_ERROR; + } + + __context.source = g_io_add_watch(__context.io, + cond, __aul_launch_handler, NULL); + if (!__context.source) { + _E("Failed to add gio watch"); + __finalize_context(); + return AUL_R_ERROR; + } + + return AUL_R_OK; +} + +API int aul_launch_init(aul_handler_fn callback, void *user_data) +{ + if (callback) { + __context.aul.callback = callback; + __context.aul.user_data = user_data; + } + + return __initialize_context(); +} + +API int aul_launch_fini(void) +{ + __finalize_context(); + return AUL_R_OK; +} + +static gboolean __app_start_cb(gpointer data) +{ + bundle *b = (bundle *)data; + struct aul_request_s req = { + .cmd = APP_START, + .clifd = 0, + .b = b + }; + + __dispatch_app_start(&req); + + if (req.b) + bundle_free(req.b); + + return G_SOURCE_REMOVE; +} + +API int aul_launch_argv_handler(int argc, char **argv) +{ + bundle *b; + + if (!aul_is_initialized()) { + _E("AUL is not initialized"); + return AUL_R_ENOINIT; + } + + b = bundle_import_from_argv(argc, argv); + if (!b) + _E("Bundle is nullptr"); + + if (!g_idle_add_full(G_PRIORITY_HIGH, __app_start_cb, b, NULL)) { + _E("Failed to add idler"); + return AUL_R_ERROR; + } + + return AUL_R_OK; +} + +API int aul_launch_local(bundle *b) +{ + if (!aul_is_initialized()) { + _E("AUL is not initialized"); + return AUL_R_ENOINIT; + } + + if (!b) + _E("Bundle is nullptr"); + + if (!g_idle_add(__app_start_cb, b)) { + _E("Failed to add idler"); + return AUL_R_ERROR; + } + + return AUL_R_OK; +} + +int aul_resume_local(void) +{ + if (!aul_is_initialized()) { + _E("AUL is not initialized"); + return AUL_R_ENOINIT; + } + + __dispatch_app_resume(NULL); + + return AUL_R_OK; +} + +API int aul_set_subapp(subapp_fn callback, void *user_data) +{ + __context.subapp.is_subapp = true; + __context.subapp.callback = callback; + __context.subapp.user_data = user_data; + + return AUL_R_OK; +} + +API int aul_is_subapp(void) +{ + return (int)__context.subapp.is_subapp; +} + +API int aul_set_data_control_provider_cb(data_control_provider_handler_fn cb) +{ + __context.dcp.callback = cb; + + return AUL_R_OK; +} + +API int aul_unset_data_control_provider_cb(void) +{ + __context.dcp.callback = NULL; + + return AUL_R_OK; +} diff --git a/src/aul_sock.c b/src/aul_sock.c index dd2f4cd..f2c2c01 100644 --- a/src/aul_sock.c +++ b/src/aul_sock.c @@ -1034,3 +1034,27 @@ API int aul_sock_destroy_server(int fd) return 0; } + +API int aul_sock_send_result(int fd, int res) +{ + int r; + + if (fd < 0) { + _E("Invalid parameter"); + return -EINVAL; + } + + r = send(fd, &res, sizeof(res), MSG_NOSIGNAL); + if (r < 0) { + _E("Failed to send result. fd(%d), errno(%d)", + fd, errno); + if (errno == EPIPE) { + _E("EPIPE error"); + close(fd); + return r; + } + } + close(fd); + + return 0; +} diff --git a/src/key.c b/src/key.c index 71a26ae..1eb09d3 100644 --- a/src/key.c +++ b/src/key.c @@ -15,99 +15,28 @@ */ #define _GNU_SOURCE -#include -#include -#include -#include -#include #include #include "aul.h" #include "aul_api.h" -#include "menu_db_util.h" -#include "aul_sock.h" -#include "aul_util.h" #include "launch.h" - -static int (*_aul_key_handler) (bundle *kb, void *data) = NULL; -static void *_aul_key_data = NULL; - -extern GSourceFuncs funcs; - int app_key_event(bundle *kb) { - if (_aul_key_handler) - _aul_key_handler(kb, _aul_key_data); - return 0; -} - -int aul_register_key_init_callback( - int (*aul_handler) (bundle *, void *), void *data) -{ - /* Save start handler function in static var */ - _aul_key_handler = aul_handler; - _aul_key_data = data; return 0; } -API int aul_key_init(int (*aul_handler) (bundle *, void *), void *data) +API int aul_key_init(int (*aul_handler)(bundle *, void *), void *data) { - int fd; - GPollFD *gpollfd; - GSource *src; - int ret; - - if (aul_handler != NULL) - aul_register_key_init_callback(aul_handler, data); - - fd = aul_initialize(); - if (fd < 0) - return fd; - - src = g_source_new(&funcs, sizeof(GSource)); - - gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); - gpollfd->events = POLLIN; - gpollfd->fd = fd; - - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, (GSourceFunc) __aul_glib_handler, - (gpointer) gpollfd, NULL); - g_source_set_priority(src, G_PRIORITY_LOW); - - ret = g_source_attach(src, NULL); - if (ret == 0) - return AUL_R_ERROR; - - g_source_unref(src); - return AUL_R_OK; } API int aul_key_reserve() { - bundle *kb; - int ret; - - kb = bundle_create(); - ret = app_send_cmd(AUL_UTIL_PID, APP_KEY_RESERVE, kb); - bundle_free(kb); - - return ret; + return AUL_R_OK; } API int aul_key_release() { - bundle *kb; - int ret; - - kb = bundle_create(); - ret = app_send_cmd(AUL_UTIL_PID, APP_KEY_RELEASE, kb); - bundle_free(kb); - - return ret; + return AUL_R_OK; } - - - diff --git a/src/launch.c b/src/launch.c index 188c24b..49794c9 100755 --- a/src/launch.c +++ b/src/launch.c @@ -48,92 +48,14 @@ static void *__window_object = NULL; static void *__bg_object = NULL; static void *__conformant_object = NULL; -static int (*_aul_handler) (aul_type type, bundle *kb, void *data) = NULL; -static void *_aul_data; - -static int app_resume(); -static int app_terminate(); static void __clear_internal_key(bundle *kb); static inline void __set_stime(bundle *kb); -static int __app_start_internal(gpointer data); -static int __app_launch_local(bundle *b); -static int __send_result_to_launchpad(int fd, int res); - -static data_control_provider_handler_fn __dc_handler = NULL; -extern int aul_launch_fini(); int aul_is_initialized() { return aul_initialized; } -int __call_aul_handler(aul_type type, bundle *kb) -{ - if (_aul_handler) - _aul_handler(type, kb, _aul_data); - return 0; -} - -int app_start(bundle *kb) -{ - const char *str = NULL; - - _app_start_res_prepare(kb); - __call_aul_handler(AUL_START, kb); - /* Handle the DataControl callback */ - str = bundle_get_val(kb, AUL_K_DATA_CONTROL_TYPE); - if (str != NULL && strcmp(str, "CORE") == 0) { - if (__dc_handler != NULL) - __dc_handler(kb, 0, NULL); /* bundle, request_id, data */ - } - - return 0; -} - -static int app_resume() -{ - __call_aul_handler(AUL_RESUME, NULL); - return 0; -} - -static int app_terminate() -{ - __call_aul_handler(AUL_TERMINATE, NULL); - return 0; -} - -static int bgapp_terminate(void) -{ - __call_aul_handler(AUL_TERMINATE_BGAPP, NULL); - return 0; -} - -static int app_pause(void) -{ - __call_aul_handler(AUL_PAUSE, NULL); - return 0; -} - -static int app_prepare_to_suspend(bundle *kb) -{ - _D("[__SUSPEND__]"); - __call_aul_handler(AUL_SUSPEND, kb); - return 0; -} - -static int app_prepare_to_wake(bundle *kb) -{ - _D("[__WAKE__]"); - __call_aul_handler(AUL_WAKE, kb); - return 0; -} - -static void app_update_requested(void) -{ - _D("[UPDATE REQUESTED]"); - __call_aul_handler(AUL_UPDATE_REQUESTED, NULL); -} - static int __send_cmd_for_uid_opt(int pid, uid_t uid, int cmd, bundle *kb, int opt) { int res; @@ -253,41 +175,6 @@ static inline void __set_stime(bundle *kb) bundle_add(kb, AUL_K_STARTTIME, tmp); } -static int __app_start_internal(gpointer data) -{ - bundle *kb; - - kb = (bundle *) data; - app_start(kb); - bundle_free(kb); - - return 0; -} - -static int __app_launch_local(bundle *b) -{ - if (!aul_is_initialized()) - return AUL_R_ENOINIT; - - if (b == NULL) - _E("bundle for APP_START is NULL"); - - if (g_idle_add(__app_start_internal, b) > 0) - return AUL_R_OK; - else - return AUL_R_ERROR; -} - -static int __app_resume_local() -{ - if (!aul_is_initialized()) - return AUL_R_ENOINIT; - - app_resume(); - - return 0; -} - /** * @brief start caller with kb * @return callee's pid @@ -343,13 +230,13 @@ int app_request_to_launchpad_for_uid(int cmd, const char *appid, bundle *kb, uid case WIDGET_UPDATE: case APP_START_RES_ASYNC: b = bundle_dup(kb); - ret = __app_launch_local(b); + ret = aul_launch_local(b); break; case APP_OPEN: case APP_RESUME: case APP_RESUME_BY_PID: case APP_RESUME_BY_PID_ASYNC: - ret = __app_resume_local(); + ret = aul_resume_local(); break; default: _E("no support packet"); @@ -366,236 +253,6 @@ int app_request_to_launchpad_for_uid(int cmd, const char *appid, bundle *kb, uid return ret; } -static int __send_result_to_launchpad(int fd, int res) -{ - if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) { - if (errno == EPIPE) { - _E("send failed due to EPIPE."); - close(fd); - return -1; - } - _E("send fail to client"); - } - close(fd); - return 0; -} - -static int widget_get_content(int clifd, bundle *kb) -{ - int ret; - int fd[2] = { 0, }; - char *widget_id = NULL; - char *instance_id = NULL; - char *content_info = NULL; - - bundle_get_str(kb, AUL_K_WIDGET_ID, &widget_id); - bundle_get_str(kb, AUL_K_WIDGET_INSTANCE_ID, &instance_id); - - ret = aul_sock_recv_reply_sock_fd(clifd, &fd, 1); - if (ret < 0) { - _E("failed to recv sock fd"); - return ret; - } - - if (!widget_id || !instance_id) { - aul_sock_send_raw_with_fd(fd[0], -EINVAL, 0, 0, AUL_SOCK_NOREPLY); - return 0; - } - - __call_aul_handler(AUL_WIDGET_CONTENT, kb); - - bundle_get_str(kb, AUL_K_WIDGET_CONTENT_INFO, &content_info); - if (content_info) { - ret = aul_sock_send_raw_with_fd(fd[0], 0, - (unsigned char *)content_info, - strlen(content_info) + 1, AUL_SOCK_NOREPLY); - } else { - ret = aul_sock_send_raw_with_fd(fd[0], -ENOENT, - NULL, 0, AUL_SOCK_NOREPLY); - } - - if (ret < 0) - _E("failed to send content %d (%d)", fd[0], ret); - - return ret; -} - -/** - * @brief caller & callee's sock handler - */ -int aul_sock_handler(int fd) -{ - app_pkt_t *pkt; - bundle *kbundle = NULL; - int clifd; - struct ucred cr; - const char *pid_str; - const char *start_time; - struct timeval tv; - int pid = -1; - int ret; - - if ((pkt = aul_sock_recv_pkt(fd, &clifd, &cr)) == NULL) { - _E("recv error"); - return -1; - } - - if (pkt->cmd != WIDGET_GET_CONTENT) { - if (pkt->opt & AUL_SOCK_NOREPLY) { - close(clifd); - } else { - ret = __send_result_to_launchpad(clifd, 0); - if (ret < 0) { - _E("Failed to send the result. cmd(%s:%d)", - aul_cmd_convert_to_string(pkt->cmd), - pkt->cmd); - free(pkt); - return -1; - } - } - } - - if (pkt->opt & AUL_SOCK_BUNDLE) { - kbundle = bundle_decode(pkt->data, pkt->len); - if (kbundle == NULL) - goto err; - } - - switch (pkt->cmd) { - case APP_START: /* run in callee */ - case APP_START_RES: - case APP_START_ASYNC: - case APP_START_RES_ASYNC: - app_start(kbundle); - break; - - case APP_OPEN: /* run in callee */ - case APP_RESUME: - case APP_RESUME_BY_PID: - app_resume(); - break; - - case APP_TERM_BY_PID: /* run in callee */ - case APP_TERM_BY_PID_ASYNC: - case APP_TERM_BY_PID_SYNC: - app_terminate(); - break; - - case APP_TERM_BGAPP_BY_PID: - bgapp_terminate(); - break; - - case APP_TERM_REQ_BY_PID: /* run in callee */ - app_subapp_terminate_request(); - break; - - case APP_RESULT: /* run in caller */ - case APP_CANCEL: - pid_str = bundle_get_val(kbundle, AUL_K_CALLEE_PID); - if (pid_str) - pid = atoi(pid_str); - - app_result(pkt->cmd, kbundle, pid); - break; - - case APP_KEY_EVENT: /* run in caller */ - app_key_event(kbundle); - break; - - case APP_PAUSE_BY_PID: - app_pause(); - break; - case APP_COM_MESSAGE: - app_com_recv(kbundle); - break; - case APP_WAKE: - app_prepare_to_wake(kbundle); - break; - case APP_SUSPEND: - app_prepare_to_suspend(kbundle); - break; - case WIDGET_GET_CONTENT: - widget_get_content(clifd, kbundle); - break; - case APP_UPDATE_REQUESTED: - app_update_requested(); - break; - case WATCHDOG_PING: - gettimeofday(&tv, NULL); - start_time = bundle_get_val(kbundle, AUL_K_STARTTIME); - _W("[__WATCHDOG__] Start time: %s, response time: %ld/%ld", - start_time ? start_time : "Unknown", - tv.tv_sec, tv.tv_usec); - break; - default: - _E("no support packet"); - } - - if (kbundle) - bundle_free(kbundle); - - free(pkt); - return 0; - -err: - free(pkt); - return -1; -} - -int aul_make_bundle_from_argv(int argc, char **argv, bundle **kb) -{ - int ac = 1; - - char *buf = NULL; - - *kb = bundle_create(); - if (*kb == NULL) - return AUL_R_ERROR; - - if (argv == NULL) - return AUL_R_OK; - - if ((argv != NULL) && (argv[0] != NULL)) { - buf = strdup(argv[0]); - if (NULL == buf) { - _E("Malloc failed"); - return AUL_R_ERROR; - } - - bundle_add(*kb, AUL_K_ARGV0, buf); - } - if (buf) { /*Prevent FIX: ID 38717 */ - free(buf); - buf = NULL; - } - - while (ac < argc) { - if (ac + 1 == argc) { - if (bundle_add(*kb, argv[ac], "") < 0) { - _E("bundle add error pos - %d", ac); - return AUL_R_ECANCELED; - } - } else { - if (bundle_add(*kb, argv[ac], argv[ac + 1]) < 0) { - _E("bundle add error pos - %d", ac); - return AUL_R_ECANCELED; - } - } - ac = ac + 2; - } - - return AUL_R_OK; -} - -int aul_register_init_callback( - int (*aul_handler) (aul_type type, bundle *, void *), void *data) -{ - /* Save start handler function in static var */ - _aul_handler = aul_handler; - _aul_data = data; - return 0; -} - static int __get_preinit_fd(void) { int fd = -1; @@ -884,18 +541,6 @@ API int aul_kill_pid(int pid) return ret; } -API int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler) -{ - __dc_handler = handler; - return 0; -} - -API int aul_unset_data_control_provider_cb(void) -{ - __dc_handler = NULL; - return 0; -} - API void aul_set_preinit_window(void *evas_object) { __window_object = evas_object; diff --git a/src/launch_glib.c b/src/launch_glib.c deleted file mode 100644 index 7d3d603..0000000 --- a/src/launch_glib.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include - -#include "aul.h" -#include "aul_api.h" -#include "aul_util.h" -#include "launch.h" - -static GSource *src; - -static gboolean __aul_glib_check(GSource *src); -static gboolean __aul_glib_dispatch(GSource *src, GSourceFunc callback, - gpointer data); -static gboolean __aul_glib_prepare(GSource *src, gint *timeout); -static gboolean __app_start_internal(gpointer data); - -static void __aul_glib_finalize(GSource *src) -{ - GSList *fd_list; - GPollFD *tmp; - - fd_list = src->poll_fds; - do { - tmp = (GPollFD *) fd_list->data; - g_free(tmp); - - fd_list = fd_list->next; - } while (fd_list); - - return; -} - -static gboolean __aul_glib_check(GSource *src) -{ - GSList *fd_list; - GPollFD *tmp; - - fd_list = src->poll_fds; - do { - tmp = (GPollFD *) fd_list->data; - if ((tmp->revents & (POLLIN | POLLPRI))) - return TRUE; - fd_list = fd_list->next; - } while (fd_list); - - return FALSE; -} - -static gboolean __aul_glib_dispatch(GSource *src, GSourceFunc callback, - gpointer data) -{ - callback(data); - return TRUE; -} - -static gboolean __aul_glib_prepare(GSource *src, gint *timeout) -{ - return FALSE; -} - -GSourceFuncs funcs = { - .prepare = __aul_glib_prepare, - .check = __aul_glib_check, - .dispatch = __aul_glib_dispatch, - .finalize = __aul_glib_finalize -}; - -gboolean __aul_glib_handler(gpointer data) -{ - GPollFD *gpollfd = (GPollFD *) data; - aul_sock_handler(gpollfd->fd); - return TRUE; -} - -static gboolean __app_start_internal(gpointer data) -{ - bundle *kb; - - kb = (bundle *) data; - app_start(kb); - bundle_free(kb); - - return 0; -} - -API int aul_launch_init( - int (*aul_handler) (aul_type type, bundle *, void *), void *data) -{ - int fd; - GPollFD *gpollfd; - int ret; - - if (aul_handler != NULL) - aul_register_init_callback(aul_handler, data); - - fd = aul_initialize(); - if (fd < 0) - return fd; - - src = g_source_new(&funcs, sizeof(GSource)); - - gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); - gpollfd->events = POLLIN; - gpollfd->fd = fd; - - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, (GSourceFunc) __aul_glib_handler, - (gpointer) gpollfd, NULL); - g_source_set_priority(src, G_PRIORITY_DEFAULT); - - ret = g_source_attach(src, NULL); - if (ret == 0) - return AUL_R_ERROR; - - g_source_unref(src); - - return AUL_R_OK; -} - -API int aul_launch_fini() -{ - if (src) { - g_source_destroy(src); - src = NULL; - } - - return AUL_R_OK; -} - -API int aul_launch_argv_handler(int argc, char **argv) -{ - bundle *b; - - if (!aul_is_initialized()) - return AUL_R_ENOINIT; - - b = bundle_import_from_argv(argc, argv); - if (b == NULL) - _E("bundle for APP_START is NULL"); - - if (g_idle_add_full(G_PRIORITY_HIGH, __app_start_internal, b, NULL) > 0) - return AUL_R_OK; - else - return AUL_R_ERROR; -} - -API int aul_launch_local(bundle *b) -{ - if (!aul_is_initialized()) - return AUL_R_ENOINIT; - - if (b == NULL) - _E("bundle for APP_START is NULL"); - - if (g_idle_add(__app_start_internal, b) > 0) - return AUL_R_OK; - else - return AUL_R_ERROR; -} - diff --git a/src/launch_with_result.c b/src/launch_with_result.c index de9055b..f4c39e8 100644 --- a/src/launch_with_result.c +++ b/src/launch_with_result.c @@ -38,11 +38,6 @@ typedef struct _app_resultcb_info_t { void *caller_data; } app_resultcb_info_t; -static int latest_caller_pid = -1; -static int is_subapp = 0; -static subapp_fn subapp_cb = NULL; -static void *subapp_data = NULL; - static pthread_mutex_t __aul_mutex = PTHREAD_MUTEX_INITIALIZER; static GList *__resultcb_list; @@ -225,63 +220,6 @@ end: return pid; } -#ifdef ACTIVATE_PREEMPT_FEATURE -static int __send_to_cancel(int pid) -{ - /* Say "Your result request is cancel!" to caller */ - bundle *kb; - int ret; - char tmp_pid[MAX_PID_STR_BUFSZ]; - - kb = bundle_create(); - if (kb == NULL) - return AUL_R_ERROR; - bundle_add(kb, AUL_K_SEND_RESULT, "1"); - - snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", pid); - bundle_add(kb, AUL_K_CALLER_PID, tmp_pid); - - ret = app_send_cmd(LAUNCHPAD_PID, APP_CANCEL, kb); - - bundle_free(kb); - return ret; -} -#else -static int __send_to_cancel(int pid) -{ - return 0; -} -#endif - -int _app_start_res_prepare(bundle *kb) -{ - int pid; - const char* str = NULL; - - if (bundle_get_val(kb, AUL_K_WAIT_RESULT) == NULL) - return 0; - - str = bundle_get_val(kb, AUL_K_NO_CANCEL); - if (str && strncmp("1", str, 1) == 0) { - _D("no cancel"); - return 0; - } - - if ((pid = __get_caller_pid(kb)) < 0) { - _E("caller pid is not valid"); - return -1; - } - /* If previous caller is still waiting result, - send cancel packet to the caller. */ - if (latest_caller_pid != -1) - __send_to_cancel(latest_caller_pid); - - latest_caller_pid = pid; - _D("result msg prepare done"); - - return 0; -} - int app_result(int cmd, bundle *kb, int launched_pid) { switch (cmd) { @@ -528,31 +466,9 @@ int aul_send_result(bundle *kb, int is_cancel) (is_cancel == 1) ? APP_CANCEL : APP_RESULT, kb); _D("app_send_cmd_with_noreply : %d", ret); - if (latest_caller_pid == pid) - latest_caller_pid = -1; - return ret; } -int app_subapp_terminate_request() -{ - if (is_subapp) - subapp_cb(subapp_data); - else - __call_aul_handler(AUL_TERMINATE, NULL); - - return 0; -} - -API int aul_set_subapp(subapp_fn cb, void *data) -{ - is_subapp = 1; - subapp_cb = cb; - subapp_data = data; - - return 0; -} - API int aul_subapp_terminate_request_pid(int pid) { char pid_str[MAX_PID_STR_BUFSZ]; @@ -581,11 +497,6 @@ API int aul_subapp_terminate_request_pid(int pid) return ret; } -API int aul_is_subapp() -{ - return is_subapp; -} - API int aul_add_caller_cb(int pid, void (*caller_cb)(int, void *), void *data) {