From: hyunho Date: Wed, 2 Dec 2020 05:32:13 +0000 (+0900) Subject: Add widget status communication functions X-Git-Tag: accepted/tizen/unified/20201231.125016~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F248761%2F2;p=platform%2Fcore%2Fappfw%2Faul-1.git Add widget status communication functions Change-Id: Id4c764a3b8bc9382e0daea9b35732ecb5c7f41cb Signed-off-by: hyunho --- diff --git a/include/aul_widget.h b/include/aul_widget.h index 7e06d0e..c15c1d0 100644 --- a/include/aul_widget.h +++ b/include/aul_widget.h @@ -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 diff --git a/src/widget.c b/src/widget.c index 30ccf79..00363cf 100644 --- a/src/widget.c +++ b/src/widget.c @@ -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; +}