Apply iotivity 0.9.2
authoryoungman <yman.jung@samsung.com>
Fri, 21 Aug 2015 11:38:51 +0000 (20:38 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:08:20 +0000 (20:08 +0900)
Change-Id: I57f15b6eed5a217a4699fb117176a3a690c6824f
Signed-off-by: youngman <yman.jung@samsung.com>
46 files changed:
common/ic-common.h
common/ic-dbus.xml
common/ic-utils.c
common/ic-utils.h
daemon/CMakeLists.txt
daemon/icd-dbus.c
daemon/icd-ioty-ocprocess.c
daemon/icd-ioty-ocprocess.h
daemon/icd-ioty-type.c [new file with mode: 0644]
daemon/icd-ioty-type.h [new file with mode: 0644]
daemon/icd-ioty.c
daemon/icd-ioty.h
daemon/icd-payload.c [new file with mode: 0644]
daemon/icd-payload.h [new file with mode: 0644]
lib/CMakeLists.txt
lib/icl-client-crud.c
lib/icl-client.c
lib/icl-client.h
lib/icl-dbus-type.c
lib/icl-dbus-type.h
lib/icl-dbus.c
lib/icl-device.c
lib/icl-payload.c [new file with mode: 0644]
lib/icl-payload.h [new file with mode: 0644]
lib/icl-presence.c
lib/icl-repr-list.c
lib/icl-repr-list.h
lib/icl-repr-obj.c
lib/icl-repr-obj.h
lib/icl-repr-value.c
lib/icl-repr-value.h
lib/icl-repr.c
lib/icl-repr.h
lib/icl-resource.c
lib/icl-response.c
lib/icl.h
lib/include/iotcon-constant.h
lib/include/iotcon-representation.h
lib/include/iotcon-struct.h
lib/include/iotcon.h
packaging/iotcon.spec
test/crud-test-client.c
test/device-test-client.c
test/device-test-server.c
test/repr-test-client.c
test/repr-test-server.c

index 810cf6a..2529d70 100644 (file)
 #define IC_INTERFACE_DEFAULT "oic.if.baseline"
 #define IC_INTERFACE_LINK "oic.if.ll"
 #define IC_INTERFACE_BATCH "oic.if.b"
-#define IC_INTERFACE_GROUP "oc.mi.grp"
-
-#define IC_JSON_KEY_OC "oc"
-#define IC_JSON_KEY_URI_PATH "href"
-#define IC_JSON_KEY_OBSERVABLE "obs"
-#define IC_JSON_KEY_RESOURCETYPES "rt"
-#define IC_JSON_KEY_INTERFACES "if"
-#define IC_JSON_KEY_PROPERTY "prop"
-#define IC_JSON_KEY_REP "rep"
-#define IC_JSON_KEY_SECURE "sec"
-#define IC_JSON_KEY_PORT "port"
-#define IC_JSON_KEY_SERVERID "sid"
+#define IC_INTERFACE_GROUP "oic.mi.grp"
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__ */
index 061089d..695a5e5 100644 (file)
@@ -34,7 +34,7 @@
                </method>
                <method name="notifyListOfObservers">
                        <arg type="i" name="resource" direction="in"/>
-                       <arg type="a(is)" name="notify_msg" direction="in"/>
+                       <arg type="a(iv)" name="notify_msg" direction="in"/>
                        <arg type="ai" name="observers" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
@@ -43,7 +43,7 @@
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="sendResponse">
-                       <arg type="(sia(qs)isii)" name="response" direction="in"/>
+                       <arg type="(sia(qs)ivii)" name="response" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="findResource">
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="get">
-                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
-                       <arg type="(a(qs)si)" name="ret" direction="out"/>
+                       <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="put">
-                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
-                       <arg type="s" name="repr" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(siasa{sv}av)" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
-                       <arg type="(a(qs)si)" name="ret" direction="out"/>
+                       <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="post">
-                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
-                       <arg type="s" name="repr" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(siasa{sv}av)" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
-                       <arg type="(a(qs)si)" name="ret" direction="out"/>
+                       <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="delete">
-                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
                        <arg type="(a(qs)i)" name="ret" direction="out"/>
                </method>
                <method name="observerStart">
-                       <arg type="(ssa(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
                        <arg type="i" name="observe_type" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="u" name="signal_number" direction="in"/>
@@ -86,7 +86,7 @@
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="registerDeviceInfo">
-                       <arg type="(ssssssssssss)" name="device_info" direction="in"/>
+                       <arg type="(s)" name="device_info" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="getDeviceInfo">
index 9701818..18f154d 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <glib.h>
 
 #include "iotcon-constant.h"
 #include "ic-common.h"
@@ -79,4 +81,36 @@ int ic_utils_convert_interface_flag(iotcon_interface_e src, char **dest)
 }
 
 
+int ic_utils_convert_interface_string(const char *src, iotcon_interface_e *dest)
+{
+       RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+       if (IC_STR_EQUAL == strcmp(IC_INTERFACE_DEFAULT, src)) {
+               *dest = IOTCON_INTERFACE_DEFAULT;
+       } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_LINK, src)) {
+               *dest = IOTCON_INTERFACE_LINK;
+       } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_BATCH, src)) {
+               *dest = IOTCON_INTERFACE_BATCH;
+       } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_GROUP, src)) {
+               *dest = IOTCON_INTERFACE_GROUP;
+       } else {
+               ERR("Invalid Interface");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+void ic_utils_gvariant_array_free(GVariant **value)
+{
+       int i;
+
+       for (i = 0; value[i]; i++)
+               g_variant_unref(value[i]);
+
+       free(value);
+}
+
 
index 3cb76f2..4bffe6c 100644 (file)
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_UTILITY_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_UTILITY_H__
 
+#include <glib.h>
+
 #include "iotcon-constant.h"
 
 #define IC_STR_EQUAL 0
 #define IC_STR_NULL "(NULL)"
 
+#define IC_INTERFACE_MAX (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | \
+               IOTCON_INTERFACE_BATCH | IOTCON_INTERFACE_GROUP)
+
 char* ic_utils_strdup(const char *src);
 const char* ic_utils_dbus_encode_str(const char *src);
 char* ic_utils_dbus_decode_str(char *src);
 int ic_utils_convert_interface_flag(iotcon_interface_e src, char **dest);
+int ic_utils_convert_interface_string(const char *src, iotcon_interface_e *dest);
+void ic_utils_gvariant_array_free(GVariant **value);
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_UTILITY_H__ */
index a31ac9a..9c554b8 100644 (file)
@@ -7,7 +7,7 @@ SET(DAEMON_SRCS ${DAEMON_SRCS} ${CMAKE_SOURCE_DIR}/common/ic-dbus.c)
 SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/ic-dbus.c
        PROPERTIES GENERATED TRUE)
 
-pkg_check_modules(daemon_pkgs REQUIRED gio-2.0 dlog gio-unix-2.0 json-glib-1.0)
+pkg_check_modules(daemon_pkgs REQUIRED gio-2.0 dlog gio-unix-2.0)
 INCLUDE_DIRECTORIES(${daemon_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${daemon_pkgs_LIBRARY_DIRS})
 
index 0bc5792..5c02938 100644 (file)
@@ -189,6 +189,7 @@ static int _icd_dbus_client_list_cleanup_handle_list(GList *client_list)
        free(client->bus_name);
        client->bus_name = NULL;
        free(client);
+       g_list_free(client_list);
 
        return IOTCON_ERROR_NONE;
 }
@@ -245,16 +246,17 @@ static void _icd_dbus_name_owner_changed_cb(GDBusConnection *conn,
 
                if (client) { /* found bus name in our bus list */
                        DBG("bus(%s) stopped", old_owner);
+                       icd_dbus_client_list = g_list_remove_link(icd_dbus_client_list, client);
+               }
+               g_mutex_unlock(&icd_dbus_client_list_mutex);
 
+               if (client) {
                        ret = _icd_dbus_client_list_cleanup_handle_list(client);
                        if (IOTCON_ERROR_NONE != ret) {
                                ERR("_icd_dbus_client_list_cleanup_handle_list() Fail(%d)", ret);
-                               g_mutex_unlock(&icd_dbus_client_list_mutex);
                                return;
                        }
-                       icd_dbus_client_list = g_list_delete_link(icd_dbus_client_list, client);
                }
-               g_mutex_unlock(&icd_dbus_client_list_mutex);
        }
 }
 
