From: Hyunho Kang Date: Wed, 12 Oct 2016 10:35:55 +0000 (+0900) Subject: Add aul_widget_instance_get_content() X-Git-Tag: accepted/tizen/3.0/ivi/20161028.123007^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51636ba7198f2edf5ef4f2a71f6113e805de7c8f;p=platform%2Fcore%2Fappfw%2Faul-1.git Add aul_widget_instance_get_content() - Retrieve content info of widget instance Change-Id: I193071a78126d888753452ae696d93aaec464411 Signed-off-by: Hyunho Kang --- diff --git a/include/aul.h b/include/aul.h index 9a0e362..927d635 100644 --- a/include/aul.h +++ b/include/aul.h @@ -68,6 +68,7 @@ typedef enum _aul_type { AUL_PAUSE, AUL_WAKE, AUL_SUSPEND, + AUL_WIDGET_CONTENT, } aul_type; typedef enum aul_widget_lifecycle_event { @@ -234,7 +235,7 @@ typedef enum aul_widget_instance_event { /** AUL internal private key */ #define AUL_K_WIDGET_STATUS "__AUL_WIDGET_STATUS__" /** AUL internal private key */ -#define AUL_K_APP_DATA_KEY "__AUL_APP_DATA_KEY__" +#define AUL_K_WIDGET_CONTENT_INFO "__AUL_WIDGET_CONTENT_INFO__" /** AUL internal private key */ #define AUL_K_TARGET_PID "__AUL_TARGET_PID__" /** AUL internal private key */ @@ -2981,6 +2982,11 @@ API int aul_listen_app_status(const char *appid, int pid, int status, int is_subapp, void *data), void *data); +/* + * This API is only for Appfw internally. + */ +int aul_widget_instance_get_content(const char *widget_id, const char *instance_id, char **content); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 108c729..84e4d8d 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -74,18 +74,12 @@ enum app_cmd { APP_COM_SEND, APP_COM_LEAVE, APP_COM_MESSAGE, - APP_DATA_NEW, - APP_DATA_GET_RAW, - APP_DATA_PUT, - APP_DATA_GET, - APP_DATA_GET_OWNER, - APP_DATA_DEL, - WIDGET_ADD, WIDGET_DEL, WIDGET_LIST, WIDGET_UPDATE, WIDGET_COUNT, + WIDGET_GET_CONTENT, APP_REGISTER_PID, diff --git a/src/launch.c b/src/launch.c index 7106d61..e3ecea7 100644 --- a/src/launch.c +++ b/src/launch.c @@ -361,6 +361,46 @@ static int __send_result_to_launchpad(int fd, int res) return 0; } +static int widget_get_content(int clifd, bundle *kb) +{ + int ret; + int fd = 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, -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, + (unsigned char *)content_info, + strlen(content_info) + 1, AUL_SOCK_NOREPLY); + } else { + ret = aul_sock_send_raw_with_fd(fd, -ENOENT, + NULL, 0, AUL_SOCK_NOREPLY); + } + + if (ret < 0) + _E("failed to send content %d (%d)", fd, ret); + + return ret; +} + /** * @brief caller & callee's sock handler */ @@ -382,7 +422,7 @@ int aul_sock_handler(int fd) if (pkt->opt & AUL_SOCK_NOREPLY) { close(clifd); - } else { + } else if (pkt->cmd != WIDGET_GET_CONTENT) { ret = __send_result_to_launchpad(clifd, 0); if (ret < 0) { free(pkt); @@ -451,6 +491,9 @@ int aul_sock_handler(int fd) case APP_STATUS_NOTIFICATION: app_status_event(kbundle); break; + case WIDGET_GET_CONTENT: + widget_get_content(clifd, kbundle); + break; default: _E("no support packet"); } diff --git a/src/widget.c b/src/widget.c index a4e5c26..b7f88ca 100644 --- a/src/widget.c +++ b/src/widget.c @@ -192,6 +192,55 @@ API int aul_widget_instance_update(const char *widget_id, return ret; } +API int aul_widget_instance_get_content(const char *widget_id, + const char *instance_id, char **content) +{ + int ret; + bundle *kb; + int fd = 0; + app_pkt_t *pkt = NULL; + + if (widget_id == NULL || instance_id == NULL || content == NULL) + return AUL_R_EINVAL; + + kb = bundle_create(); + if (kb == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + + bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id)); + bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id); + bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id); + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_GET_CONTENT, + kb, AUL_SOCK_ASYNC); + if (ret > 0) { + ret = aul_sock_recv_reply_sock_fd(ret, &fd, 1); + if (ret == 0) { + ret = aul_sock_recv_reply_pkt(fd, &pkt); + if (ret == 0 && pkt && pkt->cmd == 0) { + *content = strdup((const char *)pkt->data); + _D("recieved content: %s", *content); + } else { + if (pkt) + ret = pkt->cmd; + + _E("failed to get content"); + } + } else { + _E("failed to get socket fd:%d", ret); + } + } + + bundle_free(kb); + + if (ret < 0) + ret = aul_error_convert(ret); + + return ret; +} + API int aul_widget_instance_count(const char *widget_id) { int ret;