Fix widget instance update 65/78465/4 accepted/tizen/common/20160712.150523 accepted/tizen/ivi/20160712.000220 accepted/tizen/mobile/20160712.000056 accepted/tizen/tv/20160712.000201 accepted/tizen/wearable/20160712.000212 submit/tizen/20160711.130213
authorDaehyeon Jung <darrenh.jung@samsung.com>
Tue, 5 Jul 2016 13:57:11 +0000 (22:57 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 11 Jul 2016 07:59:25 +0000 (16:59 +0900)
Change-Id: Ia43fdb6fd16e1870ed68fcacb0c2cb26cc9bc60e
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
src/widget_app.c

index 608f729..9d717ae 100755 (executable)
@@ -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) {