Add a fallback about updating instance
[platform/core/appfw/appcore-widget.git] / src / widget_app.c
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 */