From: Jiwoong Im Date: Fri, 3 Jul 2015 08:07:52 +0000 (+0900) Subject: sync with tizen_2.4 X-Git-Tag: accepted/tizen/mobile/20150707.035235^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F42860%2F1;p=platform%2Fcore%2Fappfw%2Fappcore-widget.git sync with tizen_2.4 - change interfaces to add parameter for user data at widget instance Change-Id: I8436dc5a834c54f0c12221d04e5c4d4494cf1480 Signed-off-by: Jiwoong Im --- diff --git a/doc/images/widget_app_lifecycle.png b/doc/images/widget_app_lifecycle.png index 13d394c..9b1d87c 100755 Binary files a/doc/images/widget_app_lifecycle.png and b/doc/images/widget_app_lifecycle.png differ diff --git a/doc/images/widget_obj_lifecycle.png b/doc/images/widget_obj_lifecycle.png index 71113aa..41d11e1 100755 Binary files a/doc/images/widget_obj_lifecycle.png and b/doc/images/widget_obj_lifecycle.png differ diff --git a/include/widget_app.h b/include/widget_app.h index 49180e1..fbcf59a 100755 --- a/include/widget_app.h +++ b/include/widget_app.h @@ -70,11 +70,12 @@ typedef struct _widget_context* widget_context_h; * @param[in] content The data set for the previous status * @param[in] w The pixel value for widget width * @param[in] h The pixel value for widget height + * @param[in] user_data The user data passed from widget_app_class_create function * * @return #WIDGET_ERROR_NONE on success, * otherwise an error code (see WIDGET_ERROR_XXX) on failure */ -typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h); +typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h, void *user_data); /** * @brief Called before the widget instance is destroyed. @@ -87,6 +88,7 @@ typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *conte * @param[in] context The context of widget instance. * @param[in] reason The reason for destruction * @param[in,out] content The data set to save + * @param[in] user_data The user data passed from widget_app_class_create function * @remark Note that the parameter 'content' is used to save the status of the widget instance. * As a input parameter, content contains the saved status of the widget instance. * You can fill the content parameter with the current status in this callback, @@ -97,7 +99,7 @@ typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *conte * @return #WIDGET_ERROR_NONE on success, * otherwise an error code (see WIDGET_ERROR_XXX) on failure */ -typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content); +typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content, void *user_data); /** * @brief Called when the widget is invisible. @@ -107,10 +109,11 @@ typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_d * The paused instance may be destroyed by framework * * @param[in] context The context of widget instance. + * @param[in] user_data The user data passed from widget_app_class_create function * @return #WIDGET_ERROR_NONE on success, * otherwise an error code (see WIDGET_ERROR_XXX) on failure */ -typedef int (*widget_instance_pause_cb)(widget_context_h context); +typedef int (*widget_instance_pause_cb)(widget_context_h context, void *user_data); /** * @brief Called when the widget is visible. @@ -119,10 +122,11 @@ typedef int (*widget_instance_pause_cb)(widget_context_h context); * @details The callback function is called when the widget is visible. * * @param[in] context The context of widget instance. + * @param[in] user_data The user data passed from widget_app_class_create function * @return #WIDGET_ERROR_NONE on success, * otherwise an error code (see WIDGET_ERROR_XXX) on failure */ -typedef int (*widget_instance_resume_cb)(widget_context_h context); +typedef int (*widget_instance_resume_cb)(widget_context_h context, void *user_data); /** * @brief Called before the widget size is changed. @@ -133,10 +137,11 @@ typedef int (*widget_instance_resume_cb)(widget_context_h context); * @param[in] context The context of widget instance. * @param[in] w The pixel value for widget width * @param[in] h The pixel value for widget height + * @param[in] user_data The user data passed from widget_app_class_create function * @return #WIDGET_ERROR_NONE on success, * otherwise an error code (see WIDGET_ERROR_XXX) on failure */ -typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h); +typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h, void *user_data); /** * @brief Called when the event for updating widget is received. @@ -148,11 +153,12 @@ typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h) * @param[in] content The data set for updating this widget. It will be provided by requester. * Requester can use widget_service_trigger_update(). * @param[in] force Although the widget is paused, if it is TRUE, the widget can be updated. + * @param[in] user_data The user data passed from widget_app_class_create function * @return #WIDGET_ERROR_NONE on success, * otherwise an error code (see WIDGET_ERROR_XXX) on failure * @see widget_service_trigger_update */ -typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force); +typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force, void *user_data); /** * @brief The structure for lifecycle of a widget instance @@ -348,12 +354,13 @@ const char* widget_app_get_id(widget_context_h context); * @since_tizen 2.3.1 * * @param[in] callback The set of lifecycle callbacks + * @param[in] user_data The user data to be passed to the callback functions * @return The handle of class on success, otherwise NULL * You can get the returned value using get_last_result() * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported * @see get_last_result */ -widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback); +widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback, void *user_data); /** * @brief Sets a tag in the context diff --git a/include/widget_app_internal.h b/include/widget_app_internal.h index 968f584..260f4f3 100644 --- a/include/widget_app_internal.h +++ b/include/widget_app_internal.h @@ -48,7 +48,7 @@ typedef struct } widget_obj_event_info_s; typedef int (*widget_instance_text_signal_cb)(widget_context_h context, const char *signal_name, - const char *source, widget_obj_event_info_s *info); + const char *source, widget_obj_event_info_s *info, void *user_data); typedef struct _widget_obj_private_ops { diff --git a/src/widget-i18n.c b/src/widget-i18n.c index 84c96aa..0fbd2be 100755 --- a/src/widget-i18n.c +++ b/src/widget-i18n.c @@ -41,9 +41,10 @@ void _update_lang(void) char *r = setlocale(LC_ALL, ""); if (r == NULL) { r = setlocale(LC_ALL, lang); - if (r) { + + if (r) _D("*****appcore setlocale=%s\n", r); - } + } free(lang); } else { @@ -70,9 +71,10 @@ void _update_region(void) setenv("LC_MEASUREMENT", region, 1); setenv("LC_IDENTIFICATION", region, 1); r = setlocale(LC_ALL, ""); - if (r != NULL) { + + if (r != NULL) _D("*****appcore setlocale=%s\n", r); - } + free(region); } else { _E("failed to get current region format for set region env"); @@ -118,16 +120,6 @@ static char* __proc_get_cmdline() return strdup(buf); } -static void __get_dir_name(char *dirname, int maxlen) -{ - const char *path = NULL; - - path = aul_get_app_root_path(); - snprintf(dirname, maxlen, "%s/res/locale", path); - free(path); -} - - static int __set_i18n(const char *domain) { char *r; @@ -138,7 +130,7 @@ static int __set_i18n(const char *domain) return -1; } - __get_dir_name(dirname, PATH_MAX - 1); + snprintf(dirname, PATH_MAX, "%s/res/locale", aul_get_app_root_path()); _D("locale dir: %s", dirname); r = setlocale(LC_ALL, ""); @@ -146,26 +138,24 @@ static int __set_i18n(const char *domain) if (r == NULL) { char *lang = vconf_get_str(VCONFKEY_LANGSET); r = setlocale(LC_ALL, lang); - if (r) { + + if (r) _D("*****appcore setlocale=%s\n", r); - } - if (lang) { + + if (lang) free(lang); - } + } - if (r == NULL) { + if (r == NULL) _E("appcore: setlocale() error"); - } r = bindtextdomain(domain, dirname); - if (r == NULL) { + if (r == NULL) _E("appcore: bindtextdomain() error"); - } r = textdomain(domain); - if (r == NULL) { + if (r == NULL) _E("appcore: textdomain() error"); - } return 0; } diff --git a/src/widget_app.c b/src/widget_app.c index 17dd0f2..4556c3d 100755 --- a/src/widget_app.c +++ b/src/widget_app.c @@ -57,10 +57,10 @@ static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, }; typedef enum _widget_obj_state_e { - WC_READY = 0, - WC_RUNNING = 1, - WC_PAUSED = 2, - WC_TERMINATED = 3 + WC_READY = 0, + WC_RUNNING = 1, + WC_PAUSED = 2, + WC_TERMINATED = 3 } widget_obj_state_e; struct app_event_handler { @@ -75,6 +75,7 @@ struct app_event_info { }; struct _widget_class { + void *user_data; widget_instance_lifecycle_callback_s ops; widget_obj_private_ops_s ops_private; }; @@ -136,15 +137,15 @@ static widget_context_s* __find_context_by_id(const char *id) { GList* ret = g_list_find_custom(contexts, id, __comp_by_id); - if ( ret == NULL) + if (ret == NULL) return NULL; return ret->data; } static int __provider_create_cb(const char *id, const char *content, int w, - int h, - void *data) + int h, + void *data) { int ret = WIDGET_ERROR_FAULT; widget_context_s *wc = (widget_context_s*)malloc(sizeof(widget_context_s)); @@ -159,9 +160,12 @@ static int __provider_create_cb(const char *id, const char *content, int w, contexts = g_list_append(contexts, wc); if (wc->ops.create) { - bundle *b = bundle_decode((const bundle_raw*)content, strlen(content)); - ret = wc->ops.create(wc, b, w, h); - bundle_free(b); + bundle *b = NULL; + if (content) + b = bundle_decode((const bundle_raw*)content, strlen(content)); + ret = wc->ops.create(wc, b, w, h, widget_class->user_data); + if (b) + bundle_free(b); } _I("widget obj was created"); @@ -175,7 +179,7 @@ static int __provider_resize_cb(const char *id, int w, int h, void *data) if (cxt) { if (cxt->ops.resize) - ret = cxt->ops.resize(cxt, w, h); + ret = cxt->ops.resize(cxt, w, h, widget_class->user_data); _I("received resizing signal"); } else { _E("could not find widget obj : %s", __FUNCTION__); @@ -185,7 +189,7 @@ static int __provider_resize_cb(const char *id, int w, int h, void *data) } static int __provider_destroy_cb(const char *id, widget_destroy_type_e reason, - void *data) + void *data) { int ret = WIDGET_ERROR_FAULT; widget_context_s *cxt = __find_context_by_id(id); @@ -194,7 +198,7 @@ static int __provider_destroy_cb(const char *id, widget_destroy_type_e reason, cxt->state = WC_TERMINATED; if (cxt->ops.destroy) { bundle *b = bundle_create(); - ret = cxt->ops.destroy(cxt,(widget_app_destroy_type_e)reason, b); + ret = cxt->ops.destroy(cxt, (widget_app_destroy_type_e)reason, b, widget_class->user_data); bundle_raw *raw = NULL; int len; @@ -220,16 +224,20 @@ static int __provider_destroy_cb(const char *id, widget_destroy_type_e reason, } static int __provider_update_cb(const char *id, const char *content, int force, - void *data) + void *data) { int ret = WIDGET_ERROR_FAULT; widget_context_s *cxt = __find_context_by_id(id); if (cxt) { if (cxt->ops.update) { - bundle *b = bundle_decode((const bundle_raw*)content, strlen(content)); - ret = cxt->ops.update(cxt, b, force); - bundle_free(b); + bundle *b = NULL; + if (content) + b = bundle_decode((const bundle_raw*)content, strlen(content)); + ret = cxt->ops.update(cxt, b, force, widget_class->user_data); + + if (b) + bundle_free(b); } _I("received updating signal"); } else { @@ -246,7 +254,7 @@ static int __provider_pause_cb(const char *id, void *data) if (cxt) { if (cxt->ops.pause) - ret = cxt->ops.pause(cxt); + ret = cxt->ops.pause(cxt, widget_class->user_data); cxt->state = WC_PAUSED; _I("widget obj was paused"); } else { @@ -264,7 +272,7 @@ static int __provider_resume_cb(const char *id, void *data) if (cxt) { if (cxt->ops.resume) - ret = cxt->ops.resume(cxt); + ret = cxt->ops.resume(cxt, widget_class->user_data); cxt->state = WC_RUNNING; _I("widget obj was resumed"); } else { @@ -276,7 +284,7 @@ static int __provider_resume_cb(const char *id, void *data) } static int __provider_text_signal_cb(const char *id, const char *signal_name, - const char *source, struct widget_event_info *info, void *data) + const char *source, struct widget_event_info *info, void *data) { int ret = WIDGET_ERROR_FAULT; widget_context_s *cxt = __find_context_by_id(id); @@ -284,7 +292,7 @@ static int __provider_text_signal_cb(const char *id, const char *signal_name, if (cxt) { if (cxt->ops_private.text_signal) { ret = cxt->ops_private.text_signal(cxt, signal_name, source, - (widget_obj_event_info_s*)info); + (widget_obj_event_info_s*)info, widget_class->user_data); } _I("received text signal"); } else { @@ -352,9 +360,9 @@ static void __control(bundle *b) .data = NULL, }; - if (widget_provider_app_init(app_control, &cb) == 0) { + if (widget_provider_app_init(app_control, &cb) == 0) is_init_provider = 1; - } + } app_control_destroy(app_control); @@ -411,7 +419,7 @@ static char* __get_domain_name(const char *aid) return NULL; } - // com.vendor.name -> name + /* com.vendor.name -> name */ name_token = strrchr(aid, '.'); if (name_token == NULL) { @@ -439,13 +447,13 @@ static int __before_loop(int argc, char **argv) r = aul_launch_init(__aul_handler, NULL); if (r < 0) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, - "Fail to call the aul_launch_init"); + "Fail to call the aul_launch_init"); } r = aul_launch_argv_handler(argc, argv); if (r < 0) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, - "Fail to call the aul_launch_argv_handler"); + "Fail to call the aul_launch_argv_handler"); } r = app_get_id(&appid); @@ -456,7 +464,7 @@ static int __before_loop(int argc, char **argv) if (name == NULL) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, - "Fail to call __get_domain_name"); + "Fail to call __get_domain_name"); } r = _set_i18n(name); @@ -464,7 +472,7 @@ static int __before_loop(int argc, char **argv) free(name); if (r < 0) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, - "Fail to call _set_i18n"); + "Fail to call _set_i18n"); } widget_provider_app_create_app(); @@ -473,7 +481,7 @@ static int __before_loop(int argc, char **argv) widget_class = app_ops->create(app_user_data); if (widget_class == NULL) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, - "widget_class is NULL"); + "widget_class is NULL"); } return WIDGET_ERROR_NONE; @@ -633,8 +641,7 @@ static void __register_event(int event_type) break; case APP_EVENT_LOW_BATTERY: - vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, - NULL); + vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL); break; case APP_EVENT_LANGUAGE_CHANGED: @@ -669,7 +676,7 @@ static void __unregister_event(int event_type) } EXPORT_API int widget_app_main(int argc, char **argv, - widget_app_lifecycle_callback_s *callback, void *user_data) + widget_app_lifecycle_callback_s *callback, void *user_data) { int r; bool feature; @@ -731,7 +738,7 @@ EXPORT_API int widget_app_terminate_context(widget_context_h context) if (context == NULL) { return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, - "obj is NULL"); + "obj is NULL"); } g_idle_add(__finish_event_cb, context); @@ -757,9 +764,9 @@ EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data) while (iter != NULL) { widget_context_s *cxt = (widget_context_s*) iter->data; - if ( !cb(cxt, data)) { + + if (!cb(cxt, data)) return WIDGET_ERROR_CANCELED; - } iter = g_list_next(iter); } @@ -768,7 +775,8 @@ 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) { int r; bool feature; @@ -799,6 +807,7 @@ EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler, if (handler->cb == callback) return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + iter = g_list_next(iter); } @@ -806,9 +815,8 @@ EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler, if (!handler) return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - if (g_list_length(handler_list[event_type]) == 0) { + if (g_list_length(handler_list[event_type]) == 0) __register_event(event_type); - } handler->type = event_type; handler->cb = callback; @@ -821,7 +829,7 @@ EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler, } EXPORT_API int widget_app_remove_event_handler(app_event_handler_h - event_handler) + event_handler) { int r; bool feature; @@ -879,7 +887,7 @@ EXPORT_API const char* widget_app_get_id(widget_context_h context) } EXPORT_API int widget_app_get_elm_win(widget_context_h context, - Evas_Object **win) + Evas_Object **win) { int r; bool feature; @@ -891,9 +899,8 @@ EXPORT_API int widget_app_get_elm_win(widget_context_h context, if (!feature) return WIDGET_ERROR_NOT_SUPPORTED; - if (context == NULL || win == NULL) { + if (context == NULL || win == NULL) return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } widget_context_s *cxt = (widget_context_s*)context; Evas *evas; @@ -905,6 +912,8 @@ EXPORT_API int widget_app_get_elm_win(widget_context_h context, widget_parent = evas_object_rectangle_add(evas); if (widget_parent) { ret_win = elm_win_add(widget_parent, cxt->id, ELM_WIN_TIZEN_WIDGET); + /* ret_win = elm_win_tizen_widget_add(cxt->id, widget_parent); */ + evas_object_del(widget_parent); if (ret_win == NULL) { _E("win is NULL"); @@ -923,7 +932,7 @@ EXPORT_API int widget_app_get_elm_win(widget_context_h context, return WIDGET_ERROR_NONE; } -EXPORT_API widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback) +EXPORT_API widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback, void *user_data) { int r; bool feature; @@ -947,6 +956,7 @@ EXPORT_API widget_class_h widget_app_class_create(widget_instance_lifecycle_call return NULL; } + wc->user_data = user_data; wc->ops = callback; wc->ops_private = widget_class_tmp.ops_private; set_last_result(WIDGET_ERROR_NONE); @@ -965,9 +975,8 @@ EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag) if (!feature) return WIDGET_ERROR_NOT_SUPPORTED; - if (context == NULL) { + if (context == NULL) return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } context->tag = tag; @@ -986,9 +995,8 @@ EXPORT_API int widget_app_context_get_tag(widget_context_h context, void **tag) if (!feature) return WIDGET_ERROR_NOT_SUPPORTED; - if (context == NULL || tag == NULL) { + if (context == NULL || tag == NULL) return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } *tag = context->tag; @@ -1041,7 +1049,7 @@ EXPORT_API int widget_app_context_set_title(widget_context_h context, const char return widget_provider_app_send_extra_info(context->id, NULL, title); } -// private API +/* private API */ EXPORT_API const widget_class_factory_full_s* widget_app_get_class_factory(void) { return &factory; diff --git a/src/widget_error.c b/src/widget_error.c index 390a820..010adb0 100755 --- a/src/widget_error.c +++ b/src/widget_error.c @@ -77,13 +77,13 @@ static const char* widget_app_error_to_string(widget_error_e error) case WIDGET_ERROR_DISABLED: return "DISABLED"; - default : + default: return "UNKNOWN"; } } int widget_app_error(widget_error_e error, const char* function, - const char *description) + const char *description) { if (description) { LOGE("[%s] %s(0x%08x) : %s", function, widget_app_error_to_string(error), error,