Add get class exception handling logic 17/151317/3
authorHyunho Kang <hhstark.kang@samsung.com>
Wed, 20 Sep 2017 11:25:34 +0000 (20:25 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Thu, 21 Sep 2017 06:54:11 +0000 (06:54 +0000)
Change-Id: Ia7098fae5c74d763b59a5853bd4801329a5d4a68
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/base/widget_base.c

index 9df3504..6f19ce9 100644 (file)
@@ -162,16 +162,20 @@ static gint __comp_class(gconstpointer a, gconstpointer b)
        return strcmp(cls->id, b);
 }
 
-static widget_base_class __get_class(const char *class_id)
+static widget_base_class *__get_class(const char *class_id)
 {
        widget_base_class *cls;
        GList *class_node;
 
        class_node = g_list_find_custom(__context.classes, class_id,
                        __comp_class);
+       if (class_node == NULL) {
+               LOGE("empty classes");
+               return NULL;
+       }
        cls = (widget_base_class *)class_node->data;
 
-       return *cls;
+       return cls;
 }
 
 static int __send_lifecycle_event(const char *class_id, const char *instance_id,
@@ -313,7 +317,7 @@ static void __control_resize(const char *class_id, const char *id, bundle *b)
        int w = 0;
        int h = 0;
        void *class_data;
-       widget_base_class cls;
+       widget_base_class *cls;
        const appcore_multiwindow_base_class *raw_cls;
 
        instance_h = appcore_multiwindow_base_instance_find(id);
@@ -327,6 +331,10 @@ static void __control_resize(const char *class_id, const char *id, bundle *b)
                return;
 
        cls = __get_class(class_id);
+       if (cls == NULL) {
+               LOGE("class not found: %s", class_id);
+               return;
+       }
        class_data = raw_cls->data;
        bundle_get_str(b, WIDGET_K_WIDTH, &w_str);
        bundle_get_str(b, WIDGET_K_HEIGHT, &h_str);
@@ -337,8 +345,8 @@ static void __control_resize(const char *class_id, const char *id, bundle *b)
        if (h_str)
                h = (int)g_ascii_strtoll(h_str, &remain, 10);
 
-       if (cls.ops.resize)
-               cls.ops.resize(instance_h, w, h, class_data);
+       if (cls->ops.resize)
+               cls->ops.resize(instance_h, w, h, class_data);
 
        LOGD("%s is resized to %dx%d", id, w, h);
        __send_update_status(class_id, id,
@@ -355,7 +363,7 @@ static void __update_cb(const char *class_id, const char *id,
        char *force_str = NULL;
        int force;
        bundle *b = data;
-       widget_base_class cls;
+       widget_base_class *cls;
 
        if (!b) {
                LOGE("bundle is NULL");
@@ -370,8 +378,12 @@ static void __update_cb(const char *class_id, const char *id,
 
        class_data = raw_cls->data;
        cls = __get_class(class_id);
+       if (cls == NULL) {
+               LOGE("class not found: %s", class_id);
+               return;
+       }
 
-       if (!cls.ops.update) {
+       if (!cls->ops.update) {
                LOGE("update callback is NULL");
                return;
        }
@@ -390,8 +402,8 @@ static void __update_cb(const char *class_id, const char *id,
                                strlen(content_raw));
        }
 
-       if (cls.ops.update)
-               cls.ops.update(instance_h, content, force, class_data);
+       if (cls->ops.update)
+               cls->ops.update(instance_h, content, force, class_data);
 
        __send_update_status(class_id, id,
                WIDGET_INSTANCE_EVENT_UPDATE, NULL);
@@ -1186,7 +1198,7 @@ static void __multiwindow_instance_create(
        int w = 0;
        int h = 0;
        int ret = -1;
-       widget_base_class cls;
+       widget_base_class *cls;
 
        appcore_multiwindow_base_class_on_create(instance_h);
        instance_data = appcore_multiwindow_base_instance_get_extra(instance_h);
@@ -1198,6 +1210,11 @@ static void __multiwindow_instance_create(
                class_id = __appid;
 
        cls = __get_class(class_id);
+       if (cls == NULL) {
+               LOGE("class not found: %s", class_id);
+               return;
+       }
+
        bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &id);
        bundle_get_str(b, WIDGET_K_OPERATION, &operation);
 
@@ -1220,8 +1237,8 @@ static void __multiwindow_instance_create(
                content_info = bundle_decode((const bundle_raw *)content,
                                strlen(content));
 
-       if (cls.ops.create)
-               ret = cls.ops.create(instance_h, content_info, w, h, class_data);
+       if (cls->ops.create)
+               ret = cls->ops.create(instance_h, content_info, w, h, class_data);
 
        if (ret < 0) {
                LOGW("Create callback returns error(%d)", ret);
@@ -1246,15 +1263,19 @@ static void __multiwindow_instance_resume(
 {
        const char *id;
        const char *class_id;
-       widget_base_class cls;
+       widget_base_class *cls;
 
        appcore_multiwindow_base_class_on_resume(instance_h);
        id = appcore_multiwindow_base_instance_get_id(instance_h);
        class_id = appcore_multiwindow_base_instance_get_class_id(instance_h);
        cls = __get_class(class_id);
+       if (cls == NULL) {
+               LOGE("class not found: %s", class_id);
+               return;
+       }
 
-       if (cls.ops.resume)
-               cls.ops.resume(instance_h, class_data);
+       if (cls->ops.resume)
+               cls->ops.resume(instance_h, class_data);
 
        LOGD("%s is resumed", id);
        __send_update_status(class_id, id,
@@ -1277,15 +1298,19 @@ static void __multiwindow_instance_pause(
 {
        const char *id;
        const char *class_id;
-       widget_base_class cls;
+       widget_base_class *cls;
 
        appcore_multiwindow_base_class_on_pause(instance_h);
        id = appcore_multiwindow_base_instance_get_id(instance_h);
        class_id = appcore_multiwindow_base_instance_get_class_id(instance_h);
        cls = __get_class(class_id);
+       if (cls == NULL) {
+               LOGE("class not found: %s", class_id);
+               return;
+       }
 
-       if (cls.ops.pause)
-               cls.ops.pause(instance_h, class_data);
+       if (cls->ops.pause)
+               cls->ops.pause(instance_h, class_data);
 
        LOGD("%s is paused", id);
        __send_update_status(class_id, id,
@@ -1314,7 +1339,7 @@ static void __multiwindow_instance_terminate(
        int event = WIDGET_INSTANCE_EVENT_TERMINATE;
        const char *id;
        const char *class_id;
-       widget_base_class cls;
+       widget_base_class *cls;
 
        id = appcore_multiwindow_base_instance_get_id(instance_h);
        class_id = appcore_multiwindow_base_instance_get_class_id(instance_h);
@@ -1322,6 +1347,10 @@ static void __multiwindow_instance_terminate(
                        (appcore_multiwindow_base_instance_h)instance_h);
        b = data->args;
        cls = __get_class(class_id);
+       if (cls == NULL) {
+               LOGE("class not found: %s", class_id);
+               return;
+       }
 
        if (b) {
                bundle_get_str(b, WIDGET_K_OPERATION, &operation);
@@ -1335,8 +1364,8 @@ static void __multiwindow_instance_terminate(
        else
                content_info = bundle_create();
 
-       if (cls.ops.destroy)
-               cls.ops.destroy(instance_h, reason, content_info, class_data);
+       if (cls->ops.destroy)
+               cls->ops.destroy(instance_h, reason, content_info, class_data);
 
        LOGD("%s is destroyed %d", id, reason);
        if (reason == WIDGET_BASE_DESTROY_TYPE_PERMANENT) {