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;
}