(ACR) Modify Presence API
authoryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 06:37:16 +0000 (15:37 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 5 Nov 2015 00:50:18 +0000 (09:50 +0900)
Change-Id: Ic6a0f5045ab97a92c2ac6dc7a7292b75b2117a79
Signed-off-by: youngman <yman.jung@samsung.com>
daemon/icd-ioty-ocprocess.c
daemon/icd-ioty.c
lib/icl-presence.c
lib/icl-remote-resource-caching.c
lib/icl-remote-resource-monitoring.c
lib/include/iotcon-client.h
lib/include/iotcon-constant.h
lib/include/iotcon-internal.h
test/iotcon-test-basic-client.c

index ac6d63aa3158617612efa512d28d48db8c02a7f8..1eca6b5fa6fd0b333534d0f6deb4b82000188d60 100644 (file)
@@ -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);
index 30dec22cd97f423f7dce1edf963b05fbd688e0e7..513401ed3c6cb6bab43c6643cc72a8119ab973d3 100644 (file)
@@ -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();
 
index 5345cd88d49f6e353accfad09f84ad9ac241bf26..e2515db55ee60a167bf2e2ce45efa27db004a21f 100644 (file)
 #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;
 }
index ad686d00a6da72b600bafa37ffe5cb0439d7b3d2..4e3e1582fc117d84570995cd4e5b05c31ab03942 100644 (file)
@@ -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) {
index cbb9584ba627b1f5d8f402a0581391f02c998ee7..d94234746909a61c8147fc548aa5213783470d01 100644 (file)
@@ -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;
        }
 
index e1669c56377b5e8f4f2003d74ed21bab40c75250..3a2e0fffc4a67434308641914800e02ad4081acf 100644 (file)
  */
 
 /**
- * @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().
index 9738b819b5dbb31c017c1d7da09dda87cc2d8791..b6c7853a14be32598ffee56d39a65b509b1ba6d7 100644 (file)
@@ -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.
  *
index d16789e834315241411b5bcc7bcd3d0bd85d7810..f1997a53d496851190a07df14c33adc63a63b06d 100644 (file)
@@ -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);
 
index 9a46524ed99e43708aea4b8f979d284cdfe27a77..11de3e7c620b672ea5e09cc362d0a4950637990e 100644 (file)
@@ -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);