Remove unnecessary code in initialize and register step
authoryoungman <yman.jung@samsung.com>
Thu, 25 Jun 2015 06:39:12 +0000 (15:39 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:06:25 +0000 (20:06 +0900)
Change-Id: Ib8931567c9c00482bfee83a9c3495e4d5d36b6af
Signed-off-by: youngman <yman.jung@samsung.com>
12 files changed:
daemon/icd.c
lib/icl-ioty.h
lib/icl.c
lib/icl.h
lib/include/iotcon-constant.h
lib/include/iotcon.h
test/crud-test-client.c
test/crud-test-server.c
test/device-test-client.c
test/device-test-server.c
test/repr-test-client.c
test/repr-test-server.c

index b1116a4..5ed5cba 100644 (file)
@@ -19,6 +19,9 @@
 #include "icd-dbus.h"
 #include "icd-ioty.h"
 
+#define ICD_ALL_INTERFACES "0.0.0.0"
+#define ICD_RANDOM_PORT 0
+
 int main(int argc, char **argv)
 {
        guint id;
@@ -31,7 +34,7 @@ int main(int argc, char **argv)
        loop = g_main_loop_new(NULL, FALSE);
 
        id = icd_dbus_init();
-       icd_ioty_config(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       icd_ioty_config(ICD_ALL_INTERFACES, ICD_RANDOM_PORT);
 
        g_main_loop_run(loop);
 
index 73d6623..9135e41 100644 (file)
@@ -27,7 +27,6 @@ struct icl_notify_msg {
 
 struct icl_resource {
        char *uri;
-       char *host;
        bool is_observable;
        iotcon_resource_types_h types;
        int ifaces;
@@ -40,5 +39,4 @@ struct icl_resource {
 int icl_ioty_convert_interface_flag(iotcon_interface_e src, char **dest);
 int icl_ioty_convert_interface_string(const char *src, iotcon_interface_e *dest);
 
-
 #endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_IOTIVITY_H__*/
index a7f075b..56dc678 100644 (file)
--- a/lib/icl.c
+++ b/lib/icl.c
 /**
  * @brief global context
  */
-static GHashTable *icl_request_cb_hash;
 static bool icl_is_init = false;
 
-static void _free_resource(gpointer data)
-{
-       int ret;
-       iotcon_resource_h resource = data;
-
-       RET_IF(NULL == data);
-
-       ret = icl_dbus_unregister_resource(resource->handle);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("icl_dbus_unregister_resource() Fail(%d)", ret);
-
-       free(resource);
-}
-
-
-API int iotcon_initialize(const char *addr, unsigned short port)
+API int iotcon_initialize()
 {
        FN_CALL;
        int ret;
 
        RETVM_IF(true == icl_is_init, IOTCON_ERROR_INVALID_PARAMETER,  "already initialized");
-       RETV_IF(NULL == addr, IOTCON_ERROR_INVALID_PARAMETER);
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+       g_type_init();
+#endif
 
        ret = icl_dbus_start();
        if (IOTCON_ERROR_NONE != ret) {
@@ -64,13 +51,6 @@ API int iotcon_initialize(const char *addr, unsigned short port)
                return ret;
        }
 
-
-       icl_request_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
-                       _free_resource);
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
-       g_type_init();
-#endif
        icl_is_init = true;
 
        return IOTCON_ERROR_NONE;
@@ -85,25 +65,10 @@ API void iotcon_deinitialize()
 
        icl_dbus_stop();
 
-       g_hash_table_destroy(icl_request_cb_hash);
-       icl_request_cb_hash = NULL;
-
        icl_is_init = false;
 }
 
 
-static gboolean _find_valid_resource(gpointer key, gpointer value, gpointer user_data)
-{
-       return (key == user_data);
-}
-
-
-iotcon_resource_h icl_get_resource_handler_data(void *handle)
-{
-       return g_hash_table_find(icl_request_cb_hash, _find_valid_resource, handle);
-}
-
-
 /* The length of uri should be less than or equal to 36. */
 API iotcon_resource_h iotcon_register_resource(const char *uri,
                iotcon_resource_types_h res_types,
@@ -143,8 +108,6 @@ API iotcon_resource_h iotcon_register_resource(const char *uri,
        resource->ifaces = ifaces;
        resource->is_observable = properties & IOTCON_OBSERVABLE;
 
-       g_hash_table_insert(icl_request_cb_hash, resource->handle, resource);
-
        return resource;
 }
 
@@ -152,10 +115,23 @@ API iotcon_resource_h iotcon_register_resource(const char *uri,
 API void iotcon_unregister_resource(iotcon_resource_h resource)
 {
        FN_CALL;
+       int ret;
 
        RET_IF(NULL == resource);
 
-       g_hash_table_remove(icl_request_cb_hash, resource->handle);
+       ret = icl_dbus_unregister_resource(resource->handle);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_dbus_unregister_resource() Fail(%d)", ret);
+               return;
+       }
+       resource->handle = NULL;
+
+       free(resource->uri);
+       resource->uri = NULL;
+       free(resource->types);
+       resource->types = NULL;
+
+       free(resource);
 }
 
 
index 6a4b73c..d10d7c8 100644 (file)
--- a/lib/icl.h
+++ b/lib/icl.h
 #endif
 #define API __attribute__((visibility("default")))
 
-
 #define ICL_INTERFACE_MAX (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | \
                IOTCON_INTERFACE_BATCH | IOTCON_INTERFACE_GROUP)
 
-iotcon_resource_h icl_get_resource_handler_data(void *handle);
-
 #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_H__ */
index 9fb853b..08d121b 100644 (file)
@@ -16,8 +16,6 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
 #define __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
 
-#define IOTCON_ALL_INTERFACES "0.0.0.0"
-#define IOTCON_RANDOM_PORT 0
 #define IOTCON_MULTICAST_ADDRESS "224.0.1.187"
 
 /**
index 4db6384..d9dab9a 100644 (file)
@@ -26,7 +26,7 @@ extern "C" {
 #include <iotcon-constant.h>
 #include <iotcon-representation.h>
 
-int iotcon_initialize(const char *addr, unsigned short port);
+int iotcon_initialize();
 void iotcon_deinitialize();
 
 typedef void (*iotcon_request_handler_cb)(iotcon_request_h request, void *user_data);
index 9666436..c7d31fa 100644 (file)
@@ -236,8 +236,8 @@ int main(int argc, char **argv)
        GMainLoop *loop;
        loop = g_main_loop_new(NULL, FALSE);
 
-       /* initialize address and port */
-       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       /* iotcon initialize */
+       iotcon_initialize();
 
        /* find door typed resources */
        iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.door", &_found_resource, NULL);
index 369210b..90a7f40 100644 (file)
@@ -311,8 +311,8 @@ int main(int argc, char **argv)
 
        loop = g_main_loop_new(NULL, FALSE);
 
-       /* initialize address and port */
-       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       /* iotcon initialize */
+       iotcon_initialize();
 
        /* set local door resource */
        iotcon_error = _set_door_resource();
index c7a95ef..f7ed770 100644 (file)
@@ -24,7 +24,8 @@ int main()
 
        loop = g_main_loop_new(NULL, FALSE);
 
-       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       /* iotcon initialize */
+       iotcon_initialize();
 
        iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, _get_device_info, NULL);
 
index 4a046b0..4570502 100644 (file)
@@ -24,7 +24,8 @@ int main()
 
        loop = g_main_loop_new(NULL, FALSE);
 
-       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       /* iotcon initialize */
+       iotcon_initialize();
 
        ret = iotcon_register_device_info(device_info);
        if (IOTCON_ERROR_NONE != ret) {
index e89b7e1..2172718 100644 (file)
@@ -195,8 +195,8 @@ int main(int argc, char **argv)
        GMainLoop *loop;
        loop = g_main_loop_new(NULL, FALSE);
 
-       /* initialize address and port */
-       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       /* iotcon initialize */
+       iotcon_initialize();
 
        /* find room typed resources */
        iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.room", &_found_resource, NULL);
index 1e0341b..a565e18 100644 (file)
@@ -246,8 +246,8 @@ int main(int argc, char **argv)
 
        loop = g_main_loop_new(NULL, FALSE);
 
-       /* initialize address and port */
-       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+       /* iotcon initialize */
+       iotcon_initialize();
 
        /* register room resource */
        room_rtypes = iotcon_resource_types_new();