Add widget status communication functions 61/248761/2
authorhyunho <hhstark.kang@samsung.com>
Wed, 2 Dec 2020 05:32:13 +0000 (14:32 +0900)
committerhyunho <hhstark.kang@samsung.com>
Fri, 11 Dec 2020 06:30:46 +0000 (15:30 +0900)
Change-Id: Id4c764a3b8bc9382e0daea9b35732ecb5c7f41cb
Signed-off-by: hyunho <hhstark.kang@samsung.com>
include/aul_widget.h
src/widget.c

index 7e06d0e..c15c1d0 100644 (file)
@@ -211,6 +211,14 @@ int aul_widget_unset_event_cb(void);
  */
 int aul_widget_send_event(const char *event_name, bundle *event_data);
 
+
+int aul_widget_send_status_to_service(const char *class_id,
+       const char *instance_id, const char *sender_pkgid, int status);
+
+int aul_widget_send_status_to_viewer(const char *class_id,
+       const char *instance_id, const char *viewer_endpoint,
+       int status, int err, bundle *extra);
+
 #ifdef __cplusplus
 }
 #endif
index 30ccf79..00363cf 100644 (file)
@@ -849,3 +849,77 @@ API int aul_widget_send_event(const char *event_name, bundle *event_data)
 
        return AUL_R_OK;
 }
+
+API int aul_widget_send_status_to_viewer(const char *class_id,
+       const char *instance_id, const char *viewer_endpoint,
+       int status, int err, bundle *extra)
+{
+       bundle *data;
+       bundle_raw *raw = NULL;
+       int len;
+       char err_str[256];
+       int ret;
+
+       data = bundle_create();
+       if (!data) {
+               _E("out of memory");
+               return -1;
+       }
+
+       if (err < 0) {
+               snprintf(err_str, sizeof(err_str), "%d", err);
+               bundle_add_str(data, AUL_K_WIDGET_ERROR_CODE, err_str);
+       }
+
+       bundle_add_str(data, AUL_K_WIDGET_ID, class_id);
+       bundle_add_str(data, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+       bundle_add_byte(data, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+
+       if (extra) {
+               bundle_encode(extra, &raw, &len);
+               bundle_add_str(data,
+                       "__WIDGET_CONTENT_INFO__", (const char *)raw);
+               free(raw);
+               ret = aul_widget_instance_add(class_id, instance_id);
+               if (ret != 0) {
+                       _E("Failed to add instance. error(%d)", ret);
+                       bundle_free(data);
+                       return aul_error_convert(ret);
+               }
+       }
+
+       LOGD("send update %s(%d) to %s", instance_id, status, viewer_endpoint);
+       ret = aul_app_com_send(viewer_endpoint, data);
+       bundle_free(data);
+       if (ret != 0) {
+               _E("Failed to add instance. error(%d)", ret);
+               return aul_error_convert(ret);
+       }
+
+       return 0;
+}
+
+API int aul_widget_send_status_to_service(const char *class_id,
+       const char *instance_id, const char *sender_pkgid, int status)
+{
+       bundle *data = bundle_create();
+       int ret;
+
+       if (data == NULL) {
+               _E("out of memory");
+               return -1;
+       }
+
+       bundle_add_str(data, AUL_K_WIDGET_ID, class_id);
+       bundle_add_str(data, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+       bundle_add_byte(data, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+       bundle_add_str(data, AUL_K_PKGID, sender_pkgid);
+
+       LOGD("send lifecycle %s(%d)", instance_id, status);
+       ret = aul_app_com_send("widget.status", data);
+       if (ret < 0)
+               _E("send lifecycle error:%d", ret);
+
+       bundle_free(data);
+       return 0;
+}