Add example on doxygen
authorsung.goo.kim <sung.goo.kim@samsung.com>
Wed, 11 Nov 2015 23:59:32 +0000 (08:59 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Nov 2015 05:54:46 +0000 (14:54 +0900)
Change-Id: I7d44ce2ef7d80f2fa0e38e80bd53e22d14a21f4e

16 files changed:
doc/iotcon_doc.h
lib/icl-state.c
lib/include/iotcon-client.h
lib/include/iotcon-list.h
lib/include/iotcon-lite-resource.h
lib/include/iotcon-observers.h
lib/include/iotcon-options.h
lib/include/iotcon-query.h
lib/include/iotcon-remote-resource.h
lib/include/iotcon-representation.h
lib/include/iotcon-request.h
lib/include/iotcon-resource-types.h
lib/include/iotcon-resource.h
lib/include/iotcon-response.h
lib/include/iotcon-server.h
lib/include/iotcon-state.h

index 1884041..47e70da 100644 (file)
@@ -48,7 +48,7 @@
  * @code
 #include <iotcon.h>
 ...
-static void _request_handler(iotcon_request_h request, void *user_data)
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
 {
        int ret;
        iotcon_request_type_e type;
@@ -64,36 +64,43 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                if (IOTCON_ERROR_NONE != ret)
                        return;
 
+               ret = iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
                ret = iotcon_representation_create(&resp_repr);
                if (IOTCON_ERROR_NONE != ret) {
                        iotcon_response_destroy(response);
                        return;
                }
 
-               ret = iotcon_representation_set_uri_path(resp_repr, "org.tizen.door");
+               ret = iotcon_representation_set_uri_path(resp_repr, "/door/1");
                if (IOTCON_ERROR_NONE != ret) {
                        iotcon_representation_destroy(resp_repr);
                        iotcon_response_destroy(response);
                        return;
                }
 
-               ret = iotcon_state_set_bool(resp_repr, "opened", true);
+               ret = iotcon_state_create(&state);
                if (IOTCON_ERROR_NONE != ret) {
                        iotcon_representation_destroy(resp_repr);
                        iotcon_response_destroy(response);
                        return;
                }
 
-               ret = iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
+               ret = iotcon_state_set_bool(resp_repr, "opened", true);
                if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
                        iotcon_representation_destroy(resp_repr);
                        iotcon_response_destroy(response);
                        return;
                }
 
-
-               ret = iotcon_response_set_representation(response, resp_repr);
+               ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, resp_repr);
                if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
                        iotcon_representation_destroy(resp_repr);
                        iotcon_response_destroy(response);
                        return;
@@ -101,11 +108,13 @@ static void _request_handler(iotcon_request_h request, void *user_data)
 
                ret = iotcon_response_send(response);
                if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
                        iotcon_representation_destroy(resp_repr);
                        iotcon_response_destroy(response);
                        return;
                }
 
+               iotcon_state_destroy(state);
                iotcon_representation_destroy(resp_repr);
                iotcon_response_destroy(response);
        }
@@ -118,11 +127,11 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        const char *uri_path = "/door/1";
        const char *type = "org.tizen.door";
        iotcon_resource_types_h resource_types;
+       iotcon_resource_h resource = NULL;
 
        ret = iotcon_resource_types_create(&resource_types);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_resource_types_add(resource_types, type);
        if (IOTCON_ERROR_NONE != ret) {
@@ -130,9 +139,9 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                return;
        }
 
-       iotcon_resource_h handle = iotcon_resource_create(uri_path, resource_types,
-                       interfaces, properties, _request_handler, NULL);
-       if (NULL == handle) {
+       ret = iotcon_resource_create(uri_path, resource_types,
+                       interfaces, properties, _request_handler, NULL, &resource);
+       if (IOTCON_ERROR_NONE != ret) {
                iotcon_resource_types_destroy(resource_types);
                return;
        }
@@ -155,7 +164,8 @@ static void _on_response_get(iotcon_remote_resource_h resource, iotcon_error_e e
        // handle get from response
 }
 ...
-static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
+static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
+               void *user_data)
 {
        int ret;
        int resource_interfaces;
@@ -164,40 +174,51 @@ static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
        char *device_id;
        iotcon_query_h query;
        iotcon_resource_types_h resource_types;
+       iotcon_remote_resource_h resource_clone = NULL;
+
+       if (IOTCON_ERROR_NONE != result)
+               return;
 
        ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_remote_resource_get_device_id(resource, &device_id);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_remote_resource_get_host_address(resource, &resource_host);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_remote_resource_get_types(resource, &resource_types);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_query_create(&query);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_query_add(query, "key", "value");
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_remote_resource_clone(resource, &resource_clone);
        if (IOTCON_ERROR_NONE != ret) {
+               iotcon_query_destroy(query);
                return;
        }
 
-       iotcon_query_add(query, "key", "value");
+       ret = iotcon_remote_resource_get(resource_clone, query, _on_response_get, NULL);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_query_destroy(query);
+               return;
+       }
 
