From 7452dd97ee4ed4c294b3bd9a632d075103b00ea7 Mon Sep 17 00:00:00 2001 From: Minchul Lee Date: Wed, 3 Jun 2015 14:05:03 +0900 Subject: [PATCH] modify functions to be compatible with tizen v2.3 Change-Id: Id4c3456f0c76f1d819e091b0626c95ba32a30714 Signed-off-by: Minchul Lee --- lib/ic-repr-value.c | 9 +++++--- lib/ic-repr.c | 54 +++++++++++++++++++++++++++++++++---------- lib/include/iotcon-constant.h | 13 +++++++---- test/repr-test-client.c | 3 +++ test/repr-test-server.c | 3 +++ 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/lib/ic-repr-value.c b/lib/ic-repr-value.c index 4bce4a5..e6672cc 100755 --- a/lib/ic-repr-value.c +++ b/lib/ic-repr-value.c @@ -258,9 +258,13 @@ JsonNode* ic_value_to_json(iotcon_value_h value) RETV_IF(NULL == value, NULL); - node = json_node_new(JSON_NODE_VALUE); + if (IOTCON_TYPE_NULL == value->type) + node = json_node_new(JSON_NODE_NULL); + else + node = json_node_new(JSON_NODE_VALUE); + if (NULL == node) { - ERR("json_node_new(VALUE) Fail"); + ERR("json_node_new(%d) Fail", value->type); return NULL; } @@ -278,7 +282,6 @@ JsonNode* ic_value_to_json(iotcon_value_h value) json_node_set_string(node, real->val.s); break; case IOTCON_TYPE_NULL: - node = json_node_init_null(node); break; default: ERR("Invalid type(%d)", value->type); diff --git a/lib/ic-repr.c b/lib/ic-repr.c index df9798b..d24eee7 100755 --- a/lib/ic-repr.c +++ b/lib/ic-repr.c @@ -399,7 +399,10 @@ char* ic_repr_generate_json(iotcon_repr_h repr, bool set_pretty) } JsonGenerator *gen = json_generator_new(); +#if JSON_CHECK_VERSION(0,14,0) json_generator_set_pretty(gen, set_pretty); +#endif + root_node = json_node_new(JSON_NODE_OBJECT); json_node_set_object(root_node, obj); json_generator_set_root(gen, root_node); @@ -597,26 +600,53 @@ static void _ic_repr_obj_clone(char *key, iotcon_value_h src_val, iotcon_repr_h } } -static gpointer _ic_repr_copy_repr(gconstpointer src, gpointer data) -{ - FN_CALL; - - return iotcon_repr_clone((iotcon_repr_h)src); -} - API iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src) { FN_CALL; - iotcon_repr_h dest = NULL; + GList *node; + iotcon_repr_h dest, copied_repr; + iotcon_str_list_s *list = NULL; RETV_IF(NULL == src, NULL); dest = iotcon_repr_new(); - if (src->uri) + if (NULL == dest) { + ERR("iotcon_repr_new() Fail"); + return NULL; + } + + if (src->uri) { dest->uri = strdup(src->uri); - dest->interfaces = src->interfaces; - dest->res_types = iotcon_str_list_clone(src->res_types); - dest->children = g_list_copy_deep(src->children, _ic_repr_copy_repr, NULL); + if (NULL == dest->uri) { + ERR("strdup() Fail"); + iotcon_repr_free(dest); + return NULL; + } + } + + if (src->interfaces) + dest->interfaces = src->interfaces; + + if (src->res_types) { + list = iotcon_str_list_clone(src->res_types); + if (NULL == list) { + ERR("iotcon_str_list_clone() Fail"); + iotcon_repr_free(dest); + return NULL; + } + dest->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; + } + dest->children = g_list_append(dest->children, copied_repr); + } + g_hash_table_foreach(src->hash_table, (GHFunc)_ic_repr_obj_clone, dest); return dest; diff --git a/lib/include/iotcon-constant.h b/lib/include/iotcon-constant.h index 988b882..0b0fd12 100755 --- a/lib/include/iotcon-constant.h +++ b/lib/include/iotcon-constant.h @@ -63,12 +63,17 @@ typedef enum { IOTCON_OBSERVE_ALL = 1 } iotcon_observe_type_e; +/** + * @ingroup CAPI_IOT_CONNECTIVITY_MODULE + * @brief Enumerations of Iotcon interface types. + * @since_tizen 3.0 + */ typedef enum { IOTCON_INTERFACE_NONE = 0, - IOTCON_INTERFACE_DEFAULT = (1 << 0), - IOTCON_INTERFACE_LINK = (1 << 1), - IOTCON_INTERFACE_BATCH = (1 << 2), - IOTCON_INTERFACE_GROUP = (1 << 3), + IOTCON_INTERFACE_DEFAULT = (1 << 0), /* default interface */ + IOTCON_INTERFACE_LINK = (1 << 1), /* discovers children of the parent resource */ + IOTCON_INTERFACE_BATCH = (1 << 2), /* requests CRUD to children of the parent resource */ + IOTCON_INTERFACE_GROUP = (1 << 3), /* requests CRUD to remote resources of a group. */ IOTCON_INTERFACE_MAX = (1 << 4) } iotcon_interface_e; diff --git a/test/repr-test-client.c b/test/repr-test-client.c index 489ba3c..584d94f 100644 --- a/test/repr-test-client.c +++ b/test/repr-test-client.c @@ -61,6 +61,9 @@ static void _on_get(iotcon_repr_h recv_repr, int response_result) DBG("today's temperature :"); iotcon_list_foreach_int(list, _get_int_list_fn, NULL); iotcon_str_list_free(key_list); + + if (iotcon_repr_is_null(recv_repr, "null value")) + DBG("null value is null"); } children_count = iotcon_repr_get_children_count(recv_repr); diff --git a/test/repr-test-server.c b/test/repr-test-server.c index b03ae34..177d39c 100644 --- a/test/repr-test-server.c +++ b/test/repr-test-server.c @@ -76,6 +76,9 @@ static void _room_request_handler_get(iotcon_request_h request, iotcon_repr_set_uri(room_repr, "/a/room"); iotcon_repr_set_str(room_repr, "name", "Michael's Room"); + /* set null */ + iotcon_repr_set_null(room_repr, "null value"); + temperature_list = iotcon_list_new(IOTCON_TYPE_INT); iotcon_list_insert_int(temperature_list, 22, -1); iotcon_list_insert_int(temperature_list, 23, -1); -- 2.7.4