Reinforce documentation and prevent to send requests to found resources 78/64578/5
authoryoungman <yman.jung@samsung.com>
Mon, 4 Apr 2016 00:26:24 +0000 (09:26 +0900)
committeryoungman <yman.jung@samsung.com>
Mon, 4 Apr 2016 06:04:47 +0000 (15:04 +0900)
Change-Id: Id43d7a3780f8a5bd13bf2cc0cd8a2344407c0d99
Signed-off-by: youngman <yman.jung@samsung.com>
daemon/icd-ioty-ocprocess.c
lib/icl-remote-resource-caching.c
lib/icl-remote-resource-crud.c
lib/icl-remote-resource-monitoring.c
lib/icl-remote-resource.c
lib/icl-remote-resource.h
lib/include/iotcon-client.h
lib/include/iotcon-remote-resource.h

index 66e3766403f280ae05c8d716db002ad9abf2ee55..72ac35fb425876edcdc24de60f6f0ed977e9360b 100644 (file)
@@ -611,9 +611,10 @@ OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
        GVariantBuilder *options;
 
        RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+       RETV_IF(NULL == resp, OC_STACK_DELETE_TRANSACTION);
 
        if (NULL == resp->payload) {
-               ERR("payload is empty");
+               ERR("payload is empty(%d)", resp->result);
                icd_ioty_complete_error(ICD_CRUD_GET, ctx, IOTCON_ERROR_IOTIVITY);
                return OC_STACK_DELETE_TRANSACTION;
        }
@@ -643,9 +644,10 @@ OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
        GVariantBuilder *options;
 
        RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+       RETV_IF(NULL == resp, OC_STACK_DELETE_TRANSACTION);
 
        if (NULL == resp->payload) {
-               ERR("payload is empty");
+               ERR("payload is empty(%d)", resp->result);
                icd_ioty_complete_error(ICD_CRUD_PUT, ctx, IOTCON_ERROR_IOTIVITY);
                return OC_STACK_DELETE_TRANSACTION;
        }
@@ -675,9 +677,10 @@ OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle
        GVariantBuilder *options;
 
        RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+       RETV_IF(NULL == resp, OC_STACK_DELETE_TRANSACTION);
 
        if (NULL == resp->payload) {
-               ERR("payload is empty");
+               ERR("payload is empty(%d)", resp->result);
                icd_ioty_complete_error(ICD_CRUD_POST, ctx, IOTCON_ERROR_IOTIVITY);
                return OC_STACK_DELETE_TRANSACTION;
        }
@@ -707,9 +710,10 @@ OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle hand
        GVariantBuilder *options;
 
        RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+       RETV_IF(NULL == resp, OC_STACK_DELETE_TRANSACTION);
 
        if (NULL == resp->payload) {
-               ERR("payload is empty");
+               ERR("payload is empty(%d)", resp->result);
                icd_ioty_complete_error(ICD_CRUD_DELETE, ctx, IOTCON_ERROR_IOTIVITY);
                return OC_STACK_DELETE_TRANSACTION;
        }
