From: sung.goo.kim Date: Mon, 2 Nov 2015 05:16:25 +0000 (+0900) Subject: (ACR) Integrate remote_resource_crud/observe_cb X-Git-Tag: accepted/tizen/mobile/20151201.031626~56 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=117ba4826bf3d4aa0f7fe8762d14f9d2a98ca318;p=platform%2Fcore%2Fiot%2Fiotcon.git (ACR) Integrate remote_resource_crud/observe_cb Change-Id: If03019ad08992a4ae25069ea912b867495c4d12b --- diff --git a/common/ic-dbus.xml b/common/ic-dbus.xml index 2ad4bc2..023a8f0 100644 --- a/common/ic-dbus.xml +++ b/common/ic-dbus.xml @@ -38,7 +38,7 @@ - + diff --git a/daemon/icd-ioty-ocprocess.c b/daemon/icd-ioty-ocprocess.c index 3ca4d8a..ac6d63a 100644 --- a/daemon/icd-ioty-ocprocess.c +++ b/daemon/icd-ioty-ocprocess.c @@ -546,7 +546,6 @@ static int _ocprocess_worker(_ocprocess_cb cb, int type, OCPayload *payload, int return ret; } - static int _ocprocess_parse_oic_result(OCStackResult result) { int res; diff --git a/daemon/icd-ioty.c b/daemon/icd-ioty.c index 0678cb5..668be65 100644 --- a/daemon/icd-ioty.c +++ b/daemon/icd-ioty.c @@ -326,7 +326,6 @@ static int _ioty_get_header_options(GVariantIter *src, int src_size, int icd_ioty_send_response(GVariant *resp) { - char *new_uri_path; GVariant *repr_gvar; GVariantIter *options; OCStackResult ret; @@ -334,8 +333,7 @@ int icd_ioty_send_response(GVariant *resp) int result, error_code, options_size; int64_t request_handle, resource_handle; - g_variant_get(resp, "(&sia(qs)ivxx)", - &new_uri_path, + g_variant_get(resp, "(ia(qs)ivxx)", &error_code, &options, &result, @@ -347,9 +345,6 @@ int icd_ioty_send_response(GVariant *resp) response.resourceHandle = ICD_INT64_TO_POINTER(resource_handle); response.ehResult = (OCEntityHandlerResult)result; - if (OC_EH_RESOURCE_CREATED == response.ehResult) - snprintf(response.resourceUri, sizeof(response.resourceUri), "%s", new_uri_path); - options_size = g_variant_iter_n_children(options); response.numSendVendorSpecificHeaderOptions = options_size; @@ -505,6 +500,8 @@ void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *va case ICD_TIZEN_INFO: ic_dbus_complete_get_tizen_info(icd_dbus_get_object(), invocation, value); break; + default: + INFO("Invalid type(%d)", type); } } diff --git a/daemon/icd-payload.c b/daemon/icd-payload.c index 74327db..0239bbb 100644 --- a/daemon/icd-payload.c +++ b/daemon/icd-payload.c @@ -633,7 +633,6 @@ OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var) cur->next = icd_payload_representation_from_gvariant(child); cur = cur->next; } - return repr; } diff --git a/doc/iotcon_doc.h b/doc/iotcon_doc.h index fa106b7..0976853 100644 --- a/doc/iotcon_doc.h +++ b/doc/iotcon_doc.h @@ -154,8 +154,8 @@ static void _request_handler(iotcon_request_h request, void *user_data) * Example : * @code #include -static void _on_get(iotcon_options_h header_options, iotcon_representation_h recv_repr, - int response_result, void *user_data) +static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err, + iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) { // handle get from response } @@ -344,8 +344,8 @@ static void _request_handler(iotcon_request_h request, void *user_data) ... static iotcon_remote_resource_h door_resource; ... -static void _on_observe(iotcon_options_h header_options, iotcon_representation_h recv_repr, - int response_result, int sequence_number, void *user_data) +static void _on_observe(iotcon_remote_resource_h resource, iotcon_error_e err, + iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) { } ... diff --git a/lib/icl-dbus-type.c b/lib/icl-dbus-type.c index b9c32f9..bdb3362 100644 --- a/lib/icl-dbus-type.c +++ b/lib/icl-dbus-type.c @@ -100,8 +100,7 @@ GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response) return NULL; } - value = g_variant_new("(sia(qs)ivxx)", - ic_utils_dbus_encode_str(response->new_uri_path), + value = g_variant_new("(ia(qs)ivxx)", response->error_code, &options, response->result, diff --git a/lib/icl-remote-resource-caching.c b/lib/icl-remote-resource-caching.c index 036f411..ad686d0 100644 --- a/lib/icl-remote-resource-caching.c +++ b/lib/icl-remote-resource-caching.c @@ -192,17 +192,31 @@ static int _caching_compare_repr(iotcon_representation_h repr1, } static void _caching_get_cb(iotcon_remote_resource_h resource, - iotcon_representation_h repr, - iotcon_options_h options, - int response_result, + iotcon_error_e err, + iotcon_request_type_e request_type, + iotcon_response_h resp, void *user_data) { int ret; + int result; + iotcon_representation_h repr = NULL; iotcon_representation_h cloned_repr; RET_IF(NULL == resource); RET_IF(NULL == resource->caching_handle); - RET_IF(IOTCON_RESPONSE_RESULT_OK != response_result); + RETM_IF(IOTCON_ERROR_NONE != err, "_caching_get Fail(%d)", err); + + ret = iotcon_response_get_result(resp, &result); + if (IOTCON_ERROR_NONE != ret || IOTCON_RESPONSE_RESULT_OK != result) { + ERR("Invalid result (%d)", result); + return; + } + + ret = iotcon_response_get_representation(resp, &repr); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_representation() Fail(%d)", ret); + return; + } ret = _caching_compare_repr(resource->caching_handle->repr, repr); if (IC_EQUAL == ret) { /* same */ diff --git a/lib/icl-remote-resource-crud.c b/lib/icl-remote-resource-crud.c index 007d03f..c30b1e6 100644 --- a/lib/icl-remote-resource-crud.c +++ b/lib/icl-remote-resource-crud.c @@ -28,45 +28,23 @@ #include "icl-dbus.h" #include "icl-dbus-type.h" #include "icl-repr.h" +#include "icl-response.h" #include "icl-remote-resource.h" #include "icl-payload.h" typedef struct { - iotcon_remote_resource_cru_cb cb; + iotcon_remote_resource_response_cb cb; void *user_data; iotcon_remote_resource_h resource; -} icl_on_cru_s; +} icl_on_response_s; -typedef struct { - iotcon_remote_resource_delete_cb cb; - void *user_data; - iotcon_remote_resource_h resource; -} icl_on_delete_s; - -typedef struct { - iotcon_remote_resource_observe_cb cb; - void *user_data; - iotcon_remote_resource_h resource; -} icl_on_observe_s; - -static GList *icl_cru_cb_list = NULL; -static GList *icl_delete_cb_list = NULL; +static GList *icl_crud_cb_list = NULL; void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource) { GList *c; - for (c = icl_cru_cb_list; c; c = c->next) { - icl_on_cru_s *cb_container = c->data; - if (NULL == cb_container) { - ERR("cb_container is NULL"); - continue; - } - if (cb_container->resource == resource) - cb_container->cb = NULL; - } - - for (c = icl_delete_cb_list; c; c = c->next) { - icl_on_delete_s *cb_container = c->data; + for (c = icl_crud_cb_list; c; c = c->next) { + icl_on_response_s *cb_container = c->data; if (NULL == cb_container) { ERR("cb_container is NULL"); continue; @@ -76,72 +54,107 @@ void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource) } } - -static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container) +static int _icl_parse_crud_gvariant(iotcon_request_type_e request_type, + GVariant *gvar, iotcon_response_h *response) { - int res, ret; - iotcon_representation_h repr; - GVariantIter *options; - unsigned short option_id; - char *option_data; - GVariant *repr_gvar; - iotcon_options_h header_options = NULL; - iotcon_remote_resource_cru_cb cb = cb_container->cb; - - g_variant_get(result, "(a(qs)vi)", &options, &repr_gvar, &res); - - icl_cru_cb_list = g_list_remove(icl_cru_cb_list, cb_container); - - if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) { - ret = iotcon_options_create(&header_options); - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_options_create() Fail(%d)", ret); - free(cb_container); - return; + int res; + int ret; + int seq_number = -1; + GVariantIter *options_iter = NULL; + GVariant *repr_gvar = NULL; + iotcon_response_h resp = NULL; + iotcon_options_h options = NULL; + iotcon_representation_h repr = NULL; + + if (IOTCON_REQUEST_OBSERVE == request_type) + g_variant_get(gvar, "(a(qs)vii)", &options_iter, &repr_gvar, &res, &seq_number); + else if (IOTCON_REQUEST_DELETE == request_type) + g_variant_get(gvar, "(a(qs)i)", &options_iter, &res); + else + g_variant_get(gvar, "(a(qs)vi)", &options_iter, &repr_gvar, &res); + + if (options_iter) { + if (g_variant_iter_n_children(options_iter)) { + unsigned short option_id; + char *option_data; + + ret = iotcon_options_create(&options); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_options_create() Fail(%d)", ret); + return ret; + } + while (g_variant_iter_loop(options_iter, "(q&s)", &option_id, &option_data)) + iotcon_options_add(options, option_id, option_data); } - - while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data)) - iotcon_options_add(header_options, option_id, option_data); + g_variant_iter_free(options_iter); } - g_variant_iter_free(options); - repr = icl_representation_from_gvariant(repr_gvar); - if (NULL == repr) { - ERR("icl_representation_from_gvariant() Fail"); - if (header_options) - iotcon_options_destroy(header_options); - free(cb_container); - return; + if (repr_gvar) { + repr = icl_representation_from_gvariant(repr_gvar); + if (NULL == repr) { + ERR("icl_representation_from_gvariant() Fail"); + if (options) + iotcon_options_destroy(options); + return IOTCON_ERROR_SYSTEM; + } } res = icl_dbus_convert_daemon_error(res); - if (cb) - cb(cb_container->resource, repr, header_options, res, - cb_container->user_data); + resp = calloc(1, sizeof(struct icl_resource_response)); + if (NULL == resp) { + ERR("calloc() Fail(%d)", errno); + if (repr) + iotcon_representation_destroy(repr); + if (options) + iotcon_options_destroy(options); + return IOTCON_ERROR_OUT_OF_MEMORY; + } + resp->result = res; + resp->repr = repr; + resp->header_options = options; + resp->seq_number = seq_number; - if (repr) - iotcon_representation_destroy(repr); - if (header_options) - iotcon_options_destroy(header_options); + *response = resp; - free(cb_container); + return IOTCON_ERROR_NONE; } - -static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res, - gpointer user_data) +static void _icl_on_crud_cb(iotcon_request_type_e request_type, + GObject *object, GAsyncResult *g_async_res, icl_on_response_s *cb_container) { + int ret; + iotcon_response_h response = NULL; GVariant *result; GError *error = NULL; - icl_on_cru_s *cb_container = user_data; - ic_dbus_call_get_finish(IC_DBUS(object), &result, g_async_res, &error); + RET_IF(NULL == cb_container); + + icl_crud_cb_list = g_list_remove(icl_crud_cb_list, cb_container); + + switch (request_type) { + case IOTCON_REQUEST_GET: + ic_dbus_call_get_finish(IC_DBUS(object), &result, g_async_res, &error); + break; + case IOTCON_REQUEST_PUT: + ic_dbus_call_put_finish(IC_DBUS(object), &result, g_async_res, &error); + break; + case IOTCON_REQUEST_POST: + ic_dbus_call_post_finish(IC_DBUS(object), &result, g_async_res, &error); + break; + case IOTCON_REQUEST_DELETE: + ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error); + break; + default: + ERR("Invalid type(%d)", request_type); + return; + } + if (error) { - ERR("ic_dbus_call_get_finish() Fail(%s)", error->message); + ERR("ic_dbus_call_finish() Fail(%d, %s)", request_type, error->message); if (cb_container->cb) { int ret = icl_dbus_convert_dbus_error(error->code); - cb_container->cb(cb_container->resource, NULL, NULL, ret, + cb_container->cb(cb_container->resource, ret, request_type, NULL, cb_container->user_data); } g_error_free(error); @@ -149,70 +162,60 @@ static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res, return; } - _icl_on_cru_cb(result, cb_container); -} - - -static void _icl_on_put_cb(GObject *object, GAsyncResult *g_async_res, - gpointer user_data) -{ - GVariant *result; - GError *error = NULL; - icl_on_cru_s *cb_container = user_data; - - ic_dbus_call_put_finish(IC_DBUS(object), &result, g_async_res, &error); - if (error) { - ERR("ic_dbus_call_put_finish() Fail(%s)", error->message); + ret = _icl_parse_crud_gvariant(request_type, result, &response); + if (IOTCON_ERROR_NONE != ret) { + ERR("_icl_parse_crud_gvariant() Fail(%s)", ret); if (cb_container->cb) { - int ret = icl_dbus_convert_dbus_error(error->code); - cb_container->cb(cb_container->resource, NULL, NULL, ret, + cb_container->cb(cb_container->resource, ret, request_type, NULL, cb_container->user_data); } - g_error_free(error); free(cb_container); return; } + if (cb_container->cb) + cb_container->cb(cb_container->resource, IOTCON_ERROR_NONE, request_type, + response, cb_container->user_data); - _icl_on_cru_cb(result, cb_container); + if (response) + iotcon_response_destroy(response); + + free(cb_container); } -static void _icl_on_post_cb(GObject *object, GAsyncResult *g_async_res, +static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res, gpointer user_data) { - GVariant *result; - GError *error = NULL; - icl_on_cru_s *cb_container = user_data; + _icl_on_crud_cb(IOTCON_REQUEST_GET, object, g_async_res, user_data); +} - ic_dbus_call_post_finish(IC_DBUS(object), &result, g_async_res, &error); - if (error) { - ERR("ic_dbus_call_post_finish() Fail(%s)", error->message); - if (cb_container->cb) { - int ret = icl_dbus_convert_dbus_error(error->code); - cb_container->cb(cb_container->resource, NULL, NULL, ret, - cb_container->user_data); - } - g_error_free(error); - free(cb_container); - return; - } - _icl_on_cru_cb(result, cb_container); +static void _icl_on_put_cb(GObject *object, GAsyncResult *g_async_res, + gpointer user_data) +{ + _icl_on_crud_cb(IOTCON_REQUEST_PUT, object, g_async_res, user_data); +} + + +static void _icl_on_post_cb(GObject *object, GAsyncResult *g_async_res, + gpointer user_data) +{ + _icl_on_crud_cb(IOTCON_REQUEST_POST, object, g_async_res, user_data); } API int iotcon_remote_resource_get(iotcon_remote_resource_h resource, - iotcon_query_h query, iotcon_remote_resource_cru_cb cb, void *user_data) + iotcon_query_h query, iotcon_remote_resource_response_cb cb, void *user_data) { GVariant *arg_query; GVariant *arg_remote_resource; - icl_on_cru_s *cb_container; + icl_on_response_s *cb_container; RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS); RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER); - cb_container = calloc(1, sizeof(icl_on_cru_s)); + cb_container = calloc(1, sizeof(icl_on_response_s)); if (NULL == cb_container) { ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; @@ -228,7 +231,7 @@ API int iotcon_remote_resource_get(iotcon_remote_resource_h resource, ic_dbus_call_get(icl_dbus_get_object(), arg_remote_resource, arg_query, NULL, _icl_on_get_cb, cb_container); - icl_cru_cb_list = g_list_append(icl_cru_cb_list, cb_container); + icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container); return IOTCON_ERROR_NONE; } @@ -237,20 +240,20 @@ API int iotcon_remote_resource_get(iotcon_remote_resource_h resource, API int iotcon_remote_resource_put(iotcon_remote_resource_h resource, iotcon_representation_h repr, iotcon_query_h query, - iotcon_remote_resource_cru_cb cb, + iotcon_remote_resource_response_cb cb, void *user_data) { GVariant *arg_repr; GVariant *arg_remote_resource; GVariant *arg_query; - icl_on_cru_s *cb_container; + icl_on_response_s *cb_container; RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS); RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER); - cb_container = calloc(1, sizeof(icl_on_cru_s)); + cb_container = calloc(1, sizeof(icl_on_response_s)); if (NULL == cb_container) { ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; @@ -273,7 +276,7 @@ API int iotcon_remote_resource_put(iotcon_remote_resource_h resource, ic_dbus_call_put(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query, NULL, _icl_on_put_cb, cb_container); - icl_cru_cb_list = g_list_append(icl_cru_cb_list, cb_container); + icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container); return IOTCON_ERROR_NONE; } @@ -282,20 +285,20 @@ API int iotcon_remote_resource_put(iotcon_remote_resource_h resource, API int iotcon_remote_resource_post(iotcon_remote_resource_h resource, iotcon_representation_h repr, iotcon_query_h query, - iotcon_remote_resource_cru_cb cb, + iotcon_remote_resource_response_cb cb, void *user_data) { GVariant *arg_repr; GVariant *arg_query; GVariant *arg_remote_resource; - icl_on_cru_s *cb_container; + icl_on_response_s *cb_container; RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS); RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER); - cb_container = calloc(1, sizeof(icl_on_cru_s)); + cb_container = calloc(1, sizeof(icl_on_response_s)); if (NULL == cb_container) { ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; @@ -318,7 +321,7 @@ API int iotcon_remote_resource_post(iotcon_remote_resource_h resource, ic_dbus_call_post(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query, NULL, _icl_on_post_cb, cb_container); - icl_cru_cb_list = g_list_append(icl_cru_cb_list, cb_container); + icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container); return IOTCON_ERROR_NONE; } @@ -327,69 +330,21 @@ API int iotcon_remote_resource_post(iotcon_remote_resource_h resource, static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res, gpointer user_data) { - int res, ret; - GVariant *result; - char *option_data; - GError *error = NULL; - GVariantIter *options; - unsigned short option_id; - iotcon_options_h header_options = NULL; - - icl_on_delete_s *cb_container = user_data; - iotcon_remote_resource_delete_cb cb = cb_container->cb; - - icl_delete_cb_list = g_list_remove(icl_delete_cb_list, cb_container); - - ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error); - if (error) { - ERR("ic_dbus_call_delete_finish() Fail(%s)", error->message); - if (cb_container->cb) { - ret = icl_dbus_convert_dbus_error(error->code); - cb_container->cb(cb_container->resource, NULL, ret, cb_container->user_data); - } - g_error_free(error); - free(cb_container); - return; - } - g_variant_get(result, "(a(qs)i)", &options, &res); - - if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) { - ret = iotcon_options_create(&header_options); - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_options_create() Fail(%d)", ret); - g_variant_iter_free(options); - free(cb_container); - return; - } - - while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data)) - iotcon_options_add(header_options, option_id, option_data); - } - g_variant_iter_free(options); - - res = icl_dbus_convert_daemon_error(res); - - if (cb) - cb(cb_container->resource, header_options, res, cb_container->user_data); - - if (header_options) - iotcon_options_destroy(header_options); - - free(cb_container); + _icl_on_crud_cb(IOTCON_REQUEST_DELETE, object, g_async_res, user_data); } API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource, - iotcon_remote_resource_delete_cb cb, void *user_data) + iotcon_remote_resource_response_cb cb, void *user_data) { GVariant *arg_remote_resource; - icl_on_delete_s *cb_container; + icl_on_response_s *cb_container; RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS); RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER); - cb_container = calloc(1, sizeof(icl_on_delete_s)); + cb_container = calloc(1, sizeof(icl_on_response_s)); if (NULL == cb_container) { ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; @@ -404,12 +359,11 @@ API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource, ic_dbus_call_delete(icl_dbus_get_object(), arg_remote_resource, NULL, _icl_on_delete_cb, cb_container); - icl_delete_cb_list = g_list_append(icl_delete_cb_list, cb_container); + icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container); return IOTCON_ERROR_NONE; } - static void _icl_on_observe_cb(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -418,59 +372,32 @@ static void _icl_on_observe_cb(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { - int res, ret; - int seq_num; - iotcon_representation_h repr; - GVariantIter *options; - unsigned short option_id; - char *option_data; - GVariant *repr_gvar; - iotcon_options_h header_options = NULL; - - icl_on_observe_s *cb_container = user_data; - iotcon_remote_resource_observe_cb cb = cb_container->cb; - - g_variant_get(parameters, "(a(qs)vii)", &options, &repr_gvar, &res, - &seq_num); - - if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) { - ret = iotcon_options_create(&header_options); - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_options_create() Fail(%d)", ret); - g_variant_iter_free(options); - free(cb_container); - return; - } - - while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data)) - iotcon_options_add(header_options, option_id, option_data); - } - g_variant_iter_free(options); + int ret; + iotcon_response_h response = NULL; + icl_on_response_s *cb_container = user_data; - repr = icl_representation_from_gvariant(repr_gvar); - if (NULL == repr) { - ERR("icl_representation_from_gvariant() Fail"); - if (header_options) - iotcon_options_destroy(header_options); + RET_IF(NULL == cb_container); - free(cb_container); + ret = _icl_parse_crud_gvariant(IOTCON_REQUEST_OBSERVE, parameters, &response); + if (IOTCON_ERROR_NONE != ret) { + ERR("_icl_parse_crud_gvariant() Fail(%d)", ret); + if (cb_container->cb) { + cb_container->cb(cb_container->resource, ret, IOTCON_REQUEST_OBSERVE, NULL, + cb_container->user_data); + } return; } - res = icl_dbus_convert_daemon_error(res); - - if (cb) - cb(cb_container->resource, repr, header_options, res, seq_num, - cb_container->user_data); + if (cb_container->cb) + cb_container->cb(cb_container->resource, IOTCON_ERROR_NONE, IOTCON_REQUEST_OBSERVE, + response, cb_container->user_data); - if (repr) - iotcon_representation_destroy(repr); - if (header_options) - iotcon_options_destroy(header_options); + if (response) + iotcon_response_destroy(response); } -static void _icl_observe_conn_cleanup(icl_on_observe_s *cb_container) +static void _icl_observe_conn_cleanup(icl_on_response_s *cb_container) { cb_container->resource->observe_handle = 0; cb_container->resource->observe_sub_id = 0; @@ -531,19 +458,19 @@ int icl_remote_resource_observer_start(iotcon_remote_resource_h resource, API int iotcon_remote_resource_start_observing(iotcon_remote_resource_h resource, iotcon_observe_type_e observe_type, iotcon_query_h query, - iotcon_remote_resource_observe_cb cb, + iotcon_remote_resource_response_cb cb, void *user_data) { int ret; unsigned int sub_id; int64_t observe_handle; - icl_on_observe_s *cb_container; + icl_on_response_s *cb_container; RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(resource->observe_handle || resource->observe_sub_id, IOTCON_ERROR_ALREADY); - cb_container = calloc(1, sizeof(icl_on_observe_s)); + cb_container = calloc(1, sizeof(icl_on_response_s)); if (NULL == cb_container) { ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; diff --git a/lib/icl-remote-resource-monitoring.c b/lib/icl-remote-resource-monitoring.c index d83d90d..cbb9584 100644 --- a/lib/icl-remote-resource-monitoring.c +++ b/lib/icl-remote-resource-monitoring.c @@ -22,15 +22,24 @@ #include "icl-remote-resource.h" static void _monitoring_get_cb(iotcon_remote_resource_h resource, - iotcon_representation_h repr, - iotcon_options_h options, - int response_result, + iotcon_error_e err, + iotcon_request_type_e request_type, + iotcon_response_h response, void *user_data) { + int ret; + int response_result; iotcon_remote_resource_state_e resource_state; RET_IF(NULL == resource); RET_IF(NULL == resource->monitoring_handle); + RETM_IF(IOTCON_ERROR_NONE != err, "_monitoring_get Fail(%d)", err); + + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } if (IOTCON_RESPONSE_RESULT_OK <= response_result) resource_state = IOTCON_REMOTE_RESOURCE_STATE_ALIVE; diff --git a/lib/icl-response.c b/lib/icl-response.c index 41e63df..da399f3 100644 --- a/lib/icl-response.c +++ b/lib/icl-response.c @@ -61,34 +61,42 @@ API void iotcon_response_destroy(iotcon_response_h resp) if (resp->repr) iotcon_representation_destroy(resp->repr); - if (resp->new_uri_path) - free(resp->new_uri_path); if (resp->header_options) iotcon_options_destroy(resp->header_options); free(resp); } +API int iotcon_response_get_options(iotcon_response_h resp, + iotcon_options_h *options) +{ + RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == resp->header_options, IOTCON_ERROR_NO_DATA); -API int iotcon_response_set_new_uri_path(iotcon_response_h resp, char *new_uri_path) + *options = resp->header_options; + + return IOTCON_ERROR_NONE; +} + +API int iotcon_response_get_representation(iotcon_response_h resp, + iotcon_representation_h *repr) { RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == resp->repr, IOTCON_ERROR_NO_DATA); - 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); - return IOTCON_ERROR_OUT_OF_MEMORY; - } - } else { - resp->new_uri_path = NULL; - } + *repr = resp->repr; return IOTCON_ERROR_NONE; + } +API int iotcon_response_get_result(iotcon_response_h resp, int *result) +{ + RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER); + + *result = resp->result; + + return IOTCON_ERROR_NONE; +} API int iotcon_response_set_result(iotcon_response_h resp, iotcon_response_result_e result) diff --git a/lib/icl-response.h b/lib/icl-response.h index bd504e5..070ed87 100644 --- a/lib/icl-response.h +++ b/lib/icl-response.h @@ -28,11 +28,11 @@ typedef enum { struct icl_resource_response { - char *new_uri_path; int error_code; + int seq_number; iotcon_options_h header_options; iotcon_interface_e iface; - iotcon_response_result_e result; + int result; iotcon_representation_h repr; int64_t oic_request_h; int64_t oic_resource_h; diff --git a/lib/include/iotcon-notimsg.h b/lib/include/iotcon-notimsg.h index fc029e5..ff51cea 100644 --- a/lib/include/iotcon-notimsg.h +++ b/lib/include/iotcon-notimsg.h @@ -49,7 +49,7 @@ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory * - * @see iotcon_remote_resource_observe_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_start_observing() * @see iotcon_remote_resource_observer_stop() * @see iotcon_resource_notify() diff --git a/lib/include/iotcon-remote-resource.h b/lib/include/iotcon-remote-resource.h index d8f7068..290740d 100644 --- a/lib/include/iotcon-remote-resource.h +++ b/lib/include/iotcon-remote-resource.h @@ -104,33 +104,37 @@ void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource); */ int iotcon_remote_resource_clone(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest); + /** - * @brief Specifies the type of function passed to iotcon_remote_resource_start_observing(). - * @details Called when a client receive notifications from a server. The @a response_result could be one of #iotcon_response_result_e. + * @brief Specifies the type of function passed to iotcon_remote_resource_start_observing(), + * iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post(), + * iotcon_remote_resource_delete(). + * @details The @a err could be one of #iotcon_error_e. + * The @a request_type could be one of #iotcon_request_type_e. * * @since_tizen 3.0 * * @param[in] resource The handle of the resource - * @param[in] repr The handle of the representation - * @param[in] options The handle of the header options - * @param[in] response_result The response result code - * @param[in] sequence_number The sequence of notifications from server. + * @param[in] err The error code + * @param[in] request_type The request type + * @param[in] response The handle of the response * @param[in] user_data The user data passed from the callback registration function * - * @pre The callback must be registered using iotcon_remote_resource_start_observing() + * @pre The callback must be registered using iotcon_remote_resource_start_observing(), + * iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post(), + * iotcon_remote_resource_delete() * * @see iotcon_remote_resource_start_observing() */ -typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resource, - iotcon_representation_h repr, - iotcon_options_h options, - int response_result, - int sequence_number, +typedef void (*iotcon_remote_resource_response_cb)(iotcon_remote_resource_h resource, + iotcon_error_e err, + iotcon_request_type_e request_type, + iotcon_response_h response, void *user_data); /** * @brief Sets observation on the resource - * @details When server sends notification message, iotcon_remote_resource_observe_cb() will be called. + * @details When server sends notification message, iotcon_remote_resource_response_cb() will be called. * The @a observe_type could be one of #iotcon_observe_type_e. * * @since_tizen 3.0 @@ -151,9 +155,9 @@ typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resou * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @post When the @a resource receive notification message, iotcon_remote_resource_observe_cb() will be called. + * @post When the @a resource receive notification message, iotcon_remote_resource_response_cb() will be called. * - * @see iotcon_remote_resource_observe_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_observer_stop() * @see iotcon_notimsg_create() * @see iotcon_resource_notify() @@ -161,7 +165,7 @@ typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resou int iotcon_remote_resource_start_observing(iotcon_remote_resource_h resource, iotcon_observe_type_e observe_type, iotcon_query_h query, - iotcon_remote_resource_observe_cb cb, + iotcon_remote_resource_response_cb cb, void *user_data); /** @@ -180,7 +184,7 @@ int iotcon_remote_resource_start_observing(iotcon_remote_resource_h resource, * @retval #IOTCON_ERROR_SYSTEM System error * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @see iotcon_remote_resource_observe_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_start_observing() * @see iotcon_notimsg_create() * @see iotcon_resource_notify() @@ -188,32 +192,8 @@ int iotcon_remote_resource_start_observing(iotcon_remote_resource_h resource, int iotcon_remote_resource_observer_stop(iotcon_remote_resource_h resource); /** - * @brief Specifies the type of function passed to iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post() - * @details The @a response_result could be one of #iotcon_response_result_e. - * - * @since_tizen 3.0 - * - * @param[in] resource The handle of the resource - * @param[in] repr The handle of the representation - * @param[in] options The handle of the header options - * @param[in] response_result The response result code (Lesser than 0 on fail, otherwise a response result value) - * @param[in] user_data The user data to pass to the function - * - * @pre The callback must be registered using iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post() - * - * @see iotcon_remote_resource_get() - * @see iotcon_remote_resource_put() - * @see iotcon_remote_resource_post() - */ -typedef void (*iotcon_remote_resource_cru_cb)(iotcon_remote_resource_h resource, - iotcon_representation_h repr, - iotcon_options_h options, - int response_result, - void *user_data); - -/** * @brief Gets the attributes of a resource. - * @details When server sends response on get request, iotcon_remote_resource_cru_cb() will be called. + * @details When server sends response on get request, iotcon_remote_resource_response_cb() will be called. * * @since_tizen 3.0 * @privlevel public @@ -231,18 +211,18 @@ typedef void (*iotcon_remote_resource_cru_cb)(iotcon_remote_resource_h resource, * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @post When the client receive get response, iotcon_remote_resource_cru_cb() will be called. + * @post When the client receive get response, iotcon_remote_resource_response_cb() will be called. * - * @see iotcon_remote_resource_cru_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_put() * @see iotcon_remote_resource_post() */ int iotcon_remote_resource_get(iotcon_remote_resource_h resource, iotcon_query_h query, - iotcon_remote_resource_cru_cb cb, void *user_data); + iotcon_remote_resource_response_cb cb, void *user_data); /** * @brief Sets the representation of a resource (via PUT) - * @details When server sends response on put request, iotcon_remote_resource_cru_cb() will be called. + * @details When server sends response on put request, iotcon_remote_resource_response_cb() will be called. * * @since_tizen 3.0 * @privlevel public @@ -261,21 +241,21 @@ int iotcon_remote_resource_get(iotcon_remote_resource_h resource, iotcon_query_h * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @post When the client receive put response, iotcon_remote_resource_cru_cb() will be called. + * @post When the client receive put response, iotcon_remote_resource_response_cb() will be called. * - * @see iotcon_remote_resource_cru_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_get() * @see iotcon_remote_resource_post() */ int iotcon_remote_resource_put(iotcon_remote_resource_h resource, iotcon_representation_h repr, iotcon_query_h query, - iotcon_remote_resource_cru_cb cb, + iotcon_remote_resource_response_cb cb, void *user_data); /** * @brief Posts on a resource - * @details When server sends response on post request, iotcon_remote_resource_cru_cb() will be called. + * @details When server sends response on post request, iotcon_remote_resource_response_cb() will be called. * * @since_tizen 3.0 * @privlevel public @@ -294,41 +274,21 @@ int iotcon_remote_resource_put(iotcon_remote_resource_h resource, * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @post When the client receive post response, iotcon_remote_resource_cru_cb() will be called. + * @post When the client receive post response, iotcon_remote_resource_response_cb() will be called. * - * @see iotcon_remote_resource_cru_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_get() * @see iotcon_remote_resource_put() */ int iotcon_remote_resource_post(iotcon_remote_resource_h resource, iotcon_representation_h repr, iotcon_query_h query, - iotcon_remote_resource_cru_cb cb, - void *user_data); - -/** - * @brief Specifies the type of function passed to iotcon_remote_resource_delete() - * @details The @a response_result could be one of #iotcon_response_result_e. - * - * @since_tizen 3.0 - * - * @param[in] resource The handle of the resource - * @param[in] options The handle of the header options - * @param[in] response_result The response result code - * @param[in] user_data The user data to pass to the function - * - * @pre The callback must be registered using iotcon_remote_resource_delete() - * - * @see iotcon_remote_resource_delete() - */ -typedef void (*iotcon_remote_resource_delete_cb)(iotcon_remote_resource_h resource, - iotcon_options_h options, - int response_result, + iotcon_remote_resource_response_cb cb, void *user_data); /** * @brief Deletes a resource. - * @details When server sends response on delete request, iotcon_remote_resource_delete_cb() will be called. + * @details When server sends response on delete request, iotcon_remote_resource_response_cb() will be called. * * @since_tizen 3.0 * @privlevel public @@ -345,12 +305,12 @@ typedef void (*iotcon_remote_resource_delete_cb)(iotcon_remote_resource_h resour * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @post When the client receive delete response, iotcon_remote_resource_delete_cb() will be called. + * @post When the client receive delete response, iotcon_remote_resource_response_cb() will be called. * - * @see iotcon_remote_resource_delete_cb() + * @see iotcon_remote_resource_response_cb() */ int iotcon_remote_resource_delete(iotcon_remote_resource_h resource, - iotcon_remote_resource_delete_cb cb, void *user_data); + iotcon_remote_resource_response_cb cb, void *user_data); /** * @brief Specifies the type of function passed to iotcon_remote_resource_start_caching(). diff --git a/lib/include/iotcon-resource.h b/lib/include/iotcon-resource.h index 49c254d..1cd6512 100644 --- a/lib/include/iotcon-resource.h +++ b/lib/include/iotcon-resource.h @@ -302,7 +302,7 @@ int iotcon_resource_unbind_child_resource(iotcon_resource_h parent, * @retval #IOTCON_ERROR_SYSTEM System error * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * - * @see iotcon_remote_resource_observe_cb() + * @see iotcon_remote_resource_response_cb() * @see iotcon_remote_resource_start_observing() * @see iotcon_remote_resource_observer_stop() * @see iotcon_notimsg_create() diff --git a/lib/include/iotcon-response.h b/lib/include/iotcon-response.h index d5e0e54..9f5e29e 100644 --- a/lib/include/iotcon-response.h +++ b/lib/include/iotcon-response.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __IOT_CONNECTIVITY_MANAGER_SERVER_RESPONSE_H__ -#define __IOT_CONNECTIVITY_MANAGER_SERVER_RESPONSE_H__ +#ifndef __IOT_CONNECTIVITY_MANAGER_COMMON_RESPONSE_H__ +#define __IOT_CONNECTIVITY_MANAGER_COMMON_RESPONSE_H__ #include @@ -23,8 +23,8 @@ */ /** - * @ingroup CAPI_IOT_CONNECTIVITY_SERVER_MODULE - * @defgroup CAPI_IOT_CONNECTIVITY_SERVER_RESPONSE_MODULE Response + * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE + * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE Response * * @brief Iotcon Response provides API to manage response. * @@ -64,23 +64,60 @@ int iotcon_response_create(iotcon_request_h request, iotcon_response_h *response */ void iotcon_response_destroy(iotcon_response_h resp); + /** - * @brief Sets new uri path into the response + * @brief Gets header options of the response * * @since_tizen 3.0 * * @param[in] resp The handle of the response - * @param[in] new_uri_path New uri path to set + * @param[out] options The handle of the header options * * @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 + * @retval #IOTCON_ERROR_NO_DATA No data * - * @see iotcon_response_create() - * @see iotcon_response_destroy() + * @see iotcon_response_get_representation() + * @see iotcon_response_get_result() */ -int iotcon_response_set_new_uri_path(iotcon_response_h resp, char *new_uri_path); +int iotcon_response_get_options(iotcon_response_h resp, iotcon_options_h *options); + +/** + * @brief Gets representation of the response + * + * @since_tizen 3.0 + * + * @param[in] resp The handle of the response + * @param[out] repr The handle of the representation + * + * @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 + * + * @see iotcon_response_get_options() + * @see iotcon_response_get_result() + */ +int iotcon_response_get_representation(iotcon_response_h resp, iotcon_representation_h *repr); + +/** + * @brief Gets result of the response + * + * @since_tizen 3.0 + * + * @param[in] resp The handle of the response + * @param[out] result The result of the response + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_response_get_options() + * @see iotcon_response_get_representation() + */ +int iotcon_response_get_result(iotcon_response_h resp, int *result); + /** * @brief Sets result into the response @@ -178,4 +215,4 @@ int iotcon_response_send(iotcon_response_h resp); * @} */ -#endif /* __IOT_CONNECTIVITY_MANAGER_SERVER_RESPONSE_H__ */ +#endif /* __IOT_CONNECTIVITY_MANAGER_COMMON_RESPONSE_H__ */ diff --git a/test/iotcon-test-basic-client.c b/test/iotcon-test-basic-client.c index c3e9e9e..2362bbc 100644 --- a/test/iotcon-test-basic-client.c +++ b/test/iotcon-test-basic-client.c @@ -25,12 +25,8 @@ static GList *device_id_list; static const char* const door_uri_path = "/a/door"; -static void _on_observe(iotcon_remote_resource_h resource, - iotcon_representation_h recv_repr, - iotcon_options_h header_options, - int response_result, - int sequence_number, - void *user_data) +static void _on_observe(iotcon_remote_resource_h resource, iotcon_error_e err, + iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) { INFO("_on_observe"); @@ -43,15 +39,25 @@ static void _on_observe(iotcon_remote_resource_h resource, } } -static void _on_delete(iotcon_remote_resource_h resource, iotcon_options_h header_options, - int response_result, void *user_data) +static void _on_delete(iotcon_remote_resource_h resource, iotcon_error_e err, + iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) { - int ret; + int ret, response_result; iotcon_remote_resource_h door_resource = user_data; - RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result - && IOTCON_RESPONSE_RESULT_RESOURCE_DELETED != response_result, - "_on_delete Response error(%d)", response_result); + RETM_IF(IOTCON_ERROR_NONE != err, "_on_delete error(%d)", err); + + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } + + if (IOTCON_RESPONSE_RESULT_OK != response_result + && IOTCON_RESPONSE_RESULT_RESOURCE_DELETED != response_result) { + ERR("_on_delete Response error(%d)", response_result); + return; + } INFO("DELETE request was successful"); /* delete callback operations */ @@ -64,20 +70,37 @@ static void _on_delete(iotcon_remote_resource_h resource, iotcon_options_h heade iotcon_remote_resource_destroy(resource); } -static void _on_post(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr, - iotcon_options_h header_options, int response_result, void *user_data) +static void _on_post(iotcon_remote_resource_h resource, iotcon_error_e err, + iotcon_request_type_e type, iotcon_response_h response, void *user_data) { iotcon_state_h recv_state; char *host, *created_uri_path; - int ret, connectivity_type, ifaces = 0; + int ret, connectivity_type, response_result, ifaces = 0; iotcon_resource_types_h types = NULL; iotcon_remote_resource_h new_door_resource, door_resource; + iotcon_representation_h recv_repr = NULL; + + RETM_IF(IOTCON_ERROR_NONE != err, "_on_post error(%d)", err); + + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } - RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result - && IOTCON_RESPONSE_RESULT_RESOURCE_CREATED != response_result, - "_on_post Response error(%d)", response_result); + if (IOTCON_RESPONSE_RESULT_OK != response_result + && IOTCON_RESPONSE_RESULT_RESOURCE_CREATED != response_result) { + ERR("_on_post Response error(%d)", response_result); + return; + } INFO("POST request was successful"); + ret = iotcon_response_get_representation(response, &recv_repr); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_representation() Fail(%d)", ret); + return; + } + ret = iotcon_representation_get_state(recv_repr, &recv_state); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_representation_get_state() Fail(%d)", ret); @@ -140,14 +163,25 @@ static void _on_post(iotcon_remote_resource_h resource, iotcon_representation_h iotcon_remote_resource_destroy(resource); } -static void _on_put(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr, - iotcon_options_h header_options, int response_result, void *user_data) +static void _on_put(iotcon_remote_resource_h resource, iotcon_error_e err, + iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) { int ret; + int response_result; iotcon_representation_h send_repr; - RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_put Response error(%d)", - response_result); + RETM_IF(IOTCON_ERROR_NONE != err, "_on_put error(%d)", err); + + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } + + if (IOTCON_RESPONSE_RESULT_OK != response_result) { + ERR("_on_put Response error(%d)", response_result); + return; + } INFO("PUT request was successful"); ret = iotcon_representation_create(&send_repr); @@ -164,19 +198,45 @@ static void _on_put(iotcon_remote_resource_h resource, iotcon_representation_h r iotcon_representation_destroy(send_repr); } -static void _on_get(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr, - iotcon_options_h header_options, int response_result, void *user_data) +static void _on_get(iotcon_remote_resource_h resource, + iotcon_error_e err, + iotcon_request_type_e request_type, + iotcon_response_h response, + void *user_data) { int ret; + int response_result; bool opened = true; iotcon_representation_h send_repr; + iotcon_representation_h recv_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); + RETM_IF(IOTCON_ERROR_NONE != err, "_on_get error(%d)", err); INFO("GET request was successful"); + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } + + if (IOTCON_RESPONSE_RESULT_OK != response_result) { + ERR("_on_get Response error(%d)", response_result); + return; + } + + /* get the resource host address */ + char *resource_host = NULL; + iotcon_remote_resource_get_host_address(resource, &resource_host); + INFO("resource host : %s", resource_host); + + ret = iotcon_response_get_representation(response, &recv_repr); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_representation() Fail(%d)", ret); + return; + } + ret = iotcon_representation_get_state(recv_repr, &recv_state); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_representation_get_state() Fail(%d)", ret); @@ -430,6 +490,12 @@ static void _found_resource(iotcon_remote_resource_h resource, int result, return; } + + /* get the resource host address */ + iotcon_remote_resource_get_host_address(resource_clone, &resource_host); + INFO("[%s] resource host : %s", resource_uri_path, resource_host); + + /* send GET Request */ ret = iotcon_remote_resource_get(resource_clone, query, _on_get, NULL); if (IOTCON_ERROR_NONE != ret) diff --git a/test/iotcon-test-repr-client.c b/test/iotcon-test-repr-client.c index 1fa83cb..8394523 100644 --- a/test/iotcon-test-repr-client.c +++ b/test/iotcon-test-repr-client.c @@ -158,24 +158,57 @@ static void _on_get(iotcon_representation_h recv_repr, int response_result) } static void _on_get_2nd(iotcon_remote_resource_h resource, - iotcon_representation_h recv_repr, - iotcon_options_h header_options, - int response_result, + iotcon_error_e err, + iotcon_request_type_e request_type, + iotcon_response_h response, void *user_data) { - _on_get(recv_repr, response_result); + int ret; + int response_result; + iotcon_representation_h recv_repr = NULL; + + RETM_IF(IOTCON_ERROR_NONE != err, "Invalid err(%d)", err); + + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } + + ret = iotcon_response_get_representation(response, &recv_repr); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_representation() Fail(%d)", ret); + return; + } + _on_get(recv_repr, response_result); iotcon_remote_resource_destroy(resource); } static void _on_get_1st(iotcon_remote_resource_h resource, - iotcon_representation_h recv_repr, - iotcon_options_h header_options, - int response_result, + iotcon_error_e err, + iotcon_request_type_e request_type, + iotcon_response_h response, void *user_data) { int ret; + int response_result; iotcon_query_h query_params; + iotcon_representation_h recv_repr = NULL; + + RETM_IF(IOTCON_ERROR_NONE != err, "Invalid err(%d)", err); + + ret = iotcon_response_get_result(response, &response_result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_result() Fail(%d)", ret); + return; + } + + ret = iotcon_response_get_representation(response, &recv_repr); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_response_get_representation() Fail(%d)", ret); + return; + } _on_get(recv_repr, response_result);