-       iotcon_remote_resource_get(resource, query, _on_response_get, NULL);
        iotcon_query_destroy(query);
 }
 ...
@@ -207,9 +228,8 @@ static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
 
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4, type,
                        _found_resource, NULL);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 }
  * @endcode
  *
@@ -225,45 +245,50 @@ static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
  * If an observed resource fails to notify a client before the max-age of a resource value update,
  * the client should attempt to re-register the observation.\n
  *
- * Example : Server side
+ * Example (Server side) :
  * @code
 #include <iotcon.h>
 ...
-static iotcon_resource_h door_handle;
-static iotcon_observers_h observers;
+static iotcon_resource_h _door_handle;
+static iotcon_observers_h _observers;
 ...
 static void _request_handler(iotcon_request_h request, void *user_data)
 {
        int ret;
-       int types;
        int observe_id;
        iotcon_observe_type_e observe_type;
 
        ret = iotcon_request_get_observe_type(request, &observe_type);
-       if (IOTCON_ERROR_NONE != ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        if (IOTCON_OBSERVE_REGISTER == observe_type) {
+               int observe_id;
                ret = iotcon_request_get_observe_id(request, &observe_id);
-               if (IOTCON_ERROR_NONE != ret) {
+               if (IOTCON_ERROR_NONE != ret)
                        return;
-               }
 
-               ret = iotcon_observers_add(observers, observe_id);
-               if (IOTCON_ERROR_NONE != ret) {
-                       return;
+               if (NULL == _observers) {
+                       ret = iotcon_observers_create(&_observers);
+                       if (IOTCON_ERROR_NONE != ret)
+                               return;
                }
+               ret = iotcon_observers_add(_observers, observe_id);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
        } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
+               int observe_id;
+
+               if (NULL == _observers)
+                       return;
+
                ret = iotcon_request_get_observe_id(request, &observe_id);
-               if (IOTCON_ERROR_NONE != ret) {
+               if (IOTCON_ERROR_NONE != ret)
                        return;
-               }
 
-               ret = iotcon_observers_remove(observers, observe_id);
-               if (IOTCON_ERROR_NONE != ret) {
+               ret = iotcon_observers_remove(_observers, observe_id);
+               if (IOTCON_ERROR_NONE != ret)
                        return;
-               }
        }
 }
 ...
@@ -271,15 +296,13 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        int ret;
        int interfaces = IOTCON_INTERFACE_DEFAULT;
        int properties = (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE);
-       iotcon_resource_h door_handle;
        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);
-       if (IOTCON_ERROR_NONE == ret) {
+       if (IOTCON_ERROR_NONE != ret)
                return;
-       }
 
        ret = iotcon_resource_types_add(resource_types, type);
        if (IOTCON_ERROR_NONE != ret) {
@@ -288,7 +311,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        }
 
        ret = iotcon_resource_create(uri_path, resource_types,
-                       interfaces, properties, _request_handler, NULL, door_handle);
+                       interfaces, properties, _request_handler, NULL, &_door_handle);
        if (IOTCON_ERROR_NONE != ret) {
                iotcon_resource_types_destroy(resource_types);
                return;
@@ -306,7 +329,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                return;
        }
 
-       ret = iotcon_resource_notify(door_handle, resp_repr, observers);
+       ret = iotcon_resource_notify(_door_handle, resp_repr, _observers);
        if (IOTCON_ERROR_NONE != ret) {
                iotcon_representation_destroy(resp_repr);
                return;
@@ -316,13 +339,13 @@ static void _request_handler(iotcon_request_h request, void *user_data)
 }
  * @endcode
  *