@@ -795,7 +799,7 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx,
                OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
 
        if (NULL == resp->payload) {
-               ERR("payload is empty");
+               ERR("payload is empty(%d)", resp->result);
                _observe_cb_response_error(sig_context->bus_name, sig_context->signal_number,
                                IOTCON_ERROR_IOTIVITY);
                return cb_result;
@@ -1243,6 +1247,7 @@ OCStackApplicationResult icd_ioty_ocprocess_encap_observe_cb(void *ctx, OCDoHand
        int ret;
        icd_encap_worker_ctx_s *encap_ctx = ctx;
 
+       RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
        RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
 
        if (OC_OBSERVE_DEREGISTER == resp->sequenceNumber)
index 2e91b80da167a74a377c477a9e005dbacc1daaa8..5170361cf07b9c55c8aab9ea7061537740792045 100644 (file)
@@ -98,6 +98,11 @@ API int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        if (0 != resource->caching_sub_id) {
                ERR("Already Start Caching");
                return IOTCON_ERROR_ALREADY;
index b3e3ac2df47efa14ed154dd4942d7b88b7f85c69..c0406c6810ecd9d53facda4e43a39fd00c4c953c 100644 (file)
@@ -232,6 +232,11 @@ API int iotcon_remote_resource_get(iotcon_remote_resource_h resource,
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        cb_container = calloc(1, sizeof(icl_on_response_s));
        if (NULL == cb_container) {
                ERR("calloc() Fail(%d)", errno);
@@ -271,6 +276,11 @@ API int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        cb_container = calloc(1, sizeof(icl_on_response_s));
        if (NULL == cb_container) {
                ERR("calloc() Fail(%d)", errno);
@@ -317,6 +327,11 @@ API int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        cb_container = calloc(1, sizeof(icl_on_response_s));
        if (NULL == cb_container) {
                ERR("calloc() Fail(%d)", errno);
@@ -364,6 +379,11 @@ API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        cb_container = calloc(1, sizeof(icl_on_response_s));
        if (NULL == cb_container) {
                ERR("calloc() Fail(%d)", errno);
@@ -488,6 +508,11 @@ API int iotcon_remote_resource_observe_register(iotcon_remote_resource_h resourc
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(resource->observe_handle || resource->observe_sub_id, IOTCON_ERROR_ALREADY);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
        arg_query = icl_dbus_query_to_gvariant(query);
 
@@ -548,6 +573,12 @@ API int iotcon_remote_resource_observe_deregister(iotcon_remote_resource_h resou
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        if (0 == resource->observe_handle) {
                ERR("It doesn't have a observe_handle");
                return IOTCON_ERROR_INVALID_PARAMETER;
index 1769004be721fa8bb62ba6161ce95e79855949fb..b2d02873378890327e1dd57d2f4022429395466c 100644 (file)
@@ -75,6 +75,11 @@ API int iotcon_remote_resource_start_monitoring(iotcon_remote_resource_h resourc
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (true == resource->is_found) {
+               ERR("The resource should be cloned.");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        if (0 != resource->monitoring_sub_id) {
                ERR("Already Start Monitoring");
                return IOTCON_ERROR_ALREADY;
index 4925256dc92736b7384b16bd155c0a2600f9f7f2..fed1f6981b952b3d036c8beecb058a51c8441e12 100644 (file)
@@ -72,6 +72,8 @@ static void _icl_found_resource_cb(GDBusConnection *connection,
                return;
        }
 
+       resource->is_found = true;
+
        if (cb)
                cb(resource, IOTCON_ERROR_NONE, cb_container->user_data);
 
@@ -222,8 +224,15 @@ API int iotcon_remote_resource_create(const char *host_address,
 static void _icl_remote_resource_destroy(iotcon_remote_resource_h resource)
 {
        RET_IF(NULL == resource);
-       if (resource->ref_count < 0)
+       if (resource->ref_count < 0) {
                ERR("Invalid ref_count (%d)", resource->ref_count);
+               return;
+       }
+       if (true == resource->is_found) {
+               ERR("It can't be destroyed by user.");
+               return;
+       }
+
        free(resource->uri_path);
        free(resource->host_address);
        free(resource->device_id);
index 48cdfc8dcf7fa9e9a5f8bf91cc57e22a835caa17..d62551a9bbe5b35441dae19052e0d902e299efc3 100644 (file)
@@ -30,6 +30,7 @@ typedef enum {
 } icl_remote_resource_device_state_e;
 
 struct icl_remote_resource {
+       bool is_found;
        int ref_count;
        char *uri_path;
        char *host_address;
index 5ab2e77334edd4cb1b284b4f5f9a297ed2fd884c..ad5a00a68e5a053c365b8dde0f90f786c7a2ec80 100644 (file)
@@ -325,7 +325,9 @@ int iotcon_presence_response_get_resource_type(iotcon_presence_response_h respon
 
 /**
  * @brief Specifies the type of function passed to iotcon_find_resource().
- * @details Called when a resource is found from the remote server.
+ * @details Called when a resource is found from the remote server.\n
+ * The @a resource completes its life cycle in the function.
+ * If you want to send requests(GET, PUT, POST, DELETE, and OBSERVE) on the @a resource, you must clone the @a resource using iotcon_remote_resource_clone().
  * The @a result could be one of #iotcon_error_e.
  *
  * @since_tizen 3.0
index a4ce0e166a239d842c4e84353f3179e117ecfd8f..3d7e79feee08d59e96fa9b3dfcf6d72ecda68f56 100644 (file)
@@ -443,7 +443,8 @@ typedef void (*iotcon_remote_resource_cached_representation_changed_cb)(
  * @details Use this function to start caching the resource's attribute.\n
  * Although, remote resource is not observable, it keeps the representation up-to-date.
  * Because It checks whether representation is changed, periodically.\n
- * The default checking interval is 10 seconds, but it may be changed by an administrator.
+ * The default checking interval is 10 seconds, but it may be changed by an administrator.\n
+ * Also, you can get the cached representation even when the remote resource is off-line.
  *
  * @since_tizen 3.0
  * @privlevel public