apply put,post,delete functions
authorMinchul Lee <slotus.lee@samsung.com>
Wed, 5 Aug 2015 04:44:24 +0000 (13:44 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:08:20 +0000 (20:08 +0900)
Change-Id: I78412d23545d91d7a59135064233945beee3330b
Signed-off-by: Minchul Lee <slotus.lee@samsung.com>
13 files changed:
common/ic-dbus.xml
daemon/icd-ioty-ocprocess.c
daemon/icd-ioty-ocprocess.h
daemon/icd-ioty.c
daemon/icd-ioty.h
lib/icl-client-crud.c
lib/icl-client.c
lib/icl-dbus-type.c
lib/icl-repr-value.c
lib/icl-repr.c
lib/icl-resource.c
lib/icl-response.c
lib/icl-response.h

index 6cff5e7..82334a6 100644 (file)
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="get">
-                       <arg type="(ssba(qs)iii)" name="client" direction="in"/>
+                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)si)" name="ret" direction="out"/>
                </method>
                <method name="put">
-                       <arg type="(ssba(qs)asii)" name="client" direction="in"/>
+                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
                        <arg type="s" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)si)" name="ret" direction="out"/>
                </method>
                <method name="post">
-                       <arg type="(ssba(qs)asii)" name="client" direction="in"/>
+                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
                        <arg type="s" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)si)" name="ret" direction="out"/>
                </method>
                <method name="delete">
-                       <arg type="(ssba(qs)asii)" name="client" direction="in"/>
+                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
                        <arg type="(a(qs)i)" name="ret" direction="out"/>
                </method>
                <method name="observerStart">
index 6a6ba96..e403a44 100644 (file)
@@ -69,8 +69,9 @@ struct icd_find_context {
 };
 
 
-struct icd_get_context {
+struct icd_crud_context {
        int res;
+       int crud_type;
        char *payload;
        GVariantBuilder *options;
        GDBusMethodInvocation *invocation;
@@ -571,17 +572,20 @@ OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle
 }
 
 
-static int _worker_get_cb(void *context)
+static int _worker_crud_cb(void *context)
 {
        GVariant *value;
-       struct icd_get_context *ctx = context;
+       struct icd_crud_context *ctx = context;
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
 
-       value = g_variant_new("(a(qs)si)", ctx->options, ctx->payload, ctx->res);
-       icd_ioty_get_complete(ctx->invocation, value);
+       if (ICD_CRUD_DELETE == ctx->crud_type)
+               value = g_variant_new("(a(qs)i)", ctx->options, ctx->res);
+       else
+               value = g_variant_new("(a(qs)si)", ctx->options, ctx->payload, ctx->res);
+       icd_ioty_complete(ctx->crud_type, ctx->invocation, value);
 
-       /* ctx was allocated from icd_ioty_ocprocess_get_cb() */
+       /* ctx was allocated from icd_ioty_ocprocess_xxx_cb() */
        free(ctx->payload);
        g_variant_builder_unref(ctx->options);
        free(ctx);
@@ -590,6 +594,38 @@ static int _worker_get_cb(void *context)
 }
 
 
+static int _ocprocess_worker(_ocprocess_fn fn, int type, const char *payload, int res,
+               GVariantBuilder *options, void *ctx)
+{
+       int ret;
+       struct icd_crud_context *crud_ctx;
+
+       crud_ctx = calloc(1, sizeof(struct icd_crud_context));
+       if (NULL == crud_ctx) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       crud_ctx->crud_type = type;
+       crud_ctx->payload = strdup(ic_utils_dbus_encode_str(payload));
+       crud_ctx->res = res;
+       crud_ctx->options = options;
+       crud_ctx->invocation = ctx;
+
+       ret = _ocprocess_worker_start(fn, crud_ctx);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("_ocprocess_worker_start() Fail(%d)", ret);
+               free(crud_ctx->payload);
+               g_variant_builder_unref(crud_ctx->options);
+               free(crud_ctx);
+       }
+
+       /* DO NOT FREE crud_ctx. It MUST be freed in the _worker_crud_cb func */
+
+       return ret;
+}
+
+
 OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
                OCClientResponse *resp)
 {
@@ -597,20 +633,20 @@ OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
        int ret, res;
        OCStackResult result;
        GVariantBuilder *options;
-       struct icd_get_context *get_ctx;
+       struct icd_crud_context *crud_ctx;
 
        RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
 
        if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
                ERR("json payload is empty");
-               icd_ioty_get_complete_error(ctx, IOTCON_ERROR_IOTIVITY);
+               icd_ioty_complete_error(ICD_CRUD_GET, ctx, IOTCON_ERROR_IOTIVITY);
                return OC_STACK_DELETE_TRANSACTION;
        }
 
