* @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;
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;
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);
}
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) {
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;
}
// 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;
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);
}
...
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
*
* 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;
- }
}
}
...
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) {
}
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;
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;
}
* @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)
{
}
}
}
+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)
{
*
* @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
*
* @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
+ *
+ *
* @{
*/
*
* @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
*
* @{
*/
*
* @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
+ *
* @{
*/
*
* @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
* @{
*/
*
* @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
+ *
* @{
*/
*
* @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
+ *
* @{
*/
/**
* @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
*
* @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
* 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>
...
*
* @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
+ *
* @{
*/
*
* @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
+ *
* @{
*/
*
* @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
+ *
* @{
*/
*
* @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
+ *
* @{
*/
*
* @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
*
* @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
+ *
* @{
*/
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.
*