From 0d33841e37fb154598f5bf9927482d1dba34dc97 Mon Sep 17 00:00:00 2001 From: Minchul Lee Date: Tue, 21 Jul 2015 15:21:31 +0900 Subject: [PATCH] send response differently by interface type Change-Id: I8fcfb6dc8c9f0d14a4d427f16ef0289aec6e6ee4 Signed-off-by: Minchul Lee --- daemon/icd-ioty-ocprocess.c | 10 +- daemon/icd-ioty.c | 1 + lib/icl-client-crud.c | 4 +- lib/icl-client.c | 35 +++++-- lib/icl-client.h | 2 +- lib/icl-dbus-type.c | 5 +- lib/icl-dbus.c | 1 - lib/icl-repr.c | 216 +++++++++++++++++++++++++++++--------------- lib/icl-repr.h | 7 +- lib/icl-response.c | 52 ++++++++++- lib/icl-response.h | 8 ++ 11 files changed, 245 insertions(+), 96 deletions(-) diff --git a/daemon/icd-ioty-ocprocess.c b/daemon/icd-ioty-ocprocess.c index 5a30f39..6a6ba96 100644 --- a/daemon/icd-ioty-ocprocess.c +++ b/daemon/icd-ioty-ocprocess.c @@ -213,6 +213,7 @@ static int _worker_req_handler(void *context) OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag, OCEntityHandlerRequest *request) { + FN_CALL; int ret; unsigned int signal_number; char *query_str, *query_key, *query_value; @@ -480,7 +481,11 @@ static inline int _find_cb_handle_context(struct icd_find_context *ctx) } for (rsrc_index = 0; rsrc_index < rsrc_count; rsrc_index++) { - JsonObject *rsrc_obj = json_array_get_object_element(rsrc_array, rsrc_index); + JsonObject *rsrc_obj; + + rsrc_obj = json_array_get_object_element(rsrc_array, rsrc_index); + if (0 == json_object_get_size(rsrc_obj)) /* for the case of empty "{}" */ + continue; ret = _find_cb_response(rsrc_obj, ctx); if (IOTCON_ERROR_NONE != ret) { @@ -568,7 +573,6 @@ OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle static int _worker_get_cb(void *context) { - int ret; GVariant *value; struct icd_get_context *ctx = context; @@ -582,7 +586,7 @@ static int _worker_get_cb(void *context) g_variant_builder_unref(ctx->options); free(ctx); - return ret; + return IOTCON_ERROR_NONE; } diff --git a/daemon/icd-ioty.c b/daemon/icd-ioty.c index 2723f9b..3f6cde4 100644 --- a/daemon/icd-ioty.c +++ b/daemon/icd-ioty.c @@ -488,6 +488,7 @@ void icd_ioty_get_complete_error(GDBusMethodInvocation *invocation, int ret_val) gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation, GVariant *resource, GVariant *query) { + FN_CALL; OCStackResult result; GVariantIter *options; OCCallbackData cbdata = {0}; diff --git a/lib/icl-client-crud.c b/lib/icl-client-crud.c index f6d4525..978db6c 100644 --- a/lib/icl-client-crud.c +++ b/lib/icl-client-crud.c @@ -222,7 +222,7 @@ API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr, cb_container->cb = cb; cb_container->user_data = user_data; - arg_repr = icl_repr_generate_json(repr, FALSE); + arg_repr = icl_repr_generate_json(repr, false, true); if (NULL == arg_repr) { ERR("icl_repr_generate_json() Fail"); iotcon_client_free(cb_container->resource); @@ -271,7 +271,7 @@ API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr, cb_container->cb = cb; cb_container->user_data = user_data; - arg_repr = icl_repr_generate_json(repr, FALSE); + arg_repr = icl_repr_generate_json(repr, false, true); if (NULL == arg_repr) { ERR("icl_repr_generate_json() Fail"); iotcon_client_free(cb_container->resource); diff --git a/lib/icl-client.c b/lib/icl-client.c index 61b6756..270b72e 100644 --- a/lib/icl-client.c +++ b/lib/icl-client.c @@ -47,7 +47,6 @@ static void _icl_found_resource_cb(GDBusConnection *connection, { FN_CALL; int conn_type; - JsonParser *parser; iotcon_client_h client; char *payload, *host; icl_found_resource_s *cb_container = user_data; @@ -58,12 +57,9 @@ static void _icl_found_resource_cb(GDBusConnection *connection, RET_IF(NULL == payload); RET_IF(NULL == host); - parser = json_parser_new(); - - client = icl_client_parse_resource_object(parser, payload, host, conn_type); + client = icl_client_parse_resource_object(payload, host, conn_type); if (NULL == client) { ERR("icl_client_parse_resource_object() Fail"); - g_object_unref(parser); return; } @@ -72,8 +68,6 @@ static void _icl_found_resource_cb(GDBusConnection *connection, iotcon_client_free(client); - g_object_unref(parser); - /* TODO * When is callback removed? */ @@ -291,10 +285,11 @@ API int iotcon_client_set_options(iotcon_client_h resource, } -iotcon_client_h icl_client_parse_resource_object(JsonParser *parser, char *json_string, - const char *host, iotcon_connectivity_type_e conn_type) +iotcon_client_h icl_client_parse_resource_object(const char *json_string, const char *host, + iotcon_connectivity_type_e conn_type) { FN_CALL; + JsonParser *parser; int ret, observable; GError *error = NULL; iotcon_client_h client; @@ -305,28 +300,44 @@ iotcon_client_h icl_client_parse_resource_object(JsonParser *parser, char *json_ DBG("input str : %s", json_string); + parser = json_parser_new(); ret = json_parser_load_from_data(parser, json_string, strlen(json_string), &error); if (FALSE == ret) { ERR("json_parser_load_from_data() Fail(%s)", error->message); g_error_free(error); + g_object_unref(parser); return NULL; } rsrc_obj = json_node_get_object(json_parser_get_root(parser)); + if (NULL == rsrc_obj) { + ERR("json_node_get_object() Fail"); + g_object_unref(parser); + return NULL; + } uri_path = json_object_get_string_member(rsrc_obj, IC_JSON_KEY_URI_PATH); + if (NULL == uri_path) { + ERR("Invalid uri path"); + g_object_unref(parser); + return NULL; + } + server_id = json_object_get_string_member(rsrc_obj, IC_JSON_KEY_SERVERID); if (NULL == server_id) { ERR("Invalid Server ID"); + g_object_unref(parser); return NULL; } /* parse resources type and interfaces */ property_obj = json_object_get_object_member(rsrc_obj, IC_JSON_KEY_PROPERTY); if (property_obj) { - ret = icl_repr_parse_resource_property(property_obj, &res_types, &ifaces); + ret = icl_repr_parse_resource_property(property_obj, &res_types, &ifaces, + &observable); if (IOTCON_ERROR_NONE != ret) { ERR("icl_repr_parse_resource_property() Fail(%d)", ret); + g_object_unref(parser); return NULL; } } @@ -340,6 +351,7 @@ iotcon_client_h icl_client_parse_resource_object(JsonParser *parser, char *json_ if (NULL == client) { ERR("iotcon_client_new() Fail"); + g_object_unref(parser); return NULL; } client->ref_count = 1; @@ -348,9 +360,12 @@ iotcon_client_h icl_client_parse_resource_object(JsonParser *parser, char *json_ if (NULL == client->sid) { ERR("strdup(sid) Fail(%d)", errno); iotcon_client_free(client); + g_object_unref(parser); return NULL; } client->conn_type = conn_type; + g_object_unref(parser); + return client; } diff --git a/lib/icl-client.h b/lib/icl-client.h index 7f5a59f..74de0d6 100644 --- a/lib/icl-client.h +++ b/lib/icl-client.h @@ -35,7 +35,7 @@ struct icl_remote_resource { unsigned int observe_sub_id; }; -iotcon_client_h icl_client_parse_resource_object(JsonParser *parser, char *json_string, +iotcon_client_h icl_client_parse_resource_object(const char *json_string, const char *host, iotcon_connectivity_type_e conn_type); #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__ */ diff --git a/lib/icl-dbus-type.c b/lib/icl-dbus-type.c index f07bcd7..8c0f1f7 100644 --- a/lib/icl-dbus-type.c +++ b/lib/icl-dbus-type.c @@ -59,8 +59,7 @@ GVariant* icl_dbus_notimsg_to_gvariant(struct icl_notify_msg *msg) g_variant_builder_init(&builder, G_VARIANT_TYPE("a(is)")); if (msg) { - /* TODO Make repr_json using interface */ - repr_json = icl_repr_generate_json(msg->repr, false); + repr_json = icl_repr_generate_json(msg->repr, false, true); if (NULL == repr_json) { ERR("icl_repr_generate_json() Fail"); g_variant_builder_clear(&builder); @@ -93,7 +92,7 @@ GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response) } /* TODO Make repr_json using interface */ - repr_json = icl_repr_generate_json(response->repr, false); + repr_json = icl_repr_generate_json(response->repr, false, false); if (NULL == repr_json) { ERR("icl_repr_generate_json() Fail"); g_variant_builder_clear(&options); diff --git a/lib/icl-dbus.c b/lib/icl-dbus.c index f982fa9..3e0544b 100644 --- a/lib/icl-dbus.c +++ b/lib/icl-dbus.c @@ -286,4 +286,3 @@ void icl_dbus_stop() icl_dbus_object = NULL; _icl_dbus_unref(); } - diff --git a/lib/icl-repr.c b/lib/icl-repr.c index 65af40e..2514593 100644 --- a/lib/icl-repr.c +++ b/lib/icl-repr.c @@ -14,7 +14,9 @@ * limitations under the License. */ +#include #include +#include #include #include #include @@ -27,6 +29,7 @@ #include "icl.h" #include "icl-resource.h" #include "icl-resource-types.h" +#include "icl-response.h" #include "icl-repr-list.h" #include "icl-repr-value.h" #include "icl-repr-obj.h" @@ -241,18 +244,19 @@ static JsonObject* _icl_repr_data_generate_json(iotcon_repr_h cur_repr, int i, ret, ifaces; char *iface_str; const char *uri_path; - JsonObject *repr_obj = NULL; unsigned int rt_count = 0; + JsonObject *repr_obj = NULL; JsonObject *prop_obj = NULL; iotcon_resource_types_h resource_types = NULL; RETV_IF(NULL == cur_repr, NULL); - if (0 < iotcon_repr_get_keys_count(cur_repr)) { + /* representation attributes are included if interface type is one of None + * or Default Parent or Batch Child */ + if (ICL_VISIBILITY_REPR == cur_repr->visibility && 0 < iotcon_repr_get_keys_count(cur_repr)) { repr_obj = icl_obj_to_json(cur_repr); if (NULL == repr_obj) { ERR("icl_obj_to_json() Fail"); - json_object_unref(repr_obj); return NULL; } } else { @@ -267,48 +271,52 @@ static JsonObject* _icl_repr_data_generate_json(iotcon_repr_h cur_repr, if (cur_repr->res_types) rt_count = icl_resource_types_get_length(cur_repr->res_types); - if (0 < rt_count || IOTCON_INTERFACE_NONE != cur_repr->interfaces) { - prop_obj = json_object_new(); - json_object_set_object_member(repr_obj, IC_JSON_KEY_PROPERTY, prop_obj); - } - - if (0 < rt_count) { - JsonArray *rt_array = json_array_new(); - - ret = iotcon_repr_get_resource_types(cur_repr, &resource_types); - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_repr_get_resource_types() Fail(%d)", ret); - json_object_unref(repr_obj); - return NULL; + /* properties such as resource types and resource interfaces are included + * if interface type is one of None or Default Child or Link Child */ + if (ICL_VISIBILITY_PROP == cur_repr->visibility) { + if (0 < rt_count || IOTCON_INTERFACE_NONE != cur_repr->interfaces) { + prop_obj = json_object_new(); + json_object_set_object_member(repr_obj, IC_JSON_KEY_PROPERTY, prop_obj); } - ret = iotcon_resource_types_foreach(resource_types, _icl_repr_get_res_type_fn, - rt_array); - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_resource_types_foreach() Fail"); - json_object_unref(repr_obj); - return NULL; - } - json_object_set_array_member(prop_obj, IC_JSON_KEY_RESOURCETYPES, rt_array); - } + if (0 < rt_count) { + JsonArray *rt_array = json_array_new(); - if (IOTCON_INTERFACE_NONE != cur_repr->interfaces) { - JsonArray *if_array = json_array_new(); - ifaces = iotcon_repr_get_resource_interfaces(cur_repr); - for (i = 1; i <= ICL_INTERFACE_MAX; i = i << 1) { - if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */ - continue; - ret = ic_utils_convert_interface_flag((ifaces & i), &iface_str); + ret = iotcon_repr_get_resource_types(cur_repr, &resource_types); if (IOTCON_ERROR_NONE != ret) { - ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", i, ret); + ERR("iotcon_repr_get_resource_types() Fail(%d)", ret); json_object_unref(repr_obj); - json_array_unref(if_array); return NULL; } - json_array_add_string_element(if_array, iface_str); + + ret = iotcon_resource_types_foreach(resource_types, _icl_repr_get_res_type_fn, + rt_array); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_resource_types_foreach() Fail"); + json_object_unref(repr_obj); + return NULL; + } + json_object_set_array_member(prop_obj, IC_JSON_KEY_RESOURCETYPES, rt_array); } - json_object_set_array_member(prop_obj, IC_JSON_KEY_INTERFACES, if_array); + if (IOTCON_INTERFACE_NONE != cur_repr->interfaces) { + JsonArray *if_array = json_array_new(); + ifaces = iotcon_repr_get_resource_interfaces(cur_repr); + for (i = 1; i <= ICL_INTERFACE_MAX; i = i << 1) { + if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */ + continue; + ret = ic_utils_convert_interface_flag((ifaces & i), &iface_str); + if (IOTCON_ERROR_NONE != ret) { + ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", i, ret); + json_object_unref(repr_obj); + json_array_unref(if_array); + return NULL; + } + json_array_add_string_element(if_array, iface_str); + } + + json_object_set_array_member(prop_obj, IC_JSON_KEY_INTERFACES, if_array); + } } return repr_obj; @@ -341,34 +349,32 @@ static JsonObject* _icl_repr_data_generate_child(iotcon_repr_h cur_repr, } /* - * A general result : {oc:[{"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]}, + * A general result : [{"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]}, * "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}, * {"href":"/a/child","rep":{"string":"World","double_val":5.7}, - * "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}]} + * "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}] */ -static JsonObject* _icl_repr_generate_json(iotcon_repr_h repr) +static JsonArray* _icl_repr_generate_json_array(iotcon_repr_h repr) { + FN_CALL; + JsonObject *repr_obj; + JsonArray *root_array; unsigned int child_index; unsigned int child_count = 0; - JsonArray *root_array = NULL; - JsonObject *repr_obj, *root_obj; iotcon_repr_h child_repr = NULL; RETV_IF(NULL == repr, NULL); - root_obj = json_object_new(); - root_array = json_array_new(); - if (repr->children) child_count = iotcon_repr_get_children_count(repr); repr_obj = _icl_repr_data_generate_parent(repr, child_index); if (NULL == repr_obj) { ERR("_icl_repr_data_generate_parent() Fali(NULL == repr_obj)"); - json_object_unref(root_obj); - json_array_unref(root_array); return NULL; } + + root_array = json_array_new(); json_array_add_object_element(root_array, repr_obj); for (child_index = 0; child_index < child_count; child_index++) { @@ -376,16 +382,13 @@ static JsonObject* _icl_repr_generate_json(iotcon_repr_h repr) repr_obj = _icl_repr_data_generate_child(child_repr, child_index); if (NULL == repr_obj) { ERR("_icl_repr_data_generate_child() Fali(NULL == repr_obj)"); - json_object_unref(root_obj); json_array_unref(root_array); return NULL; } json_array_add_object_element(root_array, repr_obj); } - json_object_set_array_member(root_obj, IC_JSON_KEY_OC, root_array); - - return root_obj; + return root_array; } /* @@ -394,8 +397,10 @@ static JsonObject* _icl_repr_generate_json(iotcon_repr_h repr) gchar* _icl_repr_obj_to_json(JsonObject *obj, bool set_pretty) { gchar *json_data; + JsonGenerator *gen; JsonNode *root_node = NULL; - JsonGenerator *gen = json_generator_new(); + + gen = json_generator_new(); #if JSON_CHECK_VERSION(0,14,0) json_generator_set_pretty(gen, set_pretty); #endif @@ -414,23 +419,80 @@ gchar* _icl_repr_obj_to_json(JsonObject *obj, bool set_pretty) } -char* icl_repr_generate_json(iotcon_repr_h repr, bool set_pretty) +/* + * returned string SHOULD be released by you + */ +gchar* _icl_repr_array_to_json(JsonArray *array, bool set_pretty) { - char *json_data; - JsonObject *obj; + gchar *json_data; + char json_buf[PATH_MAX] = {0}; + int total_len = 0, json_len = 0; + unsigned int rsrc_count, rsrc_index; - obj = _icl_repr_generate_json(repr); - if (NULL == obj) { - ERR("icl_repr_generate_json() Fail"); + rsrc_count = json_array_get_length(array); + if (0 == rsrc_count) { + ERR("json_array_get_length() Fail"); return NULL; } - json_data = _icl_repr_obj_to_json(obj, set_pretty); - if (NULL == json_data) { - ERR("_icl_repr_obj_to_json() Fail"); + for (rsrc_index = 0; rsrc_index < rsrc_count; rsrc_index++) { + char *repr_str; + JsonObject *repr_obj; + + repr_obj = json_array_get_object_element(array, rsrc_index); + repr_str = _icl_repr_obj_to_json(repr_obj, false); + json_len = snprintf(json_buf + total_len, PATH_MAX, "%s", repr_str); + if (json_len < 0) { + ERR("snprintf(json buffer) Fail"); + free(repr_str); + return NULL; + } + + free(repr_str); + total_len += json_len; + } + + json_data = ic_utils_strdup(json_buf); + + return json_data; +} + + +char* icl_repr_generate_json(iotcon_repr_h repr, bool set_pretty, bool include_oc_key) +{ + FN_CALL; + JsonObject *root_obj = NULL; + JsonArray *rsrc_array; + char *json_data = NULL; + + rsrc_array = _icl_repr_generate_json_array(repr); + if (NULL == rsrc_array) { + ERR("_icl_repr_generate_json_array() Fail"); return NULL; } + if (true == include_oc_key) { + root_obj = json_object_new(); + json_object_set_array_member(root_obj, IC_JSON_KEY_OC, rsrc_array); + json_data = _icl_repr_obj_to_json(root_obj, set_pretty); + if (NULL == json_data) { + ERR("_icl_repr_obj_to_json() Fail"); + json_array_unref(rsrc_array); + return NULL; + } + + json_object_unref(root_obj); + } else { + json_data = _icl_repr_array_to_json(rsrc_array, set_pretty); + if (NULL == json_data) { + ERR("_icl_repr_array_to_json() Fail"); + json_array_unref(rsrc_array); + return NULL; + } + + json_array_unref(rsrc_array); + } + return json_data; } @@ -590,10 +652,13 @@ static int _icl_repr_convert_interface_string(const char *src, iotcon_interface_ } -int icl_repr_parse_resource_property(JsonObject *prop_obj, - iotcon_resource_types_h *types, int *ifaces) +/* + * types SHOULD be released by you + */ +int icl_repr_parse_resource_property(JsonObject *prop_obj, iotcon_resource_types_h *types, + int *ifaces, int *obs) { - int ret; + int ret, observable; int ret_ifaces = IOTCON_INTERFACE_NONE; JsonArray *iface_array, *rtye_array; iotcon_resource_types_h res_types = NULL; @@ -641,8 +706,11 @@ int icl_repr_parse_resource_property(JsonObject *prop_obj, } } + observable = json_object_get_int_member(prop_obj, IC_JSON_KEY_OBSERVABLE); + *types = res_types; *ifaces = ret_ifaces; + *obs = observable; return IOTCON_ERROR_NONE; } @@ -654,7 +722,7 @@ int icl_repr_parse_resource_property(JsonObject *prop_obj, */ iotcon_repr_h icl_repr_parse_json(const char *json_string) { - int ret; + int ret, observable; JsonParser *parser; GError *error = NULL; const char *str_value; @@ -691,12 +759,14 @@ iotcon_repr_h icl_repr_parse_json(const char *json_string) } str_value = json_object_get_string_member(root_obj, IC_JSON_KEY_URI_PATH); - ret = iotcon_repr_set_uri_path(repr, str_value); - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_repr_set_uri_path() Fail(%d)", ret); - iotcon_repr_free(repr); - g_object_unref(parser); - return NULL; + if (str_value) { + ret = iotcon_repr_set_uri_path(repr, str_value); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_repr_set_uri_path() Fail(%d)", ret); + iotcon_repr_free(repr); + g_object_unref(parser); + return NULL; + } } property_obj = json_object_get_object_member(root_obj, IC_JSON_KEY_PROPERTY); @@ -706,7 +776,8 @@ iotcon_repr_h icl_repr_parse_json(const char *json_string) return repr; } - ret = icl_repr_parse_resource_property(property_obj, &res_types, &ifaces); + ret = icl_repr_parse_resource_property(property_obj, &res_types, &ifaces, + &observable); if (IOTCON_ERROR_NONE != ret) { ERR("icl_repr_parse_resource_property() Fail(%d)", ret); iotcon_repr_free(repr); @@ -717,6 +788,7 @@ iotcon_repr_h icl_repr_parse_json(const char *json_string) iotcon_repr_set_resource_types(repr, res_types); iotcon_repr_set_resource_interfaces(repr, ifaces); + iotcon_resource_types_free(res_types); g_object_unref(parser); return repr; @@ -869,5 +941,5 @@ API iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src) API char* iotcon_repr_generate_json(iotcon_repr_h repr) { - return icl_repr_generate_json(repr, TRUE); + return icl_repr_generate_json(repr, true, true); } diff --git a/lib/icl-repr.h b/lib/icl-repr.h index c1ab2cd..d492e70 100644 --- a/lib/icl-repr.h +++ b/lib/icl-repr.h @@ -26,6 +26,7 @@ struct icl_repr_s { char *uri_path; int ref_count; int interfaces; + int visibility; GHashTable *hash_table; GList *children; iotcon_resource_types_h res_types; @@ -42,7 +43,7 @@ struct icl_repr_s { * * @return Generated JSON string, otherwise a null pointer if a parse error */ -char* icl_repr_generate_json(iotcon_repr_h repr, bool set_pretty); +char* icl_repr_generate_json(iotcon_repr_h repr, bool set_pretty, bool include_oc_key); char* icl_repr_json_get_uri_path(const char *json_string); @@ -51,7 +52,7 @@ iotcon_repr_h icl_repr_parse_json(const char *json_string); void icl_repr_inc_ref_count(iotcon_repr_h val); -int icl_repr_parse_resource_property(JsonObject *prop_obj, - iotcon_resource_types_h *types, int *ifaces); +int icl_repr_parse_resource_property(JsonObject *prop_obj, iotcon_resource_types_h *types, + int *ifaces, int *obs); #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */ diff --git a/lib/icl-response.c b/lib/icl-response.c index 0a5c70f..894e32a 100644 --- a/lib/icl-response.c +++ b/lib/icl-response.c @@ -127,6 +127,51 @@ API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e p } +static bool _icl_response_repr_child_fn(iotcon_repr_h child, void *user_data) +{ + int iface = GPOINTER_TO_INT(user_data); + + if (IOTCON_INTERFACE_DEFAULT == iface) + child->visibility = ICL_VISIBILITY_PROP; + else if (IOTCON_INTERFACE_LINK == iface) + child->visibility = ICL_VISIBILITY_PROP; + else if (IOTCON_INTERFACE_BATCH == iface) + child->visibility = ICL_VISIBILITY_REPR; + else + child->visibility = ICL_VISIBILITY_PROP; + + return IOTCON_FUNC_CONTINUE; +} + + +static int _icl_response_check_repr_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; + + DBG("interface type of response : %d", resp->iface); + if (IOTCON_INTERFACE_NONE == resp->iface) + first->visibility = ICL_VISIBILITY_REPR; + else if (IOTCON_INTERFACE_DEFAULT == resp->iface) + first->visibility = ICL_VISIBILITY_REPR; + else + first->visibility = ICL_VISIBILITY_NONE; + + ret = iotcon_repr_foreach_children(first, _icl_response_repr_child_fn, + GINT_TO_POINTER(resp->iface)); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_repr_foreach_children() Fail(%d)", ret); + return ret; + } + + return IOTCON_ERROR_NONE; +} + + API int iotcon_response_send(iotcon_response_h resp) { FN_CALL; @@ -138,6 +183,12 @@ API int iotcon_response_send(iotcon_response_h resp) RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == resp->repr, IOTCON_ERROR_INVALID_PARAMETER); + ret = _icl_response_check_repr_visibility(resp); + if (IOTCON_ERROR_NONE != ret) { + ERR("_icl_response_check_repr_visibility() Fail(%d)", ret); + return ret; + } + arg_response = icl_dbus_response_to_gvariant(resp); ic_dbus_call_send_response_sync(icl_dbus_get_object(), arg_response, &ret, NULL, &error); @@ -155,4 +206,3 @@ API int iotcon_response_send(iotcon_response_h resp) return IOTCON_ERROR_NONE; } - diff --git a/lib/icl-response.h b/lib/icl-response.h index 879c29a..1480d47 100644 --- a/lib/icl-response.h +++ b/lib/icl-response.h @@ -20,6 +20,14 @@ #include "iotcon-constant.h" #include "icl-request.h" + +typedef enum { + ICL_VISIBILITY_NONE = 0, + ICL_VISIBILITY_REPR, + ICL_VISIBILITY_PROP, +} icl_visibility_e; + + struct icl_resource_response { char *new_uri_path; int error_code; -- 2.7.4