-       get_ctx = calloc(1, sizeof(struct icd_get_context));
-       if (NULL == get_ctx) {
+       crud_ctx = calloc(1, sizeof(struct icd_crud_context));
+       if (NULL == crud_ctx) {
                ERR("calloc() Fail(%d)", errno);
-               icd_ioty_get_complete_error(ctx, IOTCON_ERROR_OUT_OF_MEMORY);
+               icd_ioty_complete_error(ICD_CRUD_GET, ctx, IOTCON_ERROR_OUT_OF_MEMORY);
                return OC_STACK_DELETE_TRANSACTION;
        }
 
@@ -625,22 +661,177 @@ OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
                options = NULL;
        }
 
-       get_ctx->payload = strdup(resp->resJSONPayload);
-       get_ctx->res = res;
-       get_ctx->options = options;
-       get_ctx->invocation = ctx;
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_GET, resp->resJSONPayload, res,
+                       options, ctx);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("_ocprocess_worker() Fail(%d)", ret);
+               icd_ioty_complete_error(ICD_CRUD_GET, ctx, ret);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       return OC_STACK_DELETE_TRANSACTION;
+}
+
+
+OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
+               OCClientResponse *resp)
+{
+       FN_CALL;
+       int ret, res;
+       OCStackResult result;
+       GVariantBuilder *options;
+
+       RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+
+       if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
+               ERR("json payload is empty");
+               icd_ioty_complete_error(ICD_CRUD_PUT, ctx, IOTCON_ERROR_IOTIVITY);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       result = resp->result;
+       switch (result) {
+       case OC_STACK_OK:
+               res = IOTCON_RESPONSE_RESULT_OK;
+               break;
+       case OC_STACK_RESOURCE_CREATED:
+               res = IOTCON_RESPONSE_RESULT_RESOURCE_CREATED;
+               break;
+       case OC_STACK_RESOURCE_DELETED:
+               res = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
+               break;
+       default:
+               WARN("resp error(%d)", result);
+               res = IOTCON_RESPONSE_RESULT_ERROR;
+               options = NULL;
+       }
+
+       if (IOTCON_RESPONSE_RESULT_ERROR != res) {
+               options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
+                               resp->numRcvdVendorSpecificHeaderOptions);
+       }
 