- * Example : Client side
+ * Example (Client side) :
  * @code
 #include <iotcon.h>
 ...
-static iotcon_remote_resource_h door_resource;
+static iotcon_remote_resource_h _door_resource;
 ...
-static void _on_resopnse_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
+static void _on_response_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
                iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
 {
 }
index 3ff2a00..3aab0e4 100644 (file)
@@ -77,6 +77,21 @@ API void iotcon_state_destroy(iotcon_state_h state)
        }
 }
 
+API int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone)
+{
+       int ret;
+       RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == state_clone, IOTCON_ERROR_INVALID_PARAMETER);
+
+       ret = icl_state_clone(state, state_clone);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_state_clone() Fail(%d)", ret);
+               return ret;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
 
 int icl_state_del_value(iotcon_state_h state, const char *key)
 {
index 8a071bb..fbbf008 100644 (file)
@@ -29,7 +29,7 @@
  *
  * @brief Iotcon Client provides API for client side.
  *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_CLIENT_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
  * @section CAPI_IOT_CONNECTIVITY_CLIENT_MODULE_OVERVIEW Overview
index 9d3061e..24c57dd 100644 (file)
  *
  * @brief Iotcon List provides API to get data from list and set data to list.
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_OVERVIEW Overview
+ * The iotcon list API provides list of bool, integer, double, string, list and state handle.
+ *
+ * Example :
+ * @code
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       int ret;
+       iot types;
+
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       if (IOTCON_REQUEST_GET & types) {
+               iotcon_response_h response = NULL;
+               iotcon_representation_h representation = NULL;
+               iotcon_state_h state = NULL;
+               iotcon_list_h list = NULL;
+
+               ret = iotcon_response_create(request, &response);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_representation_create(&representation);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ...
+
+               ret = iotcon_state_create(&state);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_list_create(IOTCON_TYPE_INT, &list);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_list_add_int(list, 1);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_list_add_int(list, 2);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_list_add_int(list, 10);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = itocon_state_set_list(state, "ids", list);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_representation_set_state(representation, state);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ...
+
+               ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT,
+                               representation);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_response_send(response);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_list_destroy(list);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               iotcon_list_destroy(list);
+               iotcon_state_destroy(state);
+               iotcon_representation_destroy(representation);
+               iotcon_response_destroy(resopnse);
+       }
+       ...
+}
+ * @endcode
+ *
+ *
  * @{
  */
 
index 6267778..3e47f05 100644 (file)
  *
  * @brief Iotcon Lite Resource provides API to encapsulate resources.
  *
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE_HEADER Required Header
+ *  \#include <iotcon.h>
+ *
  * @section CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE_OVERVIEW Overview
  * This API provides that the users manages resources without request handler.
  * When client request by CRUD functions, internal default request handler will be invoked.
  * The default request handler will create response and send to client automatically.
  * When updated state by iotcon_lite_update_state(), changes will notify to observers.
  *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE_HEADER Header
- *  \#include <iotcon.h>
+ * Example :
+ * @code
+#include <iotcon.h>
+...
+static iotcon_lite_resource_h _resource;
+
+static void _create_light_resource()
+{
+       int ret;
+       iotcon_lite_resource_h resource = NULL;
+       iotcon_resource_types_h resource_types = NULL;
+       iotcon_state_h state = NULL;
+
+       ret = iotcon_resource_types_create(&resource_types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_state_create(&state);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_state_set_bool(state, "power", true);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_state_destroy(state);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_state_set_int(state, "brightness", 75);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_state_destroy(state);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_lite_resource_create("/light/1", resource_types,
+                       IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE, state, &resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_state_destroy(state);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       iotcon_state_destroy(state);
+       iotcon_resource_types_destroy(resource_types);
+
+       _resource = resource;
+}
+
+static void _update_brightness(int brightness)
+{
+       int ret;
+       iotcon_state_h state = NULL;
+       iotcon_state_h state_clone = NULL;
+
+       ret = iotcon_lite_resource_get_state(_resource, &state);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_state_clone(state, &state_clone);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_state_set_int(state_clone, "brightness", brightness);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_state_destroy(state_clone);
+               return;
+       }
+
+       ret = iotcon_lite_resource_update_state(_resource, state_clone);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_state_destroy(state_clone);
+               return;
+       }
+
+       iotcon_state_destroy(state_clone);
+}
+
+ * @endcode
  *
  * @{
  */
index 4cc1e90..bcd721d 100644 (file)
  *
  * @brief Iotcon Observers provides API to manage client observing a resource.
  *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE_OVERVIEW Overview
+ * The iotcon overview API provides methods for managing oberve id.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+static iotcon_observers_h _observers;
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       int ret;
+       int types;
+
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       if (IOTCON_REQUEST_OBSERVE & types) {
+               int observe_id;
+               iotcon_observe_action_e action;
+
+               ret = iotcon_request_get_observe_action(request, &action);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_request_get_observe_id(request, &observe_id);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               if (IOTCON_OBSERVE_REGISTER & action) {
+                       if (NULL == _observers) {
+                               ret = iotcon_observers_create(&_observers);
+                               if (IOTCON_ERROR_NONE != ret)
+                                       return;
+                       }
+                       ret = iotcon_observers_add(_observers, observe_id);
+                       if (IOTCON_ERROR_NONE != ret)
+                               return;
+               } else if (IOTCON_OBSERVE_DEREGISTER & action) {
+                       if (NULL == _observers)
+                               return;
+                       ret = iotcon_observers_remove(_observers, observe_id);
+                       if (IOTCON_ERROR_NONE != ret)
+                               return;
+               }
+       }
+       if (IOTCON_REQUEST_PUT & types) {
+               iotcon_state_h state = NULL;
+               iotcon_representation_h repr = NULL;
+               ...
+
+               ret = iotcon_representation_create(&repr);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_state_create(&state);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(repr);
+                       return;
+               }
+               ...
+               ret = iotcon_resource_notify(resource, repr, _observers);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(repr);
+                       return;
+               }
+
+               iotcon_state_destroy(state);
+               iotcon_representation_destroy(repr);
+       }
+       ...
+}
+ * @endcode
+ *
  * @{
  */
 
index d69b297..01ca9d8 100644 (file)
  *
  * @brief Iotcon Options provides API to manage options.
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE_OVERVIEW Overview
+ * The iotcon options API provides methods for managing vendor specific options of coap packet.\n
+ * See more about coap packet in http://tools.ietf.org/html/rfc7252.
+ *
+ * Example (Client side) :
+ * @code
+#include <iotcon.h>
+...
+static void _request_get_with_option(iotcon_remote_resource_h resource)
+{
+       int i;
+       int ret;
+       unsigned short opt_id = 3000;
+       const char *opt_val = "12345";
+       iotcon_options_h options = NULL;
+
+       ..
+       ret = iotcon_options_create(&options);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_options_add(options, opt_id, opt_val);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_options_destroy(options);
+               return;
+       }
+
+       ret = iotcon_remote_resource_set_options(resource, options);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_options_destroy(options);
+               return;
+       }
+
+       ret = iotcon_remote_resource_get(resource, NULL, _on_get, NULL);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_options_destroy(options);
+               return;
+       }
+
+       iotcon_options_destroy(options);
+       ...
+}
+ * @endcode
+ *
+ * Example (Server side) :
+ * @code
+#include <iotcon.h>
+...
+static bool _options_foreach(unsigned short id, const char *data, void *user_data)
+{
+       // handle options
+       return IOTCON_FUNC_CONTINUE;
+}
+
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       int ret;
+       iotcon_options_h options;
+
+       ret = iotcon_request_get_options(request, &options);
+       if (IOTCON_ERROR_NONE == ret && options) {
+               ret = iotcon_options_foreach(options, _options_foreach, NULL);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+       }
+       ...
+}
+
+ * @endcode
  * @{
  */
 
index a62a36e..a49baef 100644 (file)
  *
  * @brief Iotcon Query provides API to manage query.
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE_OVERVIEW Overview
+ * The iotcon query API provides methods for managing query of request.
+ *
+ * Example (Client side) :
+ * @code
+#include <iotcon.h>
+...
+static void _request_get(iotcon_remote_resource_h resource)
+{
+       int ret;
+       iotcon_query_h query = NULL;
+
+       ret = iotcon_query_create(&query);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_query_add(query, "key", "value");
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_query_destroy(query);
+               return;
+       }
+
+       ret = iotcon_remote_resource_get(resource, query, _on_get, NULL);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_query_destroy(query);
+               return;
+       }
+
+       iotcon_query_destroy(query);
+}
+ * @endcode
+ *
+ * Example (Server side) :
+ * @code
+#include <iotcon.h>
+...
+static bool _query_foreach(const char *key, const char *value, void *user_data)
+{
+       // handle query
+       return IOTCON_FUNC_CONTINUE;
+}
+
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       int ret;
+       iotcon_query_h query = NULL;
+
+       ret = iotcon_request_get_query(request, &query);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       if (IOTCON_ERROR_NONE == ret && query) {
+               ret = iotcon_query_foreach(query, _query_foreach, NULL);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+       }
+       ...
+}
+ * @endcode
+ *
  * @{
  */
 
index 81bcbbf..0f0396f 100644 (file)
  *
  * @brief Iotcon Remote Resource provides API to manage remote resource.
  *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE_OVERVIEW Overview
+ * The iotcon remote resource API provides methods for managing resource handle and send request.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+...
+static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
+               iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
+{
+       if (IOTCON_ERROR_NONE != err)
+               return;
+
+       // handle get result
+       ...
+}
+
+static void _on_find(iotcon_remote_resource_h resource, iotcon_error_e result,
+               void *user_data)
+{
+       int ret;
+       iotcon_remote_resource_h resource_clone = NULL;
+
+       if (IOTCON_ERROR_NONE != result)
+               return;
+
+       if (NULL == resource)
+               return;
+
+       // clone handle
+       ret = iotcon_remote_resource_clone(resource, &resource_clone);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       // request get
+       ret = iotcon_remote_resource_get(resource_clone, NULL, _on_get, NULL);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_remote_resource_destroy(resource_clone);
+               return;
+       }
+
+       ...
+}
+
+static void _find_light_resource()
+{
+       int ret;
+
+       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
+                       "org.tizen.light", _on_find, NULL);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+}
+
+ * @endcode
+ *
  * @{
  */
 
@@ -140,14 +196,14 @@ typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resou
 /**
  * @brief Registers observe callback on the resource
  * @details When server sends notification message, iotcon_remote_resource_response_cb() will be called.
- * The @a observe_type could be one of #iotcon_observe_policy_e.
+ * The @a observe_policy could be one of #iotcon_observe_policy_e.
  *
  * @since_tizen 3.0
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] resource The handle of the resource
- * @param[in] observe_type The type to specify how client wants to observe.
+ * @param[in] observe_policy The type to specify how client wants to observe.
  * @param[in] query The query to send to server
  * @param[in] cb The callback function to get notifications from server
  * @param[in] user_data The user data to pass to the function
index ac9942b..6897169 100644 (file)
@@ -28,7 +28,7 @@
  *
  * @brief Iotcon Representation provides API to manage representation
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
  * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_OVERVIEW Overview
@@ -39,7 +39,8 @@
  * resp_repr.\n
  * A list is a container that includes number of datas of same type.\n
  * It has capabilties to store and retrieve integer, boolean, double, string, list, null, resp_repr.
- * Example
+ *
+ * Example :
  *@code
 #include <iotcon.h>
 ...
index 8a53b4b..a9e0a94 100644 (file)
  *
  * @brief Iotcon Request provides API to manage client's request.
  *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE_OVERVIEW Overview
+ * The iotcon request API provides methods for managing request handle.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       int ret;
+       int types;
+       iotcon_options_h options = NULL;
+       iotcon_query_h query = NULL;
+       iotcon_representation_h repr = NULL;
+
+       ret = iotcon_request_get_options(request, &options);
+       if (IOTCON_ERROR_NONE == ret && options) {
+               // handle options
+               ...
+       }
+
+       ret = iotcon_request_get_query(request, &query);
+       if (IOTCON_ERROR_NONE == ret && query) {
+               // handle query
+               ...
+       }
+
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       if (IOTCON_REQUEST_GET & types) {
+               // handle get
+               ...
+       }
+       if (IOTCON_REQUEST_PUT & types) {
+               // handle put
+               ret = iotcon_request_get_representation(request, &repr);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+               ...
+       }
+       if (IOTCON_REQUEST_POST & types) {
+               // handle post
+               ret = iotcon_request_get_representation(request, &repr);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+               ...
+       }
+       if (IOTCON_REQUEST_DELETE & types) {
+               // handle delete
+               ret = iotcon_request_get_representation(request, &repr);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+               ...
+       }
+       if (IOTCON_REQUEST_OBSERVE & types) {
+               int observe_id;
+               iotcon_observe_action_e action;
+               char *host_address;
+               iotcon_connectivity_type_e conn_type;
+
+               ret = iotcon_request_get_observe_action(request, &action);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_request_get_observe_id(request, &observe_id);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_request_get_host_address(request, &host_address);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_request_get_connectivity_type(request, &conn_type);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               if (IOTCON_OBSERVE_REGISTER == action) {
+                       // handle register observe
+                       ...
+               } else if (IOTCON_OBSERVE_DEREGISTER == action) {
+                       // handle deregister observe
+                       ...
+               }
+       }
+}
+ * @endcode
+ *
  * @{
  */
 
index 785046b..2ab619d 100644 (file)
  *
  * @brief Iotcon Resource Types provides API to manage resource types.
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE_OVERVIEW Overview
+ * The iotcon resource types API provides methods for managing handle and add, remove resource types.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       // handle request
+       ...
+}
+
+static void _create_light_resource()
+{
+       int ret;
+       iotcon_resource_h resource = NULL;
+       iotcon_resource_types_h resource_types = NULL;
+
+       ret = iotcon_resource_types_create(&resource_types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_create("/light/1", resource_types, IOTCON_INTERFACE_DEFAULT,
+                       IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE, _request_handler, NULL, &resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       iotcon_resource_types_destroy(resource_types);
+}
+ * @endcode
+ *
  * @{
  */
 
index ab0ce45..3cc2bb4 100644 (file)
  *
  * @brief Iotcon Resource provides API to manage resource.
  *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE_OVERVIEW Overview
+ * The iotcon resource API provides methods for managing handle and resource information.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+
+static iotcon_resource_h _resource_room;
+
+static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
+{
+       // handle request
+       ...
+}
+
+static void _door_request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
+{
+       // handle request
+       ...
+}
+
+static void _create_resource()
+{
+       int ret;
+       int ifaces;
+       int properties;
+       iotcon_resource_types_h resource_types = NULL;
+       iotcon_resource_h resource_door = NULL;
+
+       // 1. create room resource
+       ifaces = IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH;
+       properties = IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE;
+
+       ret = iotcon_resource_types_create(&resource_types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_resource_types_add(resource_types, "org.tizen.room");
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_create("/room/1", resource_types, ifaces,
+                       properties, _room_request_handler, NULL, &_resource_room);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+       iotcon_resource_types_destroy(resource_types);
+
+       // 2. create door resource
+       ifaces = IOTCON_INTERFACE_DEFAULT;
+       properties = IOTCON_OBSERVABLE;
+
+       ret = iotcon_resource_types_create(&resource_types);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_destroy(_resource_room);
+               _resource_room = NULL;
+               return;
+       }
+
+       ret = iotcon_resource_types_add(resource_types, "org.tizen.door");
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               iotcon_resource_destroy(_resource_room);
+               _resource_room = NULL;
+               return;
+       }
+
+       ret = iotcon_resource_create("/door/1", resource_types, ifaces,
+                       properties, _door_request_handler, NULL, &resource_door);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               iotcon_resource_destroy(_resource_room);
+               _resource_room = NULL;
+               return;
+       }
+       iotcon_resource_types_destroy(resource_types);
+
+       // 3. bind door resouce to room resource
+       ret = iotcon_resource_bind_child_resource(_resource_room, resource_door);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_destroy(resource_door);
+               iotcon_resource_destroy(_resource_room);
+               _resource_room = NULL;
+               return;
+       }
+}
+ * @endcode
+ *
  * @{
  */
 
index 6dc5bb1..5e7c28a 100644 (file)
  *
  * @brief Iotcon Response provides API to manage response.
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE_OVERVIEW Overview
+ * The iotcon response API provides methos for managing handle and get response information.
+ *
+ * Example (Client side) :
+ * @code
+#include <iotcon.h>
+
+static void _state_foreach(iotcon_state_h state, const char *key, void *user_data)
+{
+       // handle state
+       ...
+}
+
+static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
+               iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
+{
+       int ret;
+       iotcon_response_result_e response_result;
+       iotcon_representation_h repr = NULL;
+       iotcon_state_h state = NULL;
+
+       if (IOTCON_ERROR_NONE != err)
+               return;
+
+       ret = iotcon_response_get_result(response, &response_result);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       if (IOTCON_RESPONSE_RESULT_OK != response_result)
+               return;
+
+       ret = iotcon_response_get_representation(response, &repr);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_representation_get_state(repr, &state);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_state_foreach(state, _state_foreach, NULL);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ...
+}
+
+static void _request_get(iotcon_remote_resource_h resource)
+{
+       int ret;
+       ret = iotcon_remote_resource_get(resource, NULL, _on_get, NULL);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+}
+ * @endcode
+ *
+ *
+ * Example (Server side) :
+ * @code
+#include <iotcon.h>
+
+static iotcon_state_h _create_state()
+{
+       int ret;
+       iotcon_state_h state = NULL;
+
+       // create & set state
+       ...
+
+       return state;
+}
+
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
+{
+       int ret;
+       int types;
+       iotcon_interface_e iface = IOTCON_INTERFACE_DEFAULT;
+       iotcon_query_h query = NULL;
+
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_request_get_query(request, &query);
+       if (IOTCON_ERROR_NONE == ret && query) {
+               ret = iotcon_query_get_interface(request, &iface);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+       }
+
+       if (IOTCON_REQUEST_GET & types) {
+               iotcon_response_h response = NULL;
+               iotcon_representation_h repr = NULL;
+               iotcon_state_h state = NULL;
+
+               ret = iotcon_response_create(request, &response);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
+               ret = iotcon_representation_create(&repr);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
+               ret = iotcon_representation_set_uri_path(repr, "/light/1");
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(repr);
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
+               ret = iotcon_representation_set_state(resopnse, _create_state());
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(repr);
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
+               ret = iotcon_response_set_representation(response, iface, repr);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(repr);
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
+               ret = iotcon_response_send(response);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(repr);
+                       iotcon_response_destroy(response);
+                       return;
+               }
+
+               iotcon_representation_destroy(repr);
+               iotcon_response_destroy(response);
+       }
+       ...
+}
+ * @endcode
+ *
  * @{
  */
 
index 795b92e..ea07fdc 100644 (file)
@@ -32,7 +32,7 @@
  *
  * @brief Iotcon Server provides API for server side.
  *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_SERVER_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
  * @section CAPI_IOT_CONNECTIVITY_SERVER_MODULE_OVERVIEW Overview
index 7e8fc2a..8e602eb 100644 (file)
  *
  * @brief Iotcon State provides API to manage state.
  *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_HEADER Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_HEADER Required Header
  *  \#include <iotcon.h>
  *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_OVERVIEW Overview
+ * The iotcon state API provides string key based hash table.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+...
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       int ret;
+       int types;
+
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       if (IOTCON_REQUEST_GET & types) {
+               iotcon_response_h response = NULL;
+               iotcon_representation_h representation = NULL;
+               iotcon_state_h state = NULL;
+
+               ret = iotcon_response_create(request, &response);
+               if (IOTCON_ERROR_NONE != ret)
+                       return;
+
+               ret = iotcon_representation_create(&representation);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ...
+
+               ret = iotcon_state_create(&state);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_state_set_bool(state, "power", true);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = itocon_state_set_int(state, "brightness", 75);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_representation_set_state(representation, state);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ...
+
+               ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT,
+                               representation);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               ret = iotcon_response_send(response);
+               if (IOTCON_ERROR_NONE != ret) {
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(representation);
+                       iotcon_response_destroy(resopnse);
+                       return;
+               }
+
+               iotcon_state_destroy(state);
+               iotcon_representation_destroy(representation);
+               iotcon_response_destroy(resopnse);
+       }
+       ...
+}
+ * @endcode
+ *
  * @{
  */
 
@@ -68,6 +160,27 @@ int iotcon_state_create(iotcon_state_h *state);
 void iotcon_state_destroy(iotcon_state_h state);
 
 /**
+ * @brief Clones a state handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must destroy @a state_clone by calling iotcon_state_destroy()
+ * if @a state_clone is no longer needed.
+ *
+ * @param[in] state The state handle
+ * @param[out] state_clone The cloned state handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @see iotcon_state_create()
+ * @see iotcon_state_destroy()
+ */
+int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone);
+
+/**
  * @brief Sets a new key and integer value into the representation.
  * @details If @a key is already exists, current value will be replaced with new @a val.
  *