From 97fb68b620e3657440605130d13d2f6a06d8e413 Mon Sep 17 00:00:00 2001 From: hyunho Date: Wed, 2 Dec 2020 14:28:46 +0900 Subject: [PATCH] Refactoring communication functions Replace common communication implementation with aul functions so that we can remove the communication part duplication with component based widget app Change-Id: If5d058cfadf65ac3e80677932a92f421d02f479e Signed-off-by: hyunho --- src/base/widget_base.c | 82 +++++--------------------------------------------- 1 file changed, 7 insertions(+), 75 deletions(-) diff --git a/src/base/widget_base.c b/src/base/widget_base.c index 678b6f9..ec0d02d 100644 --- a/src/base/widget_base.c +++ b/src/base/widget_base.c @@ -196,87 +196,19 @@ static widget_base_class *__get_class(const char *class_id) return cls; } -static int __send_lifecycle_event(const char *class_id, const char *instance_id, - int status) -{ - bundle *b = bundle_create(); - int ret; - - if (b == NULL) { - LOGE("out of memory"); /* LCOV_EXCL_LINE */ - return -1; /* LCOV_EXCL_LINE */ - } - - bundle_add_str(b, AUL_K_WIDGET_ID, class_id); - bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id); - bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int)); - bundle_add_str(b, AUL_K_PKGID, __package_id); - - LOGD("send lifecycle %s(%d)", instance_id, status); - ret = aul_app_com_send("widget.status", b); - if (ret < 0) - LOGE("send lifecycle error:%d", ret); /* LCOV_EXCL_LINE */ - - bundle_free(b); - - return ret; -} - static int __send_update_status(const char *class_id, const char *instance_id, int status, int err, bundle *extra) { - bundle *b; - int lifecycle = -1; - bundle_raw *raw = NULL; - int len; - char err_str[256]; + int lifecycle; - b = bundle_create(); - if (!b) { - LOGE("out of memory"); /* LCOV_EXCL_LINE */ - return -1; /* LCOV_EXCL_LINE */ + aul_widget_send_status_to_viewer(class_id, instance_id, + __viewer_endpoint, status, err, extra); + lifecycle = widget_instance_convert_event_to_lifecycle_status(status); + if (lifecycle > -1) { + aul_widget_send_status_to_service( + class_id, instance_id, __package_id, lifecycle); } - if (err < 0) { - snprintf(err_str, sizeof(err_str), "%d", err); - bundle_add_str(b, AUL_K_WIDGET_ERROR_CODE, err_str); - } - - bundle_add_str(b, AUL_K_WIDGET_ID, class_id); - bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id); - bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int)); - - if (extra) { - bundle_encode(extra, &raw, &len); - bundle_add_str(b, WIDGET_K_CONTENT_INFO, (const char *)raw); - aul_widget_instance_add(class_id, instance_id); - } - - LOGD("send update %s(%d) to %s", instance_id, status, __viewer_endpoint); - aul_app_com_send(__viewer_endpoint, b); - - switch (status) { - case WIDGET_INSTANCE_EVENT_CREATE: - lifecycle = WIDGET_LIFE_CYCLE_EVENT_CREATE; - break; - case WIDGET_INSTANCE_EVENT_DESTROY: - lifecycle = WIDGET_LIFE_CYCLE_EVENT_DESTROY; - break; - case WIDGET_INSTANCE_EVENT_PAUSE: - lifecycle = WIDGET_LIFE_CYCLE_EVENT_PAUSE; - break; - case WIDGET_INSTANCE_EVENT_RESUME: - lifecycle = WIDGET_LIFE_CYCLE_EVENT_RESUME; - break; - } - - if (lifecycle > -1) - __send_lifecycle_event(class_id, instance_id, lifecycle); - - bundle_free(b); - if (raw) - free(raw); - return 0; } -- 2.7.4