Manage toolkit handles in consistent way 92/145192/6 accepted/tizen/3.0/common/20170824.151032 accepted/tizen/3.0/mobile/20170823.221603 accepted/tizen/3.0/tv/20170823.221634 accepted/tizen/3.0/wearable/20170823.221639 submit/tizen_3.0/20170822.050833
authorSemun Lee <semun.lee@samsung.com>
Mon, 21 Aug 2017 13:44:21 +0000 (22:44 +0900)
committerSemun Lee <semun.lee@samsung.com>
Tue, 22 Aug 2017 03:21:02 +0000 (12:21 +0900)
- upper layer is responsible for managing toolkits of lower layer

Change-Id: I685035f8cade2e089392e0a01b44bf630f0a03d6
Signed-off-by: Semun Lee <semun.lee@samsung.com>
screen_connector_watcher/src/screen_connector_toolkit.c
screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c

index c463e2d..12f49d5 100644 (file)
@@ -282,7 +282,7 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add_by_rid(screen
 
        if (type_h->toolkit_table == NULL)
                type_h->toolkit_table = g_hash_table_new_full(g_str_hash,
-                               g_str_equal, free, __destroy_toolkit_h);
+                               g_str_equal, free, NULL);
 
        g_hash_table_insert(type_h->toolkit_table, strdup(id), toolkit_h);
 
@@ -341,7 +341,7 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add_with_surface(
 
        if (type_h->toolkit_table == NULL)
                type_h->toolkit_table = g_hash_table_new_full(g_str_hash,
-                               g_str_equal, free, __destroy_toolkit_h);
+                               g_str_equal, free, NULL);
 
        g_hash_table_insert(type_h->toolkit_table, strdup(id), toolkit_h);
 
@@ -417,7 +417,7 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add(screen_connec
 
        if (type_h->toolkit_table == NULL)
                type_h->toolkit_table = g_hash_table_new_full(g_str_hash,
-                               g_str_equal, free, __destroy_toolkit_h);
+                               g_str_equal, free, NULL);
 
        g_hash_table_insert(type_h->toolkit_table, strdup(id), toolkit_h);
 
@@ -445,7 +445,7 @@ EXPORT_API int screen_connector_toolkit_remove(screen_connector_toolkit_h h)
        }
 
        g_hash_table_remove(h->type_h->toolkit_table, h->instance_id);
-
+       __destroy_toolkit_h(h);
        return 0;
 }
 
index 2140a6c..c4bbf2c 100644 (file)
@@ -156,19 +156,6 @@ static int __remove_window_visibility_info(
        return 0;
 }
 
-static void __destroy_type_h(gpointer data)
-{
-       screen_connector_type_evas_h type_h = (screen_connector_type_evas_h)data;
-       if (!type_h)
-               return;
-
-       if (type_h->toolkit_table) {
-               g_hash_table_destroy(type_h->toolkit_table);
-               type_h->toolkit_table = NULL;
-       }
-       free(type_h);
-}
-
 static void __cur_buffer_info_ref(cur_buffer_info_h info)
 {
        info->ref_count++;
@@ -311,6 +298,25 @@ static void __destroy_toolkit_evas_h(gpointer data)
        free(toolkit_evas_h);
 }
 
+static void __destroy_type_h(gpointer data)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+       screen_connector_type_evas_h type_h = (screen_connector_type_evas_h)data;
+       if (!type_h)
+               return;
+
+       if (type_h->toolkit_table) {
+               g_hash_table_iter_init(&iter, type_h->toolkit_table);
+               while (g_hash_table_iter_next(&iter, &key, &value))
+                       __destroy_toolkit_evas_h(value);
+
+               g_hash_table_destroy(type_h->toolkit_table);
+               type_h->toolkit_table = NULL;
+       }
+       free(type_h);
+}
+
 EXPORT_API int screen_connector_toolkit_evas_init(Evas_Object *win, screen_connector_screen_type_e type)
 {
        screen_connector_type_evas_h type_h;
@@ -327,7 +333,7 @@ EXPORT_API int screen_connector_toolkit_evas_init(Evas_Object *win, screen_conne
                type_h = (screen_connector_type_evas_h)calloc(1, sizeof(struct _screen_connector_type_evas_h));
                g_hash_table_insert(__type_table, GINT_TO_POINTER(type), type_h);
 
-               type_h->toolkit_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, __destroy_toolkit_evas_h);
+               type_h->toolkit_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
                if (!type_h->toolkit_table) {
                        LOGE("failed to create table");
                        return -1;
@@ -341,6 +347,8 @@ EXPORT_API int screen_connector_toolkit_evas_init(Evas_Object *win, screen_conne
 EXPORT_API int screen_connector_toolkit_evas_fini(screen_connector_screen_type_e type)
 {
        screen_connector_type_evas_h type_h;
+       GHashTableIter iter;
+       gpointer key, value;
 
        if (__type_table == NULL) {
                LOGI("__type_table is NULL");
@@ -350,6 +358,9 @@ EXPORT_API int screen_connector_toolkit_evas_fini(screen_connector_screen_type_e
        type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(type));
        if (type_h) {
                if (type_h->toolkit_table) {
+                       g_hash_table_iter_init(&iter, type_h->toolkit_table);
+                       while (g_hash_table_iter_next(&iter, &key, &value))
+                               __destroy_toolkit_evas_h(value);
                        g_hash_table_destroy(type_h->toolkit_table);
                        type_h->toolkit_table = NULL;
                }
@@ -1114,8 +1125,11 @@ EXPORT_API int screen_connector_toolkit_evas_remove(screen_connector_toolkit_eva
                LOGE("Null instance_id");
                return -1;
        }
+
        g_hash_table_remove(handle->type_h->toolkit_table, instance_id);
 
+       __destroy_toolkit_evas_h(handle);
+
        return 0;
 }