-       ret = _ocprocess_worker_start(_worker_get_cb, get_ctx);
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_PUT, resp->resJSONPayload, res,
+                       options, ctx);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("_ocprocess_worker_start() Fail(%d)", ret);
-               icd_ioty_get_complete_error(ctx, ret);
-               free(get_ctx->payload);
-               g_variant_builder_unref(get_ctx->options);
-               free(get_ctx);
+               ERR("_ocprocess_worker() Fail(%d)", ret);
+               icd_ioty_complete_error(ICD_CRUD_PUT, ctx, ret);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       return OC_STACK_DELETE_TRANSACTION;
+}
+
+
+OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle,
+               OCClientResponse *resp)
+{
+       FN_CALL;
+       int ret, res;
+       OCStackResult result;
+       GVariantBuilder *options;
+       struct icd_crud_context *crud_ctx;
+
+       RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+
+       if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
+               ERR("json payload is empty");
+               icd_ioty_complete_error(ICD_CRUD_POST, ctx, IOTCON_ERROR_IOTIVITY);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       crud_ctx = calloc(1, sizeof(struct icd_crud_context));
+       if (NULL == crud_ctx) {
+               ERR("calloc() Fail(%d)", errno);
+               icd_ioty_complete_error(ICD_CRUD_POST, ctx, IOTCON_ERROR_OUT_OF_MEMORY);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       result = resp->result;
+       switch (result) {
+       case OC_STACK_OK:
+               res = IOTCON_RESPONSE_RESULT_OK;
+               break;
+       case OC_STACK_RESOURCE_CREATED:
+               res = IOTCON_RESPONSE_RESULT_RESOURCE_CREATED;
+               break;
+       case OC_STACK_RESOURCE_DELETED:
+               res = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
+               break;
+       default:
+               WARN("resp error(%d)", result);
+               res = IOTCON_RESPONSE_RESULT_ERROR;
+               options = NULL;
+       }
+
+       if (IOTCON_RESPONSE_RESULT_ERROR != res) {
+               options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
+                               resp->numRcvdVendorSpecificHeaderOptions);
+       }
+
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_POST, resp->resJSONPayload, res,
+                       options, ctx);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("_ocprocess_worker() Fail(%d)", ret);
+               icd_ioty_complete_error(ICD_CRUD_POST, ctx, ret);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       return OC_STACK_DELETE_TRANSACTION;
+}
+
+
+OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle handle,
+               OCClientResponse *resp)
+{
+       FN_CALL;
+       int ret, res;
+       OCStackResult result;
+       GVariantBuilder *options;
+       struct icd_crud_context *crud_ctx;
+
+       RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
+
+       if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
+               ERR("json payload is empty");
+               icd_ioty_complete_error(ICD_CRUD_DELETE, ctx, IOTCON_ERROR_IOTIVITY);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       crud_ctx = calloc(1, sizeof(struct icd_crud_context));
+       if (NULL == crud_ctx) {
+               ERR("calloc() Fail(%d)", errno);
+               icd_ioty_complete_error(ICD_CRUD_DELETE, ctx, IOTCON_ERROR_OUT_OF_MEMORY);
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       result = resp->result;
+       switch (result) {
+       case OC_STACK_OK:
+               res = IOTCON_RESPONSE_RESULT_OK;
+               break;
+       case OC_STACK_RESOURCE_DELETED:
+               res = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
+               break;
+       default:
+               WARN("resp error(%d)", result);
+               res = IOTCON_RESPONSE_RESULT_ERROR;
+               options = NULL;
+       }
+
+       if (IOTCON_RESPONSE_RESULT_ERROR != res) {
+               options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
+                               resp->numRcvdVendorSpecificHeaderOptions);
+       }
+
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_DELETE, NULL, res, options, ctx);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("_ocprocess_worker() Fail(%d)", ret);
+               icd_ioty_complete_error(ICD_CRUD_DELETE, ctx, ret);
                return OC_STACK_DELETE_TRANSACTION;
        }
 
-       /* DO NOT FREE get_ctx. It MUST be freed in the _worker_get_cb func */
+       /* DO NOT FREE crud_ctx. It MUST be freed in the _worker_delete_cb func */
 
        return OC_STACK_DELETE_TRANSACTION;
 }
index 42756b5..65b31eb 100644 (file)
@@ -26,10 +26,19 @@ gpointer icd_ioty_ocprocess_thread(gpointer data);
 OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
                OCEntityHandlerRequest *request);
 
-OCStackApplicationResult icd_ioty_ocprocess_find_cb(voidctx, OCDoHandle handle,
+OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle,
                OCClientResponse* resp);
 
-OCStackApplicationResult icd_ioty_ocprocess_get_cb(voidctx, OCDoHandle handle,
+OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
                OCClientResponse* resp);
 
+OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
+               OCClientResponse *resp);
+
+OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle,
+               OCClientResponse *resp);
+
+OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle handle,
+               OCClientResponse *resp);
+
 #endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_THREAD_H__*/
index 3f6cde4..814cf80 100644 (file)
@@ -469,47 +469,106 @@ static char* _icd_ioty_resource_generate_uri(char *host, char *uri_path, GVarian
 }
 
 
