diff options
author | Daehyeon Jung <darrenh.jung@samsung.com> | 2016-01-18 14:19:33 +0900 |
---|---|---|
committer | Semun Lee <sm79.lee@samsung.com> | 2016-01-17 21:24:14 -0800 |
commit | bba9567209f1df22828618bdacebf17511ab179c (patch) | |
tree | 9874c9c8aa57937b753249ea040c2f9eb3a527c7 | |
parent | fc1b47d841e237d84673ad6883659f5be421ae57 (diff) | |
download | aul-1-bba9567209f1df22828618bdacebf17511ab179c.tar.gz aul-1-bba9567209f1df22828618bdacebf17511ab179c.tar.bz2 aul-1-bba9567209f1df22828618bdacebf17511ab179c.zip |
add option for aul_sock functionssubmit/tizen/20160118.055121accepted/tizen/wearable/20160118.084807accepted/tizen/tv/20160118.084749accepted/tizen/mobile/20160118.084729
Change-Id: If2f190fd5fb3e32d261b1073df015a94aa2b995a
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
-rw-r--r-- | include/aul_sock.h | 20 | ||||
-rw-r--r-- | src/app_group.c | 10 | ||||
-rw-r--r-- | src/aul_sock.c | 38 | ||||
-rw-r--r-- | src/launch.c | 43 | ||||
-rw-r--r-- | src/pkginfo.c | 12 | ||||
-rw-r--r-- | src/status.c | 4 |
6 files changed, 81 insertions, 46 deletions
diff --git a/include/aul_sock.h b/include/aul_sock.h index e22275ae..86b2ca24 100644 --- a/include/aul_sock.h +++ b/include/aul_sock.h @@ -30,14 +30,22 @@ #define ENOLAUNCHPAD 125 #define EREJECTED 123 -#define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int)) +#define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int)) typedef struct _app_pkt_t { int cmd; int len; + int opt; unsigned char data[1]; } app_pkt_t; +typedef enum { + AUL_SOCK_NONE = 0x0, /* default */ + AUL_SOCK_NOREPLY = 0x1, /* no reply required in app_sock_handler */ + AUL_SOCK_CLOSE = 0x2, /* close socket after sent */ + AUL_SOCK_QUEUE = 0x4, /* add request to pending list in case of receiver is busy */ +} aul_sock_opt_e; + /* * This API is only for Appfw internally. */ @@ -46,27 +54,27 @@ int aul_sock_create_server(int pid, uid_t uid); /* * This API is only for Appfw internally. */ -int aul_sock_send_raw(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen); +int aul_sock_send_raw(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt); /* * This API is only for Appfw internally. */ -int aul_sock_send_raw_async(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen); +int aul_sock_send_raw_async(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt); /* * This API is only for Appfw internally. */ -int aul_sock_send_raw_async_with_fd(int fd, int cmd, unsigned char *kb_data, int datalen); +int aul_sock_send_raw_async_with_fd(int fd, int cmd, unsigned char *kb_data, int datalen, int opt); /* * This API is only for Appfw internally. */ -int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int *ret_fd); +int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt, int *ret_fd); /* * This API is only for Appfw internally. */ -app_pkt_t *aul_sock_send_raw_with_pkt_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen); +app_pkt_t *aul_sock_send_raw_with_pkt_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt); /* * This API is only for Appfw internally. diff --git a/src/app_group.c b/src/app_group.c index acd186a6..c826b8cd 100644 --- a/src/app_group.c +++ b/src/app_group.c @@ -65,7 +65,7 @@ API void aul_app_group_get_leader_pids(int *cnt, int **pids) *pids = NULL; ret = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, getuid(), - APP_GROUP_GET_LEADER_PIDS, NULL, 0); + APP_GROUP_GET_LEADER_PIDS, NULL, 0, AUL_SOCK_NONE); if (ret != NULL) { *cnt = ret->len / sizeof(int); if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) { @@ -99,7 +99,7 @@ API void aul_app_group_get_group_pids(int leader_pid, int *cnt, int **pids) bundle_encode(b, &br, &datalen); ret = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, getuid(), - APP_GROUP_GET_GROUP_PIDS, br, datalen); + APP_GROUP_GET_GROUP_PIDS, br, datalen, AUL_SOCK_NONE); if (ret != NULL) { *cnt = ret->len / sizeof(int); if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) { @@ -139,7 +139,7 @@ API int aul_app_group_get_leader_pid(int pid) API int aul_app_group_clear_top(void) { unsigned char dummy[1] = { 0 }; - return aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_GROUP_CLEAR_TOP, dummy, 0); + return aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_GROUP_CLEAR_TOP, dummy, 0, AUL_SOCK_NONE); } API int aul_app_group_is_top(void) @@ -184,7 +184,7 @@ API void aul_app_group_lower(int *exit) int ret; unsigned char dummy[1] = { 0 }; - ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_GROUP_LOWER, dummy, 0); + ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_GROUP_LOWER, dummy, 0, AUL_SOCK_NONE); *exit = ret; } @@ -195,7 +195,7 @@ API void aul_app_group_get_idle_pids(int *cnt, int **pids) *pids = NULL; ret = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, getuid(), - APP_GROUP_GET_IDLE_PIDS, NULL, 0); + APP_GROUP_GET_IDLE_PIDS, NULL, 0, AUL_SOCK_NONE); if (ret != NULL) { *cnt = ret->len / sizeof(int); if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) { diff --git a/src/aul_sock.c b/src/aul_sock.c index 6162d4e1..cda52059 100644 --- a/src/aul_sock.c +++ b/src/aul_sock.c @@ -235,8 +235,7 @@ static int __connect_client_sock(int fd, const struct sockaddr *saptr, socklen_t return (0); } -API int aul_sock_send_raw_async_with_fd(int fd, int cmd, - unsigned char *kb_data, int datalen) +static int __send_raw_async_with_fd(int fd, int cmd, unsigned char *kb_data, int datalen, int opt) { int len; int sent = 0; @@ -250,6 +249,7 @@ API int aul_sock_send_raw_async_with_fd(int fd, int cmd, pkt->cmd = cmd; pkt->len = datalen; + pkt->opt = opt; if (kb_data) memcpy(pkt->data, kb_data, pkt->len); @@ -269,11 +269,23 @@ API int aul_sock_send_raw_async_with_fd(int fd, int cmd, return 0; } +API int aul_sock_send_raw_async_with_fd(int fd, int cmd, + unsigned char *kb_data, int datalen, int opt) +{ + int ret; + + ret = __send_raw_async_with_fd(fd, cmd, kb_data, datalen, opt); + if (opt & AUL_SOCK_CLOSE) + close(fd); + + return ret; +} + /* * @brief Send data (in raw) to the process with 'pid' via socket */ API int aul_sock_send_raw(int pid, uid_t uid, int cmd, - unsigned char *kb_data, int datalen) + unsigned char *kb_data, int datalen, int opt) { int fd; int len; @@ -290,7 +302,7 @@ API int aul_sock_send_raw(int pid, uid_t uid, int cmd, if (fd < 0) return -ECOMM; - res = aul_sock_send_raw_async_with_fd(fd, cmd, kb_data, datalen); + res = __send_raw_async_with_fd(fd, cmd, kb_data, datalen, opt); if (res < 0) { close(fd); return res; @@ -316,7 +328,7 @@ retry_recv: return res; } -API int aul_sock_send_raw_async(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen) +API int aul_sock_send_raw_async(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt) { int fd; @@ -331,7 +343,7 @@ API int aul_sock_send_raw_async(int pid, uid_t uid, int cmd, unsigned char *kb_d if (fd < 0) return -ECOMM; - aul_sock_send_raw_async_with_fd(fd, cmd, kb_data, datalen); + __send_raw_async_with_fd(fd, cmd, kb_data, datalen, opt); return fd; } @@ -347,6 +359,7 @@ API app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr) unsigned char buf[AUL_SOCK_MAXBUFF]; int cmd; int datalen; + int opt; sun_size = sizeof(struct sockaddr_un); @@ -380,6 +393,7 @@ API app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr) } memcpy(&cmd, buf, sizeof(int)); memcpy(&datalen, buf + sizeof(int), sizeof(int)); + memcpy(&opt, buf + sizeof(int) + sizeof(int), sizeof(int)); /* allocate for a null byte */ pkt = (app_pkt_t *)calloc(1, AUL_PKT_HEADER_SIZE + datalen + 1); @@ -389,6 +403,7 @@ API app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr) } pkt->cmd = cmd; pkt->len = datalen; + pkt->opt = opt; len = 0; while (len != pkt->len) { @@ -406,11 +421,12 @@ API app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr) return pkt; } -API app_pkt_t *aul_sock_send_raw_with_pkt_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen) +API app_pkt_t *aul_sock_send_raw_with_pkt_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt) { int fd; int len; int ret; + int recv_opt; app_pkt_t *pkt = NULL; unsigned char buf[AUL_SOCK_MAXBUFF]; @@ -418,7 +434,7 @@ API app_pkt_t *aul_sock_send_raw_with_pkt_reply(int pid, uid_t uid, int cmd, uns if (fd < 0) return NULL; - ret = aul_sock_send_raw_async_with_fd(fd, cmd, kb_data, datalen); + ret = __send_raw_async_with_fd(fd, cmd, kb_data, datalen, opt); if (ret < 0) { close(fd); return NULL; @@ -438,6 +454,7 @@ retry_recv: } memcpy(&cmd, buf, sizeof(int)); memcpy(&len, buf + sizeof(int), sizeof(int)); + memcpy(&recv_opt, buf + sizeof(int) + sizeof(int), sizeof(int)); /* allocate for a null byte */ pkt = (app_pkt_t *)calloc(1, AUL_PKT_HEADER_SIZE + len + 1); @@ -447,6 +464,7 @@ retry_recv: } pkt->cmd = cmd; pkt->len = len; + pkt->opt = recv_opt; len = 0; while (len != pkt->len) { @@ -576,7 +594,7 @@ int __recv_socket_fd(int fd, int cmd, int *ret_fd) return 0; } -int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int *ret_fd) +int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int opt, int *ret_fd) { int fd; int len; @@ -606,8 +624,8 @@ int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char * pkt->cmd = cmd; pkt->len = datalen; + pkt->opt = opt; memcpy(pkt->data, kb_data, pkt->len); - while (sent != AUL_PKT_HEADER_SIZE + pkt->len) { len = send(fd, pkt, AUL_PKT_HEADER_SIZE + pkt->len - sent, 0); if (len <= 0) { diff --git a/src/launch.c b/src/launch.c index 36f82206..e5fb2ba4 100644 --- a/src/launch.c +++ b/src/launch.c @@ -161,7 +161,7 @@ static int __app_send_cmd_with_fd(int pid, int uid, int cmd, bundle *kb, int *re if (res != BUNDLE_ERROR_NONE) return AUL_R_EINVAL; - if ((res = aul_sock_send_raw_with_fd_reply(pid, uid, cmd, kb_data, datalen, ret_fd)) < 0) { + if ((res = aul_sock_send_raw_with_fd_reply(pid, uid, cmd, kb_data, datalen, AUL_SOCK_NONE, ret_fd)) < 0) { switch (res) { case -EINVAL: res = AUL_R_EINVAL; @@ -202,6 +202,20 @@ static int __app_send_cmd_with_fd(int pid, int uid, int cmd, bundle *kb, int *re return res; } +static int __send_cmd_for_uid_opt(int pid, uid_t uid, int cmd, bundle *kb, int opt) +{ + int datalen; + bundle_raw *kb_data; + int res; + + bundle_encode(kb, &kb_data, &datalen); + if ((res = aul_sock_send_raw(pid, uid, cmd, kb_data, datalen, opt)) < 0) + res = __get_aul_error(res); + free(kb_data); + + return res; +} + /** * @brief encode kb and send it to 'pid' * @param[in] pid receiver's pid @@ -210,21 +224,17 @@ static int __app_send_cmd_with_fd(int pid, int uid, int cmd, bundle *kb, int *re */ API int app_send_cmd(int pid, int cmd, bundle *kb) { - return app_send_cmd_for_uid(pid, getuid(), cmd, kb); + return __send_cmd_for_uid_opt(pid, getuid(), cmd, kb, AUL_SOCK_NONE); } API int app_send_cmd_for_uid(int pid, uid_t uid, int cmd, bundle *kb) { - int datalen; - bundle_raw *kb_data; - int res; - - bundle_encode(kb, &kb_data, &datalen); - if ((res = aul_sock_send_raw(pid, uid, cmd, kb_data, datalen)) < 0) - res = __get_aul_error(res); - free(kb_data); + return __send_cmd_for_uid_opt(pid, uid, cmd, kb, AUL_SOCK_NONE); +} - return res; +API int app_send_cmd_with_queue_for_uid(int pid, uid_t uid, int cmd, bundle *kb) +{ + return __send_cmd_for_uid_opt(pid, uid, cmd, kb, AUL_SOCK_QUEUE); } API int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb) @@ -234,7 +244,7 @@ API int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb) int res; bundle_encode(kb, &kb_data, &datalen); - res = aul_sock_send_raw_async(pid, getuid(), cmd, kb_data, datalen); + res = aul_sock_send_raw_async(pid, getuid(), cmd, kb_data, datalen, AUL_SOCK_NOREPLY); if (res > 0) { close(res); res = 0; @@ -371,7 +381,7 @@ int app_request_to_launchpad_for_uid(int cmd, const char *appid, bundle *kb, uid bundle_add(kb, AUL_K_APPID, appid); __set_stime(kb); - ret = app_send_cmd_for_uid(AUL_UTIL_PID, uid, cmd, kb); + ret = app_send_cmd_with_queue_for_uid(AUL_UTIL_PID, uid, cmd, kb); _D("launch request result : %d", ret); if (ret == AUL_R_LOCAL) { @@ -434,15 +444,14 @@ int aul_sock_handler(int fd) return -1; } - if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL && pkt->cmd != APP_TERM_BY_PID_ASYNC && - pkt->cmd != APP_COM_MESSAGE) { + if (pkt->opt & AUL_SOCK_NOREPLY) { + close(clifd); + } else { ret = __send_result_to_launchpad(clifd, 0); if (ret < 0) { free(pkt); return -1; } - } else { - close(clifd); } switch (pkt->cmd) { diff --git a/src/pkginfo.c b/src/pkginfo.c index da6b2886..826f8d06 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -42,7 +42,7 @@ API int aul_app_get_pid(const char *appid) return -1; ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_GET_PID, - (unsigned char *)appid, strlen(appid)); + (unsigned char *)appid, strlen(appid), AUL_SOCK_NONE); return ret; } @@ -60,7 +60,7 @@ API int aul_app_is_running_for_uid(const char *appid, uid_t uid) return 0; ret = aul_sock_send_raw(AUL_UTIL_PID, uid, APP_IS_RUNNING, - (unsigned char*)appid, strlen(appid)); + (unsigned char*)appid, strlen(appid), AUL_SOCK_NONE); if (ret > 0) return true; @@ -82,7 +82,7 @@ API int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn, return AUL_R_EINVAL; pkt = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, getuid(), - APP_RUNNING_INFO, NULL, 0); + APP_RUNNING_INFO, NULL, 0, AUL_SOCK_NONE); if (pkt == NULL) return AUL_R_ERROR; @@ -168,7 +168,7 @@ API int aul_app_get_appid_bypid_for_uid(int pid, char *appid, int len, uid_t uid if (pid != getpid()) { pkt = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, uid, APP_GET_APPID_BYPID, (unsigned char *)&pid, - sizeof(pid)); + sizeof(pid), AUL_SOCK_NONE); if (pkt == NULL) return AUL_R_ERROR; if (pkt->cmd == APP_GET_INFO_ERROR) { @@ -237,7 +237,7 @@ API int aul_app_get_pkgid_bypid_for_uid(int pid, char *pkgid, int len, uid_t uid return AUL_R_EINVAL; pkt = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, uid, cmd, - (unsigned char *)&pid, sizeof(pid)); + (unsigned char *)&pid, sizeof(pid), AUL_SOCK_NONE); if (pkt == NULL) return AUL_R_ERROR; @@ -268,7 +268,7 @@ API int aul_delete_rua_history(bundle *b) bundle_encode(b, &br, &datalen); ret = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, getuid(), - APP_REMOVE_HISTORY, br, datalen); + APP_REMOVE_HISTORY, br, datalen, AUL_SOCK_NONE); if (ret != NULL) { if (ret->len > 0) { memcpy(&result, ret->data, ret->len); diff --git a/src/status.c b/src/status.c index 72fc0060..5f7a85e6 100644 --- a/src/status.c +++ b/src/status.c @@ -44,7 +44,7 @@ API int aul_status_update(int status) app_status = status; ret = aul_sock_send_raw_async(AUL_UTIL_PID, getuid(), APP_STATUS_UPDATE, - (unsigned char *)&status, sizeof(status)); + (unsigned char *)&status, sizeof(status), AUL_SOCK_NONE); if (ret > 0) { close(ret); ret = 0; @@ -70,7 +70,7 @@ API int aul_app_get_status_bypid(int pid) return app_status; ret = aul_sock_send_raw(AUL_UTIL_PID, getuid(), APP_GET_STATUS, - (unsigned char *)&pid, sizeof(pid)); + (unsigned char *)&pid, sizeof(pid), AUL_SOCK_NONE); return ret; } |