Handling instance id duplication
[platform/core/appfw/appcore-widget.git] / src / base / widget_base.c
index 171e37c..1af2e8a 100644 (file)
@@ -20,6 +20,7 @@
 #include <bundle.h>
 #include <bundle_internal.h>
 #include <aul.h>
+#include <aul_widget.h>
 #include <dlog.h>
 #include <glib.h>
 #include <glib-object.h>
@@ -307,6 +308,11 @@ static void __control_create(const char *class_id, const char *id, bundle *b)
        widget_base_instance_data *data;
        char *content = NULL;
 
+       if (appcore_multiwindow_base_instance_find(id)) {
+               LOGE("Already exist id (%s)", id);
+               return;
+       }
+
        data = (widget_base_instance_data *)
                        calloc(1, sizeof(widget_base_instance_data));
        if (!data) {
@@ -775,9 +781,14 @@ static void __multiwindow_exit(void *data)
 
 EXPORT_API int widget_base_exit(void)
 {
+       int ret;
+
        appcore_multiwindow_base_exit();
-       if (appcore_multiwindow_base_instance_get_cnt() != 0 && __is_permanent)
-               aul_notify_exit();
+       if (appcore_multiwindow_base_instance_get_cnt() == 0 && __is_permanent) {
+               ret = aul_notify_exit();
+               aul_widget_write_log(LOG_TAG, "[%s:%d] permanent exit : %d",
+                       __FUNCTION__, __LINE__, ret);
+       }
 
        return 0;
 }
@@ -1448,11 +1459,7 @@ static void __multiwindow_instance_resume(
 
        if (!__fg_signal) {
                LOGD("Send fg signal to resourceD");
-               aul_send_app_status_change_signal(getpid(),
-                               __appid,
-                               __package_id,
-                               STATUS_FOREGROUND,
-                               APP_TYPE_WIDGET);
+               aul_widget_instance_change_status(class_id, STATUS_FOREGROUND);
                __fg_signal = true;
        }
 }
@@ -1483,11 +1490,7 @@ static void __multiwindow_instance_pause(
 
        if (__fg_signal) {
                LOGD("Send bg signal to resourceD");
-               aul_send_app_status_change_signal(getpid(),
-                               __appid,
-                               __package_id,
-                               STATUS_BACKGROUND,
-                               APP_TYPE_WIDGET);
+               aul_widget_instance_change_status(class_id, STATUS_BACKGROUND);
                __fg_signal = false;
        }
 }
@@ -1532,7 +1535,7 @@ static void __multiwindow_instance_terminate(
        if (cls->ops.destroy)
                cls->ops.destroy(instance_h, reason, content_info, class_data);
 
-       LOGD("%s is destroyed %d", id, reason);
+       LOGW("%s is destroyed %d", id, reason);
        if (reason == WIDGET_BASE_DESTROY_TYPE_PERMANENT) {
                __is_permanent = true;
                event = WIDGET_INSTANCE_EVENT_DESTROY;