From 388a5131b7a6b3b9aa418d2039c2ba036a0faa30 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Mon, 24 Jul 2017 20:08:40 +0900 Subject: [PATCH] Add id exist check logic for toolkit add api ID should be unique. Change-Id: I3d4a5e58cce59d03a32a0cf78c0f006783aafe67 Signed-off-by: Hyunho Kang --- .../include/screen_connector_toolkit.h | 2 ++ .../src/screen_connector_toolkit.c | 27 +++++++++++++++++++--- .../src/screen_connector_toolkit_evas.c | 5 ++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/screen_connector_watcher/include/screen_connector_toolkit.h b/screen_connector_watcher/include/screen_connector_toolkit.h index 7fe718c..a614720 100644 --- a/screen_connector_watcher/include/screen_connector_toolkit.h +++ b/screen_connector_watcher/include/screen_connector_toolkit.h @@ -83,6 +83,8 @@ 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(char *id, + screen_connector_screen_type_e type); #ifdef __cplusplus } diff --git a/screen_connector_watcher/src/screen_connector_toolkit.c b/screen_connector_watcher/src/screen_connector_toolkit.c index c79e6b5..4e5b043 100644 --- a/screen_connector_watcher/src/screen_connector_toolkit.c +++ b/screen_connector_watcher/src/screen_connector_toolkit.c @@ -351,6 +351,28 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add_with_surface( return toolkit_h; } +EXPORT_API bool screen_connector_toolkit_is_exist(char *id, + screen_connector_screen_type_e type) +{ + screen_connector_type_h type_h = NULL; + + 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 +385,8 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add(screen_connec 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); + if (screen_connector_toolkit_is_exist(id, type)) { + LOGE("Already exist ID : %s", id); return NULL; } diff --git a/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c b/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c index 8c2342b..b32c04f 100644 --- a/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c +++ b/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c @@ -844,6 +844,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); -- 2.7.4