From: youngman Date: Tue, 3 Nov 2015 06:37:16 +0000 (+0900) Subject: (ACR) Modify Presence API X-Git-Tag: submit/tizen/20151130.235229~44 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ff99c7e7bb0e953ef4e19c0d23ca73c694bc527;p=platform%2Fcore%2Fiot%2Fiotcon.git (ACR) Modify Presence API Change-Id: Ic6a0f5045ab97a92c2ac6dc7a7292b75b2117a79 Signed-off-by: youngman --- diff --git a/daemon/icd-ioty-ocprocess.c b/daemon/icd-ioty-ocprocess.c index ac6d63a..1eca6b5 100644 --- a/daemon/icd-ioty-ocprocess.c +++ b/daemon/icd-ioty-ocprocess.c @@ -105,6 +105,8 @@ struct icd_presence_context { int result; unsigned int nonce; OCDevAddr *dev_addr; + iotcon_presence_trigger_e trigger; + char *resource_type; }; @@ -800,17 +802,19 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle han static int _worker_presence_cb(void *context) { - FN_CALL; - int ret; GVariant *value; + int ret, conn_type; char addr[PATH_MAX] = {0}; struct icd_presence_context *ctx = context; RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER); snprintf(addr, sizeof(addr), "%s:%d", ctx->dev_addr->addr, ctx->dev_addr->port); + conn_type = icd_ioty_transport_flag_to_conn_type(ctx->dev_addr->adapter, + ctx->dev_addr->flags); - value = g_variant_new("(ius)", ctx->result, ctx->nonce, addr); + value = g_variant_new("(iusiis)", ctx->result, ctx->nonce, addr, conn_type, + ctx->trigger, ic_utils_dbus_encode_str(ctx->resource_type)); ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_PRESENCE, ctx->signum, value); @@ -818,6 +822,7 @@ static int _worker_presence_cb(void *context) ERR("_ocprocess_response_signal() Fail(%d)", ret); /* ctx was allocated from icd_ioty_ocprocess_presence_cb() */ + free(ctx->resource_type); free(ctx->bus_name); free(ctx->dev_addr); free(ctx); @@ -833,7 +838,8 @@ static void _presence_cb_response_error(const char *dest, unsigned int signum, int ret; GVariant *value; - value = g_variant_new("(ius)", ret_val, 0, IC_STR_NULL); + value = g_variant_new("(iusiis)", ret_val, 0, IC_STR_NULL, IOTCON_CONNECTIVITY_ALL, + IOTCON_PRESENCE_TRIGGER_RESOURCE_CREATED, IC_STR_NULL); ret = _ocprocess_response_signal(dest, IC_DBUS_SIGNAL_PRESENCE, signum, value); if (IOTCON_ERROR_NONE != ret) @@ -841,12 +847,37 @@ static void _presence_cb_response_error(const char *dest, unsigned int signum, } +static int _presence_trigger_to_ioty_trigger(OCPresenceTrigger src, + iotcon_presence_trigger_e *dest) +{ + RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER); + + switch (src) { + case OC_PRESENCE_TRIGGER_CREATE: + *dest = IOTCON_PRESENCE_TRIGGER_RESOURCE_CREATED; + break; + case OC_PRESENCE_TRIGGER_CHANGE: + *dest = IOTCON_PRESENCE_TRIGGER_RESOURCE_UPDATED; + break; + case OC_PRESENCE_TRIGGER_DELETE: + *dest = IOTCON_PRESENCE_TRIGGER_RESOURCE_DESTROYED; + break; + default: + ERR("Invalid trigger(%d)", src); + return IOTCON_ERROR_INVALID_PARAMETER; + } + + return IOTCON_ERROR_NONE; +} + + OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle handle, OCClientResponse *resp) { FN_CALL; int ret; OCDevAddr *dev_addr; + OCPresencePayload *payload; icd_sig_ctx_s *sig_context = ctx; struct icd_presence_context *presence_ctx; @@ -871,9 +902,18 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha } memcpy(dev_addr, &resp->devAddr, sizeof(OCDevAddr)); + payload = (OCPresencePayload*)resp->payload; + switch (resp->result) { case OC_STACK_OK: presence_ctx->result = IOTCON_PRESENCE_OK; + ret = _presence_trigger_to_ioty_trigger(payload->trigger, &presence_ctx->trigger); + if (IOTCON_ERROR_NONE != ret) { + ERR("_presence_trigger_to_ioty_trigger() Fail(%d)", ret); + _presence_cb_response_error(sig_context->bus_name, sig_context->signum, ret); + free(presence_ctx); + return OC_STACK_KEEP_TRANSACTION; + } break; case OC_STACK_PRESENCE_STOPPED: presence_ctx->result = IOTCON_PRESENCE_STOPPED; @@ -892,10 +932,14 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha presence_ctx->nonce = resp->sequenceNumber; presence_ctx->dev_addr = dev_addr; + if (payload->resourceType) + presence_ctx->resource_type = strdup(payload->resourceType); + ret = _ocprocess_worker_start(_worker_presence_cb, presence_ctx); if (IOTCON_ERROR_NONE != ret) { ERR("_ocprocess_worker_start() Fail(%d)", ret); _presence_cb_response_error(sig_context->bus_name, sig_context->signum, ret); + free(presence_ctx->resource_type); free(presence_ctx->bus_name); free(presence_ctx->dev_addr); free(presence_ctx); diff --git a/daemon/icd-ioty.c b/daemon/icd-ioty.c index 30dec22..513401e 100644 --- a/daemon/icd-ioty.c +++ b/daemon/icd-ioty.c @@ -1165,12 +1165,8 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type, oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type); - /* In case of IPV4 or IPV6, connectivity type is CT_ADAPTER_IP in iotivity 0.9.2 */ - if (CT_IP_USE_V4 == oic_conn_type && CT_IP_USE_V6 == oic_conn_type) - oic_conn_type = CT_ADAPTER_IP; - icd_ioty_csdk_lock(); - result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, CT_ADAPTER_IP, + result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, oic_conn_type, OC_LOW_QOS, &cbdata, NULL, 0); icd_ioty_csdk_unlock(); diff --git a/lib/icl-presence.c b/lib/icl-presence.c index 5345cd8..e2515db 100644 --- a/lib/icl-presence.c +++ b/lib/icl-presence.c @@ -30,12 +30,25 @@ #define ICL_PRESENCE_TTL_SECONDS_MAX (60 * 60 * 24) /* 60 sec/min * 60 min/hr * 24 hr/day */ typedef struct icl_presence { + char *host_address; + iotcon_connectivity_type_e connectivity_type; + char *resource_type; iotcon_presence_cb cb; void *user_data; - unsigned int id; + unsigned int sub_id; int64_t handle; } icl_presence_s; + +typedef struct icl_presence_response { + char *host_address; + iotcon_connectivity_type_e connectivity_type; + char *resource_type; + iotcon_presence_result_e result; + iotcon_presence_trigger_e trigger; +} icl_presence_response_s; + + API int iotcon_start_presence(unsigned int time_to_live) { FN_CALL; @@ -97,36 +110,49 @@ static void _icl_presence_cb(GDBusConnection *connection, gpointer user_data) { FN_CALL; - int res; unsigned int nonce; - char *host_address; - icl_presence_s *presence_container = user_data; - iotcon_presence_cb cb = presence_container->cb; + char *host_address, *resource_type; + int res, connectivity_type, trigger; + icl_presence_s *presence = user_data; + iotcon_presence_cb cb = presence->cb; + icl_presence_response_s response = {0}; + + g_variant_get(parameters, "(iu&sii&s)", &res, &nonce, &host_address, + &connectivity_type, &trigger, &resource_type); - g_variant_get(parameters, "(iu&s)", &res, &nonce, &host_address); + if (res < IOTCON_ERROR_NONE && cb) + cb(presence, icl_dbus_convert_daemon_error(res), NULL, presence->user_data); - res = icl_dbus_convert_daemon_error(res); + DBG("presence nonce : %d", nonce); + + response.host_address = host_address; + response.connectivity_type = connectivity_type; + response.resource_type = ic_utils_dbus_decode_str(resource_type); + response.result = res; + response.trigger = trigger; if (cb) - cb(res, nonce, host_address, presence_container->user_data); + cb(presence, IOTCON_ERROR_NONE, &response, presence->user_data); } static void _icl_presence_conn_cleanup(icl_presence_s *presence) { - presence->id = 0; + presence->sub_id = 0; if (presence->handle) { presence->handle = 0; return; } + free(presence->resource_type); + free(presence->host_address); free(presence); } /* The length of resource_type should be less than or equal to 61. */ -API int iotcon_subscribe_presence(const char *host_address, +API int iotcon_add_presence_cb(const char *host_address, iotcon_connectivity_type_e connectivity_type, const char *resource_type, iotcon_presence_cb cb, @@ -138,7 +164,7 @@ API int iotcon_subscribe_presence(const char *host_address, unsigned int sub_id; int signal_number, ret; char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0}; - icl_presence_s *presence_container; + icl_presence_s *presence; RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER); @@ -151,8 +177,8 @@ API int iotcon_subscribe_presence(const char *host_address, signal_number = icl_dbus_generate_signal_number(); - presence_container = calloc(1, sizeof(icl_presence_s)); - if (NULL == presence_container) { + presence = calloc(1, sizeof(icl_presence_s)); + if (NULL == presence) { ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; } @@ -164,46 +190,53 @@ API int iotcon_subscribe_presence(const char *host_address, connectivity_type, resource_type, signal_number, - &(presence_container->handle), + &(presence->handle), NULL, &error); if (error) { ERR("ic_dbus_call_subscribe_presence_sync() Fail(%s)", error->message); ret = icl_dbus_convert_dbus_error(error->code); g_error_free(error); - free(presence_container); + free(presence); return ret; } - if (0 == presence_container->handle) { + if (0 == presence->handle) { ERR("iotcon-daemon Fail"); - free(presence_container); + free(presence); return IOTCON_ERROR_IOTIVITY; } snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PRESENCE, signal_number); - presence_container->cb = cb; - presence_container->user_data = user_data; + presence->cb = cb; + presence->user_data = user_data; + + presence->host_address = ic_utils_strdup(host_address); + presence->connectivity_type = connectivity_type; + if (resource_type) + presence->resource_type = strdup(resource_type); - sub_id = icl_dbus_subscribe_signal(signal_name, presence_container, + sub_id = icl_dbus_subscribe_signal(signal_name, presence, _icl_presence_conn_cleanup, _icl_presence_cb); if (0 == sub_id) { ERR("icl_dbus_subscribe_signal() Fail"); - free(presence_container); + free(presence->resource_type); + free(presence->host_address); + free(presence); return IOTCON_ERROR_DBUS; } - presence_container->id = sub_id; + presence->sub_id = sub_id; - *presence_handle = presence_container; + *presence_handle = presence; return IOTCON_ERROR_NONE; } -API int iotcon_unsubscribe_presence(iotcon_presence_h presence) +API int iotcon_remove_presence_cb(iotcon_presence_h presence) { FN_CALL; int ret; @@ -211,8 +244,10 @@ API int iotcon_unsubscribe_presence(iotcon_presence_h presence) RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER); - if (0 == presence->id) { /* disconnected iotcon dbus */ + if (0 == presence->sub_id) { /* disconnected iotcon dbus */ WARN("Invalid Presence handle"); + free(presence->resource_type); + free(presence->host_address); free(presence); return IOTCON_ERROR_NONE; } @@ -237,7 +272,107 @@ API int iotcon_unsubscribe_presence(iotcon_presence_h presence) } presence->handle = 0; - icl_dbus_unsubscribe_signal(presence->id); + icl_dbus_unsubscribe_signal(presence->sub_id); + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_get_host_address(iotcon_presence_h presence, char **host_address) +{ + RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER); + + *host_address = presence->host_address; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_get_connectivity_type(iotcon_presence_h presence, + int *connectivity_type) +{ + RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER); + + *connectivity_type = presence->connectivity_type; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_get_resource_type(iotcon_presence_h presence, + char **resource_type) +{ + RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER); + + *resource_type = presence->resource_type; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_response_get_host_address(iotcon_presence_response_h response, + char **host_address) +{ + RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER); + + *host_address = response->host_address; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_response_get_connectivity_type( + iotcon_presence_response_h response, int *connectivity_type) +{ + RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER); + + *connectivity_type = response->connectivity_type; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_response_get_resource_type(iotcon_presence_response_h response, + char **resource_type) +{ + RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER); + + *resource_type = response->resource_type; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_response_get_result(iotcon_presence_response_h response, + int *result) +{ + RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == result, IOTCON_ERROR_INVALID_PARAMETER); + + *result = response->result; + + return IOTCON_ERROR_NONE; +} + + +API int iotcon_presence_response_get_trigger(iotcon_presence_response_h response, + int *trigger) +{ + RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == trigger, IOTCON_ERROR_INVALID_PARAMETER); + + if (IOTCON_PRESENCE_OK != response->result) { + ERR("trigger is valid if IOTCON_PRESENCE_OK"); + return IOTCON_ERROR_INVALID_PARAMETER; + } + + *trigger = response->trigger; return IOTCON_ERROR_NONE; } diff --git a/lib/icl-remote-resource-caching.c b/lib/icl-remote-resource-caching.c index ad686d0..4e3e158 100644 --- a/lib/icl-remote-resource-caching.c +++ b/lib/icl-remote-resource-caching.c @@ -204,7 +204,7 @@ static void _caching_get_cb(iotcon_remote_resource_h resource, RET_IF(NULL == resource); RET_IF(NULL == resource->caching_handle); - RETM_IF(IOTCON_ERROR_NONE != err, "_caching_get Fail(%d)", err); + 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) { diff --git a/lib/icl-remote-resource-monitoring.c b/lib/icl-remote-resource-monitoring.c index cbb9584..d942347 100644 --- a/lib/icl-remote-resource-monitoring.c +++ b/lib/icl-remote-resource-monitoring.c @@ -33,7 +33,7 @@ static void _monitoring_get_cb(iotcon_remote_resource_h resource, RET_IF(NULL == resource); RET_IF(NULL == resource->monitoring_handle); - RETM_IF(IOTCON_ERROR_NONE != err, "_monitoring_get Fail(%d)", err); + RETM_IF(IOTCON_ERROR_NONE != err, "_monitoring_get() Fail(%d)", err); ret = iotcon_response_get_result(response, &response_result); if (IOTCON_ERROR_NONE != ret) { @@ -72,14 +72,15 @@ static gboolean _monitoring_get_timer(gpointer user_data) } -static void _monitoring_presence_cb(int result, unsigned int nonce, - const char *host_address, void *user_data) +static void _monitoring_presence_cb(iotcon_presence_h presence, iotcon_error_e err, + iotcon_presence_response_h response, void *user_data) { unsigned int get_timer_id; iotcon_remote_resource_h resource = user_data; RET_IF(NULL == resource); RET_IF(NULL == resource->monitoring_handle); + RETM_IF(IOTCON_ERROR_NONE != err, "_monitoring_presence() Fail(%d)", err); g_source_remove(resource->monitoring_handle->get_timer_id); @@ -154,10 +155,10 @@ API int iotcon_remote_resource_start_monitoring(iotcon_remote_resource_h resourc return ret; } - ret = iotcon_subscribe_presence(host_address, connectivity_type, NULL, + ret = iotcon_add_presence_cb(host_address, connectivity_type, NULL, _monitoring_presence_cb, resource, &resource->monitoring_handle->presence); if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_subscribe_presence() Fail(%d)", ret); + ERR("iotcon_add_presence_cb() Fail(%d)", ret); g_source_remove(resource->monitoring_handle->get_timer_id); free(resource->monitoring_handle); resource->monitoring_handle = NULL; @@ -182,9 +183,9 @@ API int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource INFO("Stop Monitoring"); /* Device Presence */ - ret = iotcon_unsubscribe_presence(resource->monitoring_handle->presence); + ret = iotcon_remove_presence_cb(resource->monitoring_handle->presence); if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_unsubscribe_presence() Fail(%d)", ret); + ERR("iotcon_remove_presence_cb() Fail(%d)", ret); return ret; } diff --git a/lib/include/iotcon-client.h b/lib/include/iotcon-client.h index e1669c5..3a2e0ff 100644 --- a/lib/include/iotcon-client.h +++ b/lib/include/iotcon-client.h @@ -39,25 +39,25 @@ */ /** - * @brief Specifies the type of function passed to iotcon_subscribe_presence(). + * @brief Specifies the type of function passed to iotcon_add_presence_cb(). * @details Called when client receive presence events from the server. * * @since_tizen 3.0 * - * @param[in] result The result code of server's presence - * @param[in] nonce Current nonce of server's presence - * @param[in] host_address The address or addressable name of server + * @param[in] presence The presence handle + * @param[in] err The error code(0 on success, otherwise a negative error value) + * @param[in] response The presence response handle * @param[in] user_data The user data to pass to the function * - * @pre The callback must be registered using iotcon_subscribe_presence() + * @pre The callback must be registered using iotcon_add_presence_cb() * - * @see iotcon_subscribe_presence() + * @see iotcon_add_presence_cb() */ -typedef void (*iotcon_presence_cb)(int result, unsigned int nonce, - const char *host_address, void *user_data); +typedef void (*iotcon_presence_cb)(iotcon_presence_h presence, iotcon_error_e err, + iotcon_presence_response_h response, void *user_data); /** - * @brief Subscribes to a server to receive presence events. + * @brief Adds callback to a server to receive presence events. * @details Request to receive presence to an interested server's resource with @a resource_type.\n * If succeed to subscribe, iotcon_presence_cb() will be invoked when the server sends presence\n * A server sends presence events when adds/removes/alters a resource or start/stop presence. @@ -91,10 +91,10 @@ typedef void (*iotcon_presence_cb)(int result, unsigned int nonce, * * @see iotcon_start_presence() * @see iotcon_stop_presence() - * @see iotcon_unsubscribe_presence() + * @see iotcon_remove_presence_cb() * @see iotcon_presence_cb() */ -int iotcon_subscribe_presence(const char *host_address, +int iotcon_add_presence_cb(const char *host_address, iotcon_connectivity_type_e connectivity_type, const char *resource_type, iotcon_presence_cb cb, @@ -102,9 +102,9 @@ int iotcon_subscribe_presence(const char *host_address, iotcon_presence_h *presence_handle); /** - * @brief Unsubscribes to a server's presence events. + * @brief Removes callback to a server's presence events. * @details Request not to receive server's presence any more. - * + /* * @since_tizen 3.0 * @privlevel public * @privilege %http://tizen.org/privilege/internet @@ -120,10 +120,174 @@ int iotcon_subscribe_presence(const char *host_address, * * @see iotcon_start_presence() * @see iotcon_stop_presence() - * @see iotcon_subscribe_presence() + * @see iotcon_add_presence_cb() * @see iotcon_presence_cb() */ -int iotcon_unsubscribe_presence(iotcon_presence_h presence_handle); +int iotcon_remove_presence_cb(iotcon_presence_h presence_handle); + +/** + * @brief Gets host address from the presence handle + * + * @since_tizen 3.0 + * + * @remarks @a host_address must not be released using free(). + * + * @param[in] presence The handle of the presence + * @param[out] host_address The host address of the presence + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_get_connectivity_type() + * @see iotcon_presence_get_resource_type() + */ +int iotcon_presence_get_host_address(iotcon_presence_h presence, char **host_address); + +/** + * @brief Gets connectivity type from the presence handle + * @details The @a connectivity_type could be one of #iotcon_connectivity_type_e. + * + * @since_tizen 3.0 + * + * @param[in] presence The handle of the presence + * @param[out] connectivity_type The connectivity type of the presence + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_get_host_address() + * @see iotcon_presence_get_resource_type() + */ +int iotcon_presence_get_connectivity_type(iotcon_presence_h presence, + int *connectivity_type); + +/** + * @brief Gets resource type from the presence handle + * + * @since_tizen 3.0 + * + * @remarks @a resource_type must not be released using free(). + * + * @param[in] presence The handle of the presence + * @param[out] resource_type The resource type of the presence + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_get_host_address() + * @see iotcon_presence_get_connectivity_type() + */ +int iotcon_presence_get_resource_type(iotcon_presence_h presence, + char **resource_type); + +/** + * @brief Gets result from the presence response handle + * + * @details The @a result could be one of #iotcon_presence_result_e. + * @since_tizen 3.0 + * + * @param[in] response The handle of the presence response + * @param[out] result The result code + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_response_get_trigger() + * @see iotcon_presence_response_get_host_address() + * @see iotcon_presence_response_get_connectivity_type() + * @see iotcon_presence_response_get_resource_type() + */ +int iotcon_presence_response_get_result(iotcon_presence_response_h response, int *result); + +/** + * @brief Gets trigger from the presence response handle + * + * @details The @a trigger could be one of #iotcon_presence_trigger_e. + * @since_tizen 3.0 + * + * @param[in] response The handle of the presence response + * @param[out] trigger The presence trigger value. It is set only if @a result is IOTCON_PRESENCE_OK. + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_response_get_result() + * @see iotcon_presence_response_get_host_address() + * @see iotcon_presence_response_get_connectivity_type() + * @see iotcon_presence_response_get_resource_type() + */ +int iotcon_presence_response_get_trigger(iotcon_presence_response_h response, + int *trigger); + +/** + * @brief Gets host address from the presence response handle + * + * @since_tizen 3.0 + * + * @remarks @a host_address must not be released using free(). + * + * @param[in] response The handle of the presence response + * @param[out] host_address The host address of the presence response + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_response_get_result() + * @see iotcon_presence_response_get_trigger() + * @see iotcon_presence_response_get_connectivity_type() + * @see iotcon_presence_response_get_resource_type() + */ +int iotcon_presence_response_get_host_address(iotcon_presence_response_h response, + char **host_address); + +/** + * @brief Gets connectivity type from the presence response handle + * + * @details The @a connectivity_type could be one of #iotcon_connectivity_type_e. + * @since_tizen 3.0 + * + * @param[in] response The handle of the presence response + * @param[out] connectivity_type The connectivity type of the presence response + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_response_get_result() + * @see iotcon_presence_response_get_trigger() + * @see iotcon_presence_response_get_host_address() + * @see iotcon_presence_response_get_resource_type() + */ +int iotcon_presence_response_get_connectivity_type(iotcon_presence_response_h response, + int *connectivity_type); + +/** + * @brief Gets resource type from the presence response handle + * + * @since_tizen 3.0 + * + * @remarks @a resource_type must not be released using free(). + * + * @param[in] response The handle of the presence response + * @param[out] resource_type The resource type of the presence response + * + * @return 0 on success, otherwise a negative error value. + * @retval #IOTCON_ERROR_NONE Successful + * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see iotcon_presence_response_get_result() + * @see iotcon_presence_response_get_trigger() + * @see iotcon_presence_response_get_host_address() + * @see iotcon_presence_response_get_connectivity_type() + */ +int iotcon_presence_response_get_resource_type(iotcon_presence_response_h response, + char **resource_type); /** * @brief Specifies the type of function passed to iotcon_find_resource(). diff --git a/lib/include/iotcon-constant.h b/lib/include/iotcon-constant.h index 9738b81..b6c7853 100644 --- a/lib/include/iotcon-constant.h +++ b/lib/include/iotcon-constant.h @@ -119,6 +119,15 @@ typedef struct icl_remote_resource* iotcon_remote_resource_h; */ typedef struct icl_presence* iotcon_presence_h; +/** + * @brief The handle of presence response. + * @details @a iotcon_presence_response_h is a handle of presence response subscription.\n + * It is used to get the information of presence response from server. + * + * @since_tizen 3.0 + */ +typedef struct icl_presence_response* iotcon_presence_response_h; + /** * @brief The handle of device information. * @details @a iotcon_device_info_h is a handle of device information. @@ -336,9 +345,19 @@ typedef enum { IOTCON_PRESENCE_OK = 0, /**< Indicates for successful action of presence */ IOTCON_PRESENCE_STOPPED, /**< Indicates for stopped action of presence */ IOTCON_PRESENCE_TIMEOUT, /**< Indicates for no response of presence for some time */ - IOTCON_PRESENCE_ERROR /**< Indicates for some errors of presence */ } iotcon_presence_result_e; +/** + * @brief Enumeration for operation of presence response. + * + * @since_tizen 3.0 + */ +typedef enum { + IOTCON_PRESENCE_TRIGGER_RESOURCE_CREATED, /**< Indicates for resource creation operation of server */ + IOTCON_PRESENCE_TRIGGER_RESOURCE_UPDATED, /**< Indicates for resource update operation of server */ + IOTCON_PRESENCE_TRIGGER_RESOURCE_DESTROYED, /**< Indicates for resource destruction operation of server */ +} iotcon_presence_trigger_e; + /** * @brief Enumeration for types of representation that is able to have. * diff --git a/lib/include/iotcon-internal.h b/lib/include/iotcon-internal.h index d16789e..f1997a5 100644 --- a/lib/include/iotcon-internal.h +++ b/lib/include/iotcon-internal.h @@ -46,8 +46,8 @@ extern "C" { * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * * @see iotcon_stop_presence() - * @see iotcon_subscribe_presence() - * @see iotcon_unsubscribe_presence() + * @see iotcon_add_presence_cb() + * @see iotcon_remove_presence_cb() */ int iotcon_start_presence(unsigned int time_to_live); @@ -67,8 +67,8 @@ int iotcon_start_presence(unsigned int time_to_live); * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied * * @see iotcon_start_presence() - * @see iotcon_subscribe_presence() - * @see iotcon_unsubscribe_presence() + * @see iotcon_add_presence_cb() + * @see iotcon_remove_presence_cb() */ int iotcon_stop_presence(void); diff --git a/test/iotcon-test-basic-client.c b/test/iotcon-test-basic-client.c index 9a46524..11de3e7 100644 --- a/test/iotcon-test-basic-client.c +++ b/test/iotcon-test-basic-client.c @@ -297,13 +297,53 @@ static bool _get_res_type_cb(const char *string, void *user_data) return IOTCON_FUNC_CONTINUE; } -static void _presence_handler(int result, unsigned int nonce, - const char *host_address, void *user_data) +static void _presence_handler(iotcon_presence_h presence, iotcon_error_e err, + iotcon_presence_response_h response, void *user_data) { + char *host_address; + char *resource_type; + int ret, connectivity_type, result, trigger; + + RETM_IF(IOTCON_ERROR_NONE != err, "_presence_handler error(%d)", err); + + ret = iotcon_presence_response_get_result(response, &result); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_presence_response_get_result() Fail(%d)", ret); + return; + } + + if (IOTCON_PRESENCE_OK == result) { + ret = iotcon_presence_response_get_trigger(response, &trigger); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_presence_response_get_trigger() Fail(%d)", ret); + return; + } + } + + ret = iotcon_presence_response_get_host_address(response, &host_address); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_presence_response_get_host_address() Fail(%d)", ret); + return; + } + + ret = iotcon_presence_response_get_connectivity_type(response, &connectivity_type); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_presence_response_get_connectivity_type() Fail(%d)", ret); + return; + } + + ret = iotcon_presence_response_get_resource_type(response, &resource_type); + if (IOTCON_ERROR_NONE != ret) { + ERR("iotcon_presence_response_get_resource_type() Fail(%d)", ret); + return; + } + INFO("_presence_handler"); INFO("result : %d", result); - INFO("nonce : %d", nonce); + if (IOTCON_PRESENCE_OK == result) + INFO("trigger : %d", trigger); INFO("host_address : %s", host_address); + INFO("resource_type : %s", resource_type); } static int _device_id_compare(const void *a, const void *b) @@ -452,10 +492,10 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re return; } - ret = iotcon_subscribe_presence(resource_host, connectivity_type, "core.door", + ret = iotcon_add_presence_cb(resource_host, connectivity_type, "core.door", _presence_handler, NULL, &presence_handle); if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_subscribe_presence() Fail(%d)", ret); + ERR("iotcon_add_presence_cb() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); return; @@ -490,7 +530,6 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re 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);