diff options
author | Jiwoong Im <jiwoong.im@samsung.com> | 2015-08-24 14:36:49 +0900 |
---|---|---|
committer | Jiwoong Im <jiwoong.im@samsung.com> | 2015-08-25 16:22:44 +0900 |
commit | 95db5adb9535d313e08ee00a3faee642501499ed (patch) | |
tree | 4009574ea679296f0160a7aff57e8ee4fc741a44 | |
parent | e563309ddbeaf517a33c0e6d74d21feeaa64a73b (diff) | |
download | aul-1-95db5adb9535d313e08ee00a3faee642501499ed.tar.gz aul-1-95db5adb9535d313e08ee00a3faee642501499ed.tar.bz2 aul-1-95db5adb9535d313e08ee00a3faee642501499ed.zip |
add status api from tizen_2.4
- int aul_app_get_status_bypid(int pid);
- int aul_add_status_local_cb(int (*func) (int, void *), void *data);
- int aul_remove_status_local_cb(int (*func) (int, void *), void *data);
- int aul_invoke_status_local_cb(int status);
Change-Id: If680ab9228fdebd28c5a5cbd2487a6b37b702e34
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
-rw-r--r-- | am_daemon/amd_request.c | 13 | ||||
-rw-r--r-- | am_daemon/amd_status.c | 4 | ||||
-rw-r--r-- | include/app_sock.h | 1 | ||||
-rw-r--r-- | include/aul.h | 150 | ||||
-rw-r--r-- | src/status.c | 112 | ||||
-rw-r--r-- | test/aul_test.c | 28 |
6 files changed, 305 insertions, 3 deletions
diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index 64982a78..91250004 100644 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -535,10 +535,21 @@ static gboolean __request_handler(gpointer data) break; case APP_STATUS_UPDATE: status = (int *)pkt->data; - ret = _status_update_app_info_list(cr.pid, *status, cr.uid); + if (*status == STATUS_NORESTART) { + appid = _status_app_get_appid_bypid(cr.pid); + ai = appinfo_find(cr.uid, appid); + appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart"); + } else { + ret = _status_update_app_info_list(cr.pid, *status, cr.uid); + } //__send_result_to_client(clifd, ret); close(clifd); break; + case APP_GET_STATUS: + memcpy(&pid, pkt->data, sizeof(int)); + ret = _status_get_app_info_status(pid, 0); + __send_result_to_client(clifd, ret); + break; case APP_RELEASED: appid = malloc(MAX_PACKAGE_STR_SIZE); if (appid == NULL) { diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c index 10a131ef..e4c9a96b 100644 --- a/am_daemon/amd_status.c +++ b/am_daemon/amd_status.c @@ -21,6 +21,7 @@ #include <stdlib.h> #include <stdio.h> +#include <stdbool.h> #include <glib.h> #include <aul.h> #include <string.h> @@ -159,7 +160,8 @@ int _status_get_app_info_status(int pid, uid_t uid) for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) { info_t = (app_status_info_t *)iter->data; - if(pid == info_t->pid && uid == info_t->uid) { + if (pid == info_t->pid && + (uid == 0) ? true : (uid == info_t->uid)) { return info_t->status; } } diff --git a/include/app_sock.h b/include/app_sock.h index 6f272ff9..620cb905 100644 --- a/include/app_sock.h +++ b/include/app_sock.h @@ -64,6 +64,7 @@ enum app_cmd { APP_GROUP_GET_GROUP_PIDS, APP_GROUP_RESUME, APP_GROUP_GET_LEADER_PID, + APP_GET_STATUS, /* for special purpose */ AMD_RELOAD_APPINFO, diff --git a/include/aul.h b/include/aul.h index deccf7c3..e2fd2491 100644 --- a/include/aul.h +++ b/include/aul.h @@ -94,7 +94,9 @@ enum app_status { STATUS_VISIBLE, STATUS_BG, STATUS_DYING, - STATUS_HOME + STATUS_HOME, + STATUS_NORESTART, + STATUS_SERVICE }; /** @} */ @@ -1656,6 +1658,152 @@ int aul_add_caller_cb(int pid, void (*caller_cb) (int, void *), void *data); int aul_remove_caller_cb(int pid); int aul_invoke_caller_cb(int pid); +/** + * @par Description: + * This API gets status of specified application process id. + * @par Purpose: + * This API's purpose is to get the application's status. + * + * @param[in] pid pid of application + * @return 0 or greater if success, nagative value if fail + * @retval STATUS_LAUNCHING + * @retval STATUS_CREATED + * @retval STATUS_FOCUS + * @retval STATUS_VISIBLE + * @retval STATUS_BG + * @retval STATUS_DYING + * @retval STATUS_HOME + * @retval STATUS_NORESTART + * @see + * aul_status_update + * @pre + * None + * @post + * None + * @code + * #include <aul.h> + * + * int iterfunc(const aul_app_info *info, void *data) + * { + * int status; + * status = aul_app_get_status_bypid(info->pid); + * if (status == STATUS_FOCUS) { + * printf("%s has focus", info->app_id); + * (int *)data = info->pid; + * return -1; + * } + * return 0; + * } + * + * int find_focus_app_pid() + * { + * int pid = 0; + * aul_app_get_running_app_info(iterfunc, &pid); + * return pid; + * } + * @endcode + * @remark + * None + */ +int aul_app_get_status_bypid(int pid); + +/** + * @par Description + * This API sets callback function that on application status changed. + * @par Purpose: + * This API's purpose is to listen the application's status changed within + * the caller process. In general, a library that required to release resource on + * application's status may use this API. + * + * @param[in] func callback function + * @param[in] data user data + * @return 0 if success, negative value if fail + * @retval AUL_R_OK - success + * @retval AUL_R_ERROR - general error + * @see + * aul_remove_status_local_cb + * @pre + * None + * @post + * None + * @code + * #include <aul.h> + * + * int status_changed(int status, void *data) + * { + * if (status == STATUS_FOCUS) + * printf("%d has focus\n", getpid()); + * + * if (status == STATUS_VISIBLE) + * printf("%d resume\n", getpid()); + * + * if (status == STATUS_BG0 + * printf("%d pause\n", getpid()); + * } + * + * void listen_app_status() + * { + * aul_add_status_local_cb(status_changed, NULL); + * } + * @endcode + * @remark + * None + * + */ +int aul_add_status_local_cb(int (*func) (int, void *), void *data); + +/** + * @par Description + * This API unsets callback function that on application status changed. + * @par Purpose: + * This API's purpose is to remove callback that added by + * aul_add_status_local_cb. + * + * @param[in] func callback function + * @param[in] data user data + * @return 0 if success, negative value if fail + * @retval AUL_R_OK - success + * @retval AUL_R_ERROR - general error + * + * @pre + * None + * @post + * None + * @see + * aul_add_status_local_cb + * @code + * #include <aul.h> + * + * int status_changed(int status, void *data) + * { + * if (status == STATUS_FOCUS) + * printf("%d has focus\n", getpid()); + * + * if (status == STATUS_VISIBLE) + * printf("%d resume\n", getpid()); + * + * if (status == STATUS_BG0 + * printf("%d pause\n", getpid()); + * } + * + * void listen_app_status() + * { + * aul_add_status_local_cb(status_changed, NULL); + * } + * + * void ignore_app_status() + * { + * aul_remove_status_local_cb(status_changed, NULL); + * } + * + * @endcode + * @remark + * None + * + */ +int aul_remove_status_local_cb(int (*func) (int, void *), void *data); +int aul_invoke_status_local_cb(int status); + typedef int (*data_control_provider_handler_fn) (bundle *b, int request_id, void *data); int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler); int aul_unset_data_control_provider_cb(void); diff --git a/src/status.c b/src/status.c index 83678b65..f337d38a 100644 --- a/src/status.c +++ b/src/status.c @@ -27,15 +27,127 @@ #include "aul_api.h" #include "launch.h" +typedef struct _app_status_cb_info_t { + int (*handler) (int status, void *data); + void *data; + struct _app_status_cb_info_t *next; +} app_status_cb_info_t; + +app_status_cb_info_t *app_status_cb = NULL; + +static int app_status = STATUS_LAUNCHING; + SLPAPI int aul_status_update(int status) { int ret; + app_status_cb_info_t *cb = app_status_cb; + + app_status = status; ret = __app_send_raw_with_noreply(AUL_UTIL_PID, APP_STATUS_UPDATE, (unsigned char *)&status, sizeof(status)); + if (!ret) { + while (cb) { + if (cb->handler) { + if (cb->handler(app_status, cb->data) < 0) + aul_remove_status_local_cb(cb->handler, cb->data); + } + + cb = cb->next; + } + } + + return ret; +} + +SLPAPI int aul_app_get_status_bypid(int pid) +{ + int ret; + + if (pid == getpid()) { + return app_status; + } + + ret = __app_send_raw(AUL_UTIL_PID, APP_GET_STATUS, (unsigned char *)&pid, sizeof(pid)); + return ret; } +SLPAPI int aul_add_status_local_cb(int (*func)(int status, void *data), void *data) +{ + app_status_cb_info_t *cb = app_status_cb; + + if (func == NULL) + return -1; + + // check known callback + while (cb) { + if (cb && cb->handler == func && cb->data == data) { + // already in list + return 0; + } + cb = cb->next; + } + + cb = (app_status_cb_info_t *)malloc(sizeof(app_status_cb_info_t)); + if (cb == NULL) + return -1; + + cb->handler = func; + cb->data = data; + + cb->next = app_status_cb; + app_status_cb = cb; + + return 0; +} + +SLPAPI int aul_remove_status_local_cb(int (*func)(int status, void *data), void *data) +{ + app_status_cb_info_t *cb = app_status_cb; + app_status_cb_info_t *tmp = NULL; + + if (app_status_cb + && app_status_cb->handler == func + && app_status_cb->data == data) { + cb = app_status_cb->next; + free(app_status_cb); + app_status_cb = cb; + return 0; + } + + while (cb) { + if (cb->next + && cb->next->handler == func + && cb->next->data == data) { + tmp = cb->next->next; + free(cb->next); + cb->next = tmp; + return 0; + } + + cb = cb->next; + } + + return -1; +} + +SLPAPI int aul_invoke_status_local_cb(int status) +{ + app_status_cb_info_t *cb = app_status_cb; + + while (cb) { + if (cb->handler) { + if (cb->handler(status, cb->data) < 0) + aul_remove_status_local_cb(cb->handler, cb->data); + } + + cb = cb->next; + } + + return 0; +} + SLPAPI int aul_running_list_update(char *appid, char *app_path, char *pid) { int ret; diff --git a/test/aul_test.c b/test/aul_test.c index 38d39d3d..f43eb015 100644 --- a/test/aul_test.c +++ b/test/aul_test.c @@ -399,6 +399,32 @@ static int get_pkg_func() return 0; } +static char *status_text[] = { + "STATUS_LAUNCHING", + "STATUS_CREATED", + "STATUS_FOCUS", + "STATUS_VISIBLE", + "STATUS_BG", + "STATUS_DYING", + "STATUS_HOME", + "STATUS_NORESTART", + "STATUS_SERVICE", +}; + +static int get_status_pid() +{ + int ret; + ret = aul_app_get_status_bypid(apn_pid); + + printf("pid: %d status: %d ", apn_pid, ret); + if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART) + printf("(%s)", status_text[ret]); + + printf("\n"); + + return 0; +} + static int update_running_list() { aul_running_list_update(gargv[2], gargv[3], gargv[4]); @@ -559,6 +585,8 @@ static test_func_t test_func[] = { "[usage] update_list <appid> <app_path> <pid>"}, {"reload", reload_appinfo, "reload appinfo table", "[usage] reload"}, + {"get_status_pid", get_status_pid, "aul_app_get_status_bypid test", + "[usage] get_status_pid <pid>"}, /* {"setpkg", set_pkg_func, "set package", "[usage] setpkg <pkgname> <apppath>"}, |