Add id exist check logic for toolkit add api 36/141736/3
authorHyunho Kang <hhstark.kang@samsung.com>
Mon, 24 Jul 2017 11:08:40 +0000 (20:08 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 2 Aug 2017 01:29:44 +0000 (01:29 +0000)
ID should be unique.

Change-Id: I154e9abf832a8415d71d452636c804a581292882
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
screen_connector_watcher/include/screen_connector_toolkit.h
screen_connector_watcher/src/screen_connector_toolkit.c
screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c

index 7fe718c..e061079 100644 (file)
@@ -83,6 +83,7 @@ screen_connector_toolkit_h screen_connector_toolkit_add_with_surface(screen_conn
 
 int screen_connector_toolkit_bind(screen_connector_toolkit_h h, struct wl_surface *surface);
 int screen_connector_toolkit_unbind(screen_connector_toolkit_h h);
+bool screen_connector_toolkit_is_exist(const char *id, screen_connector_screen_type_e type);
 
 #ifdef __cplusplus
 }
index c79e6b5..4242721 100644 (file)
@@ -351,6 +351,27 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add_with_surface(
        return toolkit_h;
 }
 
+EXPORT_API bool screen_connector_toolkit_is_exist(const char *id, screen_connector_screen_type_e type)
+{
+       screen_connector_type_h type_h;
+
+       if (id == NULL) {
+               LOGE("Invalid param");
+               return false;
+       }
+
+       type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(type));
+       if (type_h == NULL) {
+               LOGE("type %d is not initialized !!", type);
+               return false;
+       }
+
+       if (type_h->toolkit_table == NULL)
+               return false;
+
+       return (g_hash_table_lookup(type_h->toolkit_table, id) != NULL);
+}
+
 EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add(screen_connector_toolkit_ops *ops, char *id,
        screen_connector_screen_type_e type, void *data)
 {
@@ -363,9 +384,14 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add(screen_connec
                return NULL;
        }
 
+       if (screen_connector_toolkit_is_exist(id, type)) {
+               LOGE("Already exist ID : %s", id);
+               return NULL;
+       }
+
        type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(type));
        if (type_h == NULL) {
-               LOGE("type %d is not initialized !!", type);
+               LOGE("Type(%s) is not initializaed", type);
                return NULL;
        }
 
index fce15d4..7a8f925 100644 (file)
@@ -902,6 +902,11 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add(scr
        screen_connector_type_evas_h type_h;
        int int_type = type;
 
+       if (screen_connector_toolkit_is_exist(id, type)) {
+               LOGE("Already exist ID : %s", id);
+               return NULL;
+       }
+
        type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(int_type));
        if (type_h == NULL) {
                LOGE("type %d is not initialized !!", type);