@@ -592,7 +594,7 @@ static gboolean _dbus_handle_send_response(icDbus *object,
        return TRUE;
 }
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
+
 static gboolean _dbus_handle_register_device_info(icDbus *object,
                GDBusMethodInvocation *invocation, GVariant *device_info)
 {
@@ -617,15 +619,15 @@ static gboolean _dbus_handle_get_device_info(icDbus *object,
        const gchar *sender;
 
        sender = g_dbus_method_invocation_get_sender(invocation);
-       ret = icd_ioty_get_device_info(host_address, signal_number, sender);
+       ret = icd_ioty_get_info(ICD_DEVICE_INFO, host_address, signal_number, sender);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("icd_ioty_get_device_info() Fail(%d)", ret);
+               ERR("icd_ioty_get_info(device info) Fail(%d)", ret);
 
        ic_dbus_complete_get_device_info(object, invocation, ret);
 
        return TRUE;
 }
-#endif
+
 
 static gboolean _dbus_handle_register_platform_info(icDbus *object,
                GDBusMethodInvocation *invocation, GVariant *platform_info)
@@ -651,9 +653,9 @@ static gboolean _dbus_handle_get_platform_info(icDbus *object,
        const gchar *sender;
 
        sender = g_dbus_method_invocation_get_sender(invocation);
-       ret = icd_ioty_get_platform_info(host_address, signal_number, sender);
+       ret = icd_ioty_get_info(ICD_PLATFORM_INFO, host_address, signal_number, sender);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("icd_ioty_get_platform_info() Fail(%d)", ret);
+               ERR("icd_ioty_get_info(platform info) Fail(%d)", ret);
 
        ic_dbus_complete_get_platform_info(object, invocation, ret);
 
@@ -772,12 +774,10 @@ static void _dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name,
                        G_CALLBACK(_dbus_handle_notify_all), NULL);
        g_signal_connect(icd_dbus_object, "handle-send-response",
                        G_CALLBACK(_dbus_handle_send_response), NULL);
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
        g_signal_connect(icd_dbus_object, "handle-register-device-info",
                        G_CALLBACK(_dbus_handle_register_device_info), NULL);
        g_signal_connect(icd_dbus_object, "handle-get-device-info",
                        G_CALLBACK(_dbus_handle_get_device_info), NULL);
-#endif
        g_signal_connect(icd_dbus_object, "handle-register-platform-info",
                        G_CALLBACK(_dbus_handle_register_platform_info), NULL);
        g_signal_connect(icd_dbus_object, "handle-get-platform-info",
index cee6f67..b230995 100644 (file)
 #include <stdlib.h>
 #include <unistd.h> /* for usleep() */
 #include <glib.h>
-#include <json-glib/json-glib.h>
 
 #include <ocstack.h>
 #include <octypes.h>
+#include <ocpayload.h>
 
 #include "iotcon.h"
 #include "ic-utils.h"
 #include "icd.h"
+#include "icd-payload.h"
 #include "icd-dbus.h"
 #include "icd-ioty.h"
+#include "icd-ioty-type.h"
 #include "icd-ioty-ocprocess.h"
 
 static int icd_ioty_alive;
@@ -40,22 +42,15 @@ struct icd_ioty_worker
 };
 
 
-enum _icd_secure_type
-{
-       ICD_TRANSPORT_IPV4_SECURE,
-       ICD_TRANSPORT_IPV4
-};
-
-
 struct icd_req_context {
        unsigned int signum;
        char *bus_name;
-       char *payload;
        int types;
        int observer_id;
        int observe_action;
        OCRequestHandle request_h;
        OCResourceHandle resource_h;
+       GVariant *payload;
        GVariantBuilder *options;
        GVariantBuilder *query;
 };
@@ -64,26 +59,25 @@ struct icd_req_context {
 struct icd_find_context {
        unsigned int signum;
        char *bus_name;
-       char *payload;
-       OCDevAddr *dev_addr;
        int conn_type;
+       GVariant **payload;
 };
 
 
 struct icd_crud_context {
        int res;
        int crud_type;
-       char *payload;
+       GVariant *payload;
        GVariantBuilder *options;
        GDBusMethodInvocation *invocation;
 };
 
 
-struct icd_platform_context {
+struct icd_info_context {
        unsigned int signum;
-       int res;
+       int info_type;
        char *bus_name;
-       char *payload;
+       GVariant *payload;
 };
 
 
@@ -92,7 +86,7 @@ struct icd_observe_context {
        int res;
        int seqnum;
        char *bus_name;
-       char *payload;
+       GVariant *payload;
        GVariantBuilder *options;
 };
 
@@ -105,11 +99,13 @@ struct icd_presence_context {
        OCDevAddr *dev_addr;
 };
 
+
 void icd_ioty_ocprocess_stop()
 {
        icd_ioty_alive = 0;
 }
 
+
 static void* _ocprocess_worker_thread(void *data)
 {
        int ret;
@@ -210,16 +206,21 @@ static int _worker_req_handler(void *context)
        int ret;
        GVariant *value;
        struct icd_req_context *ctx = context;
+       GVariantBuilder payload_builder;
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
 
-       value = g_variant_new("(ia(qs)a(ss)iisii)",
+       g_variant_builder_init(&payload_builder, G_VARIANT_TYPE("av"));
+       if (ctx->payload)
+               g_variant_builder_add(&payload_builder, "v", ctx->payload);
+
+       value = g_variant_new("(ia(qs)a(ss)iiavii)",
                        ctx->types,
                        ctx->options,
                        ctx->query,
                        ctx->observe_action,
                        ctx->observer_id,
-                       ctx->payload,
+                       &payload_builder,
                        GPOINTER_TO_INT(ctx->request_h),
                        GPOINTER_TO_INT(ctx->resource_h));
 
@@ -229,7 +230,6 @@ static int _worker_req_handler(void *context)
                ERR("_ocprocess_response_signal() Fail(%d)", ret);
 
        free(ctx->bus_name);
-       free(ctx->payload);
        g_variant_builder_unref(ctx->options);
        g_variant_builder_unref(ctx->query);
        free(ctx);
@@ -239,7 +239,7 @@ static int _worker_req_handler(void *context)
 
 
 OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
-               OCEntityHandlerRequest *request)
+               OCEntityHandlerRequest *request, void *user_data)
 {
        FN_CALL;
        int ret;
@@ -277,7 +277,7 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
                switch (request->method) {
                case OC_REST_GET:
                        req_ctx->types = IOTCON_REQUEST_GET;
-                       req_ctx->payload = strdup(IC_STR_NULL);
+                       req_ctx->payload = NULL;
 
                        if (OC_OBSERVE_FLAG & flag) {
                                req_ctx->types |= IOTCON_REQUEST_OBSERVE;
@@ -288,15 +288,15 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
                        break;
                case OC_REST_PUT:
                        req_ctx->types = IOTCON_REQUEST_PUT;
-                       req_ctx->payload = ic_utils_strdup(request->reqJSONPayload);
+                       req_ctx->payload = icd_payload_to_gvariant(request->payload);
                        break;
                case OC_REST_POST:
                        req_ctx->types = IOTCON_REQUEST_POST;
-                       req_ctx->payload = ic_utils_strdup(request->reqJSONPayload);
+                       req_ctx->payload = icd_payload_to_gvariant(request->payload);
                        break;
                case OC_REST_DELETE:
                        req_ctx->types = IOTCON_REQUEST_DELETE;
-                       req_ctx->payload = strdup(IC_STR_NULL);
+                       req_ctx->payload = NULL;
                        break;
                default:
                        free(req_ctx->bus_name);
@@ -313,7 +313,7 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
        /* query */
        req_ctx->query = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
        query_str = request->query;
-       while ((token = strtok_r(query_str, "&", &save_ptr1))) {
+       while ((token = strtok_r(query_str, "&;", &save_ptr1))) {
                while ((query_key = strtok_r(token, "=", &save_ptr2))) {
                        token = NULL;
                        query_value = strtok_r(token, "=", &save_ptr2);
@@ -329,7 +329,8 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker_start() Fail(%d)", ret);
                free(req_ctx->bus_name);
-               free(req_ctx->payload);
+               if (req_ctx->payload)
+                       g_variant_unref(req_ctx->payload);
                g_variant_builder_unref(req_ctx->options);
                g_variant_builder_unref(req_ctx->query);
                free(req_ctx);
@@ -365,185 +366,30 @@ gpointer icd_ioty_ocprocess_thread(gpointer data)
 }
 
 
-/*
- * returned string SHOULD be released by you
- */
-static inline char* _find_cb_get_address(OCDevAddr *address, int sec_type, int sec_port)
-{
-       FN_CALL;
-       int ret;
-       uint16_t port;
-       uint8_t a, b, c, d;
-       char addr[1024] = {0};
-
-       RETVM_IF(ICD_TRANSPORT_IPV4 != sec_type && ICD_TRANSPORT_IPV4_SECURE != sec_type,
-                       NULL, "Invalid secure type(%d)", sec_type);
-
-       ret = OCDevAddrToIPv4Addr(address, &a, &b, &c, &d);
-       if (OC_STACK_OK != ret) {
-               ERR("OCDevAddrToIPv4Addr() Fail(%d)", ret);
-               return NULL;
-       }
-
-       if (ICD_TRANSPORT_IPV4_SECURE == sec_type) {
-               if (sec_port <= 0 || 65535 < sec_port) {
-                       SECURE_ERR("Invalid secure port(%d)", sec_port);
-                       return NULL;
-               }
-
-               ret = snprintf(addr, sizeof(addr), ICD_IOTY_COAPS"%d.%d.%d.%d:%d", a, b, c, d,
-                               sec_port);
-       } else {
-               ret = OCDevAddrToPort(address, &port);
-               if (OC_STACK_OK != ret) {
-                       ERR("OCDevAddrToPort() Fail(%d)", ret);
-                       return NULL;
-               }
-
-               ret = snprintf(addr, sizeof(addr), ICD_IOTY_COAP"%d.%d.%d.%d:%d", a, b, c, d,
-                               port);
-       }
-
-       WARN_IF(ret <= 0 || sizeof(addr) <= ret, "snprintf() Fail(%d)", ret);
-
-       return ic_utils_strdup(addr);
-}
-
-
-static inline int _find_cb_response(JsonObject *rsrc_obj,
-               struct icd_find_context *ctx)
+static int _worker_find_cb(void *context)
 {
        GVariant *value;
-       JsonGenerator *gen;
-       JsonNode *root_node;
-       char *host, *json_data;
-       JsonObject *property_obj;
-       int ret, secure, secure_type, secure_port;
-
-       RETV_IF(NULL == rsrc_obj, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
-       /* parse secure secure_port */
-       property_obj = json_object_get_object_member(rsrc_obj, IC_JSON_KEY_PROPERTY);
-       if (NULL == property_obj) {
-               ERR("json_object_get_object_member() Fail");
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       secure = json_object_get_int_member(property_obj, IC_JSON_KEY_SECURE);
-       if (0 == secure) {
-               secure_type = ICD_TRANSPORT_IPV4;
-               secure_port = 0;
-       } else {
-               secure_type = ICD_TRANSPORT_IPV4_SECURE;
-               secure_port = json_object_get_int_member(property_obj, IC_JSON_KEY_PORT);
-       }
-
-       host = _find_cb_get_address(ctx->dev_addr, secure_type, secure_port);
-       if (NULL == host) {
-               ERR("_find_cb_get_address() Fail");
-               return IOTCON_ERROR_IOTIVITY;
-       }
-
-       gen = json_generator_new();
-       root_node = json_node_new(JSON_NODE_OBJECT);
-       json_node_set_object(root_node, rsrc_obj);
-       json_generator_set_root(gen, root_node);
-
-       json_data = json_generator_to_data(gen, NULL);
-       json_node_free(root_node);
-       g_object_unref(gen);
-
-       value = g_variant_new("(ssi)", json_data, host, ctx->conn_type);
-       free(json_data);
-       free(host);
-
-       /* TODO : If one device has multi resources, it comes as bulk data.
-        * To reduce the number of emit_signal, let's send signal only one time for one device.
-        * for ex, client list. */
-       ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_FOUND_RESOURCE,
-                       ctx->signum, value);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("_ocprocess_response_signal() Fail(%d)", ret);
-               return ret;
-       }
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-static inline int _find_cb_handle_context(struct icd_find_context *ctx)
-{
-       int ret;
-       JsonParser *parser;
-       GError *error = NULL;
-       JsonObject *root_obj;
-       JsonArray *rsrc_array;
-       unsigned int rsrc_count, rsrc_index;
+       int i, ret;
+       struct icd_find_context *ctx = context;
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == ctx->payload, IOTCON_ERROR_INVALID_PARAMETER);
-
-       parser = json_parser_new();
-       ret = json_parser_load_from_data(parser, ctx->payload, strlen(ctx->payload), &error);
-       if (FALSE == ret) {
-               ERR("json_parser_load_from_data() Fail(%s)", error->message);
-               g_error_free(error);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       /* parse 'oc' prefix */
-       root_obj = json_node_get_object(json_parser_get_root(parser));
-       rsrc_array = json_object_get_array_member(root_obj, IC_JSON_KEY_OC);
-       if (NULL == rsrc_array) {
-               ERR("json_object_get_array_member() Fail");
-               g_object_unref(parser);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       rsrc_count = json_array_get_length(rsrc_array);
-       if (0 == rsrc_count) {
-               ERR("Invalid count(%d)", rsrc_count);
-               g_object_unref(parser);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
 
-       for (rsrc_index = 0; rsrc_index < rsrc_count; rsrc_index++) {
-               JsonObject *rsrc_obj;
-
-               rsrc_obj = json_array_get_object_element(rsrc_array, rsrc_index);
-               if (0 == json_object_get_size(rsrc_obj)) /* for the case of empty "{}" */
-                       continue;
-
-               ret = _find_cb_response(rsrc_obj, ctx);
+       for (i = 0; ctx->payload[i]; i++) {
+               value = g_variant_new("(vi)", ctx->payload[i], ctx->conn_type);
+               /* TODO : If one device has multi resources, it comes as bulk data.
+                * To reduce the number of emit_signal, let's send signal only one time for one device.
+                * for ex, client list. */
+               ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_FOUND_RESOURCE,
+                               ctx->signum, value);
                if (IOTCON_ERROR_NONE != ret) {
-                       ERR("_find_cb_response() Fail(%d)", ret);
-                       g_object_unref(parser);
+                       ERR("_ocprocess_response_signal() Fail(%d)", ret);
+                       g_variant_unref(value);
                        return ret;
                }
        }
 
-       g_object_unref(parser);
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-static int _worker_find_cb(void *context)
-{
-       int ret;
-       struct icd_find_context *ctx = context;
-
-       RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
-       ret = _find_cb_handle_context(ctx);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("_find_cb_handle_context() Fail(%d)", ret);
-
        /* ctx was allocated from icd_ioty_ocprocess_find_cb() */
        free(ctx->bus_name);
-       free(ctx->payload);
-       free(ctx->dev_addr);
        free(ctx);
 
        return ret;
@@ -554,13 +400,16 @@ OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle
                OCClientResponse *resp)
 {
        int ret;
-       OCDevAddr *dev_addr;
        struct icd_find_context *find_ctx;
        icd_sig_ctx_s *sig_context = ctx;
 
        RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
        RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
-       RETV_IF(NULL == resp->resJSONPayload, OC_STACK_KEEP_TRANSACTION);
+       if (NULL == resp->payload)
+               /* normal case : payload COULD be NULL */
+               return OC_STACK_KEEP_TRANSACTION;
+       RETV_IF(PAYLOAD_TYPE_DISCOVERY != resp->payload->type,
+                       OC_STACK_KEEP_TRANSACTION);
 
        find_ctx = calloc(1, sizeof(struct icd_find_context));
        if (NULL == find_ctx) {
@@ -568,26 +417,17 @@ OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle
                return OC_STACK_KEEP_TRANSACTION;
        }
 
-       dev_addr = calloc(1, sizeof(OCDevAddr));
-       if (NULL == dev_addr) {
-               ERR("calloc() Fail(%d)", errno);
-               free(find_ctx);
-               return OC_STACK_KEEP_TRANSACTION;
-       }
-       memcpy(dev_addr, resp->addr, sizeof(OCDevAddr));
-
        find_ctx->signum = sig_context->signum;
        find_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
-       find_ctx->payload = ic_utils_strdup(resp->resJSONPayload);
-       find_ctx->dev_addr = dev_addr;
-       find_ctx->conn_type = resp->connType;
+       find_ctx->payload = icd_payload_res_to_gvariant(resp->payload, &resp->devAddr);
+       find_ctx->conn_type = icd_ioty_transport_flag_to_conn_type(resp->devAddr.adapter,
+                       resp->devAddr.flags);
 
        ret = _ocprocess_worker_start(_worker_find_cb, find_ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker_start() Fail(%d)", ret);
                free(find_ctx->bus_name);
-               free(find_ctx->payload);
-               free(find_ctx->dev_addr);
+               ic_utils_gvariant_array_free(find_ctx->payload);
                free(find_ctx);
                return OC_STACK_KEEP_TRANSACTION;
        }
@@ -609,11 +449,10 @@ static int _worker_crud_cb(void *context)
        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);
+               value = g_variant_new("(a(qs)vi)", ctx->options, ctx->payload, ctx->res);
        icd_ioty_complete(ctx->crud_type, ctx->invocation, value);
 
        /* ctx was allocated from icd_ioty_ocprocess_xxx_cb() */
-       free(ctx->payload);
        g_variant_builder_unref(ctx->options);
        free(ctx);
 
@@ -621,31 +460,32 @@ static int _worker_crud_cb(void *context)
 }
 
 
-static int _worker_platform_cb(void *context)
+static int _worker_info_cb(void *context)
 {
        int ret;
-       GVariant *value;
-       struct icd_platform_context *ctx = context;
+       const char *sig_name = NULL;
+       struct icd_info_context *ctx = context;
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
 
-       value = g_variant_new("(s)", ctx->payload);
+       if (ICD_DEVICE_INFO == ctx->info_type)
+               sig_name = IC_DBUS_SIGNAL_DEVICE;
+       else if (ICD_PLATFORM_INFO == ctx->info_type)
+               sig_name = IC_DBUS_SIGNAL_PLATFORM;
 
-       ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_PLATFORM, ctx->signum,
-                       value);
+       ret = _ocprocess_response_signal(ctx->bus_name, sig_name, ctx->signum, ctx->payload);
        if (IOTCON_ERROR_NONE != ret)
                ERR("_ocprocess_response_signal() Fail(%d)", ret);
 
-       /* ctx was allocated from icd_ioty_ocprocess_platform_cb() */
+       /* ctx was allocated from icd_ioty_ocprocess_info_cb() */
        free(ctx->bus_name);
-       free(ctx->payload);
        free(ctx);
 
        return ret;
 }
 
 
-static int _ocprocess_worker(_ocprocess_fn fn, int type, const char *payload, int res,
+static int _ocprocess_worker(_ocprocess_fn fn, int type, OCPayload *payload, int res,
                GVariantBuilder *options, void *ctx)
 {
        int ret;
@@ -658,7 +498,7 @@ static int _ocprocess_worker(_ocprocess_fn fn, int type, const char *payload, in
        }
 
        crud_ctx->crud_type = type;
-       crud_ctx->payload = strdup(ic_utils_dbus_encode_str(payload));
+       crud_ctx->payload = icd_payload_to_gvariant(payload);
        crud_ctx->res = res;
        crud_ctx->options = options;
        crud_ctx->invocation = ctx;
@@ -666,7 +506,8 @@ static int _ocprocess_worker(_ocprocess_fn fn, int type, const char *payload, in
        ret = _ocprocess_worker_start(fn, crud_ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker_start() Fail(%d)", ret);
-               free(crud_ctx->payload);
+               if (crud_ctx->payload)
+                       g_variant_unref(crud_ctx->payload);
                g_variant_builder_unref(crud_ctx->options);
                free(crud_ctx);
        }
@@ -684,23 +525,15 @@ OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
        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");
+       if (NULL == resp->payload) {
+               ERR("payload is empty");
                icd_ioty_complete_error(ICD_CRUD_GET, 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_GET, ctx, IOTCON_ERROR_OUT_OF_MEMORY);
-               return OC_STACK_DELETE_TRANSACTION;
-       }
-
        result = resp->result;
        if (OC_STACK_OK == result) {
                res = IOTCON_RESPONSE_RESULT_OK;
@@ -712,7 +545,7 @@ OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
                options = NULL;
        }
 
-       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_GET, resp->resJSONPayload, res,
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_GET, resp->payload, res,
                        options, ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker() Fail(%d)", ret);
@@ -734,8 +567,8 @@ OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
 
        RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
 
-       if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
-               ERR("json payload is empty");
+       if (NULL == resp->payload) {
+               ERR("payload is empty");
                icd_ioty_complete_error(ICD_CRUD_PUT, ctx, IOTCON_ERROR_IOTIVITY);
                return OC_STACK_DELETE_TRANSACTION;
        }
@@ -759,7 +592,7 @@ OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
                                resp->numRcvdVendorSpecificHeaderOptions);
        }
 
-       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_PUT, resp->resJSONPayload, res,
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_PUT, resp->payload, res,
                        options, ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker() Fail(%d)", ret);
@@ -778,23 +611,15 @@ OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle
        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");
+       if (NULL == resp->payload) {
+               ERR("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:
@@ -814,7 +639,7 @@ OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle
                                resp->numRcvdVendorSpecificHeaderOptions);
        }
 
-       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_POST, resp->resJSONPayload, res,
+       ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_POST, resp->payload, res,
                        options, ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker() Fail(%d)", ret);
@@ -833,23 +658,15 @@ OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle hand
        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");
+       if (NULL == resp->payload) {
+               ERR("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:
@@ -876,8 +693,6 @@ OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle hand
                return OC_STACK_DELETE_TRANSACTION;
        }
 
-       /* DO NOT FREE crud_ctx. It MUST be freed in the _worker_delete_cb func */
-
        return OC_STACK_DELETE_TRANSACTION;
 }
 
@@ -890,7 +705,7 @@ static int _worker_observe_cb(void *context)
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
 
-       value = g_variant_new("(a(qs)sii)", ctx->options, ctx->payload, ctx->res,
+       value = g_variant_new("(a(qs)vii)", ctx->options, ctx->payload, ctx->res,
                        ctx->seqnum);
 
        ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_OBSERVE, ctx->signum,
@@ -900,7 +715,6 @@ static int _worker_observe_cb(void *context)
 
        /* ctx was allocated from icd_ioty_ocprocess_observe_cb() */
        free(ctx->bus_name);
-       free(ctx->payload);
        g_variant_builder_unref(ctx->options);
        free(ctx);
 
@@ -913,7 +727,7 @@ static void _observe_cb_response_error(const char *dest, unsigned int signum, in
        int ret;
        GVariant *value;
 
-       value = g_variant_new("(a(qs)sii)", NULL, IC_STR_NULL, ret_val, 0);
+       value = g_variant_new("(a(qs)vii)", NULL, NULL, ret_val, 0);
 
        ret = _ocprocess_response_signal(dest, IC_DBUS_SIGNAL_OBSERVE, signum, value);
        if (IOTCON_ERROR_NONE != ret)
@@ -932,8 +746,8 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle han
 
        RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
 
-       if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
-               ERR("json payload is empty");
+       if (NULL == resp->payload) {
+               ERR("payload is empty");
                _observe_cb_response_error(sig_context->bus_name, sig_context->signum,
                                IOTCON_ERROR_IOTIVITY);
                return OC_STACK_KEEP_TRANSACTION;
@@ -958,7 +772,7 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle han
                options = NULL;
        }
 
-       observe_ctx->payload = strdup(resp->resJSONPayload);
+       observe_ctx->payload = icd_payload_to_gvariant(resp->payload);
        observe_ctx->signum = sig_context->signum;
        observe_ctx->res = res;
        observe_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
@@ -969,7 +783,8 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle han
                ERR("_ocprocess_worker_start() Fail(%d)", ret);
                _observe_cb_response_error(sig_context->bus_name, sig_context->signum, ret);
                free(observe_ctx->bus_name);
-               free(observe_ctx->payload);
+               if (observe_ctx->payload)
+                       g_variant_unref(observe_ctx->payload);
                g_variant_builder_unref(observe_ctx->options);
                free(observe_ctx);
                return OC_STACK_KEEP_TRANSACTION;
@@ -982,39 +797,17 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle han
 }
 
 
-
 static int _worker_presence_cb(void *context)
 {
        FN_CALL;
        int ret;
-       uint16_t port;
-       uint8_t a, b, c, d;
        GVariant *value;
        char addr[PATH_MAX] = {0};
        struct icd_presence_context *ctx = context;
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
 
-       ret = OCDevAddrToIPv4Addr(ctx->dev_addr, &a, &b, &c, &d);
-       if (OC_STACK_OK != ret) {
-               ERR("OCDevAddrToIPv4Addr() Fail(%d)", ret);
-               free(ctx->bus_name);
-               free(ctx->dev_addr);
-               free(ctx);
-               return ret;
-       }
-
-       ret = OCDevAddrToPort(ctx->dev_addr, &port);
-       if (OC_STACK_OK != ret) {
-               ERR("OCDevAddrToPort() Fail(%d)", ret);
-               free(ctx->bus_name);
-               free(ctx->dev_addr);
-               free(ctx);
-               return ret;
-       }
-
-       /* TODO coap:// ? */
-       snprintf(addr, sizeof(addr), ICD_IOTY_COAP"%d.%d.%d.%d:%d", a, b, c, d, port);
+       snprintf(addr, sizeof(addr), "%s:%d", ctx->dev_addr->addr, ctx->dev_addr->port);
 
        value = g_variant_new("(ius)", ctx->result, ctx->nonce, addr);
 
@@ -1057,6 +850,7 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
        struct icd_presence_context *presence_ctx;
 
        RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
+       RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
 
        presence_ctx = calloc(1, sizeof(struct icd_presence_context));
        if (NULL == presence_ctx) {
@@ -1074,7 +868,7 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
                free(presence_ctx);
                return OC_STACK_KEEP_TRANSACTION;
        }
-       memcpy(dev_addr, resp->addr, sizeof(OCDevAddr));
+       memcpy(dev_addr, &resp->devAddr, sizeof(OCDevAddr));
 
        switch (resp->result) {
        case OC_STACK_OK:
@@ -1114,41 +908,50 @@ OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle ha
 }
 
 
-OCStackApplicationResult icd_ioty_ocprocess_platform_cb(void *ctx, OCDoHandle handle,
+OCStackApplicationResult icd_ioty_ocprocess_info_cb(void *ctx, OCDoHandle handle,
                OCClientResponse *resp)
 {
        int ret;
-       struct icd_platform_context *platform_ctx;
+       int info_type;
+       struct icd_info_context *info_ctx;
        icd_sig_ctx_s *sig_context = ctx;
 
        RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
+       RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
+       RETV_IF(NULL == resp->payload, OC_STACK_KEEP_TRANSACTION);
 
-       if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
-               ERR("json payload is empty");
+       if (PAYLOAD_TYPE_DEVICE == resp->payload->type)
+               info_type = ICD_DEVICE_INFO;
+       else if (PAYLOAD_TYPE_PLATFORM == resp->payload->type)
+               info_type = ICD_PLATFORM_INFO;
+       else
                return OC_STACK_KEEP_TRANSACTION;
-       }
 
-       platform_ctx = calloc(1, sizeof(struct icd_platform_context));
-       if (NULL == platform_ctx) {
+       info_ctx = calloc(1, sizeof(struct icd_info_context));
+       if (NULL == info_ctx) {
                ERR("calloc() Fail(%d)", errno);
                return OC_STACK_KEEP_TRANSACTION;
        }
 
-       platform_ctx->payload = strdup(resp->resJSONPayload);
-       platform_ctx->signum = sig_context->signum;
-       platform_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
+       info_ctx->info_type = info_type;
+       info_ctx->payload = icd_payload_to_gvariant(resp->payload);
+       info_ctx->signum = sig_context->signum;
+       info_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
 
-       ret = _ocprocess_worker_start(_worker_platform_cb, platform_ctx);
+       ret = _ocprocess_worker_start(_worker_info_cb, info_ctx);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_ocprocess_worker_start() Fail(%d)", ret);
-               free(platform_ctx->bus_name);
-               free(platform_ctx->payload);
-               free(platform_ctx);
+               free(info_ctx->bus_name);
+               if (info_ctx->payload)
+                       g_variant_unref(info_ctx->payload);
+               free(info_ctx);
                return OC_STACK_KEEP_TRANSACTION;
        }
 
        /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
-       /* DO NOT FREE platform_ctx. It MUST be freed in the _worker_platform_cb func */
+       /* DO NOT FREE info_ctx. It MUST be freed in the _worker_info_cb func */
 
        return OC_STACK_KEEP_TRANSACTION;
 }
+
+
index eb18682..fec5cbe 100644 (file)
@@ -13,8 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_THREAD_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_THREAD_H__
+#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_OCPROCESS_H__
+#define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_OCPROCESS_H__
 
 #include <glib.h>
 #include <octypes.h>
@@ -24,7 +24,7 @@ void icd_ioty_ocprocess_stop();
 gpointer icd_ioty_ocprocess_thread(gpointer data);
 
 OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
-               OCEntityHandlerRequest *request);
+               OCEntityHandlerRequest *request, void *user_data);
 
 OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle,
                OCClientResponse* resp);
@@ -47,7 +47,7 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle han
 OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle handle,
                OCClientResponse* resp);
 
-OCStackApplicationResult icd_ioty_ocprocess_platform_cb(void *ctx, OCDoHandle handle,
+OCStackApplicationResult icd_ioty_ocprocess_info_cb(void *ctx, OCDoHandle handle,
                OCClientResponse *resp);
 
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_THREAD_H__*/
+#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_OCPROCESS_H__*/
diff --git a/daemon/icd-ioty-type.c b/daemon/icd-ioty-type.c
new file mode 100644 (file)
index 0000000..59575bc
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <octypes.h>
+
+#include "iotcon-constant.h"
+#include "icd.h"
+#include "icd-ioty-type.h"
+
+OCConnectivityType icd_ioty_conn_type_to_oic_conn_type(int conn_type)
+{
+       OCConnectivityType oic_conn_type = CT_DEFAULT;
+
+       switch (conn_type) {
+       case IOTCON_CONNECTIVITY_IPV4:
+               oic_conn_type = CT_IP_USE_V4;
+               break;
+       case IOTCON_CONNECTIVITY_IPV6:
+               oic_conn_type = CT_IP_USE_V6;
+               break;
+       case IOTCON_CONNECTIVITY_EDR:
+               oic_conn_type = CT_ADAPTER_RFCOMM_BTEDR;
+               break;
+       case IOTCON_CONNECTIVITY_LE:
+               oic_conn_type = CT_ADAPTER_GATT_BTLE;
+               break;
+       case IOTCON_CONNECTIVITY_ALL:
+       default:
+               oic_conn_type = CT_DEFAULT;
+       }
+
+       return oic_conn_type;
+}
+
+
+int icd_ioty_transport_flag_to_conn_type(OCTransportAdapter adapter,
+               OCTransportFlags flag)
+{
+       int conn_type = IOTCON_CONNECTIVITY_ALL;
+
+       /* Need to consider to allow various connectivity types */
+       switch (adapter) {
+       case OC_ADAPTER_IP:
+               if (OC_IP_USE_V4 == flag)
+                       conn_type = IOTCON_CONNECTIVITY_IPV4;
+               else if (OC_IP_USE_V6 == flag)
+                       conn_type = IOTCON_CONNECTIVITY_IPV6;
+               break;
+       case OC_ADAPTER_RFCOMM_BTEDR:
+               conn_type = IOTCON_CONNECTIVITY_EDR;
+               break;
+       case OC_ADAPTER_GATT_BTLE:
+               conn_type = IOTCON_CONNECTIVITY_LE;
+               break;
+       default:
+               ERR("Invalid Adpater");
+       }
+
+       return conn_type;
+}
+
+
+
diff --git a/daemon/icd-ioty-type.h b/daemon/icd-ioty-type.h
new file mode 100644 (file)
index 0000000..5fc1ecb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_TYPE_H__
+#define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_TYPE_H__
+
+#include <octypes.h>
+
+#include "iotcon-constant.h"
+
+OCConnectivityType icd_ioty_conn_type_to_oic_conn_type(int conn_type);
+
+int icd_ioty_transport_flag_to_conn_type(OCTransportAdapter adapter,
+               OCTransportFlags flag);
+
+#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_TYPE_H__*/
index 08a9deb..5d2896e 100644 (file)
@@ -20,7 +20,6 @@
 #include <stdbool.h>
 #include <errno.h>
 #include <glib.h>
-#include <json-glib/json-glib.h>
 
 #include <octypes.h>
 #include <ocstack.h>
 #include "ic-dbus.h"
 #include "ic-utils.h"
 #include "icd.h"
+#include "icd-payload.h"
 #include "icd-dbus.h"
 #include "icd-ioty.h"
+#include "icd-ioty-type.h"
 #include "icd-ioty-ocprocess.h"
 
-#define ICD_IOTY_PLATFORM_URI_PATH "/oic/p"
-
 static GMutex icd_csdk_mutex;
 
 void icd_ioty_csdk_lock()
@@ -95,28 +94,31 @@ OCResourceHandle icd_ioty_register_resource(const char *uri_path,
        int i;
        OCStackResult ret;
        OCResourceHandle handle;
-       const char *resInterface = NULL;
+       const char *res_iface = NULL;
 
        if (IOTCON_INTERFACE_DEFAULT & ifaces) {
-               resInterface = IC_INTERFACE_DEFAULT;
+               res_iface = IC_INTERFACE_DEFAULT;
                ifaces ^= IOTCON_INTERFACE_DEFAULT;
        } else if (IOTCON_INTERFACE_LINK & ifaces) {
-               resInterface = IC_INTERFACE_LINK;
+               res_iface = IC_INTERFACE_LINK;
                ifaces ^= IOTCON_INTERFACE_LINK;
        } else if (IOTCON_INTERFACE_BATCH & ifaces) {
-               resInterface = IC_INTERFACE_BATCH;
+               res_iface = IC_INTERFACE_BATCH;
                ifaces ^= IOTCON_INTERFACE_BATCH;
        } else if (IOTCON_INTERFACE_GROUP & ifaces) {
-               resInterface = IC_INTERFACE_GROUP;
+               res_iface = IC_INTERFACE_GROUP;
                ifaces ^= IOTCON_INTERFACE_GROUP;
        } else {
                ERR("Invalid interface type(%d)", ifaces);
                return NULL;
        }
 
+       /* Secure option is not supported yet. */
+       properties = (properties & OC_SECURE)? (properties ^ OC_SECURE):properties;
+
        icd_ioty_csdk_lock();
-       ret = OCCreateResource(&handle, res_types[0], resInterface, uri_path,
-                       icd_ioty_ocprocess_req_handler, properties);
+       ret = OCCreateResource(&handle, res_types[0], res_iface, uri_path,
+                       icd_ioty_ocprocess_req_handler, NULL, properties);
        icd_ioty_csdk_unlock();
        if (OC_STACK_OK != ret) {
                ERR("OCCreateResource() Fail(%d)", ret);
@@ -141,7 +143,6 @@ OCResourceHandle icd_ioty_register_resource(const char *uri_path,
 
 int icd_ioty_unregister_resource(OCResourceHandle handle)
 {
-       FN_CALL;
        OCStackResult ret;
 
        icd_ioty_csdk_lock();
@@ -232,9 +233,10 @@ int icd_ioty_notify_list_of_observers(OCResourceHandle handle, GVariant *msg,
                GVariant *observers)
 {
        int i, error_code, obs_length;
-       char *repr_json = NULL;
+       GVariant *repr_gvar;
        GVariantIter obs_iter, msg_iter;
        OCStackResult ret;
+       OCRepPayload *payload;
 
        g_variant_iter_init(&obs_iter, observers);
        obs_length = g_variant_iter_n_children(&obs_iter);
@@ -246,12 +248,14 @@ int icd_ioty_notify_list_of_observers(OCResourceHandle handle, GVariant *msg,
                g_variant_iter_loop(&obs_iter, "i", &obs_ids[i]);
 
        g_variant_iter_init(&msg_iter, msg);
-       g_variant_iter_loop(&msg_iter, "(i&s)", &error_code, &repr_json);
+       g_variant_iter_loop(&msg_iter, "(iv)", &error_code, &repr_gvar);
        /* TODO : How to use error_code. */
 
+       payload = icd_payload_repr_from_gvariant(repr_gvar);
+
        icd_ioty_csdk_lock();
-       /* TODO : QoS is come from lib. And user can set QoS to client structure.  */
-       ret = OCNotifyListOfObservers(handle, obs_ids, obs_length, repr_json, OC_HIGH_QOS);
+       /* TODO : QoS is come from lib. */
+       ret = OCNotifyListOfObservers(handle, obs_ids, obs_length, payload, OC_LOW_QOS);
        icd_ioty_csdk_unlock();
 
        if (OC_STACK_NO_OBSERVERS == ret) {
@@ -271,8 +275,8 @@ int icd_ioty_notify_all(OCResourceHandle handle)
        OCStackResult ret;
 
        icd_ioty_csdk_lock();
-       /* TODO : QoS is come from lib. And user can set QoS to client structure.  */
-       ret = OCNotifyAllObservers(handle, OC_HIGH_QOS);
+       /* TODO : QoS is come from lib. */
+       ret = OCNotifyAllObservers(handle, OC_LOW_QOS);
        icd_ioty_csdk_unlock();
 
        if (OC_STACK_NO_OBSERVERS == ret) {
@@ -317,17 +321,18 @@ int icd_ioty_send_response(GVariant *resp)
 {
        int result, error_code, options_size;
        int request_handle, resource_handle;
-       char *new_uri_path, *repr_json;
+       char *new_uri_path;
+       GVariant *repr_gvar;
        GVariantIter *options;
        OCStackResult ret;
        OCEntityHandlerResponse response = {0};
 
-       g_variant_get(resp, "(&sia(qs)i&sii)",
+       g_variant_get(resp, "(&sia(qs)ivii)",
                        &new_uri_path,
                        &error_code,
                        &options,
                        &result,
-                       &repr_json,
+                       &repr_gvar,
                        &request_handle,
                        &resource_handle);
 
@@ -353,8 +358,7 @@ int icd_ioty_send_response(GVariant *resp)
        }
        g_variant_iter_free(options);
 
-       response.payload = repr_json;
-       response.payloadSize = strlen(response.payload) + 1;
+       response.payload = (OCPayload*)icd_payload_repr_from_gvariant(repr_gvar);
 
        /* related to block transfer */
        response.persistentBufferFlag = 0;
@@ -379,22 +383,23 @@ static void _ioty_free_signal_context(void *data)
        free(context);
 }
 
+
 int icd_ioty_find_resource(const char *host_address, const char *resource_type,
                unsigned int signum, const char *bus_name)
 {
        int len;
        OCStackResult result;
-       OCCallbackData cbdata = {0};
        icd_sig_ctx_s *context;
        char uri[PATH_MAX] = {0};
+       OCCallbackData cbdata = {0};
+       OCConnectivityType oic_conn_type;
        iotcon_connectivity_type_e conn_type = IOTCON_CONNECTIVITY_IPV4;
 
        if (IC_STR_EQUAL == strcmp(IOTCON_MULTICAST_ADDRESS, host_address)) {
-               len = snprintf(uri, sizeof(uri), "%s", OC_MULTICAST_DISCOVERY_URI);
-               conn_type = IOTCON_CONNECTIVITY_ALL;
+               len = snprintf(uri, sizeof(uri), "%s", OC_RSRVD_WELL_KNOWN_URI);
        } else {
                len = snprintf(uri, sizeof(uri), ICD_IOTY_COAP"%s%s", host_address,
-                               OC_MULTICAST_DISCOVERY_URI);
+                               OC_RSRVD_WELL_KNOWN_URI);
        }
        if (len <= 0 || sizeof(uri) <= len) {
                ERR("snprintf() Fail(%d)", len);
@@ -417,9 +422,12 @@ int icd_ioty_find_resource(const char *host_address, const char *resource_type,
        cbdata.cb = icd_ioty_ocprocess_find_cb;
        cbdata.cd = _ioty_free_signal_context;
 
+       oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
+
        icd_ioty_csdk_lock();
-       result = OCDoResource(NULL, OC_REST_GET, uri, NULL, NULL, conn_type, OC_LOW_QOS,
-                       &cbdata, NULL, 0);
+       /* TODO : QoS is come from lib. */
+       result = OCDoResource(NULL, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
+                       OC_LOW_QOS, &cbdata, NULL, 0);
        icd_ioty_csdk_unlock();
 
        if (OC_STACK_OK != result) {
@@ -436,7 +444,8 @@ int icd_ioty_find_resource(const char *host_address, const char *resource_type,
 /*
  * returned string SHOULD be released by you
  */
-static char* _icd_ioty_resource_generate_uri(char *host, char *uri_path, GVariant *query)
+static char* _icd_ioty_resource_generate_uri(char *host, bool is_secure, char *uri_path,
+               GVariant *query)
 {
        int len;
        bool loop_first = true;
@@ -444,7 +453,10 @@ static char* _icd_ioty_resource_generate_uri(char *host, char *uri_path, GVarian
        GVariantIter query_iter;
        char uri_buf[PATH_MAX] = {0};
 
-       len = snprintf(uri_buf, sizeof(uri_buf), "%s%s", host, uri_path);
+       if (is_secure)
+               len = snprintf(uri_buf, sizeof(uri_buf), ICD_IOTY_COAPS"%s%s", host, uri_path);
+       else
+               len = snprintf(uri_buf, sizeof(uri_buf), ICD_IOTY_COAP"%s%s", host, uri_path);
 
        /* remove suffix '/' */
        if ('/' == uri_buf[strlen(uri_buf) - 1]) {
@@ -498,15 +510,15 @@ void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int re
 
        switch (type) {
        case ICD_CRUD_GET:
-               value = g_variant_new("(a(qs)si)", NULL, IC_STR_NULL, ret_val);
+               value = g_variant_new("(a(qs)vi)", NULL, 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);
+               value = g_variant_new("(a(qs)vi)", NULL, 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);
+               value = g_variant_new("(a(qs)vi)", NULL, NULL, ret_val);
                ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
                break;
        case ICD_CRUD_DELETE:
@@ -518,8 +530,9 @@ void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int re
 
 
 static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *invocation,
-               GVariant *resource, GVariant *query, const char *repr)
+               GVariant *resource, GVariant *query, GVariant *repr)
 {
+       bool is_secure;
        OCMethod rest_type;
        OCStackResult result;
        GVariantIter *options;
@@ -529,6 +542,8 @@ static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *
        char uri_buf[PATH_MAX] = {0};
        OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
        OCHeaderOption *oic_options_ptr = NULL;
+       OCPayload *payload = NULL;
+       OCConnectivityType oic_conn_type;
 
        switch (type) {
        case ICD_CRUD_GET:
@@ -552,13 +567,14 @@ static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *
                return FALSE;
        }
 
-       g_variant_get(resource, "(&s&sa(qs)i)", &uri_path, &host, &options, &conn_type);
+       g_variant_get(resource, "(&s&sba(qs)i)", &uri_path, &host, &is_secure,  &options,
+                       &conn_type);
 
        switch (type) {
        case ICD_CRUD_GET:
        case ICD_CRUD_PUT:
        case ICD_CRUD_POST:
-               uri = _icd_ioty_resource_generate_uri(host, uri_path, query);
+               uri = _icd_ioty_resource_generate_uri(host, is_secure, uri_path, query);
                if (NULL == uri) {
                        ERR("_icd_ioty_resource_generate_uri() Fail");
                        g_variant_iter_free(options);
@@ -589,9 +605,14 @@ static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *
        }
        g_variant_iter_free(options);
 
+       if (repr)
+               payload = (OCPayload*)icd_payload_repr_from_gvariant(repr);
+
+       oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
+
        icd_ioty_csdk_lock();
        /* TODO : QoS is come from lib. And user can set QoS to client structure.  */
-       result = OCDoResource(NULL, rest_type, uri, NULL, repr, conn_type, OC_HIGH_QOS,
+       result = OCDoResource(NULL, rest_type, uri, NULL, payload, oic_conn_type, OC_LOW_QOS,
                        &cbdata, oic_options_ptr, options_size);
        icd_ioty_csdk_unlock();
 
@@ -609,23 +630,20 @@ static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *
 gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, GVariant *query)
 {
-       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)
+               GVariant *resource, GVariant *repr, GVariant *query)
 {
-       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)
+               GVariant *resource, GVariant *repr, GVariant *query)
 {
-       FN_CALL;
        return _icd_ioty_crud(ICD_CRUD_POST, object, invocation, resource, query, repr);
 }
 
@@ -633,7 +651,6 @@ gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
 gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource)
 {
-       FN_CALL;
        return _icd_ioty_crud(ICD_CRUD_DELETE, object, invocation, resource, NULL, NULL);
 }
 
@@ -641,6 +658,7 @@ gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
 OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVariant *query,
                unsigned int signal_number, const char *bus_name)
 {
+       bool is_secure;
        OCMethod method;
        OCDoHandle handle;
        OCStackResult result;
@@ -651,10 +669,12 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVarian
        char *uri_path, *host, *uri;
        OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
        OCHeaderOption *oic_options_ptr = NULL;
+       OCConnectivityType oic_conn_type;
 
-       g_variant_get(resource, "(&s&sa(qs)i)", &uri_path, &host, &options, &conn_type);
+       g_variant_get(resource, "(&s&sba(qs)i)", &uri_path, &host, &is_secure,  &options,
+                       &conn_type);
 
-       uri = _icd_ioty_resource_generate_uri(host, uri_path, query);
+       uri = _icd_ioty_resource_generate_uri(host, is_secure, uri_path, query);
        if (NULL == uri) {
                ERR("_icd_ioty_resource_generate_uri() Fail");
                g_variant_iter_free(options);
@@ -696,9 +716,11 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVarian
        }
        g_variant_iter_free(options);
 
+       oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
+
        icd_ioty_csdk_lock();
        /* TODO : QoS is come from lib. And user can set QoS to client structure.  */
-       result = OCDoResource(&handle, method, uri, NULL, NULL, conn_type, OC_HIGH_QOS,
+       result = OCDoResource(&handle, method, uri, NULL, NULL, oic_conn_type, OC_LOW_QOS,
                        &cbdata, oic_options_ptr, options_size);
        icd_ioty_csdk_unlock();
        free(uri);
@@ -746,21 +768,24 @@ int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options)
 }
 
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
 int icd_ioty_register_device_info(GVariant *value)
 {
-       // TODO : To be implemented
-       return IOTCON_ERROR_NONE;
-}
+       OCStackResult result;
+       OCDeviceInfo device_info = {0};
 
+       g_variant_get(value, "(&s)", &device_info.deviceName);
+
+       icd_ioty_csdk_lock();
+       result = OCSetDeviceInfo(device_info);
+       icd_ioty_csdk_unlock();
+
+       if (OC_STACK_OK != result) {
+               ERR("OCSetDeviceInfo() Fail(%d)", result);
+               return IOTCON_ERROR_IOTIVITY;
+       }
 
-int icd_ioty_get_device_info(const char *host_address,
-               unsigned int signal_number, const char *bus_name)
-{
-       // TODO : To be implemented
        return IOTCON_ERROR_NONE;
 }
-#endif
 
 
 int icd_ioty_register_platform_info(GVariant *value)
@@ -794,46 +819,49 @@ int icd_ioty_register_platform_info(GVariant *value)
 }
 
 
-int icd_ioty_get_platform_info(const char *host_address, unsigned int signal_number,
+int icd_ioty_get_info(int type, const char *host_address, unsigned int signal_number,
                const char *bus_name)
 {
-       FN_CALL;
-       char *uri;
        OCStackResult result;
        icd_sig_ctx_s *context;
        OCCallbackData cbdata = {0};
-       char uri_buf[PATH_MAX] = {0};
+       char uri[PATH_MAX] = {0};
+       char *uri_path = NULL;
        iotcon_connectivity_type_e conn_type = IOTCON_CONNECTIVITY_IPV4;
+       OCConnectivityType oic_conn_type;
 
-       snprintf(uri_buf, sizeof(uri_buf), "%s:%d"ICD_IOTY_PLATFORM_URI_PATH, host_address,
-                       OC_MULTICAST_PORT);
-       uri = strdup(uri_buf);
-       if (NULL == uri) {
-               ERR("strdup() Fail(%d)", errno);
+       if (ICD_DEVICE_INFO == type)
+               uri_path = OC_RSRVD_DEVICE_URI;
+       else if (ICD_PLATFORM_INFO == type)
+               uri_path = OC_RSRVD_PLATFORM_URI;
+       else
                return IOTCON_ERROR_INVALID_PARAMETER;
-       }
+
+       if (IC_STR_EQUAL == strcmp(IOTCON_MULTICAST_ADDRESS, host_address))
+               snprintf(uri, sizeof(uri), "%s", uri_path);
+       else
+               snprintf(uri, sizeof(uri), "%s%s", host_address, uri_path);
 
        context = calloc(1, sizeof(icd_sig_ctx_s));
        if (NULL == context) {
                ERR("calloc() Fail(%d)", errno);
-               free(uri);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
        context->bus_name = ic_utils_strdup(bus_name);
        context->signum = signal_number;
 
        cbdata.context = context;
-       cbdata.cb = icd_ioty_ocprocess_platform_cb;
+       cbdata.cb = icd_ioty_ocprocess_info_cb;
        cbdata.cd = _ioty_free_signal_context;
 
+       oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
+
        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, NULL, 0);
+       result = OCDoResource(NULL, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
+                       OC_LOW_QOS, &cbdata, NULL, 0);
        icd_ioty_csdk_unlock();
 
-       free(uri);
-
        if (OC_STACK_OK != result) {
                ERR("OCDoResource() Fail(%d)", result);
                free(context->bus_name);
@@ -855,8 +883,9 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address,
        OCCallbackData cbdata = {0};
        icd_sig_ctx_s *context;
        iotcon_connectivity_type_e conn_type = IOTCON_CONNECTIVITY_IPV4;
+       OCConnectivityType oic_conn_type;
 
-       len = snprintf(uri, sizeof(uri), "%s%s", host_address, OC_PRESENCE_URI);
+       len = snprintf(uri, sizeof(uri), "%s%s", host_address, OC_RSRVD_PRESENCE_URI);
        if (len <= 0 || sizeof(uri) <= len) {
                ERR("snprintf() Fail(%d)", len);
                return NULL;
@@ -877,11 +906,10 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address,
        cbdata.cb = icd_ioty_ocprocess_presence_cb;
        cbdata.cd = _ioty_free_signal_context;
 
-       /* TODO : OC_ALL has wrong behaviour in iotivity version 0.9.1.
-        * Therefore, OC_IPV4 SHOULD be changed to OC_ALL later.
-        */
+       oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
+
        icd_ioty_csdk_lock();
-       result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, conn_type,
+       result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, oic_conn_type,
                        OC_LOW_QOS, &cbdata, NULL, 0);
        icd_ioty_csdk_unlock();
 
index 7fbc758..60fa22a 100644 (file)
@@ -36,7 +36,9 @@ enum {
        ICD_CRUD_GET,
        ICD_CRUD_PUT,
        ICD_CRUD_POST,
-       ICD_CRUD_DELETE
+       ICD_CRUD_DELETE,
+       ICD_DEVICE_INFO,
+       ICD_PLATFORM_INFO,
 };
 
 void icd_ioty_csdk_lock();
@@ -77,10 +79,10 @@ gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource, GVariant *query);
 
 gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
-               GVariant *resource, const char *repr, GVariant *query);
+               GVariant *resource, GVariant *repr, GVariant *query);
 
 gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
-               GVariant *resource, const char *repr, GVariant *query);
+               GVariant *resource, GVariant *repr, GVariant *query);
 
 gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
                GVariant *resource);
@@ -90,16 +92,11 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVarian
 
 int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options);
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
 int icd_ioty_register_device_info(GVariant *value);
 
-int icd_ioty_get_device_info(const char *host_address, unsigned int signal_number,
-               const char *bus_name);
-#endif
-
 int icd_ioty_register_platform_info(GVariant *value);
 
-int icd_ioty_get_platform_info(const char *host_address, unsigned int signal_number,
+int icd_ioty_get_info(int type, const char *host_address, unsigned int signal_number,
                const char *bus_name);
 
 OCDoHandle icd_ioty_subscribe_presence(const char *host_address,
diff --git a/daemon/icd-payload.c b/daemon/icd-payload.c
new file mode 100644 (file)
index 0000000..b9cfbf8
--- /dev/null
@@ -0,0 +1,622 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdint.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include <ocstack.h>
+#include <octypes.h>
+#include <ocpayload.h>
+#include <ocrandom.h>
+
+#include "iotcon.h"
+#include "ic-utils.h"
+#include "icd.h"
+#include "icd-payload.h"
+
+union icd_repr_value_u {
+       int i;
+       double d;
+       bool b;
+};
+
+struct icd_repr_list_s {
+       OCRepPayloadPropType type;
+       size_t dimensions[MAX_REP_ARRAY_DEPTH];
+       GList *list;
+};
+
+static GVariant* _icd_payload_repr_to_gvariant(OCRepPayload *repr, gboolean is_parent);
+
+GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
+{
+       int port = 0;
+       int ifaces = 0;
+       GVariant **value;
+       OCStringLL *node;
+       iotcon_interface_e iface;
+       GVariantBuilder types;
+       OCRandomUuidResult random_res;
+       OCDiscoveryPayload *discovered;
+       char sid[UUID_STRING_SIZE] = {0};
+       struct OCResourcePayload *resource;
+       int i, is_observable, ret, res_count;
+
+       discovered = (OCDiscoveryPayload*)payload;
+       resource = discovered->resources;
+
+       res_count = OCDiscoveryPayloadGetResourceCount(discovered);
+
+       value = calloc(res_count, sizeof(GVariant*));
+       if (NULL == value) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+       for (i = 0; resource; i++) {
+               /* uri path */
+               if (NULL == resource->uri) {
+                       ERR("resource uri is NULL");
+                       resource = resource->next;
+               }
+
+               /* sid */
+               random_res = OCConvertUuidToString(resource->sid, sid);
+               if (RAND_UUID_OK != random_res) {
+                       ERR("OCConvertUuidToString() Fail(%d)", random_res);
+                       resource = resource->next;
+               }
+
+               /* Resource Types */
+               g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
+               node = resource->types;
+               if (NULL == node) {
+                       ERR("resource types is NULL");
+                       resource = resource->next;
+               }
+               while (node) {
+                       g_variant_builder_add(&types, "s", node->value);
+                       node = node->next;
+               }
+
+               /* Resource Interfaces */
+               node = resource->interfaces;
+               if (NULL == node) {
+                       ERR("resource interfaces is NULL");
+                       resource = resource->next;
+               }
+               while (node) {
+                       ret = ic_utils_convert_interface_string(node->value, &iface);
+                       if (IOTCON_ERROR_NONE != ret) {
+                               ERR("ic_utils_convert_interface_string() Fail(%d)", ret);
+                               resource = resource->next;
+                       }
+                       ifaces |= iface;
+
+                       node = node->next;
+               }
+
+               /* is_observable */
+               is_observable = resource->bitmap & OC_OBSERVABLE;
+
+               /* port */
+               port = (resource->port)? resource->port:dev_addr->port;
+
+               value[i] = g_variant_new("(ssiasibsi)", resource->uri, sid, ifaces, &types,
+                               is_observable, resource->secure, dev_addr->addr, port);
+               DBG("found resource[%d] : %s", i, g_variant_print(value[i], FALSE));
+
+               resource = resource->next;
+       }
+
+       return value;
+}
+
+
+static GVariant* _icd_repr_array_attr_to_gvariant(OCRepPayloadValueArray *arr, int len,
+               int index)
+{
+       int i;
+       GVariant *var;
+       GVariantBuilder builder;
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+
+       switch (arr->type) {
+       case OCREP_PROP_INT:
+               for (i = 0; i < len; i++)
+                       g_variant_builder_add(&builder, "i", arr->iArray[index + i]);
+               break;
+       case OCREP_PROP_BOOL:
+               for (i = 0; i < len; i++)
+                       g_variant_builder_add(&builder, "b", arr->bArray[index + i]);
+               break;
+       case OCREP_PROP_DOUBLE:
+               for (i = 0; i < len; i++)
+                       g_variant_builder_add(&builder, "d", arr->dArray[index + i]);
+               break;
+       case OCREP_PROP_STRING:
+               for (i = 0; i < len; i++)
+                       g_variant_builder_add(&builder, "s", arr->strArray[index + i]);
+               break;
+       case OCREP_PROP_NULL:
+               for (i = 0; i < len; i++)
+                       g_variant_builder_add(&builder, "s", IC_STR_NULL);
+               break;
+       case OCREP_PROP_OBJECT:
+               for (i = 0; i < len; i++) {
+                       var = _icd_payload_repr_to_gvariant(arr->objArray[index + i], TRUE);
+                       g_variant_builder_add(&builder, "v", var);
+               }
+               break;
+       case OCREP_PROP_ARRAY:
+       default:
+               break;
+       }
+
+       return g_variant_builder_end(&builder);
+}
+
+
+static GVariant* _icd_repr_array_to_gvariant(OCRepPayloadValueArray *arr,
+               int current_depth, int current_len, int index)
+{
+       int i, next_len;
+       GVariantBuilder builder;
+       GVariant *arr_var = NULL;
+
+       if ((MAX_REP_ARRAY_DEPTH - 1) == current_depth
+                       || 0 == arr->dimensions[current_depth + 1])
+               return _icd_repr_array_attr_to_gvariant(arr, current_len, index);
+
+       i = current_len + index;
+
+       next_len = current_len / arr->dimensions[current_depth];
+       index -= next_len;
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+
+       while ((index += next_len) < i) {
+               arr_var = _icd_repr_array_to_gvariant(arr, current_depth + 1, next_len, index);
+               g_variant_builder_add(&builder, "v", arr_var);
+       }
+
+       return g_variant_builder_end(&builder);
+}
+
+
+static GVariantBuilder* _icd_repr_value_to_gvariant(OCRepPayload *repr)
+{
+       int total_len;
+       GVariant *var = NULL;
+       GVariantBuilder *builder;
+       OCRepPayloadValue *val = repr->values;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       while (val) {
+               switch (val->type) {
+               case OCREP_PROP_INT:
+                       var = g_variant_new_int32(val->i);
+                       break;
+               case OCREP_PROP_BOOL:
+                       var = g_variant_new_boolean(val->b);
+                       break;
+               case OCREP_PROP_DOUBLE:
+                       var = g_variant_new_double(val->d);
+                       break;
+               case OCREP_PROP_STRING:
+                       var = g_variant_new_string(val->str);
+                       break;
+               case OCREP_PROP_NULL:
+                       var = g_variant_new_string(IC_STR_NULL);
+                       break;
+               case OCREP_PROP_ARRAY:
+                       total_len = calcDimTotal(val->arr.dimensions);
+                       var = _icd_repr_array_to_gvariant(&(val->arr), 0, total_len, 0);
+                       break;
+               case OCREP_PROP_OBJECT:
+                       var = _icd_payload_repr_to_gvariant(val->obj, TRUE);
+                       break;
+               default:
+                       ERR("Invalid Type");
+               }
+               if (var) {
+                       g_variant_builder_add(builder, "{sv}", val->name, var);
+                       var = NULL;
+               }
+               val = val->next;
+       }
+
+       return builder;
+}
+
+
+static GVariant* _icd_payload_repr_to_gvariant(OCRepPayload *repr, gboolean is_parent)
+{
+       OCStringLL *node;
+       int ret, ifaces = 0;
+       GVariant *child, *value;
+       OCRepPayload *child_node;
+       iotcon_interface_e iface;
+       GVariantBuilder *repr_gvar;
+       GVariantBuilder children, types_builder;
+
+       RETV_IF(NULL == repr, NULL);
+
+       /* Resource Types */
+       g_variant_builder_init(&types_builder, G_VARIANT_TYPE("as"));
+
+       node = repr->types;
+       while (node) {
+               g_variant_builder_add(&types_builder, "s", node->value);
+               node = node->next;
+       }
+
+       /* Resource Interfaces */
+       node = repr->interfaces;
+       while (node) {
+               ret = ic_utils_convert_interface_string(node->value, &iface);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("ic_utils_convert_interface_string() Fail(%d)", ret);
+                       return NULL;
+               }
+               ifaces |= iface;
+
+               node = node->next;
+       }
+
+       /* Representation */
+       repr_gvar = _icd_repr_value_to_gvariant(repr);
+
+       /* Children */
+       g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
+
+       child_node = repr->next;
+       while (is_parent && child_node) {
+               /* generate recursively */
+               child = _icd_payload_repr_to_gvariant(child_node, FALSE);
+               g_variant_builder_add(&children, "v", child);
+               child_node = child_node->next;
+       }
+
+       value = g_variant_new("(siasa{sv}av)", ic_utils_dbus_encode_str(repr->uri), ifaces,
+                       &types_builder, repr_gvar, &children);
+
+       return value;
+}
+
+
+static GVariant* _icd_payload_platform_to_gvariant(OCPlatformPayload *repr)
+{
+       GVariant *value;
+
+       value = g_variant_new("(ssssssssssss)",
+                       repr->uri,
+                       repr->info.platformID,
+                       repr->info.manufacturerName,
+                       repr->info.manufacturerUrl,
+                       repr->info.modelNumber,
+                       repr->info.dateOfManufacture,
+                       repr->info.platformVersion,
+                       repr->info.operatingSystemVersion,
+                       repr->info.hardwareVersion,
+                       repr->info.firmwareVersion,
+                       repr->info.supportUrl,
+                       repr->info.systemTime);
+
+       return value;
+}
+
+
+static GVariant* _icd_payload_device_to_gvariant(OCDevicePayload *repr)
+{
+       GVariant *value;
+       OCRandomUuidResult random_res;
+       char sid[UUID_STRING_SIZE] = {0};
+
+       random_res = OCConvertUuidToString(repr->sid, sid);
+       if (RAND_UUID_OK != random_res) {
+               ERR("OCConvertUuidToString() Fail(%d)", random_res);
+               return NULL;
+       }
+
+       value = g_variant_new("(ssss)", repr->deviceName, sid, repr->specVersion,
+                       repr->dataModelVersion);
+
+       return value;
+}
+
+
+GVariant* icd_payload_to_gvariant(OCPayload *repr)
+{
+       GVariant *value = NULL;
+
+       if (NULL == repr)
+               return value;
+
+       switch (repr->type) {
+       case PAYLOAD_TYPE_REPRESENTATION:
+               value = _icd_payload_repr_to_gvariant((OCRepPayload*)repr, TRUE);
+               break;
+       case PAYLOAD_TYPE_PLATFORM:
+               value = _icd_payload_platform_to_gvariant((OCPlatformPayload*)repr);
+               break;
+       case PAYLOAD_TYPE_DEVICE:
+               value = _icd_payload_device_to_gvariant((OCDevicePayload*)repr);
+               break;
+       case PAYLOAD_TYPE_PRESENCE:
+       case PAYLOAD_TYPE_SECURITY:
+       default:
+               break;
+       }
+
+       return value;
+}
+
+
+static void _icd_repr_list_from_gvariant(GVariant *var,
+               struct icd_repr_list_s *value_list, int depth)
+{
+       GVariantIter iter;
+       const GVariantType *type;
+       union icd_repr_value_u *value;
+
+       type = g_variant_get_type(var);
+
+       g_variant_iter_init(&iter, var);
+
+       value_list->dimensions[depth] = g_variant_iter_n_children(&iter);
+       DBG("[%d]list dim : %d", depth, value_list->dimensions[depth]);
+
+       if (g_variant_type_equal(G_VARIANT_TYPE("ab"), type)) {
+               bool b;
+               value_list->type = OCREP_PROP_BOOL;
+               while (g_variant_iter_loop(&iter, "b", &b)) {
+                       value = calloc(1, sizeof(union icd_repr_value_u));
+                       if (NULL == value) {
+                               ERR("calloc() Fail(%d)", errno);
+                               return;
+                       }
+                       value->b = b;
+                       value_list->list = g_list_append(value_list->list, value);
+               }
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("ai"), type)) {
+               int i;
+               value_list->type = OCREP_PROP_INT;
+               while (g_variant_iter_loop(&iter, "i", &i)) {
+                       value = calloc(1, sizeof(union icd_repr_value_u));
+                       if (NULL == value) {
+                               ERR("calloc() Fail(%d)", errno);
+                               return;
+                       }
+                       value->i = i;
+                       value_list->list = g_list_append(value_list->list, value);
+               }
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("ad"), type)) {
+               double d;
+               value_list->type = OCREP_PROP_DOUBLE;
+               while (g_variant_iter_loop(&iter, "d", &d)) {
+                       value = calloc(1, sizeof(union icd_repr_value_u));
+                       if (NULL == value) {
+                               ERR("calloc() Fail(%d)", errno);
+                               return;
+                       }
+                       value->d = d;
+                       value_list->list = g_list_append(value_list->list, value);
+               }
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("as"), type)) {
+               char *s;
+               value_list->type = OCREP_PROP_STRING;
+               while (g_variant_iter_next(&iter, "s", &s))
+                       value_list->list = g_list_append(value_list->list, s);
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("av"), type)) {
+               GVariant *value;
+
+               if (g_variant_iter_loop(&iter, "v", &value)) {
+                       if (g_variant_is_of_type(value, G_VARIANT_TYPE("(siasa{sv}av)"))) {
+                               OCRepPayload *repr_value;
+                               value_list->type = OCREP_PROP_OBJECT;
+                               do {
+                                       repr_value = icd_payload_repr_from_gvariant(value);
+                                       value_list->list = g_list_append(value_list->list, repr_value);
+
+                               } while (g_variant_iter_loop(&iter, "v", &value));
+
+                       } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
+                               do {
+                                       _icd_repr_list_from_gvariant(value, value_list, depth + 1);
+                               } while (g_variant_iter_loop(&iter, "v", &value));
+                       }
+               }
+       }
+
+       return;
+}
+
+
+static void _icd_repr_list_free(gpointer node)
+{
+       OCRepPayloadDestroy(node);
+}
+
+
+static void _icd_repr_array_from_list(OCRepPayload *repr,
+               struct icd_repr_list_s *value_list, const char *key)
+{
+       int i, len;
+       GList *node;
+       bool *b_arr;
+       double *d_arr;
+       char **str_arr;
+       int64_t *i_arr;
+       union icd_repr_value_u *value;
+       struct OCRepPayload **repr_arr;
+
+       len = calcDimTotal(value_list->dimensions);
+
+       switch (value_list->type) {
+       case OCREP_PROP_INT:
+               i_arr = calloc(len, sizeof(int64_t));
+               if (NULL == i_arr) {
+                       ERR("calloc() Fail(%d)", errno);
+                       return;
+               }
+               for (node = value_list->list, i = 0; node; node = node->next, i++) {
+                       value = node->data;
+                       i_arr[i] = value->i;
+               }
+               g_list_free_full(value_list->list, free);
+               OCRepPayloadSetIntArrayAsOwner(repr, key, i_arr, value_list->dimensions);
+               break;
+       case OCREP_PROP_BOOL:
+               b_arr = calloc(len, sizeof(bool));
+               if (NULL == b_arr) {
+                       ERR("calloc() Fail(%d)", errno);
+                       return;
+               }
+               for (node = value_list->list, i = 0; node; node = node->next, i++) {
+                       value = node->data;
+                       b_arr[i] = value->b;
+               }
+               g_list_free_full(value_list->list, free);
+               OCRepPayloadSetBoolArrayAsOwner(repr, key, b_arr, value_list->dimensions);
+               break;
+       case OCREP_PROP_DOUBLE:
+               d_arr = calloc(len, sizeof(double));
+               if (NULL == d_arr) {
+                       ERR("calloc() Fail(%d)", errno);
+                       return;
+               }
+               for (node = value_list->list, i = 0; node; node = node->next, i++) {
+                       value = node->data;
+                       d_arr[i] = value->d;
+               }
+               g_list_free_full(value_list->list, free);
+               OCRepPayloadSetDoubleArrayAsOwner(repr, key, d_arr, value_list->dimensions);
+               break;
+       case OCREP_PROP_STRING:
+               str_arr = calloc(len, sizeof(char *));
+               if (NULL == str_arr) {
+                       ERR("calloc() Fail(%d)", errno);
+                       return;
+               }
+               for (node = value_list->list, i = 0; node; node = node->next, i++)
+                       str_arr[i] = strdup(node->data);
+               g_list_free_full(value_list->list, free);
+               OCRepPayloadSetStringArrayAsOwner(repr, key, str_arr, value_list->dimensions);
+               break;
+       case OCREP_PROP_OBJECT:
+               repr_arr = calloc(len, sizeof(struct OCRepPayload *));
+               if (NULL == repr_arr) {
+                       ERR("calloc() Fail(%d)", errno);
+                       return;
+               }
+               for (node = value_list->list, i = 0; node; node = node->next, i++)
+                       repr_arr[i] = OCRepPayloadClone(node->data);
+               g_list_free_full(value_list->list, _icd_repr_list_free);
+               OCRepPayloadSetPropObjectArrayAsOwner(repr, key, repr_arr,
+                               value_list->dimensions);
+               break;
+       case OCREP_PROP_ARRAY:
+       case OCREP_PROP_NULL:
+       default:
+               ERR("Invalid Type");
+       }
+}
+
+
+static void _icd_repr_value_from_gvariant(OCRepPayload *repr, GVariantIter *iter)
+{
+       char *key;
+       GVariant *var;
+       const char *str_value;
+       OCRepPayload *repr_value;
+       struct icd_repr_list_s value_list = {0};
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+
+               if (g_variant_is_of_type(var, G_VARIANT_TYPE_BOOLEAN)) {
+                       OCRepPayloadSetPropBool(repr, key, g_variant_get_boolean(var));
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
+                       OCRepPayloadSetPropInt(repr, key, g_variant_get_int32(var));
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_DOUBLE)) {
+                       OCRepPayloadSetPropDouble(repr, key, g_variant_get_double(var));
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) {
+                       str_value = g_variant_get_string(var, NULL);
+                       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, str_value))
+                               OCRepPayloadSetNull(repr, key);
+                       else
+                               OCRepPayloadSetPropString(repr, key, str_value);
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
+                       memset(&value_list, 0, sizeof(struct icd_repr_list_s));
+                       _icd_repr_list_from_gvariant(var, &value_list, 0);
+                       _icd_repr_array_from_list(repr, &value_list, key);
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("(siasa{sv}av)"))) {
+                       repr_value = icd_payload_repr_from_gvariant(var);
+                       OCRepPayloadSetPropObjectAsOwner(repr, key, repr_value);
+               }
+       }
+
+       return;
+}
+
+
+OCRepPayload* icd_payload_repr_from_gvariant(GVariant *var)
+{
+       GVariant *child;
+       int ret, i, ifaces = 0;
+       OCRepPayload *repr, *cur;
+       char *uri_path, *iface_str, *resource_type;
+       GVariantIter *resource_types, *repr_gvar, *children;
+
+       repr = OCRepPayloadCreate();
+
+       g_variant_get(var, "(&siasa{sv}av)", &uri_path, &ifaces, &resource_types, &repr_gvar,
+                       &children);
+
+       if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
+               OCRepPayloadSetUri(repr, uri_path);
+
+       for (i = 1; i <= IC_INTERFACE_MAX; i = i << 1) {
+               if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */
+                       continue;
+               ret = ic_utils_convert_interface_flag((ifaces & i), &iface_str);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", i, ret);
+                       OCRepPayloadDestroy(repr);
+                       return NULL;
+               }
+               OCRepPayloadAddInterface(repr, iface_str);
+       }
+       while (g_variant_iter_loop(resource_types, "s", &resource_type))
+               OCRepPayloadAddResourceType(repr, resource_type);
+
+       _icd_repr_value_from_gvariant(repr, repr_gvar);
+
+       cur = repr;
+       while (g_variant_iter_loop(children, "v", &child)) {
+               cur->next = icd_payload_repr_from_gvariant(child);
+               cur = cur->next;
+       }
+
+       return repr;
+}
+
diff --git a/daemon/icd-payload.h b/daemon/icd-payload.h
new file mode 100644 (file)
index 0000000..5d402d0
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__
+#define __IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__
+
+#include <glib.h>
+
+#include <ocpayload.h>
+
+GVariant* icd_payload_to_gvariant(OCPayload *payload);
+GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr);
+OCRepPayload* icd_payload_repr_from_gvariant(GVariant *var);
+
+#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__*/
index 016f7a2..fc4ed83 100644 (file)
@@ -7,8 +7,8 @@ SET(CLIENT_SRCS ${CLIENT_SRCS} ${CMAKE_SOURCE_DIR}/common/ic-dbus.c)
 SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/ic-dbus.c
        PROPERTIES GENERATED TRUE)
 
-pkg_check_modules(client_pkgs REQUIRED glib-2.0 dlog json-glib-1.0 capi-base-common
-       gio-2.0 gio-unix-2.0)
+pkg_check_modules(client_pkgs REQUIRED glib-2.0 dlog capi-base-common gio-2.0
+       gio-unix-2.0)
 INCLUDE_DIRECTORIES(${client_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${client_pkgs_LIBRARY_DIRS})
 
index 3ebd812..88e26e6 100644 (file)
@@ -27,6 +27,7 @@
 #include "icl-dbus-type.h"
 #include "icl-repr.h"
 #include "icl-client.h"
+#include "icl-payload.h"
 
 typedef struct {
        iotcon_on_cru_cb cb;
@@ -49,16 +50,16 @@ 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;
        unsigned short option_id;
-       char *option_data, *repr_json;
+       char *option_data;
+       GVariant *repr_gvar;
        iotcon_options_h header_options = NULL;
        iotcon_on_cru_cb cb = cb_container->cb;
 
-       g_variant_get(result, "(a(qs)si)", &options, &repr_json, &res);
+       g_variant_get(result, "(a(qs)vi)", &options, &repr_gvar, &res);
 
        if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
                header_options = iotcon_options_new();
@@ -67,19 +68,15 @@ static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
        }
        g_variant_iter_free(options);
 
-       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, repr_json)) {
-               repr = iotcon_repr_new();
-       } else {
-               repr = icl_repr_create_repr(repr_json);
-               if (NULL == repr) {
-                       ERR("icl_repr_create_repr() Fail");
-                       if (header_options)
-                               iotcon_options_free(header_options);
-
-                       iotcon_client_free(cb_container->resource);
-                       free(cb_container);
-                       return;
-               }
+       repr = icl_repr_from_gvariant(repr_gvar);
+       if (NULL == repr) {
+               ERR("icl_repr_from_gvariant() Fail");
+               if (header_options)
+                       iotcon_options_free(header_options);
+
+               iotcon_client_free(cb_container->resource);
+               free(cb_container);
+               return;
        }
 
        res = icl_dbus_convert_daemon_error(res);
@@ -197,7 +194,7 @@ API int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
 API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
                iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
 {
-       char *arg_repr;
+       GVariant *arg_repr;
        GVariant *arg_client;
        GVariant *arg_query;
        icl_on_cru_s *cb_container;
@@ -223,9 +220,9 @@ API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
        cb_container->cb = cb;
        cb_container->user_data = user_data;
 
-       arg_repr = icl_repr_generate_json(repr, false, true);
+       arg_repr = icl_repr_to_gvariant(repr);
        if (NULL == arg_repr) {
-               ERR("icl_repr_generate_json() Fail");
+               ERR("icl_repr_to_gvariant() Fail");
                iotcon_client_free(cb_container->resource);
                free(cb_container);
                return IOTCON_ERROR_REPRESENTATION;
@@ -237,8 +234,6 @@ API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
        ic_dbus_call_put(icl_dbus_get_object(), arg_client, arg_repr, arg_query, NULL,
                        _icl_on_put_cb, cb_container);
 
-       free(arg_repr);
-
        return IOTCON_ERROR_NONE;
 }
 
@@ -246,7 +241,7 @@ API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
 API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
                iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
 {
-       char *arg_repr;
+       GVariant *arg_repr;
        GVariant *arg_client;
        GVariant *arg_query;
        icl_on_cru_s *cb_container;
@@ -272,9 +267,9 @@ API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
        cb_container->cb = cb;
        cb_container->user_data = user_data;
 
-       arg_repr = icl_repr_generate_json(repr, false, true);
+       arg_repr = icl_repr_to_gvariant(repr);
        if (NULL == arg_repr) {
-               ERR("icl_repr_generate_json() Fail");
+               ERR("icl_repr_to_gvariant() Fail");
                iotcon_client_free(cb_container->resource);
                free(cb_container);
                return IOTCON_ERROR_REPRESENTATION;
@@ -286,8 +281,6 @@ API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
        ic_dbus_call_post(icl_dbus_get_object(), arg_client, arg_repr, arg_query, NULL,
                        _icl_on_post_cb, cb_container);
 
-       free(arg_repr);
-
        return IOTCON_ERROR_NONE;
 }
 
@@ -295,7 +288,6 @@ 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;
@@ -379,19 +371,19 @@ static void _icl_on_observe_cb(GDBusConnection *connection,
                GVariant *parameters,
                gpointer user_data)
 {
-       FN_CALL;
        int res;
        int seq_num;
        iotcon_repr_h repr;
        GVariantIter *options;
        unsigned short option_id;
-       char *option_data, *repr_json;
+       char *option_data;
+       GVariant *repr_gvar;
        iotcon_options_h header_options = NULL;
 
        icl_on_observe_s *cb_container = user_data;
        iotcon_on_observe_cb cb = cb_container->cb;
 
-       g_variant_get(parameters, "(a(qs)sii)", &options, &repr_json, &res, &seq_num);
+       g_variant_get(parameters, "(a(qs)vii)", &options, &repr_gvar, &res, &seq_num);
 
        if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
                header_options = iotcon_options_new();
@@ -400,19 +392,15 @@ static void _icl_on_observe_cb(GDBusConnection *connection,
        }
        g_variant_iter_free(options);
 
-       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, repr_json)) {
-               repr = iotcon_repr_new();
-       } else {
-               repr = icl_repr_create_repr(repr_json);
-               if (NULL == repr) {
-                       ERR("icl_repr_create_repr() Fail");
-                       if (header_options)
-                               iotcon_options_free(header_options);
-
-                       iotcon_client_free(cb_container->resource);
-                       free(cb_container);
-                       return;
-               }
+       repr = icl_repr_from_gvariant(repr_gvar);
+       if (NULL == repr) {
+               ERR("icl_repr_from_gvariant() Fail");
+               if (header_options)
+                       iotcon_options_free(header_options);
+
+               iotcon_client_free(cb_container->resource);
+               free(cb_container);
+               return;
        }
 
        res = icl_dbus_convert_daemon_error(res);
@@ -443,7 +431,6 @@ API int iotcon_observer_start(iotcon_client_h resource,
                iotcon_on_observe_cb cb,
                void *user_data)
 {
-       FN_CALL;
        int observe_handle;
        GError *error = NULL;
        unsigned int sub_id;
@@ -511,7 +498,6 @@ API int iotcon_observer_start(iotcon_client_h resource,
 
 API int iotcon_observer_stop(iotcon_client_h resource)
 {
-       FN_CALL;
        int ret;
        GError *error = NULL;
        GVariant *arg_options;
index 76fa620..af420af 100644 (file)
@@ -19,7 +19,6 @@
 #include <string.h>
 #include <errno.h>
 #include <glib.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon.h"
 #include "ic-utils.h"
@@ -29,6 +28,7 @@
 #include "icl-dbus.h"
 #include "icl-repr.h"
 #include "icl-client.h"
+#include "icl-payload.h"
 
 typedef struct {
        iotcon_found_resource_cb cb;
@@ -36,6 +36,8 @@ typedef struct {
        unsigned int id;
 } icl_found_resource_s;
 
+static iotcon_client_h _icl_client_from_gvariant(GVariant *payload,
+               iotcon_connectivity_type_e conn_type);
 
 static void _icl_found_resource_cb(GDBusConnection *connection,
                const gchar *sender_name,
@@ -48,16 +50,14 @@ static void _icl_found_resource_cb(GDBusConnection *connection,
        FN_CALL;
        int conn_type;
        iotcon_client_h client;
-       char *payload, *host;
+
+       GVariant *payload;
        icl_found_resource_s *cb_container = user_data;
        iotcon_found_resource_cb cb = cb_container->cb;
 
-       g_variant_get(parameters, "(&s&si)", &payload, &host, &conn_type);
-
-       RET_IF(NULL == payload);
-       RET_IF(NULL == host);
+       g_variant_get(parameters, "(vi)", &payload, &conn_type);
 
-       client = icl_client_parse_resource_object(payload, host, conn_type);
+       client = _icl_client_from_gvariant(payload, conn_type);
        if (NULL == client) {
                ERR("icl_client_parse_resource_object() Fail");
                return;
@@ -283,87 +283,51 @@ API int iotcon_client_set_options(iotcon_client_h resource,
 }
 
 
-iotcon_client_h icl_client_parse_resource_object(const char *json_string, const char *host,
+static iotcon_client_h _icl_client_from_gvariant(GVariant *payload,
                iotcon_connectivity_type_e conn_type)
 {
-       FN_CALL;
-       JsonParser *parser;
-       int ret, observable;
-       GError *error = NULL;
+       char host_addr[PATH_MAX] = {0};
+       char *uri_path, *sid, *res_type, *addr;
+       int ifaces, is_observable, is_secure, port;
+       GVariantIter *types_iter;
+       iotcon_resource_types_h res_types;
        iotcon_client_h client;
-       const char *uri_path, *server_id;
-       int ifaces = IOTCON_INTERFACE_NONE;
-       JsonObject *rsrc_obj, *property_obj;
-       iotcon_resource_types_h res_types = NULL;
 
-       DBG("input str : %s", json_string);
+       g_variant_get(payload, "(&s&siasib&si)", &uri_path, &sid, &ifaces, &types_iter,
+                       &is_observable, &is_secure, &addr, &port);
 
-       parser = json_parser_new();
-       ret = json_parser_load_from_data(parser, json_string, strlen(json_string), &error);
-       if (FALSE == ret) {
-               ERR("json_parser_load_from_data() Fail(%s)", error->message);
-               g_error_free(error);
-               g_object_unref(parser);
-               return NULL;
+       switch (conn_type) {
+       case IOTCON_CONNECTIVITY_IPV6:
+               snprintf(host_addr, sizeof(host_addr), "[%s]:%d", addr, port);
+               break;
+       case IOTCON_CONNECTIVITY_IPV4:
+       default:
+               snprintf(host_addr, sizeof(host_addr), "%s:%d", addr, port);
        }
 
-       rsrc_obj = json_node_get_object(json_parser_get_root(parser));
-       if (NULL == rsrc_obj) {
-               ERR("json_node_get_object() Fail");
-               g_object_unref(parser);
-               return NULL;
-       }
+       res_types = iotcon_resource_types_new();
+       while (g_variant_iter_loop(types_iter, "s", &res_type))
+               iotcon_resource_types_insert(res_types, res_type);
 
-       uri_path = json_object_get_string_member(rsrc_obj, IC_JSON_KEY_URI_PATH);
-       if (NULL == uri_path) {
-               ERR("Invalid uri path");
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       server_id = json_object_get_string_member(rsrc_obj, IC_JSON_KEY_SERVERID);
-       if (NULL == server_id) {
-               ERR("Invalid Server ID");
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       /* parse resources type and interfaces */
-       property_obj = json_object_get_object_member(rsrc_obj, IC_JSON_KEY_PROPERTY);
-       if (property_obj) {
-               ret = icl_repr_parse_resource_property(property_obj, &res_types, &ifaces,
-                               &observable);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_repr_parse_resource_property() Fail(%d)", ret);
-                       g_object_unref(parser);
-                       return NULL;
-               }
-       }
-
-       /* parse observable */
-       observable = json_object_get_int_member(rsrc_obj, IC_JSON_KEY_OBSERVABLE);
-
-       client = iotcon_client_new(host, uri_path, !!observable, res_types, ifaces);
+       client = iotcon_client_new(host_addr, uri_path, !!is_observable, res_types, ifaces);
        if (res_types)
                iotcon_resource_types_free(res_types);
 
        if (NULL == client) {
                ERR("iotcon_client_new() Fail");
-               g_object_unref(parser);
                return NULL;
        }
        client->ref_count = 1;
 
-       client->sid = strdup(server_id);
+       client->sid = strdup(sid);
        if (NULL == client->sid) {
                ERR("strdup(sid) Fail(%d)", errno);
                iotcon_client_free(client);
-               g_object_unref(parser);
                return NULL;
        }
        client->conn_type = conn_type;
-
-       g_object_unref(parser);
+       client->is_secure = true;
 
        return client;
 }
+
index 74de0d6..fb99042 100644 (file)
 
 #include "iotcon-struct.h"
 #include "icl-options.h"
-#include <json-glib/json-glib.h>
 
 struct icl_remote_resource {
        int ref_count;
        char *uri_path;
        char *host;
        char *sid;
+       bool is_secure;
        bool is_observable;
-       bool is_collection;
        iotcon_options_h header_options;
        iotcon_resource_types_h types;
        int ifaces;
@@ -35,7 +34,4 @@ struct icl_remote_resource {
        unsigned int observe_sub_id;
 };
 
-iotcon_client_h icl_client_parse_resource_object(const char *json_string,
-               const char *host, iotcon_connectivity_type_e conn_type);
-
 #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__ */
index 4d2edbf..f964f3b 100644 (file)
@@ -30,6 +30,7 @@
 #include "icl-client.h"
 #include "icl-repr.h"
 #include "icl-dbus-type.h"
+#include "icl-payload.h"
 
 const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
 {
@@ -53,21 +54,19 @@ const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
 
 GVariant* icl_dbus_notimsg_to_gvariant(struct icl_notify_msg *msg)
 {
-       char *repr_json = NULL;
        GVariantBuilder builder;
+       GVariant *repr_gvar;
 
-       g_variant_builder_init(&builder, G_VARIANT_TYPE("a(is)"));
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("a(iv)"));
 
        if (msg) {
-               repr_json = icl_repr_generate_json(msg->repr, false, false);
-               if (NULL == repr_json) {
-                       ERR("icl_repr_generate_json() Fail");
+               repr_gvar = icl_repr_to_gvariant(msg->repr);
+               if (NULL == repr_gvar) {
+                       ERR("icl_repr_to_gvariant() Fail");
                        g_variant_builder_clear(&builder);
                        return NULL;
                }
-               g_variant_builder_add(&builder, "(is)", msg->error_code, repr_json);
-
-               free(repr_json);
+               g_variant_builder_add(&builder, "(iv)", msg->error_code, repr_gvar);
        }
 
        return g_variant_builder_end(&builder);
@@ -76,8 +75,9 @@ GVariant* icl_dbus_notimsg_to_gvariant(struct icl_notify_msg *msg)
 
 GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
 {
-       char *repr_json;
+       FN_CALL;
        GVariant *value;
+       GVariant *repr_gvar;
        GHashTableIter iter;
        GVariantBuilder options;
        gpointer option_id, option_data;
@@ -91,29 +91,31 @@ GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
                }
        }
 
-       /* TODO Make repr_json using interface */
-       repr_json = icl_repr_generate_json(response->repr, false, false);
-       if (NULL == repr_json) {
-               ERR("icl_repr_generate_json() Fail");
+       repr_gvar = icl_repr_to_gvariant(response->repr);
+       if (NULL == repr_gvar) {
+               ERR("icl_repr_to_gvariant() Fail");
                g_variant_builder_clear(&options);
                return NULL;
        }
 
-       value = g_variant_new("(sia(qs)isii)",
+       value = g_variant_new("(sia(qs)ivii)",
                        ic_utils_dbus_encode_str(response->new_uri_path),
                        response->error_code,
                        &options,
                        response->result,
-                       repr_json,
+                       repr_gvar,
                        GPOINTER_TO_INT(response->request_handle),
                        GPOINTER_TO_INT(response->resource_handle));
 
+       DBG("response : %s", g_variant_print(value, FALSE));
+
        return value;
 }
 
 
 GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource)
 {
+       FN_CALL;
        GVariant *value;
        GHashTableIter iter;
        GVariantBuilder options;
@@ -128,34 +130,22 @@ GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource)
                }
        }
 
-       value = g_variant_new("(ssa(qs)i)", resource->uri_path, resource->host, &options,
-                       resource->conn_type);
+       value = g_variant_new("(ssba(qs)i)", resource->uri_path, resource->host,
+                       resource->is_secure, &options, resource->conn_type);
 
        return value;
 }
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
-GVariant* icl_dbus_device_info_to_gvariant(iotcon_device_info_s *device_info)
+
+GVariant* icl_dbus_device_info_to_gvariant(const char *device_name)
 {
        GVariant *value;
 
-       value = g_variant_new("(ssssssssssss)",
-                       ic_utils_dbus_encode_str(device_info->name),
-                       ic_utils_dbus_encode_str(device_info->host_name),
-                       ic_utils_dbus_encode_str(device_info->uuid),
-                       ic_utils_dbus_encode_str(device_info->content_type),
-                       ic_utils_dbus_encode_str(device_info->version),
-                       ic_utils_dbus_encode_str(device_info->manuf_name),
-                       ic_utils_dbus_encode_str(device_info->manuf_url),
-                       ic_utils_dbus_encode_str(device_info->model_number),
-                       ic_utils_dbus_encode_str(device_info->date_of_manufacture),
-                       ic_utils_dbus_encode_str(device_info->platform_ver),
-                       ic_utils_dbus_encode_str(device_info->firmware_ver),
-                       ic_utils_dbus_encode_str(device_info->support_url));
+       value = g_variant_new("(s)", device_name);
 
        return value;
 }
-#endif
+
 
 GVariant* icl_dbus_platform_info_to_gvariant(iotcon_platform_info_s *platform_info)
 {
@@ -180,6 +170,7 @@ GVariant* icl_dbus_platform_info_to_gvariant(iotcon_platform_info_s *platform_in
 
 GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query)
 {
+       FN_CALL;
        gpointer key, value;
        GHashTableIter iter;
        GVariantBuilder builder;
index 18bf5cb..f8cc40c 100644 (file)
@@ -24,9 +24,7 @@ const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types);
 GVariant* icl_dbus_notimsg_to_gvariant(struct icl_notify_msg *msg);
 GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response);
 GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource);
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
-GVariant* icl_dbus_device_info_to_gvariant(iotcon_device_info_s *device_info);
-#endif
+GVariant* icl_dbus_device_info_to_gvariant(const char *device_name);
 GVariant* icl_dbus_platform_info_to_gvariant(iotcon_platform_info_s *platform_info);
 GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query);
 GVariant* icl_dbus_options_to_gvariant(iotcon_options_h options);
index 678bf01..0e4993a 100644 (file)
@@ -249,6 +249,7 @@ int icl_dbus_start()
                return IOTCON_ERROR_DBUS;
        }
 
+       icl_dbus_count++;
        return IOTCON_ERROR_NONE;
 }
 
index 9ee6cb9..3c1697d 100644 (file)
 #include "icl-dbus.h"
 #include "icl-dbus-type.h"
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
 typedef struct {
        iotcon_device_info_cb cb;
        void *user_data;
        unsigned int id;
 } icl_device_info_s;
-#endif
 
 typedef struct {
        iotcon_platform_info_cb cb;
@@ -41,30 +39,16 @@ typedef struct {
 } icl_platform_info_s;
 
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
-/* The length of manufacturer_name should be less than and equal to 16.
- * The length of manufacturer_url should be less than and equal to 32. */
-int iotcon_register_device_info(iotcon_device_info_s device_info)
+API int iotcon_register_device_info(const char *device_name)
 {
        int ret;
        GError *error = NULL;
        GVariant *arg_info;
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == device_name, IOTCON_ERROR_INVALID_PARAMETER);
 
-       if (device_info.manuf_name
-                       && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(device_info.manuf_name))) {
-               ERR("The length of manufacturer_name(%s) is invalid.", device_info.manuf_name);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       if (device_info.manuf_url
-                       && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(device_info.manuf_url))) {
-               ERR("The length of manufacturer_url(%s) is invalid.", device_info.manuf_url);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       arg_info = icl_dbus_device_info_to_gvariant(&device_info);
+       arg_info = icl_dbus_device_info_to_gvariant(device_name);
        ic_dbus_call_register_device_info_sync(icl_dbus_get_object(), arg_info, &ret,
                        NULL, &error);
        if (error) {
@@ -93,42 +77,17 @@ static void _icl_device_info_cb(GDBusConnection *connection,
 {
        icl_device_info_s *cb_container = user_data;
        iotcon_device_info_cb cb = cb_container->cb;
+       char *device_name, *sid, *spec_version, *data_model_version;
 
-       iotcon_device_info_s info = {0};
-
-       g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
-                       &info.name,
-                       &info.host_name,
-                       &info.uuid,
-                       &info.content_type,
-                       &info.version,
-                       &info.manuf_name,
-                       &info.manuf_url,
-                       &info.model_number,
-                       &info.date_of_manufacture,
-                       &info.platform_ver,
-                       &info.firmware_ver,
-                       &info.support_url);
-
-       info.name = ic_utils_dbus_decode_str(info.name);
-       info.host_name = ic_utils_dbus_decode_str(info.host_name);
-       info.uuid = ic_utils_dbus_decode_str(info.uuid);
-       info.content_type = ic_utils_dbus_decode_str(info.content_type);
-       info.version = ic_utils_dbus_decode_str(info.version);
-       info.manuf_name = ic_utils_dbus_decode_str(info.manuf_name);
-       info.manuf_url = ic_utils_dbus_decode_str(info.manuf_url);
-       info.model_number = ic_utils_dbus_decode_str(info.model_number);
-       info.date_of_manufacture = ic_utils_dbus_decode_str(info.date_of_manufacture);
-       info.platform_ver = ic_utils_dbus_decode_str(info.platform_ver);
-       info.firmware_ver = ic_utils_dbus_decode_str(info.firmware_ver);
-       info.support_url = ic_utils_dbus_decode_str(info.support_url);
+       g_variant_get(parameters, "(&s&s&s&s)", &device_name, &sid, &spec_version,
+                       &data_model_version);
 
        if (cb)
-               cb(info, cb_container->user_data);
+               cb(device_name, sid, spec_version, data_model_version, cb_container->user_data);
 }
 
 
-int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
+API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
                void *user_data)
 {
        int ret;
@@ -160,7 +119,7 @@ int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
        snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
                        signal_number);
 
-       cb_container = calloc(1, sizeof(icl_device_info_container_s));
+       cb_container = calloc(1, sizeof(icl_device_info_s));
        if (NULL == cb_container) {
                ERR("calloc() Fail(%d)", errno);
                return IOTCON_ERROR_OUT_OF_MEMORY;
@@ -180,7 +139,6 @@ int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
 
        return ret;
 }
-#endif
 
 
 /* The length of manufacturer_name should be less than and equal to 16.
@@ -247,24 +205,29 @@ static void _icl_platform_info_cb(GDBusConnection *connection,
                GVariant *parameters,
                gpointer user_data)
 {
-       FN_CALL;
-       char *repr_json = NULL;
-       iotcon_repr_h repr;
+       char *uri_path;
+       iotcon_platform_info_s info = {0};
        icl_platform_info_s *cb_container = user_data;
        iotcon_platform_info_cb cb = cb_container->cb;
 
-       g_variant_get(parameters, "(&s)", &repr_json);
-       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, repr_json)) {
-               ERR("Invalid Representation");
-               return;
-       }
+       g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
+                       &uri_path,
+                       &info.platform_id,
+                       &info.manuf_name,
+                       &info.manuf_url,
+                       &info.model_number,
+                       &info.date_of_manufacture,
+                       &info.platform_ver,
+                       &info.os_ver,
+                       &info.hardware_ver,
+                       &info.firmware_ver,
+                       &info.support_url,
+                       &info.system_time);
 
-       repr = icl_repr_create_repr(repr_json);
+       /* From iotivity, we can get uri_path. But, the value is always "/oic/p". */
 
        if (cb)
-               cb(repr, cb_container->user_data);
-
-       iotcon_repr_free(repr);
+               cb(info, cb_container->user_data);
 }
 
 
diff --git a/lib/icl-payload.c b/lib/icl-payload.c
new file mode 100644 (file)
index 0000000..f9abf14
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-repr.h"
+#include "icl-repr-list.h"
+#include "icl-repr-value.h"
+#include "icl-resource-types.h"
+#include "icl-response.h"
+#include "icl-payload.h"
+
+static GVariantBuilder* _icl_repr_value_to_gvariant(GHashTable *hash);
+
+static GVariant* _icl_repr_list_to_gvariant(iotcon_list_h list)
+{
+       GList *node;
+       GVariant *var = NULL;
+       GVariantBuilder builder;
+       struct icl_value_s *repr_value = NULL;
+
+       RETV_IF(NULL == list, NULL);
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+
+       switch (list->type) {
+       case IOTCON_TYPE_INT:
+               for (node = list->list; node; node = node->next) {
+                       repr_value = node->data;
+                       g_variant_builder_add(&builder, "i", ((icl_basic_s*)repr_value)->val.i);
+               }
+               break;
+       case IOTCON_TYPE_BOOL:
+               for (node = list->list; node; node = node->next) {
+                       repr_value = node->data;
+                       g_variant_builder_add(&builder, "b", ((icl_basic_s*)repr_value)->val.b);
+               }
+               break;
+       case IOTCON_TYPE_DOUBLE:
+               for (node = list->list; node; node = node->next) {
+                       repr_value = node->data;
+                       g_variant_builder_add(&builder, "d", ((icl_basic_s*)repr_value)->val.d);
+               }
+               break;
+       case IOTCON_TYPE_STR:
+               for (node = list->list; node; node = node->next) {
+                       repr_value = node->data;
+                       g_variant_builder_add(&builder, "s", ((icl_basic_s*)repr_value)->val.s);
+               }
+               break;
+       case IOTCON_TYPE_LIST:
+               for (node = list->list; node; node = node->next) {
+                       repr_value = node->data;
+                       var = _icl_repr_list_to_gvariant(((icl_val_list_s*)repr_value)->list);
+                       g_variant_builder_add(&builder, "v", var);
+               }
+               break;
+       case IOTCON_TYPE_REPR:
+               for (node = list->list; node; node = node->next) {
+                       repr_value = node->data;
+                       var = icl_repr_to_gvariant(((icl_val_repr_s*)repr_value)->repr);
+                       g_variant_builder_add(&builder, "v", var);
+               }
+               break;
+       default:
+               ERR("Invalid type(%d)", list->type);
+               return NULL;
+       }
+
+       return g_variant_builder_end(&builder);
+
+}
+
+static GVariantBuilder* _icl_repr_value_to_gvariant(GHashTable *hash)
+{
+       gpointer key, value;
+       GHashTableIter iter;
+       GVariant *var = NULL;
+       GVariantBuilder *builder;
+       struct icl_value_s *repr_value = NULL;
+
+       if (NULL == hash)
+               return NULL;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       g_hash_table_iter_init(&iter, hash);
+       while (g_hash_table_iter_next(&iter, &key, &value)) {
+               repr_value = value;
+               switch (repr_value->type) {
+               case IOTCON_TYPE_INT:
+                       var = g_variant_new_int32(((icl_basic_s*)repr_value)->val.i);
+                       break;
+               case IOTCON_TYPE_BOOL:
+                       var = g_variant_new_boolean(((icl_basic_s*)repr_value)->val.b);
+                       break;
+               case IOTCON_TYPE_DOUBLE:
+                       var = g_variant_new_double(((icl_basic_s*)repr_value)->val.d);
+                       break;
+               case IOTCON_TYPE_STR:
+                       var = g_variant_new_string(((icl_basic_s*)repr_value)->val.s);
+                       break;
+               case IOTCON_TYPE_NULL:
+                       var = g_variant_new_string(IC_STR_NULL);
+                       break;
+               case IOTCON_TYPE_LIST:
+                       var = _icl_repr_list_to_gvariant(((icl_val_list_s*)repr_value)->list);
+                       break;
+               case IOTCON_TYPE_REPR:
+                       var = icl_repr_to_gvariant(((icl_val_repr_s*)repr_value)->repr);
+                       break;
+               case IOTCON_TYPE_NONE:
+               default:
+                       ERR("Invalid Type");
+                       g_variant_builder_unref(builder);
+                       return NULL;
+               }
+
+               if (var)
+                       g_variant_builder_add(builder, "{sv}", key, var);
+       }
+
+       return builder;
+}
+
+
+GVariant* icl_repr_to_gvariant(iotcon_repr_h repr)
+{
+       GList *node;
+       int ifaces = 0;
+       const char *uri_path;
+       GVariant *value, *child;
+       GVariantBuilder *repr_gvar = NULL;
+       GVariantBuilder children, resource_types;
+
+       RETV_IF(NULL == repr, NULL);
+
+       /* uri path */
+       uri_path = ic_utils_dbus_encode_str(repr->uri_path);
+
+       /* Resource Types & Interfaces */
+       g_variant_builder_init(&resource_types, G_VARIANT_TYPE("as"));
+
+       if (ICL_VISIBILITY_PROP & repr->visibility) {
+               if (repr->res_types) {
+                       for (node = repr->res_types->type_list; node; node = node->next)
+                               g_variant_builder_add(&resource_types, "s", node->data);
+               }
+
+               ifaces = repr->interfaces;
+       }
+
+       /* Representation */
+       if (ICL_VISIBILITY_REPR & repr->visibility)
+               repr_gvar = _icl_repr_value_to_gvariant(repr->hash_table);
+
+       /* Children */
+       g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
+
+       for (node = repr->children; node; node = node->next) {
+               /* generate recursively */
+               child = icl_repr_to_gvariant(node->data);
+               g_variant_builder_add(&children, "v", child);
+       }
+
+       value = g_variant_new("(siasa{sv}av)", uri_path, ifaces, &resource_types,
+                       repr_gvar, &children);
+
+       return value;
+}
+
+
+static iotcon_list_h _icl_repr_list_from_gvariant(GVariant *var)
+{
+       GVariantIter iter;
+       const GVariantType *type;
+       iotcon_list_h list = NULL;
+
+       type = g_variant_get_type(var);
+
+       g_variant_iter_init(&iter, var);
+
+       if (g_variant_type_equal(G_VARIANT_TYPE("ab"), type)) {
+               bool b;
+               list = iotcon_list_new(IOTCON_TYPE_BOOL);
+               while (g_variant_iter_loop(&iter, "b", &b))
+                       iotcon_list_insert_bool(list, b, -1);
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("ai"), type)) {
+               int i;
+               list = iotcon_list_new(IOTCON_TYPE_INT);
+               while (g_variant_iter_loop(&iter, "i", &i))
+                       iotcon_list_insert_int(list, i, -1);
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("ad"), type)) {
+               double d;
+               list = iotcon_list_new(IOTCON_TYPE_DOUBLE);
+               while (g_variant_iter_loop(&iter, "d", &d))
+                       iotcon_list_insert_double(list, d, -1);
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("as"), type)) {
+               char *s;
+               list = iotcon_list_new(IOTCON_TYPE_STR);
+               while (g_variant_iter_loop(&iter, "s", &s))
+                       iotcon_list_insert_str(list, s, -1);
+       } else if (g_variant_type_equal(G_VARIANT_TYPE("v"), type)) {
+               GVariant *value;
+               iotcon_list_h list_value;
+               iotcon_repr_h repr_value;
+
+               while (g_variant_iter_loop(&iter, "v", &value)) {
+                       if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
+                               list_value = _icl_repr_list_from_gvariant(value);
+                               iotcon_list_insert_list(list, list_value, -1);
+                       } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("(siasa{sv}av)"))) {
+                               repr_value = icl_repr_from_gvariant(value);
+                               iotcon_list_insert_repr(list, repr_value, -1);
+                       }
+               }
+       }
+
+       return list;
+}
+
+
+static void _icl_repr_value_from_gvariant(iotcon_repr_h repr, GVariantIter *iter)
+{
+       char *key;
+       GVariant *var;
+       const char *str_value;
+       iotcon_list_h list_value;
+       iotcon_repr_h repr_value;
+       iotcon_value_h value = NULL;
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+
+               if (g_variant_is_of_type(var, G_VARIANT_TYPE_BOOLEAN)) {
+                       value = icl_value_new_bool(g_variant_get_boolean(var));
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
+                       value = icl_value_new_int(g_variant_get_int32(var));
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_DOUBLE)) {
+                       value = icl_value_new_double(g_variant_get_double(var));
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) {
+                       str_value = g_variant_get_string(var, NULL);
+                       if (IC_STR_EQUAL == strcmp(IC_STR_NULL, str_value))
+                               value = icl_value_new_null();
+                       else
+                               value = icl_value_new_str(str_value);
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
+                       list_value = _icl_repr_list_from_gvariant(var);
+                       value = icl_value_new_list(list_value);
+
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("(siasa{sv}av)"))) {
+                       repr_value = icl_repr_from_gvariant(var);
+                       value = icl_value_new_repr(repr_value);
+               }
+
+               g_hash_table_replace(repr->hash_table, ic_utils_strdup(key), value);
+       }
+
+       return;
+}
+
+
+iotcon_repr_h icl_repr_from_gvariant(GVariant *var)
+{
+       iotcon_repr_h repr;
+       GVariant *child;
+       char *uri_path, *resource_type;
+       GVariantIter *children, *repr_gvar, *resource_types;
+
+       repr = iotcon_repr_new();
+       if (NULL == repr) {
+               ERR("iotcon_repr_new() Fail");
+               return NULL;
+       }
+
+       DBG("repr : %s", g_variant_print(var, FALSE));
+
+       g_variant_get(var, "(&siasa{sv}av)", &uri_path, &repr->interfaces, &resource_types,
+                       &repr_gvar, &children);
+
+       /* uri path */
+       if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
+               repr->uri_path = strdup(uri_path);
+
+       /* resource types */
+       if (g_variant_iter_n_children(resource_types)) {
+               repr->res_types = iotcon_resource_types_new();
+               while (g_variant_iter_loop(resource_types, "s", &resource_type))
+                       iotcon_resource_types_insert(repr->res_types, resource_type);
+       }
+       g_variant_iter_free(resource_types);
+
+       /* attribute */
+       _icl_repr_value_from_gvariant(repr, repr_gvar);
+
+       /* children */
+       while (g_variant_iter_loop(children, "v", &child))
+               repr->children = g_list_append(repr->children, icl_repr_from_gvariant(child));
+       g_variant_iter_free(children);
+
+       return repr;
+}
diff --git a/lib/icl-payload.h b/lib/icl-payload.h
new file mode 100644 (file)
index 0000000..49a8ea5
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__
+
+#include <glib.h>
+
+GVariant* icl_repr_to_gvariant(iotcon_repr_h repr);
+iotcon_repr_h icl_repr_from_gvariant(GVariant *var);
+
+#endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__*/
index 5fe798c..6bd31ba 100644 (file)
@@ -115,6 +115,7 @@ static void _icl_presence_conn_cleanup(icl_presence_s *presence)
 API iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
                const char *resource_type, iotcon_presence_cb cb, void *user_data)
 {
+       FN_CALL;
        GError *error = NULL;
        unsigned int sub_id;
        int signal_number;
index d4e299b..1d9c778 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <stdlib.h>
 #include <errno.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon-struct.h"
 #include "iotcon-constant.h"
@@ -659,194 +658,6 @@ static iotcon_value_h _icl_list_get_nth_value(iotcon_list_h list, int pos)
 }
 
 
-
-/*
- * A general result : [1,2,3]
- */
-JsonArray* icl_list_to_json(iotcon_list_h list)
-{
-       int i, ret, count;
-       JsonArray *parray = NULL;
-       JsonNode *child_node = NULL;
-       JsonObject *child_obj = NULL;
-       JsonArray *child_array = NULL;
-       iotcon_repr_h child_repr = NULL;
-       iotcon_list_h child_list = NULL;
-       iotcon_value_h child_value = NULL;
-
-       RETV_IF(NULL == list, NULL);
-       RETV_IF(NULL == list->list, NULL);
-
-       count = g_list_length(list->list);
-
-       parray = json_array_new();
-       for (i = 0; i < count; i++) {
-               child_value = _icl_list_get_nth_value(list, i);
-
-               int type = child_value->type;
-               switch (type) {
-               case IOTCON_TYPE_INT:
-               case IOTCON_TYPE_BOOL:
-               case IOTCON_TYPE_DOUBLE:
-               case IOTCON_TYPE_STR:
-               case IOTCON_TYPE_NULL:
-                       child_node = icl_value_to_json(child_value);
-                       if (NULL == child_node) {
-                               ERR("icl_value_to_json(child_value) Fail");
-                               json_array_unref(parray);
-                               return NULL;
-                       }
-                       json_array_add_element(parray, child_node);
-                       break;
-               case IOTCON_TYPE_LIST:
-                       ret = icl_value_get_list(child_value, &child_list);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("icl_value_get_list() Fail(%d)", ret);
-                               json_array_unref(parray);
-                               return NULL;
-                       }
-
-                       child_array = icl_list_to_json(child_list);
-                       if (NULL == child_array) {
-                               ERR("icl_list_to_json(child_list) Fail");
-                               json_array_unref(parray);
-                               return NULL;
-                       }
-                       child_node = json_node_new(JSON_NODE_ARRAY);
-                       json_node_set_array(child_node, child_array);
-                       json_array_add_element(parray, child_node);
-                       break;
-               case IOTCON_TYPE_REPR:
-                       ret = icl_value_get_repr(child_value, &child_repr);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("icl_value_get_repr() Fail(%d)", ret);
-                               json_array_unref(parray);
-                               return NULL;
-                       }
-
-                       child_obj = icl_obj_to_json(child_repr);
-                       if (NULL == child_obj) {
-                               ERR("icl_obj_to_json(child_repr) Fail");
-                               json_array_unref(parray);
-                               return NULL;
-                       }
-                       child_node = json_node_new(JSON_NODE_OBJECT);
-                       json_node_set_object(child_node, child_obj);
-                       json_array_add_element(parray, child_node);
-               }
-       }
-
-       return parray;
-}
-
-/*
- * A general input : [1,2,3]
- */
-iotcon_list_h icl_list_from_json(JsonArray *parray)
-{
-       int i, ret;
-       int count = json_array_get_length(parray);
-
-       iotcon_list_h list = _icl_list_new(IOTCON_TYPE_NONE);
-       if (NULL == list) {
-               ERR("_icl_list_new() Fail");
-               return NULL;
-       }
-
-       for (i = 0; i < count; i++) {
-               JsonNode *child_node = json_array_get_element(parray, i);
-               if (JSON_NODE_HOLDS_NULL(child_node) || JSON_NODE_HOLDS_VALUE(child_node)) {
-                       iotcon_value_h value = icl_value_from_json(child_node);
-                       if (NULL == value) {
-                               ERR("icl_value_from_json() Fail");
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       icl_basic_s *real = (icl_basic_s*)value;
-                       if (IOTCON_TYPE_NONE != list->type && list->type != real->type) {
-                               ERR("Type matching Fail(list:%d,value:%d)", list->type, real->type);
-                               icl_value_free(value);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       ret = icl_list_insert(list, value, -1);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("icl_list_insert() Fail(%d)", ret);
-                               icl_value_free(value);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-                       list->type = real->type;
-               } else if (JSON_NODE_HOLDS_ARRAY(child_node)) {
-                       if (IOTCON_TYPE_NONE != list->type && IOTCON_TYPE_LIST != list->type) {
-                               ERR("Type matching Fail(%d)", list->type);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       JsonArray *child_array = json_node_get_array(child_node);
-                       iotcon_list_h parsed_list = icl_list_from_json(child_array);
-                       if (NULL == parsed_list) {
-                               ERR("icl_list_from_json() Fail(NULL == parsed_list)");
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       iotcon_value_h value = icl_value_new_list(parsed_list);
-                       if (NULL == value) {
-                               ERR("icl_value_new_list(%p) Fail", parsed_list);
-                               iotcon_list_free(parsed_list);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       ret = icl_list_insert(list, value, -1);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("icl_list_insert() Fail(%d)", ret);
-                               iotcon_list_free(parsed_list);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-                       list->type = IOTCON_TYPE_LIST;
-               } else if (JSON_NODE_HOLDS_OBJECT(child_node)) {
-                       if (IOTCON_TYPE_NONE != list->type && IOTCON_TYPE_REPR != list->type) {
-                               ERR("Type matching Fail(%d)", list->type);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       JsonObject *child_obj = json_node_get_object(child_node);
-                       iotcon_repr_h ret_repr = icl_obj_from_json(child_obj);
-                       if (NULL == ret_repr) {
-                               ERR("icl_obj_from_json() Fail(NULL == ret_repr)");
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       iotcon_value_h value = icl_value_new_repr(ret_repr);
-                       if (NULL == value) {
-                               ERR("icl_value_new_repr(%p) Fail", ret_repr);
-                               iotcon_repr_free(ret_repr);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-
-                       ret = icl_list_insert(list, value, -1);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("icl_list_insert() Fail(%d)", ret);
-                               iotcon_repr_free(ret_repr);
-                               iotcon_list_free(list);
-                               return NULL;
-                       }
-                       list->type = IOTCON_TYPE_REPR;
-               }
-       }
-
-       return list;
-}
-
 API void iotcon_list_free(iotcon_list_h list)
 {
        FN_CALL;
index 5a87773..973db16 100644 (file)
@@ -17,7 +17,6 @@
 #define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_LIST_H__
 
 #include <glib.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon-struct.h"
 
@@ -30,9 +29,6 @@ struct icl_list_s {
 int icl_list_remove(iotcon_list_h list, iotcon_value_h val);
 int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
 
-JsonArray* icl_list_to_json(iotcon_list_h list);
-iotcon_list_h icl_list_from_json(JsonArray *parray);
-
 iotcon_list_h icl_list_clone(iotcon_list_h list);
 
 void icl_list_inc_ref_count(iotcon_list_h val);
index fcaa3f8..e90c00a 100644 (file)
@@ -483,214 +483,3 @@ int icl_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value)
 
        return IOTCON_ERROR_NONE;
 }
-
-static inline int _icl_obj_to_json(const char *key, iotcon_value_h value,
-               JsonObject *json_obj)
-{
-       FN_CALL;
-       int type, ret;
-       iotcon_repr_h child_repr = NULL;
-       iotcon_list_h child_list = NULL;
-
-       JsonObject *child_obj = NULL;
-       JsonNode *child_node = NULL;
-       JsonArray *child_array = NULL;
-
-       RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
-       type = value->type;
-       switch (type) {
-       case IOTCON_TYPE_INT:
-       case IOTCON_TYPE_BOOL:
-       case IOTCON_TYPE_DOUBLE:
-       case IOTCON_TYPE_STR:
-       case IOTCON_TYPE_NULL:
-               child_node = icl_value_to_json(value);
-               if (NULL == child_node) {
-                       ERR("icl_value_to_json() Fail");
-                       return IOTCON_ERROR_INVALID_PARAMETER;
-               }
-               json_object_set_member(json_obj, key, child_node);
-               break;
-       case IOTCON_TYPE_LIST:
-               ret = icl_value_get_list(value, &child_list);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_value_get_list() Fail(%d)", ret);
-                       return IOTCON_ERROR_REPRESENTATION;
-               }
-
-               child_array = icl_list_to_json(child_list);
-               if (NULL == child_array) {
-                       ERR("icl_list_to_json() Fail");
-                       return IOTCON_ERROR_INVALID_PARAMETER;
-               }
-               child_node = json_node_new(JSON_NODE_ARRAY);
-               json_node_set_array(child_node, child_array);
-               json_object_set_member(json_obj, key, child_node);
-               break;
-       case IOTCON_TYPE_REPR:
-               ret = icl_value_get_repr(value, &child_repr);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_value_get_repr() Fail(%d)", ret);
-                       return IOTCON_ERROR_REPRESENTATION;
-               }
-
-               child_obj = icl_obj_to_json(child_repr);
-               if (NULL == child_obj) {
-                       ERR("icl_obj_to_json() Fail");
-                       return IOTCON_ERROR_INVALID_PARAMETER;
-               }
-               child_node = json_node_new(JSON_NODE_OBJECT);
-               json_node_set_object(child_node, child_obj);
-               json_object_set_member(json_obj, key, child_node);
-               break;
-       default:
-               ERR("Invalid type(%d)", type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       return IOTCON_ERROR_NONE;
-}
-
-/*
- * A general result : {"rep":{"string":"Hello","intlist":[1,2,3]}}
- */
-JsonObject* icl_obj_to_json(iotcon_repr_h repr)
-{
-       int ret;
-       unsigned int key_count;
-       JsonObject *json_obj = NULL;
-       JsonObject *parent_obj = NULL;
-
-       GHashTableIter iter;
-       gpointer key, value;
-
-       RETV_IF(NULL == repr, NULL);
-       RETV_IF(NULL == repr->hash_table, NULL);
-
-       key_count = iotcon_repr_get_keys_count(repr);
-       if (key_count) {
-               json_obj = json_object_new();
-
-               g_hash_table_iter_init(&iter, repr->hash_table);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       ret = _icl_obj_to_json(key, value, json_obj);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("_icl_obj_to_json() Fail(%d)", ret);
-                               json_object_unref(json_obj);
-                               return NULL;
-                       }
-               }
-       }
-
-       parent_obj = json_object_new();
-
-       if (json_obj)
-               json_object_set_object_member(parent_obj, IC_JSON_KEY_REP, json_obj);
-
-       return parent_obj;
-}
-
-static inline int _icl_obj_from_json(JsonObject *obj, GList *key_list, unsigned int index,
-               iotcon_repr_h ret_repr)
-{
-       char *key;
-
-       RETV_IF(NULL == obj, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == key_list, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == ret_repr, IOTCON_ERROR_INVALID_PARAMETER);
-
-       key = g_list_nth_data(key_list, index);
-
-       /* search child object recursively */
-       JsonNode *child_node = json_object_get_member(obj, key);
-       if (NULL == child_node) {
-               ERR("json_object_get_member() Fail");
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-       if (JSON_NODE_HOLDS_NULL(child_node) || JSON_NODE_HOLDS_VALUE(child_node)) {
-               iotcon_value_h value = icl_value_from_json(child_node);
-               if (NULL == value) {
-                       ERR("icl_value_from_json() Fail");
-                       return IOTCON_ERROR_INVALID_PARAMETER;
-               }
-               icl_obj_set_value(ret_repr, key, value);
-       } else if (JSON_NODE_HOLDS_ARRAY(child_node)) {
-               iotcon_value_h value;
-               JsonArray *child_array = json_node_get_array(child_node);
-
-               iotcon_list_h list = icl_list_from_json(child_array);
-               if (NULL == list) {
-                       ERR("icl_list_from_json() Fail");
-                       return IOTCON_ERROR_INVALID_PARAMETER;
-               }
-
-               value = icl_value_new_list(list);
-               if (NULL == value) {
-                       ERR("icl_value_new_list() Fail");
-                       iotcon_list_free(list);
-                       return IOTCON_ERROR_OUT_OF_MEMORY;
-               }
-
-               icl_obj_set_value(ret_repr, key, value);
-       } else if (JSON_NODE_HOLDS_OBJECT(child_node)) {
-               iotcon_value_h value;
-               JsonObject *child_obj = json_node_get_object(child_node);
-
-               iotcon_repr_h repr = icl_obj_from_json(child_obj);
-               if (NULL == repr) {
-                       ERR("icl_obj_from_json() Fail");
-                       return IOTCON_ERROR_INVALID_PARAMETER;
-               }
-
-               value = icl_value_new_repr(repr);
-               if (NULL == value) {
-                       ERR("icl_value_new_repr(%p) Fail", repr);
-                       iotcon_repr_free(repr);
-                       return IOTCON_ERROR_OUT_OF_MEMORY;
-               }
-
-               icl_obj_set_value(ret_repr, key, value);
-       } else {
-               ERR("node type(%d) Fail", json_node_get_node_type(child_node));
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       return IOTCON_ERROR_NONE;
-}
-
-/*
- * A general input : {"rep:"{"string":"Hello","intlist":[1,2,3]}}
- */
-iotcon_repr_h icl_obj_from_json(JsonObject *json_repr)
-{
-       int ret;
-       unsigned int i = 0;
-       GList *key_list = NULL;
-       iotcon_repr_h repr = NULL;
-       JsonObject *obj = NULL;
-
-       RETV_IF(NULL == json_repr, NULL);
-
-       obj = json_object_get_object_member(json_repr, IC_JSON_KEY_REP);
-
-       key_list = json_object_get_members(obj);
-
-       repr = iotcon_repr_new();
-       if (key_list) {
-               for (i = 0; i < g_list_length(key_list); i++) {
-                       ret = _icl_obj_from_json(obj, key_list, i, repr);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("_icl_obj_from_json() Fail(%d)", ret);
-                               iotcon_repr_free(repr);
-                               g_list_free(key_list);
-                               return NULL;
-                       }
-               }
-               g_list_free(key_list);
-       }
-
-       return repr;
-}
-
index f6ad7ea..2b6c644 100644 (file)
@@ -16,8 +16,6 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_OBJECT_H__
 #define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_OBJECT_H__
 
-#include <json-glib/json-glib.h>
-
 #include "iotcon-struct.h"
 #include "iotcon-constant.h"
 
@@ -27,7 +25,4 @@ int icl_obj_del_value(iotcon_repr_h repr, const char *key,
 int ic_repr_obj_get_value(iotcon_repr_h repr, const char *key, iotcon_value_h *retval);
 int icl_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value);
 
-JsonObject* icl_obj_to_json(iotcon_repr_h repr);
-iotcon_repr_h icl_obj_from_json(JsonObject *obj);
-
 #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_OBJECT_H__ */
index 7fc0234..5cb21ac 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <stdlib.h>
 #include <errno.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon-struct.h"
 #include "iotcon-representation.h"
@@ -118,7 +117,7 @@ iotcon_value_h icl_value_new_double(double val)
        return (iotcon_value_h)value;
 }
 
-iotcon_value_h icl_value_new_str(char *val)
+iotcon_value_h icl_value_new_str(const char *val)
 {
        icl_basic_s *value;
 
@@ -245,107 +244,6 @@ int icl_value_get_repr(iotcon_value_h value, iotcon_repr_h *repr)
        return IOTCON_ERROR_NONE;
 }
 
-/*
- * A general result : 1
- *                  : true
- *                                     : 5.5
- *                  : "Hello"
- */
-JsonNode* icl_value_to_json(iotcon_value_h value)
-{
-       JsonNode *node;
-       icl_basic_s *real = (icl_basic_s*)value;
-
-       RETV_IF(NULL == value, NULL);
-
-       if (IOTCON_TYPE_NULL == value->type)
-               node = json_node_new(JSON_NODE_NULL);
-       else
-               node = json_node_new(JSON_NODE_VALUE);
-
-       if (NULL == node) {
-               ERR("json_node_new(%d) Fail", value->type);
-               return NULL;
-       }
-
-       switch (value->type) {
-       case IOTCON_TYPE_INT:
-               json_node_set_int(node, real->val.i);
-               break;
-       case IOTCON_TYPE_BOOL:
-               json_node_set_boolean(node, real->val.b);
-               break;
-       case IOTCON_TYPE_DOUBLE:
-               json_node_set_double(node, real->val.d);
-               break;
-       case IOTCON_TYPE_STR:
-               json_node_set_string(node, real->val.s);
-               break;
-       case IOTCON_TYPE_NULL:
-               break;
-       default:
-               ERR("Invalid type(%d)", value->type);
-               break;
-       }
-
-       return node;
-}
-
-/*
- * A general result : 1
- *                  : true
- *                  : 5.5
- *                  : "Hello"
- */
-API iotcon_value_h icl_value_from_json(JsonNode *node)
-{
-       gint64 ival64;
-       GType gtype = 0;
-       iotcon_value_h value = NULL;
-
-       RETV_IF(NULL == node, NULL);
-
-       if (JSON_NODE_HOLDS_NULL(node)) {
-               value = icl_value_new_null();
-               if (NULL == value)
-                       ERR("icl_value_new_null() Fail");
-               return value;
-       }
-
-       gtype = json_node_get_value_type(node);
-       switch (gtype) {
-       case G_TYPE_INT64:
-               ival64 = json_node_get_int(node);
-               if (INT_MAX < ival64 || ival64 < INT_MIN) {
-                       ERR("value SHOULD NOT exceeds the integer range. ival64(%lld)", ival64);
-                       return NULL;
-               }
-               value = icl_value_new_int(ival64);
-               if (NULL == value)
-                       ERR("icl_value_new_int(%ll) Fail", ival64);
-               break;
-       case G_TYPE_BOOLEAN:
-               value = icl_value_new_bool(json_node_get_boolean(node));
-               if (NULL == value)
-                       ERR("icl_value_new_bool() Fail");
-               break;
-       case G_TYPE_DOUBLE:
-               value = icl_value_new_double(json_node_get_double(node));
-               if (NULL == value)
-                       ERR("icl_value_new_double() Fail");
-               break;
-       case G_TYPE_STRING:
-               value = icl_value_new_str(ic_utils_strdup(json_node_get_string(node)));
-               if (NULL == value)
-                       ERR("icl_value_new_str() Fail");
-               break;
-       default:
-               ERR("Invalid type(%d)", gtype);
-               break;
-       }
-
-       return value;
-}
 
 void icl_value_free(gpointer data)
 {
index 4e18d6d..f030769 100644 (file)
@@ -17,7 +17,6 @@
 #define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_VALUE_H__
 
 #include <stdbool.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon-struct.h"
 
@@ -49,7 +48,7 @@ iotcon_value_h icl_value_new_null();
 iotcon_value_h icl_value_new_int(int val);
 iotcon_value_h icl_value_new_bool(bool val);
 iotcon_value_h icl_value_new_double(double val);
-iotcon_value_h icl_value_new_str(char *val);
+iotcon_value_h icl_value_new_str(const char *val);
 iotcon_value_h icl_value_new_list(iotcon_list_h val);
 iotcon_value_h icl_value_new_repr(iotcon_repr_h val);
 
@@ -61,9 +60,6 @@ int icl_value_get_str(iotcon_value_h value, const char **val);
 int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list);
 int icl_value_get_repr(iotcon_value_h value, iotcon_repr_h *repr);
 
-
-JsonNode* icl_value_to_json(iotcon_value_h value);
-iotcon_value_h icl_value_from_json(JsonNode *node);
 void icl_value_free(gpointer data);
 
 iotcon_value_h icl_value_clone(iotcon_value_h src);
index dba62c3..c5e98c1 100644 (file)
@@ -21,7 +21,6 @@
 #include <errno.h>
 #include <limits.h>
 #include <glib.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon-struct.h"
 #include "iotcon-representation.h"
@@ -141,7 +140,7 @@ API int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces)
 {
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
-       RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || ICL_INTERFACE_MAX < ifaces,
+       RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || IC_INTERFACE_MAX < ifaces,
                        IOTCON_ERROR_INVALID_PARAMETER);
 
        repr->interfaces = ifaces;
@@ -227,574 +226,6 @@ API unsigned int iotcon_repr_get_keys_count(iotcon_repr_h repr)
        return g_hash_table_size(repr->hash_table);
 }
 
-static int _icl_repr_get_res_type_fn(const char *res_type, void *user_data)
-{
-       JsonArray *rt_array = user_data;
-       json_array_add_string_element(rt_array, res_type);
-
-       return IOTCON_FUNC_CONTINUE;
-}
-
-/*
- * A general result : {"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}
- */
-static JsonObject* _icl_repr_data_generate_json(iotcon_repr_h cur_repr,
-               unsigned int child_index)
-{
-       int i, ret, ifaces;
-       char *iface_str;
-       const char *uri_path;
-       unsigned int rt_count = 0;
-       JsonObject *repr_obj = NULL;
-       JsonObject *prop_obj = NULL;
-       iotcon_resource_types_h resource_types = NULL;
-
-       RETV_IF(NULL == cur_repr, NULL);
-
-       /* 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)) {
-               repr_obj = icl_obj_to_json(cur_repr);
-               if (NULL == repr_obj) {
-                       ERR("icl_obj_to_json() Fail");
-                       return NULL;
-               }
-       } else {
-               repr_obj = json_object_new();
-       }
-
-       if (cur_repr->uri_path) {
-               iotcon_repr_get_uri_path(cur_repr, &uri_path);
-               json_object_set_string_member(repr_obj, IC_JSON_KEY_URI_PATH, uri_path);
-       }
-
-       if (cur_repr->res_types)
-               rt_count = icl_resource_types_get_length(cur_repr->res_types);
-
-       /* 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 (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);
-               }
-
-               if (0 < rt_count) {
-                       JsonArray *rt_array = json_array_new();
-
-                       ret = iotcon_repr_get_resource_types(cur_repr, &resource_types);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("iotcon_repr_get_resource_types() Fail(%d)", ret);
-                               json_object_unref(repr_obj);
-                               return NULL;
-                       }
-
-                       ret = iotcon_resource_types_foreach(resource_types, _icl_repr_get_res_type_fn,
-                                       rt_array);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("iotcon_resource_types_foreach() Fail");
-                               json_object_unref(repr_obj);
-                               return NULL;
-                       }
-                       json_object_set_array_member(prop_obj, IC_JSON_KEY_RESOURCETYPES, rt_array);
-               }
-
-               if (IOTCON_INTERFACE_NONE != cur_repr->interfaces) {
-                       JsonArray *if_array = json_array_new();
-                       ifaces = iotcon_repr_get_resource_interfaces(cur_repr);
-                       for (i = 1; i <= ICL_INTERFACE_MAX; i = i << 1) {
-                               if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */
-                                       continue;
-                               ret = ic_utils_convert_interface_flag((ifaces & i), &iface_str);
-                               if (IOTCON_ERROR_NONE != ret) {
-                                       ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", i, ret);
-                                       json_object_unref(repr_obj);
-                                       json_array_unref(if_array);
-                                       return NULL;
-                               }
-                               json_array_add_string_element(if_array, iface_str);
-                       }
-
-                       json_object_set_array_member(prop_obj, IC_JSON_KEY_INTERFACES, if_array);
-               }
-       }
-
-       return repr_obj;
-}
-
-static JsonObject* _icl_repr_data_generate_parent(iotcon_repr_h cur_repr,
-               unsigned int child_index)
-{
-       FN_CALL;
-       JsonObject *obj = _icl_repr_data_generate_json(cur_repr, child_index);
-       if (NULL == obj) {
-               ERR("_icl_repr_data_generate_json() Fail");
-               return NULL;
-       }
-
-       return obj;
-}
-
-static JsonObject* _icl_repr_data_generate_child(iotcon_repr_h cur_repr,
-               unsigned int child_index)
-{
-       FN_CALL;
-       JsonObject *obj = _icl_repr_data_generate_json(cur_repr, child_index);
-       if (NULL == obj) {
-               ERR("_icl_repr_data_generate_json() Fail");
-               return NULL;
-       }
-
-       return obj;
-}
-
-/*
- * A general result : [{"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}},
- *                                             {"href":"/a/child","rep":{"string":"World","double_val":5.7},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}]
- */
-static JsonArray* _icl_repr_generate_json_array(iotcon_repr_h repr)
-{
-       FN_CALL;
-       JsonObject *repr_obj;
-       JsonArray *root_array;
-       unsigned int child_index;
-       unsigned int child_count = 0;
-       iotcon_repr_h child_repr = NULL;
-
-       RETV_IF(NULL == repr, NULL);
-
-       if (repr->children)
-               child_count = iotcon_repr_get_children_count(repr);
-
-       repr_obj = _icl_repr_data_generate_parent(repr, child_index);
-       if (NULL == repr_obj) {
-               ERR("_icl_repr_data_generate_parent() Fali(NULL == repr_obj)");
-               return NULL;
-       }
-
-       root_array = json_array_new();
-       json_array_add_object_element(root_array, repr_obj);
-
-       for (child_index = 0; child_index < child_count; child_index++) {
-               iotcon_repr_get_nth_child(repr, child_index, &child_repr);
-               repr_obj = _icl_repr_data_generate_child(child_repr, child_index);
-               if (NULL == repr_obj) {
-                       ERR("_icl_repr_data_generate_child() Fali(NULL == repr_obj)");
-                       json_array_unref(root_array);
-                       return NULL;
-               }
-               json_array_add_object_element(root_array, repr_obj);
-       }
-
-       return root_array;
-}
-
-/*
- * returned string SHOULD be released by you
- */
-gchar* _icl_repr_obj_to_json(JsonObject *obj, bool set_pretty)
-{
-       gchar *json_data;
-       JsonGenerator *gen;
-       JsonNode *root_node = NULL;
-
-       gen = json_generator_new();
-#if JSON_CHECK_VERSION(0,14,0)
-       json_generator_set_pretty(gen, set_pretty);
-#endif
-
-       root_node = json_node_new(JSON_NODE_OBJECT);
-       json_node_set_object(root_node, obj);
-       json_generator_set_root(gen, root_node);
-
-       json_data = json_generator_to_data(gen, NULL);
-       DBG("result : %s", json_data);
-
-       json_node_free(root_node);
-       g_object_unref(gen);
-
-       return json_data;
-}
-
-
-/*
- * returned string SHOULD be released by you
- */
-gchar* _icl_repr_array_to_json(JsonArray *array, bool set_pretty)
-{
-       gchar *json_data;
-       char json_buf[PATH_MAX] = {0};
-       int total_len = 0, json_len = 0;
-       unsigned int rsrc_count, rsrc_index;
-
-       rsrc_count = json_array_get_length(array);
-       if (0 == rsrc_count) {
-               ERR("json_array_get_length() Fail");
-               return NULL;
-       }
-
-       for (rsrc_index = 0; rsrc_index < rsrc_count; rsrc_index++) {
-               char *repr_str;
-               JsonObject *repr_obj;
-
-               repr_obj = json_array_get_object_element(array, rsrc_index);
-               repr_str = _icl_repr_obj_to_json(repr_obj, false);
-               json_len = snprintf(json_buf + total_len, PATH_MAX, "%s", repr_str);
-               if (json_len < 0) {
-                       ERR("snprintf(json buffer) Fail");
-                       free(repr_str);
-                       return NULL;
-               }
-
-               free(repr_str);
-               total_len += json_len;
-       }
-
-       json_data = ic_utils_strdup(json_buf);
-
-       return json_data;
-}
-
-
-char* icl_repr_generate_json(iotcon_repr_h repr, bool set_pretty, bool include_oc_key)
-{
-       FN_CALL;
-       JsonObject *root_obj = NULL;
-       JsonArray *rsrc_array;
-       char *json_data = NULL;
-
-       rsrc_array = _icl_repr_generate_json_array(repr);
-       if (NULL == rsrc_array) {
-               ERR("_icl_repr_generate_json_array() Fail");
-               return NULL;
-       }
-
-       if (true == include_oc_key) {
-               root_obj = json_object_new();
-               json_object_set_array_member(root_obj, IC_JSON_KEY_OC, rsrc_array);
-               json_data = _icl_repr_obj_to_json(root_obj, set_pretty);
-               if (NULL == json_data) {
-                       ERR("_icl_repr_obj_to_json() Fail");
-                       json_array_unref(rsrc_array);
-                       return NULL;
-               }
-
-               json_object_unref(root_obj);
-       } else {
-               json_data = _icl_repr_array_to_json(rsrc_array, set_pretty);
-               if (NULL == json_data) {
-                       ERR("_icl_repr_array_to_json() Fail");
-                       json_array_unref(rsrc_array);
-                       return NULL;
-               }
-
-               json_array_unref(rsrc_array);
-       }
-
-       return json_data;
-}
-
-
-/*
- * returned string SHOULD be released by you
- */
-char* icl_repr_json_get_uri_path(const char *json_string)
-{
-       GError *error = NULL;
-       gboolean ret = FALSE;
-       char *uri_path = NULL;
-       const char *str_value = NULL;
-       JsonParser *parser;
-       JsonObject *root_obj;
-
-       RETV_IF(NULL == json_string, NULL);
-
-       parser = json_parser_new();
-       ret = json_parser_load_from_data(parser, json_string, strlen(json_string), &error);
-       if (FALSE == ret) {
-               ERR("json_parser_load_from_data() Fail(%s)", error->message);
-               g_error_free(error);
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       root_obj = json_node_get_object(json_parser_get_root(parser));
-       if (json_object_has_member(root_obj, IC_JSON_KEY_URI_PATH)) {
-               str_value = json_object_get_string_member(root_obj, IC_JSON_KEY_URI_PATH);
-               if (NULL == str_value) {
-                       ERR("json_object_get_string_member() Fail");
-                       return NULL;
-               }
-               uri_path = strdup(str_value);
-               if (NULL == uri_path) {
-                       ERR("strdup() Fail");
-                       return NULL;
-               }
-       }
-       return uri_path;
-}
-
-
-/*
- * A general input : {"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}
- *
- * Result : A iotcon_repr_h handle including uri_path
- */
-static iotcon_repr_h _icl_repr_create_repr(JsonObject *rsrc_obj)
-{
-       FN_CALL;
-       char *json_data;
-       iotcon_repr_h repr;
-
-       json_data = _icl_repr_obj_to_json(rsrc_obj, false);
-       if (NULL == json_data) {
-               ERR("json_data is NULL");
-               return NULL;
-       }
-
-       repr = icl_repr_parse_json(json_data);
-       if (NULL == repr) {
-               ERR("icl_repr_parse_json() Fail");
-               g_free(json_data);
-               return NULL;
-       }
-
-       free(json_data);
-
-       return repr;
-}
-
-
-/*
- * A general input : {oc:[{"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}},
- *                                             {"href":"/a/child","rep":{"string":"World","double_val":5.7},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}]}
- *
- * Result : iotcon_repr_h handles(parent and child) including uri_path
- */
-iotcon_repr_h icl_repr_create_repr(const char *json_string)
-{
-       FN_CALL;
-       gboolean ret;
-       JsonParser *parser;
-       GError *error = NULL;
-       JsonArray *rsrc_array;
-       iotcon_repr_h repr_cur;
-       iotcon_repr_h repr_parent = NULL;
-       JsonObject *root_obj, *rsrc_obj;
-       unsigned int rsrc_count, rsrc_index;
-
-       parser = json_parser_new();
-       ret = json_parser_load_from_data(parser, json_string, strlen(json_string), &error);
-       if (FALSE == ret) {
-               ERR("json_parser_load_from_data() Fail(%s)", error->message);
-               g_error_free(error);
-               return NULL;
-       }
-
-       root_obj = json_node_get_object(json_parser_get_root(parser));
-
-       /* parse 'oc' prefix */
-       rsrc_array = json_object_get_array_member(root_obj, IC_JSON_KEY_OC);
-       if (NULL == rsrc_array) {
-               ERR("json_object_get_array_member() Fail");
-               return NULL;
-       }
-
-       rsrc_count = json_array_get_length(rsrc_array);
-       for (rsrc_index = 0; rsrc_index < rsrc_count; rsrc_index++) {
-               rsrc_obj = json_array_get_object_element(rsrc_array, rsrc_index);
-               repr_cur = _icl_repr_create_repr(rsrc_obj);
-               if (NULL == repr_cur) {
-                       ERR("_icl_repr_create_repr() Fail");
-                       if (0 < rsrc_index) /* parent was already made */
-                               iotcon_repr_free(repr_parent);
-                       return NULL;
-               }
-
-               if (0 == rsrc_index) { /* parent representation */
-                       repr_parent = repr_cur;
-               } else { /* child representation */
-                       ret = iotcon_repr_append_child(repr_parent, repr_cur);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("iotcon_repr_append_child() Fail(%d)", ret);
-                               iotcon_repr_free(repr_parent);
-                               return NULL;
-                       }
-               }
-       }
-
-       return repr_parent;
-}
-
-
-static int _icl_repr_convert_interface_string(const char *src, iotcon_interface_e *dest)
-{
-       RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
-       if (IC_STR_EQUAL == strcmp(IC_INTERFACE_DEFAULT, src)) {
-               *dest = IOTCON_INTERFACE_DEFAULT;
-       } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_LINK, src)) {
-               *dest = IOTCON_INTERFACE_LINK;
-       } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_BATCH, src)) {
-               *dest = IOTCON_INTERFACE_BATCH;
-       } else {
-               ERR("Invalid Interface");
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-/*
- * types SHOULD be released by you
- */
-int icl_repr_parse_resource_property(JsonObject *prop_obj, iotcon_resource_types_h *types,
-               int *ifaces, int *obs)
-{
-       int ret, observable;
-       int ret_ifaces = IOTCON_INTERFACE_NONE;
-       JsonArray *iface_array, *rtye_array;
-       iotcon_resource_types_h res_types = NULL;
-
-       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
-
-       rtye_array = json_object_get_array_member(prop_obj, IC_JSON_KEY_RESOURCETYPES);
-       if (rtye_array) {
-               unsigned int rt_count, rt_index;
-
-               rt_count = json_array_get_length(rtye_array);
-               if (0 < rt_count) {
-                       res_types = iotcon_resource_types_new();
-                       if (NULL == res_types) {
-                               ERR("iotcon_resource_types_new() Fail");
-                               return IOTCON_ERROR_OUT_OF_MEMORY;
-                       }
-
-                       for (rt_index = 0; rt_index < rt_count; rt_index++) {
-                               const char *rtype_str;
-
-                               rtype_str = json_array_get_string_element(rtye_array, rt_index);
-                               iotcon_resource_types_insert(res_types, rtype_str);
-                       }
-               }
-       }
-
-       iface_array = json_object_get_array_member(prop_obj, IC_JSON_KEY_INTERFACES);
-       if (iface_array) {
-               iotcon_interface_e iface_flag;
-               unsigned int if_count, if_index;
-
-               if_count = json_array_get_length(iface_array);
-               for (if_index = 0; if_index < if_count; if_index++) {
-                       const char *iface_str = json_array_get_string_element(iface_array, if_index);
-                       ret = _icl_repr_convert_interface_string(iface_str, &iface_flag);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("icl_ioty_convert_interface_string() Fail(%d)", ret);
-                               if (res_types)
-                                       iotcon_resource_types_free(res_types);
-                               return ret;
-                       }
-
-                       ret_ifaces |= iface_flag;
-               }
-       }
-
-       observable = json_object_get_int_member(prop_obj, IC_JSON_KEY_OBSERVABLE);
-
-       *types = res_types;
-       *ifaces = ret_ifaces;
-       *obs = observable;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-/*
- * A general input : {"href":"/a/parent","rep":{"string":"Hello","intlist":[1,2,3]},
- *                                             "prop":{"rt":["core.light"],"if":["oc.mi.def"]}}
- */
-iotcon_repr_h icl_repr_parse_json(const char *json_string)
-{
-       int ret, observable;
-       JsonParser *parser;
-       GError *error = NULL;
-       const char *str_value;
-       iotcon_repr_h repr = NULL;
-       iotcon_resource_types_h res_types;
-       int ifaces = IOTCON_INTERFACE_NONE;
-       JsonObject *root_obj, *property_obj;
-
-       RETV_IF(NULL == json_string, NULL);
-
-       DBG("input str : %s", json_string);
-
-       parser = json_parser_new();
-       ret = json_parser_load_from_data(parser, json_string, strlen(json_string), &error);
-       if (FALSE == ret) {
-               ERR("json_parser_load_from_data() Fail(%s)", error->message);
-               g_error_free(error);
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       root_obj = json_node_get_object(json_parser_get_root(parser));
-       if (NULL == root_obj) {
-               ERR("json_node_get_object() Fail");
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       repr = icl_obj_from_json(root_obj);
-       if (NULL == repr) {
-               ERR("icl_obj_from_json() Fail()");
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       str_value = json_object_get_string_member(root_obj, IC_JSON_KEY_URI_PATH);
-       if (str_value) {
-               ret = iotcon_repr_set_uri_path(repr, str_value);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_repr_set_uri_path() Fail(%d)", ret);
-                       iotcon_repr_free(repr);
-                       g_object_unref(parser);
-                       return NULL;
-               }
-       }
-
-       property_obj = json_object_get_object_member(root_obj, IC_JSON_KEY_PROPERTY);
-       if (NULL == property_obj) {
-               /* Here is normal condition */
-               g_object_unref(parser);
-               return repr;
-       }
-
-       ret = icl_repr_parse_resource_property(property_obj, &res_types, &ifaces,
-                       &observable);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("icl_repr_parse_resource_property() Fail(%d)", ret);
-               iotcon_repr_free(repr);
-               g_object_unref(parser);
-               return NULL;
-       }
-
-       iotcon_repr_set_resource_types(repr, res_types);
-       iotcon_repr_set_resource_interfaces(repr, ifaces);
-
-       iotcon_resource_types_free(res_types);
-       g_object_unref(parser);
-
-       return repr;
-}
-
 
 API void iotcon_repr_free(iotcon_repr_h repr)
 {
@@ -938,8 +369,3 @@ API iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src)
 
        return dest;
 }
-
-API char* iotcon_repr_generate_json(iotcon_repr_h repr)
-{
-       return icl_repr_generate_json(repr, true, true);
-}
index d492e70..a70a0d2 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <stdbool.h>
 #include <glib.h>
-#include <json-glib/json-glib.h>
 
 #include "iotcon-struct.h"
 
@@ -32,27 +31,6 @@ struct icl_repr_s {
        iotcon_resource_types_h res_types;
 };
 
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
- * @brief Generates JSON string from Representation.
- * @since_tizen 3.0
- * @remarks The returned string must be released with free() by you.
- *
- * @param[in] repr The handle to the Representation
- * @param[in] set_pretty Whether the generated JSON string should be pretty printed
- *
- * @return Generated JSON string, otherwise a null pointer if a parse error
- */
-char* icl_repr_generate_json(iotcon_repr_h repr, bool set_pretty, bool include_oc_key);
-
-char* icl_repr_json_get_uri_path(const char *json_string);
-
-iotcon_repr_h icl_repr_create_repr(const char *json_string);
-iotcon_repr_h icl_repr_parse_json(const char *json_string);
-
 void icl_repr_inc_ref_count(iotcon_repr_h val);
 
-int icl_repr_parse_resource_property(JsonObject *prop_obj, iotcon_resource_types_h *types,
-               int *ifaces, int *obs);
-
 #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */
index 72a81cf..3001c9c 100644 (file)
@@ -30,6 +30,7 @@
 #include "icl-dbus.h"
 #include "icl-dbus-type.h"
 #include "icl.h"
+#include "icl-payload.h"
 
 static void _icl_request_handler(GDBusConnection *connection,
                const gchar *sender_name,
@@ -44,22 +45,23 @@ static void _icl_request_handler(GDBusConnection *connection,
        unsigned short option_id;
        char *option_data;
        GVariantIter *query;
+       GVariantIter *repr_iter;
        char *key = NULL;
        char *value = NULL;
-       char *repr_json;
        int request_handle;
        int resource_handle;
        struct icl_resource_request request = {0};
        iotcon_resource_h resource = user_data;
        iotcon_request_handler_cb cb = resource->cb;
+       GVariant *repr_gvar;
 
-       g_variant_get(parameters, "(ia(qs)a(ss)ii&sii)",
+       g_variant_get(parameters, "(ia(qs)a(ss)iiavii)",
                        &request.types,
                        &options,
                        &query,
                        &request.observation_info.action,
                        &request.observation_info.observer_id,
-                       &repr_json,
+                       &repr_iter,
                        &request_handle,
                        &resource_handle);
 
@@ -80,8 +82,8 @@ static void _icl_request_handler(GDBusConnection *connection,
        request.request_handle = GINT_TO_POINTER(request_handle);
        request.resource_handle = GINT_TO_POINTER(resource_handle);
 
-       if (ic_utils_dbus_decode_str(repr_json)) {
-               request.repr = icl_repr_create_repr(repr_json);
+       if (g_variant_iter_loop(repr_iter, "v", &repr_gvar)) {
+               request.repr = icl_repr_from_gvariant(repr_gvar);
                if (NULL == request.repr) {
                        ERR("icl_repr_create_repr() Fail");
                        if (request.query)
@@ -123,7 +125,6 @@ API iotcon_resource_h iotcon_register_resource(const char *uri_path,
                iotcon_request_handler_cb cb,
                void *user_data)
 {
-       FN_CALL;
        int signal_number;
        unsigned int sub_id;
        GError *error = NULL;
index e10b867..b2fac9e 100644 (file)
@@ -190,7 +190,7 @@ static int _icl_response_check_repr_visibility(iotcon_response_h resp)
 API int iotcon_response_send(iotcon_response_h resp)
 {
        FN_CALL;
-       int ret;
+       int ret = 0;
        GError *error = NULL;
        GVariant *arg_response;
 
index d10d7c8..540dbc5 100644 (file)
--- a/lib/icl.h
+++ b/lib/icl.h
@@ -25,7 +25,4 @@
 #endif
 #define API __attribute__((visibility("default")))
 
-#define ICL_INTERFACE_MAX (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | \
-               IOTCON_INTERFACE_BATCH | IOTCON_INTERFACE_GROUP)
-
 #endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_H__ */
index 53b0b02..dc949ba 100644 (file)
@@ -100,9 +100,9 @@ typedef enum {
 
 typedef enum {
        IOTCON_HIDDEN = 0,
-       IOTCON_ACTIVE = (1 << 0),
-       IOTCON_DISCOVERABLE = (1 << 1),
-       IOTCON_OBSERVABLE = (1 << 2),
+       IOTCON_DISCOVERABLE = (1 << 0),
+       IOTCON_OBSERVABLE = (1 << 1),
+       IOTCON_ACTIVE = (1 << 2),
        IOTCON_SLOW = (1 << 3),
        IOTCON_SECURE = (1 << 4),
 } iotcon_resource_property_e;
index e4a9c36..f999c92 100644 (file)
@@ -112,8 +112,6 @@ typedef int (*iotcon_repr_fn)(iotcon_repr_h repr, const char *key, void *user_da
 int iotcon_repr_foreach(iotcon_repr_h repr, iotcon_repr_fn fn, void *user_data);
 unsigned int iotcon_repr_get_keys_count(iotcon_repr_h repr);
 
-char* iotcon_repr_generate_json(iotcon_repr_h repr);
-
 iotcon_list_h iotcon_list_new(iotcon_types_e type);
 void iotcon_list_free(iotcon_list_h list);
 
index 9939a29..e04a5d3 100644 (file)
@@ -28,22 +28,9 @@ typedef struct icl_notify_msg* iotcon_notimsg_h;
 
 typedef struct icl_presence* iotcon_presence_h;
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
 typedef struct _device_info {
-       char *name;
-       char *host_name;
-       char *uuid;
-       char *content_type;
-       char *version;
-       char *manuf_name;
-       char *manuf_url;
-       char *model_number;
-       char *date_of_manufacture;
-       char *platform_ver;
-       char *firmware_ver;
-       char *support_url;
+       char *device_name;
 } iotcon_device_info_s;
-#endif
 
 typedef struct _platform_info {
        char *platform_id;
@@ -145,4 +132,20 @@ iotcon_response_h iotcon_response_new(iotcon_request_h request_h);
 void iotcon_response_free(iotcon_response_h resp);
 int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop, ...);
 
+typedef struct icl_device_info* iotcon_device_h;
+int iotcon_device_get_name(iotcon_device_h device, char **name);
+
+typedef struct icl_platform_info* iotcon_platform_h;
+int iotcon_platform_get_id(iotcon_device_h device, char **id);
+int iotcon_platform_get_manuf_name(iotcon_device_h device, char **manuf_name);
+int iotcon_platform_get_manuf_url(iotcon_device_h device, char **manuf_url);
+int iotcon_platform_get_model_number(iotcon_device_h device, char **model_number);
+int iotcon_platform_get_date_of_maunfacture(iotcon_device_h device, char **date);
+int iotcon_platform_get_platform_ver(iotcon_device_h device, char **platform_ver);
+int iotcon_platform_get_os_ver(iotcon_device_h device, char **os_ver);
+int iotcon_platform_get_hardware_ver(iotcon_device_h device, char **hardware_ver);
+int iotcon_platform_get_firmware_ver(iotcon_device_h device, char **firmware_ver);
+int iotcon_platform_get_support_url(iotcon_device_h device, char **support_url);
+int iotcon_platform_get_system_time(iotcon_device_h device, char **system_time);
+
 #endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_H__ */
index c4d69e0..54e9623 100644 (file)
@@ -67,15 +67,15 @@ int iotcon_bind_request_handler(iotcon_resource_h resource, iotcon_request_handl
 int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child);
 int iotcon_unbind_resource(iotcon_resource_h parent, iotcon_resource_h child);
 
-#ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
-int iotcon_register_device_info(iotcon_device_info_s device_info);
-typedef void (*iotcon_device_info_cb)(iotcon_device_info_s info, void *user_data);
+
+int iotcon_register_device_info(const char *device_name);
+typedef void (*iotcon_device_info_cb)(const char *device_name, const char *sid,
+               const char *spec_version, const char *data_model_version, void *user_data);
 int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
                void *user_data);
-#endif
 
 int iotcon_register_platform_info(iotcon_platform_info_s platform_info);
-typedef void (*iotcon_platform_info_cb)(iotcon_repr_h repr, void *user_data);
+typedef void (*iotcon_platform_info_cb)(iotcon_platform_info_s info, void *user_data);
 int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
                void *user_data);
 
index a16b6d6..40ca96a 100644 (file)
@@ -12,7 +12,6 @@ BuildRequires:  cmake
 BuildRequires:  boost-devel
 BuildRequires:  iotivity-devel
 BuildRequires:  pkgconfig(glib-2.0)
-BuildRequires:  pkgconfig(json-glib-1.0)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(capi-base-common)
 %if "%{tizen}" == "2.3"
index 401ba93..8edf46a 100644 (file)
 static const char* const door_uri_path = "/a/door";
 static char *door_resource_sid;
 
-void _print_repr_info(iotcon_repr_h repr)
-{
-       if (0 < iotcon_repr_get_keys_count(repr))
-               DBG("rep : \n%s", iotcon_repr_generate_json(repr));
-}
-
 static void _on_observe(iotcon_client_h resource,
                iotcon_repr_h recv_repr,
                iotcon_options_h header_options,
@@ -77,8 +71,6 @@ static void _on_post(iotcon_client_h resource, iotcon_repr_h recv_repr,
                        "_on_post Response error(%d)", response_result);
        INFO("POST request was successful");
 
-       _print_repr_info(recv_repr);
-
        iotcon_repr_get_str(recv_repr, "createduripath", &created_uri_path);
 
        if (NULL == created_uri_path) {
@@ -121,8 +113,6 @@ static void _on_put(iotcon_client_h resource, iotcon_repr_h recv_repr,
                        response_result);
        INFO("PUT request was successful");
 
-       _print_repr_info(recv_repr);
-
        iotcon_repr_h send_repr = iotcon_repr_new();
 
        /* send POST request */
@@ -138,8 +128,6 @@ static void _on_get(iotcon_client_h resource, iotcon_repr_h recv_repr,
                        response_result);
        INFO("GET request was successful");
 
-       _print_repr_info(recv_repr);
-
        iotcon_repr_h send_repr = iotcon_repr_new();
        iotcon_repr_set_bool(send_repr, "opened", true);
 
index 4ae3648..079c93d 100644 (file)
 #include <iotcon.h>
 #include "test.h"
 
-static void _get_platform_info(iotcon_repr_h repr, void *user_data)
+static void _get_platform_info(iotcon_platform_info_s info, void *user_data)
 {
-       FN_CALL;
-       char *platform_id = NULL;
-       char *manuf_name = NULL;
-       char *manuf_url = NULL;
-       char *model_number = NULL;
-       char *date_of_manufacture = NULL;
-       char *platform_ver = NULL;
-       char *os_ver = NULL;
-       char *hardware_ver = NULL;
-       char *firmware_ver = NULL;
-       char *support_url = NULL;
-       char *system_time = NULL;
+       INFO("platform_id : %s", info.platform_id);
+       INFO("manuf_name : %s", info.manuf_name);
+       INFO("manuf_url : %s", info.manuf_url);
+       INFO("model_number : %s", info.model_number);
+       INFO("date_of_manufacture : %s", info.date_of_manufacture);
+       INFO("platform_ver : %s", info.platform_ver);
+       INFO("os_ver : %s", info.os_ver);
+       INFO("hardware_ver : %s", info.hardware_ver);
+       INFO("firmware_ver : %s", info.firmware_ver);
+       INFO("support_url : %s", info.support_url);
+       INFO("system_time : %s", info.system_time);
+}
 
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_PLATFORM_ID, &platform_id);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_MFG_NAME, &manuf_name);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_MFG_URL, &manuf_url);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_MODEL_NUM, &model_number);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_MFG_DATE, &date_of_manufacture);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_PLATFORM_VERSION, &platform_ver);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_OS_VERSION, &os_ver);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_HARDWARE_VERSION, &hardware_ver);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_FIRMWARE_VERSION, &firmware_ver);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_SUPPORT_URL, &support_url);
-       iotcon_repr_get_str(repr, IOTCON_PLATFORM_SYSTEM_TIME, &system_time);
 
-       INFO("platform_id : %s", platform_id);
-       INFO("manuf_name : %s", manuf_name);
-       INFO("manuf_url : %s", manuf_url);
-       INFO("model_number : %s", model_number);
-       INFO("date_of_manufacture : %s", date_of_manufacture);
-       INFO("platform_ver : %s", platform_ver);
-       INFO("os_ver : %s", os_ver);
-       INFO("hardware_ver : %s", hardware_ver);
-       INFO("firmware_ver : %s", firmware_ver);
-       INFO("support_url : %s", support_url);
-       INFO("system_time : %s", system_time);
+static void _get_device_info(const char *device_name, const char *sid,
+               const char *spec_version, const char *data_model_version, void *user_data)
+{
+       INFO("device_name : %s", device_name);
+       INFO("sid : %s", sid);
+       INFO("spec_version : %s", spec_version);
+       INFO("data_model_version : %s", data_model_version);
 }
 
+
 int main()
 {
-       FN_CALL;
        GMainLoop *loop;
 
        loop = g_main_loop_new(NULL, FALSE);
@@ -70,6 +55,8 @@ int main()
 
        iotcon_get_platform_info(IOTCON_MULTICAST_ADDRESS, _get_platform_info, NULL);
 
+       iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, _get_device_info, NULL);
+
        g_main_loop_run(loop);
 
        g_main_loop_unref(loop);
index 772086a..10df533 100644 (file)
@@ -20,9 +20,9 @@
 
 int main()
 {
-       FN_CALL;
        int ret;
        GMainLoop *loop;
+       char *device_name;
 
        iotcon_platform_info_s platform_info = {0};
 
@@ -38,6 +38,8 @@ int main()
        platform_info.support_url = "support_url";
        platform_info.system_time = "system_time";
 
+       device_name = "device_name";
+
        loop = g_main_loop_new(NULL, FALSE);
 
        /* iotcon open */
@@ -49,6 +51,12 @@ int main()
                return -1;
        }
 
+       ret = iotcon_register_device_info(device_name);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_register_platform_info() Fail(%d)", ret);
+               return -1;
+       }
+
        g_main_loop_run(loop);
 
        g_main_loop_unref(loop);
index dfe5ae0..02c6299 100644 (file)
@@ -111,7 +111,7 @@ static void _on_get_1st(iotcon_client_h resource, iotcon_repr_h recv_repr,
        _on_get(recv_repr, response_result);
 
        query_params = iotcon_query_new();
-       iotcon_query_insert(query_params, "if", "oc.mi.b");
+       iotcon_query_insert(query_params, "if", "oic.if.b");
 
        /* send GET request again with BATCH interface */
        iotcon_get(resource, query_params, _on_get_2nd, NULL);
index 527e30e..4201b3a 100644 (file)
@@ -113,7 +113,7 @@ static void _room_request_handler_get(iotcon_request_h request,
        if (query)
                iotcon_query_foreach(query, _query_foreach_fn, &query_str);
 
-       if (query_str && (TEST_STR_EQUAL == strcmp("oc.mi.b", query_str))) {
+       if (query_str && (TEST_STR_EQUAL == strcmp("oic.if.b", query_str))) {
                DBG("operation for BATCH interface");
                interface = IOTCON_INTERFACE_BATCH;
        } else {