From: Hawnkyu Jhun Date: Tue, 18 Apr 2017 14:32:41 +0000 (+0900) Subject: Refactor aul_listen_app_status API X-Git-Tag: accepted/tizen/unified/20170421.113814~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5aedc005ea0ad8a60382c961616b7153a9671e7;p=platform%2Fcore%2Fappfw%2Faul-1.git Refactor aul_listen_app_status API The APP_LISTEN_STATUS and APP_STATUS_NOTIFICATION are deleted. The aul_listen_app_status API uses the app com. This patch changes the callback type to provide more information. Change-Id: I68272b701d4c7eaf9c64bc67df5d35b3753ad456 Signed-off-by: Hawnkyu Jhun --- diff --git a/include/aul.h b/include/aul.h index f57be06..118c0e7 100644 --- a/include/aul.h +++ b/include/aul.h @@ -2983,13 +2983,21 @@ int aul_enable_alias_info(const char *appid); */ int aul_disable_alias_info(const char *appid); -/* +/** + * This API is only for Appfw internally. + */ +typedef int (*app_status_cb)(aul_app_info *info, int ctx_status, void *data); + +/** + * This API is only for Appfw internally. + */ +typedef struct status_listen_s *status_listen_h; + +/** * This API is only for Appfw internally. */ -API int aul_listen_app_status(const char *appid, - int (*aul_handler)(const char *appid, const char *pkgid, - int pid, int status, int is_subapp, void *data), - void *data); +int aul_listen_app_status(const char *appid, app_status_cb callback, + void *data, status_listen_h *handle); /* * This API is only for Appfw internally. diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 455a433..07271f7 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -101,28 +101,26 @@ enum app_cmd { APP_RESUME_BY_PID_ASYNC = 72, APP_SET_ALIAS_APPID = 73, APP_UNSET_ALIAS_APPID = 74, - APP_LISTEN_STATUS = 75, - APP_STATUS_NOTIFICATION = 76, - APP_ENABLE_ALIAS_INFO = 77, - APP_DISABLE_ALIAS_INFO = 78, - APP_GROUP_ACTIVATE_ABOVE = 79, - ADD_APP_SCREEN = 80, + APP_ENABLE_ALIAS_INFO = 75, + APP_DISABLE_ALIAS_INFO = 76, + APP_GROUP_ACTIVATE_ABOVE = 77, + ADD_APP_SCREEN = 78, + REMOVE_APP_SCREEN = 79, + APP_UPDATE_REQUESTED = 80, - REMOVE_APP_SCREEN = 81, - APP_UPDATE_REQUESTED = 82, - ADD_SCREEN_VIEWER = 83, - REMOVE_SCREEN_VIEWER = 84, - LAUNCHPAD_LAUNCH_SIGNAL = 85, - APP_RUNNING_INSTANCE_INFO = 86, - APP_GET_INSTANCE_ID_BYPID = 87, - APP_SET_CACHE = 88, - APP_GET_APPID_FROM_CACHE = 89, - APP_INVALIDATE_CACHE = 90, + ADD_SCREEN_VIEWER = 81, + REMOVE_SCREEN_VIEWER = 82, + LAUNCHPAD_LAUNCH_SIGNAL = 83, + APP_RUNNING_INSTANCE_INFO = 84, + APP_GET_INSTANCE_ID_BYPID = 85, + APP_SET_CACHE = 86, + APP_GET_APPID_FROM_CACHE = 87, + APP_INVALIDATE_CACHE = 88, + APP_STARTUP_SIGNAL = 89, + APP_WINDOW_ATTACH = 90, - APP_STARTUP_SIGNAL = 91, - APP_WINDOW_ATTACH = 92, - APP_WINDOW_DETACH = 93, - APP_START_RES_ASYNC = 94, + APP_WINDOW_DETACH = 91, + APP_START_RES_ASYNC = 92, APP_CMD_MAX }; diff --git a/include/launch.h b/include/launch.h index 04893a2..8cd5f83 100644 --- a/include/launch.h +++ b/include/launch.h @@ -48,7 +48,6 @@ int __call_aul_handler(aul_type type, bundle *kb); gboolean __aul_glib_handler(gpointer data); int app_com_recv(bundle *b); -void app_status_event(bundle *kb); 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, diff --git a/src/launch.c b/src/launch.c index e57f92e..f1d6057 100755 --- a/src/launch.c +++ b/src/launch.c @@ -499,9 +499,6 @@ int aul_sock_handler(int fd) case APP_SUSPEND: app_prepare_to_suspend(kbundle); break; - case APP_STATUS_NOTIFICATION: - app_status_event(kbundle); - break; case WIDGET_GET_CONTENT: widget_get_content(clifd, kbundle); break; diff --git a/src/status.c b/src/status.c index ab1f0dd..4439ff3 100644 --- a/src/status.c +++ b/src/status.c @@ -26,18 +26,20 @@ #include "aul_sock.h" #include "aul_api.h" #include "launch.h" +#include "aul_app_com.h" typedef struct _app_status_cb_info_t { int (*handler)(int status, void *data); void *data; } app_status_cb_info_t; -static int (*_aul_status_listen_handler)(const char *appid, const char *pkgid, - int pid, int status, int is_sub_app, void *data); -static void *_aul_status_listen_data; +struct status_listen_s { + aul_app_com_connection_h conn; + app_status_cb callback; + void *user_data; +}; static int app_status = STATUS_LAUNCHING; -extern int aul_launch_fini(); static GList *app_status_cb_list; API int aul_status_update(int status) @@ -244,79 +246,103 @@ API int aul_set_process_group(int owner_pid, int child_pid) return ret; } -void app_status_event(bundle *kb) +static int __app_status_event_cb(const char *endpoint, aul_app_com_result_e res, + bundle *envelope, void *user_data) { - const char *appid; - const char *pkgid; + struct status_listen_s *listen = (struct status_listen_s *)user_data; + aul_app_info app_info = { 0, }; const char *val; - int pid = -1; - int status = -1; - int is_subapp = -1; + int context_status; - if (kb == NULL) { - _E("Invalid parameter"); - return; + if (listen == NULL) { + _E("Critical error"); + return -1; + } + + bundle_get_str(envelope, AUL_K_APPID, &app_info.appid); + if (app_info.appid == NULL) { + _E("Failed to get application id"); + return -1; + } + + bundle_get_str(envelope, AUL_K_PKGID, &app_info.pkgid); + if (app_info.pkgid == NULL) { + _E("Failed to get package id"); + return -1; + } + + bundle_get_str(envelope, AUL_K_EXEC, &app_info.app_path); + if (app_info.app_path == NULL) { + _E("Failed to get app path"); + return -1; + } + + bundle_get_str(envelope, AUL_K_INSTANCE_ID, &app_info.instance_id); + + val = bundle_get_val(envelope, AUL_K_PID); + if (val == NULL) { + _E("Failed to get pid"); + return -1; + } + app_info.pid = atoi(val); + + val = bundle_get_val(envelope, AUL_K_STATUS); + if (val == NULL) { + _E("Failed to get status"); + return -1; } + app_info.status = atoi(val); - appid = bundle_get_val(kb, AUL_K_APPID); - pkgid = bundle_get_val(kb, AUL_K_PKGID); - val = bundle_get_val(kb, AUL_K_PID); - if (val) - pid = atoi(val); - val = bundle_get_val(kb, AUL_K_STATUS); - if (val) - status = atoi(val); - val = bundle_get_val(kb, AUL_K_IS_SUBAPP); - if (val) - is_subapp = atoi(val); - - if (appid == NULL || pkgid == NULL || - pid == -1 || status == -1 || is_subapp == -1) { - _E("Failed to get app status info"); - return; + val = bundle_get_val(envelope, AUL_K_IS_SUBAPP); + if (val == NULL) { + _E("Failed to get is_subapp"); + return -1; } + app_info.is_sub_app = atoi(val); - if (_aul_status_listen_handler) { - _aul_status_listen_handler(appid, pkgid, pid, status, - is_subapp, _aul_status_listen_data); + val = bundle_get_val(envelope, "__CONTEXT_STATUS__"); + if (val == NULL) { + _E("Failed to get context status"); + return -1; } + context_status = atoi(val); + + listen->callback(&app_info, context_status, listen->user_data); + + return 0; } -API int aul_listen_app_status(const char *appid, - int (*aul_handler)(const char *appid, const char *pkgid, - int pid, int status, int is_subapp, void *data), - void *data) +API int aul_listen_app_status(const char *appid, app_status_cb callback, + void *data, status_listen_h *handle) { - int ret; - bundle *kb; - int initialized = 0; + struct status_listen_s *listen; + char endpoint[128]; - if (appid == NULL || aul_handler == NULL) { + if (appid == NULL || callback == NULL || handle == NULL) { _E("Invalid parameter"); return AUL_R_EINVAL; } - if (!aul_is_initialized()) { - if (aul_launch_init(NULL, NULL) < 0) - return AUL_R_ENOINIT; - initialized = 1; + listen = calloc(1, sizeof(struct status_listen_s)); + if (listen == NULL) { + _E("Out of memory"); + return AUL_R_ERROR; } - kb = bundle_create(); - if (kb == NULL) { - _E("out of memory"); - if (initialized) - aul_launch_fini(); + snprintf(endpoint, sizeof(endpoint), "app_status_event:%s:%d", + appid, getuid()); + aul_app_com_create(endpoint, NULL, __app_status_event_cb, + listen, &listen->conn); + if (listen->conn == NULL) { + _E("Failed to create app com"); + free(listen); return AUL_R_ERROR; } - bundle_add(kb, AUL_K_APPID, appid); - ret = app_send_cmd(AUL_UTIL_PID, APP_LISTEN_STATUS, kb); - bundle_free(kb); + listen->callback = callback; + listen->user_data = data; - _aul_status_listen_handler = aul_handler; - _aul_status_listen_data = data; + *handle = listen; - return ret; + return AUL_R_OK; } - diff --git a/tool/aul_test.c b/tool/aul_test.c index fa37cc7..e1fbe1e 100644 --- a/tool/aul_test.c +++ b/tool/aul_test.c @@ -34,6 +34,7 @@ static int gargc; static char *cmd; static int apn_pid; static GMainLoop *mainloop = NULL; +static status_listen_h listen_handle; typedef struct _test_func_t { char *name; @@ -680,10 +681,9 @@ static int resume_pid_async_test_for_uid(void) return aul_resume_pid_async_for_uid(apn_pid, atoi(gargv[3])); } -static int app_status_handler(const char *appid, const char *pkgid, - int pid, int status, int is_subapp, void *data) +static int app_status_handler(aul_app_info *info, int ctx_status, void *data) { - printf("aul_listen_app_status: %s status: %d\n", appid, status); + printf("aul_listen_app_status: %s status: %d\n", info->appid, ctx_status); return 0; } @@ -692,7 +692,7 @@ static int listen_app_status(void) static int num; printf("aul_listen_app_status %d test] %s \n", num++, gargv[2]); - return aul_listen_app_status(gargv[2], app_status_handler, NULL); + return aul_listen_app_status(gargv[2], app_status_handler, NULL, &listen_handle); } static int test_regex() @@ -888,7 +888,8 @@ static gboolean run_func(void *data) if (strcmp(cmd, "launch_res") == 0 || strcmp(cmd, "all") == 0 || strcmp(cmd, "dbuslaunch") == 0 || strcmp(cmd, "listen_app_status") == 0 - || strcmp(cmd, "open_svc_res") == 0) + || strcmp(cmd, "open_svc_res") == 0 || + strcmp(cmd, "listen_app_status") == 0) return 0; else g_main_loop_quit(mainloop);