Add APIs related to device name 44/69044/13
authoryoungman <yman.jung@samsung.com>
Mon, 9 May 2016 04:15:23 +0000 (13:15 +0900)
committerSunggoo Kim <sung.goo.kim@samsung.com>
Thu, 2 Jun 2016 05:29:29 +0000 (22:29 -0700)
Change-Id: I32b1706eacc84abbe1205d87ed6a59b7a8f4c780
Signed-off-by: youngman <yman.jung@samsung.com>
16 files changed:
lib/icl-device.c
lib/icl-ioty-types.c
lib/icl-lite-resource.c
lib/icl-remote-resource.c
lib/icl-remote-resource.h
lib/icl-resource.c
lib/icl-resource.h
lib/include/iotcon-client.h
lib/include/iotcon-lite-resource.h
lib/include/iotcon-remote-resource.h
lib/include/iotcon-resource.h
lib/include/iotcon-server.h
test/iotcon-test-basic-client.c
test/iotcon-test-basic-server.c
test/iotcon-test-iface-client.c
test/iotcon-test-iface-server.c

index b019966dcae752068f76e4124a0d2cf1b349415e..32544d9ffc2da97b750e0b8d94042bf62d9fa58a 100644 (file)
@@ -82,6 +82,22 @@ API int iotcon_find_device_info(const char *host_address,
        return IOTCON_ERROR_NONE;
 }
 
+API int iotcon_set_device_name(const char *device_name)
+{
+       int ret;
+
+       RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == device_name || '\0' == *device_name, IOTCON_ERROR_INVALID_PARAMETER);
+
+       ret = icl_ioty_set_device_info(device_name);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_set_device_info() Fail(%d)", ret);
+               return ret;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
 API int iotcon_platform_info_get_property(iotcon_platform_info_h platform_info,
                iotcon_platform_info_e property, char **value)
 {
index 7d4063bd075bd6fc06a40b794ced0d11331d5294..7dd95314317c793de5063e485d08c12042952ee9 100644 (file)
@@ -93,6 +93,7 @@ int icl_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
                iotcon_resource_interfaces_h ifaces;
                iotcon_resource_types_h types;
                char host_addr[PATH_MAX] = {0};
+               char *device_name;
                OCStringLL *node;
 
                /* uri path */
@@ -178,6 +179,19 @@ int icl_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
                        _icl_ioty_free_resource_list(res_list, res_count);
                        return IOTCON_ERROR_OUT_OF_MEMORY;
                }
+
+               if (payload->name)
+                       device_name = strdup(payload->name);
+               else
+                       device_name = strdup("");
+               if (NULL == device_name) {
+                       ERR("strdup(device_name) Fail(%d)", errno);
+                       _icl_ioty_free_resource_list(res_list, res_count);
+                       return IOTCON_ERROR_OUT_OF_MEMORY;
+               }
+
+               res_list[i]->device_name = device_name;
+
                iotcon_resource_interfaces_destroy(ifaces);
                iotcon_resource_types_destroy(types);
        }
