From 49cfed7131365b3b6a23594a619752a343cd027b Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Mon, 18 Apr 2016 18:13:07 +0900 Subject: [PATCH 01/16] implement widget_context_foreach, add window cb Change-Id: I112c0e502ae7906e8cf4614377b32f7f4ac5f231 Signed-off-by: Daehyeon Jung --- src/widget_app.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/widget_app.c b/src/widget_app.c index 38cda3d..96212dc 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -293,6 +293,41 @@ static void __show_all() LOGD("resume"); } +static Eina_Bool __show_cb(void *data, int type, void *event) +{ + Ecore_Wl_Event_Window_Show *ev = event; + LOGD("show %d %d", (unsigned int)ev->win, (unsigned int)ev->data[0]); + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __hide_cb(void *data, int type, void *event) +{ + Ecore_Wl_Event_Window_Hide *ev = event; + LOGD("hide %d", (unsigned int)ev->win); + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __visibility_cb(void *data, int type, void *event) +{ + Ecore_Wl_Event_Window_Visibility_Change *ev = event; + LOGD("visiblity change: %d %d", (unsigned int)ev->win, (unsigned int)ev->fully_obscured); + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __lower_cb(void *data, int type, void *event) +{ + LOGD("lower"); + return ECORE_CALLBACK_RENEW; +} + +static void __add_climsg() +{ + ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, NULL); + ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, NULL); + ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, __visibility_cb, NULL); + ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __lower_cb, NULL); +} + static int __aul_handler(aul_type type, bundle *b, void *data) { char *caller = NULL; @@ -421,6 +456,8 @@ static int __before_loop(int argc, char **argv) "Fail to call _set_i18n"); } + __add_climsg(); + class_provider = app_ops->create(app_user_data); if (class_provider == NULL) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, @@ -528,6 +565,9 @@ EXPORT_API int widget_app_terminate_context(widget_context_h context) EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data) { + GList *list; + widget_context_s *wc; + if (!_is_widget_feature_enabled()) { _E("not supported"); return WIDGET_ERROR_NOT_SUPPORTED; @@ -536,6 +576,17 @@ EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data) if (!cb) return WIDGET_ERROR_INVALID_PARAMETER; + list = g_list_first(contexts); + + while (list) { + wc = (widget_context_s *)list->data; + if (wc) { + if (!cb(wc, data)) + break; + } + list = list->next; + } + return WIDGET_ERROR_NONE; } -- 2.7.4 From 782ef2dfa646d2673132cc73bfaefb5a8c6c4f3d Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Wed, 27 Apr 2016 17:02:48 +0900 Subject: [PATCH 02/16] fix set title Change-Id: I52191e195fb9ec316a0208ff1045008a7481a9bd --- src/widget_app.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/widget_app.c b/src/widget_app.c index 96212dc..50be7da 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -816,13 +816,12 @@ EXPORT_API int widget_app_context_set_title(widget_context_h context, return WIDGET_ERROR_NOT_SUPPORTED; } - /* TODO - call elm_win_title_set() - */ - if (!context || !title) return WIDGET_ERROR_INVALID_PARAMETER; + if (context->win) + elm_win_title_set(context->win, title); + return WIDGET_ERROR_NONE; } -- 2.7.4 From 16315dfb6b7cc68bc75a6e0c6bfb425620cc10b2 Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Tue, 10 May 2016 15:37:17 +0900 Subject: [PATCH 03/16] Implements system and lifecycle events - Status updates only supports partial events, and will be fixed later - App common event handler are adopted from 2.x implementation - Lifecycle handler are not yet completed Change-Id: I5b9956cf26b7cf516c943227a4fda1d36cfc2f09 Signed-off-by: Daehyeon Jung --- CMakeLists.txt | 1 + packaging/appcore-widget.spec | 1 + src/widget_app.c | 579 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 539 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d57515e..652d965 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ pkg_check_modules(pkg_widget REQUIRED aul dlog capi-appfw-app-control + appcore-common capi-appfw-app-common vconf elementary diff --git a/packaging/appcore-widget.spec b/packaging/appcore-widget.spec index 1fbbb9f..71da10d 100644 --- a/packaging/appcore-widget.spec +++ b/packaging/appcore-widget.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(vconf-internal-keys) BuildRequires: pkgconfig(alarm-service) BuildRequires: pkgconfig(capi-appfw-app-control) +BuildRequires: pkgconfig(appcore-common) BuildRequires: pkgconfig(capi-appfw-app-common) BuildRequires: pkgconfig(widget_service) BuildRequires: pkgconfig(capi-system-info) diff --git a/src/widget_app.c b/src/widget_app.c index 50be7da..491ca1c 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -29,10 +29,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include "widget_app.h" #include "widget-log.h" @@ -54,6 +57,14 @@ typedef enum _widget_obj_state_e { WC_TERMINATED = 3 } widget_obj_state_e; +struct _widget_class { + void *user_data; + widget_instance_lifecycle_callback_s ops; + char *classid; + struct _widget_class *next; + struct _widget_class *prev; +}; + struct app_event_handler { app_event_type_e type; app_event_cb cb; @@ -65,20 +76,13 @@ struct app_event_info { void *value; }; -struct _widget_class { - void *user_data; - widget_instance_lifecycle_callback_s ops; - char *classid; - struct _widget_class *next; - struct _widget_class *prev; -}; - struct _widget_context { char *id; struct _widget_class *provider; int state; void *tag; Evas_Object *win; + int win_id; bundle *content; widget_instance_lifecycle_callback_s ops; }; @@ -86,6 +90,9 @@ struct _widget_context { typedef struct _widget_class widget_class_s; typedef struct _widget_context widget_context_s; +#define WIDGET_APP_EVENT_MAX 5 +static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, }; + static int caller_pid = 0; static widget_app_lifecycle_callback_s *app_ops; static void *app_user_data = NULL; @@ -94,6 +101,25 @@ static widget_class_h class_provider = NULL; static GList *contexts = NULL; static char *viewer_endpoint = NULL; +static void _widget_core_set_appcore_event_cb(void); +static void _widget_core_unset_appcore_event_cb(void); + +static void __free_handler_cb(gpointer data) +{ + if (data) + free(data); +} + +static void __free_handler_list(void) +{ + int i; + + for (i = 0; i < WIDGET_APP_EVENT_MAX; i++) { + g_list_free_full(handler_list[i], __free_handler_cb); + handler_list[i] = NULL; + } +} + static inline bool _is_widget_feature_enabled(void) { static bool feature = false; @@ -132,10 +158,54 @@ static widget_context_s *__find_context_by_id(const char *id) return ret->data; } +static gint __comp_by_win(gconstpointer a, gconstpointer b) +{ + int win = GPOINTER_TO_INT(b); + widget_context_s *wc = (widget_context_s *)a; + + return (wc && wc->win_id == win) ? 0 : -1; +} + +static widget_context_s *__find_context_by_win(int win) +{ + GList *ret = g_list_find_custom(contexts, GINT_TO_POINTER(win), __comp_by_win); + + if (ret == NULL) + return NULL; + + return ret->data; +} + +static int __send_lifecycle_event(const char *class_id, const char *instance_id, + int status) +{ + bundle *b = bundle_create(); + int ret; + + if (b == NULL) { + _E("out of memory"); + return -1; + } + + bundle_add_str(b, WIDGET_K_ID, class_id); + bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); + bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int)); + + _D("send lifecycle %s(%d)", instance_id, status); + ret = aul_app_com_send("widget.status", b); + if (ret < 0) + _E("send lifecycle error:%d", ret); + + bundle_free(b); + + return ret; +} + static int __send_update_status(const char *class_id, const char *instance_id, int status, bundle *extra, int internal_only) { bundle *b = extra; + int lifecycle = -1; if (b == NULL) b = bundle_create(); @@ -144,15 +214,142 @@ static int __send_update_status(const char *class_id, const char *instance_id, bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int)); - _E("send update %s(%d) to %s", instance_id, status, viewer_endpoint); + _D("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); + if (extra == NULL) bundle_free(b); return 0; } +static int __instance_resume(widget_class_h handle, const char *id, bundle *b) +{ + widget_context_s *wc = __find_context_by_id(id); + int ret; + + if (wc) { + if (handle->ops.resume) + handle->ops.resume(wc, handle->user_data); + + wc->state = WC_RUNNING; + _D("%s is resumed", id); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_RESUME, NULL, 0); + } else { + _E("context not found: %s", id); + ret = -1; + } + + return ret; +} + +static int __instance_pause(widget_class_h handle, const char *id, bundle *b) +{ + widget_context_s *wc = __find_context_by_id(id); + int ret; + + if (wc) { + if (handle->ops.pause) + handle->ops.pause(wc, handle->user_data); + + wc->state = WC_PAUSED; + _D("%s is paused", id); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_PAUSE, NULL, 0); + } else { + _E("context not found: %s", id); + ret = -1; + } + + return ret; +} + +static int __instance_resize(widget_class_h handle, const char *id, bundle *b) +{ + widget_context_s *wc = __find_context_by_id(id); + int ret; + int w; + int h; + char *w_str = NULL; + char *h_str = NULL; + char *remain = NULL; + + if (wc) { + bundle_get_str(b, WIDGET_K_WIDTH, &w_str); + bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); + + if (w_str) + w = (int)g_ascii_strtoll(w_str, &remain, 10); + else + w = -1; + + if (h_str) + h = (int)g_ascii_strtoll(h_str, &remain, 10); + else + h = -1; + + if (handle->ops.resize) + handle->ops.resize(wc, w, h, handle->user_data); + _D("%s is resized to %dx%d", id, w, h); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL, 0); + } else { + _E("context not found: %s", id); + ret = -1; + } + + return ret; +} + +static int __instance_update(widget_class_h handle, const char *id, bundle *b) +{ + widget_context_s *wc = __find_context_by_id(id); + int ret; + int force; + char *force_str = NULL; + + if (!wc) { + _E("context not found: %s", id); + return -1; + } + + if (handle->ops.update) { + if (b) + bundle_get_str(b, WIDGET_K_FORCE, &force_str); + + if (force_str && strcmp(force_str, "true") == 0) + force = 1; + else + force = 0; + + handle->ops.update(wc, b, force, handle->user_data); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_UPDATE, b, 0); + _D("updated:%s", id); + } + + return ret; +} + static int __instance_create(widget_class_h handle, const char *id, bundle *b) { widget_context_s *wc = NULL; @@ -169,6 +366,7 @@ static int __instance_create(widget_class_h handle, const char *id, bundle *b) wc->id = g_strdup(id); wc->provider = handle; wc->win = NULL; + wc->win_id = -1; wc->content = bundle_dup(b); bundle_get_str(b, WIDGET_K_WIDTH, &w_str); @@ -266,9 +464,9 @@ static void __control(bundle *b) if (strcmp(operation, "create") == 0) { __instance_create(handle, id, b); } else if (strcmp(operation, "resize") == 0) { - /* TODO */ + __instance_resize(handle, id, b); } else if (strcmp(operation, "update") == 0) { - /* TODO */ + __instance_update(handle, id, b); } else if (strcmp(operation, "destroy") == 0) { bundle_get_str(b, WIDGET_K_REASON, &reason); if (reason) @@ -277,9 +475,9 @@ static void __control(bundle *b) __instance_destroy(handle, id, destroy_type, b); } else if (strcmp(operation, "resume") == 0) { - /* TODO */ + __instance_resume(handle, id, b); } else if (strcmp(operation, "pause") == 0) { - /* TODO */ + __instance_pause(handle, id, b); } return; @@ -288,22 +486,96 @@ error: return; } -static void __show_all() +static void __resume_cb(const char *id, void *data) { - LOGD("resume"); + widget_context_s *cxt = __find_context_by_id(id); + + if (cxt) + __instance_resume(cxt->provider, id, NULL); + else + _E("invalid context id:%s", id); + +} + +static void __pause_cb(const char *id, void *data) +{ + widget_context_s *cxt = __find_context_by_id(id); + + if (cxt) + __instance_pause(cxt->provider, id, NULL); + else + _E("invalid context id:%s", id); +} + +static void __pause_all() +{ + GList *iter = g_list_first(contexts); + + while (iter != NULL) { + widget_context_s *cxt = (widget_context_s *)iter->data; + const char *id = cxt->id; + + switch (cxt->state) { + case WC_READY: + __resume_cb(id, NULL); + __pause_cb(id, NULL); + break; + case WC_RUNNING: + __pause_cb(id, NULL); + break; + } + iter = g_list_next(iter); + } +} + +static void __resume_all() +{ + GList *iter = g_list_first(contexts); + + while (iter != NULL) { + widget_context_s *cxt = (widget_context_s *)iter->data; + const char *id = cxt->id; + + switch (cxt->state) { + case WC_READY: + __resume_cb(id, NULL); + break; + case WC_PAUSED: + __resume_cb(id, NULL); + break; + } + iter = g_list_next(iter); + } } static Eina_Bool __show_cb(void *data, int type, void *event) { Ecore_Wl_Event_Window_Show *ev = event; + widget_context_s *cxt = __find_context_by_win(ev->win); + LOGD("show %d %d", (unsigned int)ev->win, (unsigned int)ev->data[0]); + + if (cxt) + __instance_resume(cxt->provider, cxt->id, NULL); + else + LOGE("unknown window error: %d", ev->win); + return ECORE_CALLBACK_RENEW; } static Eina_Bool __hide_cb(void *data, int type, void *event) { Ecore_Wl_Event_Window_Hide *ev = event; + widget_context_s *cxt = __find_context_by_win(ev->win); + + LOGD("hide %d", (unsigned int)ev->win); + + if (cxt) + __instance_pause(cxt->provider, cxt->id, NULL); + else + LOGE("unknown window error: %d", ev->win); + return ECORE_CALLBACK_RENEW; } @@ -311,6 +583,7 @@ static Eina_Bool __visibility_cb(void *data, int type, void *event) { Ecore_Wl_Event_Window_Visibility_Change *ev = event; LOGD("visiblity change: %d %d", (unsigned int)ev->win, (unsigned int)ev->fully_obscured); + /* this is not working so far*/ return ECORE_CALLBACK_RENEW; } @@ -349,7 +622,7 @@ static int __aul_handler(aul_type type, bundle *b, void *data) __control(b); break; case AUL_RESUME: - __show_all(); + __resume_all(); break; case AUL_TERMINATE: widget_app_exit(); @@ -382,6 +655,25 @@ static char *__get_domain_name(char *appid) return name_token; } +static void __on_poweroff(keynode_t *key, void *data) +{ + int val; + + val = vconf_keynode_get_int(key); + switch (val) { + case VCONFKEY_SYSMAN_POWER_OFF_DIRECT: + case VCONFKEY_SYSMAN_POWER_OFF_RESTART: + _I("power off changed: %d", val); + widget_app_exit(); + break; + case VCONFKEY_SYSMAN_POWER_OFF_NONE: + case VCONFKEY_SYSMAN_POWER_OFF_POPUP: + default: + /* DO NOTHING */ + break; + } +} + extern int _set_i18n(const char *name); static int __before_loop(int argc, char **argv) @@ -458,26 +750,186 @@ static int __before_loop(int argc, char **argv) __add_climsg(); + _widget_core_set_appcore_event_cb(); + class_provider = app_ops->create(app_user_data); if (class_provider == NULL) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "widget_class is NULL"); } + vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, __on_poweroff, NULL); + return WIDGET_ERROR_NONE; } static void __after_loop() { + vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, __on_poweroff); + + __pause_all(); + if (app_ops->terminate) app_ops->terminate(app_user_data); if (viewer_endpoint) free(viewer_endpoint); + _widget_core_unset_appcore_event_cb(); + __free_handler_list(); elm_shutdown(); } +static void __on_low_memory(keynode_t *key, void *data) +{ + int val; + + val = vconf_keynode_get_int(key); + if (val == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) { + app_event_handler_h handler; + struct app_event_info event; + + _I("widget_app_low_memory"); + + event.type = APP_EVENT_LOW_MEMORY; + event.value = (void *)&val; + + GList *iter = g_list_first(handler_list[APP_EVENT_LOW_MEMORY]); + + while (iter) { + handler = (app_event_handler_h) iter->data; + handler->cb(&event, handler->data); + iter = g_list_next(iter); + } + } +} + +static void __on_low_battery(keynode_t *key, void *data) +{ + int val; + + val = vconf_keynode_get_int(key); + if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) { + app_event_handler_h handler; + struct app_event_info event; + + _I("widget_app_low_battery"); + + event.type = APP_EVENT_LOW_BATTERY; + event.value = (void *)&val; + + GList *iter = g_list_first(handler_list[APP_EVENT_LOW_BATTERY]); + + while (iter) { + handler = (app_event_handler_h) iter->data; + handler->cb(&event, handler->data); + iter = g_list_next(iter); + } + } +} + +static void __on_lang_changed(keynode_t *key, void *data) +{ + char *val; + + _update_lang(); + val = vconf_keynode_get_str(key); + + app_event_handler_h handler; + struct app_event_info event; + + _I("widget_app_lang_changed"); + + event.type = APP_EVENT_LANGUAGE_CHANGED; + event.value = (void *)val; + + GList *iter = g_list_first(handler_list[APP_EVENT_LANGUAGE_CHANGED]); + + while (iter) { + handler = (app_event_handler_h) iter->data; + handler->cb(&event, handler->data); + iter = g_list_next(iter); + } +} + +static void __on_region_changed(keynode_t *key, void *data) +{ + char *val; + + _update_region(); + val = vconf_keynode_get_str(key); + + app_event_handler_h handler; + struct app_event_info event; + + _I("widget_app_region_changed"); + + event.type = APP_EVENT_REGION_FORMAT_CHANGED; + event.value = (void *)val; + + GList *iter = g_list_first(handler_list[APP_EVENT_REGION_FORMAT_CHANGED]); + + while (iter) { + handler = (app_event_handler_h) iter->data; + handler->cb(&event, handler->data); + iter = g_list_next(iter); + } +} + +static void __register_event(int event_type) +{ + switch (event_type) { + case APP_EVENT_LOW_MEMORY: + vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL); + break; + + case APP_EVENT_LOW_BATTERY: + vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL); + break; + + case APP_EVENT_LANGUAGE_CHANGED: + vconf_notify_key_changed(VCONFKEY_LANGSET, __on_lang_changed, NULL); + break; + + case APP_EVENT_REGION_FORMAT_CHANGED: + vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_changed, NULL); + break; + } +} + +static void __unregister_event(int event_type) +{ + switch (event_type) { + case APP_EVENT_LOW_MEMORY: + vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory); + break; + + case APP_EVENT_LOW_BATTERY: + vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery); + break; + + case APP_EVENT_LANGUAGE_CHANGED: + vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_lang_changed); + break; + + case APP_EVENT_REGION_FORMAT_CHANGED: + vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_changed); + break; + } +} + +static void _widget_core_set_appcore_event_cb(void) +{ + __register_event(APP_EVENT_LANGUAGE_CHANGED); + __register_event(APP_EVENT_REGION_FORMAT_CHANGED); +} + +static void _widget_core_unset_appcore_event_cb(void) +{ + __unregister_event(APP_EVENT_LANGUAGE_CHANGED); + __unregister_event(APP_EVENT_REGION_FORMAT_CHANGED); +} + EXPORT_API int widget_app_main(int argc, char **argv, widget_app_lifecycle_callback_s *callback, void *user_data) { @@ -544,7 +996,6 @@ static gboolean __finish_event_cb(gpointer user_data) break; } - return FALSE; } @@ -591,45 +1042,86 @@ EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data) } EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler, - app_event_type_e event_type, app_event_cb callback, - void *user_data) + app_event_type_e event_type, app_event_cb callback, + void *user_data) { - if (!_is_widget_feature_enabled()) { - _E("not supported"); + int r; + bool feature; + + r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature); + if (r < 0) + return WIDGET_ERROR_FAULT; + + if (!feature) return WIDGET_ERROR_NOT_SUPPORTED; - } - /* TODO */ - if (!event_handler || !callback) - return WIDGET_ERROR_INVALID_PARAMETER; + app_event_handler_h handler; - switch (event_type) { - case APP_EVENT_LOW_MEMORY: - case APP_EVENT_LOW_BATTERY: - case APP_EVENT_LANGUAGE_CHANGED: - case APP_EVENT_DEVICE_ORIENTATION_CHANGED: - case APP_EVENT_REGION_FORMAT_CHANGED: - case APP_EVENT_SUSPENDED_STATE_CHANGED: + if (event_handler == NULL || callback == NULL) + return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - break; - default: - return WIDGET_ERROR_INVALID_PARAMETER; + if (event_type < APP_EVENT_LOW_MEMORY + || event_type > APP_EVENT_REGION_FORMAT_CHANGED) + return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + if (event_type == APP_EVENT_DEVICE_ORIENTATION_CHANGED) + return widget_app_error(WIDGET_ERROR_NOT_SUPPORTED, __FUNCTION__, NULL); + + GList *iter = g_list_first(handler_list[event_type]); + + while (iter) { + handler = (app_event_handler_h) iter->data; + + if (handler->cb == callback) + return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + iter = g_list_next(iter); } + handler = calloc(1, sizeof(struct app_event_handler)); + if (!handler) + return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + + if (g_list_length(handler_list[event_type]) == 0) + __register_event(event_type); + + handler->type = event_type; + handler->cb = callback; + handler->data = user_data; + handler_list[event_type] = g_list_append(handler_list[event_type], handler); + + *event_handler = handler; + return WIDGET_ERROR_NONE; } EXPORT_API int widget_app_remove_event_handler(app_event_handler_h event_handler) { - if (!_is_widget_feature_enabled()) { - _E("not supported"); + int r; + bool feature; + + r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature); + if (r < 0) + return WIDGET_ERROR_FAULT; + + if (!feature) return WIDGET_ERROR_NOT_SUPPORTED; - } - /* TODO */ - if (!event_handler) - return WIDGET_ERROR_INVALID_PARAMETER; + app_event_type_e type; + + if (event_handler == NULL) + return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + type = event_handler->type; + if (type < APP_EVENT_LOW_MEMORY || type > APP_EVENT_REGION_FORMAT_CHANGED) + return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + handler_list[type] = g_list_remove(handler_list[type], event_handler); + free(event_handler); + + if (g_list_length(handler_list[type]) == 0) + __unregister_event(type); return WIDGET_ERROR_NONE; } @@ -684,6 +1176,9 @@ EXPORT_API int widget_app_get_elm_win(widget_context_h context, *win = ret_win; cxt->win = ret_win; + cxt->win_id = ecore_wl_window_id_get(wl_win); + + _D("window created: %d", cxt->win_id); return WIDGET_ERROR_NONE; } @@ -796,7 +1291,7 @@ EXPORT_API int widget_app_context_set_content_info(widget_context_h context, return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL); ret = __send_update_status(class_id, context->id, - WIDGET_INSTANCE_EVENT_UPDATE, content_info, true); + WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info, true); if (ret < 0) { _E("failed to send content info: %s of %s (%d)", context->id, -- 2.7.4 From 52c08435887de74da64c77caee7adad0b67cf54a Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Fri, 20 May 2016 21:21:59 +0900 Subject: [PATCH 04/16] Implement window event callback Change-Id: I3792b4762b14ec655943d44d7d06291fc7a65e1d Signed-off-by: Daehyeon Jung --- src/widget_app.c | 216 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 147 insertions(+), 69 deletions(-) diff --git a/src/widget_app.c b/src/widget_app.c index 491ca1c..c8e3764 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -246,19 +246,29 @@ static int __instance_resume(widget_class_h handle, const char *id, bundle *b) widget_context_s *wc = __find_context_by_id(id); int ret; - if (wc) { - if (handle->ops.resume) - handle->ops.resume(wc, handle->user_data); - - wc->state = WC_RUNNING; - _D("%s is resumed", id); - ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_RESUME, NULL, 0); - } else { + if (!wc) { _E("context not found: %s", id); - ret = -1; + return -1; + } + + if (wc->state == WC_RUNNING) { + _D("%s is already in running state", id); + return 0; } + if (wc->state == WC_TERMINATED) { + _D("%s is in terminated state", id); + return 0; + } + + if (handle->ops.resume) + handle->ops.resume(wc, handle->user_data); + + wc->state = WC_RUNNING; + _D("%s is resumed", id); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_RESUME, NULL, 0); + return ret; } @@ -267,56 +277,49 @@ static int __instance_pause(widget_class_h handle, const char *id, bundle *b) widget_context_s *wc = __find_context_by_id(id); int ret; - if (wc) { - if (handle->ops.pause) - handle->ops.pause(wc, handle->user_data); - - wc->state = WC_PAUSED; - _D("%s is paused", id); - ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_PAUSE, NULL, 0); - } else { + if (!wc) { _E("context not found: %s", id); - ret = -1; + return -1; } + if (wc->state == WC_PAUSED) { + _D("%s is already in paused state", id); + return 0; + } + + if (wc->state == WC_TERMINATED) { + _D("%s is in terminated state", id); + return 0; + } + + if (handle->ops.pause) + handle->ops.pause(wc, handle->user_data); + + wc->state = WC_PAUSED; + _D("%s is paused", id); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_PAUSE, NULL, 0); + return ret; } -static int __instance_resize(widget_class_h handle, const char *id, bundle *b) +static int __instance_resize(widget_class_h handle, const char *id, int w, int h, bundle *b) { widget_context_s *wc = __find_context_by_id(id); int ret; - int w; - int h; - char *w_str = NULL; - char *h_str = NULL; - char *remain = NULL; - - if (wc) { - bundle_get_str(b, WIDGET_K_WIDTH, &w_str); - bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); - if (w_str) - w = (int)g_ascii_strtoll(w_str, &remain, 10); - else - w = -1; - - if (h_str) - h = (int)g_ascii_strtoll(h_str, &remain, 10); - else - h = -1; - - if (handle->ops.resize) - handle->ops.resize(wc, w, h, handle->user_data); - _D("%s is resized to %dx%d", id, w, h); - ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL, 0); - } else { + if (!wc) { _E("context not found: %s", id); - ret = -1; + return -1; } + if (handle->ops.resize) + handle->ops.resize(wc, w, h, handle->user_data); + + _D("%s is resized to %dx%d", id, w, h); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL, 0); + return ret; } @@ -393,23 +396,24 @@ static int __instance_destroy(widget_class_h handle, const char *id, widget_context_s *wc = __find_context_by_id(id); int ret = 0; - if (wc) { - wc->state = WC_TERMINATED; - handle->ops.destroy(wc, (widget_app_destroy_type_e)reason, b, - handle->user_data); + if (!wc) { + _E("could not find widget obj: %s", id); + return WIDGET_ERROR_INVALID_PARAMETER; + } - ret = __send_update_status(handle->classid, id, - WIDGET_INSTANCE_EVENT_TERMINATE, b, 0); + wc->state = WC_TERMINATED; + handle->ops.destroy(wc, (widget_app_destroy_type_e)reason, b, + handle->user_data); - contexts = g_list_remove(contexts, wc); + ret = __send_update_status(handle->classid, id, + WIDGET_INSTANCE_EVENT_TERMINATE, b, 0); - if (wc->id) - free(wc->id); - free(wc); - } else { - _E("could not find widget obj: %s", id); - ret = WIDGET_ERROR_INVALID_PARAMETER; - } + contexts = g_list_remove(contexts, wc); + + if (wc->id) + free(wc->id); + + free(wc); return ret; } @@ -432,6 +436,38 @@ static widget_class_h __find_class_handler(const char *class_id, return NULL; } +static void __resize_window(char *id, bundle *b) +{ + widget_context_s *wc = __find_context_by_id(id); + char *w_str = NULL; + char *h_str = NULL; + char *remain = NULL; + int w; + int h; + + bundle_get_str(b, WIDGET_K_WIDTH, &w_str); + bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); + + if (w_str) { + w = (int)g_ascii_strtoll(w_str, &remain, 10); + } else { + _E("unable to get width"); + return; + } + + if (h_str) { + h = (int)g_ascii_strtoll(h_str, &remain, 10); + } else { + _E("unable to get height"); + return; + } + + if (wc->win) + evas_object_resize(wc->win, w, h); + else + _E("unable to find window of %d", wc->id); +} + static void __control(bundle *b) { char *class_id = NULL; @@ -464,7 +500,7 @@ static void __control(bundle *b) if (strcmp(operation, "create") == 0) { __instance_create(handle, id, b); } else if (strcmp(operation, "resize") == 0) { - __instance_resize(handle, id, b); + __resize_window(id, b); } else if (strcmp(operation, "update") == 0) { __instance_update(handle, id, b); } else if (strcmp(operation, "destroy") == 0) { @@ -490,21 +526,24 @@ static void __resume_cb(const char *id, void *data) { widget_context_s *cxt = __find_context_by_id(id); - if (cxt) - __instance_resume(cxt->provider, id, NULL); - else + if (!cxt) { _E("invalid context id:%s", id); + return; + } + __instance_resume(cxt->provider, id, NULL); } static void __pause_cb(const char *id, void *data) { widget_context_s *cxt = __find_context_by_id(id); - if (cxt) - __instance_pause(cxt->provider, id, NULL); - else + if (!cxt) { _E("invalid context id:%s", id); + return; + } + + __instance_pause(cxt->provider, id, NULL); } static void __pause_all() @@ -582,8 +621,23 @@ static Eina_Bool __hide_cb(void *data, int type, void *event) static Eina_Bool __visibility_cb(void *data, int type, void *event) { Ecore_Wl_Event_Window_Visibility_Change *ev = event; + widget_context_s *cxt = __find_context_by_win(ev->win); + LOGD("visiblity change: %d %d", (unsigned int)ev->win, (unsigned int)ev->fully_obscured); - /* this is not working so far*/ + + if (!cxt) { + LOGE("unknown window error: %d", ev->win); + return ECORE_CALLBACK_RENEW; + } + + if (cxt->state == WC_PAUSED && ev->fully_obscured == 0) { + __instance_resume(cxt->provider, cxt->id, NULL); + } else if (cxt->state == WC_RUNNING && ev->fully_obscured == 1) { + __instance_pause(cxt->provider, cxt->id, NULL); + } else { + LOGD("cxt:%s state:%d obscured:%d", cxt->id, cxt->state, ev->fully_obscured); + } + return ECORE_CALLBACK_RENEW; } @@ -593,12 +647,32 @@ static Eina_Bool __lower_cb(void *data, int type, void *event) return ECORE_CALLBACK_RENEW; } +static Eina_Bool __configure_cb(void *data, int type, void *event) +{ + Ecore_Wl_Event_Window_Configure *ev = event; + widget_context_s *cxt = __find_context_by_win(ev->win); + + LOGD("configure: %d %d", ev->w, ev->h); + + if (!cxt) { + LOGE("unknown window error: %d", ev->win); + return ECORE_CALLBACK_RENEW; + } + + if (cxt->state == WC_PAUSED || cxt->state == WC_RUNNING) + __instance_resize(cxt->provider, cxt->id, ev->w, ev->h, NULL); + LOGD("cxt:%s resized to %dx%d", cxt->id, ev->w, ev->h); + + return ECORE_CALLBACK_RENEW; +} + static void __add_climsg() { ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, NULL); ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, NULL); ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, __visibility_cb, NULL); ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __lower_cb, NULL); + ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE, __configure_cb, NULL); } static int __aul_handler(aul_type type, bundle *b, void *data) @@ -703,9 +777,13 @@ static int __before_loop(int argc, char **argv) if (xdg_runtime_dir) setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1); + _D("xdg_runtime_dir:%s", xdg_runtime_dir); + if (wayland_display) setenv("WAYLAND_DISPLAY", wayland_display, 1); + _D("wayland_display:%s", wayland_display); + bundle_free(kb); kb = NULL; } else { -- 2.7.4 From c8b6d7c69aa6227d6f288349379c89f9a20fb48e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 14 Jun 2016 15:13:21 +0900 Subject: [PATCH 05/16] Fix getting locale resource path Change-Id: I7583298a629d57d3df27dccbc9ef8a1420b7021e Signed-off-by: Hwankyu Jhun --- src/widget-i18n.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/widget-i18n.c b/src/widget-i18n.c index 91804e2..c739dd8 100755 --- a/src/widget-i18n.c +++ b/src/widget-i18n.c @@ -31,6 +31,8 @@ #include "widget-log.h" #include "widget-private.h" +#define PATH_LOCALE "locale" + void _update_lang(void) { char *r; @@ -80,10 +82,27 @@ void _update_region(void) } } +static int __get_locale_resource_dir(char *locale_dir, int size) +{ + const char *res_path; + + res_path = aul_get_app_resource_path(); + if (res_path == NULL) { + _E("Failed to get resource path"); + return -1; + } + + snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path); + if (access(locale_dir, R_OK) != 0) + return -1; + + return 0; +} + static int __set_i18n(const char *domain) { char *r; - char dirname[PATH_MAX] = {0, }; + char locale_dir[PATH_MAX]; char *lang; if (domain == NULL) { @@ -91,8 +110,8 @@ static int __set_i18n(const char *domain) return -1; } - snprintf(dirname, PATH_MAX, "%s/res/locale", aul_get_app_root_path()); - _D("locale dir: %s", dirname); + __get_locale_resource_dir(locale_dir, sizeof(locale_dir)); + _D("locale dir: %s", locale_dir); r = setlocale(LC_ALL, ""); /* if locale is not set properly, try again to set as language base */ @@ -108,7 +127,7 @@ static int __set_i18n(const char *domain) if (r == NULL) _E("appcore: setlocale() error"); - r = bindtextdomain(domain, dirname); + r = bindtextdomain(domain, locale_dir); if (r == NULL) _E("appcore: bindtextdomain() error"); -- 2.7.4 From d6f67ac711930f8789599f5c8f09746025ebbbba Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Fri, 17 Jun 2016 14:22:16 +0900 Subject: [PATCH 06/16] fix dereference wrong ptr and uninitialized val Change-Id: Ib47aaf212970c533912ac2cd08f7a7324ce5897f --- src/widget_app.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/widget_app.c b/src/widget_app.c index c8e3764..ba14ac9 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -326,7 +326,7 @@ static int __instance_resize(widget_class_h handle, const char *id, int w, int h static int __instance_update(widget_class_h handle, const char *id, bundle *b) { widget_context_s *wc = __find_context_by_id(id); - int ret; + int ret = 0; int force; char *force_str = NULL; @@ -445,6 +445,11 @@ static void __resize_window(char *id, bundle *b) int w; int h; + if (!wc) { + _E("can not find instance: %s", id); + return; + } + bundle_get_str(b, WIDGET_K_WIDTH, &w_str); bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); -- 2.7.4 From 0d8c91b6bf1dc48314bf49345b058dd34b2c8b7b Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Thu, 23 Jun 2016 12:59:16 +0900 Subject: [PATCH 07/16] fix update content info - from 2.x implementation, widget internally uses content_info as string. - in initial 3.0 impemenation of widget tried use bundle as is, but using bundle with content_info together may involves security issues and may introduce unintended bugs that developer expects bundle contains only their data. Change-Id: I98629753ab7141a4bbe6fd0299c8068a0e33a748 Signed-off-by: Daehyeon Jung --- src/widget_app.c | 311 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 178 insertions(+), 133 deletions(-) diff --git a/src/widget_app.c b/src/widget_app.c index ba14ac9..2018931 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -57,6 +57,11 @@ typedef enum _widget_obj_state_e { WC_TERMINATED = 3 } widget_obj_state_e; +enum { + UPDATE_LOCAL = 0, + UPDATE_ALL = 1, +}; + struct _widget_class { void *user_data; widget_instance_lifecycle_callback_s ops; @@ -83,7 +88,7 @@ struct _widget_context { void *tag; Evas_Object *win; int win_id; - bundle *content; + char *content; widget_instance_lifecycle_callback_s ops; }; @@ -93,13 +98,14 @@ typedef struct _widget_context widget_context_s; #define WIDGET_APP_EVENT_MAX 5 static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, }; -static int caller_pid = 0; +static int caller_pid; static widget_app_lifecycle_callback_s *app_ops; -static void *app_user_data = NULL; -static char *appid = NULL; -static widget_class_h class_provider = NULL; -static GList *contexts = NULL; -static char *viewer_endpoint = NULL; +static void *app_user_data; +static char *appid; +static widget_class_h class_provider; +static GList *contexts; +static char *viewer_endpoint; +static int exit_called; static void _widget_core_set_appcore_event_cb(void); static void _widget_core_unset_appcore_event_cb(void); @@ -202,18 +208,28 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id, } static int __send_update_status(const char *class_id, const char *instance_id, - int status, bundle *extra, int internal_only) + int status, bundle *extra) { - bundle *b = extra; + bundle *b; int lifecycle = -1; + bundle_raw *raw = NULL; + int len; - if (b == NULL) - b = bundle_create(); + b = bundle_create(); + if (!b) { + _E("out of memory"); + return -1; + } bundle_add_str(b, WIDGET_K_ID, class_id); bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int)); + if (extra) { + bundle_encode(extra, &raw, &len); + bundle_add_str(b, WIDGET_K_CONTENT_INFO, (const char *)raw); + } + _D("send update %s(%d) to %s", instance_id, status, viewer_endpoint); aul_app_com_send(viewer_endpoint, b); @@ -235,13 +251,14 @@ static int __send_update_status(const char *class_id, const char *instance_id, if (lifecycle > -1) __send_lifecycle_event(class_id, instance_id, lifecycle); - if (extra == NULL) - bundle_free(b); + bundle_free(b); + if (raw) + free(raw); return 0; } -static int __instance_resume(widget_class_h handle, const char *id, bundle *b) +static int __instance_resume(widget_class_h handle, const char *id, int send_update) { widget_context_s *wc = __find_context_by_id(id); int ret; @@ -266,13 +283,17 @@ static int __instance_resume(widget_class_h handle, const char *id, bundle *b) wc->state = WC_RUNNING; _D("%s is resumed", id); - ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_RESUME, NULL, 0); + if (send_update) { + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_RESUME, NULL); + } else { + ret = 0; + } return ret; } -static int __instance_pause(widget_class_h handle, const char *id, bundle *b) +static int __instance_pause(widget_class_h handle, const char *id, int send_update) { widget_context_s *wc = __find_context_by_id(id); int ret; @@ -297,13 +318,17 @@ static int __instance_pause(widget_class_h handle, const char *id, bundle *b) wc->state = WC_PAUSED; _D("%s is paused", id); - ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_PAUSE, NULL, 0); + if (send_update) { + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_PAUSE, NULL); + } else { + ret = 0; + } return ret; } -static int __instance_resize(widget_class_h handle, const char *id, int w, int h, bundle *b) +static int __instance_resize(widget_class_h handle, const char *id, int w, int h) { widget_context_s *wc = __find_context_by_id(id); int ret; @@ -318,48 +343,42 @@ static int __instance_resize(widget_class_h handle, const char *id, int w, int h _D("%s is resized to %dx%d", id, w, h); ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL, 0); + WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL); return ret; } -static int __instance_update(widget_class_h handle, const char *id, bundle *b) +static int __instance_update(widget_class_h handle, const char *id, int force, const char *content) { widget_context_s *wc = __find_context_by_id(id); int ret = 0; - int force; - char *force_str = NULL; - + bundle *b = NULL; if (!wc) { _E("context not found: %s", id); return -1; } - if (handle->ops.update) { - if (b) - bundle_get_str(b, WIDGET_K_FORCE, &force_str); - - if (force_str && strcmp(force_str, "true") == 0) - force = 1; - else - force = 0; + if (content) + b = bundle_decode((const bundle_raw *)content, strlen(content)); + if (handle->ops.update) { handle->ops.update(wc, b, force, handle->user_data); ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_UPDATE, b, 0); + WIDGET_INSTANCE_EVENT_UPDATE, NULL); _D("updated:%s", id); } + if (b) + bundle_free(b); + return ret; } -static int __instance_create(widget_class_h handle, const char *id, bundle *b) +static int __instance_create(widget_class_h handle, const char *id, const char *content, int w, int h) { widget_context_s *wc = NULL; - int w = 0, h = 0; - char *w_str = NULL, *h_str = NULL; - char *remain = NULL; int ret = 0; + bundle *content_info = NULL; wc = (widget_context_s *)malloc(sizeof(widget_context_s)); if (!wc) @@ -371,30 +390,30 @@ static int __instance_create(widget_class_h handle, const char *id, bundle *b) wc->win = NULL; wc->win_id = -1; - wc->content = bundle_dup(b); - bundle_get_str(b, WIDGET_K_WIDTH, &w_str); - bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); - - if (w_str) - w = (int)g_ascii_strtoll(w_str, &remain, 10); - - if (h_str) - h = (int)g_ascii_strtoll(h_str, &remain, 10); + if (content) { + wc->content = strdup(content); + content_info = bundle_decode((const bundle_raw *)content, strlen(content)); + } contexts = g_list_append(contexts, wc); - handle->ops.create(wc, b, w, h, handle->user_data); + handle->ops.create(wc, content_info, w, h, handle->user_data); ret = __send_update_status(handle->classid, wc->id, - WIDGET_INSTANCE_EVENT_CREATE, b, 0); + WIDGET_INSTANCE_EVENT_CREATE, NULL); + + if (content_info) + bundle_free(content_info); return ret; } static int __instance_destroy(widget_class_h handle, const char *id, - widget_destroy_type_e reason, bundle *b) + widget_app_destroy_type_e reason, int send_update) { widget_context_s *wc = __find_context_by_id(id); int ret = 0; + int event = WIDGET_INSTANCE_EVENT_TERMINATE; + bundle *content_info; if (!wc) { _E("could not find widget obj: %s", id); @@ -402,19 +421,39 @@ static int __instance_destroy(widget_class_h handle, const char *id, } wc->state = WC_TERMINATED; - handle->ops.destroy(wc, (widget_app_destroy_type_e)reason, b, + if (wc->content) + content_info = bundle_decode((const bundle_raw *)wc->content, strlen(wc->content)); + else + content_info = bundle_create(); + + handle->ops.destroy(wc, reason, content_info, handle->user_data); - ret = __send_update_status(handle->classid, id, - WIDGET_INSTANCE_EVENT_TERMINATE, b, 0); + if (reason == WIDGET_APP_DESTROY_TYPE_PERMANENT) { + event = WIDGET_INSTANCE_EVENT_DESTROY; + } else { + ret = __send_update_status(handle->classid, id, + WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info); + } + + if (content_info) + bundle_free(content_info); + + ret = __send_update_status(handle->classid, id, event, NULL); contexts = g_list_remove(contexts, wc); if (wc->id) free(wc->id); + if (wc->content) + free(wc->content); + free(wc); + if (contexts == NULL && !exit_called) /* all instance destroyed */ + widget_app_exit(); + return ret; } @@ -436,37 +475,15 @@ static widget_class_h __find_class_handler(const char *class_id, return NULL; } -static void __resize_window(char *id, bundle *b) +static void __resize_window(char *id, int w, int h) { widget_context_s *wc = __find_context_by_id(id); - char *w_str = NULL; - char *h_str = NULL; - char *remain = NULL; - int w; - int h; if (!wc) { _E("can not find instance: %s", id); return; } - bundle_get_str(b, WIDGET_K_WIDTH, &w_str); - bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); - - if (w_str) { - w = (int)g_ascii_strtoll(w_str, &remain, 10); - } else { - _E("unable to get width"); - return; - } - - if (h_str) { - h = (int)g_ascii_strtoll(h_str, &remain, 10); - } else { - _E("unable to get height"); - return; - } - if (wc->win) evas_object_resize(wc->win, w, h); else @@ -478,11 +495,16 @@ static void __control(bundle *b) char *class_id = NULL; char *id = NULL; char *operation = NULL; - char *reason = NULL; + char *content = NULL; + char *w_str = NULL; + char *h_str = NULL; + int w = 0; + int h = 0; char *remain = NULL; - int destroy_type = WIDGET_DESTROY_TYPE_DEFAULT; - + int force; + char *force_str = NULL; widget_class_h handle = NULL; + bundle_get_str(b, WIDGET_K_CLASS, &class_id); /* for previous version compatibility, use appid for default class id */ if (class_id == NULL) @@ -502,23 +524,36 @@ static void __control(bundle *b) goto error; } + bundle_get_str(b, WIDGET_K_FORCE, &force_str); + + if (force_str && strcmp(force_str, "true") == 0) + force = 1; + else + force = 0; + + bundle_get_str(b, WIDGET_K_CONTENT_INFO, &content); + bundle_get_str(b, WIDGET_K_WIDTH, &w_str); + bundle_get_str(b, WIDGET_K_HEIGHT, &h_str); + if (w_str) + w = (int)g_ascii_strtoll(w_str, &remain, 10); + + if (h_str) + h = (int)g_ascii_strtoll(h_str, &remain, 10); + if (strcmp(operation, "create") == 0) { - __instance_create(handle, id, b); + __instance_create(handle, id, content, w, h); } else if (strcmp(operation, "resize") == 0) { - __resize_window(id, b); + __resize_window(id, w, h); } else if (strcmp(operation, "update") == 0) { - __instance_update(handle, id, b); + __instance_update(handle, id, force, content); } else if (strcmp(operation, "destroy") == 0) { - bundle_get_str(b, WIDGET_K_REASON, &reason); - if (reason) - destroy_type = (int)g_ascii_strtoll(reason, &remain, - 10); - - __instance_destroy(handle, id, destroy_type, b); + __instance_destroy(handle, id, WIDGET_APP_DESTROY_TYPE_PERMANENT, UPDATE_ALL); } else if (strcmp(operation, "resume") == 0) { - __instance_resume(handle, id, b); + __instance_resume(handle, id, UPDATE_ALL); } else if (strcmp(operation, "pause") == 0) { - __instance_pause(handle, id, b); + __instance_pause(handle, id, UPDATE_ALL); + } else if (strcmp(operation, "terminate") == 0) { + __instance_destroy(handle, id, WIDGET_APP_DESTROY_TYPE_TEMPORARY, UPDATE_ALL); } return; @@ -527,71 +562,64 @@ error: return; } -static void __resume_cb(const char *id, void *data) +static void __pause_all(int send_update) { - widget_context_s *cxt = __find_context_by_id(id); - - if (!cxt) { - _E("invalid context id:%s", id); - return; - } - - __instance_resume(cxt->provider, id, NULL); -} + GList *iter = g_list_first(contexts); -static void __pause_cb(const char *id, void *data) -{ - widget_context_s *cxt = __find_context_by_id(id); + while (iter != NULL) { + widget_context_s *cxt = (widget_context_s *)iter->data; - if (!cxt) { - _E("invalid context id:%s", id); - return; + switch (cxt->state) { + case WC_READY: + __instance_resume(cxt->provider, cxt->id, send_update); + __instance_pause(cxt->provider, cxt->id, send_update); + break; + case WC_RUNNING: + __instance_pause(cxt->provider, cxt->id, send_update); + break; + } + iter = g_list_next(iter); } - - __instance_pause(cxt->provider, id, NULL); } -static void __pause_all() +static void __resume_all(int send_update) { GList *iter = g_list_first(contexts); while (iter != NULL) { widget_context_s *cxt = (widget_context_s *)iter->data; - const char *id = cxt->id; switch (cxt->state) { case WC_READY: - __resume_cb(id, NULL); - __pause_cb(id, NULL); + __instance_resume(cxt->provider, cxt->id, send_update); break; - case WC_RUNNING: - __pause_cb(id, NULL); + case WC_PAUSED: + __instance_resume(cxt->provider, cxt->id, send_update); break; } iter = g_list_next(iter); } } -static void __resume_all() +static void __destroy_all(int reason, int send_update) { GList *iter = g_list_first(contexts); + __pause_all(send_update); + while (iter != NULL) { widget_context_s *cxt = (widget_context_s *)iter->data; - const char *id = cxt->id; switch (cxt->state) { - case WC_READY: - __resume_cb(id, NULL); - break; case WC_PAUSED: - __resume_cb(id, NULL); + __instance_destroy(cxt->provider, cxt->id, reason, send_update); break; } iter = g_list_next(iter); } } + static Eina_Bool __show_cb(void *data, int type, void *event) { Ecore_Wl_Event_Window_Show *ev = event; @@ -600,7 +628,7 @@ static Eina_Bool __show_cb(void *data, int type, void *event) LOGD("show %d %d", (unsigned int)ev->win, (unsigned int)ev->data[0]); if (cxt) - __instance_resume(cxt->provider, cxt->id, NULL); + __instance_resume(cxt->provider, cxt->id, UPDATE_ALL); else LOGE("unknown window error: %d", ev->win); @@ -616,7 +644,7 @@ static Eina_Bool __hide_cb(void *data, int type, void *event) LOGD("hide %d", (unsigned int)ev->win); if (cxt) - __instance_pause(cxt->provider, cxt->id, NULL); + __instance_pause(cxt->provider, cxt->id, UPDATE_ALL); else LOGE("unknown window error: %d", ev->win); @@ -636,9 +664,9 @@ static Eina_Bool __visibility_cb(void *data, int type, void *event) } if (cxt->state == WC_PAUSED && ev->fully_obscured == 0) { - __instance_resume(cxt->provider, cxt->id, NULL); + __instance_resume(cxt->provider, cxt->id, UPDATE_ALL); } else if (cxt->state == WC_RUNNING && ev->fully_obscured == 1) { - __instance_pause(cxt->provider, cxt->id, NULL); + __instance_pause(cxt->provider, cxt->id, UPDATE_ALL); } else { LOGD("cxt:%s state:%d obscured:%d", cxt->id, cxt->state, ev->fully_obscured); } @@ -665,7 +693,7 @@ static Eina_Bool __configure_cb(void *data, int type, void *event) } if (cxt->state == WC_PAUSED || cxt->state == WC_RUNNING) - __instance_resize(cxt->provider, cxt->id, ev->w, ev->h, NULL); + __instance_resize(cxt->provider, cxt->id, ev->w, ev->h); LOGD("cxt:%s resized to %dx%d", cxt->id, ev->w, ev->h); return ECORE_CALLBACK_RENEW; @@ -701,7 +729,7 @@ static int __aul_handler(aul_type type, bundle *b, void *data) __control(b); break; case AUL_RESUME: - __resume_all(); + __resume_all(UPDATE_ALL); break; case AUL_TERMINATE: widget_app_exit(); @@ -848,9 +876,11 @@ static int __before_loop(int argc, char **argv) static void __after_loop() { + exit_called = 1; vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, __on_poweroff); - __pause_all(); + __pause_all(UPDATE_LOCAL); + __destroy_all(WIDGET_APP_DESTROY_TYPE_TEMPORARY, UPDATE_ALL); if (app_ops->terminate) app_ops->terminate(app_user_data); @@ -1053,6 +1083,11 @@ EXPORT_API int widget_app_exit(void) return WIDGET_ERROR_NOT_SUPPORTED; } + if (exit_called) + return WIDGET_ERROR_NONE; + + exit_called = 1; + ecore_main_loop_quit(); return WIDGET_ERROR_NONE; @@ -1067,13 +1102,12 @@ static gboolean __finish_event_cb(gpointer user_data) switch (wc->state) { case WC_READY: - - break; + __instance_resume(wc->provider, wc->id, UPDATE_LOCAL); case WC_RUNNING: - - break; + __instance_pause(wc->provider, wc->id, UPDATE_LOCAL); case WC_PAUSED: - + __instance_destroy(wc->provider, wc->id, + WIDGET_DESTROY_TYPE_TEMPORARY, UPDATE_ALL); break; default: break; @@ -1354,6 +1388,8 @@ EXPORT_API int widget_app_context_set_content_info(widget_context_h context, { const char *class_id = NULL; int ret = 0; + bundle_raw *raw = NULL; + int len; if (!_is_widget_feature_enabled()) { _E("not supported"); @@ -1374,7 +1410,16 @@ EXPORT_API int widget_app_context_set_content_info(widget_context_h context, return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL); ret = __send_update_status(class_id, context->id, - WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info, true); + WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info); + + if (context->content) + free(context->content); + + bundle_encode(content_info, &raw, &len); + if (raw) + context->content = strdup((const char *)raw); + else + context->content = NULL; if (ret < 0) { _E("failed to send content info: %s of %s (%d)", context->id, -- 2.7.4 From d80235315bcd8e876cb7ecfef6f345fc6b9dbcad Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Mon, 4 Jul 2016 13:16:35 +0900 Subject: [PATCH 08/16] Initialize widget data structures Uninitialized context->content_info causes crashes Change-Id: I949e6c36dd754713447d32515505aa6640c2b4fb Signed-off-by: Semun Lee --- src/widget_app.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widget_app.c b/src/widget_app.c index 2018931..77ac4dd 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -380,7 +380,7 @@ static int __instance_create(widget_class_h handle, const char *id, const char * int ret = 0; bundle *content_info = NULL; - wc = (widget_context_s *)malloc(sizeof(widget_context_s)); + wc = (widget_context_s *)calloc(1, sizeof(widget_context_s)); if (!wc) return WIDGET_ERROR_OUT_OF_MEMORY; @@ -1316,9 +1316,9 @@ widget_class_h _widget_class_create(widget_class_s *prev, const char *class_id, return NULL; } - wc = (widget_class_s *)malloc(sizeof(widget_class_s)); + wc = (widget_class_s *)calloc(1, sizeof(widget_class_s)); if (wc == NULL) { - _E("failed to malloc : %s", __FUNCTION__); + _E("failed to calloc : %s", __FUNCTION__); set_last_result(WIDGET_ERROR_OUT_OF_MEMORY); return NULL; } -- 2.7.4 From d5dd2c37aac691dcbb0a392eb9e7295abeeb15e1 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 8 Jul 2016 14:44:42 +0900 Subject: [PATCH 09/16] Exclude lines from measure coverage Change-Id: Ic58695f8f9859e427b61730dd825c4808bc1b3af Signed-off-by: Hwankyu Jhun --- src/widget-i18n.c | 22 ++++---- src/widget_app.c | 153 ++++++++++++++++++++++++++++++----------------------- src/widget_error.c | 28 +++++----- 3 files changed, 114 insertions(+), 89 deletions(-) diff --git a/src/widget-i18n.c b/src/widget-i18n.c index c739dd8..7fbca1a 100755 --- a/src/widget-i18n.c +++ b/src/widget-i18n.c @@ -43,13 +43,15 @@ void _update_lang(void) r = setlocale(LC_ALL, ""); if (r == NULL) { + /* LCOV_EXCL_START */ r = setlocale(LC_ALL, lang); if (r) _D("*****appcore setlocale=%s\n", r); + /* LCOV_EXCL_STOP */ } free(lang); } else { - _E("failed to get current language for set lang env"); + _E("failed to get current language for set lang env"); /* LCOV_EXCL_LINE */ } } @@ -78,7 +80,7 @@ void _update_region(void) free(region); } else { - _E("failed to get current region format for set region env"); + _E("failed to get current region format for set region env"); /* LCOV_EXCL_LINE */ } } @@ -88,8 +90,8 @@ static int __get_locale_resource_dir(char *locale_dir, int size) res_path = aul_get_app_resource_path(); if (res_path == NULL) { - _E("Failed to get resource path"); - return -1; + _E("Failed to get resource path"); /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path); @@ -106,8 +108,8 @@ static int __set_i18n(const char *domain) char *lang; if (domain == NULL) { - errno = EINVAL; - return -1; + errno = EINVAL; /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } __get_locale_resource_dir(locale_dir, sizeof(locale_dir)); @@ -116,6 +118,7 @@ static int __set_i18n(const char *domain) r = setlocale(LC_ALL, ""); /* if locale is not set properly, try again to set as language base */ if (r == NULL) { + /* LCOV_EXCL_START */ lang = vconf_get_str(VCONFKEY_LANGSET); r = setlocale(LC_ALL, lang); if (r) @@ -123,17 +126,18 @@ static int __set_i18n(const char *domain) if (lang) free(lang); + /* LCOV_EXCL_STOP */ } if (r == NULL) - _E("appcore: setlocale() error"); + _E("appcore: setlocale() error"); /* LCOV_EXCL_LINE */ r = bindtextdomain(domain, locale_dir); if (r == NULL) - _E("appcore: bindtextdomain() error"); + _E("appcore: bindtextdomain() error"); /* LCOV_EXCL_LINE */ r = textdomain(domain); if (r == NULL) - _E("appcore: textdomain() error"); + _E("appcore: textdomain() error"); /* LCOV_EXCL_LINE */ return 0; } diff --git a/src/widget_app.c b/src/widget_app.c index 77ac4dd..608f729 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -138,8 +138,8 @@ static inline bool _is_widget_feature_enabled(void) ret = system_info_get_platform_bool( "http://tizen.org/feature/shell.appwidget", &feature); if (ret != SYSTEM_INFO_ERROR_NONE) { - _E("failed to get system info"); - return false; + _E("failed to get system info"); /* LCOV_EXCL_LINE */ + return false; /* LCOV_EXCL_LINE */ } retrieved = true; @@ -189,8 +189,8 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id, int ret; if (b == NULL) { - _E("out of memory"); - return -1; + _E("out of memory"); /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } bundle_add_str(b, WIDGET_K_ID, class_id); @@ -200,7 +200,7 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id, _D("send lifecycle %s(%d)", instance_id, status); ret = aul_app_com_send("widget.status", b); if (ret < 0) - _E("send lifecycle error:%d", ret); + _E("send lifecycle error:%d", ret); /* LCOV_EXCL_LINE */ bundle_free(b); @@ -217,8 +217,8 @@ static int __send_update_status(const char *class_id, const char *instance_id, b = bundle_create(); if (!b) { - _E("out of memory"); - return -1; + _E("out of memory"); /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } bundle_add_str(b, WIDGET_K_ID, class_id); @@ -264,18 +264,18 @@ static int __instance_resume(widget_class_h handle, const char *id, int send_upd int ret; if (!wc) { - _E("context not found: %s", id); - return -1; + _E("context not found: %s", id); /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } if (wc->state == WC_RUNNING) { - _D("%s is already in running state", id); - return 0; + _D("%s is already in running state", id); /* LCOV_EXCL_LINE */ + return 0; /* LCOV_EXCL_LINE */ } if (wc->state == WC_TERMINATED) { - _D("%s is in terminated state", id); - return 0; + _D("%s is in terminated state", id); /* LCOV_EXCL_LINE */ + return 0; /* LCOV_EXCL_LINE */ } if (handle->ops.resume) @@ -299,18 +299,18 @@ static int __instance_pause(widget_class_h handle, const char *id, int send_upda int ret; if (!wc) { - _E("context not found: %s", id); - return -1; + _E("context not found: %s", id); /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } if (wc->state == WC_PAUSED) { - _D("%s is already in paused state", id); - return 0; + _D("%s is already in paused state", id); /* LCOV_EXCL_LINE */ + return 0; /* LCOV_EXCL_LINE */ } if (wc->state == WC_TERMINATED) { - _D("%s is in terminated state", id); - return 0; + _D("%s is in terminated state", id); /* LCOV_EXCL_LINE */ + return 0; /* LCOV_EXCL_LINE */ } if (handle->ops.pause) @@ -334,8 +334,8 @@ static int __instance_resize(widget_class_h handle, const char *id, int w, int h int ret; if (!wc) { - _E("context not found: %s", id); - return -1; + _E("context not found: %s", id); /* LCOV_EXCL_LINE */ + return -1; /* LCOV_EXCL_LINE */ } if (handle->ops.resize) @@ -348,6 +348,7 @@ static int __instance_resize(widget_class_h handle, const char *id, int w, int h return ret; } +/* LCOV_EXCL_START */ static int __instance_update(widget_class_h handle, const char *id, int force, const char *content) { widget_context_s *wc = __find_context_by_id(id); @@ -373,6 +374,7 @@ static int __instance_update(widget_class_h handle, const char *id, int force, c return ret; } +/* LCOV_EXCL_STOP */ static int __instance_create(widget_class_h handle, const char *id, const char *content, int w, int h) { @@ -416,8 +418,8 @@ static int __instance_destroy(widget_class_h handle, const char *id, bundle *content_info; if (!wc) { - _E("could not find widget obj: %s", id); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("could not find widget obj: %s", id); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */ } wc->state = WC_TERMINATED; @@ -475,6 +477,7 @@ static widget_class_h __find_class_handler(const char *class_id, return NULL; } +/* LCOV_EXCL_START */ static void __resize_window(char *id, int w, int h) { widget_context_s *wc = __find_context_by_id(id); @@ -489,6 +492,7 @@ static void __resize_window(char *id, int w, int h) else _E("unable to find window of %d", wc->id); } +/* LCOV_EXCL_STOP */ static void __control(bundle *b) { @@ -515,7 +519,7 @@ static void __control(bundle *b) handle = __find_class_handler(class_id, class_provider); if (!handle) { - _E("no handle provided: %s", class_id); + _E("no handle provided: %s", class_id); /* LCOV_EXCL_LINE */ goto error; } @@ -582,6 +586,7 @@ static void __pause_all(int send_update) } } +/* LCOV_EXCL_START */ static void __resume_all(int send_update) { GList *iter = g_list_first(contexts); @@ -600,6 +605,7 @@ static void __resume_all(int send_update) iter = g_list_next(iter); } } +/* LCOV_EXCL_STOP */ static void __destroy_all(int reason, int send_update) { @@ -630,7 +636,7 @@ static Eina_Bool __show_cb(void *data, int type, void *event) if (cxt) __instance_resume(cxt->provider, cxt->id, UPDATE_ALL); else - LOGE("unknown window error: %d", ev->win); + LOGE("unknown window error: %d", ev->win); /* LCOV_EXCL_LINE */ return ECORE_CALLBACK_RENEW; } @@ -646,7 +652,7 @@ static Eina_Bool __hide_cb(void *data, int type, void *event) if (cxt) __instance_pause(cxt->provider, cxt->id, UPDATE_ALL); else - LOGE("unknown window error: %d", ev->win); + LOGE("unknown window error: %d", ev->win); /* LCOV_EXCL_LINE */ return ECORE_CALLBACK_RENEW; } @@ -674,11 +680,13 @@ static Eina_Bool __visibility_cb(void *data, int type, void *event) return ECORE_CALLBACK_RENEW; } +/* LCOV_EXCL_START */ static Eina_Bool __lower_cb(void *data, int type, void *event) { LOGD("lower"); return ECORE_CALLBACK_RENEW; } +/* LCOV_EXCL_STOP */ static Eina_Bool __configure_cb(void *data, int type, void *event) { @@ -688,8 +696,8 @@ static Eina_Bool __configure_cb(void *data, int type, void *event) LOGD("configure: %d %d", ev->w, ev->h); if (!cxt) { - LOGE("unknown window error: %d", ev->win); - return ECORE_CALLBACK_RENEW; + LOGE("unknown window error: %d", ev->win); /* LCOV_EXCL_LINE */ + return ECORE_CALLBACK_RENEW; /* LCOV_EXCL_LINE */ } if (cxt->state == WC_PAUSED || cxt->state == WC_RUNNING) @@ -746,15 +754,15 @@ static char *__get_domain_name(char *appid) char *name_token; if (appid == NULL) { - _E("appid is NULL"); - return NULL; + _E("appid is NULL"); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ } name_token = strrchr(appid, '.'); if (name_token == NULL) { - _E("appid is invalid"); - return appid; + _E("appid is invalid"); /* LCOV_EXCL_LINE */ + return appid; /* LCOV_EXCL_LINE */ } name_token++; @@ -762,6 +770,7 @@ static char *__get_domain_name(char *appid) return name_token; } +/* LCOV_EXCL_START */ static void __on_poweroff(keynode_t *key, void *data) { int val; @@ -780,6 +789,7 @@ static void __on_poweroff(keynode_t *key, void *data) break; } } +/* LCOV_EXCL_STOP */ extern int _set_i18n(const char *name); @@ -820,23 +830,27 @@ static int __before_loop(int argc, char **argv) bundle_free(kb); kb = NULL; } else { - _E("failed to get launch argv"); + _E("failed to get launch argv"); /* LCOV_EXCL_LINE */ } elm_init(argc, argv); r = aul_launch_init(__aul_handler, NULL); if (r < 0) { + /* LCOV_EXCL_START */ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "Fail to call the aul_launch_init"); + /* LCOV_EXCL_STOP */ } r = aul_launch_argv_handler(argc, argv); if (r < 0) { + /* LCOV_EXCL_START */ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "Fail to call the aul_launch_argv_handler"); + /* LCOV_EXCL_STOP */ } r = app_get_id(&appid); @@ -846,17 +860,21 @@ static int __before_loop(int argc, char **argv) name = __get_domain_name(appid); if (name == NULL) { + /* LCOV_EXCL_START */ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "Fail to call __get_domain_name"); + /* LCOV_EXCL_STOP */ } r = _set_i18n(name); if (r < 0) { + /* LCOV_EXCL_START */ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "Fail to call _set_i18n"); + /* LCOV_EXCL_STOP */ } __add_climsg(); @@ -1049,8 +1067,8 @@ EXPORT_API int widget_app_main(int argc, char **argv, int r; if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (argc <= 0 || argv == NULL || callback == NULL) @@ -1079,8 +1097,8 @@ EXPORT_API int widget_app_main(int argc, char **argv, EXPORT_API int widget_app_exit(void) { if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (exit_called) @@ -1093,6 +1111,7 @@ EXPORT_API int widget_app_exit(void) return WIDGET_ERROR_NONE; } +/* LCOV_EXCL_START */ static gboolean __finish_event_cb(gpointer user_data) { if (user_data == NULL) @@ -1115,12 +1134,13 @@ static gboolean __finish_event_cb(gpointer user_data) return FALSE; } +/* LCOV_EXCL_STOP */ EXPORT_API int widget_app_terminate_context(widget_context_h context) { if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (context == NULL) @@ -1137,8 +1157,8 @@ EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data) widget_context_s *wc; if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (!cb) @@ -1197,7 +1217,7 @@ EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler, handler = calloc(1, sizeof(struct app_event_handler)); if (!handler) - return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */ if (g_list_length(handler_list[event_type]) == 0) __register_event(event_type); @@ -1246,9 +1266,9 @@ EXPORT_API int widget_app_remove_event_handler(app_event_handler_h EXPORT_API const char *widget_app_get_id(widget_context_h context) { if (!_is_widget_feature_enabled()) { - _E("not supported"); - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); - return NULL; + _E("not supported"); /* LCOV_EXCL_LINE */ + set_last_result(WIDGET_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ } if (!context) { @@ -1268,8 +1288,8 @@ EXPORT_API int widget_app_get_elm_win(widget_context_h context, Ecore_Wl_Window *wl_win; if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (context == NULL || win == NULL) @@ -1278,15 +1298,15 @@ EXPORT_API int widget_app_get_elm_win(widget_context_h context, ret_win = elm_win_add(NULL, cxt->id, ELM_WIN_BASIC); if (ret_win == NULL) { - _E("failed to create window"); - return WIDGET_ERROR_FAULT; + _E("failed to create window"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_FAULT; /* LCOV_EXCL_LINE */ } wl_win = elm_win_wl_window_get(ret_win); if (wl_win == NULL) { - _E("failed to get wayland window"); - evas_object_del(ret_win); - return WIDGET_ERROR_FAULT; + _E("failed to get wayland window"); /* LCOV_EXCL_LINE */ + evas_object_del(ret_win); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_FAULT; /* LCOV_EXCL_LINE */ } ecore_wl_window_class_name_set(wl_win, cxt->id); @@ -1306,8 +1326,8 @@ widget_class_h _widget_class_create(widget_class_s *prev, const char *class_id, widget_class_s *wc; if (!_is_widget_feature_enabled()) { - _E("not supported"); - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); + _E("not supported"); /* LCOV_EXCL_LINE */ + set_last_result(WIDGET_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */ return NULL; } @@ -1318,9 +1338,9 @@ widget_class_h _widget_class_create(widget_class_s *prev, const char *class_id, wc = (widget_class_s *)calloc(1, sizeof(widget_class_s)); if (wc == NULL) { - _E("failed to calloc : %s", __FUNCTION__); - set_last_result(WIDGET_ERROR_OUT_OF_MEMORY); - return NULL; + _E("failed to calloc : %s", __FUNCTION__); /* LCOV_EXCL_LINE */ + set_last_result(WIDGET_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ } wc->classid = strdup(class_id); @@ -1354,8 +1374,8 @@ EXPORT_API widget_class_h widget_app_class_create( EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag) { if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (context == NULL) @@ -1370,8 +1390,8 @@ EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag) EXPORT_API int widget_app_context_get_tag(widget_context_h context, void **tag) { if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (context == NULL || tag == NULL) @@ -1392,8 +1412,8 @@ EXPORT_API int widget_app_context_set_content_info(widget_context_h context, int len; if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (context == NULL || content_info == NULL) @@ -1405,7 +1425,6 @@ EXPORT_API int widget_app_context_set_content_info(widget_context_h context, __FUNCTION__, NULL); class_id = context->provider->classid; - if (class_id == NULL) return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL); @@ -1422,10 +1441,12 @@ EXPORT_API int widget_app_context_set_content_info(widget_context_h context, context->content = NULL; if (ret < 0) { + /* LCOV_EXCL_START */ _E("failed to send content info: %s of %s (%d)", context->id, class_id, ret); return widget_app_error(WIDGET_ERROR_IO_ERROR, __FUNCTION__, NULL); + /* LCOV_EXCL_STOP */ } return WIDGET_ERROR_NONE; @@ -1435,8 +1456,8 @@ EXPORT_API int widget_app_context_set_title(widget_context_h context, const char *title) { if (!_is_widget_feature_enabled()) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + _E("not supported"); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */ } if (!context || !title) diff --git a/src/widget_error.c b/src/widget_error.c index b6a63cc..bbe1549 100755 --- a/src/widget_error.c +++ b/src/widget_error.c @@ -37,33 +37,33 @@ static const char *widget_app_error_to_string(widget_error_e error) case WIDGET_ERROR_INVALID_PARAMETER: return "INVALID_PARAMETER"; case WIDGET_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; + return "OUT_OF_MEMORY"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_RESOURCE_BUSY: - return "RESOURCE_BUSY"; + return "RESOURCE_BUSY"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_PERMISSION_DENIED: - return "PERMISSION_DENIED"; + return "PERMISSION_DENIED"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_CANCELED: - return "CANCELED"; + return "CANCELED"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_IO_ERROR: - return "IO_ERROR"; + return "IO_ERROR"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_TIMED_OUT: - return "TIMED_OUT"; + return "TIMED_OUT"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_NOT_SUPPORTED: - return "NOT_SUPPORTED"; + return "NOT_SUPPORTED"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_FILE_NO_SPACE_ON_DEVICE: - return "FILE_NO_SPACE_ON_DEVICE"; + return "FILE_NO_SPACE_ON_DEVICE"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_FAULT: - return "FAULT"; + return "FAULT"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_ALREADY_EXIST: - return "ALREADY_EXIST"; + return "ALREADY_EXIST"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_ALREADY_STARTED: - return "ALREADY_STARTED"; + return "ALREADY_STARTED"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_NOT_EXIST: - return "NOT_EXIST"; + return "NOT_EXIST"; /* LCOV_EXCL_LINE */ case WIDGET_ERROR_DISABLED: - return "DISABLED"; + return "DISABLED"; /* LCOV_EXCL_LINE */ default: - return "UNKNOWN"; + return "UNKNOWN"; /* LCOV_EXCL_LINE */ } } -- 2.7.4 From 783fbd2f0f9fc204ad9797e3ee964bde37277973 Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Tue, 5 Jul 2016 22:57:11 +0900 Subject: [PATCH 10/16] Fix widget instance update Change-Id: Ia43fdb6fd16e1870ed68fcacb0c2cb26cc9bc60e Signed-off-by: Daehyeon Jung --- src/widget_app.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/src/widget_app.c b/src/widget_app.c index 608f729..9d717ae 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -156,8 +156,12 @@ static gint __comp_by_id(gconstpointer a, gconstpointer b) static widget_context_s *__find_context_by_id(const char *id) { - GList *ret = g_list_find_custom(contexts, id, __comp_by_id); + GList *ret; + if (id == NULL) + return NULL; + + ret = g_list_find_custom(contexts, id, __comp_by_id); if (ret == NULL) return NULL; @@ -228,6 +232,7 @@ static int __send_update_status(const char *class_id, const char *instance_id, 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); } _D("send update %s(%d) to %s", instance_id, status, viewer_endpoint); @@ -349,6 +354,35 @@ static int __instance_resize(widget_class_h handle, const char *id, int w, int h } /* LCOV_EXCL_START */ +static int __instance_update_all(widget_class_h handle, int force, const char *content) +{ + widget_context_s *wc; + int ret = 0; + bundle *b = NULL; + GList *context = contexts; + + if (content) + b = bundle_decode((const bundle_raw *)content, strlen(content)); + + if (handle->ops.update) { + while (context) { + wc = (widget_context_s *)context->data; + handle->ops.update(wc, b, force, handle->user_data); + ret = __send_update_status(handle->classid, wc->id, + WIDGET_INSTANCE_EVENT_UPDATE, NULL); + _D("updated:%s", wc->id); + context = context->next; + } + } + + if (b) + bundle_free(b); + + return ret; +} +/* LCOV_EXCL_STOP */ + +/* LCOV_EXCL_START */ static int __instance_update(widget_class_h handle, const char *id, int force, const char *content) { widget_context_s *wc = __find_context_by_id(id); @@ -399,10 +433,19 @@ static int __instance_create(widget_class_h handle, const char *id, const char * contexts = g_list_append(contexts, wc); - handle->ops.create(wc, content_info, w, h, handle->user_data); - ret = __send_update_status(handle->classid, wc->id, + ret = handle->ops.create(wc, content_info, w, h, handle->user_data); + if (ret < 0) { + /* TODO send abort */ + } else { + ret = __send_update_status(handle->classid, wc->id, WIDGET_INSTANCE_EVENT_CREATE, NULL); + if (content == NULL) + content = "NULL"; + + aul_widget_instance_add(handle->classid, id); + } + if (content_info) bundle_free(content_info); @@ -438,6 +481,8 @@ static int __instance_destroy(widget_class_h handle, const char *id, WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info); } + aul_widget_instance_del(handle->classid, id); + if (content_info) bundle_free(content_info); @@ -549,7 +594,11 @@ static void __control(bundle *b) } else if (strcmp(operation, "resize") == 0) { __resize_window(id, w, h); } else if (strcmp(operation, "update") == 0) { - __instance_update(handle, id, force, content); + if (id) + __instance_update(handle, id, force, content); + else + __instance_update_all(handle, force, content); + } else if (strcmp(operation, "destroy") == 0) { __instance_destroy(handle, id, WIDGET_APP_DESTROY_TYPE_PERMANENT, UPDATE_ALL); } else if (strcmp(operation, "resume") == 0) { -- 2.7.4 From d076ceffa92521cd4e6a554212f8efeda4d85da6 Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Fri, 29 Jul 2016 17:01:15 +0900 Subject: [PATCH 11/16] Consider fallback to english for i18n LANGUAGE variable can contain default language information. It will be used when the mo files for the selected language is not available. Change-Id: I3a7fa43cd3736bf29bdbad6a0ea8b3b80fbabf8b Signed-off-by: Semun Lee --- src/widget-i18n.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widget-i18n.c b/src/widget-i18n.c index 7fbca1a..39ae5c5 100755 --- a/src/widget-i18n.c +++ b/src/widget-i18n.c @@ -35,9 +35,12 @@ void _update_lang(void) { + char language[32]; char *r; char *lang = vconf_get_str(VCONFKEY_LANGSET); if (lang) { + snprintf(language, sizeof(language), "%s:en_US:en_GB:en", lang); + setenv("LANGUAGE", language, 1); setenv("LANG", lang, 1); setenv("LC_MESSAGES", lang, 1); -- 2.7.4 From 150f55cbec59b7f623b8381992b8db8a1e66ce87 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Mon, 18 Jul 2016 20:20:33 +0900 Subject: [PATCH 12/16] Add widget app restart logic Change-Id: I54bce1b3e0eba8c919a238c808986fdb814fc277 Signed-off-by: Hyunho Kang --- CMakeLists.txt | 1 + include/widget_app_internal.h | 3 ++ src/widget-private.h | 30 +++++++++++ src/widget_app.c | 60 ++++++++-------------- src/widget_app_internal.c | 114 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 170 insertions(+), 38 deletions(-) create mode 100644 src/widget_app_internal.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 652d965..8e4023a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ SET(APPCORE_WIDGET "capi-appfw-widget-application") SET(SRCS_widget src/widget-i18n.c src/widget_app.c + src/widget_app_internal.c src/widget_error.c ) SET(HEADERS_widget widget_app.h widget_app_efl.h widget_app_internal.h) diff --git a/include/widget_app_internal.h b/include/widget_app_internal.h index 024cfa9..c278012 100644 --- a/include/widget_app_internal.h +++ b/include/widget_app_internal.h @@ -27,6 +27,7 @@ extern "C" { * For in-house applications * */ + typedef struct { struct __pointer { double x; @@ -60,6 +61,8 @@ struct _widget_class_factory_full { }; const widget_class_factory_full_s *widget_app_get_class_factory(void); +int widget_app_restart(); + #ifdef __cplusplus } diff --git a/src/widget-private.h b/src/widget-private.h index ef6d32c..847c099 100644 --- a/src/widget-private.h +++ b/src/widget-private.h @@ -18,12 +18,42 @@ #ifndef __APPCORE_WIDGET_PRIVATE_H__ #define __APPCORE_WIDGET_PRIVATE_H__ +#include + +#include #include #include #include #define FEATURE_SHELL_APPWIDGET "http://tizen.org/feature/shell.appwidget" +struct _widget_class { + void *user_data; + widget_instance_lifecycle_callback_s ops; + char *classid; + struct _widget_class *next; + struct _widget_class *prev; +}; + +struct _widget_context { + char *id; + struct _widget_class *provider; + int state; + void *tag; + Evas_Object *win; + int win_id; + char *content; + widget_instance_lifecycle_callback_s ops; +}; + +typedef struct _widget_context widget_context_s; + +GList *_widget_app_get_contexts(); +int _widget_app_add_context(widget_context_s *wc); +int _widget_app_remove_context(widget_context_s *wc); +int _widget_app_set_viewer_endpoint(char *viewer_endpoint); +char *_widget_app_get_viewer_endpoint(); +int _widget_app_free_viewer_endpoint(); int _set_i18n(const char *domainname); void _update_lang(void); void _update_region(void); diff --git a/src/widget_app.c b/src/widget_app.c index 9d717ae..f90e7ec 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -62,14 +62,6 @@ enum { UPDATE_ALL = 1, }; -struct _widget_class { - void *user_data; - widget_instance_lifecycle_callback_s ops; - char *classid; - struct _widget_class *next; - struct _widget_class *prev; -}; - struct app_event_handler { app_event_type_e type; app_event_cb cb; @@ -81,19 +73,7 @@ struct app_event_info { void *value; }; -struct _widget_context { - char *id; - struct _widget_class *provider; - int state; - void *tag; - Evas_Object *win; - int win_id; - char *content; - widget_instance_lifecycle_callback_s ops; -}; - typedef struct _widget_class widget_class_s; -typedef struct _widget_context widget_context_s; #define WIDGET_APP_EVENT_MAX 5 static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, }; @@ -103,8 +83,6 @@ static widget_app_lifecycle_callback_s *app_ops; static void *app_user_data; static char *appid; static widget_class_h class_provider; -static GList *contexts; -static char *viewer_endpoint; static int exit_called; static void _widget_core_set_appcore_event_cb(void); @@ -157,6 +135,7 @@ static gint __comp_by_id(gconstpointer a, gconstpointer b) static widget_context_s *__find_context_by_id(const char *id) { GList *ret; + GList *contexts = _widget_app_get_contexts(); if (id == NULL) return NULL; @@ -178,6 +157,7 @@ static gint __comp_by_win(gconstpointer a, gconstpointer b) static widget_context_s *__find_context_by_win(int win) { + GList *contexts = _widget_app_get_contexts(); GList *ret = g_list_find_custom(contexts, GINT_TO_POINTER(win), __comp_by_win); if (ret == NULL) @@ -197,9 +177,9 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id, return -1; /* LCOV_EXCL_LINE */ } - bundle_add_str(b, WIDGET_K_ID, class_id); - bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); - bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int)); + 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)); _D("send lifecycle %s(%d)", instance_id, status); ret = aul_app_com_send("widget.status", b); @@ -218,6 +198,7 @@ static int __send_update_status(const char *class_id, const char *instance_id, int lifecycle = -1; bundle_raw *raw = NULL; int len; + char *viewer_endpoint = _widget_app_get_viewer_endpoint(); b = bundle_create(); if (!b) { @@ -225,9 +206,9 @@ static int __send_update_status(const char *class_id, const char *instance_id, return -1; /* LCOV_EXCL_LINE */ } - bundle_add_str(b, WIDGET_K_ID, class_id); - bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); - bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int)); + 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); @@ -359,7 +340,7 @@ static int __instance_update_all(widget_class_h handle, int force, const char *c widget_context_s *wc; int ret = 0; bundle *b = NULL; - GList *context = contexts; + GList *context = _widget_app_get_contexts(); if (content) b = bundle_decode((const bundle_raw *)content, strlen(content)); @@ -431,7 +412,7 @@ static int __instance_create(widget_class_h handle, const char *id, const char * content_info = bundle_decode((const bundle_raw *)content, strlen(content)); } - contexts = g_list_append(contexts, wc); + _widget_app_add_context(wc); ret = handle->ops.create(wc, content_info, w, h, handle->user_data); if (ret < 0) { @@ -460,6 +441,7 @@ static int __instance_destroy(widget_class_h handle, const char *id, int event = WIDGET_INSTANCE_EVENT_TERMINATE; bundle *content_info; + if (!wc) { _E("could not find widget obj: %s", id); /* LCOV_EXCL_LINE */ return WIDGET_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */ @@ -488,7 +470,7 @@ static int __instance_destroy(widget_class_h handle, const char *id, ret = __send_update_status(handle->classid, id, event, NULL); - contexts = g_list_remove(contexts, wc); + _widget_app_remove_context(wc); if (wc->id) free(wc->id); @@ -498,7 +480,7 @@ static int __instance_destroy(widget_class_h handle, const char *id, free(wc); - if (contexts == NULL && !exit_called) /* all instance destroyed */ + if (_widget_app_get_contexts() == NULL && !exit_called) /* all instance destroyed */ widget_app_exit(); return ret; @@ -559,7 +541,7 @@ static void __control(bundle *b) if (class_id == NULL) class_id = appid; - bundle_get_str(b, WIDGET_K_INSTANCE, &id); + bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &id); bundle_get_str(b, WIDGET_K_OPERATION, &operation); handle = __find_class_handler(class_id, class_provider); @@ -617,6 +599,7 @@ error: static void __pause_all(int send_update) { + GList *contexts = _widget_app_get_contexts(); GList *iter = g_list_first(contexts); while (iter != NULL) { @@ -638,6 +621,7 @@ static void __pause_all(int send_update) /* LCOV_EXCL_START */ static void __resume_all(int send_update) { + GList *contexts = _widget_app_get_contexts(); GList *iter = g_list_first(contexts); while (iter != NULL) { @@ -658,6 +642,7 @@ static void __resume_all(int send_update) static void __destroy_all(int reason, int send_update) { + GList *contexts = _widget_app_get_contexts(); GList *iter = g_list_first(contexts); __pause_all(send_update); @@ -849,6 +834,7 @@ static int __before_loop(int argc, char **argv) char *wayland_display = NULL; char *xdg_runtime_dir = NULL; char *name; + char *viewer_endpoint; #if !(GLIB_CHECK_VERSION(2, 36, 0)) g_type_init(); @@ -861,7 +847,7 @@ static int __before_loop(int argc, char **argv) bundle_get_str(kb, WIDGET_K_ENDPOINT, &viewer_endpoint); if (viewer_endpoint) { _E("viewer endpoint :%s", viewer_endpoint); - viewer_endpoint = strdup(viewer_endpoint); + _widget_app_set_viewer_endpoint(viewer_endpoint); } else { _E("endpoint is missing"); } @@ -952,9 +938,7 @@ static void __after_loop() if (app_ops->terminate) app_ops->terminate(app_user_data); - if (viewer_endpoint) - free(viewer_endpoint); - + _widget_app_free_viewer_endpoint(); _widget_core_unset_appcore_event_cb(); __free_handler_list(); elm_shutdown(); @@ -1202,6 +1186,7 @@ EXPORT_API int widget_app_terminate_context(widget_context_h context) EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data) { + GList *contexts = _widget_app_get_contexts(); GList *list; widget_context_s *wc; @@ -1517,4 +1502,3 @@ EXPORT_API int widget_app_context_set_title(widget_context_h context, return WIDGET_ERROR_NONE; } - diff --git a/src/widget_app_internal.c b/src/widget_app_internal.c new file mode 100644 index 0000000..45b56d8 --- /dev/null +++ b/src/widget_app_internal.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "widget_app.h" +#include "widget-log.h" +#include "widget-private.h" +#include "widget_app_internal.h" +#include "widget-private.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_WIDGET_APPLICATION" + +static char *viewer_endpoint = NULL; +static GList *contexts = NULL; + +EXPORT_API int widget_app_restart() +{ + int ret; + int status = AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST; + bundle *kb; + widget_context_s *wc; + char *classid; + + if (contexts == NULL) { + _E("no widget"); + return WIDGET_ERROR_IO_ERROR; + } + wc = (widget_context_s *)contexts->data; + classid = wc->provider->classid; + _D("restart widget classid : %s", classid); + + kb = bundle_create(); + bundle_add_str(kb, AUL_K_WIDGET_ID, classid); + bundle_add_byte(kb, AUL_K_WIDGET_STATUS, &status, sizeof(int)); + ret = aul_app_com_send(viewer_endpoint, kb); + bundle_free(kb); + if (ret != AUL_R_OK) { + _E("failed to kill app"); + return WIDGET_ERROR_IO_ERROR; + } + return WIDGET_ERROR_NONE; +} + +GList *_widget_app_get_contexts() +{ + return contexts; +} + +int _widget_app_add_context(widget_context_s *wc) +{ + contexts = g_list_append(contexts, wc); + return WIDGET_ERROR_NONE; +} + +int _widget_app_remove_context(widget_context_s *wc) +{ + contexts = g_list_remove(contexts, wc); + return WIDGET_ERROR_NONE; +} + +int _widget_app_set_viewer_endpoint(char *endpoint) +{ + if (endpoint == NULL) + return WIDGET_ERROR_INVALID_PARAMETER; + + viewer_endpoint = strdup(endpoint); + if (viewer_endpoint == NULL) + return WIDGET_ERROR_OUT_OF_MEMORY; + + return WIDGET_ERROR_NONE; +} + +char *_widget_app_get_viewer_endpoint() +{ + return viewer_endpoint; +} + +int _widget_app_free_viewer_endpoint() +{ + if (viewer_endpoint) + free(viewer_endpoint); + + return WIDGET_ERROR_NONE; +} -- 2.7.4 From 94e629734622f169fd471ab4f5545235ffffc784 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Wed, 17 Aug 2016 17:10:59 +0900 Subject: [PATCH 13/16] Fix uninitialized value Change-Id: Ic81d24835bf996c312eb1a5b8ea67bb6e4b6cf67 Signed-off-by: Hyunho Kang --- src/widget_app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget_app.c b/src/widget_app.c index f90e7ec..2128f0b 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -834,7 +834,7 @@ static int __before_loop(int argc, char **argv) char *wayland_display = NULL; char *xdg_runtime_dir = NULL; char *name; - char *viewer_endpoint; + char *viewer_endpoint = NULL; #if !(GLIB_CHECK_VERSION(2, 36, 0)) g_type_init(); -- 2.7.4 From 18493cdad7b750868f2b30cbb375146fc7baebb0 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Tue, 6 Sep 2016 18:05:53 +0900 Subject: [PATCH 14/16] Implement widget_service_get_instance_count Change-Id: Ie927848973f36955635ff120bcf85ffe6ef18f2e Signed-off-by: Hyunho Kang --- src/widget_app.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/widget_app.c b/src/widget_app.c index 2128f0b..60d3d08 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -441,10 +441,10 @@ static int __instance_destroy(widget_class_h handle, const char *id, int event = WIDGET_INSTANCE_EVENT_TERMINATE; bundle *content_info; - if (!wc) { - _E("could not find widget obj: %s", id); /* LCOV_EXCL_LINE */ - return WIDGET_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */ + _E("could not find widget obj: %s, clear amd info", id); /* LCOV_EXCL_LINE */ + aul_widget_instance_del(handle->classid, id); /* LCOV_EXCL_LINE */ + return WIDGET_ERROR_NONE; /* LCOV_EXCL_LINE */ } wc->state = WC_TERMINATED; @@ -458,13 +458,12 @@ static int __instance_destroy(widget_class_h handle, const char *id, if (reason == WIDGET_APP_DESTROY_TYPE_PERMANENT) { event = WIDGET_INSTANCE_EVENT_DESTROY; + aul_widget_instance_del(handle->classid, id); } else { ret = __send_update_status(handle->classid, id, WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info); } - aul_widget_instance_del(handle->classid, id); - if (content_info) bundle_free(content_info); @@ -614,6 +613,7 @@ static void __pause_all(int send_update) __instance_pause(cxt->provider, cxt->id, send_update); break; } + LOGD("pause %s", cxt->id); iter = g_list_next(iter); } } @@ -646,16 +646,15 @@ static void __destroy_all(int reason, int send_update) GList *iter = g_list_first(contexts); __pause_all(send_update); - while (iter != NULL) { widget_context_s *cxt = (widget_context_s *)iter->data; - + iter = g_list_next(iter); switch (cxt->state) { case WC_PAUSED: + LOGD("destroy %s", cxt->state, cxt->id); __instance_destroy(cxt->provider, cxt->id, reason, send_update); break; } - iter = g_list_next(iter); } } -- 2.7.4 From 7615492553b49fc96faa0ee8f2c20afeab00ae1e Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Fri, 23 Sep 2016 10:34:19 +0900 Subject: [PATCH 15/16] Fix wrong doxygen format Change-Id: Idbb4c367cd57724e9b0c210a075e668b66d4a636 Signed-off-by: Hyunho Kang --- include/widget_app.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/widget_app.h b/include/widget_app.h index 3b49868..3cd38a0 100755 --- a/include/widget_app.h +++ b/include/widget_app.h @@ -38,9 +38,9 @@ extern "C" { * @since_tizen 2.3.1 */ typedef enum widget_app_destroy_type { - WIDGET_APP_DESTROY_TYPE_PERMANENT = 0x00, /* User deleted this widget from the viewer */ - WIDGET_APP_DESTROY_TYPE_TEMPORARY = 0x01, /* Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by the system) */ -} widget_app_destroy_type_e; /**< Delete type */ + WIDGET_APP_DESTROY_TYPE_PERMANENT = 0x00, /**< User deleted this widget from the viewer */ + WIDGET_APP_DESTROY_TYPE_TEMPORARY = 0x01, /**< Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by the system) */ +} widget_app_destroy_type_e; /** * @brief The handle for widget class. -- 2.7.4 From 54fa55eb30fa95fc111a23d2ccee190901ddf60f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 7 Oct 2016 15:05:27 +0900 Subject: [PATCH 16/16] Add package id to the lifecycle info Change-Id: I812173fb03a725df74c710fe756d35bc9492f6f6 Signed-off-by: Hwankyu Jhun --- src/widget_app.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/widget_app.c b/src/widget_app.c index 60d3d08..c3edd63 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -84,6 +84,7 @@ static void *app_user_data; static char *appid; static widget_class_h class_provider; static int exit_called; +static char *package_id; static void _widget_core_set_appcore_event_cb(void); static void _widget_core_unset_appcore_event_cb(void); @@ -170,6 +171,7 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id, int status) { bundle *b = bundle_create(); + char pkgid[256] = {0, }; int ret; if (b == NULL) { @@ -177,9 +179,17 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id, return -1; /* LCOV_EXCL_LINE */ } + if (package_id == NULL) { + ret = aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)); + if (ret == 0) + package_id = strdup(pkgid); + } + 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 (package_id) + bundle_add_str(b, AUL_K_PKGID, package_id); _D("send lifecycle %s(%d)", instance_id, status); ret = aul_app_com_send("widget.status", b); @@ -940,6 +950,12 @@ static void __after_loop() _widget_app_free_viewer_endpoint(); _widget_core_unset_appcore_event_cb(); __free_handler_list(); + + if (package_id) { + free(package_id); + package_id = NULL; + } + elm_shutdown(); } -- 2.7.4