-void icd_ioty_get_complete(GDBusMethodInvocation *invocation, GVariant *value)
-{
-       ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
+void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value)
+{
+       switch(type) {
+       case ICD_CRUD_GET:
+               ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
+               break;
+       case ICD_CRUD_PUT:
+               ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
+               break;
+       case ICD_CRUD_POST:
+               ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
+               break;
+       case ICD_CRUD_DELETE:
+               ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
+               break;
+       }
 }
 
 
-void icd_ioty_get_complete_error(GDBusMethodInvocation *invocation, int ret_val)
+void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val)
 {
        GVariant *value;
 
-       value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
-
-       ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
+       switch (type) {
+       case ICD_CRUD_GET:
+               value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+               ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
+               break;
+       case ICD_CRUD_PUT:
+               value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+               ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
+               break;
+       case ICD_CRUD_POST:
+               value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+               ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
+               break;
+       case ICD_CRUD_DELETE:
+               value = g_variant_new("(a(qs)i)", NULL, ret_val);
+               ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
+               break;
+       }
 }
 
 
-gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
-               GVariant *resource, GVariant *query)
+static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *invocation,
+               GVariant *resource, GVariant *query, const char *repr)
 {
-       FN_CALL;
+       OCMethod rest_type;
        OCStackResult result;
        GVariantIter *options;
        OCCallbackData cbdata = {0};
        int conn_type, options_size;
        char *uri_path, *host, *uri;
-       int is_observable, ifaces, observe_handle;
+       char uri_buf[PATH_MAX] = {0};
        OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
+       OCHeaderOption *oic_options_ptr = NULL;
+
+       switch (type) {
+       case ICD_CRUD_GET:
+               cbdata.cb = icd_ioty_ocprocess_get_cb;
+               rest_type = OC_REST_GET;
+               break;
+       case ICD_CRUD_PUT:
+               cbdata.cb = icd_ioty_ocprocess_put_cb;
+               rest_type = OC_REST_PUT;
+               break;
+       case ICD_CRUD_POST:
+               cbdata.cb = icd_ioty_ocprocess_post_cb;
+               rest_type = OC_REST_POST;
+               break;
+       case ICD_CRUD_DELETE:
+               cbdata.cb = icd_ioty_ocprocess_delete_cb;
+               rest_type = OC_REST_DELETE;
+               break;
+       default:
+               ERR("Invalid CRUD Type(%d)", type);
+               return FALSE;
+       }
 
-       g_variant_get(resource, "(&s&sba(qs)iii)", &uri_path, &host, &is_observable, &options,
-                       &ifaces, &observe_handle, &conn_type);
+       g_variant_get(resource, "(&s&sa(qs)i)", &uri_path, &host, &options, &conn_type);
 
-       uri = _icd_ioty_resource_generate_uri(host, uri_path, query);
-       if (NULL == uri) {
-               ERR("_icd_ioty_resource_generate_uri() Fail");
-               g_variant_iter_free(options);
-               icd_ioty_get_complete_error(invocation, IOTCON_ERROR_INVALID_PARAMETER);
-               return TRUE;
+       switch (type) {
+       case ICD_CRUD_GET:
+       case ICD_CRUD_PUT:
+       case ICD_CRUD_POST:
+               uri = _icd_ioty_resource_generate_uri(host, uri_path, query);
+               if (NULL == uri) {
+                       ERR("_icd_ioty_resource_generate_uri() Fail");
+                       g_variant_iter_free(options);
+                       icd_ioty_complete_error(type, invocation, IOTCON_ERROR_INVALID_PARAMETER);
+                       return TRUE;
+               }
+               break;
+       case ICD_CRUD_DELETE:
+               snprintf(uri_buf, sizeof(uri_buf), "%s%s", host, uri_path);
+               uri = strdup(uri_buf);
+               break;
        }
 
        cbdata.context = invocation;
-       cbdata.cb = icd_ioty_ocprocess_get_cb;
 
        options_size = g_variant_iter_n_children(options);
        if (0 != options_size) {
@@ -519,99 +578,59 @@ gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
                        ERR("_ioty_get_header_options() Fail(%d)", ret);
                        free(uri);
                        g_variant_iter_free(options);
-                       icd_ioty_get_complete_error(invocation, ret);
+                       icd_ioty_complete_error(type, invocation, ret);
                        return TRUE;
                }
+               oic_options_ptr = oic_options;
        }
        g_variant_iter_free(options);
 
        icd_ioty_csdk_lock();
        /* TODO : QoS is come from lib. And user can set QoS to client structure.  */
-       result = OCDoResource(NULL, OC_REST_GET, uri, NULL, NULL, conn_type, OC_HIGH_QOS,
-                       &cbdata, options_size?oic_options:NULL, options_size);
+       result = OCDoResource(NULL, rest_type, uri, NULL, repr, conn_type, OC_HIGH_QOS,
+                       &cbdata, oic_options_ptr, options_size);
        icd_ioty_csdk_unlock();
 
        free(uri);
 
        if (OC_STACK_OK != result) {
                ERR("OCDoResource() Fail(%d)", result);
-               icd_ioty_get_complete_error(invocation, IOTCON_ERROR_IOTIVITY);
+               icd_ioty_complete_error(type, invocation, IOTCON_ERROR_IOTIVITY);
                return TRUE;
        }
 
        return TRUE;
 }
 
