Add resource handle hashing 70/129270/1 accepted/tizen/unified/20170516.044840 submit/tizen/20170516.032557 tizen_4.0.m1_release
authorJooseok Park <jooseok.park@samsung.com>
Tue, 16 May 2017 02:09:06 +0000 (11:09 +0900)
committerJooseok Park <jooseok.park@samsung.com>
Tue, 16 May 2017 02:09:06 +0000 (11:09 +0900)
Change-Id: I4e6c4c710fa3fd597b278161168dd4bc1b4dd01a

src/ic-ioty-ocprocess.c
src/ic-ioty.c

index 9bd3c93..284b067 100644 (file)
@@ -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;
index cf63637..3698779 100644 (file)
@@ -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;