static int icd_ioty_alive;
-typedef int (*_ocprocess_fn)(void *user_data);
+typedef int (*_ocprocess_cb)(void *user_data);
struct icd_ioty_worker
{
void *ctx;
- _ocprocess_fn fn;
+ _ocprocess_cb cb;
};
return NULL;
}
- ret = worker->fn(worker->ctx);
+ ret = worker->cb(worker->ctx);
if (IOTCON_ERROR_NONE != ret)
- ERR("fn() Fail(%d)", ret);
+ ERR("cb() Fail(%d)", ret);
/* worker was allocated from _ocprocess_worker_start() */
free(worker);
}
-static int _ocprocess_worker_start(_ocprocess_fn fn, void *ctx)
+static int _ocprocess_worker_start(_ocprocess_cb cb, void *ctx)
{
GError *error;
GThread *thread;
struct icd_ioty_worker *worker;
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
worker = calloc(1, sizeof(struct icd_ioty_worker));
if (NULL == worker) {
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- worker->fn = fn;
+ worker->cb = cb;
worker->ctx = ctx;
/* TODO : consider thread pool mechanism */
ret = snprintf(sig_name, sizeof(sig_name), "%s_%u", signal, signum);
if (ret <= 0 || sizeof(sig_name) <= ret) {
ERR("snprintf() Fail(%d)", ret);
- return IOTCON_ERROR_UNKNOWN;
+ return IOTCON_ERROR_IO_ERROR;
}
ret = icd_dbus_emit_signal(dest, sig_name, value);
if (NULL == resp->payload)
/* normal case : payload COULD be NULL */
return OC_STACK_KEEP_TRANSACTION;
- RETV_IF(PAYLOAD_TYPE_DISCOVERY != resp->payload->type,
- OC_STACK_KEEP_TRANSACTION);
+ RETVM_IF(PAYLOAD_TYPE_DISCOVERY != resp->payload->type,
+ OC_STACK_KEEP_TRANSACTION, "Invalid payload type(%d)", resp->payload->type);
find_ctx = calloc(1, sizeof(struct icd_find_context));
if (NULL == find_ctx) {
}
-static int _ocprocess_worker(_ocprocess_fn fn, int type, OCPayload *payload, int res,
+static int _ocprocess_worker(_ocprocess_cb cb, int type, OCPayload *payload, int res,
GVariantBuilder *options, void *ctx)
{
int ret;
crud_ctx->options = options;
crud_ctx->invocation = ctx;
- ret = _ocprocess_worker_start(fn, crud_ctx);
+ ret = _ocprocess_worker_start(cb, crud_ctx);
if (IOTCON_ERROR_NONE != ret) {
ERR("_ocprocess_worker_start() Fail(%d)", ret);
if (crud_ctx->payload)
g_variant_iter_loop(&msg_iter, "(iv)", &error_code, &repr_gvar);
/* TODO : How to use error_code. */
- payload = icd_payload_repr_from_gvariant(repr_gvar);
+ payload = icd_payload_representation_from_gvariant(repr_gvar);
icd_ioty_csdk_lock();
/* TODO : QoS is come from lib. */
}
g_variant_iter_free(options);
- response.payload = (OCPayload*)icd_payload_repr_from_gvariant(repr_gvar);
+ response.payload = (OCPayload*)icd_payload_representation_from_gvariant(repr_gvar);
/* related to block transfer */
response.persistentBufferFlag = 0;
}
if (len <= 0 || sizeof(uri) <= len) {
ERR("snprintf() Fail(%d)", len);
- return IOTCON_ERROR_UNKNOWN;
+ return IOTCON_ERROR_IO_ERROR;
}
if (IC_STR_EQUAL != strcmp(IC_STR_NULL, resource_type))
g_variant_iter_free(options);
if (repr)
- payload = (OCPayload*)icd_payload_repr_from_gvariant(repr);
+ payload = (OCPayload*)icd_payload_representation_from_gvariant(repr);
oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
#include "icd.h"
#include "icd-payload.h"
-union icd_repr_value_u {
+union icd_state_value_u {
int i;
double d;
bool b;
};
-struct icd_repr_list_s {
+struct icd_state_list_s {
OCRepPayloadPropType type;
size_t dimensions[MAX_REP_ARRAY_DEPTH];
GList *list;
};
-static GVariant* _icd_payload_repr_to_gvariant(OCRepPayload *repr, gboolean is_parent);
+static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr, gboolean is_parent);
GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
{
}
-static GVariant* _icd_repr_array_attr_to_gvariant(OCRepPayloadValueArray *arr, int len,
+static GVariant* _icd_state_array_attr_to_gvariant(OCRepPayloadValueArray *arr, int len,
int index)
{
int i;
break;
case OCREP_PROP_OBJECT:
for (i = 0; i < len; i++) {
- var = _icd_payload_repr_to_gvariant(arr->objArray[index + i], TRUE);
+ var = _icd_payload_representation_to_gvariant(arr->objArray[index + i], TRUE);
g_variant_builder_add(&builder, "v", var);
}
break;
}
-static GVariant* _icd_repr_array_to_gvariant(OCRepPayloadValueArray *arr,
+static GVariant* _icd_state_array_to_gvariant(OCRepPayloadValueArray *arr,
int current_depth, int current_len, int index)
{
int i, next_len;
if ((MAX_REP_ARRAY_DEPTH - 1) == current_depth
|| 0 == arr->dimensions[current_depth + 1])
- return _icd_repr_array_attr_to_gvariant(arr, current_len, index);
+ return _icd_state_array_attr_to_gvariant(arr, current_len, index);
i = current_len + index;
g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
while ((index += next_len) < i) {
- arr_var = _icd_repr_array_to_gvariant(arr, current_depth + 1, next_len, index);
+ arr_var = _icd_state_array_to_gvariant(arr, current_depth + 1, next_len, index);
g_variant_builder_add(&builder, "v", arr_var);
}
}
-static GVariantBuilder* _icd_repr_value_to_gvariant(OCRepPayload *repr)
+static GVariantBuilder* _icd_state_value_to_gvariant(OCRepPayload *repr)
{
int total_len;
GVariant *var = NULL;
break;
case OCREP_PROP_ARRAY:
total_len = calcDimTotal(val->arr.dimensions);
- var = _icd_repr_array_to_gvariant(&(val->arr), 0, total_len, 0);
+ var = _icd_state_array_to_gvariant(&(val->arr), 0, total_len, 0);
break;
case OCREP_PROP_OBJECT:
- var = _icd_payload_repr_to_gvariant(val->obj, TRUE);
+ var = _icd_payload_representation_to_gvariant(val->obj, TRUE);
break;
default:
ERR("Invalid Type");
}
-static GVariant* _icd_payload_repr_to_gvariant(OCRepPayload *repr, gboolean is_parent)
+static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr, gboolean is_parent)
{
OCStringLL *node;
int ret, ifaces = 0;
}
/* Representation */
- repr_gvar = _icd_repr_value_to_gvariant(repr);
+ repr_gvar = _icd_state_value_to_gvariant(repr);
/* Children */
g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
child_node = repr->next;
while (is_parent && child_node) {
/* generate recursively */
- child = _icd_payload_repr_to_gvariant(child_node, FALSE);
+ child = _icd_payload_representation_to_gvariant(child_node, FALSE);
g_variant_builder_add(&children, "v", child);
child_node = child_node->next;
}
switch (repr->type) {
case PAYLOAD_TYPE_REPRESENTATION:
- value = _icd_payload_repr_to_gvariant((OCRepPayload*)repr, TRUE);
+ value = _icd_payload_representation_to_gvariant((OCRepPayload*)repr, TRUE);
break;
case PAYLOAD_TYPE_PLATFORM:
value = _icd_payload_platform_to_gvariant((OCPlatformPayload*)repr);
}
-static void _icd_repr_list_from_gvariant(GVariant *var,
- struct icd_repr_list_s *value_list, int depth)
+static void _icd_state_list_from_gvariant(GVariant *var,
+ struct icd_state_list_s *value_list, int depth)
{
GVariantIter iter;
const GVariantType *type;
- union icd_repr_value_u *value;
+ union icd_state_value_u *value;
type = g_variant_get_type(var);
bool b;
value_list->type = OCREP_PROP_BOOL;
while (g_variant_iter_loop(&iter, "b", &b)) {
- value = calloc(1, sizeof(union icd_repr_value_u));
+ value = calloc(1, sizeof(union icd_state_value_u));
if (NULL == value) {
ERR("calloc() Fail(%d)", errno);
return;
int i;
value_list->type = OCREP_PROP_INT;
while (g_variant_iter_loop(&iter, "i", &i)) {
- value = calloc(1, sizeof(union icd_repr_value_u));
+ value = calloc(1, sizeof(union icd_state_value_u));
if (NULL == value) {
ERR("calloc() Fail(%d)", errno);
return;
double d;
value_list->type = OCREP_PROP_DOUBLE;
while (g_variant_iter_loop(&iter, "d", &d)) {
- value = calloc(1, sizeof(union icd_repr_value_u));
+ value = calloc(1, sizeof(union icd_state_value_u));
if (NULL == value) {
ERR("calloc() Fail(%d)", errno);
return;
OCRepPayload *repr_value;
value_list->type = OCREP_PROP_OBJECT;
do {
- repr_value = icd_payload_repr_from_gvariant(value);
+ repr_value = icd_payload_representation_from_gvariant(value);
value_list->list = g_list_append(value_list->list, repr_value);
} while (g_variant_iter_loop(&iter, "v", &value));
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
do {
- _icd_repr_list_from_gvariant(value, value_list, depth + 1);
+ _icd_state_list_from_gvariant(value, value_list, depth + 1);
} while (g_variant_iter_loop(&iter, "v", &value));
}
}
}
-static void _icd_repr_list_free(gpointer node)
+static void _icd_state_list_free(gpointer node)
{
OCRepPayloadDestroy(node);
}
-static void _icd_repr_array_from_list(OCRepPayload *repr,
- struct icd_repr_list_s *value_list, const char *key)
+static void _icd_state_array_from_list(OCRepPayload *repr,
+ struct icd_state_list_s *value_list, const char *key)
{
int i, len;
GList *node;
double *d_arr;
char **str_arr;
int64_t *i_arr;
- union icd_repr_value_u *value;
- struct OCRepPayload **repr_arr;
+ union icd_state_value_u *value;
+ struct OCRepPayload **state_arr;
len = calcDimTotal(value_list->dimensions);
OCRepPayloadSetStringArrayAsOwner(repr, key, str_arr, value_list->dimensions);
break;
case OCREP_PROP_OBJECT:
- repr_arr = calloc(len, sizeof(struct OCRepPayload *));
- if (NULL == repr_arr) {
+ state_arr = calloc(len, sizeof(struct OCRepPayload *));
+ if (NULL == state_arr) {
ERR("calloc() Fail(%d)", errno);
return;
}
for (node = value_list->list, i = 0; node; node = node->next, i++)
- repr_arr[i] = OCRepPayloadClone(node->data);
- g_list_free_full(value_list->list, _icd_repr_list_free);
- OCRepPayloadSetPropObjectArrayAsOwner(repr, key, repr_arr,
+ state_arr[i] = OCRepPayloadClone(node->data);
+ g_list_free_full(value_list->list, _icd_state_list_free);
+ OCRepPayloadSetPropObjectArrayAsOwner(repr, key, state_arr,
value_list->dimensions);
break;
case OCREP_PROP_ARRAY:
}
-static void _icd_repr_value_from_gvariant(OCRepPayload *repr, GVariantIter *iter)
+static void _icd_state_value_from_gvariant(OCRepPayload *repr, GVariantIter *iter)
{
char *key;
GVariant *var;
const char *str_value;
OCRepPayload *repr_value;
- struct icd_repr_list_s value_list = {0};
+ struct icd_state_list_s value_list = {0};
while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
OCRepPayloadSetPropString(repr, key, str_value);
} else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
- memset(&value_list, 0, sizeof(struct icd_repr_list_s));
- _icd_repr_list_from_gvariant(var, &value_list, 0);
- _icd_repr_array_from_list(repr, &value_list, key);
+ memset(&value_list, 0, sizeof(struct icd_state_list_s));
+ _icd_state_list_from_gvariant(var, &value_list, 0);
+ _icd_state_array_from_list(repr, &value_list, key);
} else if (g_variant_is_of_type(var, G_VARIANT_TYPE("(siasa{sv}av)"))) {
- repr_value = icd_payload_repr_from_gvariant(var);
+ repr_value = icd_payload_representation_from_gvariant(var);
OCRepPayloadSetPropObjectAsOwner(repr, key, repr_value);
}
}
}
-OCRepPayload* icd_payload_repr_from_gvariant(GVariant *var)
+OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var)
{
GVariant *child;
int ret, i, ifaces = 0;
while (g_variant_iter_loop(resource_types, "s", &resource_type))
OCRepPayloadAddResourceType(repr, resource_type);
- _icd_repr_value_from_gvariant(repr, repr_gvar);
+ _icd_state_value_from_gvariant(repr, repr_gvar);
cur = repr;
while (g_variant_iter_loop(children, "v", &child)) {
- cur->next = icd_payload_repr_from_gvariant(child);
+ cur->next = icd_payload_representation_from_gvariant(child);
cur = cur->next;
}
GVariant* icd_payload_to_gvariant(OCPayload *payload);
GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr);
-OCRepPayload* icd_payload_repr_from_gvariant(GVariant *var);
+OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var);
#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__*/
int ret;
int types;
iotcon_response_h response;
- iotcon_repr_h resp_repr;
+ iotcon_representation_h resp_repr;
ret = iotcon_request_get_types(request, &types);
if (IOTCON_ERROR_NONE != ret)
return;
if (IOTCON_REQUEST_GET & types) {
- response = iotcon_response_new(request);
- if (NULL == response)
+ ret = iotcon_response_create(request, &response);
+ if (IOTCON_ERROR_NONE != ret)
return;
- resp_repr = iotcon_repr_new();
- if (NULL == resp_repr) {
- iotcon_response_free(response);
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_response_destroy(response);
return;
}
- ret = iotcon_repr_set_uri_path(resp_repr, "core.door");
+ ret = iotcon_representation_set_uri_path(resp_repr, "core.door");
if (IOTCON_ERROR_NONE != ret) {
- iotcon_repr_free(resp_repr);
- iotcon_response_free(response);
+ iotcon_representation_destroy(resp_repr);
+ iotcon_response_destroy(response);
return;
}
- ret = iotcon_repr_set_bool(resp_repr, "opened", true);
+ ret = iotcon_state_set_bool(resp_repr, "opened", true);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_repr_free(resp_repr);
- iotcon_response_free(response);
+ iotcon_representation_destroy(resp_repr);
+ iotcon_response_destroy(response);
return;
}
- ret = iotcon_response_set(response, IOTCON_RESPONSE_RESULT, IOTCON_RESPONSE_RESULT_OK);
+ ret = iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_repr_free(resp_repr);
- iotcon_response_free(response);
+ iotcon_representation_destroy(resp_repr);
+ iotcon_response_destroy(response);
return;
}
- ret = iotcon_response_set(response, IOTCON_RESPONSE_REPRESENTATION, resp_repr);
+
+ ret = iotcon_response_set_representation(response, resp_repr);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_repr_free(resp_repr);
- iotcon_response_free(response);
+ iotcon_representation_destroy(resp_repr);
+ iotcon_response_destroy(response);
return;
}
ret = iotcon_response_send(response);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_repr_free(resp_repr);
- iotcon_response_free(response);
+ iotcon_representation_destroy(resp_repr);
+ iotcon_response_destroy(response);
return;
}
- iotcon_repr_free(resp_repr);
- iotcon_response_free(response);
+ iotcon_representation_destroy(resp_repr);
+ iotcon_response_destroy(response);
}
}
...
int properties = (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE);
const char *uri_path = "/a/door1";
const char *type = "core.door";
+ iotcon_resource_types_h resource_types;
- iotcon_resource_types_h resource_types = iotcon_resource_types_new();
- if (NULL == resource_types) {
+ ret = iotcon_resource_types_create(&resource_types);
+ if (IOTCON_ERROR_NONE != ret) {
return;
}
ret = iotcon_resource_types_insert(resource_types, type);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
return;
}
iotcon_resource_h handle = iotcon_register_resource(uri_path, resource_types,
interfaces, properties, _request_handler, NULL);
if (NULL == handle) {
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
return;
}
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
}
* @endcode
*
* Example :
* @code
#include <iotcon.h>
-static void _on_get(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+static void _on_get(iotcon_options_h header_options, iotcon_representation_h recv_repr,
int response_result, void *user_data)
{
// handle get from response
return;
}
- query = iotcon_query_new();
+ ret = iotcon_query_create(&query);
+ if (IOTCON_ERROR_NONE != ret) {
+ return;
+ }
+
iotcon_query_insert(query, "key", "value");
iotcon_get(resource, query, &_on_get, NULL);
- iotcon_query_free(query);
+ iotcon_query_destroy(query);
}
...
{
if (IOTCON_ERROR_NONE != ret) {
return;
}
- observers = iotcon_observers_append(observers, observer_id);
+ ret = iotcon_observers_append(observers, observer_id, &observers);
+ if (IOTCON_ERROR_NONE != ret) {
+ return;
+ }
} else if (IOTCON_OBSERVE_DEREGISTER == observer_action) {
ret = iotcon_request_get_observer_id(request, &observer_id);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- observers = iotcon_observers_remove(observers, observer_id);
+ ret = iotcon_observers_remove(observers, observer_id, &observers);
+ 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 = "/a/door1";
const char *type = "core.door";
+ iotcon_resource_types_h resource_types;
- iotcon_resource_types_h resource_types = iotcon_resource_types_new();
- if (NULL == resource_types) {
+ ret = iotcon_resource_types_create(&resource_types);
+ if (IOTCON_ERROR_NONE == ret) {
return;
}
ret = iotcon_resource_types_insert(resource_types, type);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
return;
}
- iotcon_resource_h door_handle = iotcon_register_resource(uri_path, resource_types,
- interfaces, properties, _request_handler, NULL);
- if (NULL == door_handle) {
- iotcon_resource_types_free(resource_types);
+ ret = iotcon_register_resource(uri_path, resource_types,
+ interfaces, properties, _request_handler, NULL, door_handle);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_types_destroy(resource_types);
return;
}
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
}
...
{
- iotcon_repr_h repr = iotcon_repr_new();
- iotcon_notimsg_h msg = iotcon_notimsg_new(repr, IOTCON_INTERFACE_DEFAULT);
+ int ret;
+ iotcon_representation_h repr;
+ iotcon_notimsg_h msg;
+
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ return;
+ }
+
+ ret = iotcon_notimsg_create(resp_repr, IOTCON_INTERFACE_DEFAULT, &msg);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
ret = iotcon_notify_list_of_observers(door_handle, msg, observers);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_notimsg_free(msg);
- iotcon_repr_free(repr);
+ iotcon_notimsg_destroy(msg);
+ iotcon_representation_destroy(resp_repr);
return;
}
- iotcon_notimsg_free(msg);
- iotcon_repr_free(repr);
+ iotcon_notimsg_destroy(msg);
+ iotcon_representation_destroy(resp_repr);
}
* @endcode
*
...
static iotcon_client_h door_resource;
...
-static void _on_observe(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+static void _on_observe(iotcon_options_h header_options, iotcon_representation_h recv_repr,
int response_result, int sequence_number, void *user_data)
{
}
* <td>iotcon_subscribe_presence</td>
* </tr>
* <tr>
- * <td>iotcon_bind_interface</td>
+ * <td>iotcon_resource_bind_interface</td>
* <td>iotcon_unsubscribe_presence</td>
* </tr>
* <tr>
- * <td>iotcon_bind_type</td>
+ * <td>iotcon_resource_bind_type</td>
* <td>iotcon_find_resource</td>
* </tr>
* <tr>
- * <td>iotcon_bind_request_handler</td>
+ * <td>iotcon_resource_bind_request_handler</td>
* <td>iotcon_observer_start</td>
* </tr>
* <tr>
- * <td>iotcon_bind_resource</td>
+ * <td>iotcon_resource_bind_child_resource</td>
* <td>iotcon_observer_stop</td>
* </tr>
* <tr>
- * <td>iotcon_unbind_resource</td>
+ * <td>iotcon_resource_unbind_child_resource</td>
* <td>iotcon_get</td>
* </tr>
* <tr>
* <td></td>
* </tr>
* <tr>
- * <td>iotcon_notify_all</td>
+ * <td>iotcon_resource_notify_all</td>
* <td></td>
* </tr>
* <tr>
* @defgroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE Iotcon Representation
*
* @section CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE_HEADER Required Header
- * \#include <iotcon-representation.h>
+ * \#include <iotcon-resp_repr.h>
*
* @section CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE_OVERVIEW Overview
- * The Iotcon Representation API provides data type of representation handling.\n
- * A representation is a payload of a request or a response.\n
+ * The Iotcon Representation API provides data type of resp_repr handling.\n
+ * A resp_repr is a payload of a request or a response.\n
* It has uri_path, interface, list of resource types and its attributes.\n
* Attributes have capabilties to store and retrieve integer, boolean, double, string, list, null,
- * representation.\n
+ * 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, representation.
+ * It has capabilties to store and retrieve integer, boolean, double, string, list, null, resp_repr.
*
*@code
#include <iotcon.h>
...
{
int ret;
- iotcon_repr_h repr;
+ iotcon_representation_h repr;
iotcon_resource_types_h types;
iotcon_list_h bright_step_list;
- repr = iotcon_repr_new();
- if (NULL == repr)
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
return;
+ }
- ret = iotcon_repr_set_uri_path(repr, "/a/light");
+ ret = iotcon_representation_set_uri_path(resp_repr, "/a/light");
if (IOTCON_ERROR_NONE != ret) {
- iotcon_repr_free(repr);
+ iotcon_representation_destroy(resp_repr);
return;
}
- types = iotcon_resource_types_new();
- if (NULL == types) {
- iotcon_repr_free(repr);
+ ret = iotcon_resource_types_create(&types);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_representation_destroy(resp_repr);
return;
}
ret = iotcon_resource_types_insert(types, "core.light");
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_resource_types(repr, types);
+ ret = iotcon_representation_set_resource_types(resp_repr, types);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_resource_interfaces(repr, IOTCON_INTERFACE_LINK);
+ ret = iotcon_representation_set_resource_interfaces(resp_repr, IOTCON_INTERFACE_LINK);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_str(repr, "type", "lamp");
+ ret = iotcon_state_set_str(resp_repr, "type", "lamp");
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_str(repr, "where", "desk");
+ ret = iotcon_state_set_str(resp_repr, "where", "desk");
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_double(repr, "default_bright", 200.0);
+ ret = iotcon_state_set_double(resp_repr, "default_bright", 200.0);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_str(repr, "unit", "lux");
+ ret = iotcon_state_set_str(resp_repr, "unit", "lux");
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_bool(repr, "bright_step", true);
+ ret = iotcon_state_set_bool(resp_repr, "bright_step", true);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- bright_step_list = iotcon_list_new(IOTCON_TYPE_DOUBLE);
- if (NULL == bright_step_list) {
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ ret = iotcon_list_create(IOTCON_TYPE_DOUBLE, &bright_step_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
ret = iotcon_list_insert_double(bright_step_list, 100.0, -1);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
ret = iotcon_list_insert_double(bright_step_list, 200.0, -1);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
ret = iotcon_list_insert_double(bright_step_list, 300.0, -1);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
ret = iotcon_list_insert_double(bright_step_list, 400.0, -1);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
ret = iotcon_list_insert_double(bright_step_list, 500.0, -1);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_repr_set_list(repr, "bright_step_list", bright_step_list);
+ ret = iotcon_state_set_list(resp_repr, "bright_step_list", bright_step_list);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
return;
}
- iotcon_list_free(bright_step_list);
- iotcon_resource_types_free(types);
- iotcon_repr_free(repr);
+ iotcon_list_destroy(bright_step_list);
+ iotcon_resource_types_destroy(types);
+ iotcon_representation_destroy(resp_repr);
}
* @endcode
*/
static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
{
- int res;
- iotcon_repr_h repr;
+ int res, ret;
+ iotcon_representation_h repr;
GVariantIter *options;
unsigned short option_id;
char *option_data;
g_variant_get(result, "(a(qs)vi)", &options, &repr_gvar, &res);
if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
- header_options = iotcon_options_new();
+ ret = iotcon_options_create(&header_options);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_create() Fail(%d)", ret);
+ return;
+ }
+
while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
iotcon_options_insert(header_options, option_id, option_data);
}
g_variant_iter_free(options);
- repr = icl_repr_from_gvariant(repr_gvar);
+ repr = icl_representation_from_gvariant(repr_gvar);
if (NULL == repr) {
- ERR("icl_repr_from_gvariant() Fail");
+ ERR("icl_representation_from_gvariant() Fail");
if (header_options)
- iotcon_options_free(header_options);
+ iotcon_options_destroy(header_options);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return;
}
res = icl_dbus_convert_daemon_error(res);
if (cb)
- cb(cb_container->resource, repr, header_options, res, cb_container->user_data);
+ cb(cb_container->resource, repr, header_options, res,
+ cb_container->user_data);
if (repr)
- iotcon_repr_free(repr);
+ iotcon_representation_destroy(repr);
if (header_options)
- iotcon_options_free(header_options);
+ iotcon_options_destroy(header_options);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
}
if (error) {
ERR("ic_dbus_call_get_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return;
}
if (error) {
ERR("ic_dbus_call_put_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return;
}
if (error) {
ERR("ic_dbus_call_post_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return;
}
}
-API int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
- iotcon_on_cru_cb cb, void *user_data)
+API int iotcon_get(iotcon_client_h resource, iotcon_query_h query, iotcon_on_cru_cb cb,
+ void *user_data)
{
- GVariant *arg_client;
+ int ret;
GVariant *arg_query;
+ GVariant *arg_client;
icl_on_cru_s *cb_container;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- cb_container->resource = iotcon_client_ref(resource);
- if (NULL == cb_container->resource) {
+ ret = iotcon_client_ref(resource, &cb_container->resource);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_ref() Fail");
free(cb_container);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
-API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
+API int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr,
iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
{
+ int ret;
GVariant *arg_repr;
GVariant *arg_client;
GVariant *arg_query;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- cb_container->resource = iotcon_client_ref(resource);
- if (NULL == cb_container->resource) {
+ ret = iotcon_client_ref(resource, &cb_container->resource);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_ref() Fail");
free(cb_container);
return IOTCON_ERROR_OUT_OF_MEMORY;
cb_container->cb = cb;
cb_container->user_data = user_data;
- arg_repr = icl_repr_to_gvariant(repr);
+ arg_repr = icl_representation_to_gvariant(repr);
if (NULL == arg_repr) {
- ERR("icl_repr_to_gvariant() Fail");
- iotcon_client_free(cb_container->resource);
+ ERR("icl_representation_to_gvariant() Fail");
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return IOTCON_ERROR_REPRESENTATION;
}
arg_client = icl_dbus_client_to_gvariant(resource);
arg_query = icl_dbus_query_to_gvariant(query);
- ic_dbus_call_put(icl_dbus_get_object(), arg_client, arg_repr, arg_query, NULL,
- _icl_on_put_cb, cb_container);
+ ic_dbus_call_put(icl_dbus_get_object(), arg_client, arg_repr, arg_query,
+ NULL, _icl_on_put_cb, cb_container);
return IOTCON_ERROR_NONE;
}
-API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
+API int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr,
iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
{
+ int ret;
GVariant *arg_repr;
- GVariant *arg_client;
GVariant *arg_query;
+ GVariant *arg_client;
icl_on_cru_s *cb_container;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- cb_container->resource = iotcon_client_ref(resource);
- if (NULL == cb_container->resource) {
+ ret = iotcon_client_ref(resource, &cb_container->resource);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_ref() Fail");
free(cb_container);
return IOTCON_ERROR_OUT_OF_MEMORY;
cb_container->cb = cb;
cb_container->user_data = user_data;
- arg_repr = icl_repr_to_gvariant(repr);
+ arg_repr = icl_representation_to_gvariant(repr);
if (NULL == arg_repr) {
- ERR("icl_repr_to_gvariant() Fail");
- iotcon_client_free(cb_container->resource);
+ ERR("icl_representation_to_gvariant() Fail");
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return IOTCON_ERROR_REPRESENTATION;
}
arg_client = icl_dbus_client_to_gvariant(resource);
arg_query = icl_dbus_query_to_gvariant(query);
- ic_dbus_call_post(icl_dbus_get_object(), arg_client, arg_repr, arg_query, NULL,
- _icl_on_post_cb, cb_container);
+ ic_dbus_call_post(icl_dbus_get_object(), arg_client, arg_repr, arg_query,
+ NULL, _icl_on_post_cb, cb_container);
return IOTCON_ERROR_NONE;
}
static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
gpointer user_data)
{
- int res;
+ int res, ret;
GVariant *result;
char *option_data;
GError *error = NULL;
if (error) {
ERR("ic_dbus_call_delete_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return;
}
g_variant_get(result, "(a(qs)i)", &options, &res);
if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
- header_options = iotcon_options_new();
+ ret = iotcon_options_create(&header_options);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_create() Fail(%d)", ret);
+ g_variant_iter_free(options);
+ iotcon_client_destroy(cb_container->resource);
+ free(cb_container);
+ return;
+ }
+
while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
iotcon_options_insert(header_options, option_id, option_data);
}
cb(cb_container->resource, header_options, res, cb_container->user_data);
if (header_options)
- iotcon_options_free(header_options);
+ iotcon_options_destroy(header_options);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
}
API int iotcon_delete(iotcon_client_h resource, iotcon_on_delete_cb cb, void *user_data)
{
+ int ret;
GVariant *arg_client;
icl_on_delete_s *cb_container;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- cb_container->resource = iotcon_client_ref(resource);
- if (NULL == cb_container->resource) {
+ ret = iotcon_client_ref(resource, &cb_container->resource);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_ref() Fail");
free(cb_container);
return IOTCON_ERROR_OUT_OF_MEMORY;
GVariant *parameters,
gpointer user_data)
{
- int res;
+ int res, ret;
int seq_num;
- iotcon_repr_h repr;
+ iotcon_representation_h repr;
GVariantIter *options;
unsigned short option_id;
char *option_data;
icl_on_observe_s *cb_container = user_data;
iotcon_on_observe_cb cb = cb_container->cb;
- g_variant_get(parameters, "(a(qs)vii)", &options, &repr_gvar, &res, &seq_num);
+ g_variant_get(parameters, "(a(qs)vii)", &options, &repr_gvar, &res,
+ &seq_num);
if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
- header_options = iotcon_options_new();
+ ret = iotcon_options_create(&header_options);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_create() Fail(%d)", ret);
+ g_variant_iter_free(options);
+ iotcon_client_destroy(cb_container->resource);
+ free(cb_container);
+ return;
+ }
+
while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
iotcon_options_insert(header_options, option_id, option_data);
}
g_variant_iter_free(options);
- repr = icl_repr_from_gvariant(repr_gvar);
+ repr = icl_representation_from_gvariant(repr_gvar);
if (NULL == repr) {
- ERR("icl_repr_from_gvariant() Fail");
+ ERR("icl_representation_from_gvariant() Fail");
if (header_options)
- iotcon_options_free(header_options);
+ iotcon_options_destroy(header_options);
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
return;
}
cb_container->user_data);
if (repr)
- iotcon_repr_free(repr);
+ iotcon_representation_destroy(repr);
if (header_options)
- iotcon_options_free(header_options);
+ iotcon_options_destroy(header_options);
}
{
cb_container->resource->observe_handle = 0;
cb_container->resource->observe_sub_id = 0;
- iotcon_client_free(cb_container->resource);
+ iotcon_client_destroy(cb_container->resource);
free(cb_container);
}
-API int iotcon_observer_start(iotcon_client_h resource,
- iotcon_observe_type_e observe_type,
- iotcon_query_h query,
- iotcon_on_observe_cb cb,
- void *user_data)
+API int iotcon_observer_start(iotcon_client_h resource, int observe_type,
+ iotcon_query_h query, iotcon_on_observe_cb cb, void *user_data)
{
- int64_t observe_handle;
- GError *error = NULL;
+ GVariant *arg_query;
unsigned int sub_id;
- int signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
- icl_on_observe_s *cb_container;
GVariant *arg_client;
- GVariant *arg_query;
+ GError *error = NULL;
+ icl_on_observe_s *cb_container;
+ int ret, signal_number;
+ int64_t observe_handle;
+ char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- cb_container->resource = iotcon_client_ref(resource);
- if (NULL == cb_container->resource) {
+ ret = iotcon_client_ref(resource, &cb_container->resource);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_ref() Fail");
free(cb_container);
return IOTCON_ERROR_OUT_OF_MEMORY;
#include "ic-utils.h"
#include "icl.h"
#include "icl-options.h"
-#include "icl-resource-types.h"
#include "icl-dbus.h"
#include "icl-repr.h"
#include "icl-client.h"
+#include "icl-resource-types.h"
#include "icl-payload.h"
typedef struct {
if (cb)
cb(client, cb_container->user_data);
- iotcon_client_free(client);
+ iotcon_client_destroy(client);
/* TODO
* When is callback removed?
{
int ret;
int signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
unsigned int sub_id;
- icl_found_resource_s *cb_container;
GError *error = NULL;
+ icl_found_resource_s *cb_container;
+ char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- if (resource_type && (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
+ if (resource_type && (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
ERR("The length of resource_type(%s) is invalid", resource_type);
return IOTCON_ERROR_INVALID_PARAMETER;
}
/* If you know the information of resource, then you can make a proxy of the resource. */
-API iotcon_client_h iotcon_client_new(const char *host, const char *uri_path,
- bool is_observable, iotcon_resource_types_h resource_types, int resource_ifs)
+API int iotcon_client_create(const char *host,
+ const char *uri_path,
+ bool is_observable,
+ iotcon_resource_types_h resource_types,
+ int resource_ifs,
+ iotcon_client_h *client_handle)
{
FN_CALL;
iotcon_client_h resource = NULL;
- RETV_IF(NULL == host, NULL);
- RETV_IF(NULL == uri_path, NULL);
- RETV_IF(NULL == resource_types, NULL);
+ RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
resource = calloc(1, sizeof(struct icl_remote_resource));
if (NULL == resource) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
resource->host = ic_utils_strdup(host);
resource->ref_count = 1;
- return resource;
+ *client_handle = resource;
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_client_free(iotcon_client_h resource)
+API void iotcon_client_destroy(iotcon_client_h resource)
{
RET_IF(NULL == resource);
free(resource->uri_path);
free(resource->host);
free(resource->sid);
- iotcon_resource_types_free(resource->types);
+ iotcon_resource_types_destroy(resource->types);
/* null COULD be allowed */
if (resource->header_options)
- iotcon_options_free(resource->header_options);
+ iotcon_options_destroy(resource->header_options);
free(resource);
}
-API iotcon_client_h iotcon_client_ref(iotcon_client_h resource)
+API int iotcon_client_ref(iotcon_client_h src, iotcon_client_h *dest)
{
- RETV_IF(NULL == resource, NULL);
- RETV_IF(resource->ref_count <= 0, NULL);
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(src->ref_count <= 0, IOTCON_ERROR_INVALID_PARAMETER);
+
+ src->ref_count++;
- resource->ref_count++;
+ *dest = src;
- return resource;
+ return IOTCON_ERROR_NONE;
}
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
if (resource->header_options)
- iotcon_options_free(resource->header_options);
+ iotcon_options_destroy(resource->header_options);
if (header_options)
resource->header_options = icl_options_ref(header_options);
static iotcon_client_h _icl_client_from_gvariant(GVariant *payload,
iotcon_connectivity_type_e conn_type)
{
+ int ret;
+ iotcon_client_h client;
+ GVariantIter *types_iter;
char host_addr[PATH_MAX] = {0};
+ iotcon_resource_types_h res_types;
char *uri_path, *sid, *res_type, *addr;
int ifaces, is_observable, is_secure, port;
- GVariantIter *types_iter;
- iotcon_resource_types_h res_types;
- iotcon_client_h client;
g_variant_get(payload, "(&s&siasib&si)", &uri_path, &sid, &ifaces, &types_iter,
&is_observable, &is_secure, &addr, &port);
snprintf(host_addr, sizeof(host_addr), "%s:%d", addr, port);
}
- res_types = iotcon_resource_types_new();
+ ret = iotcon_resource_types_create(&res_types);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ return NULL;
+ }
+
while (g_variant_iter_loop(types_iter, "s", &res_type))
iotcon_resource_types_insert(res_types, res_type);
- client = iotcon_client_new(host_addr, uri_path, !!is_observable, res_types, ifaces);
+ ret = iotcon_client_create(host_addr, uri_path, !!is_observable, res_types, ifaces,
+ &client);
if (res_types)
- iotcon_resource_types_free(res_types);
+ iotcon_resource_types_destroy(res_types);
- if (NULL == client) {
- ERR("iotcon_client_new() Fail");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_client_create() Fail");
return NULL;
}
client->ref_count = 1;
client->sid = strdup(sid);
if (NULL == client->sid) {
ERR("strdup(sid) Fail(%d)", errno);
- iotcon_client_free(client);
+ iotcon_client_destroy(client);
return NULL;
}
client->conn_type = conn_type;
#include "icl-response.h"
#include "icl-client.h"
#include "icl-repr.h"
-#include "icl-dbus-type.h"
#include "icl-payload.h"
+#include "icl-dbus-type.h"
const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
{
g_variant_builder_init(&builder, G_VARIANT_TYPE("a(iv)"));
if (msg) {
- repr_gvar = icl_repr_to_gvariant(msg->repr);
+ repr_gvar = icl_representation_to_gvariant(msg->repr);
if (NULL == repr_gvar) {
- ERR("icl_repr_to_gvariant() Fail");
+ ERR("icl_representation_to_gvariant() Fail");
g_variant_builder_clear(&builder);
return NULL;
}
}
}
- repr_gvar = icl_repr_to_gvariant(response->repr);
+ repr_gvar = icl_representation_to_gvariant(response->repr);
if (NULL == repr_gvar) {
- ERR("icl_repr_to_gvariant() Fail");
+ ERR("icl_representation_to_gvariant() Fail");
g_variant_builder_clear(&options);
return NULL;
}
}
-static icl_cb_container_s* _icl_dbus_find_connection_changed_cb(
- iotcon_connection_changed_cb cb, void *user_data)
+static icl_cb_container_s* _dbus_find_conn_changed_cb(iotcon_connection_changed_cb cb,
+ void *user_data)
{
GList *node;
icl_cb_container_s *cb_container;
- if (_icl_dbus_find_connection_changed_cb(cb, user_data)) {
+ if (_dbus_find_conn_changed_cb(cb, user_data)) {
ERR("This callback is already registered.");
return IOTCON_ERROR_ALREADY;
}
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- cb_container = _icl_dbus_find_connection_changed_cb(cb, user_data);
+ cb_container = _dbus_find_conn_changed_cb(cb, user_data);
if (NULL == cb_container) {
ERR("This callback is not registered");
return IOTCON_ERROR_INVALID_PARAMETER;
*
* @since_tizen 3.0
*/
-#define IOTCON_MANUFACTURER_NAME_LENGTH_MAX 15
+#define ICL_MANUFACTURER_NAME_LENGTH_MAX 15
/**
* @brief The maximum length which can be held in a manufacturer url.
*
* @since_tizen 3.0
*/
-#define IOTCON_MANUFACTURER_URL_LENGTH_MAX 32
+#define ICL_MANUFACTURER_URL_LENGTH_MAX 32
typedef struct {
/* The length of manufacturer_name should be less than and equal to 16.
* The length of manufacturer_url should be less than and equal to 32. */
-API int iotcon_register_platform_info(iotcon_platform_info_s platform_info)
+API int iotcon_register_platform_info(iotcon_platform_info_s *platform_info)
{
int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- if (NULL == platform_info.platform_id
- || NULL == platform_info.manuf_name
- || NULL == platform_info.manuf_url
- || NULL == platform_info.model_number
- || NULL == platform_info.date_of_manufacture
- || NULL == platform_info.platform_ver
- || NULL == platform_info.os_ver
- || NULL == platform_info.hardware_ver
- || NULL == platform_info.firmware_ver
- || NULL == platform_info.support_url
- || NULL == platform_info.system_time) {
+ if (NULL == platform_info->platform_id
+ || NULL == platform_info->manuf_name
+ || NULL == platform_info->manuf_url
+ || NULL == platform_info->model_number
+ || NULL == platform_info->date_of_manufacture
+ || NULL == platform_info->platform_ver
+ || NULL == platform_info->os_ver
+ || NULL == platform_info->hardware_ver
+ || NULL == platform_info->firmware_ver
+ || NULL == platform_info->support_url
+ || NULL == platform_info->system_time) {
ERR("one of parameter is NULL");
return IOTCON_ERROR_INVALID_PARAMETER;
}
- if (platform_info.manuf_name
- && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info.manuf_name))) {
- ERR("The length of manufacturer_name(%s) is invalid.", platform_info.manuf_name);
+ if (platform_info->manuf_name
+ && (ICL_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info->manuf_name))) {
+ ERR("The length of manufacturer_name(%s) is invalid.", platform_info->manuf_name);
return IOTCON_ERROR_INVALID_PARAMETER;
}
- if (platform_info.manuf_url
- && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info.manuf_url))) {
- ERR("The length of manufacturer_url(%s) is invalid.", platform_info.manuf_url);
+ if (platform_info->manuf_url
+ && (ICL_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info->manuf_url))) {
+ ERR("The length of manufacturer_url(%s) is invalid.", platform_info->manuf_url);
return IOTCON_ERROR_INVALID_PARAMETER;
}
- arg_info = icl_dbus_platform_info_to_gvariant(&platform_info);
+ arg_info = icl_dbus_platform_info_to_gvariant(platform_info);
ic_dbus_call_register_platform_info_sync(icl_dbus_get_object(), arg_info, &ret,
NULL, &error);
if (error) {
gpointer user_data)
{
char *uri_path;
- iotcon_platform_info_s info = {0};
+ iotcon_platform_info_s *info = calloc(1, sizeof(iotcon_platform_info_s));
icl_platform_info_s *cb_container = user_data;
iotcon_platform_info_cb cb = cb_container->cb;
g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
&uri_path,
- &info.platform_id,
- &info.manuf_name,
- &info.manuf_url,
- &info.model_number,
- &info.date_of_manufacture,
- &info.platform_ver,
- &info.os_ver,
- &info.hardware_ver,
- &info.firmware_ver,
- &info.support_url,
- &info.system_time);
+ &info->platform_id,
+ &info->manuf_name,
+ &info->manuf_url,
+ &info->model_number,
+ &info->date_of_manufacture,
+ &info->platform_ver,
+ &info->os_ver,
+ &info->hardware_ver,
+ &info->firmware_ver,
+ &info->support_url,
+ &info->system_time);
/* From iotivity, we can get uri_path. But, the value is always "/oic/p". */
return ret;
}
+
#include "iotcon-struct.h"
#include "icl.h"
-API void iotcon_observers_free(iotcon_observers_h observers)
+API void iotcon_observers_destroy(iotcon_observers_h observers)
{
RET_IF(NULL == observers);
/* If you want to make a new list, then you should set observers is NULL. */
-API iotcon_observers_h iotcon_observers_append(iotcon_observers_h observers,
- int obs_id)
+API int iotcon_observers_append(iotcon_observers_h observers, int obs_id,
+ iotcon_observers_h *ret_observers)
{
- return g_list_append(observers, GUINT_TO_POINTER(obs_id));
+ *ret_observers = g_list_append(observers, GUINT_TO_POINTER(obs_id));
+
+ return IOTCON_ERROR_NONE;
}
-API iotcon_observers_h iotcon_observers_remove(iotcon_observers_h observers,
- int obs_id)
+API int iotcon_observers_remove(iotcon_observers_h observers, int obs_id,
+ iotcon_observers_h *ret_observers)
{
- RETV_IF(NULL == observers, observers);
+ *ret_observers = g_list_remove(observers, GUINT_TO_POINTER(obs_id));
- return g_list_remove(observers, GUINT_TO_POINTER(obs_id));
+ return IOTCON_ERROR_NONE;
}
*
* @since_tizen 3.0
*/
-#define IOTCON_OPTIONID_MIN 2048
+#define ICL_OPTIONID_MIN 2048
/**
* @brief The maximum value of option id which can be held in a resource.
*
* @since_tizen 3.0
*/
-#define IOTCON_OPTIONID_MAX 3000
+#define ICL_OPTIONID_MAX 3000
/**
* @brief The maximum number of option which can be held in a resource.
*
* @since_tizen 3.0
*/
-#define IOTCON_OPTIONS_MAX 2
+#define ICL_OPTIONS_MAX 2
/**
* @brief The maximum length of option data which can be held in a resource.
*
* @since_tizen 3.0
*/
-#define IOTCON_OPTION_DATA_LENGTH_MAX 16
+#define ICL_OPTION_DATA_LENGTH_MAX 16
iotcon_options_h icl_options_ref(iotcon_options_h options)
}
-API iotcon_options_h iotcon_options_new()
+API int iotcon_options_create(iotcon_options_h *ret_options)
{
iotcon_options_h options = calloc(1, sizeof(struct icl_options));
if (NULL == options) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
options->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free);
options->ref_count = 1;
- return options;
+ *ret_options = options;
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_options_free(iotcon_options_h options)
+API void iotcon_options_destroy(iotcon_options_h options)
{
RET_IF(NULL == options);
RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(1 < options->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
"Don't modify it. It is already set.");
- RETVM_IF(IOTCON_OPTIONS_MAX <= g_hash_table_size(options->hash),
+ RETVM_IF(ICL_OPTIONS_MAX <= g_hash_table_size(options->hash),
IOTCON_ERROR_OUT_OF_MEMORY, "Options already have maximum elements.");
- RETVM_IF(((id < IOTCON_OPTIONID_MIN) || (IOTCON_OPTIONID_MAX < id)),
+ RETVM_IF(((id < ICL_OPTIONID_MIN) || (ICL_OPTIONID_MAX < id)),
IOTCON_ERROR_INVALID_PARAMETER, "Invalid id(%d)", id);
RETV_IF(NULL == data, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_OPTION_DATA_LENGTH_MAX < strlen(data), IOTCON_ERROR_INVALID_PARAMETER,
+ RETVM_IF(ICL_OPTION_DATA_LENGTH_MAX < strlen(data), IOTCON_ERROR_INVALID_PARAMETER,
"The length of option data(%s) is invalid.", data);
g_hash_table_insert(options->hash, GUINT_TO_POINTER(id), ic_utils_strdup(data));
}
-API const char* iotcon_options_lookup(iotcon_options_h options, unsigned short id)
+API int iotcon_options_lookup(iotcon_options_h options, unsigned short id,
+ const char **data)
{
const char *ret;
- RETV_IF(NULL == options, NULL);
+ RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
ret = g_hash_table_lookup(options->hash, GUINT_TO_POINTER(id));
if (NULL == ret)
ERR("g_hash_table_lookup() Fail");
- return ret;
+ *data = ret;
+
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_options_foreach(iotcon_options_h options,
- iotcon_options_foreach_fn fn, void *user_data)
+API int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
+ void *user_data)
{
GHashTableIter iter;
gpointer key, value;
RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
g_hash_table_iter_init(&iter, options->hash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (false == fn(GPOINTER_TO_UINT(key), value, user_data))
+ if (false == cb(GPOINTER_TO_UINT(key), value, user_data))
break;
}
#include "icl-response.h"
#include "icl-payload.h"
-static GVariantBuilder* _icl_repr_value_to_gvariant(GHashTable *hash);
+static GVariant* _icl_state_value_to_gvariant(GHashTable *hash);
+static iotcon_list_h _icl_state_list_from_gvariant(GVariant *var);
-static GVariant* _icl_repr_list_to_gvariant(iotcon_list_h list)
+static GVariant* _icl_state_list_to_gvariant(iotcon_list_h list)
{
GList *node;
GVariant *var = NULL;
GVariantBuilder builder;
- struct icl_value_s *repr_value = NULL;
+ iotcon_state_h state;
+ struct icl_value_s *state_value = NULL;
RETV_IF(NULL == list, NULL);
switch (list->type) {
case IOTCON_TYPE_INT:
for (node = list->list; node; node = node->next) {
- repr_value = node->data;
- g_variant_builder_add(&builder, "i", ((icl_basic_s*)repr_value)->val.i);
+ state_value = node->data;
+ g_variant_builder_add(&builder, "i", ((icl_basic_s*)state_value)->val.i);
}
break;
case IOTCON_TYPE_BOOL:
for (node = list->list; node; node = node->next) {
- repr_value = node->data;
- g_variant_builder_add(&builder, "b", ((icl_basic_s*)repr_value)->val.b);
+ state_value = node->data;
+ g_variant_builder_add(&builder, "b", ((icl_basic_s*)state_value)->val.b);
}
break;
case IOTCON_TYPE_DOUBLE:
for (node = list->list; node; node = node->next) {
- repr_value = node->data;
- g_variant_builder_add(&builder, "d", ((icl_basic_s*)repr_value)->val.d);
+ state_value = node->data;
+ g_variant_builder_add(&builder, "d", ((icl_basic_s*)state_value)->val.d);
}
break;
case IOTCON_TYPE_STR:
for (node = list->list; node; node = node->next) {
- repr_value = node->data;
- g_variant_builder_add(&builder, "s", ((icl_basic_s*)repr_value)->val.s);
+ state_value = node->data;
+ g_variant_builder_add(&builder, "s", ((icl_basic_s*)state_value)->val.s);
}
break;
case IOTCON_TYPE_LIST:
for (node = list->list; node; node = node->next) {
- repr_value = node->data;
- var = _icl_repr_list_to_gvariant(((icl_val_list_s*)repr_value)->list);
+ state_value = node->data;
+ var = _icl_state_list_to_gvariant(((icl_val_list_s*)state_value)->list);
g_variant_builder_add(&builder, "v", var);
}
break;
- case IOTCON_TYPE_REPR:
+ case IOTCON_TYPE_STATE:
for (node = list->list; node; node = node->next) {
- repr_value = node->data;
- var = icl_repr_to_gvariant(((icl_val_repr_s*)repr_value)->repr);
+ state_value = node->data;
+ state = ((icl_val_state_s*)state_value)->state;
+ var = _icl_state_value_to_gvariant(state->hash_table);
g_variant_builder_add(&builder, "v", var);
}
break;
}
-static GVariantBuilder* _icl_repr_value_to_gvariant(GHashTable *hash)
+
+static GVariantBuilder* _icl_state_value_to_gvariant_builder(GHashTable *hash)
{
gpointer key, value;
GHashTableIter iter;
GVariant *var = NULL;
+ iotcon_state_h state;
GVariantBuilder *builder;
- struct icl_value_s *repr_value = NULL;
+// GVariantBuilder *state_builder;
+ struct icl_value_s *state_value = NULL;
if (NULL == hash)
return NULL;
g_hash_table_iter_init(&iter, hash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
- repr_value = value;
- switch (repr_value->type) {
+ state_value = value;
+ switch (state_value->type) {
case IOTCON_TYPE_INT:
- var = g_variant_new_int32(((icl_basic_s*)repr_value)->val.i);
+ var = g_variant_new_int32(((icl_basic_s*)state_value)->val.i);
break;
case IOTCON_TYPE_BOOL:
- var = g_variant_new_boolean(((icl_basic_s*)repr_value)->val.b);
+ var = g_variant_new_boolean(((icl_basic_s*)state_value)->val.b);
break;
case IOTCON_TYPE_DOUBLE:
- var = g_variant_new_double(((icl_basic_s*)repr_value)->val.d);
+ var = g_variant_new_double(((icl_basic_s*)state_value)->val.d);
break;
case IOTCON_TYPE_STR:
- var = g_variant_new_string(((icl_basic_s*)repr_value)->val.s);
+ var = g_variant_new_string(((icl_basic_s*)state_value)->val.s);
break;
case IOTCON_TYPE_NULL:
var = g_variant_new_string(IC_STR_NULL);
break;
case IOTCON_TYPE_LIST:
- var = _icl_repr_list_to_gvariant(((icl_val_list_s*)repr_value)->list);
+ var = _icl_state_list_to_gvariant(((icl_val_list_s*)state_value)->list);
break;
- case IOTCON_TYPE_REPR:
- var = icl_repr_to_gvariant(((icl_val_repr_s*)repr_value)->repr);
+ case IOTCON_TYPE_STATE:
+ state = ((icl_val_state_s*)state_value)->state;
+ var = _icl_state_value_to_gvariant(state->hash_table);
+// var = g_variant_new("a{sv}", state_builder);
break;
case IOTCON_TYPE_NONE:
default:
}
-GVariant* icl_repr_to_gvariant(iotcon_repr_h repr)
+static GVariant* _icl_state_value_to_gvariant(GHashTable *hash)
+{
+ GVariantBuilder* builder;
+
+ builder = _icl_state_value_to_gvariant_builder(hash);
+
+ return g_variant_builder_end(builder);
+}
+
+
+GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
{
GList *node;
int ifaces = 0;
const char *uri_path;
GVariant *value, *child;
+ iotcon_state_h state;
GVariantBuilder *repr_gvar = NULL;
GVariantBuilder children, resource_types;
}
/* Representation */
- if (ICL_VISIBILITY_REPR & repr->visibility)
- repr_gvar = _icl_repr_value_to_gvariant(repr->hash_table);
+ state = repr->state;
+ if (state && (ICL_VISIBILITY_REPR & repr->visibility))
+ repr_gvar = _icl_state_value_to_gvariant_builder(state->hash_table);
/* Children */
g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
for (node = repr->children; node; node = node->next) {
/* generate recursively */
- child = icl_repr_to_gvariant(node->data);
+ child = icl_representation_to_gvariant(node->data);
g_variant_builder_add(&children, "v", child);
}
}
-static iotcon_list_h _icl_repr_list_from_gvariant(GVariant *var)
+static void _icl_state_from_gvariant(iotcon_state_h state, GVariantIter *iter)
+{
+ char *key;
+ GVariant *var;
+ const char *str_value;
+ iotcon_list_h list_value;
+ iotcon_value_h value = NULL;
+ iotcon_state_h state_value = NULL;
+
+ while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+
+ if (g_variant_is_of_type(var, G_VARIANT_TYPE_BOOLEAN)) {
+ value = icl_value_create_bool(g_variant_get_boolean(var));
+
+ } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
+ value = icl_value_create_int(g_variant_get_int32(var));
+
+ } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_DOUBLE)) {
+ value = icl_value_create_double(g_variant_get_double(var));
+
+ } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) {
+ str_value = g_variant_get_string(var, NULL);
+ if (IC_STR_EQUAL == strcmp(IC_STR_NULL, str_value))
+ value = icl_value_create_null();
+ else
+ value = icl_value_create_str(str_value);
+
+ } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
+ list_value = _icl_state_list_from_gvariant(var);
+ value = icl_value_create_list(list_value);
+ } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("a{sv}"))) {
+ GVariantIter *state_iter;
+ g_variant_get(var, "(&a{sv})", &state_iter);
+ _icl_state_from_gvariant(state_value, state_iter);
+ value = icl_value_create_state(state_value);
+ }
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+ }
+
+ return;
+}
+
+
+static iotcon_list_h _icl_state_list_from_gvariant(GVariant *var)
{
+ int ret;
GVariantIter iter;
const GVariantType *type;
iotcon_list_h list = NULL;
if (g_variant_type_equal(G_VARIANT_TYPE("ab"), type)) {
bool b;
- list = iotcon_list_new(IOTCON_TYPE_BOOL);
+ ret = iotcon_list_create(IOTCON_TYPE_BOOL, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create() Fail(%d)", ret);
+ return NULL;
+ }
+
while (g_variant_iter_loop(&iter, "b", &b))
iotcon_list_insert_bool(list, b, -1);
} else if (g_variant_type_equal(G_VARIANT_TYPE("ai"), type)) {
int i;
- list = iotcon_list_new(IOTCON_TYPE_INT);
+ ret = iotcon_list_create(IOTCON_TYPE_INT, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create() Fail(%d)", ret);
+ return NULL;
+ }
+
while (g_variant_iter_loop(&iter, "i", &i))
iotcon_list_insert_int(list, i, -1);
} else if (g_variant_type_equal(G_VARIANT_TYPE("ad"), type)) {
double d;
- list = iotcon_list_new(IOTCON_TYPE_DOUBLE);
+ ret = iotcon_list_create(IOTCON_TYPE_DOUBLE, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create() Fail(%d)", ret);
+ return NULL;
+ }
+
while (g_variant_iter_loop(&iter, "d", &d))
iotcon_list_insert_double(list, d, -1);
} else if (g_variant_type_equal(G_VARIANT_TYPE("as"), type)) {
char *s;
- list = iotcon_list_new(IOTCON_TYPE_STR);
+ ret = iotcon_list_create(IOTCON_TYPE_STR, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create() Fail(%d)", ret);
+ return NULL;
+ }
+
while (g_variant_iter_loop(&iter, "s", &s))
iotcon_list_insert_str(list, s, -1);
} else if (g_variant_type_equal(G_VARIANT_TYPE("v"), type)) {
GVariant *value;
iotcon_list_h list_value;
- iotcon_repr_h repr_value;
+ iotcon_state_h state_value = NULL;
while (g_variant_iter_loop(&iter, "v", &value)) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
- list_value = _icl_repr_list_from_gvariant(value);
+ list_value = _icl_state_list_from_gvariant(value);
iotcon_list_insert_list(list, list_value, -1);
- } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("(siasa{sv}av)"))) {
- repr_value = icl_repr_from_gvariant(value);
- iotcon_list_insert_repr(list, repr_value, -1);
+ } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("a{sv}"))) {
+ GVariantIter *state_iter;
+ g_variant_get(value, "(&a{sv})", &state_iter);
+ _icl_state_from_gvariant(state_value, state_iter);
+ iotcon_list_insert_state(list, state_value, -1);
}
}
}
}
-static void _icl_repr_value_from_gvariant(iotcon_repr_h repr, GVariantIter *iter)
-{
- char *key;
- GVariant *var;
- const char *str_value;
- iotcon_list_h list_value;
- iotcon_repr_h repr_value;
- iotcon_value_h value = NULL;
-
- while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
-
- if (g_variant_is_of_type(var, G_VARIANT_TYPE_BOOLEAN)) {
- value = icl_value_new_bool(g_variant_get_boolean(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
- value = icl_value_new_int(g_variant_get_int32(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_DOUBLE)) {
- value = icl_value_new_double(g_variant_get_double(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) {
- str_value = g_variant_get_string(var, NULL);
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, str_value))
- value = icl_value_new_null();
- else
- value = icl_value_new_str(str_value);
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
- list_value = _icl_repr_list_from_gvariant(var);
- value = icl_value_new_list(list_value);
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("(siasa{sv}av)"))) {
- repr_value = icl_repr_from_gvariant(var);
- value = icl_value_new_repr(repr_value);
- }
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
- }
-
- return;
-}
-
-
-iotcon_repr_h icl_repr_from_gvariant(GVariant *var)
+iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
{
- iotcon_repr_h repr;
+ int ret;
GVariant *child;
+ iotcon_representation_h repr;
+ iotcon_state_h state;
char *uri_path, *resource_type;
GVariantIter *children, *repr_gvar, *resource_types;
- repr = iotcon_repr_new();
- if (NULL == repr) {
- ERR("iotcon_repr_new() Fail");
+ ret = iotcon_representation_create(&repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return NULL;
+ }
+
+ ret = iotcon_state_create(&state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ return NULL;
+ }
+
+ ret = iotcon_representation_set_state(repr, state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
return NULL;
}
DBG("repr : %s", g_variant_print(var, FALSE));
- g_variant_get(var, "(&siasa{sv}av)", &uri_path, &repr->interfaces, &resource_types,
- &repr_gvar, &children);
+ g_variant_get(var, "(&siasa{sv}av)", &uri_path, &repr->interfaces,
+ &resource_types, &repr_gvar, &children);
/* uri path */
if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
/* resource types */
if (g_variant_iter_n_children(resource_types)) {
- repr->res_types = iotcon_resource_types_new();
+ ret = iotcon_resource_types_create(&repr->res_types);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ g_variant_iter_free(resource_types);
+ g_variant_iter_free(children);
+ return NULL;
+ }
+
while (g_variant_iter_loop(resource_types, "s", &resource_type))
iotcon_resource_types_insert(repr->res_types, resource_type);
}
g_variant_iter_free(resource_types);
/* attribute */
- _icl_repr_value_from_gvariant(repr, repr_gvar);
+ _icl_state_from_gvariant(state, repr_gvar);
/* children */
- while (g_variant_iter_loop(children, "v", &child))
- repr->children = g_list_append(repr->children, icl_repr_from_gvariant(child));
+ while (g_variant_iter_loop(children, "v", &child)) {
+ repr->children = g_list_append(repr->children,
+ icl_representation_from_gvariant(child));
+ }
g_variant_iter_free(children);
return repr;
#include <glib.h>
-GVariant* icl_repr_to_gvariant(iotcon_repr_h repr);
-iotcon_repr_h icl_repr_from_gvariant(GVariant *var);
+GVariant* icl_representation_to_gvariant(iotcon_representation_h repr);
+iotcon_representation_h icl_representation_from_gvariant(GVariant *var);
#endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__*/
#include "icl-resource-types.h"
#include "icl-dbus.h"
+#define ICL_PRESENCE_TTL_SECONDS_MAX (60 * 60 * 24) /* 60 sec/min * 60 min/hr * 24 hr/day */
+
typedef struct icl_presence {
iotcon_presence_cb cb;
void *user_data;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+ RETV_IF(ICL_PRESENCE_TTL_SECONDS_MAX < time_to_live, IOTCON_ERROR_INVALID_PARAMETER);
ic_dbus_call_start_presence_sync(icl_dbus_get_object(), time_to_live, &ret, NULL,
&error);
}
-API int iotcon_stop_presence()
+API int iotcon_stop_presence(void)
{
FN_CALL;
int ret;
/* The length of resource_type should be less than or equal to 61. */
-API iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
- const char *resource_type, iotcon_presence_cb cb, void *user_data)
+API int iotcon_subscribe_presence(const char *host_address, const char *resource_type,
+ iotcon_presence_cb cb, void *user_data, iotcon_presence_h *presence_handle)
{
FN_CALL;
GError *error = NULL;
char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
icl_presence_s *presence_container;
- RETV_IF(NULL == icl_dbus_get_object(), NULL);
- RETV_IF(NULL == host_address, NULL);
- RETV_IF(NULL == cb, NULL);
- if (resource_type && (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
+ RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (resource_type && (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
ERR("The length of resource_type(%s) is invalid", resource_type);
- return NULL;
+ return IOTCON_ERROR_INVALID_PARAMETER;
}
signal_number = icl_dbus_generate_signal_number();
presence_container = calloc(1, sizeof(icl_presence_s));
if (NULL == presence_container) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
resource_type = ic_utils_dbus_encode_str(resource_type);
ERR("ic_dbus_call_subscribe_presence_sync() Fail(%s)", error->message);
g_error_free(error);
free(presence_container);
- return NULL;
+ return IOTCON_ERROR_DBUS;
}
if (0 == presence_container->handle) {
ERR("iotcon-daemon Fail");
free(presence_container);
- return NULL;
+ return IOTCON_ERROR_IOTIVITY;
}
snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PRESENCE,
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
free(presence_container);
- return NULL;
+ return IOTCON_ERROR_DBUS;
}
presence_container->id = sub_id;
- return presence_container;
+ *presence_handle = presence_container;
+
+ return IOTCON_ERROR_NONE;
}
#include "iotcon-struct.h"
#include "ic-utils.h"
#include "icl.h"
+#include "icl-resource-types.h"
#include "icl-query.h"
-API iotcon_query_h iotcon_query_new()
+API int iotcon_query_create(iotcon_query_h *ret_query)
{
iotcon_query_h query = calloc(1, sizeof(struct icl_query));
if (NULL == query) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
query->hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
- return query;
+
+ *ret_query = query;
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_query_free(iotcon_query_h query)
+API void iotcon_query_destroy(iotcon_query_h query)
{
RET_IF(NULL == query);
/* first query : ?key=value
* Rest of query : &key=value */
query_len = strlen(key) + strlen(value) + 2;
- if (IOTCON_QUERY_LENGTH_MAX < (query->len + query_len)) {
+ if (ICL_QUERY_LENGTH_MAX < (query->len + query_len)) {
ERR("Length of query is invalid.");
return IOTCON_ERROR_OUT_OF_MEMORY;
}
}
-API const char* iotcon_query_lookup(iotcon_query_h query, const char *key)
+API int iotcon_query_lookup(iotcon_query_h query, const char *key, const char **data)
{
- const char *ret = NULL;
+ const char *value = NULL;
- RETV_IF(NULL == query, NULL);
- RETV_IF(NULL == key, NULL);
+ RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- ret = g_hash_table_lookup(query->hash, key);
- if (NULL == ret)
+ value = g_hash_table_lookup(query->hash, key);
+ if (NULL == value)
ERR("g_hash_table_lookup() Fail");
- return ret;
+ *data = value;
+
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_fn fn,
+API int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
void *user_data)
{
GHashTableIter iter;
gpointer key, value;
RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
g_hash_table_iter_init(&iter, query->hash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (false == fn(key, value, user_data))
+ if (false == cb(key, value, user_data))
break;
}
*
* @since_tizen 3.0
*/
-#define IOTCON_QUERY_LENGTH_MAX 64
+#define ICL_QUERY_LENGTH_MAX 64
struct icl_query {
#include "iotcon-constant.h"
#include "iotcon-representation.h"
#include "icl.h"
-#include "icl-repr-obj.h"
+#include "icl-repr-state.h"
#include "icl-repr.h"
#include "icl-repr-value.h"
#include "icl-repr-list.h"
return ret;
}
-static iotcon_list_h _icl_list_new(iotcon_types_e type)
+static int _icl_list_create(iotcon_types_e type, iotcon_list_h *ret_list)
{
iotcon_list_h list;
list = calloc(1, sizeof(struct icl_list_s));
if (NULL == list) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
icl_list_inc_ref_count(list);
list->type = type;
- return list;
+ *ret_list = list;
+
+ return IOTCON_ERROR_NONE;
}
-API iotcon_list_h iotcon_list_new(iotcon_types_e type)
+API int iotcon_list_create(iotcon_types_e type, iotcon_list_h *ret_list)
{
- if (type < IOTCON_TYPE_INT || IOTCON_TYPE_REPR < type) {
+ int ret;
+ iotcon_list_h list;
+
+ if (type < IOTCON_TYPE_INT || IOTCON_TYPE_STATE < type) {
ERR("Invalid Type(%d)", type);
- return NULL;
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _icl_list_create(type, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_icl_list_create() Fail");
+ return ret;
}
- return _icl_list_new(type);
+ *ret_list = list;
+
+ return IOTCON_ERROR_NONE;
}
RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
list->type);
- value = icl_value_new_int(val);
+ value = icl_value_create_int(val);
if (NULL == value) {
- ERR("icl_value_new_int(%d) Fail", val);
+ ERR("icl_value_create_int(%d) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- value = icl_value_new_bool(val);
+ value = icl_value_create_bool(val);
if (NULL == value) {
- ERR("icl_value_new_bool(%d) Fail", val);
+ ERR("icl_value_create_bool(%d) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- value = icl_value_new_double(val);
+ value = icl_value_create_double(val);
if (NULL == value) {
- ERR("icl_value_new_double(%f) Fail", val);
+ ERR("icl_value_create_double(%f) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- value = icl_value_new_str(val);
+ value = icl_value_create_str(val);
if (NULL == value) {
- ERR("icl_value_new_str(%s) Fail", val);
+ ERR("icl_value_create_str(%s) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- value = icl_value_new_list(val);
+ value = icl_value_create_list(val);
if (NULL == value) {
- ERR("icl_value_new_list(%p) Fail", val);
+ ERR("icl_value_create_list(%p) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
}
-API int iotcon_list_insert_repr(iotcon_list_h list, iotcon_repr_h val, int pos)
+API int iotcon_list_insert_state(iotcon_list_h list, iotcon_state_h val, int pos)
{
iotcon_value_h value;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_REPR != list->type, IOTCON_ERROR_INVALID_TYPE,
+ RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- value = icl_value_new_repr(val);
+ value = icl_value_create_state(val);
if (NULL == value) {
- ERR("icl_value_new_repr(%p) Fail", val);
+ ERR("icl_value_create_state(%p) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- icl_repr_inc_ref_count(val);
+ icl_state_inc_ref_count(val);
return icl_list_insert(list, value, pos);
}
}
-API int iotcon_list_get_nth_repr(iotcon_list_h list, int pos, iotcon_repr_h *repr)
+API int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state)
{
int ret;
iotcon_value_h value;
- iotcon_repr_h repr_val;
+ iotcon_state_h state_val;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
value = g_list_nth_data(list->list, pos);
if (NULL == value) {
return IOTCON_ERROR_NO_DATA;
}
- ret = icl_value_get_repr(value, &repr_val);
+ ret = icl_value_get_state(value, &state_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_list() Fail(%d)", ret);
+ ERR("icl_value_get_state() Fail(%d)", ret);
return IOTCON_ERROR_REPRESENTATION;
}
- *repr = repr_val;
+ *state = state_val;
return IOTCON_ERROR_NONE;
}
free(real->val.s);
} else if (IOTCON_TYPE_LIST == value->type) {
icl_val_list_s *real = (icl_val_list_s*)value;
- iotcon_list_free(real->list);
- } else if (IOTCON_TYPE_REPR == value->type) {
- icl_val_repr_s *real = (icl_val_repr_s*)value;
- iotcon_repr_free(real->repr);
+ iotcon_list_destroy(real->list);
+ } else if (IOTCON_TYPE_STATE == value->type) {
+ icl_val_state_s *real = (icl_val_state_s*)value;
+ iotcon_state_destroy(real->state);
}
icl_list_remove(list, value);
}
-API int iotcon_list_del_nth_repr(iotcon_list_h list, int pos)
+API int iotcon_list_del_nth_state(iotcon_list_h list, int pos)
{
int ret;
- ret = _icl_list_del_nth_value(list, pos, IOTCON_TYPE_REPR);
+ ret = _icl_list_del_nth_value(list, pos, IOTCON_TYPE_STATE);
if (IOTCON_ERROR_NONE != ret)
ERR("_icl_list_del_nth_value() Fail(%d)", ret);
}
-API unsigned int iotcon_list_get_length(iotcon_list_h list)
+API int iotcon_list_get_length(iotcon_list_h list, unsigned int *length)
{
- RETV_IF(NULL == list, 0);
- RETV_IF(NULL == list->list, 0);
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *length = g_list_length(list->list);
- return g_list_length(list->list);
+ return IOTCON_ERROR_NONE;
}
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn,
+API int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb,
void *user_data)
{
GList *cur;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
list->type);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == fn(index, real->val.i, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->val.i, user_data))
break;
index++;
cur = next;
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn,
+API int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb,
void *user_data)
{
GList *cur;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == fn(index, real->val.b, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->val.b, user_data))
break;
index++;
cur = next;
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn,
+API int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
void *user_data)
{
GList *cur;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == fn(index, real->val.d, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->val.d, user_data))
break;
index++;
cur = next;
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn,
+API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb,
void *user_data)
{
GList *cur;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
list->type);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == fn(index, real->val.s, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->val.s, user_data))
break;
index++;
cur = next;
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_fn fn,
+API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb,
void *user_data)
{
int index = 0;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == fn(index, real->list, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->list, user_data))
break;
index++;
cur = next;
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data)
+API int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb,
+ void *user_data)
{
int index = 0;
GList *cur = NULL;
- icl_val_repr_s *real = NULL;
+ icl_val_state_s *real = NULL;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_REPR != list->type, IOTCON_ERROR_INVALID_TYPE,
+ RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);;
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);;
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == fn(index, real->repr, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->state, user_data))
break;
index++;
cur = next;
}
-API void iotcon_list_free(iotcon_list_h list)
+API void iotcon_list_destroy(iotcon_list_h list)
{
FN_CALL;
GList *cur = NULL;
cur = list->list;
while (cur) {
- icl_value_free(cur->data);
+ icl_value_destroy(cur->data);
cur = cur->next;
}
free(list);
ret = icl_list_insert(ret_list, copied_value, -1);
if (IOTCON_ERROR_NONE != ret) {
ERR("icl_list_insert() Fail");
- icl_value_free(copied_value);
+ icl_value_destroy(copied_value);
return IOTCON_ERROR_REPRESENTATION;
}
}
return IOTCON_ERROR_REPRESENTATION;
}
- value = icl_value_new_list(copied_list);
+ value = icl_value_create_list(copied_list);
if (NULL == value) {
- ERR("icl_value_new_list(%p) Fail", copied_list);
- iotcon_list_free(copied_list);
+ ERR("icl_value_create_list(%p) Fail", copied_list);
+ iotcon_list_destroy(copied_list);
return IOTCON_ERROR_REPRESENTATION;
}
ret = icl_list_insert(ret_list, value, -1);
if (IOTCON_ERROR_NONE != ret) {
ERR("icl_list_insert(%d) Fail", ret);
- icl_value_free(value);
+ icl_value_destroy(value);
return IOTCON_ERROR_REPRESENTATION;
}
}
}
-static int _icl_list_clone_repr(iotcon_list_h list, iotcon_list_h ret_list)
+static int _icl_list_clone_state(iotcon_list_h list, iotcon_list_h ret_list)
{
int i, ret, count;
iotcon_value_h value;
- iotcon_repr_h repr_val, copied_repr;
+ iotcon_state_h state_val;
+ iotcon_state_h copied_state = NULL;
count = g_list_length(list->list);
for (i = 0; i < count; i++) {
- ret = iotcon_list_get_nth_repr(list, i, &repr_val);
+ ret = iotcon_list_get_nth_state(list, i, &state_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_get_nth_repr() Fail");
+ ERR("iotcon_list_get_nth_state() Fail");
return IOTCON_ERROR_REPRESENTATION;
}
- copied_repr = iotcon_repr_clone(repr_val);
- if (NULL == copied_repr) {
- ERR("_ic_repr_clone_repr() Fail");
- return IOTCON_ERROR_REPRESENTATION;
+
+ if (state_val->hash_table) {
+ g_hash_table_foreach(state_val->hash_table, (GHFunc)icl_state_clone,
+ copied_state);
}
- value = icl_value_new_repr(copied_repr);
+ value = icl_value_create_state(copied_state);
if (NULL == value) {
- ERR("icl_value_new_repr(%p) Fail", copied_repr);
- iotcon_repr_free(copied_repr);
+ ERR("icl_value_create_state(%p) Fail", copied_state);
+ iotcon_state_destroy(copied_state);
return IOTCON_ERROR_REPRESENTATION;
}
ret = icl_list_insert(ret_list, value, -1);
if (IOTCON_ERROR_NONE != ret) {
ERR("icl_list_insert(%d) Fail", ret);
- icl_value_free(value);
+ icl_value_destroy(value);
return IOTCON_ERROR_REPRESENTATION;
}
}
RETV_IF(NULL == list, NULL);
RETV_IF(NULL == list->list, NULL);
- ret_list = iotcon_list_new(list->type);
- if (NULL == ret_list) {
- ERR("iotcon_list_new(%d) Fail", list->type);
+ ret = iotcon_list_create(list->type, &ret_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create(%d) Fail(%d)", list->type, ret);
return NULL;
}
ret = _icl_list_clone_value(list, ret_list);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_list_clone_value() Fail(%d)", ret);
- iotcon_list_free(ret_list);
+ iotcon_list_destroy(ret_list);
return NULL;
}
break;
ret = _icl_list_clone_list(list, ret_list);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_list_clone_list() Fail(%d)", ret);
- iotcon_list_free(ret_list);
+ iotcon_list_destroy(ret_list);
return NULL;
}
break;
- case IOTCON_TYPE_REPR:
- ret = _icl_list_clone_repr(list, ret_list);
+ case IOTCON_TYPE_STATE:
+ ret = _icl_list_clone_state(list, ret_list);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_repr() Fail(%d)", ret);
- iotcon_list_free(ret_list);
+ ERR("_icl_list_clone_state() Fail(%d)", ret);
+ iotcon_list_destroy(ret_list);
return NULL;
}
break;
default:
ERR("Invalid type(%d)", list->type);
- iotcon_list_free(ret_list);
+ iotcon_list_destroy(ret_list);
return NULL;
}
#include <glib.h>
#include "iotcon-struct.h"
+#include "icl-repr-value.h"
struct icl_list_s {
int type;
+++ /dev/null
-/* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-
-#include "iotcon-struct.h"
-#include "iotcon-constant.h"
-#include "iotcon-representation.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-repr-list.h"
-#include "icl-repr-value.h"
-#include "icl-repr.h"
-#include "icl-repr-obj.h"
-
-int icl_obj_del_value(iotcon_repr_h repr, const char *key,
- iotcon_types_e value_type)
-{
- gboolean ret = FALSE;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup(%s) Fail", key);
- return IOTCON_ERROR_NO_DATA;
- }
-
- if (value_type != value->type) {
- ERR("Type matching Fail(input:%d, saved:%d)", value_type, value->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- ret = g_hash_table_remove(repr->hash_table, key);
- if (FALSE == ret) {
- ERR("g_hash_table_remove(%s) Fail", key);
- return IOTCON_ERROR_NO_DATA;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_get_int(iotcon_repr_h repr, const char *key, int *val)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- icl_basic_s *real = (icl_basic_s*)value;
- if (IOTCON_TYPE_INT != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.i;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_set_int(iotcon_repr_h repr, const char *key, int val)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_int(val);
- if (NULL == value) {
- ERR("icl_value_new_int(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_int(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_INT);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API int iotcon_repr_get_bool(iotcon_repr_h repr, const char *key, bool *val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_BOOL != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.b;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_set_bool(iotcon_repr_h repr, const char *key, bool val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_bool(val);
- if (NULL == value) {
- ERR("icl_value_new_bool(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_bool(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_BOOL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API int iotcon_repr_get_double(iotcon_repr_h repr, const char *key, double *val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_DOUBLE != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.d;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_set_double(iotcon_repr_h repr, const char *key, double val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_double(val);
- if (NULL == value) {
- ERR("icl_value_new_double(%f) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_double(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_DOUBLE);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API int iotcon_repr_get_str(iotcon_repr_h repr, const char *key, char **val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_STR != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.s;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_set_str(iotcon_repr_h repr, const char *key, char *val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_str(val);
- if (NULL == value) {
- ERR("icl_value_new_str(%s) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_str(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_STR);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API bool iotcon_repr_is_null(iotcon_repr_h repr, const char *key)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, false);
- RETV_IF(NULL == key, false);
-
- value = (iotcon_value_h) g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return false;
- }
-
- real = (icl_basic_s*)value;
-
- return (IOTCON_TYPE_NULL == real->type) ? true : false;
-}
-
-API int iotcon_repr_set_null(iotcon_repr_h repr, const char *key)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_null();
- if (NULL == value) {
- ERR("icl_value_new_null() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_null(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API int iotcon_repr_get_list(iotcon_repr_h repr, const char *key, iotcon_list_h *list)
-{
- iotcon_value_h value = NULL;
- icl_val_list_s *real = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_list_s*)value;
- if (IOTCON_TYPE_LIST != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *list = real->list;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_set_list(iotcon_repr_h repr, const char *key, iotcon_list_h list)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_list(list);
- if (NULL == value) {
- ERR("icl_value_new_list() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- icl_list_inc_ref_count(list);
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_list(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_LIST);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-
-API int iotcon_repr_get_repr(iotcon_repr_h src, const char *key, iotcon_repr_h *dest)
-{
- icl_val_repr_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(src->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_repr_s*)value;
- if (IOTCON_TYPE_REPR != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *dest = real->repr;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_set_repr(iotcon_repr_h repr, const char *key, iotcon_repr_h val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_new_repr(val);
- if (NULL == value) {
- ERR("icl_value_new_repr(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- icl_repr_inc_ref_count(val);
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_repr_del_repr(iotcon_repr_h repr, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_obj_del_value(repr, key, IOTCON_TYPE_REPR);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_obj_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API int iotcon_repr_get_type(iotcon_repr_h repr, const char *key, int *type)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(repr->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
- *type = value->type;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
--- /dev/null
+/* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "iotcon-representation.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-repr-list.h"
+#include "icl-repr-value.h"
+#include "icl-repr.h"
+#include "icl-repr-state.h"
+
+void icl_state_inc_ref_count(iotcon_state_h val)
+{
+ RET_IF(NULL == val);
+ RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count++;
+}
+
+
+bool icl_state_dec_ref_count(iotcon_state_h val)
+{
+ bool ret;
+
+ RETV_IF(NULL == val, -1);
+ RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count--;
+ if (0 == val->ref_count)
+ ret = true;
+ else
+ ret = false;
+
+ return ret;
+}
+
+
+API int iotcon_state_create(iotcon_state_h *ret_state)
+{
+ errno = 0;
+ iotcon_state_h state;
+
+ state = calloc(1, sizeof(struct icl_state_s));
+ if (NULL == state) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ state->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
+ icl_value_destroy);
+ icl_state_inc_ref_count(state);
+
+ *ret_state = state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_state_destroy(iotcon_state_h state)
+{
+ RET_IF(NULL == state);
+
+ if (false == icl_state_dec_ref_count(state)) {
+ return;
+ }
+
+ g_hash_table_destroy(state->hash_table);
+ free(state);
+}
+
+
+int icl_state_del_value(iotcon_state_h state, const char *key, iotcon_types_e value_type)
+{
+ gboolean ret = FALSE;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup(%s) Fail", key);
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ if (value_type != value->type) {
+ ERR("Type matching Fail(input:%d, saved:%d)", value_type, value->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ ret = g_hash_table_remove(state->hash_table, key);
+ if (FALSE == ret) {
+ ERR("g_hash_table_remove(%s) Fail", key);
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ icl_basic_s *real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_INT != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.i;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_int(iotcon_state_h state, const char *key, int val)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_int(val);
+ if (NULL == value) {
+ ERR("icl_value_create_int(%d) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_int(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_INT);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_BOOL != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.b;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_bool(iotcon_state_h state, const char *key, bool val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_bool(val);
+ if (NULL == value) {
+ ERR("icl_value_create_bool(%d) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_bool(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_BOOL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_DOUBLE != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.d;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_double(iotcon_state_h state, const char *key, double val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_double(val);
+ if (NULL == value) {
+ ERR("icl_value_create_double(%f) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_double(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_DOUBLE);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_STR != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.s;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_str(iotcon_state_h state, const char *key, char *val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_str(val);
+ if (NULL == value) {
+ ERR("icl_value_create_str(%s) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_str(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_STR);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = (iotcon_value_h) g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ *is_null = (IOTCON_TYPE_NULL == real->type) ? true : false;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_null(iotcon_state_h state, const char *key)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_null();
+ if (NULL == value) {
+ ERR("icl_value_create_null() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_null(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_NULL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_state_get_list(iotcon_state_h state, const char *key, iotcon_list_h *list)
+{
+ iotcon_value_h value = NULL;
+ icl_val_list_s *real = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_val_list_s*)value;
+ if (IOTCON_TYPE_LIST != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *list = real->list;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_list(iotcon_state_h state, const char *key, iotcon_list_h list)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_list(list);
+ if (NULL == value) {
+ ERR("icl_value_create_list() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ icl_list_inc_ref_count(list);
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_list(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_LIST);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+
+API int iotcon_state_get_state(iotcon_state_h src, const char *key, iotcon_state_h *dest)
+{
+ icl_val_state_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(src->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_val_state_s*)value;
+ if (IOTCON_TYPE_STATE != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *dest = real->state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_set_state(iotcon_state_h state, const char *key, iotcon_state_h val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_state(val);
+ if (NULL == value) {
+ ERR("icl_value_create_state(%p) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ icl_state_inc_ref_count(val);
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_del_state(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key, IOTCON_TYPE_STATE);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_state_get_type(iotcon_state_h state, const char *key, int *type)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(state->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+ *type = value->type;
+
+ return IOTCON_ERROR_NONE;
+}
+
+int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value)
+{
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+
+ g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_OBJECT_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_OBJECT_H__
+#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_STATE_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_STATE_H__
#include "iotcon-struct.h"
#include "iotcon-constant.h"
+#include "icl-repr-value.h"
-int icl_obj_del_value(iotcon_repr_h repr, const char *key,
+void icl_state_inc_ref_count(iotcon_state_h val);
+bool icl_state_dec_ref_count(iotcon_state_h val);
+
+int icl_state_del_value(iotcon_state_h state, const char *key,
iotcon_types_e value_type);
-int ic_repr_obj_get_value(iotcon_repr_h repr, const char *key, iotcon_value_h *retval);
-int icl_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value);
+int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value);
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_OBJECT_H__ */
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_STATE_H__ */
#include "icl-repr-list.h"
#include "icl-repr-value.h"
-static iotcon_value_h _icl_value_new(int type)
+static iotcon_value_h _icl_value_create(int type)
{
iotcon_value_h ret_val;
case IOTCON_TYPE_LIST:
ret_val = calloc(1, sizeof(icl_val_list_s));
break;
- case IOTCON_TYPE_REPR:
- ret_val = calloc(1, sizeof(icl_val_repr_s));
+ case IOTCON_TYPE_STATE:
+ ret_val = calloc(1, sizeof(icl_val_state_s));
break;
default:
ERR("Invalid Type(%d)", type);
}
-iotcon_value_h icl_value_new_null()
+iotcon_value_h icl_value_create_null()
{
iotcon_value_h value;
- value = _icl_value_new(IOTCON_TYPE_NULL);
+ value = _icl_value_create(IOTCON_TYPE_NULL);
if (NULL == value) {
- ERR("_icl_value_new(NULL) Fail");
+ ERR("_icl_value_create(NULL) Fail");
return NULL;
}
return value;
}
-iotcon_value_h icl_value_new_int(int val)
+iotcon_value_h icl_value_create_int(int val)
{
icl_basic_s *value;
- value = (icl_basic_s*)_icl_value_new(IOTCON_TYPE_INT);
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_INT);
if (NULL == value) {
- ERR("_icl_value_new(INT:%d) Fail", val);
+ ERR("_icl_value_create(INT:%d) Fail", val);
return NULL;
}
return (iotcon_value_h)value;
}
-iotcon_value_h icl_value_new_bool(bool val)
+iotcon_value_h icl_value_create_bool(bool val)
{
icl_basic_s *value;
- value = (icl_basic_s*)_icl_value_new(IOTCON_TYPE_BOOL);
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_BOOL);
if (NULL == value) {
- ERR("_icl_value_new(BOOL:%d) Fail", val);
+ ERR("_icl_value_create(BOOL:%d) Fail", val);
return NULL;
}
return (iotcon_value_h)value;
}
-iotcon_value_h icl_value_new_double(double val)
+iotcon_value_h icl_value_create_double(double val)
{
icl_basic_s *value;
- value = (icl_basic_s*)_icl_value_new(IOTCON_TYPE_DOUBLE);
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_DOUBLE);
if (NULL == value) {
- ERR("_icl_value_new(DOUBLE:%f) Fail", val);
+ ERR("_icl_value_create(DOUBLE:%f) Fail", val);
return NULL;
}
return (iotcon_value_h)value;
}
-iotcon_value_h icl_value_new_str(const char *val)
+iotcon_value_h icl_value_create_str(const char *val)
{
icl_basic_s *value;
RETV_IF(NULL == val, NULL);
- value = (icl_basic_s*)_icl_value_new(IOTCON_TYPE_STR);
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_STR);
if (NULL == value) {
- ERR("_icl_value_new(STR:%s) Fail", val);
+ ERR("_icl_value_create(STR:%s) Fail", val);
return NULL;
}
}
-iotcon_value_h icl_value_new_list(iotcon_list_h val)
+iotcon_value_h icl_value_create_list(iotcon_list_h val)
{
icl_val_list_s *value;
- value = (icl_val_list_s*)_icl_value_new(IOTCON_TYPE_LIST);
+ value = (icl_val_list_s*)_icl_value_create(IOTCON_TYPE_LIST);
if (NULL == value) {
- ERR("_icl_value_new(LIST) Fail");
+ ERR("_icl_value_create(LIST) Fail");
return NULL;
}
return (iotcon_value_h)value;
}
-iotcon_value_h icl_value_new_repr(iotcon_repr_h val)
+iotcon_value_h icl_value_create_state(iotcon_state_h val)
{
- icl_val_repr_s *value;
+ icl_val_state_s *value;
- value = (icl_val_repr_s*)_icl_value_new(IOTCON_TYPE_REPR);
+ value = (icl_val_state_s*)_icl_value_create(IOTCON_TYPE_STATE);
if (NULL == value) {
- ERR("_icl_value_new(REPR) Fail");
+ ERR("_icl_value_create(state) Fail");
return NULL;
}
- value->repr = val;
+ value->state = val;
return (iotcon_value_h)value;
}
return IOTCON_ERROR_NONE;
}
-int icl_value_get_repr(iotcon_value_h value, iotcon_repr_h *repr)
+int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state)
{
- icl_val_repr_s *real = (icl_val_repr_s*)value;
+ icl_val_state_s *real = (icl_val_state_s*)value;
RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_REPR != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ RETVM_IF(IOTCON_TYPE_STATE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
"Invalid Type(%d)", real->type);
- *repr = real->repr;
+ *state = real->state;
return IOTCON_ERROR_NONE;
}
-void icl_value_free(gpointer data)
+void icl_value_destroy(gpointer data)
{
int ret;
iotcon_value_h value;
iotcon_list_h list;
- iotcon_repr_h repr;
+ iotcon_state_h state;
RET_IF(NULL == data);
ERR("icl_value_get_list() Fail(%d)", ret);
break;
}
- iotcon_list_free(list);
+ iotcon_list_destroy(list);
break;
- case IOTCON_TYPE_REPR:
+ case IOTCON_TYPE_STATE:
DBG("value is Repr");
- ret = icl_value_get_repr(value, &repr);
+ ret = icl_value_get_state(value, &state);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_repr() Fail(%d)", ret);
+ ERR("icl_value_get_state() Fail(%d)", ret);
break;
}
- iotcon_repr_free(repr);
+ iotcon_state_destroy(state);
break;
default:
ERR("Invalid type(%d)", type);
switch (src->type) {
case IOTCON_TYPE_INT:
- dest = icl_value_new_int(real->val.i);
+ dest = icl_value_create_int(real->val.i);
break;
case IOTCON_TYPE_BOOL:
- dest = icl_value_new_bool(real->val.b);
+ dest = icl_value_create_bool(real->val.b);
break;
case IOTCON_TYPE_DOUBLE:
- dest = icl_value_new_double(real->val.d);
+ dest = icl_value_create_double(real->val.d);
break;
case IOTCON_TYPE_STR:
- dest = icl_value_new_str(ic_utils_strdup(real->val.s));
+ dest = icl_value_create_str(ic_utils_strdup(real->val.s));
break;
case IOTCON_TYPE_NULL:
- dest = icl_value_new_null();
+ dest = icl_value_create_null();
break;
default:
ERR("Invalid type(%d)", src->type);
}
if (NULL == dest)
- ERR("ic_value_new_xxx(%d) Fail", src->type);
+ ERR("ic_value_create_xxx(%d) Fail", src->type);
return dest;
}
#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_VALUE_H__
#include <stdbool.h>
+#include <glib.h>
#include "iotcon-struct.h"
typedef struct {
int type;
- struct icl_repr_s *repr;
-} icl_val_repr_s;
+ struct icl_state_s *state;
+} icl_val_state_s;
-iotcon_value_h icl_value_new_null();
-iotcon_value_h icl_value_new_int(int val);
-iotcon_value_h icl_value_new_bool(bool val);
-iotcon_value_h icl_value_new_double(double val);
-iotcon_value_h icl_value_new_str(const char *val);
-iotcon_value_h icl_value_new_list(iotcon_list_h val);
-iotcon_value_h icl_value_new_repr(iotcon_repr_h val);
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
+ * @brief The handle of representation value.
+ * @details iotcon_value_h is an opaque data structure to have variant datatype and
+ * store values along with information about the type of that value.\n
+ * The range of possible values is determined by the type.\n
+ * The type of iotcon_value_h should be one of them\n
+ * #IOTCON_TYPE_INT\n
+ * #IOTCON_TYPE_BOOL\n
+ * #IOTCON_TYPE_DOUBLE\n
+ * #IOTCON_TYPE_STR\n
+ * #IOTCON_TYPE_NULL\n
+ * #IOTCON_TYPE_LIST\n
+ * #IOTCON_TYPE_STATE
+ *
+ * @since_tizen 3.0
+ */
+typedef struct icl_value_s* iotcon_value_h;
+
+iotcon_value_h icl_value_create_null();
+iotcon_value_h icl_value_create_int(int val);
+iotcon_value_h icl_value_create_bool(bool val);
+iotcon_value_h icl_value_create_double(double val);
+iotcon_value_h icl_value_create_str(const char *val);
+iotcon_value_h icl_value_create_list(iotcon_list_h val);
+iotcon_value_h icl_value_create_state(iotcon_state_h val);
int icl_value_get_int(iotcon_value_h value, int *val);
int icl_value_get_double(iotcon_value_h value, double *val);
int icl_value_get_str(iotcon_value_h value, const char **val);
int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list);
-int icl_value_get_repr(iotcon_value_h value, iotcon_repr_h *repr);
+int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state);
-void icl_value_free(gpointer data);
+void icl_value_destroy(gpointer data);
iotcon_value_h icl_value_clone(iotcon_value_h src);
#include "icl-response.h"
#include "icl-repr-list.h"
#include "icl-repr-value.h"
-#include "icl-repr-obj.h"
+#include "icl-repr-state.h"
#include "icl-repr.h"
-void icl_repr_inc_ref_count(iotcon_repr_h val)
+void icl_representation_inc_ref_count(iotcon_representation_h val)
{
RET_IF(NULL == val);
RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
val->ref_count++;
}
-static bool _icl_repr_dec_ref_count(iotcon_repr_h val)
+
+static bool _icl_representation_dec_ref_count(iotcon_representation_h val)
{
bool ret;
return ret;
}
-API iotcon_repr_h iotcon_repr_new()
+
+API int iotcon_representation_create(iotcon_representation_h *ret_repr)
{
- iotcon_repr_h ret_val;
errno = 0;
+ iotcon_representation_h repr;
- ret_val = calloc(1, sizeof(struct icl_repr_s));
- if (NULL == ret_val) {
+ repr = calloc(1, sizeof(struct icl_representation_s));
+ if (NULL == repr) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ret_val->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
- icl_value_free);
- icl_repr_inc_ref_count(ret_val);
- ret_val->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
+ repr->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
+ icl_representation_inc_ref_count(repr);
- return ret_val;
+ *ret_repr = repr;
+
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_get_uri_path(iotcon_repr_h repr, const char **uri_path)
+
+API void iotcon_representation_destroy(iotcon_representation_h repr)
+{
+ RET_IF(NULL == repr);
+
+ if (false == _icl_representation_dec_ref_count(repr))
+ return;
+
+ free(repr->uri_path);
+
+ /* (GDestroyNotify) : iotcon_representation_h is proper type than gpointer */
+ g_list_free_full(repr->children, (GDestroyNotify)iotcon_representation_destroy);
+
+ /* null COULD be allowed */
+ if (repr->res_types)
+ iotcon_resource_types_destroy(repr->res_types);
+
+ /* null COULD be allowed */
+ if (repr->state)
+ iotcon_state_destroy(repr->state);
+
+ free(repr);
+}
+
+
+API int iotcon_representation_get_uri_path(iotcon_representation_h repr, const char **uri_path)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_set_uri_path(iotcon_repr_h repr, const char *uri_path)
+API int iotcon_representation_set_uri_path(iotcon_representation_h repr, const char *uri_path)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resource_types_h *types)
+API int iotcon_representation_get_resource_types(iotcon_representation_h repr,
+ iotcon_resource_types_h *types)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_resource_types_h types)
+API int iotcon_representation_set_resource_types(iotcon_representation_h repr,
+ iotcon_resource_types_h types)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- iotcon_resource_types_free(repr->res_types);
+ iotcon_resource_types_destroy(repr->res_types);
repr->res_types = NULL;
if (types)
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_get_resource_interfaces(iotcon_repr_h repr)
+API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
+ int *ifaces)
{
- RETV_IF(NULL == repr, IOTCON_INTERFACE_NONE);
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *ifaces = repr->interfaces;
- return repr->interfaces;
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces)
+API int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
+ int ifaces)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_append_child(iotcon_repr_h parent, iotcon_repr_h child)
+
+API int iotcon_representation_set_state(iotcon_representation_h repr,
+ iotcon_state_h state)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (repr->state) {
+ ERR("state already set. Remove first !");
+ return IOTCON_ERROR_ALREADY;
+ }
+
+ icl_state_inc_ref_count(state);
+ repr->state = state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_get_state(iotcon_representation_h repr,
+ iotcon_state_h *state)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *state = repr->state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_del_state(iotcon_representation_h repr)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (repr->state)
+ iotcon_state_destroy(repr->state);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_append_child(iotcon_representation_h parent,
+ iotcon_representation_h child)
{
RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
- icl_repr_inc_ref_count(child);
+ icl_representation_inc_ref_count(child);
parent->children = g_list_append(parent->children, child);
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_foreach_children(iotcon_repr_h parent, iotcon_children_fn fn,
- void *user_data)
+
+API int iotcon_representation_remove_child(iotcon_representation_h parent,
+ iotcon_representation_h child)
+{
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+
+ parent->children = g_list_remove(parent->children, child);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_foreach_children(iotcon_representation_h parent,
+ iotcon_children_cb cb, void *user_data)
{
GList *list, *next;
RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
list = parent->children;
while (list) {
next = list->next;
- if (IOTCON_FUNC_STOP == fn(list->data, user_data))
+ if (IOTCON_FUNC_STOP == cb(list->data, user_data))
break;
list = next;
}
return IOTCON_ERROR_NONE;
}
-API unsigned int iotcon_repr_get_children_count(iotcon_repr_h parent)
+API int iotcon_representation_get_children_count(iotcon_representation_h parent,
+ unsigned int *count)
{
- RETV_IF(NULL == parent, 0);
- RETV_IF(NULL == parent->children, 0);
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *count = g_list_length(parent->children);
- return g_list_length(parent->children);
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_get_nth_child(iotcon_repr_h parent, int pos, iotcon_repr_h *child)
+API int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos,
+ iotcon_representation_h *child)
{
RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_foreach(iotcon_repr_h repr, iotcon_repr_fn fn, void *user_data)
+API int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data)
{
GHashTableIter iter;
gpointer key;
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- g_hash_table_iter_init(&iter, repr->hash_table);
+ g_hash_table_iter_init(&iter, state->hash_table);
while (g_hash_table_iter_next(&iter, &key, NULL)) {
- if (IOTCON_FUNC_STOP == fn(repr, key, user_data))
+ if (IOTCON_FUNC_STOP == cb(state, key, user_data))
break;
}
return IOTCON_ERROR_NONE;
}
-API unsigned int iotcon_repr_get_keys_count(iotcon_repr_h repr)
-{
- RETV_IF(NULL == repr, 0);
- RETV_IF(NULL == repr->hash_table, 0);
-
- return g_hash_table_size(repr->hash_table);
-}
-
-API void iotcon_repr_free(iotcon_repr_h repr)
+API int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count)
{
- RET_IF(NULL == repr);
-
- if (false == _icl_repr_dec_ref_count(repr))
- return;
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state->hash_table, IOTCON_ERROR_INVALID_PARAMETER);
- free(repr->uri_path);
-
- /* (GDestroyNotify) : iotcon_repr_h is proper type than gpointer */
- g_list_free_full(repr->children, (GDestroyNotify)iotcon_repr_free);
+ *count = g_hash_table_size(state->hash_table);
- /* null COULD be allowed */
- if (repr->res_types)
- iotcon_resource_types_free(repr->res_types);
- g_hash_table_destroy(repr->hash_table);
- free(repr);
+ return IOTCON_ERROR_NONE;
}
-static void _icl_repr_obj_clone(char *key, iotcon_value_h src_val, iotcon_repr_h dest_repr)
+
+void icl_state_clone(char *key, iotcon_value_h src_val, iotcon_state_h dest_state)
{
FN_CALL;
int type, ret;
iotcon_value_h value, copied_val;
iotcon_list_h child_list, copied_list;
- iotcon_repr_h child_repr, copied_repr;
+ iotcon_state_h child_state;
+ iotcon_state_h copied_state = NULL;
type = src_val->type;
switch (type) {
return;
}
- icl_obj_set_value(dest_repr, key, copied_val);
+ icl_state_set_value(dest_state, key, copied_val);
break;
case IOTCON_TYPE_LIST:
ret = icl_value_get_list(src_val, &child_list);
return;
}
- value = icl_value_new_list(copied_list);
+ value = icl_value_create_list(copied_list);
if (NULL == value) {
- ERR("icl_value_new_list() Fail");
- iotcon_list_free(copied_list);
+ ERR("icl_value_create_list() Fail");
+ iotcon_list_destroy(copied_list);
return;
}
- icl_obj_set_value(dest_repr, key, value);
+ icl_state_set_value(dest_state, key, value);
break;
- case IOTCON_TYPE_REPR:
- ret = icl_value_get_repr(src_val, &child_repr);
+ case IOTCON_TYPE_STATE:
+ ret = icl_value_get_state(src_val, &child_state);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_repr() Fail(%d)", ret);
+ ERR("icl_value_get_state() Fail(%d)", ret);
return;
}
- copied_repr = iotcon_repr_clone(child_repr);
- if (NULL == copied_repr) {
- ERR("icl_list_clone() Fail");
- return;
- }
+ g_hash_table_foreach(child_state->hash_table, (GHFunc)icl_state_clone,
+ copied_state);
- value = icl_value_new_repr(copied_repr);
+ value = icl_value_create_state(copied_state);
if (NULL == value) {
- ERR("icl_value_new_repr(%p) Fail", copied_repr);
+ ERR("icl_value_create_state(%p) Fail", copied_state);
return;
}
- icl_obj_set_value(dest_repr, key, value);
+ icl_state_set_value(dest_state, key, value);
break;
default:
ERR("Invalid type(%d)", type);
}
}
-API iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src)
+API int iotcon_representation_clone(const iotcon_representation_h src,
+ iotcon_representation_h *dest)
{
FN_CALL;
+ int ret;
GList *node;
- iotcon_repr_h dest, copied_repr;
iotcon_resource_types_h list;
+ iotcon_state_h ori_state;
+ iotcon_state_h cloned_state = NULL;
+ iotcon_representation_h cloned_repr, copied_repr;
- RETV_IF(NULL == src, NULL);
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- dest = iotcon_repr_new();
- if (NULL == dest) {
- ERR("iotcon_repr_new() Fail");
- return NULL;
+ ret = iotcon_representation_create(&cloned_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return ret;
}
if (src->uri_path) {
- dest->uri_path = strdup(src->uri_path);
- if (NULL == dest->uri_path) {
+ cloned_repr->uri_path = strdup(src->uri_path);
+ if (NULL == cloned_repr->uri_path) {
ERR("strdup() Fail");
- iotcon_repr_free(dest);
- return NULL;
+ iotcon_representation_destroy(cloned_repr);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
}
if (src->interfaces)
- dest->interfaces = src->interfaces;
+ cloned_repr->interfaces = src->interfaces;
if (src->res_types) {
- list = iotcon_resource_types_clone(src->res_types);
- if (NULL == list) {
+ ret = iotcon_resource_types_clone(src->res_types, &list);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_clone() Fail");
- iotcon_repr_free(dest);
- return NULL;
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
}
- dest->res_types = list;
+ cloned_repr->res_types = list;
}
for (node = g_list_first(src->children); node; node = node->next) {
- copied_repr = iotcon_repr_clone((iotcon_repr_h)node->data);
- if (NULL == copied_repr) {
- ERR("iotcon_repr_clone(child) Fail");
- iotcon_repr_free(dest);
- return NULL;
+ ret = iotcon_representation_clone((iotcon_representation_h)node->data,
+ &copied_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_clone(child) Fail(%d)", ret);
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
}
- dest->children = g_list_append(dest->children, copied_repr);
+ cloned_repr->children = g_list_append(cloned_repr->children, copied_repr);
}
- g_hash_table_foreach(src->hash_table, (GHFunc)_icl_repr_obj_clone, dest);
+ ori_state = src->state;
+ if (ori_state->hash_table) {
+ g_hash_table_foreach(ori_state->hash_table, (GHFunc)icl_state_clone,
+ cloned_state);
+ ret = iotcon_representation_set_state(cloned_repr, cloned_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail");
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
+ }
+ }
- return dest;
+ *dest = cloned_repr;
+
+ return IOTCON_ERROR_NONE;
}
#include <glib.h>
#include "iotcon-struct.h"
+#include "icl-repr-value.h"
-struct icl_repr_s {
+struct icl_representation_s {
char *uri_path;
int ref_count;
int interfaces;
int visibility;
- GHashTable *hash_table;
GList *children;
iotcon_resource_types_h res_types;
+ struct icl_state_s *state;
+};
+
+struct icl_state_s {
+ int ref_count;
+ GHashTable *hash_table;
};
-void icl_repr_inc_ref_count(iotcon_repr_h val);
+void icl_representation_inc_ref_count(iotcon_representation_h val);
+
+void icl_state_clone(char *key, iotcon_value_h src_val, iotcon_state_h dest_state);
#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */
/* The content of the request should not be freed by user. */
-API int iotcon_request_get_representation(iotcon_request_h request, iotcon_repr_h *repr)
+API int iotcon_request_get_representation(iotcon_request_h request,
+ iotcon_representation_h *repr)
{
RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
API int iotcon_request_get_observer_action(iotcon_request_h request,
- iotcon_observe_action_e *action)
+ int *action)
{
RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == action, IOTCON_ERROR_INVALID_PARAMETER);
iotcon_options_h header_options;
iotcon_query_h query;
struct icl_observe_info observation_info;
- iotcon_repr_h repr;
+ iotcon_representation_h repr;
int64_t oic_request_h;
int64_t oic_resource_h;
};
}
-API iotcon_resource_types_h iotcon_resource_types_new()
+API int iotcon_resource_types_create(iotcon_resource_types_h *ret_types)
{
iotcon_resource_types_h types = calloc(1, sizeof(struct icl_resource_types));
if (NULL == types) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
types->ref_count = 1;
- return types;
+ *ret_types = types;
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_resource_types_free(iotcon_resource_types_h types)
+API void iotcon_resource_types_destroy(iotcon_resource_types_h types)
{
RET_IF(NULL == types);
RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
"Don't modify it. It is already set.");
- if (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(type)) {
+ if (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(type)) {
ERR("The length of type(%s) should be less than or equal to %d.", type,
- IOTCON_RESOURCE_TYPE_LENGTH_MAX);
+ ICL_RESOURCE_TYPE_LENGTH_MAX);
return IOTCON_ERROR_INVALID_PARAMETER;
}
API int iotcon_resource_types_foreach(iotcon_resource_types_h types,
- iotcon_resource_types_foreach_fn fn, void *user_data)
+ iotcon_resource_types_foreach_cb cb, void *user_data)
{
GList *node;
RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
for (node = types->type_list; node; node = node->next) {
- if (IOTCON_FUNC_STOP == fn((const char*)node->data, user_data))
+ if (IOTCON_FUNC_STOP == cb((const char*)node->data, user_data))
break;
}
}
-API iotcon_resource_types_h iotcon_resource_types_clone(iotcon_resource_types_h types)
+API int iotcon_resource_types_clone(iotcon_resource_types_h src,
+ iotcon_resource_types_h *dest)
{
GList *node;
char *resource_type;
- iotcon_resource_types_h clone;
+ iotcon_resource_types_h resource_types;
- RETV_IF(NULL == types, NULL);
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- clone = calloc(1, sizeof(struct icl_resource_types));
- if (NULL == clone) {
+ resource_types = calloc(1, sizeof(struct icl_resource_types));
+ if (NULL == resource_types) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
- for (node = types->type_list; node; node = node->next) {
+ for (node = src->type_list; node; node = node->next) {
resource_type = ic_utils_strdup(node->data);
if (NULL == resource_type) {
- iotcon_resource_types_free(clone);
+ iotcon_resource_types_destroy(resource_types);
ERR("ic_utils_strdup() Fail");
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
- clone->type_list = g_list_append(clone->type_list, resource_type);
+ resource_types->type_list = g_list_append(resource_types->type_list,
+ resource_type);
}
- clone->ref_count = 1;
+ resource_types->ref_count = 1;
+
+ *dest = resource_types;
- return clone;
+ return IOTCON_ERROR_NONE;
}
*
* @since_tizen 3.0
*/
-#define IOTCON_RESOURCE_TYPE_LENGTH_MAX (IOTCON_QUERY_LENGTH_MAX - 3)
+#define ICL_RESOURCE_TYPE_LENGTH_MAX (ICL_QUERY_LENGTH_MAX - 3)
struct icl_resource_types {
#include "iotcon.h"
#include "ic-utils.h"
-#include "icl-resource-types.h"
-#include "icl-resource.h"
-#include "icl-request.h"
+#include "icl.h"
#include "icl-repr.h"
#include "icl-dbus.h"
+#include "icl-request.h"
#include "icl-dbus-type.h"
-#include "icl.h"
+#include "icl-resource-types.h"
+#include "icl-resource.h"
#include "icl-payload.h"
/**
*
* @since_tizen 3.0
*/
-#define IOTCON_URI_PATH_LENGTH_MAX 36
+#define ICL_URI_PATH_LENGTH_MAX 36
static void _icl_request_handler(GDBusConnection *connection,
gpointer user_data)
{
FN_CALL;
- GVariantIter *options;
- unsigned short option_id;
+ int ret;
+ char *key = NULL;
char *option_data;
+ char *value = NULL;
+ GVariant *repr_gvar;
GVariantIter *query;
+ GVariantIter *options;
GVariantIter *repr_iter;
- char *key = NULL;
- char *value = NULL;
+ unsigned short option_id;
struct icl_resource_request request = {0};
iotcon_resource_h resource = user_data;
iotcon_request_handler_cb cb = resource->cb;
- GVariant *repr_gvar;
g_variant_get(parameters, "(ia(qs)a(ss)iiavxx)",
&request.types,
&request.oic_resource_h);
if (g_variant_iter_n_children(options)) {
- request.header_options = iotcon_options_new();
+ ret = iotcon_options_create(&request.header_options);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_create() Fail(%d)", ret);
+ g_variant_iter_free(options);
+ g_variant_iter_free(query);
+ g_variant_iter_free(repr_iter);
+ return;
+ }
+
while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
iotcon_options_insert(request.header_options, option_id, option_data);
}
g_variant_iter_free(options);
if (g_variant_iter_n_children(query)) {
- request.query = iotcon_query_new();
+ ret = iotcon_query_create(&request.query);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_query_create() Fail(%d)", ret);
+ g_variant_iter_free(query);
+ g_variant_iter_free(repr_iter);
+ return;
+ }
+
while (g_variant_iter_loop(query, "(&s&s)", &key, &value))
iotcon_query_insert(request.query, key, value);
}
g_variant_iter_free(query);
if (g_variant_iter_loop(repr_iter, "v", &repr_gvar)) {
- request.repr = icl_repr_from_gvariant(repr_gvar);
+ request.repr = icl_representation_from_gvariant(repr_gvar);
if (NULL == request.repr) {
- ERR("icl_repr_create_repr() Fail");
+ ERR("icl_representation_from_gvariant() Fail");
if (request.query)
- iotcon_query_free(request.query);
+ iotcon_query_destroy(request.query);
if (request.header_options)
- iotcon_options_free(request.header_options);
+ iotcon_options_destroy(request.header_options);
return;
}
}
+ g_variant_iter_free(repr_iter);
/* TODO remove request.uri */
request.uri_path = "temp_uri_path";
if (cb)
cb(resource, &request, resource->user_data);
- /* To avoid unnecessary ERR log (repr could be NULL) */
+ /* To avoid unnecessary ERR log (representation could be NULL) */
if (request.repr)
- iotcon_repr_free(request.repr);
+ iotcon_representation_destroy(request.repr);
if (request.query)
- iotcon_query_free(request.query);
+ iotcon_query_destroy(request.query);
if (request.header_options)
- iotcon_options_free(request.header_options);
+ iotcon_options_destroy(request.header_options);
}
return;
}
- iotcon_resource_types_free(resource->types);
+ iotcon_resource_types_destroy(resource->types);
free(resource->uri_path);
free(resource);
}
/* The length of uri_path should be less than or equal to 36. */
-API iotcon_resource_h iotcon_register_resource(const char *uri_path,
+API int iotcon_register_resource(const char *uri_path,
iotcon_resource_types_h res_types,
int ifaces,
uint8_t properties,
iotcon_request_handler_cb cb,
- void *user_data)
+ void *user_data,
+ iotcon_resource_h *resource_handle)
{
int signal_number;
unsigned int sub_id;
char sig_name[IC_DBUS_SIGNAL_LENGTH];
iotcon_resource_h resource;
- RETV_IF(NULL == icl_dbus_get_object(), NULL);
- RETV_IF(NULL == uri_path, NULL);
- RETVM_IF(IOTCON_URI_PATH_LENGTH_MAX < strlen(uri_path), NULL, "Invalid uri_path(%s)",
- uri_path);
- RETV_IF(NULL == res_types, NULL);
- RETV_IF(NULL == cb, NULL);
+ RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(ICL_URI_PATH_LENGTH_MAX < strlen(uri_path),
+ IOTCON_ERROR_INVALID_PARAMETER, "Invalid uri_path(%s)", uri_path);
+ RETV_IF(NULL == res_types, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
resource = calloc(1, sizeof(struct icl_resource));
if (NULL == resource) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
types = icl_dbus_resource_types_to_array(res_types);
if (NULL == types) {
ERR("icl_dbus_resource_types_to_array() Fail");
free(resource);
- return NULL;
+ return IOTCON_ERROR_INVALID_PARAMETER;
}
signal_number = icl_dbus_generate_signal_number();
g_error_free(error);
free(types);
free(resource);
- return NULL;
+ return IOTCON_ERROR_DBUS;
}
free(types);
if (0 == resource->handle) {
ERR("iotcon-daemon Fail");
free(resource);
- return NULL;
+ return IOTCON_ERROR_IOTIVITY;
}
resource->cb = cb;
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
free(resource);
- return NULL;
+ return IOTCON_ERROR_DBUS;
}
resource->sub_id = sub_id;
- return resource;
+ *resource_handle = resource;
+
+ return IOTCON_ERROR_NONE;
}
if (0 == resource->sub_id) {
WARN("Invalid Resource handle");
- iotcon_resource_types_free(resource->types);
+ iotcon_resource_types_destroy(resource->types);
free(resource->uri_path);
free(resource);
return IOTCON_ERROR_NONE;
}
-API int iotcon_bind_interface(iotcon_resource_h resource, iotcon_interface_e iface)
+API int iotcon_resource_bind_interface(iotcon_resource_h resource, int iface)
{
FN_CALL;
int ret;
}
-API int iotcon_bind_type(iotcon_resource_h resource, const char *resource_type)
+API int iotcon_resource_bind_type(iotcon_resource_h resource, const char *resource_type)
{
FN_CALL;
int ret;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER);
- if (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type)) {
+ if (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type)) {
ERR("Invalid resource_type(%s)", resource_type);
return IOTCON_ERROR_INVALID_PARAMETER;
}
}
-API int iotcon_bind_request_handler(iotcon_resource_h resource,
+API int iotcon_resource_bind_request_handler(iotcon_resource_h resource,
iotcon_request_handler_cb cb)
{
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
}
-API int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child)
+API int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
+ iotcon_resource_h child)
{
FN_CALL;
int ret;
return IOTCON_ERROR_INVALID_PARAMETER;
}
- for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+ for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
if (child == parent->children[i]) {
ERR("Child resource was already bound to parent resource.");
return IOTCON_ERROR_ALREADY;
}
}
- for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+ for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
if (NULL == parent->children[i]) {
ic_dbus_call_bind_resource_sync(icl_dbus_get_object(), parent->handle,
child->handle, &ret, NULL, &error);
}
-API int iotcon_unbind_resource(iotcon_resource_h parent, iotcon_resource_h child)
+API int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
+ iotcon_resource_h child)
{
int ret;
int i;
return icl_dbus_convert_daemon_error(ret);
}
- for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+ for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
if (child == parent->children[i])
parent->children[i] = NULL;
}
RETV_IF(NULL == number, IOTCON_ERROR_INVALID_PARAMETER);
*number = 0;
- for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+ for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
if (resource->children[i])
*number += 1;
}
{
RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
- if ((index < 0) || (IOTCON_CONTAINED_RESOURCES_MAX <= index)) {
+ if ((index < 0) || (ICL_CONTAINED_RESOURCES_MAX <= index)) {
ERR("Invalid index(%d)", index);
return IOTCON_ERROR_INVALID_PARAMETER;
}
}
-API iotcon_notimsg_h iotcon_notimsg_new(iotcon_repr_h repr, iotcon_interface_e iface)
+API int iotcon_notimsg_create(iotcon_representation_h repr, int iface,
+ iotcon_notimsg_h *notimsg_handle)
{
iotcon_notimsg_h msg;
- RETV_IF(NULL == repr, NULL);
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
msg = calloc(1, sizeof(struct icl_notify_msg));
if (NULL == msg) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
msg->repr = repr;
- icl_repr_inc_ref_count(msg->repr);
+ icl_representation_inc_ref_count(msg->repr);
msg->iface = iface;
msg->error_code = 200;
- return msg;
+ *notimsg_handle = msg;
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_notimsg_free(iotcon_notimsg_h msg)
+API void iotcon_notimsg_destroy(iotcon_notimsg_h msg)
{
RET_IF(NULL == msg);
- iotcon_repr_free(msg->repr);
+ iotcon_representation_destroy(msg->repr);
free(msg);
}
}
-API int iotcon_notify_all(iotcon_resource_h resource)
+API int iotcon_resource_notify_all(iotcon_resource_h resource)
{
int ret;
GError *error = NULL;
*
* @since_tizen 3.0
*/
-#define IOTCON_CONTAINED_RESOURCES_MAX 5
+#define ICL_CONTAINED_RESOURCES_MAX 5
struct icl_notify_msg {
int error_code;
iotcon_interface_e iface;
- iotcon_repr_h repr;
+ iotcon_representation_h repr;
};
struct icl_resource {
void *user_data;
unsigned int sub_id;
int64_t handle;
- iotcon_resource_h children[IOTCON_CONTAINED_RESOURCES_MAX];
+ iotcon_resource_h children[ICL_CONTAINED_RESOURCES_MAX];
};
#endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_H__*/
#include "icl-request.h"
#include "icl-response.h"
-API iotcon_response_h iotcon_response_new(iotcon_request_h request_h)
+/* the last index of iotcon_response_result_e */
+#define ICL_RESPONSE_RESULT_MAX (IOTCON_RESPONSE_RESULT_FORBIDDEN + 1)
+
+API int iotcon_response_create(iotcon_request_h request,
+ iotcon_response_h *response)
{
FN_CALL;
- RETV_IF(NULL == request_h, NULL);
+ RETV_IF(NULL == request, TIZEN_ERROR_INVALID_PARAMETER);
iotcon_response_h resp = calloc(1, sizeof(struct icl_resource_response));
if (NULL == resp) {
ERR("calloc() Fail(%d)", errno);
- return NULL;
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
- resp->oic_request_h = request_h->oic_request_h;
- resp->oic_resource_h = request_h->oic_resource_h;
+ resp->oic_request_h = request->oic_request_h;
+ resp->oic_resource_h = request->oic_resource_h;
resp->error_code = 200;
- return resp;
+ *response = resp;
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_response_free(iotcon_response_h resp)
+API void iotcon_response_destroy(iotcon_response_h resp)
{
RET_IF(NULL == resp);
if (resp->repr)
- iotcon_repr_free(resp->repr);
+ iotcon_representation_destroy(resp->repr);
if (resp->new_uri_path)
free(resp->new_uri_path);
if (resp->header_options)
- iotcon_options_free(resp->header_options);
+ iotcon_options_destroy(resp->header_options);
free(resp);
}
-API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop, ...)
+API int iotcon_response_set_new_uri_path(iotcon_response_h resp, char *new_uri_path)
{
- int value;
- va_list args;
- char *new_uri_path = NULL;
- iotcon_options_h options = NULL;
+ RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
- va_start(args, prop);
+ if (resp->new_uri_path)
+ free(resp->new_uri_path);
- switch (prop) {
- case IOTCON_RESPONSE_INTERFACE:
- resp->iface = va_arg(args, int);
- break;
- case IOTCON_RESPONSE_REPRESENTATION:
- resp->repr = va_arg(args, iotcon_repr_h);
- icl_repr_inc_ref_count(resp->repr);
- break;
- case IOTCON_RESPONSE_RESULT:
- value = va_arg(args, int);
- if (value < IOTCON_RESPONSE_RESULT_OK || IOTCON_RESPONSE_RESULT_MAX <= value) {
- ERR("Invalid value(%d)", value);
- va_end(args);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- resp->result = value;
- break;
- case IOTCON_RESPONSE_NEW_URI_PATH:
- new_uri_path = va_arg(args, char*);
- if (resp->new_uri_path)
- free(resp->new_uri_path);
-
- if (new_uri_path) {
- resp->new_uri_path = strdup(new_uri_path);
- if (NULL == resp->new_uri_path) {
- ERR("strdup() Fail(%d)", errno);
- va_end(args);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- } else {
- resp->new_uri_path = NULL;
+ if (new_uri_path) {
+ resp->new_uri_path = strdup(new_uri_path);
+ if (NULL == resp->new_uri_path) {
+ ERR("strdup() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
- break;
- case IOTCON_RESPONSE_HEADER_OPTIONS:
- options = va_arg(args, iotcon_options_h);
- if (resp->header_options)
- iotcon_options_free(resp->header_options);
-
- if (options)
- resp->header_options = icl_options_ref(options);
- else
- resp->header_options = NULL;
- break;
- default:
- ERR("Invalid Response Property(%d)", prop);
- break;
+ } else {
+ resp->new_uri_path = NULL;
}
- va_end(args);
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_response_set_result(iotcon_response_h resp, int result)
+{
+ RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (result < IOTCON_RESPONSE_RESULT_OK || ICL_RESPONSE_RESULT_MAX <= result) {
+ ERR("Invalid result(%d)", result);
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+ resp->result = result;
return IOTCON_ERROR_NONE;
}
-static bool _icl_response_repr_child_fn(iotcon_repr_h child, void *user_data)
+API int iotcon_response_set_representation(iotcon_response_h resp,
+ iotcon_representation_h repr)
+{
+ RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ resp->repr = repr;
+ icl_representation_inc_ref_count(resp->repr);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_response_set_header_options(iotcon_response_h resp,
+ iotcon_options_h options)
+{
+ RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (resp->header_options)
+ iotcon_options_destroy(resp->header_options);
+
+ if (options)
+ resp->header_options = icl_options_ref(options);
+ else
+ resp->header_options = NULL;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_response_set_interface(iotcon_response_h resp, int iface)
+{
+ RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+
+ resp->iface = iface;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static bool _icl_response_representation_child_cb(iotcon_representation_h child,
+ void *user_data)
{
int iface = GPOINTER_TO_INT(user_data);
}
-static int _icl_response_check_repr_visibility(iotcon_response_h resp)
+static int _icl_response_check_representation_visibility(iotcon_response_h resp)
{
int ret;
RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resp->repr, IOTCON_ERROR_INVALID_PARAMETER);
- iotcon_repr_h first = resp->repr;
+ iotcon_representation_h first = resp->repr;
DBG("interface type of response : %d", resp->iface);
break;
}
- ret = iotcon_repr_foreach_children(first, _icl_response_repr_child_fn,
- GINT_TO_POINTER(resp->iface));
+ ret = iotcon_representation_foreach_children(first,
+ _icl_response_representation_child_cb, GINT_TO_POINTER(resp->iface));
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_repr_foreach_children() Fail(%d)", ret);
+ ERR("iotcon_representation_foreach_children() Fail(%d)", ret);
return ret;
}
API int iotcon_response_send(iotcon_response_h resp)
{
FN_CALL;
- int ret = 0;
+ int ret;
GError *error = NULL;
GVariant *arg_response;
RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resp->repr, IOTCON_ERROR_INVALID_PARAMETER);
- ret = _icl_response_check_repr_visibility(resp);
+ ret = _icl_response_check_representation_visibility(resp);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_response_check_repr_visibility() Fail(%d)", ret);
+ ERR("_icl_response_check_representation_visibility() Fail(%d)", ret);
return ret;
}
iotcon_options_h header_options;
iotcon_interface_e iface;
iotcon_response_result_e result;
- iotcon_repr_h repr;
+ iotcon_representation_h repr;
int64_t oic_request_h;
int64_t oic_resource_h;
};
#include "icl.h"
#include "icl-dbus.h"
-API int iotcon_open()
+API int iotcon_open(void)
{
int ret;
}
-API void iotcon_close()
+API int iotcon_close(void)
{
int ret;
ret = icl_dbus_stop();
if (IOTCON_ERROR_NONE != ret)
ERR("icl_dbus_stop() Fail(%d)", ret);
+
+ return ret;
}
IOTCON_RESPONSE_RESULT_RESOURCE_DELETED, /**< Indicates result of response for resource has deleted */
IOTCON_RESPONSE_RESULT_SLOW, /**< Indicates result of response for slow resource */
IOTCON_RESPONSE_RESULT_FORBIDDEN, /**< Indicates result of response for accessing unauthorized resource */
- IOTCON_RESPONSE_RESULT_MAX
} iotcon_response_result_e;
/**
IOTCON_TYPE_STR, /**< Indicates for representation that have string type */
IOTCON_TYPE_NULL, /**< Indicates for representation that have null type */
IOTCON_TYPE_LIST, /**< Indicates for representation that have list type */
- IOTCON_TYPE_REPR, /**< Indicates for representation that have another representation type */
+ IOTCON_TYPE_STATE, /**< Indicates for representation that have another representation type */
} iotcon_types_e;
/**
*/
typedef enum
{
- IOTCON_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful*/
+ IOTCON_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ IOTCON_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
IOTCON_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ IOTCON_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ IOTCON_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
IOTCON_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
IOTCON_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */
- IOTCON_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Daemon operation error */
IOTCON_ERROR_IOTIVITY = TIZEN_ERROR_IOTCON | 0x01, /**< Iotivity errors */
IOTCON_ERROR_REPRESENTATION = TIZEN_ERROR_IOTCON | 0x02, /**< Representation errors */
IOTCON_ERROR_INVALID_TYPE = TIZEN_ERROR_IOTCON | 0x03, /**< Invalid type */
*
* @since_tizen 3.0
*
- * @return A newly allocated representation handle, otherwise NULL on failure.
- * @retval iotcon_repr_h Success
- * @retval NULL Failure
+ * @param[out] repr A newly allocated representation handle
*
- * @see iotcon_repr_free()
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_representation_destroy()
*/
-iotcon_repr_h iotcon_repr_new();
+int iotcon_representation_create(iotcon_representation_h *ret_repr);
/**
* @brief Frees a representation.
- * @details Releases a @a repr and its internal data.
+ * @details Releases a @a representation and its internal data.
*
* @since_tizen 3.0
*
*
* @return void
*
- * @see iotcon_repr_new()
+ * @see iotcon_representation_create()
*/
-void iotcon_repr_free(iotcon_repr_h repr);
+void iotcon_representation_destroy(iotcon_representation_h repr);
/**
* @brief Clones from the source representation.
* @since_tizen 3.0
*
* @param[in] src Source of representation to be copied
+ * @param[out] dest Clone of a source representation
*
* @return Clone of a source representation, otherwise NULL on failure
- * @retval iotcon_repr_h Success
+ * @retval iotcon_representation_h Success
* @retval NULL Failure
*/
-iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src);
+int iotcon_representation_clone(const iotcon_representation_h src, iotcon_representation_h *dest);
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_uri_path(iotcon_repr_h repr, const char *uri_path);
+int iotcon_representation_set_uri_path(iotcon_representation_h repr, const char *uri_path);
/**
* @brief Gets an URI path from the representation.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_get_uri_path(iotcon_repr_h repr, const char **uri_path);
+int iotcon_representation_get_uri_path(iotcon_representation_h repr, const char **uri_path);
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_resource_types_h types);
+int iotcon_representation_set_resource_types(iotcon_representation_h repr, iotcon_resource_types_h types);
/**
* @brief Gets list of resource type from the representation.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resource_types_h *types);
+int iotcon_representation_get_resource_types(iotcon_representation_h repr, iotcon_resource_types_h *types);
/**
* @brief Sets interfaces to the representation.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces);
+int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr, int ifaces);
/**
* @brief Gets resource interfaces from the representation.
* @since_tizen 3.0
*
* @param[in] repr The representation handle
+ * @param[out] ifaces The interfaces to get
*
* @return Interfaces to get. Interfaces may contain multiple interfaces.
* @retval #IOTCON_INTERFACE_NONE Not set
* @retval Bitwise OR value which consists of iotcon_interface_e items
*/
-int iotcon_repr_get_resource_interfaces(iotcon_repr_h repr);
+int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr, int *ifaces);
+
+/**
+ * @brief Sets a new state handle into the representation.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] repr The representation handle
+ * @param[in] state The state handle to set newly
+ *
+ * @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
+ */
+int iotcon_representation_set_state(iotcon_representation_h repr, iotcon_state_h state);
+
+/**
+ * @brief Gets a state handle in the representation.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] repr The representation handle
+ * @param[in] state The state handle to get
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_representation_get_state(iotcon_representation_h repr, iotcon_state_h *state);
+
+/**
+ * @brief Deletes state handle in the representation.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] repr The representation handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_representation_del_state(iotcon_representation_h repr);
+
+/**
+ * @brief Creates a new state handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[out] state A newly allocated 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
+ *
+ * @see iotcon_state_destroy()
+ */
+int iotcon_state_create(iotcon_state_h *ret_state);
+
+/**
+ * @brief Frees a state.
+ * @details Releases a @a state and its internal data.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] state The state handle to free
+ *
+ * @return void
+ *
+ * @see iotcon_state_create()
+ */
+void iotcon_state_destroy(iotcon_state_h state);
/**
* @brief Sets a new key and integer value into the representation.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[in] val The value
*
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_int(iotcon_repr_h repr, const char *key, int val);
+int iotcon_state_set_int(iotcon_state_h state, const char *key, int val);
/**
* @brief Sets a new key and boolean value into the representation.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[in] val The value
*
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_bool(iotcon_repr_h repr, const char *key, bool val);
+int iotcon_state_set_bool(iotcon_state_h state, const char *key, bool val);
/**
* @brief Sets a new key and double value into the representation.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[in] val The value
*
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_double(iotcon_repr_h repr, const char *key, double val);
+int iotcon_state_set_double(iotcon_state_h state, const char *key, double val);
/**
* @brief Sets a new key and string value into the representation.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[in] val The value
*
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_str(iotcon_repr_h repr, const char *key, char *val);
+int iotcon_state_set_str(iotcon_state_h state, const char *key, char *val);
/**
- * @brief Sets a new key and iotcon_list_h into the representation.
+ * @brief Sets a new key and list value into the representation.
* @details If @a key is already exists, current list will be replaced with new @a list.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[in] list The value
*
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_list(iotcon_repr_h repr, const char *key, iotcon_list_h list);
+int iotcon_state_set_list(iotcon_state_h state, const char *key, iotcon_list_h list);
/**
- * @brief Sets a new key and iotcon_repr_h into the representation.
- * @details If @a key is already exists, current reprsentation will be replaced with new @a src.
+ * @brief Sets a new key and state value into the representation.
+ * @details If @a key is already exists, current state will be replaced with new @a src.
*
* @since_tizen 3.0
*
- * @param[in] dest The representation handle
+ * @param[in] dest The state handle
* @param[in] key The key
- * @param[in] src The representation handle to set newly
+ * @param[in] src The state handle to set newly
*
* @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
*/
-int iotcon_repr_set_repr(iotcon_repr_h dest, const char *key, iotcon_repr_h src);
+int iotcon_state_set_state(iotcon_state_h dest, const char *key, iotcon_state_h src);
/**
* @brief Sets a new key with NULL value into the representation.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key to be set NULL
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_set_null(iotcon_repr_h repr, const char *key);
+int iotcon_state_set_null(iotcon_state_h state, const char *key);
/**
* @brief Gets the integer value from the given key.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[out] val The integer value
*
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_get_int(iotcon_repr_h repr, const char *key, int *val);
+int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val);
/**
* @brief Gets the boolean value from the given key.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[out] val The boolean value
*
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_get_bool(iotcon_repr_h repr, const char *key, bool *val);
+int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val);
/**
* @brief Gets the double value from the given key.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[out] val The double value
*
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_get_double(iotcon_repr_h repr, const char *key, double *val);
+int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val);
/**
* @brief Gets the string value from the given key.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[out] val The string value
*
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_get_str(iotcon_repr_h repr, const char *key, char **val);
+int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val);
/**
* @brief Gets the list value from the given key.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[out] list The list value
*
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_get_list(iotcon_repr_h repr, const char *key, iotcon_list_h *list);
+int iotcon_state_get_list(iotcon_state_h state, const char *key, iotcon_list_h *list);
/**
- * @brief Gets the representation value from the given key.
+ * @brief Gets the state value from the given key.
*
* @since_tizen 3.0
*
- * @param[in] src The representation handle
+ * @param[in] src The state handle
* @param[in] key The key
- * @param[out] dest The representation value at the key
+ * @param[out] dest The state value at the key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_get_repr(iotcon_repr_h src, const char *key, iotcon_repr_h *dest);
+int iotcon_state_get_state(iotcon_state_h src, const char *key, iotcon_state_h *dest);
/**
* @brief Checks whether the value of given key is NULL or not.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
+ * @param[out] is_null true if the type of the given key is null, otherwise false
*
- * @return true if the type of the given key is null, otherwise false.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-bool iotcon_repr_is_null(iotcon_repr_h repr, const char *key);
+int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null);
/**
- * @brief Deletes the key and its associated integer value from the representation.
+ * @brief Deletes the key and its associated integer value from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_int(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_int(iotcon_state_h state, const char *key);
/**
- * @brief Deletes the key and its associated boolean value from the representation.
+ * @brief Deletes the key and its associated boolean value from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_bool(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_bool(iotcon_state_h state, const char *key);
/**
- * @brief Deletes the key and its associated double value from the representation.
+ * @brief Deletes the key and its associated double value from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_double(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_double(iotcon_state_h state, const char *key);
/**
- * @brief Deletes the key and its associated string value from the representation.
+ * @brief Deletes the key and its associated string value from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_str(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_str(iotcon_state_h state, const char *key);
/**
- * @brief Deletes the key and its associated list value from the representation.
+ * @brief Deletes the key and its associated list value from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_list(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_list(iotcon_state_h state, const char *key);
/**
- * @brief Deletes the key and its associated representation value from the representation.
+ * @brief Deletes the key and its associated state value from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_repr(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_state(iotcon_state_h state, const char *key);
/**
- * @brief Deletes the key from the representation.
+ * @brief Deletes the key from the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_repr_del_null(iotcon_repr_h repr, const char *key);
+int iotcon_state_del_null(iotcon_state_h state, const char *key);
/**
* @brief Gets the type of a value at the given key.
+ * @details It gets the data type of value related the @a key in @a state.
+ * The data type could be one of #iotcon_types_e.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
- * @param[out] type The type
+ * @param[out] type The data type of value related the key in state handle.
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_NO_DATA No data available
*/
-int iotcon_repr_get_type(iotcon_repr_h repr, const char *key, int *type);
+int iotcon_state_get_type(iotcon_state_h state, const char *key, int *type);
/**
* @brief Appends a new child representation on to the end of the parent representation
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_repr_append_child(iotcon_repr_h parent, iotcon_repr_h child);
+int iotcon_representation_append_child(iotcon_representation_h parent,
+ iotcon_representation_h child);
+
+/**
+ * @brief Removes a child representation from parent representation without freeing.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] parent The parent representation handle
+ * @param[in] child The child representation handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_representation_remove_child(iotcon_representation_h parent,
+ iotcon_representation_h child);
/**
- * @brief Specifies the type of function passed to iotcon_repr_foreach_children()
+ * @brief Specifies the type of function passed to iotcon_representation_foreach_children()
*
* @since_tizen 3.0
*
* @retval #IOTCON_FUNC_CONTINUE Continue to iterate next child representation
* @retval #IOTCON_FUNC_STOP Stop to iterate children representation
*
- * @pre iotcon_repr_foreach_children() will invoke this callback function.
+ * @pre iotcon_representation_foreach_children() will invoke this callback function.
*
- * @see iotcon_repr_foreach_children()
+ * @see iotcon_representation_foreach_children()
*
*/
-typedef bool (*iotcon_children_fn)(iotcon_repr_h child, void *user_data);
+typedef bool (*iotcon_children_cb)(iotcon_representation_h child, void *user_data);
/**
* @brief Call a function for each children representation of parent.
- * @details iotcon_children_fn() will be called for each child.
+ * @details iotcon_children_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] parent The parent representation handle
- * @param[in] fn The callback function to invoke
+ * @param[in] cb The callback function to invoke
* @param[in] user_data The user data to pass to the function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_children_fn() will be called for each child.
+ * @post iotcon_children_cb() will be called for each child.
*
- * @see iotcon_children_fn()
+ * @see iotcon_children_cb()
*/
-int iotcon_repr_foreach_children(iotcon_repr_h parent, iotcon_children_fn fn,
+int iotcon_representation_foreach_children(iotcon_representation_h parent, iotcon_children_cb cb,
void *user_data);
/**
* @since_tizen 3.0
*
* @param[in] parent The parent representation handle
+ * @param[out] count The number of children representation
*
- * @return the number of children representation, otherwise 0 on failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-unsigned int iotcon_repr_get_children_count(iotcon_repr_h parent);
+int iotcon_representation_get_children_count(iotcon_representation_h parent, unsigned int *count);
/**
* @brief Gets the child representation at the given position.
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_NO_DATA No data available
*/
-int iotcon_repr_get_nth_child(iotcon_repr_h parent, int pos, iotcon_repr_h *child);
+int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos, iotcon_representation_h *child);
/**
- * @brief Specifies the type of function passed to iotcon_repr_foreach()
+ * @brief Specifies the type of function passed to iotcon_state_foreach()
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
* @param[in] key The key
* @param[in] user_data The user data to pass to the function
*
* @retval #IOTCON_FUNC_CONTINUE Continue to iterate next key
* @retval #IOTCON_FUNC_STOP Stop to iterate key
*
- * @pre iotcon_repr_foreach() will invoke this callback function.
+ * @pre iotcon_state_foreach() will invoke this callback function.
*
- * @see iotcon_repr_foreach_keys()
+ * @see iotcon_state_foreach()
*/
-typedef int (*iotcon_repr_fn)(iotcon_repr_h repr, const char *key, void *user_data);
+typedef int (*iotcon_state_cb)(iotcon_state_h state, const char *key, void *user_data);
/**
- * @brief Call a function for each element of representation.
- * @details iotcon_repr_fn() will be called for each child.
+ * @brief Call a function for each element of state.
+ * @details iotcon_state_cb() will be called for each child.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
- * @param[in] fn The callback function to invoke
+ * @param[in] state The state handle
+ * @param[in] cb The callback function to invoke
* @param[in] user_data The user data to pass to the function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_repr_fn() will be called for each child.
+ * @post iotcon_state_cb() will be called for each child.
*
- * @see iotcon_repr_fn()
+ * @see iotcon_state_cb()
*/
-int iotcon_repr_foreach(iotcon_repr_h repr, iotcon_repr_fn fn, void *user_data);
+int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data);
/**
- * @brief Gets the number of keys in the parent representation.
+ * @brief Gets the number of keys in the state.
*
* @since_tizen 3.0
*
- * @param[in] repr The representation handle
+ * @param[in] state The state handle
+ * @param[out] count The number of keys
*
- * @return the number of keys, otherwise 0 on failure.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-unsigned int iotcon_repr_get_keys_count(iotcon_repr_h repr);
+int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count);
/**
* @brief Creates a new list handle.
* @since_tizen 3.0
*
* @param[in] type The type of list
+ * @param[out] list A newly allocated list handle
*
* @return A newly allocated list handle, otherwise NULL on failure.
* @retval iotcon_list_h Success
* @retval NULL Failure
*/
-iotcon_list_h iotcon_list_new(iotcon_types_e type);
+int iotcon_list_create(iotcon_types_e type, iotcon_list_h *list);
/**
* @brief Frees a list handle.
*
* @return void
*/
-void iotcon_list_free(iotcon_list_h list);
+void iotcon_list_destroy(iotcon_list_h list);
/**
* @brief Inserts a new element integer value into the list at the given position.
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new value
+ * @param[in] val The new integer value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new value
+ * @param[in] val The new boolean value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new value
+ * @param[in] val The new double value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new value
+ * @param[in] val The new char value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new value
+ * @param[in] val The new list value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
int iotcon_list_insert_list(iotcon_list_h list, iotcon_list_h val, int pos);
/**
- * @brief Inserts a new element representation value into the list at the given position.
+ * @brief Inserts a new element state value into the list at the given position.
* @details If @a pos is negative, or is larger than the number of elements in the list,
* the new value is added on to the end of the list.
*
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new value
+ * @param[in] val The new state value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_list_insert_repr(iotcon_list_h list, iotcon_repr_h val, int pos);
+int iotcon_list_insert_state(iotcon_list_h list, iotcon_state_h val, int pos);
/**
* @brief Gets the integer value at the given position.
int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest);
/**
- * @brief Gets the representation value at the given position.
+ * @brief Gets the state value at the given position.
* @details Iterates over the list until it reaches the @a pos-1 position.
*
* @since_tizen 3.0
*
* @param[in] list The list handle
* @param[in] pos The position
- * @param[out] repr The representation value to get
+ * @param[out] state The state value to get
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_REPRESENTATION Representation errors
*/
-int iotcon_list_get_nth_repr(iotcon_list_h list, int pos, iotcon_repr_h *repr);
+int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state);
/**
* @brief Deletes the integer value at the given position.
int iotcon_list_del_nth_list(iotcon_list_h list, int pos);
/**
- * @brief Deletes the representation value at the given position.
+ * @brief Deletes the state value at the given position.
* @details Iterates over the list until it reaches the @a pos-1 position.
*
* @since_tizen 3.0
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_list_del_nth_repr(iotcon_list_h list, int pos);
+int iotcon_list_del_nth_state(iotcon_list_h list, int pos);
/**
* @brief Gets the type of the list.
+ * @details It gets the data type of value related the @a key in @a state.
+ * The data type could be one of #iotcon_types_e.
*
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[out] type The type
+ * @param[out] type The data type of list.
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @since_tizen 3.0
*
* @param[in] list The handle to the list
+ * @param[out] length The length of list
*
- * @return the length of list, otherwise 0 on failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-unsigned int iotcon_list_get_length(iotcon_list_h list);
+int iotcon_list_get_length(iotcon_list_h list, unsigned int *length);
/**
* @brief Specifies the type of function passed to iotcon_list_foreach_int()
*
* @see iotcon_list_foreach_int()
*/
-typedef int (*iotcon_list_int_fn)(int pos, const int value, void *user_data);
+typedef int (*iotcon_list_int_cb)(int pos, const int value, void *user_data);
/**
* @brief Gets all integer values of the given list by invoking the callback function.
- * @details iotcon_list_int_fn() will be called for each child.
+ * @details iotcon_list_int_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the list
- * @param[in] fn The callback function to get each integer value
+ * @param[in] cb The callback function to get each integer value
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_int_fn() will be called for each item.
+ * @post iotcon_list_int_cb() will be called for each item.
*
- * @see iotcon_list_int_fn()
+ * @see iotcon_list_int_cb()
*/
-int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn, void *user_data);
+int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb, void *user_data);
/**
* @brief Specifies the type of function passed to iotcon_list_foreach_bool()
*
* @see iotcon_list_foreach_bool()
*/
-typedef int (*iotcon_list_bool_fn)(int pos, const bool value, void *user_data);
+typedef int (*iotcon_list_bool_cb)(int pos, const bool value, void *user_data);
/**
* @brief Gets all boolean values of the given list by invoking the callback function.
- * @details iotcon_list_bool_fn() will be called for each child.
+ * @details iotcon_list_bool_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the list
- * @param[in] fn The callback function to get each boolean value
+ * @param[in] cb The callback function to get each boolean value
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_bool_fn() will be called for each item.
+ * @post iotcon_list_bool_cb() will be called for each item.
*
- * @see iotcon_list_bool_fn()
+ * @see iotcon_list_bool_cb()
*/
-int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn, void *user_data);
+int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb, void *user_data);
/**
* @brief Specifies the type of function passed to iotcon_list_foreach_double()
*
* @see iotcon_list_foreach_double()
*/
-typedef int (*iotcon_list_double_fn)(int pos, const double value, void *user_data);
+typedef int (*iotcon_list_double_cb)(int pos, const double value, void *user_data);
/**
* @brief Gets all double values of the given list by invoking the callback function.
- * @details iotcon_list_double_fn() will be called for each child.
+ * @details iotcon_list_double_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the list
- * @param[in] fn The callback function to get each double value
+ * @param[in] cb The callback function to get each double value
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_double_fn() will be called for each item.
+ * @post iotcon_list_double_cb() will be called for each item.
*
- * @see iotcon_list_double_fn()
+ * @see iotcon_list_double_cb()
*/
-int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn,
+int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
void *user_data);
/**
*
* @see iotcon_list_foreach_str()
*/
-typedef int (*iotcon_list_str_fn)(int pos, const char *value, void *user_data);
+typedef int (*iotcon_list_str_cb)(int pos, const char *value, void *user_data);
/**
* @brief Gets all string values of the given list by invoking the callback function.
- * @details iotcon_list_str_fn() will be called for each child.
+ * @details iotcon_list_str_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the list
- * @param[in] fn The callback function to get each string value
+ * @param[in] cb The callback function to get each string value
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_str_fn() will be called for each item.
+ * @post iotcon_list_str_cb() will be called for each item.
*
- * @see iotcon_list_str_fn()
+ * @see iotcon_list_str_cb()
*/
-int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn, void *user_data);
+int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb, void *user_data);
/**
* @brief Specifies the type of function passed to iotcon_list_foreach_list()
*
* @see iotcon_list_foreach_list()
*/
-typedef int (*iotcon_list_list_fn)(int pos, iotcon_list_h value, void *user_data);
+typedef int (*iotcon_list_list_cb)(int pos, iotcon_list_h value, void *user_data);
/**
* @brief Gets all sub lists of the given list by invoking the callback function.
- * @details iotcon_list_list_fn() will be called for each child.
+ * @details iotcon_list_list_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the origin list
- * @param[in] fn The callback function to get each sub list
+ * @param[in] cb The callback function to get each sub list
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_list_fn() will be called for each item.
+ * @post iotcon_list_list_cb() will be called for each item.
*
- * @see iotcon_list_list_fn()
+ * @see iotcon_list_list_cb()
*/
-int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_fn fn, void *user_data);
+int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb, void *user_data);
/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_repr()
+ * @brief Specifies the type of function passed to iotcon_list_foreach_state()
*
* @since_tizen 3.0
*
- * @param[in] pos The number of the representation value (0 being the first)
- * @param[in] value The representation value
+ * @param[in] pos The number of the state value (0 being the first)
+ * @param[in] value The state value
* @param[in] user_data The user data to pass to the function
*
* @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop,
* @retval #IOTCON_FUNC_STOP stop to call next function
* @retval #IOTCON_FUNC_CONTINUE continue to call next function
*
- * @pre iotcon_list_foreach_repr() will invoke this callback function.
+ * @pre iotcon_list_foreach_state() will invoke this callback function.
*
- * @see iotcon_list_foreach_repr()
+ * @see iotcon_list_foreach_state()
*/
-typedef int (*iotcon_list_repr_fn)(int pos, iotcon_repr_h value, void *user_data);
+typedef int (*iotcon_list_state_cb)(int pos, iotcon_state_h value, void *user_data);
/**
- * @brief Gets all representations of the given list by invoking the callback function.
- * @details iotcon_list_repr_fn() will be called for each child.
+ * @brief Gets all state of the given list by invoking the callback function.
+ * @details iotcon_list_state_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the list
- * @param[in] fn The callback function to get each representation
+ * @param[in] cb The callback function to get each state
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_repr_fn() will be called for each item.
+ * @post iotcon_list_state_cb() will be called for each item.
*
- * @see iotcon_list_repr_fn()
+ * @see iotcon_list_state_cb()
*/
-int iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data);
+int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb, void *user_data);
/**
* @}
/**
* @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
- * @brief The handle of representation value.
- * @details iotcon_value_h is an opaque data structure to have variant datatype and
- * store values along with information about the type of that value.\n
- * The range of possible values is determined by the type.\n
- * The type of iotcon_value_h should be one of them\n
- * #IOTCON_TYPE_INT\n
- * #IOTCON_TYPE_BOOL\n
- * #IOTCON_TYPE_DOUBLE\n
- * #IOTCON_TYPE_STR\n
- * #IOTCON_TYPE_NULL\n
- * #IOTCON_TYPE_LIST\n
- * #IOTCON_TYPE_REPR
+ * @brief The handle of list which is consist of iotcon_value_h type values.
+ * @details iotcon_list_h is an opaque data structure to have iotcon_value_h type values.
*
* @since_tizen 3.0
*/
-typedef struct icl_value_s* iotcon_value_h;
+typedef struct icl_list_s* iotcon_list_h;
/**
* @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
- * @brief The handle of list which is consist of iotcon_value_h type values.
- * @details iotcon_list_h is an opaque data structure to have iotcon_value_h type values.
+ * @brief The handle of representation.
+ * @details iotcon_representation_h is an opaque data structure to have uri_path, list of resource types
+ * and interfaces.\n
+ * It could contain other representation as children.\n
*
* @since_tizen 3.0
*/
-typedef struct icl_list_s* iotcon_list_h;
+typedef struct icl_representation_s* iotcon_representation_h;
/**
* @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
- * @brief The handle of representation.
- * @details iotcon_repr_h is an opaque data structure to have uri_path, list of resource types,
- * interfaces and attribute value map.\n
- * It could contain other representation as children.\n
+ * @brief The handle of state.
+ * @details iotcon_state_h is an opaque data structure to have attribute value map.\n
* Attribute value map consists of a key and a value.\n
* Datatype of the key is string and the value should be one of them\n
* #IOTCON_TYPE_INT\n
* #IOTCON_TYPE_STR\n
* #IOTCON_TYPE_NULL\n
* #IOTCON_TYPE_LIST\n
- * #IOTCON_TYPE_REPR
+ * #IOTCON_TYPE_STATE
*
* @since_tizen 3.0
*/
-typedef struct icl_repr_s* iotcon_repr_h;
+typedef struct icl_state_s* iotcon_state_h;
/**
* @brief The handle of notifications message.
*
* @since_tizen 3.0
*
- * @return A newly allocated option handle, otherwise NULL on failure.
- * @retval iotcon_options_h Success
- * @retval NULL Failure
+ * @param[out] options A newly allocated option handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
- * @see iotcon_options_free()
+ * @see iotcon_options_destroy()
* @see iotcon_options_insert()
* @see iotcon_options_delete()
* @see iotcon_options_lookup()
*/
-iotcon_options_h iotcon_options_new();
+int iotcon_options_create(iotcon_options_h *options);
/**
* @brief Free an option handle.
*
* @return void
*
- * @see iotcon_options_new()
+ * @see iotcon_options_create()
* @see iotcon_options_insert()
* @see iotcon_options_delete()
* @see iotcon_options_lookup()
*/
-void iotcon_options_free(iotcon_options_h options);
+void iotcon_options_destroy(iotcon_options_h options);
/**
* @brief Inserts a new id and a correspoding data into the options.
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_options_new()
- * @see iotcon_options_free()
+ * @see iotcon_options_create()
+ * @see iotcon_options_destroy()
* @see iotcon_options_delete()
* @see iotcon_options_lookup()
*/
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_options_new()
- * @see iotcon_options_free()
+ * @see iotcon_options_create()
+ * @see iotcon_options_destroy()
* @see iotcon_options_insert()
* @see iotcon_options_lookup()
*/
*
* @param[in] options The handle of the options
* @param[in] id The id of the option to lookup
+ * @param[out] data Found data from options
*
- * @return Found data from options on success, otherwise NULL on failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_options_new()
- * @see iotcon_options_free()
+ * @see iotcon_options_create()
+ * @see iotcon_options_destroy()
* @see iotcon_options_insert()
* @see iotcon_options_delete()
*/
-const char* iotcon_options_lookup(iotcon_options_h options, unsigned short id);
+int iotcon_options_lookup(iotcon_options_h options, unsigned short id, const char **data);
/**
* @brief Specifies the type of function passed to iotcon_options_foreach()
*
* @see iotcon_options_foreach()
*/
-typedef int (*iotcon_options_foreach_fn)(unsigned short id, const char *data,
+typedef int (*iotcon_options_foreach_cb)(unsigned short id, const char *data,
void *user_data);
/**
* @brief Gets all datas of the options by invoking the callback function.
- * @details iotcon_options_foreach_fn() will be called for each option.\n
- * If iotcon_options_foreach_fn() returns #IOTCON_FUNC_STOP, iteration will be stop.
+ * @details iotcon_options_foreach_cb() will be called for each option.\n
+ * If iotcon_options_foreach_cb() returns #IOTCON_FUNC_STOP, iteration will be stop.
*
* @since_tizen 3.0
*
* @param[in] options The handle of the options
- * @param[in] fn The callback function to get data
+ * @param[in] cb The callback function to get data
* @param[in] user_data The user data to pass to the function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_options_foreach_fn() will be called for each option.
+ * @post iotcon_options_foreach_cb() will be called for each option.
*
- * @see iotcon_options_foreach_fn()
+ * @see iotcon_options_foreach_cb()
*/
-int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_fn fn,
+int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
void *user_data);
/**
*
* @since_tizen 3.0
*
- * @return A newly allocated query handle, otherwise NULL on failure.
- * @retval iotcon_query_h Success
- * @retval NULL Failure
+ * @param[out] query A newly allocated query handle
*
- * @see iotcon_query_free()
+ * @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_query_destroy()
* @see iotcon_query_insert()
* @see iotcon_query_delete()
* @see iotcon_query_lookup()
*/
-iotcon_query_h iotcon_query_new();
+int iotcon_query_create(iotcon_query_h *query);
/**
* @brief Free a query handle.
*
* @return void
*
- * @see iotcon_query_new()
+ * @see iotcon_query_create()
* @see iotcon_query_insert()
* @see iotcon_query_delete()
* @see iotcon_query_lookup()
*/
-void iotcon_query_free(iotcon_query_h query);
+void iotcon_query_destroy(iotcon_query_h query);
/**
* @brief Inserts a new key and correspoding value into the query.
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_query_new()
- * @see iotcon_query_free()
+ * @see iotcon_query_create()
+ * @see iotcon_query_destroy()
* @see iotcon_query_delete()
* @see iotcon_query_lookup()
*/
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_query_new()
- * @see iotcon_query_free()
+ * @see iotcon_query_create()
+ * @see iotcon_query_destroy()
* @see iotcon_query_insert()
* @see iotcon_query_lookup()
*/
*
* @param[in] query The handle of the query
* @param[in] key The key of the query to lookup
+ * @param[out] data Found data from query
*
- * @return Found data from query on success, otherwise a null pointer if fail to lookup
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_query_new()
- * @see iotcon_query_free()
+ * @see iotcon_query_create()
+ * @see iotcon_query_destroy()
* @see iotcon_query_insert()
* @see iotcon_query_delete()
*/
-const char* iotcon_query_lookup(iotcon_query_h query, const char *key);
+int iotcon_query_lookup(iotcon_query_h query, const char *key, const char **data);
/**
* @brief Specifies the type of function passed to iotcon_query_foreach()
*
* @see iotcon_query_foreach()
*/
-typedef int (*iotcon_query_foreach_fn)(const char *key, const char *value,
+typedef int (*iotcon_query_foreach_cb)(const char *key, const char *value,
void *user_data);
/**
* @brief Gets all datas of the query by invoking the callback function.
- * @details iotcon_query_foreach_fn() will be called for each query.\n
- * If iotcon_query_foreach_fn() returns #IOTCON_FUNC_STOP, iteration will be stop.
+ * @details iotcon_query_foreach_cb() will be called for each query.\n
+ * If iotcon_query_foreach_cb() returns #IOTCON_FUNC_STOP, iteration will be stop.
*
* @since_tizen 3.0
*
* @param[in] query The handle of the query
- * @param[in] fn The callback function to get data
+ * @param[in] cb The callback function to get data
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_query_foreach_fn() will be called for each query.
+ * @post iotcon_query_foreach_cb() will be called for each query.
*
- * @see iotcon_query_foreach_fn()
+ * @see iotcon_query_foreach_cb()
*/
-int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_fn fn,
+int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
void *user_data);
/**
*
* @since_tizen 3.0
*
- * @return A newly allocated list of resource types handle, otherwise NULL on failure.
- * @retval iotcon_resource_types_h Success
- * @retval NULL Failure
+ * @param[out] ret_types A newly allocated list of resource types handle
*
- * @see iotcon_resource_types_free()
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_resource_types_destroy()
* @see iotcon_resource_types_insert()
* @see iotcon_resource_types_delete()
* @see iotcon_resource_types_clone()
*/
-iotcon_resource_types_h iotcon_resource_types_new();
+int iotcon_resource_types_create(iotcon_resource_types_h *ret_types);
/**
* @brief Free a resource types handle.
*
* @return void
*
- * @see iotcon_resource_types_new()
+ * @see iotcon_resource_types_create()
* @see iotcon_resource_types_insert()
* @see iotcon_resource_types_delete()
* @see iotcon_resource_types_clone()
*/
-void iotcon_resource_types_free(iotcon_resource_types_h types);
+void iotcon_resource_types_destroy(iotcon_resource_types_h types);
/**
* @brief Inserts a resource type into the list.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_resource_types_new()
- * @see iotcon_resource_types_free()
+ * @see iotcon_resource_types_create()
+ * @see iotcon_resource_types_destroy()
* @see iotcon_resource_types_delete()
* @see iotcon_resource_types_clone()
*/
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_NO_DATA No data available
*
- * @see iotcon_resource_types_new()
- * @see iotcon_resource_types_free()
+ * @see iotcon_resource_types_create()
+ * @see iotcon_resource_types_destroy()
* @see iotcon_resource_types_insert()
* @see iotcon_resource_types_clone()
*/
*
* @see iotcon_resource_types_foreach()
*/
-typedef int (*iotcon_resource_types_foreach_fn)(const char *type, void *user_data);
+typedef int (*iotcon_resource_types_foreach_cb)(const char *type, void *user_data);
/**
* @brief Gets all of the resource types of the list by invoking the callback function.
- * @details iotcon_resource_types_foreach_fn() will be called for each type.\n
- * If iotcon_resource_types_foreach_fn() returns #IOTCON_FUNC_STOP, iteration will be stop.
+ * @details iotcon_resource_types_foreach_cb() will be called for each type.\n
+ * If iotcon_resource_types_foreach_cb() returns #IOTCON_FUNC_STOP, iteration will be stop.
*
* @since_tizen 3.0
*
* @param[in] types The handle of resource types
- * @param[in] fn The callback function to get data
+ * @param[in] cb The callback function to get data
* @param[in] user_data The user data to pass to the function
*
* @return 0 on success, otherwise a negative error value.
*
* @post iotcon_resource_types_foreach() will be called for each type.
*
- * @see iotcon_resource_types_foreach_fn()
+ * @see iotcon_resource_types_foreach_cb()
*/
int iotcon_resource_types_foreach(iotcon_resource_types_h types,
- iotcon_resource_types_foreach_fn fn, void *user_data);
+ iotcon_resource_types_foreach_cb cb, void *user_data);
/**
* @brief Clones the resource types handle.
*
* @since_tizen 3.0
*
- * @param[in] types The origin handle of the resource types
+ * @param[in] src The origin handle of the resource types
+ * @param[out] dest Clone of a source list of resource types
*
- * @return Clone of a source list of resource types., otherwise NULL on failure
- * @retval iotcon_resource_types_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_resource_types_new()
- * @see iotcon_resource_types_free()
+ * @see iotcon_resource_types_create()
+ * @see iotcon_resource_types_destroy()
* @see iotcon_resource_types_insert()
* @see iotcon_resource_types_delete()
*/
-iotcon_resource_types_h iotcon_resource_types_clone(iotcon_resource_types_h types);
+int iotcon_resource_types_clone(iotcon_resource_types_h src,
+ iotcon_resource_types_h *dest);
/**
* @brief The handle of observers.
* @see iotcon_observers_append()
* @see iotcon_observers_remove()
*/
-void iotcon_observers_free(iotcon_observers_h observers);
+void iotcon_observers_destroy(iotcon_observers_h observers);
/**
* @brief Sets a observer id into the observers handle
*
* @param[in] observers The handle of the observers
* @param[in] obs_id The id to be appended to observers
+ * @param[out] ret_observers New appended observers handle
*
- * @return New appended observers handle, otherwise a null pointer if error
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
*
- * @see iotcon_observers_free()
+ * @see iotcon_observers_destroy()
* @see iotcon_observers_remove()
*/
-iotcon_observers_h iotcon_observers_append(iotcon_observers_h observers, int obs_id);
+int iotcon_observers_append(iotcon_observers_h observers, int obs_id,
+ iotcon_observers_h *ret_observers);
/**
* @brief Remove id from the observers.
*
* @param[in] observers observers The handle of the observers
* @param[in] obs_id The id to be removed from observers
+ * @param[out] ret_observers New deleted observers handle
*
- * @return New deleted observers handle, otherwise a null pointer if error
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
*
- * @see iotcon_observers_free()
+ * @see iotcon_observers_destroy()
* @see iotcon_observers_append()
*/
-iotcon_observers_h iotcon_observers_remove(iotcon_observers_h observers, int obs_id);
+int iotcon_observers_remove(iotcon_observers_h observers, int obs_id,
+ iotcon_observers_h *ret_observers);
/**
* @brief The handle of resource.
* @brief Gets an URI path of the client
*
* @since_tizen 3.0
+ * @remarks @a uri_path must not be released using free().
*
* @param[in] resource The handle of the client
* @param[out] uri_path The URI path of the client
* @brief Gets an host address of the client
*
* @since_tizen 3.0
+ * @remarks @a host must not be released using free().
*
* @param[in] resource The handle of the client
* @param[out] host The host address of the client
* @brief Gets an server id of the client
*
* @since_tizen 3.0
+ * @remarks @a sid must not be released using free().
*
* @param[in] resource The handle of the client
* @param[out] sid The server id of the client
* @brief Gets an URI path of the request
*
* @since_tizen 3.0
+ * @remarks @a uri_path must not be released using free().
*
* @param[in] request The handle of the request
* @param[out] uri_path The URI path of the request
* @brief Gets an representation of the request
*
* @since_tizen 3.0
+ * @remarks @a repr must not be released using free().
*
* @param[in] request The handle of the request
* @param[out] repr The representation of the request
* @see iotcon_request_get_observer_action()
* @see iotcon_request_get_observer_id()
*/
-int iotcon_request_get_representation(iotcon_request_h request, iotcon_repr_h *repr);
+int iotcon_request_get_representation(iotcon_request_h request, iotcon_representation_h *repr);
/**
* @brief Get types of the request
* @brief Get options of the request
*
* @since_tizen 3.0
+ * @remarks @a options must not be released using free().
*
* @param[in] request The handle of the request
* @param[out] options The options of the request
* @brief Get query of the request
*
* @since_tizen 3.0
+ * @remarks @a query must not be released using free().
*
* @param[in] request The handle of the request
* @param[out] query The query of the request
* @brief Get observation action of the request
*
* @since_tizen 3.0
+ * @details The @a action could be one of #iotcon_observe_action_e.
*
* @param[in] request The handle of the request
* @param[out] action The observation action of the request
* @see iotcon_request_get_query()
* @see iotcon_request_get_observer_id()
*/
-int iotcon_request_get_observer_action(iotcon_request_h request,
- iotcon_observe_action_e *action);
+int iotcon_request_get_observer_action(iotcon_request_h request, int *action);
/**
* @brief Get observation id of the request
*
* @since_tizen 3.0
*
- * @param[in] request_h The handle of received request handle
+ * @param[in] request The handle of received request handle
+ * @param[out] response Generated response handle
*
- * @return Generated response handle, otherwise a null pointer if a allocation error
- * @retval iotcon_response_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
- * @see iotcon_response_free()
+ * @see iotcon_response_destroy()
* @see iotcon_response_set()
*/
-iotcon_response_h iotcon_response_new(iotcon_request_h request_h);
+int iotcon_response_create(iotcon_request_h request, iotcon_response_h *response);
/**
* @brief Free a response handle.
*
* @param[in] resp The handle of the response
*
- * @see iotcon_response_new()
+ * @see iotcon_response_create()
* @see iotcon_response_set()
*/
-void iotcon_response_free(iotcon_response_h resp);
+void iotcon_response_destroy(iotcon_response_h resp);
/**
- * @brief Sets values into the response
+ * @brief Sets new uri path into the response
*
* @since_tizen 3.0
*
* @param[in] resp The handle of the response
- * @param[in] prop The property of the response to set
- * @param[in] ... arguments, as per format_string
+ * @param[in] new_uri_path New uri path to set
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
- * @see iotcon_response_new()
- * @see iotcon_response_free()
+ * @see iotcon_response_create()
+ * @see iotcon_response_destroy()
*/
-int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop, ...);
+int iotcon_response_set_new_uri_path(iotcon_response_h resp, char *new_uri_path);
+/**
+ * @brief Sets result into the response
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] resp The handle of the response
+ * @param[in] result The result to set
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_response_create()
+ * @see iotcon_response_destroy()
+ */
+int iotcon_response_set_result(iotcon_response_h resp, int result);
+
+/**
+ * @brief Sets representation into the response
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] resp The handle of the response
+ * @param[in] representation The representation of the response
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_response_create()
+ * @see iotcon_response_destroy()
+ */
+int iotcon_response_set_representation(iotcon_response_h resp, iotcon_representation_h repr);
+
+/**
+ * @brief Sets header options into the response
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] resp The handle of the response
+ * @param[in] options The header options of the response
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_response_create()
+ * @see iotcon_response_destroy()
+ */
+int iotcon_response_set_header_options(iotcon_response_h resp, iotcon_options_h options);
+
+/**
+ * @brief Sets resource interface into the response
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] resp The handle of the response
+ * @param[in] iface The resource interface
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_response_create()
+ * @see iotcon_response_destroy()
+ */
+int iotcon_response_set_interface(iotcon_response_h resp, int iface);
/**
* @}
*
* @see iotcon_close()
*/
-int iotcon_open();
+int iotcon_open(void);
/**
* @brief Closes Iotcon.
*
* @see iotcon_open()
*/
-void iotcon_close();
+int iotcon_close(void);
/**
* @brief Specifies the type of function passed to iotcon_add_connection_changed_cb() and
/**
* @brief Specifies the type of function passed to iotcon_register_resource() and
- * iotcon_bind_request_handler()
+ * iotcon_resource_bind_request_handler()
* @details Called when server receive request from the client.
*
* @since_tizen 3.0
* @pre The callback must be registered using iotcon_register_resource()
*
* @see iotcon_register_resource()
- * @see iotcon_bind_request_handler()
+ * @see iotcon_resource_bind_request_handler()
*/
typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
iotcon_request_h request, void *user_data);
* @param[in] properties The property of the resource.
* @param[in] cb The request handler callback function
* @param[in] user_data The user data to pass to the callback function
+ * @param[out] resource_handle The handle of the resource
*
- * @return resource handle of the registered resource, otherwise a null pointer if registering
- * has an error
- * @retval iotcon_resource_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
+ * @retval #IOTCON_ERROR_DBUS Dbus errors
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
* @post When the resource receive CRUD request, iotcon_request_handler_cb() will be called.
*
* @see iotcon_unregister_resource()
- * @see iotcon_bind_interface()
- * @see iotcon_bind_type()
- * @see iotcon_bind_request_handler()
- * @see iotcon_bind_resource()
- * @see iotcon_unbind_resource()
+ * @see iotcon_resource_bind_interface()
+ * @see iotcon_resource_bind_type()
+ * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_bind_child_resource()
+ * @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-iotcon_resource_h iotcon_register_resource(const char *uri_path,
+int iotcon_register_resource(const char *uri_path,
iotcon_resource_types_h res_types,
int ifaces,
uint8_t properties,
iotcon_request_handler_cb cb,
- void *user_data);
+ void *user_data,
+ iotcon_resource_h *resource_handle);
/**
* @brief Unregisters a resource and releases its data.
* @retval #IOTCON_ERROR_DBUS Dbus error
*
* @see iotcon_register_resource()
- * @see iotcon_bind_interface()
- * @see iotcon_bind_type()
- * @see iotcon_bind_request_handler()
- * @see iotcon_bind_resource()
- * @see iotcon_unbind_resource()
+ * @see iotcon_resource_bind_interface()
+ * @see iotcon_resource_bind_type()
+ * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_bind_child_resource()
+ * @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
int iotcon_unregister_resource(iotcon_resource_h resource_handle);
/**
* @brief Binds an interface to the resource
*
+ * @details The @a action could be one of #iotcon_interface_e.
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/internet
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
- * @see iotcon_bind_type()
- * @see iotcon_bind_request_handler()
- * @see iotcon_bind_resource()
- * @see iotcon_unbind_resource()
+ * @see iotcon_resource_bind_type()
+ * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_bind_child_resource()
+ * @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_bind_interface(iotcon_resource_h resource, iotcon_interface_e iface);
+int iotcon_resource_bind_interface(iotcon_resource_h resource, int iface);
/**
* @brief Binds a type to the resource
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
- * @see iotcon_bind_interface()
- * @see iotcon_bind_request_handler()
- * @see iotcon_bind_resource()
- * @see iotcon_unbind_resource()
+ * @see iotcon_resource_bind_interface()
+ * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_bind_child_resource()
+ * @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_bind_type(iotcon_resource_h resource_handle, const char *resource_type);
+int iotcon_resource_bind_type(iotcon_resource_h resource_handle, const char *resource_type);
/**
* @brief Binds a request handler to the resource
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
- * @see iotcon_bind_interface()
- * @see iotcon_bind_type()
- * @see iotcon_bind_resource()
- * @see iotcon_unbind_resource()
+ * @see iotcon_resource_bind_interface()
+ * @see iotcon_resource_bind_type()
+ * @see iotcon_resource_bind_child_resource()
+ * @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_bind_request_handler(iotcon_resource_h resource, iotcon_request_handler_cb cb);
+int iotcon_resource_bind_request_handler(iotcon_resource_h resource, iotcon_request_handler_cb cb);
/**
* @brief Binds a child resource into the parent resource.
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
- * @see iotcon_bind_interface()
- * @see iotcon_bind_type()
- * @see iotcon_bind_request_handler()
- * @see iotcon_unbind_resource()
+ * @see iotcon_resource_bind_interface()
+ * @see iotcon_resource_bind_type()
+ * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child);
+int iotcon_resource_bind_child_resource(iotcon_resource_h parent, iotcon_resource_h child);
/**
* @brief Unbinds a child resource from the parent resource.
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
- * @see iotcon_bind_interface()
- * @see iotcon_bind_type()
- * @see iotcon_bind_request_handler()
- * @see iotcon_bind_resource()
+ * @see iotcon_resource_bind_interface()
+ * @see iotcon_resource_bind_type()
+ * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_bind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_unbind_resource(iotcon_resource_h parent, iotcon_resource_h child);
+int iotcon_resource_unbind_child_resource(iotcon_resource_h parent, iotcon_resource_h child);
/**
* @brief Register device information in a server.
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
*/
-int iotcon_register_platform_info(iotcon_platform_info_s platform_info);
+int iotcon_register_platform_info(iotcon_platform_info_s *platform_info);
/**
* @brief Specifies the type of function passed to iotcon_get_platform_info().
*
* @see iotcon_get_platform_info()
*/
-typedef void (*iotcon_platform_info_cb)(iotcon_platform_info_s info, void *user_data);
+typedef void (*iotcon_platform_info_cb)(iotcon_platform_info_s *info, void *user_data);
/**
* @brief Calls a function for platform information of remote server.
* @see iotcon_subscribe_presence()
* @see iotcon_unsubscribe_presence()
*/
-int iotcon_stop_presence();
+int iotcon_stop_presence(void);
/**
* @brief Specifies the type of function passed to iotcon_subscribe_presence().
* @param[in] resource_type A resource type that a client has interested in
* @param[in] cb The callback function to invoke
* @param[in] user_data The user data to pass to the function
+ * @param[out] presence_handle The generated presence handle
*
- * @return Generated presence handle, otherwise a null pointer if fail to subscribe
- * @retval iotcon_presence_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
+ * @retval #IOTCON_ERROR_DBUS Dbus errors
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
* @post When the resource receive presence, iotcon_presence_cb() will be called.
*
* @see iotcon_unsubscribe_presence()
* @see iotcon_presence_cb()
*/
-iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
- const char *resource_type, iotcon_presence_cb cb, void *user_data);
+int iotcon_subscribe_presence(const char *host_address, const char *resource_type,
+ iotcon_presence_cb cb, void *user_data, iotcon_presence_h *presence_handle);
/**
* @brief Unsubscribes to a server's presence events.
* @param[in] is_observable Allow observation
* @param[in] resource_types The resource type of the resource. For example, "core.light"
* @param[in] resource_interfaces The resource interfaces (whether it is collection etc)
+ * @param[out] client_handle Generated resource handle
*
- * @return Generated resource handle, otherwise a null pointer if a allocation error
- * @retval iotcon_client_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
+ * @retval #IOTCON_ERROR_DBUS Dbus errors
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
- * @see iotcon_client_free()
+ * @see iotcon_client_destroy()
* @see iotcon_client_ref()
*/
-iotcon_client_h iotcon_client_new(const char *host,
+int iotcon_client_create(const char *host,
const char *uri_path,
bool is_observable,
iotcon_resource_types_h resource_types,
- int resource_interfaces);
+ int resource_ifs,
+ iotcon_client_h *client_handle);
/**
* @brief Releases a resource handle.
*
* @return void
*
- * @see iotcon_client_new()
+ * @see iotcon_client_create()
* @see iotcon_client_ref()
*/
-void iotcon_client_free(iotcon_client_h resource);
+void iotcon_client_destroy(iotcon_client_h resource);
/**
* @brief Increments reference count of the source resource.
*
* @since_tizen 3.0
*
- * @param[in] resource The Source of resource
+ * @param[in] src The Source of resource
+ * @param[out] dest The referenced resource handle
*
- * @return Referenced resource handle, otherwise a null pointer if the operation has an error
- * @retval iotcon_client_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_client_new()
- * @see iotcon_client_free()
+ * @see iotcon_client_create()
+ * @see iotcon_client_destroy()
*/
-iotcon_client_h iotcon_client_ref(iotcon_client_h resource);
+int iotcon_client_ref(iotcon_client_h src, iotcon_client_h *dest);
/**
* @brief Specifies the type of function passed to iotcon_observer_start().
- * @details Called when a client receive notifications from a server.
+ * @details Called when a client receive notifications from a server. The @a response_result could be one of #iotcon_response_result_e.
*
* @since_tizen 3.0
*
* @see iotcon_observer_start()
*/
typedef void (*iotcon_on_observe_cb)(iotcon_client_h resource,
- iotcon_repr_h repr,
+ iotcon_representation_h repr,
iotcon_options_h options,
int response_result,
int sequence_number,
/**
* @brief Sets observation on the resource
* @details When server sends notification message, iotcon_on_observe_cb() will be called.
+ * The @a observe_type could be one of #iotcon_observe_type_e.
*
* @since_tizen 3.0
* @privlevel public
*
* @see iotcon_on_observe_cb()
* @see iotcon_observer_stop()
- * @see iotcon_notimsg_new()
+ * @see iotcon_notimsg_create()
* @see iotcon_notify_list_of_observers()
- * @see iotcon_notify_all()
+ * @see iotcon_resource_notify_all()
*/
-int iotcon_observer_start(iotcon_client_h resource,
- iotcon_observe_type_e observe_type,
- iotcon_query_h query,
- iotcon_on_observe_cb cb,
- void *user_data);
+int iotcon_observer_start(iotcon_client_h resource, int observe_type,
+ iotcon_query_h query, iotcon_on_observe_cb cb, void *user_data);
/**
* @brief Cancels the observation on the resource
*
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
- * @see iotcon_notimsg_new()
+ * @see iotcon_notimsg_create()
* @see iotcon_notify_list_of_observers()
- * @see iotcon_notify_all()
+ * @see iotcon_resource_notify_all()
*/
int iotcon_observer_stop(iotcon_client_h resource);
/**
* @brief Creates a new notifications message handle.
+ * @details @a iface could be one of #iotcon_interface_e.
*
* @since_tizen 3.0
*
* @param[in] repr The handle of the representation
* @param[in] iface The resource interface
+ * @param[out] notimsg_handle The generated notifications message handle
*
- * @return Generated notifications message handle, otherwise a null pointer if a allocation error.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
*
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
* @see iotcon_observer_stop()
* @see iotcon_notify_list_of_observers()
- * @see iotcon_notify_all()
+ * @see iotcon_resource_notify_all()
*/
-iotcon_notimsg_h iotcon_notimsg_new(iotcon_repr_h repr, iotcon_interface_e iface);
+int iotcon_notimsg_create(iotcon_representation_h repr, int iface,
+ iotcon_notimsg_h *notimsg_handle);
/**
* @brief Releases a notifications message handle.
*
* @return void
*
- * @see iotcon_notimsg_new()
+ * @see iotcon_notimsg_create()
*/
-void iotcon_notimsg_free(iotcon_notimsg_h msg);
+void iotcon_notimsg_destroy(iotcon_notimsg_h msg);
/**
* @brief Notifies only specific clients that resource's attributes have changed.
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
* @see iotcon_observer_stop()
- * @see iotcon_notimsg_new()
- * @see iotcon_notify_all()
+ * @see iotcon_notimsg_create()
+ * @see iotcon_resource_notify_all()
*/
int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notimsg_h msg,
iotcon_observers_h observers);
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
* @see iotcon_observer_stop()
- * @see iotcon_notimsg_new()
+ * @see iotcon_notimsg_create()
* @see iotcon_notify_list_of_observers()
*/
-int iotcon_notify_all(iotcon_resource_h resource);
+int iotcon_resource_notify_all(iotcon_resource_h resource);
/**
* @brief Specifies the type of function passed to iotcon_get(), iotcon_put(), iotcon_post()
+ * @details The @a response_result could be one of #iotcon_response_result_e.
*
* @since_tizen 3.0
*
* @see iotcon_put()
* @see iotcon_post()
*/
-typedef void (*iotcon_on_cru_cb)(iotcon_client_h resource, iotcon_repr_h repr,
+typedef void (*iotcon_on_cru_cb)(iotcon_client_h resource, iotcon_representation_h repr,
iotcon_options_h options, int response_result, void *user_data);
/**
* @see iotcon_get()
* @see iotcon_post()
*/
-int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr, iotcon_query_h query,
+int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr, iotcon_query_h query,
iotcon_on_cru_cb cb, void *user_data);
/**
* @see iotcon_get()
* @see iotcon_put()
*/
-int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr, iotcon_query_h query,
+int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr, iotcon_query_h query,
iotcon_on_cru_cb cb, void *user_data);
/**
* @brief Specifies the type of function passed to iotcon_delete()
+ * @details The @a response_result could be one of #iotcon_response_result_e.
*
* @since_tizen 3.0
*
static char *door_resource_sid;
static void _on_observe(iotcon_client_h resource,
- iotcon_repr_h recv_repr,
+ iotcon_representation_h recv_repr,
iotcon_options_h header_options,
int response_result,
int sequence_number,
/* delete callback operations */
iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe, NULL);
- iotcon_client_free(door_resource);
+ iotcon_client_destroy(door_resource);
}
-static void _on_post(iotcon_client_h resource, iotcon_repr_h recv_repr,
+static void _on_post(iotcon_client_h resource, iotcon_representation_h recv_repr,
iotcon_options_h header_options, int response_result, void *user_data)
{
int ret;
- char *created_uri_path = NULL;
- iotcon_client_h new_door_resource = NULL;
- iotcon_client_h door_resource = NULL;
- char *host = NULL;
- iotcon_resource_types_h types = NULL;
int ifaces = 0;
+ iotcon_state_h recv_state;
+ char *host, *created_uri_path;
+ iotcon_resource_types_h types = NULL;
+ iotcon_client_h new_door_resource, door_resource;
RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
&& IOTCON_RESPONSE_RESULT_RESOURCE_CREATED != response_result,
"_on_post Response error(%d)", response_result);
INFO("POST request was successful");
- iotcon_repr_get_str(recv_repr, "createduripath", &created_uri_path);
+ iotcon_representation_get_state(recv_repr, &recv_state);
+ iotcon_state_get_str(recv_state, "createduripath", &created_uri_path);
if (NULL == created_uri_path) {
ERR("created_uri_path is NULL");
return;
}
- new_door_resource = iotcon_client_new(host, created_uri_path, true, types, ifaces);
- door_resource = iotcon_client_ref(resource);
+ ret = iotcon_client_create(host, created_uri_path, true, types, ifaces,
+ &new_door_resource);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_client_create() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_client_ref(resource, &door_resource);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_client_ref() Fail(%d)", ret);
+ iotcon_client_destroy(new_door_resource);
+ return;
+ }
iotcon_delete(new_door_resource, _on_delete, door_resource);
- iotcon_client_free(new_door_resource);
+ iotcon_client_destroy(new_door_resource);
}
-static void _on_put(iotcon_client_h resource, iotcon_repr_h recv_repr,
+static void _on_put(iotcon_client_h resource, iotcon_representation_h recv_repr,
iotcon_options_h header_options, int response_result, void *user_data)
{
+ int ret;
+ iotcon_representation_h send_repr;
+
RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_put Response error(%d)",
response_result);
INFO("PUT request was successful");
- iotcon_repr_h send_repr = iotcon_repr_new();
+ ret = iotcon_representation_create(&send_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
/* send POST request */
iotcon_post(resource, send_repr, NULL, _on_post, NULL);
- iotcon_repr_free(send_repr);
+ iotcon_representation_destroy(send_repr);
}
-static void _on_get(iotcon_client_h resource, iotcon_repr_h recv_repr,
+static void _on_get(iotcon_client_h resource, iotcon_representation_h recv_repr,
iotcon_options_h header_options, int response_result, void *user_data)
{
+ int ret;
+ bool opened = true;
+ iotcon_representation_h send_repr;
+ iotcon_state_h send_state;
+ iotcon_state_h recv_state = NULL;
+
RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_get Response error(%d)",
response_result);
INFO("GET request was successful");
- iotcon_repr_h send_repr = iotcon_repr_new();
- iotcon_repr_set_bool(send_repr, "opened", true);
+ iotcon_representation_get_state(recv_repr, &recv_state);
+ iotcon_state_get_bool(recv_state, "opened", &opened);
+
+ ret = iotcon_representation_create(&send_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_state_create(&send_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ return;
+ }
+
+ iotcon_state_set_bool(send_state, "opened", true);
+
+ iotcon_representation_set_state(send_repr, send_state);
/* send PUT request */
iotcon_put(resource, send_repr, NULL, _on_put, NULL);
- iotcon_repr_free(send_repr);
+ iotcon_representation_destroy(send_repr);
}
-static int _get_res_type_fn(const char *string, void *user_data)
+static int _get_res_type_cb(const char *string, void *user_data)
{
char *resource_uri_path = user_data;
static void _found_resource(iotcon_client_h resource, void *user_data)
{
int ret;
- char *resource_uri_path = NULL;
- char *resource_host = NULL;
char *resource_sid = NULL;
+ char *resource_host = NULL;
+ char *resource_uri_path = NULL;
+ iotcon_presence_h presence_handle;
iotcon_resource_types_h resource_types = NULL;
int resource_interfaces = 0;
return;
}
- ret = iotcon_resource_types_foreach(resource_types, _get_res_type_fn,
+ ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
resource_uri_path);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
return;
}
- iotcon_subscribe_presence(resource_host, "core.door", _presence_handler, NULL);
+ iotcon_subscribe_presence(resource_host, "core.door", _presence_handler, NULL,
+ &presence_handle);
if (TEST_STR_EQUAL == strcmp(door_uri_path, resource_uri_path)) {
- iotcon_query_h query = iotcon_query_new();
+ iotcon_query_h query;
+
+ ret = iotcon_query_create(&query);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_query_create() Fail(%d)", ret);
+ return;
+ }
+
ret = iotcon_query_insert(query, "query_key", "query_value");
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_query_insert() Fail(%d)", ret);
+ iotcon_query_destroy(query);
return;
}
/* send GET Request */
iotcon_get(resource, query, _on_get, NULL);
- iotcon_query_free(query);
+ iotcon_query_destroy(query);
}
}
bool state;
char *uri_path;
char *type;
- iotcon_repr_h repr;
+ iotcon_representation_h repr;
} door_resource_s;
static door_resource_s my_door;
INFO("[Door] opened.");
}
-static iotcon_resource_h _create_door_resource(char *uri_path, iotcon_interface_e interfaces,
- iotcon_resource_property_e properties)
+static iotcon_resource_h _create_door_resource(char *uri_path,
+ iotcon_interface_e interfaces, iotcon_resource_property_e properties)
{
- iotcon_resource_types_h resource_types = iotcon_resource_types_new();
- if (NULL == resource_types) {
- ERR("iotcon_resource_types_new() Fail");
+ int ret;
+ iotcon_resource_h handle;
+ iotcon_resource_types_h resource_types;
+
+ ret = iotcon_resource_types_create(&resource_types);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_create() Fail(%d)", ret);
return NULL;
}
- int ret = iotcon_resource_types_insert(resource_types, my_door.type);
+ ret = iotcon_resource_types_insert(resource_types, my_door.type);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
ERR("iotcon_resource_types_insert() Fail(%d)", ret);
return NULL;
}
/* register door resource */
- iotcon_resource_h handle = iotcon_register_resource(uri_path, resource_types,
- interfaces, properties, _request_handler, NULL);
- if (NULL == handle) {
- iotcon_resource_types_free(resource_types);
+ ret = iotcon_register_resource(uri_path, resource_types,
+ interfaces, properties, _request_handler, NULL, &handle);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_resource_types_destroy(resource_types);
ERR("iotcon_register_resource() Fail");
return NULL;
}
- iotcon_resource_types_free(resource_types);
+ iotcon_resource_types_destroy(resource_types);
return handle;
}
-static void _send_response(iotcon_response_h response, iotcon_repr_h repr,
+static void _send_response(iotcon_response_h response, iotcon_representation_h repr,
iotcon_response_result_e result)
{
- iotcon_response_set(response, IOTCON_RESPONSE_RESULT, result);
- iotcon_response_set(response, IOTCON_RESPONSE_REPRESENTATION, repr);
+ iotcon_response_set_result(response, result);
+ iotcon_response_set_representation(response, repr);
/* send Representation to the client */
iotcon_response_send(response);
static void _request_handler_get(iotcon_response_h response)
{
- iotcon_repr_h resp_repr = NULL;
+ int ret;
+ iotcon_representation_h resp_repr;
+ iotcon_state_h resp_state;
INFO("GET request");
/* create a door Representation */
- resp_repr = iotcon_repr_new();
- iotcon_repr_set_uri_path(resp_repr, my_door.uri_path);
- iotcon_repr_set_bool(resp_repr, "opened", my_door.state);
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
+ /* create a door state */
+ ret = iotcon_state_create(&resp_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ return;
+ }
+
+ iotcon_representation_set_uri_path(resp_repr, my_door.uri_path);
+ iotcon_state_set_bool(resp_state, "opened", my_door.state);
+
+ iotcon_representation_set_state(resp_repr, resp_state);
_send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
{
bool bval;
int ret;
- iotcon_repr_h req_repr = NULL;
- iotcon_repr_h resp_repr = NULL;
+ iotcon_representation_h req_repr, resp_repr;
+ iotcon_state_h req_state, resp_state;;
INFO("PUT request");
ret = iotcon_request_get_representation(request, &req_repr);
ERR("iotcon_request_get_representation() Fail(%d)", ret);
return;
}
- iotcon_repr_get_bool(req_repr, "opened", &bval);
+
+ iotcon_representation_get_state(req_repr, &req_state);
+
+ iotcon_state_get_bool(req_state, "opened", &bval);
my_door.state = bval;
_check_door_state();
- resp_repr = iotcon_repr_new();
- iotcon_repr_set_uri_path(resp_repr, my_door.uri_path);
- iotcon_repr_set_bool(resp_repr, "opened", my_door.state);
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_state_create(&resp_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ return;
+ }
+
+ iotcon_representation_set_uri_path(resp_repr, my_door.uri_path);
+ iotcon_state_set_bool(resp_state, "opened", my_door.state);
+
+ iotcon_representation_set_state(resp_repr, resp_state);
_send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
static gboolean _notifier(gpointer user_data)
{
+ int ret;
+ iotcon_representation_h repr;
+ iotcon_notimsg_h msg;
+
static int i = 0;
if ((5 == i++) || !(observers))
return FALSE;
INFO("NOTIFY!");
- iotcon_repr_h repr = iotcon_repr_new();
- iotcon_notimsg_h msg = iotcon_notimsg_new(repr, IOTCON_INTERFACE_DEFAULT);
+ ret = iotcon_representation_create(&repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return FALSE;
+ }
+
+ ret = iotcon_notimsg_create(repr, IOTCON_INTERFACE_DEFAULT, &msg);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_notimsg_create() Fail(%d)", ret);
+ return FALSE;
+ }
+
iotcon_notify_list_of_observers(user_data, msg, observers);
- iotcon_notimsg_free(msg);
- iotcon_repr_free(repr);
+ iotcon_notimsg_destroy(msg);
+ iotcon_representation_destroy(repr);
return TRUE;
}
static void _request_handler_post(iotcon_resource_h resource, iotcon_response_h response)
{
+ int ret;
+ iotcon_state_h resp_state;
+ iotcon_representation_h resp_repr = NULL;
iotcon_resource_h new_door_handle;
- iotcon_repr_h resp_repr = NULL;
INFO("POST request");
if (resource_created) {
resource_created = true;
/* send information that new resource was created */
- resp_repr = iotcon_repr_new();
- iotcon_repr_set_str(resp_repr, "createduripath", "/a/door1");
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_state_create(&resp_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ return;
+ }
+
+ iotcon_state_set_str(resp_state, "createduripath", "/a/door1");
+
+ iotcon_representation_set_state(resp_repr, resp_state);
_send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
/* add observe */
g_timeout_add_seconds(5, _notifier, resource);
static void _request_handler_delete(iotcon_resource_h resource,
iotcon_response_h response)
{
- iotcon_repr_h resp_repr = NULL;
+ int ret;
+ iotcon_representation_h resp_repr = NULL;
iotcon_response_result_e result = IOTCON_RESPONSE_RESULT_OK;
INFO("DELETE request");
iotcon_unregister_resource(resource);
- resp_repr = iotcon_repr_new();
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
result = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
_send_response(response, resp_repr, result);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
-static int _query_fn(const char *key, const char *value, void *user_data)
+static int _query_cb(const char *key, const char *value, void *user_data)
{
INFO("key : %s", key);
INFO("value : %s", value);
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
- int ret;
- int types;
iotcon_query_h query;
iotcon_response_h response = NULL;
- iotcon_observe_action_e observer_action;
- int observer_id;
+ int ret, types, observer_id, observer_action;
RET_IF(NULL == request);
return;
}
if (query)
- iotcon_query_foreach(query, _query_fn, NULL);
+ iotcon_query_foreach(query, _query_cb, NULL);
ret = iotcon_request_get_types(request, &types);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- response = iotcon_response_new(request);
- if (NULL == response) {
- ERR("iotcon_response_new() Fail(NULL == response)");
+ ret = iotcon_response_create(request, &response);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_create() Fail(%d)", ret);
return;
}
else if (IOTCON_REQUEST_DELETE & types)
_request_handler_delete(resource, response);
- iotcon_response_free(response);
+ iotcon_response_destroy(response);
if (IOTCON_REQUEST_OBSERVE & types) {
ret = iotcon_request_get_observer_action(request, &observer_action);
ERR("iotcon_request_get_observer_id() Fail(%d)", ret);
return;
}
- observers = iotcon_observers_append(observers, observer_id);
+ ret = iotcon_observers_append(observers, observer_id, &observers);
} else if (IOTCON_OBSERVE_DEREGISTER == observer_action) {
ret = iotcon_request_get_observer_id(request, &observer_id);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_observer_id() Fail(%d)", ret);
return;
}
- observers = iotcon_observers_remove(observers, observer_id);
+ ret = iotcon_observers_remove(observers, observer_id, &observers);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_observers_remove() Fail(%d)", ret);
+ return;
+ }
}
}
}
#include <iotcon.h>
#include "test.h"
-static void _get_platform_info(iotcon_platform_info_s info, void *user_data)
+static void _get_platform_info(iotcon_platform_info_s *info, void *user_data)
{
- INFO("platform_id : %s", info.platform_id);
- INFO("manuf_name : %s", info.manuf_name);
- INFO("manuf_url : %s", info.manuf_url);
- INFO("model_number : %s", info.model_number);
- INFO("date_of_manufacture : %s", info.date_of_manufacture);
- INFO("platform_ver : %s", info.platform_ver);
- INFO("os_ver : %s", info.os_ver);
- INFO("hardware_ver : %s", info.hardware_ver);
- INFO("firmware_ver : %s", info.firmware_ver);
- INFO("support_url : %s", info.support_url);
- INFO("system_time : %s", info.system_time);
+ INFO("platform_id : %s", info->platform_id);
+ INFO("manuf_name : %s", info->manuf_name);
+ INFO("manuf_url : %s", info->manuf_url);
+ INFO("model_number : %s", info->model_number);
+ INFO("date_of_manufacture : %s", info->date_of_manufacture);
+ INFO("platform_ver : %s", info->platform_ver);
+ INFO("os_ver : %s", info->os_ver);
+ INFO("hardware_ver : %s", info->hardware_ver);
+ INFO("firmware_ver : %s", info->firmware_ver);
+ INFO("support_url : %s", info->support_url);
+ INFO("system_time : %s", info->system_time);
}
int main()
{
+ FN_CALL;
int ret;
GMainLoop *loop;
char *device_name;
- iotcon_platform_info_s platform_info = {0};
-
- platform_info.platform_id = "platform_id";
- platform_info.manuf_name = "manuf_name";
- platform_info.manuf_url = "manuf_url";
- platform_info.model_number = "model_number";
- platform_info.date_of_manufacture = "date_of_manufacture";
- platform_info.platform_ver = "platform_ver";
- platform_info.os_ver = "os_ver";
- platform_info.hardware_ver = "hardware_ver";
- platform_info.firmware_ver = "firmware_ver";
- platform_info.support_url = "support_url";
- platform_info.system_time = "system_time";
+ iotcon_platform_info_s *platform_info = calloc(1, sizeof(iotcon_platform_info_s));
+
+ platform_info->platform_id = "platform_id";
+ platform_info->manuf_name = "manuf_name";
+ platform_info->manuf_url = "manuf_url";
+ platform_info->model_number = "model_number";
+ platform_info->date_of_manufacture = "date_of_manufacture";
+ platform_info->platform_ver = "platform_ver";
+ platform_info->os_ver = "os_ver";
+ platform_info->hardware_ver = "hardware_ver";
+ platform_info->firmware_ver = "firmware_ver";
+ platform_info->support_url = "support_url";
+ platform_info->system_time = "system_time";
device_name = "device_name";
static const char* const room_uri_path = "/a/room";
static char *room_resource_sid;
-static int _get_int_list_fn(int pos, const int value, void *user_data)
+static int _get_int_list_cb(int pos, const int value, void *user_data)
{
DBG("%d°C", value);
return IOTCON_FUNC_CONTINUE;
}
-static void _on_get(iotcon_repr_h recv_repr, int response_result)
+static void _on_get(iotcon_representation_h recv_repr, int response_result)
{
int i, ret;
- unsigned int key_count, children_count;
- const char *uri_path;
- iotcon_repr_h child_repr;
+ bool is_null;
iotcon_list_h list;
+ const char *uri_path;
+ iotcon_representation_h child_repr;
+ iotcon_state_h recv_state, child_state;
+ unsigned int key_count, children_count;
RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result,
"_on_get Response error(%d)", response_result);
INFO("GET request was successful");
DBG("[ parent representation ]");
- iotcon_repr_get_uri_path(recv_repr, &uri_path);
+ iotcon_representation_get_uri_path(recv_repr, &uri_path);
if (uri_path)
DBG("uri_path : %s", uri_path);
- key_count = iotcon_repr_get_keys_count(recv_repr);
+
+ iotcon_representation_get_state(recv_repr, &recv_state);
+
+ ret = iotcon_state_get_keys_count(recv_state, &key_count);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
+ return;
+ }
+
if (key_count) {
char *str;
- iotcon_repr_get_str(recv_repr, "name", &str);
+ iotcon_state_get_str(recv_state, "name", &str);
if (str)
DBG("name : %s", str);
- iotcon_repr_get_list(recv_repr, "today_temp", &list);
+ iotcon_state_get_list(recv_state, "today_temp", &list);
DBG("today's temperature :");
- iotcon_list_foreach_int(list, _get_int_list_fn, NULL);
+ iotcon_list_foreach_int(list, _get_int_list_cb, NULL);
- if (iotcon_repr_is_null(recv_repr, "null value"))
+ ret = iotcon_state_is_null(recv_state, "null value", &is_null);
+ if (is_null)
DBG("null value is null");
}
- children_count = iotcon_repr_get_children_count(recv_repr);
+ ret = iotcon_representation_get_children_count(recv_repr, &children_count);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_children_count() Fail(%d)", ret);
+ return;
+ }
for (i = 0; i < children_count; i++) {
DBG("[ child representation ]");
const char *uri_path;
- ret = iotcon_repr_get_nth_child(recv_repr, i, &child_repr);
+ ret = iotcon_representation_get_nth_child(recv_repr, i, &child_repr);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_repr_get_nth_child(%d) Fail(%d)", i, ret);
+ ERR("iotcon_representation_get_nth_child(%d) Fail(%d)", i, ret);
continue;
}
- iotcon_repr_get_uri_path(child_repr, &uri_path);
+ iotcon_representation_get_uri_path(child_repr, &uri_path);
if (NULL == uri_path)
continue;
DBG("uri_path : %s", uri_path);
+ iotcon_representation_get_state(child_repr, &child_state);
if (TEST_STR_EQUAL == strcmp("/a/light", uri_path)) {
- key_count = iotcon_repr_get_keys_count(child_repr);
+ ret = iotcon_state_get_keys_count(child_state, &key_count);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
+ return;
+ }
+
if (key_count) {
int brightness;
- iotcon_repr_get_int(child_repr, "brightness", &brightness);
+ iotcon_state_get_int(child_state, "brightness", &brightness);
DBG("brightness : %d", brightness);
}
} else if (TEST_STR_EQUAL == strcmp("/a/switch", uri_path)) {
- key_count = iotcon_repr_get_keys_count(child_repr);
+ ret = iotcon_state_get_keys_count(child_state, &key_count);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
+ return;
+ }
if (key_count) {
bool bswitch;
- iotcon_repr_get_bool(child_repr, "switch", &bswitch);
+ iotcon_state_get_bool(child_state, "switch", &bswitch);
DBG("switch : %d", bswitch);
}
}
}
}
-static void _on_get_2nd(iotcon_client_h resource, iotcon_repr_h recv_repr,
+static void _on_get_2nd(iotcon_client_h resource, iotcon_representation_h recv_repr,
iotcon_options_h header_options, int response_result, void *user_data)
{
_on_get(recv_repr, response_result);
}
-static void _on_get_1st(iotcon_client_h resource, iotcon_repr_h recv_repr,
+static void _on_get_1st(iotcon_client_h resource, iotcon_representation_h recv_repr,
iotcon_options_h header_options, int response_result, void *user_data)
{
+ int ret;
iotcon_query_h query_params;
_on_get(recv_repr, response_result);
- query_params = iotcon_query_new();
+ ret = iotcon_query_create(&query_params);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_query_create() Fail(%d)", ret);
+ return;
+ }
+
iotcon_query_insert(query_params, "if", "oic.if.b");
/* send GET request again with BATCH interface */
iotcon_get(resource, query_params, _on_get_2nd, NULL);
- iotcon_query_free(query_params);
+ iotcon_query_destroy(query_params);
}
static int _get_res_type_fn(const char *string, void *user_data)
static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data);
-static void _send_response(iotcon_response_h response, iotcon_repr_h repr,
+static void _send_response(iotcon_response_h response, iotcon_representation_h repr,
iotcon_interface_e interface)
{
- iotcon_response_set(response, IOTCON_RESPONSE_REPRESENTATION, repr);
- iotcon_response_set(response, IOTCON_RESPONSE_INTERFACE, interface);
- iotcon_response_set(response, IOTCON_RESPONSE_RESULT, IOTCON_RESPONSE_RESULT_OK);
+ iotcon_response_set_representation(response, repr);
+ iotcon_response_set_interface(response, interface);
+ iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
/* send Representation to the client */
iotcon_response_send(response);
static void _light_request_handler_get(iotcon_response_h response)
{
- iotcon_repr_h resp_repr;
+ int ret;
+ iotcon_representation_h resp_repr;
INFO("GET request - Light");
/* create a light Representation */
- resp_repr = iotcon_repr_new();
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
_send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
-static int _query_foreach_fn(const char *key, const char *value, void *user_data)
+static int _query_foreach_cb(const char *key, const char *value, void *user_data)
{
char **interface_str = user_data;
iotcon_response_h response)
{
int ret;
- iotcon_repr_h room_repr;
- iotcon_repr_h light_repr;
- iotcon_repr_h switch_repr;
+ iotcon_representation_h room_repr, light_repr, switch_repr;
+ iotcon_state_h room_state, light_state, switch_state;
iotcon_list_h temperature_list;
iotcon_query_h query;
INFO("GET request - Room");
/* create a room Representation */
- room_repr = iotcon_repr_new();
- iotcon_repr_set_uri_path(room_repr, "/a/room");
- iotcon_repr_set_str(room_repr, "name", "Michael's Room");
+ ret = iotcon_representation_create(&room_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
+ /* create a room state */
+ ret = iotcon_state_create(&room_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ iotcon_representation_set_uri_path(room_repr, "/a/room");
+ iotcon_state_set_str(room_state, "name", "Michael's Room");
/* set null */
- iotcon_repr_set_null(room_repr, "null value");
+ iotcon_state_set_null(room_state, "null value");
+
+ ret = iotcon_list_create(IOTCON_TYPE_INT, &temperature_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create() Fail(%d)", ret);
+ return;
+ }
- temperature_list = iotcon_list_new(IOTCON_TYPE_INT);
iotcon_list_insert_int(temperature_list, 22, -1);
iotcon_list_insert_int(temperature_list, 23, -1);
iotcon_list_insert_int(temperature_list, 24, -1);
iotcon_list_insert_int(temperature_list, 25, -1);
iotcon_list_insert_int(temperature_list, 26, -1);
- iotcon_repr_set_list(room_repr, "today_temp", temperature_list);
- iotcon_list_free(temperature_list);
+ iotcon_state_set_list(room_state, "today_temp", temperature_list);
+
+ /* Set a room state into room Representation */
+ iotcon_representation_set_state(room_repr, room_state);
+
+ iotcon_list_destroy(temperature_list);
+ iotcon_state_destroy(room_state);
/* create a light Representation */
- light_repr = iotcon_repr_new();
- iotcon_repr_set_uri_path(light_repr, "/a/light");
- iotcon_repr_set_int(light_repr, "brightness", 50);
- iotcon_repr_append_child(room_repr, light_repr);
- iotcon_repr_free(light_repr);
+ ret = iotcon_representation_create(&light_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ /* create a light state */
+ ret = iotcon_state_create(&light_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_representation_destroy(light_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ iotcon_representation_set_uri_path(light_repr, "/a/light");
+ iotcon_state_set_int(light_state, "brightness", 50);
+
+ /* Set a light state into light Representation */
+ iotcon_representation_set_state(light_repr, light_state);
+
+ iotcon_representation_append_child(room_repr, light_repr);
+
+ iotcon_state_destroy(light_state);
+ iotcon_representation_destroy(light_repr);
/* create a switch Representation */
- switch_repr = iotcon_repr_new();
- iotcon_repr_set_uri_path(switch_repr, "/a/switch");
- iotcon_repr_set_bool(switch_repr, "switch", false);
- iotcon_repr_append_child(room_repr, switch_repr);
- iotcon_repr_free(switch_repr);
+ ret = iotcon_representation_create(&switch_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ /* create a switch state */
+ ret = iotcon_state_create(&switch_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_representation_destroy(room_repr);
+ iotcon_representation_destroy(switch_repr);
+ return;
+ }
+
+ iotcon_representation_set_uri_path(switch_repr, "/a/switch");
+ iotcon_state_set_bool(switch_state, "switch", false);
+
+ /* Set a light state into light Representation */
+ iotcon_representation_set_state(switch_repr, switch_state);
+ iotcon_representation_append_child(room_repr, switch_repr);
+
+ iotcon_state_destroy(switch_state);
+ iotcon_representation_destroy(switch_repr);
ret = iotcon_request_get_query(request, &query);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_query() Fail(%d)", ret);
- iotcon_repr_free(room_repr);
+ iotcon_representation_destroy(room_repr);
return;
}
if (query)
- iotcon_query_foreach(query, _query_foreach_fn, &query_str);
+ iotcon_query_foreach(query, _query_foreach_cb, &query_str);
if (query_str && (TEST_STR_EQUAL == strcmp("oic.if.b", query_str))) {
DBG("operation for BATCH interface");
}
_send_response(response, room_repr, interface);
- iotcon_repr_free(room_repr);
+ iotcon_representation_destroy(room_repr);
}
static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
{
- iotcon_repr_h resp_repr = iotcon_repr_new();
+ int ret;
+ iotcon_representation_h resp_repr;
+
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
INFO("PUT request");
/* do PUT operation */
_send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
static void _request_handler_post(iotcon_response_h response)
{
- iotcon_repr_h resp_repr = iotcon_repr_new();
+ int ret;
+ iotcon_representation_h resp_repr;
+
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
INFO("POST request");
/* do POST operation */
_send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
static void _request_handler_delete(iotcon_response_h response)
{
- iotcon_repr_h resp_repr = iotcon_repr_new();
+ int ret;
+ iotcon_representation_h resp_repr;
+
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
INFO("DELETE request");
/* do DELETE operation */
_send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_repr_free(resp_repr);
+ iotcon_representation_destroy(resp_repr);
}
return;
}
- response = iotcon_response_new(request);
- if (NULL == response) {
- ERR("iotcon_response_new() Fail");
+ ret = iotcon_response_create(request, &response);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_create() Fail");
return;
}
else if (IOTCON_REQUEST_DELETE & types)
_request_handler_delete(response);
- iotcon_response_free(response);
+ iotcon_response_destroy(response);
}
static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
- int ret;
- int types;
- iotcon_response_h response;
FN_CALL;
+ int ret, types;
+ iotcon_response_h response;
RET_IF(NULL == request);
return;
}
- response = iotcon_response_new(request);
- if (NULL == response) {
- ERR("iotcon_response_new() Fail");
+ ret = iotcon_response_create(request, &response);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_create() Fail(%d)", ret);
return;
}
else if (IOTCON_REQUEST_DELETE & types)
_request_handler_delete(response);
- iotcon_response_free(response);
+ iotcon_response_destroy(response);
}
int main(int argc, char **argv)
{
FN_CALL;
+ int ret;
GMainLoop *loop;
- iotcon_resource_types_h room_rtypes = NULL;
- iotcon_resource_types_h light_rtypes = NULL;
- int ret = IOTCON_ERROR_NONE;
+ iotcon_resource_h room_handle, light_handle;
+ iotcon_resource_types_h room_rtypes, light_rtypes;
loop = g_main_loop_new(NULL, FALSE);
iotcon_open();
/* register room resource */
- room_rtypes = iotcon_resource_types_new();
+ ret = iotcon_resource_types_create(&room_rtypes);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ return -1;
+ }
+
iotcon_resource_types_insert(room_rtypes, "core.room");
- iotcon_resource_h room_handle = iotcon_register_resource("/a/room", room_rtypes,
+ ret = iotcon_register_resource("/a/room", room_rtypes,
(IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
(IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _room_request_handler,
- NULL);
+ NULL, &room_handle);
if (NULL == room_handle) {
ERR("iotcon_register_resource() Fail");
+ iotcon_resource_types_destroy(room_rtypes);
return -1;
}
- /* register room resource */
- light_rtypes = iotcon_resource_types_new();
- if (NULL == light_rtypes) {
- ERR("iotcon_resource_types_new() Fail");
+ /* register light resource */
+ ret = iotcon_resource_types_create(&light_rtypes);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ iotcon_resource_types_destroy(room_rtypes);
+ iotcon_unregister_resource(room_handle);
return -1;
}
iotcon_resource_types_insert(light_rtypes, "core.light");
- iotcon_resource_h light_handle = iotcon_register_resource("/a/light", light_rtypes,
+ ret = iotcon_register_resource("/a/light", light_rtypes,
(IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
(IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _light_request_handler,
- NULL);
- if (NULL == light_handle) {
+ NULL, &light_handle);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_register_resource() Fail");
+ iotcon_resource_types_destroy(light_rtypes);
+ iotcon_resource_types_destroy(room_rtypes);
+ iotcon_unregister_resource(room_handle);
return -1;
}
- ret = iotcon_bind_resource(room_handle, light_handle);
+ ret = iotcon_resource_bind_child_resource(room_handle, light_handle);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_bind_resource() Fail");
+ ERR("iotcon_resource_bind_child_resource() Fail");
+ iotcon_resource_types_destroy(light_rtypes);
+ iotcon_unregister_resource(light_handle);
+ iotcon_resource_types_destroy(room_rtypes);
+ iotcon_unregister_resource(room_handle);
return -1;
}
- iotcon_resource_types_free(light_rtypes);
+ iotcon_resource_types_destroy(light_rtypes);
+ iotcon_resource_types_destroy(room_rtypes);
g_main_loop_run(loop);
g_main_loop_unref(loop);
+ iotcon_unregister_resource(light_handle);
iotcon_unregister_resource(room_handle);
/* iotcon close */