From 7afe5f4b4737229b5b3b27383973a984367da232 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Mon, 8 Aug 2016 10:39:56 +0900 Subject: [PATCH] Implement widget_service_get_widget_max_count feature Change-Id: I6ec823188629ce0bf900cd953965cbe98f79f5e8 Signed-off-by: Hyunho Kang --- widget_viewer_evas/include/widget_viewer_evas.h | 1 + widget_viewer_evas/src/widget_viewer_evas.c | 34 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/widget_viewer_evas/include/widget_viewer_evas.h b/widget_viewer_evas/include/widget_viewer_evas.h index b402394..f810deb 100644 --- a/widget_viewer_evas/include/widget_viewer_evas.h +++ b/widget_viewer_evas/include/widget_viewer_evas.h @@ -160,6 +160,7 @@ extern int widget_viewer_evas_fini(void); * @exception #WIDGET_ERROR_NONE Successfully added * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported * @exception #WIDGET_ERROR_PERMISSION_DENIED Permission denied + * @exception #WIDGET_ERROR_MAX_EXCEEDED Maximum number of instances exceeded * @see get_last_result() * @see #widget_service_get_widget_id */ diff --git a/widget_viewer_evas/src/widget_viewer_evas.c b/widget_viewer_evas/src/widget_viewer_evas.c index 349c6b8..a371ee2 100644 --- a/widget_viewer_evas/src/widget_viewer_evas.c +++ b/widget_viewer_evas/src/widget_viewer_evas.c @@ -138,12 +138,14 @@ static struct info { bool initialized; Evas_Object *win; GHashTable *widget_table; + GHashTable *instance_cnt_table; } s_info = { .w = 0, .h = 0, .initialized = false, .win = NULL, .widget_table = NULL, + .instance_cnt_table = NULL, }; struct widget_info { @@ -569,6 +571,7 @@ EAPI int widget_viewer_evas_init(Evas_Object *win) s_info.initialized = true; s_info.widget_table = g_hash_table_new(g_str_hash, g_str_equal); + s_info.instance_cnt_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); return WIDGET_ERROR_NONE; } @@ -640,6 +643,7 @@ static void del_cb(void *data, Evas *e, Evas_Object *layout, void *event_info) { struct widget_info *info = data; struct widget_evas_event_info evas_info; + int *cur_instance_cnt; if (info->restart) return; @@ -668,6 +672,13 @@ static void del_cb(void *data, Evas *e, Evas_Object *layout, void *event_info) info->event_queue = NULL; } + cur_instance_cnt = g_hash_table_lookup(s_info.instance_cnt_table, info->widget_id); + if (cur_instance_cnt != NULL) { + (*cur_instance_cnt)--; + if (*cur_instance_cnt == 0) + g_hash_table_remove(s_info.instance_cnt_table, info->widget_id); + } + free(info->widget_id); free(info->instance_id); free(info->content_info); @@ -724,6 +735,7 @@ static void resize_cb(void *data, Evas *e, Evas_Object *layout, void *event_info smart_callback_call(info->layout, WIDGET_SMART_SIGNAL_WIDGET_CREATE_ABORTED, &event_info); __display_overlay_text(info); + return; } } else { @@ -813,6 +825,27 @@ EAPI Evas_Object *widget_viewer_evas_add_widget(Evas_Object *parent, const char { char *instance_id = NULL; struct widget_info *widget_instance_info = NULL; + int max_instance_cnt; + int *cur_instance_cnt; + + max_instance_cnt = widget_service_get_widget_max_count(widget_id); + if (max_instance_cnt < 0) { + ErrPrint("get widget max instance count fail"); + return NULL; + } + + cur_instance_cnt = g_hash_table_lookup(s_info.instance_cnt_table, widget_id); + if (cur_instance_cnt == NULL) { + cur_instance_cnt = (int *)calloc(1, sizeof(int)); + *cur_instance_cnt = 0; + g_hash_table_insert(s_info.instance_cnt_table, strdup(widget_id), cur_instance_cnt); + } + + if (max_instance_cnt != 0 && max_instance_cnt <= *cur_instance_cnt) { + set_last_result(WIDGET_ERROR_MAX_EXCEEDED); + ErrPrint("already have max count instances"); + return NULL; + } if (!is_widget_feature_enabled()) { set_last_result(WIDGET_ERROR_NOT_SUPPORTED); @@ -865,6 +898,7 @@ EAPI Evas_Object *widget_viewer_evas_add_widget(Evas_Object *parent, const char g_hash_table_insert(s_info.widget_table, widget_instance_info->instance_id, widget_instance_info); widget_service_set_lifecycle_event_cb(widget_id, __lifecycle_event_cb, NULL); + (*cur_instance_cnt)++; /** * @note -- 2.7.4