-
-void icd_ioty_put_complete(GDBusMethodInvocation *invocation, GVariant *value)
-{
-       ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
-}
-
-
-void icd_ioty_put_complete_error(GDBusMethodInvocation *invocation, int ret_val)
+gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
+               GVariant *resource, GVariant *query)
 {
-       GVariant *value;
-
-       value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
-
-       ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
+       FN_CALL;
+       return _icd_ioty_crud(ICD_CRUD_GET, object, invocation, resource, query, NULL);
 }
 
 
 gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, const char *repr, GVariant *query)
 {
-       // TODO : To be implemented
-       return IOTCON_ERROR_NONE;
-}
-
-
-void icd_ioty_post_complete(GDBusMethodInvocation *invocation, GVariant *value)
-{
-       ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
-}
-
-
-void icd_ioty_post_complete_error(GDBusMethodInvocation *invocation, int ret_val)
-{
-       GVariant *value;
-
-       value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
-
-       ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
+       FN_CALL;
+       return _icd_ioty_crud(ICD_CRUD_PUT, object, invocation, resource, query, repr);
 }
 
 
 gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, const char *repr, GVariant *query)
 {
-       // TODO : To be implemented
-       return IOTCON_ERROR_NONE;
-}
-
-
-void icd_ioty_delete_complete(GDBusMethodInvocation *invocation, GVariant *value)
-{
-       ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
-}
-
-
-void icd_ioty_delete_complete_error(GDBusMethodInvocation *invocation, int ret_val)
-{
-       GVariant *value;
-
-       value = g_variant_new("(a(qs)i)", NULL, IC_STR_NULL, ret_val);
-
-       ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
+       FN_CALL;
+       return _icd_ioty_crud(ICD_CRUD_POST, object, invocation, resource, query, repr);
 }
 
 
 gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource)
 {
-       // TODO : To be implemented
-       return IOTCON_ERROR_NONE;
+       FN_CALL;
+       return _icd_ioty_crud(ICD_CRUD_DELETE, object, invocation, resource, NULL, NULL);
 }
 
 
index faa0128..54bb7f1 100644 (file)
@@ -30,6 +30,12 @@ typedef struct {
        char *bus_name;
 } icd_sig_ctx_s;
 
+enum {
+       ICD_CRUD_GET,
+       ICD_CRUD_PUT,
+       ICD_CRUD_POST,
+       ICD_CRUD_DELETE
+};
 
 void icd_ioty_csdk_lock();
 
@@ -61,23 +67,18 @@ int icd_ioty_send_response(GVariant *resp);
 int icd_ioty_find_resource(const char *host_address, const char *resource_type,
                unsigned int signal_number, const char *bus_name);
 
-void icd_ioty_get_complete(GDBusMethodInvocation *invocation, GVariant *value);
-void icd_ioty_get_complete_error(GDBusMethodInvocation *invocation, int ret_val);
+void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value);
+void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val);
+
 gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, GVariant *query);
 
