Send error code to viewer
[platform/core/appfw/appcore-widget.git] / src / base / widget_base.c
index 34c94f5..e43635d 100644 (file)
@@ -239,12 +239,13 @@ static int __send_lifecycle_event(const char *class_id, const char *instance_id,
 }
 
 static int __send_update_status(const char *class_id, const char *instance_id,
-       int status, bundle *extra)
+       int status, int err, bundle *extra)
 {
        bundle *b;
        int lifecycle = -1;
        bundle_raw *raw = NULL;
        int len;
+       char err_str[256];
 
        b = bundle_create();
        if (!b) {
@@ -252,6 +253,11 @@ static int __send_update_status(const char *class_id, const char *instance_id,
                return -1; /* LCOV_EXCL_LINE */
        }
 
+       if (err < 0) {
+               snprintf(err_str, sizeof(err_str), "%d", err);
+               bundle_add_str(b, AUL_K_WIDGET_ERROR_CODE, err_str);
+       }
+
        bundle_add_str(b, AUL_K_WIDGET_ID, class_id);
        bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id);
        bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int));
@@ -294,9 +300,6 @@ static void __control_create(const char *class_id, const char *id, bundle *b)
 {
        widget_base_instance_data *data;
        char *content = NULL;
-       double *period = NULL;
-       size_t size;
-       int ret;
 
        data = (widget_base_instance_data *)
                        calloc(1, sizeof(widget_base_instance_data));
@@ -307,12 +310,6 @@ static void __control_create(const char *class_id, const char *id, bundle *b)
 
        data->id = strdup(id);
        data->args = b;
-       ret = bundle_get_byte(b, WIDGET_K_PERIOD, (void **)&period, &size);
-       if (ret == BUNDLE_ERROR_NONE) {
-               data->period = *period;
-               data->periodic_timer = g_timeout_add_seconds(data->period,
-                               __timeout_cb, data);
-       }
 
        /* call stub create */
        appcore_multiwindow_base_instance_run(class_id, id, data);
@@ -394,7 +391,7 @@ static void __control_resize(const char *class_id, const char *id, bundle *b)
 
        LOGD("%s is resized to %dx%d", id, w, h);
        __send_update_status(class_id, id,
-               WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL);
+               WIDGET_INSTANCE_EVENT_SIZE_CHANGED, 0, NULL);
 }
 
 static void __call_update_cb(const char *class_id, const char *id, int force,
@@ -439,7 +436,7 @@ static void __call_update_cb(const char *class_id, const char *id, int force,
                cls->ops.update(instance_h, content, force, class_data);
 
        __send_update_status(class_id, id,
-               WIDGET_INSTANCE_EVENT_UPDATE, NULL);
+               WIDGET_INSTANCE_EVENT_UPDATE, 0, NULL);
        LOGD("updated:%s", id);
 
        if (content)
@@ -973,7 +970,7 @@ EXPORT_API int widget_base_context_set_content_info(
                return WIDGET_BASE_ERROR_FAULT;
 
        ret = __send_update_status(class_id, id,
-                       WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info);
+                       WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, 0, content_info);
 
        if (data->content)
                free(data->content);
@@ -1330,6 +1327,8 @@ static void __multiwindow_instance_create(
        int h = 0;
        int ret = -1;
        widget_base_class *cls;
+       double *period = NULL;
+       size_t size;
 
        appcore_multiwindow_base_class_on_create(instance_h);
        instance_data = appcore_multiwindow_base_instance_get_extra(instance_h);
@@ -1374,14 +1373,27 @@ static void __multiwindow_instance_create(
        if (ret < 0) {
                LOGW("Create callback returns error(%d)", ret);
                ret = __send_update_status(class_id, id,
-                               WIDGET_INSTANCE_EVENT_CREATE_ABORTED, NULL);
+                               WIDGET_INSTANCE_EVENT_CREATE_ABORTED, ret, NULL);
+               if (ret < 0)
+                       LOGE("Fail to send abort status (%d) ", ret);
                __instance_drop(instance_h);
        } else {
                LOGD("%s is created", id);
                ret = __send_update_status(class_id, id,
-                       WIDGET_INSTANCE_EVENT_CREATE, NULL);
+                       WIDGET_INSTANCE_EVENT_CREATE, 0, NULL);
+               if (ret < 0)
+                       LOGE("Fail to send create status (%d) ", ret);
 
                aul_widget_instance_add(class_id, id);
+
+               ret = bundle_get_byte(b, WIDGET_K_PERIOD, (void **)&period,
+                               &size);
+               if (ret == BUNDLE_ERROR_NONE) {
+                       instance_data->period = *period;
+                       instance_data->periodic_timer = g_timeout_add_seconds(
+                                       instance_data->period,
+                                       __timeout_cb, instance_data);
+               }
        }
 
        if (content_info)
@@ -1426,7 +1438,7 @@ static void __multiwindow_instance_resume(
 
        LOGD("%s is resumed", id);
        __send_update_status(class_id, id,
-               WIDGET_INSTANCE_EVENT_RESUME, NULL);
+               WIDGET_INSTANCE_EVENT_RESUME, 0, NULL);
 
        if (!__fg_signal) {
                LOGD("Send fg signal to resourceD");
@@ -1461,7 +1473,7 @@ static void __multiwindow_instance_pause(
 
        LOGD("%s is paused", id);
        __send_update_status(class_id, id,
-               WIDGET_INSTANCE_EVENT_PAUSE, NULL);
+               WIDGET_INSTANCE_EVENT_PAUSE, 0, NULL);
 
        if (__fg_signal) {
                LOGD("Send bg signal to resourceD");
@@ -1522,7 +1534,7 @@ static void __multiwindow_instance_terminate(
        } else {
                __is_permanent = false;
                __send_update_status(class_id, id,
-                               WIDGET_INSTANCE_EVENT_EXTRA_UPDATED,
+                               WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, 0,
                                content_info);
        }
 
@@ -1532,7 +1544,7 @@ static void __multiwindow_instance_terminate(
        if (data->periodic_timer)
                g_source_remove(data->periodic_timer);
 
-       __send_update_status(class_id, id, event, NULL);
+       __send_update_status(class_id, id, event, 0, NULL);
        appcore_multiwindow_base_class_on_terminate(instance_h);
 }