Add aul_widget_instance_get_content() 12/81312/8 accepted/tizen/3.0/ivi/20161028.123007 accepted/tizen/3.0/mobile/20161028.122256 accepted/tizen/3.0/tv/20161028.122553 accepted/tizen/3.0/wearable/20161028.122812 accepted/tizen/common/20161013.155657 accepted/tizen/ivi/20161013.000915 accepted/tizen/mobile/20161013.000838 accepted/tizen/tv/20161013.000851 accepted/tizen/wearable/20161013.000903 submit/tizen/20161012.155021 submit/tizen_3.0/20161028.062323 submit/tizen_3.0/20161028.082323 submit/tizen_3.0_common/20161104.104000
authorHyunho Kang <hhstark.kang@samsung.com>
Wed, 12 Oct 2016 10:35:55 +0000 (19:35 +0900)
committerHawnkyu Jhun <h.jhun@samsung.com>
Wed, 12 Oct 2016 15:28:52 +0000 (00:28 +0900)
- Retrieve content info of widget instance

Change-Id: I193071a78126d888753452ae696d93aaec464411
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
include/aul.h
include/aul_cmd.h
src/launch.c
src/widget.c

index 9a0e362..927d635 100644 (file)
@@ -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
index 108c729..84e4d8d 100644 (file)
@@ -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,
 
index 7106d61..e3ecea7 100644 (file)
@@ -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");
        }
index a4e5c26..b7f88ca 100644 (file)
@@ -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;