-void icd_ioty_put_complete(GDBusMethodInvocation *invocation, GVariant *value);
-void icd_ioty_put_complete_error(GDBusMethodInvocation *invocation, int ret_val);
 gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, const char *repr, GVariant *query);
 
-void icd_ioty_post_complete(GDBusMethodInvocation *invocation, GVariant *value);
-void icd_ioty_post_complete_error(GDBusMethodInvocation *invocation, int ret_val);
 gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, const char *repr, GVariant *query);
 
-void icd_ioty_delete_complete(GDBusMethodInvocation *invocation, GVariant *value);
-void icd_ioty_delete_complete_error(GDBusMethodInvocation *invocation, int ret_val);
 gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource);
 
index 978db6c..96a3566 100644 (file)
@@ -49,6 +49,7 @@ typedef struct {
 
 static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
 {
+       FN_CALL;
        int res;
        iotcon_repr_h repr;
        GVariantIter *options;
@@ -294,6 +295,7 @@ API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
 static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
                gpointer user_data)
 {
+       FN_CALL;
        int res;
        GVariant *result;
        char *option_data;
@@ -315,7 +317,7 @@ static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
        }
        g_variant_get(result, "(a(qs)i)", &options, &res);
 
-       if (IOTCON_ERROR_NONE != res && g_variant_iter_n_children(options)) {
+       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
                header_options = iotcon_options_new();
                while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
                        iotcon_options_insert(header_options, option_id, option_data);
index 270b72e..76fa620 100644 (file)
@@ -165,8 +165,6 @@ API iotcon_client_h iotcon_client_new(const char *host, const char *uri_path,
 
 API void iotcon_client_free(iotcon_client_h resource)
 {
-       FN_CALL;
-
        RET_IF(NULL == resource);
 
        resource->ref_count--;
index 8c0f1f7..2395e31 100644 (file)
@@ -128,14 +128,8 @@ GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource)
                }
        }
 
-       value = g_variant_new("(ssba(qs)iii)",
-                       resource->uri_path,
-                       resource->host,
-                       resource->is_observable,
-                       &options,
-                       resource->ifaces,
-                       resource->conn_type,
-                       GPOINTER_TO_INT(resource->observe_handle));
+       value = g_variant_new("(ssa(qs)i)", resource->uri_path, resource->host, &options,
+                       resource->conn_type);
 
        return value;
 }
index bb35920..7fc0234 100644 (file)
@@ -349,7 +349,6 @@ API iotcon_value_h icl_value_from_json(JsonNode *node)
 
 void icl_value_free(gpointer data)
 {
-       FN_CALL;
        int ret;
        iotcon_value_h value;
        iotcon_list_h list;
index 2514593..dba62c3 100644 (file)
@@ -73,6 +73,7 @@ API iotcon_repr_h iotcon_repr_new()
        ret_val->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
                        icl_value_free);
        icl_repr_inc_ref_count(ret_val);
+       ret_val->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
 
        return ret_val;
 }
