From: Jooseok Park Date: Tue, 16 May 2017 02:09:06 +0000 (+0900) Subject: Add resource handle hashing X-Git-Tag: submit/tizen/20170516.032557^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=151c58f5d5713737ee4b38b53bda74ac3519d7ec;p=platform%2Fcore%2Fiot%2Fiotcon.git Add resource handle hashing Change-Id: I4e6c4c710fa3fd597b278161168dd4bc1b4dd01a --- diff --git a/src/ic-ioty-ocprocess.c b/src/ic-ioty-ocprocess.c index 9bd3c93..284b067 100644 --- a/src/ic-ioty-ocprocess.c +++ b/src/ic-ioty-ocprocess.c @@ -43,6 +43,7 @@ #include "ic-resource-interfaces.h" static int icl_ioty_alive = 1; +extern GHashTable *resource_hash_table; void icl_ioty_ocprocess_stop() { @@ -633,10 +634,19 @@ static gboolean _icl_ioty_ocprocess_request_idle_cb(gpointer p) resource = req_container->resource; request = req_container->request; + gchar *key = NULL; + key = g_strdup_printf("%p", resource); + if (NULL == g_hash_table_lookup(resource_hash_table, key)) { + DBG("Request callback will be not called because there is no resource[%p] in resource_hash_table.", resource); + goto OUT; + } + DBG("resource:[%p], resource->cb:[%p] on [%s]", resource, resource->cb, resource->uri_path); resource->cb(resource, request, resource->user_data); DBG("callback done"); +OUT: + g_free(key); icl_destroy_request_container(req_container); return G_SOURCE_REMOVE; diff --git a/src/ic-ioty.c b/src/ic-ioty.c index cf63637..3698779 100644 --- a/src/ic-ioty.c +++ b/src/ic-ioty.c @@ -66,6 +66,7 @@ static char icl_svr_db_file[PATH_MAX]; static OCPersistentStorage icl_ioty_ps; static GList *icl_generated_pin_cb_list; +GHashTable *resource_hash_table; void icl_ioty_deinit(pthread_t thread) { FN_CALL; @@ -1779,6 +1780,12 @@ int icl_ioty_resource_create(const char *uri_path, *resource_handle = resource; DBG("resource:[%p]", resource); + if (NULL == resource_hash_table) { + DBG("resource_hash_table will be created"); + resource_hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + } + g_hash_table_add(resource_hash_table, g_strdup_printf("%p", resource)); + return IOTCON_ERROR_NONE; } @@ -1976,6 +1983,20 @@ int icl_ioty_resource_destroy(iotcon_resource_h resource) } OUT: + DBG("resource:[%p]", resource); + if (NULL != resource_hash_table) { + gchar *key = NULL; + key = g_strdup_printf("%p", resource); + g_hash_table_remove(resource_hash_table, key); + g_free(key); + + if (0 == g_hash_table_size(resource_hash_table)) { + DBG("resource_hash_table will be destoryed"); + g_hash_table_destroy(resource_hash_table); + resource_hash_table = NULL; + } + } + free(resource->uri_path); free(resource); return ret;