@@ -201,7 +215,13 @@ int icl_ioty_parse_oic_device_payload(OCDevicePayload *payload,
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       info->device_name = ic_utils_strdup(payload->deviceName);
+       if (payload->deviceName)
+               info->device_name = strdup(payload->deviceName);
+       else
+               info->device_name = strdup("");
+       if (NULL == info->device_name)
+               ERR("strdup(device_name) Fail(%d)", errno);
+
        info->spec_ver = ic_utils_strdup(payload->specVersion);
        info->data_model_ver = ic_utils_strdup(payload->dataModelVersion);
        info->device_id = ic_utils_strdup(payload->sid);
index 15f1cede8f7eb174627b5285afd6b98d66456197..907681c29744b3f15825350fe91b0cdd4df634dc 100644 (file)
@@ -30,7 +30,7 @@
 #include "icl-ioty.h"
 
 
-/* The length of uri_path should be less than or equal to 36. */
+/* The length of uri_path should be less than 64. */
 API int iotcon_lite_resource_create(const char *uri_path,
                iotcon_resource_types_h res_types,
                uint8_t policies,
index f7ac7df484b146d39863d0d46b3cf1803c79fd04..9d6c9d7f7c0fe1e8a88b00b9f0f9264dc83602c0 100644 (file)
@@ -125,6 +125,7 @@ static void _icl_remote_resource_destroy(iotcon_remote_resource_h resource)
        free(resource->uri_path);
        free(resource->host_address);
        free(resource->device_id);
+       free(resource->device_name);
        iotcon_resource_interfaces_destroy(resource->ifaces);
        iotcon_resource_types_destroy(resource->types);
 
@@ -207,6 +208,7 @@ API int iotcon_remote_resource_clone(iotcon_remote_resource_h src,
        resource->host_address = ic_utils_strdup(src->host_address);
        resource->connectivity_type = src->connectivity_type;
        resource->device_id = ic_utils_strdup(src->device_id);
+       resource->device_name = ic_utils_strdup(src->device_name);
        resource->policies = src->policies;
        resource->ref_count = 1;
 
@@ -299,6 +301,23 @@ API int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource,
        return IOTCON_ERROR_NONE;
 }
 
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_remote_resource_get_device_name(iotcon_remote_resource_h resource,
+               char **device_name)
+{
+       RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == device_name, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(NULL == resource->device_name, IOTCON_ERROR_NO_DATA,
+                       "If you want to get device name, you should call iotcon_find_resource().");
+
+       *device_name = resource->device_name;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
 /* The content of the resource should not be freed by user. */
 API int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
                iotcon_resource_types_h *types)
index 719baacbdba044373a76b25a2aa93a57664b58f1..fc6c49f5e25d18ad28be862829184dcaf110b067 100644 (file)
@@ -29,6 +29,7 @@ struct icl_remote_resource {
        char *uri_path;
        char *host_address;
        char *device_id;
+       char *device_name;
        uint8_t policies;
        iotcon_options_h header_options;
        iotcon_resource_types_h types;
index e95952ddc861e8427a20bf625fbe94fa8df62f62..24c1ff9f133297c944513041bfa8d9f50df34283 100644 (file)
@@ -102,7 +102,7 @@ bool icl_resource_check_interface(const char *iface)
 }
 
 
-/* The length of uri_path should be less than or equal to 36. */
+/* The length of uri_path should be less than 64. */
 API int iotcon_resource_create(const char *uri_path,
                iotcon_resource_types_h res_types,
                iotcon_resource_interfaces_h ifaces,
index 05c4663614d01ade18ecc681389b890abdd4bbd4..89cb864eb0067e35c3ec22c8386ac8be9f798407 100644 (file)
@@ -26,7 +26,7 @@
  *
  * @since_tizen 3.0
  */
-#define ICL_URI_PATH_LENGTH_MAX 36
+#define ICL_URI_PATH_LENGTH_MAX 64
 
 struct icl_notify_msg {
        char *iface;
index 98d47b3488e527455ebc93f02223f74356e4d159..7e83c62c187ad23bdae2a5014f0ef0d435b78eb6 100644 (file)
@@ -430,6 +430,7 @@ typedef void (*iotcon_device_info_cb)(iotcon_device_info_h device_info,
  * @pre iotcon_initialize() should be called to initialize.
  * @post iotcon_device_info_cb() will be invoked.
  *
+ * @see iotcon_set_device_name()
  * @see iotcon_device_info_cb()
  * @see iotcon_device_info_get_property()
  * @see iotcon_set_timeout()
@@ -455,6 +456,7 @@ int iotcon_find_device_info(const char *host_address,
  * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_set_device_name()
  * @see iotcon_device_info_cb()
  * @see iotcon_find_device_info()
  */
index c1ee6f96467baf1b1430220dd68f570da4372517..be35675c2d1d5ae406232f13911eb6c9bea098ee 100644 (file)
@@ -178,7 +178,7 @@ typedef bool (*iotcon_lite_resource_post_request_cb)(iotcon_lite_resource_h reso
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
- * @remarks @a uri_path length must be less than or equal 36.\n
+ * @remarks @a uri_path length must be less than 64.\n
  * You must destroy @a resource_handle by calling iotcon_lite_resource_destroy()
  * if @a remote_handle is no longer needed.
  *
index 53d86287fed98b928259749c4d8563bb8aa955ad..62f4a5b00d8253c7e6430f2cf3359dc201bd79a9 100644 (file)
@@ -583,6 +583,7 @@ int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource);
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_get_policies()
@@ -608,6 +609,7 @@ int iotcon_remote_resource_get_uri_path(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_get_policies()
@@ -634,6 +636,7 @@ int iotcon_remote_resource_get_connectivity_type(iotcon_remote_resource_h resour
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_uri_path()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_get_policies()
@@ -661,6 +664,7 @@ int iotcon_remote_resource_get_host_address(iotcon_remote_resource_h resource,
  * @retval #IOTCON_ERROR_NO_DATA No data available
  *
  * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_types()
@@ -671,6 +675,38 @@ int iotcon_remote_resource_get_host_address(iotcon_remote_resource_h resource,
 int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource,
                char **device_id);
 
+/**
+ * @brief Gets the device name of the remote resource.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a device_name must not be released using free().\n
+ * If @a resource is created by calling iotcon_remote_resource_create(), you cannot get
+ * @a device_name. In this case, the return value of this function is #IOTCON_ERROR_NO_DATA.
+ *
+ * @param[in] resource The handle of the remote resource
+ * @param[out] device_name The device name of the remote resource
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ *
+ * @see iotcon_set_device_name()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
+ * @see iotcon_remote_resource_get_host_address()
+ * @see iotcon_remote_resource_get_connectivity_type()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_get_properties()
+ * @see iotcon_remote_resource_set_options()
+ */
+int iotcon_remote_resource_get_device_name(iotcon_remote_resource_h resource,
+               char **device_name);
+
 /**
  * @brief Gets resource types of the remote resource.
  *
@@ -690,6 +726,7 @@ int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_get_policies()
  * @see iotcon_remote_resource_set_options()
@@ -716,6 +753,7 @@ int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_policies()
  * @see iotcon_remote_resource_set_options()
@@ -742,6 +780,7 @@ int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_set_options()
@@ -769,6 +808,7 @@ int iotcon_remote_resource_get_policies(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_set_options()
@@ -794,6 +834,7 @@ int iotcon_remote_resource_get_options(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_host_address()
  * @see iotcon_remote_resource_get_connectivity_type()
  * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_device_name()
  * @see iotcon_remote_resource_get_types()
  * @see iotcon_remote_resource_get_interfaces()
  * @see iotcon_remote_resource_get_options()
index f23442ea1a3814ca9fff76239b158f32a9405706..bab4ed4d763750610d3d24240aa66d7ae2b94516 100644 (file)
@@ -218,7 +218,7 @@ typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
- * @remarks @a uri_path length must be less than or equal 36.\n
+ * @remarks @a uri_path length must be less than 64.\n
  * You must destroy @a resource by calling iotcon_resource_destroy()
  * if @a resource is no longer needed.
  *
index ccb2493d731e2838a586ac4116f87710455ec1d7..4ae4884bec1d1374c52d50dc1f2bed8a14cac2a7 100644 (file)
@@ -97,6 +97,30 @@ int iotcon_start_presence(unsigned int time_to_live);
  */
 int iotcon_stop_presence(void);
 
+/**
+ * @brief Sets the device name.
+ * @details The function sets the name of the local device (the device calling the function).
+ * If the device name is set, clients can get the name using iotcon_device_info_get_property()
+ * or iotcon_remote_resource_get_device_name().
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a device_name may not be an empty string.
+ *
+ * @param[in] device_name The device name
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
+ *
+ * @see iotcon_get_device_info()
+ * @see iotcon_device_info_get_property()
+ * @see iotcon_remote_resource_get_device_name()
+ */
+int iotcon_set_device_name(const char *device_name);
 
 /**
  * @}
index ff3a2eefba9e4b15fc1fb611cd5be8eadb9d7f0f..1518fed44fa76ccc8e4e70e6a361611f165f8b11 100644 (file)
@@ -421,6 +421,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
        char *resource_host;
        char *resource_uri_path;
        char *resource_device_id;
+       char *resource_device_name;
        iotcon_presence_h presence_handle;
        iotcon_resource_types_h resource_types;
        iotcon_resource_interfaces_h resource_interfaces;
@@ -450,6 +451,13 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
        }
        DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
 
+       ret = iotcon_remote_resource_get_device_name(resource, &resource_device_name);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_get_device_name() Fail(%d)", ret);
+               return;
+       }
+       DBG("[%s] resource device name : %s", resource_uri_path, resource_device_name);
+
        node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
 
        if (node && TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path,
index 0a259e67664413ce3ee5b7e1b2f01f0ca9e79cd9..41c20f925c772937be64b210540d4b04469cccd8 100644 (file)
@@ -570,6 +570,14 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       /* set device name */
+       ret = iotcon_set_device_name("iotcon-test-basic-server");
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_set_device_name() Fail(%d)", ret);
+               iotcon_deinitialize();
+               return -1;
+       }
+
        /* set local door resource */
        ret = _set_door_resource(&my_door);
        if (0 != ret) {
index ef34e29d3e2c8fbecb7a9f2361b5bf0c3d25805f..9bab6b2daeeb4d078f698bc7cf876d9df0b07f42 100644 (file)
@@ -278,6 +278,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
        char *resource_host;
        char *resource_uri_path;
        char *resource_device_id;
+       char *resource_device_name;
        iotcon_resource_interfaces_h resource_interfaces;
        iotcon_resource_types_h resource_types;
        iotcon_remote_resource_h cloned_resource;
@@ -304,6 +305,13 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
        }
        DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
 
+       ret = iotcon_remote_resource_get_device_name(resource, &resource_device_name);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_get_device_name() Fail(%d)", ret);
+               return;
+       }
+       DBG("[%s] resource device name : %s", resource_uri_path, resource_device_name);
+
        node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
 
        if (node && TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path,
index 90c737e84917b5a2395744b1358b3bccf9f43eba..1f08b5c73603df7e83a4394be00b49e94917081c 100644 (file)
@@ -752,6 +752,14 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       /* set device name */
+       ret = iotcon_set_device_name("iotcon-test-iface-server");
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_set_device_name() Fail(%d)", ret);
+               iotcon_deinitialize();
+               return -1;
+       }
+
        /* set resource */
        ret = _set_room_resource(&room);
        if (0 != ret) {