@@ -253,7 +254,7 @@ static JsonObject* _icl_repr_data_generate_json(iotcon_repr_h cur_repr,
 
        /* representation attributes are included if interface type is one of None
         * or Default Parent or Batch Child */
-       if (ICL_VISIBILITY_REPR == cur_repr->visibility && 0 < iotcon_repr_get_keys_count(cur_repr)) {
+       if ((ICL_VISIBILITY_REPR & cur_repr->visibility) && 0 < iotcon_repr_get_keys_count(cur_repr)) {
                repr_obj = icl_obj_to_json(cur_repr);
                if (NULL == repr_obj) {
                        ERR("icl_obj_to_json() Fail");
@@ -273,7 +274,7 @@ static JsonObject* _icl_repr_data_generate_json(iotcon_repr_h cur_repr,
 
        /* properties such as resource types and resource interfaces are included
         * if interface type is one of None or Default Child or Link Child */
-       if (ICL_VISIBILITY_PROP == cur_repr->visibility) {
+       if (ICL_VISIBILITY_PROP & cur_repr->visibility) {
                if (0 < rt_count || IOTCON_INTERFACE_NONE != cur_repr->interfaces) {
                        prop_obj = json_object_new();
                        json_object_set_object_member(repr_obj, IC_JSON_KEY_PROPERTY, prop_obj);
@@ -797,7 +798,6 @@ iotcon_repr_h icl_repr_parse_json(const char *json_string)
 
 API void iotcon_repr_free(iotcon_repr_h repr)
 {
-       FN_CALL;
        RET_IF(NULL == repr);
 
        if (false == _icl_repr_dec_ref_count(repr))
index b3d3488..72a81cf 100644 (file)
@@ -39,6 +39,7 @@ static void _icl_request_handler(GDBusConnection *connection,
                GVariant *parameters,
                gpointer user_data)
 {
+       FN_CALL;
        GVariantIter *options;
        unsigned short option_id;
        char *option_data;
index 894e32a..e10b867 100644 (file)
@@ -50,8 +50,6 @@ API iotcon_response_h iotcon_response_new(iotcon_request_h request_h)
 
 API void iotcon_response_free(iotcon_response_h resp)
 {
-       FN_CALL;
-
        RET_IF(NULL == resp);
 
        if (resp->repr)
@@ -131,14 +129,21 @@ static bool _icl_response_repr_child_fn(iotcon_repr_h child, void *user_data)
 {
        int iface = GPOINTER_TO_INT(user_data);
 
-       if (IOTCON_INTERFACE_DEFAULT == iface)
-               child->visibility = ICL_VISIBILITY_PROP;
-       else if (IOTCON_INTERFACE_LINK == iface)
-               child->visibility = ICL_VISIBILITY_PROP;
-       else if (IOTCON_INTERFACE_BATCH == iface)
+       switch(iface) {
+       case IOTCON_INTERFACE_BATCH:
                child->visibility = ICL_VISIBILITY_REPR;
-       else
+               break;
+       case IOTCON_INTERFACE_NONE:
+       case IOTCON_INTERFACE_DEFAULT:
+       case IOTCON_INTERFACE_LINK:
+       case IOTCON_INTERFACE_GROUP:
                child->visibility = ICL_VISIBILITY_PROP;
+               break;
+       default:
+               WARN("Invalid interface type(%d)", iface);
+               child->visibility = ICL_VISIBILITY_PROP;
+               break;
+       }
 
        return IOTCON_FUNC_CONTINUE;
 }
@@ -154,12 +159,22 @@ static int _icl_response_check_repr_visibility(iotcon_response_h resp)
        iotcon_repr_h first = resp->repr;
 
        DBG("interface type of response : %d", resp->iface);
-       if (IOTCON_INTERFACE_NONE == resp->iface)
-               first->visibility = ICL_VISIBILITY_REPR;
-       else if (IOTCON_INTERFACE_DEFAULT == resp->iface)
+
+       switch(resp->iface) {
+       case IOTCON_INTERFACE_NONE:
+       case IOTCON_INTERFACE_DEFAULT:
+       case IOTCON_INTERFACE_GROUP:
                first->visibility = ICL_VISIBILITY_REPR;
-       else
+               break;
+       case IOTCON_INTERFACE_LINK:
+       case IOTCON_INTERFACE_BATCH:
                first->visibility = ICL_VISIBILITY_NONE;
+               break;
+       default:
+               WARN("Invalid interface type(%d)", resp->iface);
+               first->visibility = ICL_VISIBILITY_REPR;
+               break;
+       }
 
        ret = iotcon_repr_foreach_children(first, _icl_response_repr_child_fn,
                        GINT_TO_POINTER(resp->iface));
index 1480d47..8b566b0 100644 (file)
@@ -23,8 +23,8 @@
 
 typedef enum {
        ICL_VISIBILITY_NONE = 0,
-       ICL_VISIBILITY_REPR,
-       ICL_VISIBILITY_PROP,
+       ICL_VISIBILITY_REPR = (1 << 0),
+       ICL_VISIBILITY_PROP = (1 << 1),
 } icl_visibility_e;