Add a fallback about updating instance 60/143660/2 accepted/tizen/3.0/common/20170811.132449 accepted/tizen/3.0/ivi/20170811.095624 accepted/tizen/3.0/mobile/20170811.095628 accepted/tizen/3.0/tv/20170811.095618 accepted/tizen/3.0/wearable/20170811.095633 submit/tizen_3.0/20170811.072820
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 11 Aug 2017 01:54:53 +0000 (10:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 11 Aug 2017 02:39:00 +0000 (11:39 +0900)
Change-Id: Icc45d5f4fddbadd8deeb81bdd024a47543b2a09c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/widget-private.h
src/widget_app.c

index 1c7f519..0813ebc 100644 (file)
@@ -47,6 +47,7 @@ struct _widget_context {
        guint periodic_timer;
        bool pending_update;
        widget_instance_lifecycle_callback_s ops;
+       char *pending_content;
 };
 
 typedef struct _widget_context widget_context_s;
index 858e7fc..50712c8 100755 (executable)
@@ -324,10 +324,11 @@ static int __instance_resume(widget_class_h handle, const char *id, int send_upd
                return 0; /* LCOV_EXCL_LINE */
        }
 
+       wc->state = WC_RUNNING;
        if (wc->pending_update) {
                _D("pending update!");
                wc->pending_update = false;
-               __instance_update(wc->provider, wc->id, 0, NULL);
+               __instance_update(wc->provider, wc->id, 0, wc->pending_content);
 
                if (wc->period > 0) {
                        _D("Restart timer!");
@@ -339,7 +340,6 @@ static int __instance_resume(widget_class_h handle, const char *id, int send_upd
        if (handle->ops.resume)
                handle->ops.resume(wc, handle->user_data);
 
-       wc->state = WC_RUNNING;
        _D("%s is resumed", id);
        if (send_update) {
                ret = __send_update_status(handle->classid, wc->id,
@@ -425,6 +425,20 @@ static int __instance_resize(widget_class_h handle, const char *id, int w, int h
        return ret;
 }
 
+static void __update_pending_content(widget_context_s *wc, const char *content)
+{
+       if (wc->pending_content) {
+               free(wc->pending_content);
+               wc->pending_content = NULL;
+       }
+
+       if (content) {
+               wc->pending_content = strdup(content);
+               if (wc->pending_content == NULL)
+                       _W("Out of memory");
+       }
+}
+
 /* LCOV_EXCL_START */
 static int __instance_update_all(widget_class_h handle, int force, const char *content)
 {
@@ -439,11 +453,17 @@ static int __instance_update_all(widget_class_h handle, int force, const char *c
        if (handle->ops.update) {
                while (context) {
                        wc = (widget_context_s *)context->data;
+                       context = context->next;
+                       if (wc->state != WC_RUNNING && !force) {
+                               __update_pending_content(wc, content);
+                               wc->pending_update = true;
+                               continue;
+                       }
+
                        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;
                }
        }
 
@@ -465,6 +485,12 @@ static int __instance_update(widget_class_h handle, const char *id, int force, c
                return -1;
        }
 
+       if (wc->state != WC_RUNNING && !force) {
+               __update_pending_content(wc, content);
+               wc->pending_update = true;
+               return 0;
+       }
+
        if (content)
                b = bundle_decode((const bundle_raw *)content, strlen(content));
 
@@ -593,6 +619,9 @@ static int __instance_destroy(widget_class_h handle, const char *id,
        if (wc->periodic_timer)
                g_source_remove(wc->periodic_timer);
 
+       if (wc->pending_content)
+               free(wc->pending_content);
+
        free(wc);
 
        if (_widget_app_get_contexts() == NULL && !exit_called) /* all instance destroyed */