Revise resource_type/uri on sample code
authorsung.goo.kim <sung.goo.kim@samsung.com>
Thu, 5 Nov 2015 00:45:19 +0000 (09:45 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 10 Nov 2015 10:12:36 +0000 (19:12 +0900)
Change-Id: Ief69d8f8e9f3998a6eba4670e17e5346a848d4ee

doc/iotcon_doc.h
lib/icl-resource.c
test/iotcon-test-basic-client.c
test/iotcon-test-basic-server.c
test/iotcon-test-encap-client.c
test/iotcon-test-encap-server.c
test/iotcon-test-repr-client.c
test/iotcon-test-repr-server.c

index 9dcfb8a..0da0ab6 100644 (file)
@@ -70,7 +70,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                        return;
                }
 
-               ret = iotcon_representation_set_uri_path(resp_repr, "core.door");
+               ret = iotcon_representation_set_uri_path(resp_repr, "org.tizen.door");
                if (IOTCON_ERROR_NONE != ret) {
                        iotcon_representation_destroy(resp_repr);
                        iotcon_response_destroy(response);
@@ -115,8 +115,8 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        int ret;
        int interfaces = IOTCON_INTERFACE_DEFAULT;
        int properties = (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE);
-       const char *uri_path = "/a/door1";
-       const char *type = "core.door";
+       const char *uri_path = "/door/1";
+       const char *type = "org.tizen.door";
        iotcon_resource_types_h resource_types;
 
        ret = iotcon_resource_types_create(&resource_types);
@@ -203,7 +203,7 @@ static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
 ...
 {
        int ret;
-       const char *type = "core.door";
+       const char *type = "org.tizen.door";
 
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4, type,
                        &_found_resource, NULL);
@@ -277,8 +277,8 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        int interfaces = IOTCON_INTERFACE_DEFAULT;
        int properties = (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE);
        iotcon_resource_h door_handle;
-       const char *uri_path = "/a/door1";
-       const char *type = "core.door";
+       const char *uri_path = "/door/1";
+       const char *type = "org.tizen.door";
        iotcon_resource_types_h resource_types;
 
        ret = iotcon_resource_types_create(&resource_types);
index ccd8b5d..56327e4 100644 (file)
@@ -542,7 +542,6 @@ API int iotcon_resource_notify(iotcon_resource_h resource,
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
        if (0 == resource->sub_id) {
                ERR("Invalid Resource handle");
index 11de3e7..19304e7 100644 (file)
@@ -23,7 +23,8 @@
 static char *door_resource_device_id;
 static GList *device_id_list;
 
-static const char* const door_uri_path = "/a/door";
+#define DOOR_RESOURCE_URI_PREFIX "/door"
+#define DOOR_RESOURCE_TYPE "org.tizen.door"
 
 static void _on_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
                iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
@@ -417,7 +418,8 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
 
        node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
 
-       if (node && TEST_STR_EQUAL == strcmp(door_uri_path, resource_uri_path)) {
+       if (node && TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path,
+                       strlen(DOOR_RESOURCE_URI_PREFIX))) {
                DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
                return;
        }
@@ -492,7 +494,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                return;
        }
 
-       ret = iotcon_add_presence_cb(resource_host, connectivity_type, "core.door",
+       ret = iotcon_add_presence_cb(resource_host, connectivity_type, DOOR_RESOURCE_TYPE,
                        _presence_handler, NULL, &presence_handle);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_add_presence_cb() Fail(%d)", ret);
@@ -501,7 +503,8 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                return;
        }
 
-       if (TEST_STR_EQUAL == strcmp(door_uri_path, resource_uri_path)) {
+       if (TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path,
+                       strlen(DOOR_RESOURCE_URI_PREFIX))) {
                iotcon_query_h query;
 
                ret = iotcon_query_create(&query);
@@ -564,7 +567,7 @@ int main(int argc, char **argv)
 
        /* find door typed resources */
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
-                       "core.door", &_found_resource, NULL);
+                       DOOR_RESOURCE_TYPE, &_found_resource, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
                iotcon_disconnect();
index e6a7c43..c373550 100644 (file)
@@ -36,6 +36,10 @@ typedef struct _door_resource_s {
 
 static bool resource_created;
 
+#define DOOR_RESOURCE_URI "/door/1"
+#define DOOR_RESOURCE_URI2 "/door/2"
+#define DOOR_RESOURCE_TYPE "org.tizen.door"
+
 static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
                void *user_data);
 
@@ -45,15 +49,15 @@ static int _set_door_resource(door_resource_s *door)
 
        door->state = false;
 
-       door->uri_path = strdup("/a/door");
+       door->uri_path = strdup(DOOR_RESOURCE_URI);
        if (NULL == door->uri_path) {
-               ERR("strdup(/a/door) Fail");
+               ERR("strdup(%s) Fail", DOOR_RESOURCE_URI);
                return -1;
        }
 
-       door->type = strdup("core.door");
+       door->type = strdup(DOOR_RESOURCE_TYPE);
        if (NULL == door->type) {
-               ERR("strdup(core.door) Fail");
+               ERR("strdup(%s) Fail", DOOR_RESOURCE_TYPE);
                free(door->uri_path);
                return -1;
        }
@@ -323,7 +327,7 @@ static void _request_handler_post(door_resource_s *door, iotcon_response_h respo
                return;
        }
 
-       new_door_handle = _create_door_resource("/a/door1", door->type,
+       new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type,
                        IOTCON_INTERFACE_DEFAULT, (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), NULL);
        if (NULL == new_door_handle) {
                ERR("_create_door_resource() Fail");
@@ -345,7 +349,7 @@ static void _request_handler_post(door_resource_s *door, iotcon_response_h respo
                return;
        }
 
-       ret = iotcon_state_set_str(resp_state, "createduripath", "/a/door1");
+       ret = iotcon_state_set_str(resp_state, "createduripath", DOOR_RESOURCE_URI2);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_state_set_str() Fail(%d)", ret);
                iotcon_state_destroy(resp_state);
index 41dbc7f..e02691e 100644 (file)
@@ -23,6 +23,8 @@
 static char *door_resource_device_id;
 static GList *device_id_list;
 
+#define DOOR_RESOURCE_TYPE "org.tizen.door"
+
 static bool _get_res_type_cb(const char *string, void *user_data)
 {
        char *resource_uri_path = user_data;
@@ -232,7 +234,7 @@ int main(int argc, char **argv)
 
        /* find door typed resources */
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
-                       "core.door", &_found_resource, &resource);
+                       DOOR_RESOURCE_TYPE, &_found_resource, &resource);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
                iotcon_disconnect();
index 4dd0676..7c3868b 100644 (file)
@@ -22,6 +22,9 @@
 #include <iotcon-internal.h>
 #include "test.h"
 
+#define DOOR_RESOURCE_URI "/door/1"
+#define DOOR_RESOURCE_TYPE "org.tizen.door"
+
 /* Door Resource */
 typedef struct _door_resource_s {
        bool state;
@@ -35,15 +38,15 @@ static int _set_door_resource(door_resource_s *door)
 {
        door->state = false;
 
-       door->uri_path = strdup("/a/door");
+       door->uri_path = strdup(DOOR_RESOURCE_URI);
        if (NULL == door->uri_path) {
-               ERR("strdup(/a/door) Fail");
+               ERR("strdup(%s) Fail", DOOR_RESOURCE_URI);
                return -1;
        }
 
-       door->type = strdup("core.door");
+       door->type = strdup(DOOR_RESOURCE_TYPE);
        if (NULL == door->type) {
-               ERR("strdup(core.door) Fail");
+               ERR("strdup(%s) Fail", DOOR_RESOURCE_TYPE);
                free(door->uri_path);
                return -1;
        }
index 6c3a3ad..c28a1d3 100644 (file)
 static char *room_resource_device_id;
 static GList *device_id_list;
 
-static const char* const room_uri_path = "/a/room";
+#define ROOM_RESOURCE_TYPE "org.tizen.room"
+#define ROOM_RESOURCE_URI_PREFIX "/room"
+#define LIGHT_RESOURCE_URI_PREFIX "/light"
+#define SWITCH_RESOURCE_URI_PREFIX "/switch"
 
 static bool _get_int_list_cb(int pos, const int value, void *user_data)
 {
@@ -124,7 +127,8 @@ static void _on_get(iotcon_representation_h recv_repr, int response_result)
                        continue;
                }
 
-               if (TEST_STR_EQUAL == strcmp("/a/light", uri_path)) {
+               if (TEST_STR_EQUAL == strncmp(LIGHT_RESOURCE_URI_PREFIX, uri_path,
+                               strlen(LIGHT_RESOURCE_URI_PREFIX))) {
                        ret = iotcon_state_get_keys_count(child_state, &key_count);
                        if (IOTCON_ERROR_NONE != ret) {
                                ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
@@ -139,7 +143,8 @@ static void _on_get(iotcon_representation_h recv_repr, int response_result)
                                }
                                DBG("brightness : %d", int_val);
                        }
-               } else if (TEST_STR_EQUAL == strcmp("/a/switch", uri_path)) {
+               } else if (TEST_STR_EQUAL == strncmp(SWITCH_RESOURCE_URI_PREFIX, uri_path,
+                               strlen(SWITCH_RESOURCE_URI_PREFIX))) {
                        ret = iotcon_state_get_keys_count(child_state, &key_count);
                        if (IOTCON_ERROR_NONE != ret) {
                                ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
@@ -285,7 +290,8 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
 
        node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
 
-       if (node && TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
+       if (node && TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path,
+                       strlen(ROOM_RESOURCE_URI_PREFIX))) {
                DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
                return;
        }
@@ -342,7 +348,8 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                return;
        }
 
-       if (TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
+       if (TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path,
+                       strlen(ROOM_RESOURCE_URI_PREFIX))) {
                ret = iotcon_remote_resource_clone(resource, &cloned_resource);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("iotcon_remote_resource_clone() Fail(%d)", ret);
@@ -378,7 +385,7 @@ int main(int argc, char **argv)
 
        /* find room typed resources */
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
-                       "core.room", &_found_resource, NULL);
+                       ROOM_RESOURCE_TYPE, &_found_resource, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
                iotcon_disconnect();
index 4f021b9..2d78ae7 100644 (file)
 #include <iotcon.h>
 #include "test.h"
 
+#define LIGHT_RESOURCE_URI "/light/1"
+#define LIGHT_RESOURCE_TYPE "org.tizen.light"
+
+#define ROOM_RESOURCE_URI "/room/1"
+#define ROOM_RESOURCE_TYPE "org.tizen.room"
+
+#define SWITCH_RESOURCE_URI "/switch/1"
+
 static int _send_response(iotcon_response_h response, iotcon_representation_h repr,
                iotcon_interface_e iface)
 {
@@ -98,7 +106,7 @@ static void _room_request_handler_get(iotcon_request_h request,
                return;
        }
 
-       ret = iotcon_representation_set_uri_path(room_repr, "/a/room");
+       ret = iotcon_representation_set_uri_path(room_repr, ROOM_RESOURCE_URI);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
                iotcon_state_destroy(room_state);
@@ -200,7 +208,7 @@ static void _room_request_handler_get(iotcon_request_h request,
                return;
        }
 
-       ret = iotcon_representation_set_uri_path(light_repr, "/a/light");
+       ret = iotcon_representation_set_uri_path(light_repr, LIGHT_RESOURCE_URI);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
                iotcon_representation_destroy(light_repr);
@@ -257,7 +265,7 @@ static void _room_request_handler_get(iotcon_request_h request,
                return;
        }
 
-       ret = iotcon_representation_set_uri_path(switch_repr, "/a/switch");
+       ret = iotcon_representation_set_uri_path(switch_repr, SWITCH_RESOURCE_URI);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
                iotcon_representation_destroy(switch_repr);
@@ -498,15 +506,15 @@ int main(int argc, char **argv)
                iotcon_disconnect();
                return -1;
        }
-       ret = iotcon_resource_types_add(room_rtypes, "core.room");
+       ret = iotcon_resource_types_add(room_rtypes, ROOM_RESOURCE_TYPE);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_resource_types_add(%s) Fail(%d)", "core.room", ret);
+               ERR("iotcon_resource_types_add(%s) Fail(%d)", ROOM_RESOURCE_TYPE, ret);
                iotcon_resource_types_destroy(room_rtypes);
                iotcon_disconnect();
                return -1;
        }
 
-       ret = iotcon_resource_create("/a/room", room_rtypes,
+       ret = iotcon_resource_create(ROOM_RESOURCE_URI, room_rtypes,
                        (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
                        (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _room_request_handler,
                        NULL, &room_handle);
@@ -526,16 +534,16 @@ int main(int argc, char **argv)
                iotcon_disconnect();
                return -1;
        }
-       ret = iotcon_resource_types_add(light_rtypes, "core.light");
+       ret = iotcon_resource_types_add(light_rtypes, LIGHT_RESOURCE_TYPE);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_resource_types_add(%s) Fail(%d)", "core.light", ret);
+               ERR("iotcon_resource_types_add(%s) Fail(%d)", LIGHT_RESOURCE_TYPE, ret);
                iotcon_resource_types_destroy(light_rtypes);
                iotcon_resource_destroy(room_handle);
                iotcon_disconnect();
                return -1;
        }
 
-       ret = iotcon_resource_create("/a/light", light_rtypes,
+       ret = iotcon_resource_create(LIGHT_RESOURCE_URI, light_rtypes,
                        (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
                        (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _light_request_handler,
                        NULL, &light_handle);