modify interface data type (int->string) 35/58835/11
authoryoungman <yman.jung@samsung.com>
Thu, 4 Feb 2016 01:01:13 +0000 (10:01 +0900)
committeryoungman <yman.jung@samsung.com>
Fri, 19 Feb 2016 06:06:45 +0000 (15:06 +0900)
Change-Id: I107b33b15e750f5b0f05a1ed3e152923abd98641
Signed-off-by: youngman <yman.jung@samsung.com>
39 files changed:
common/ic-common.h
common/ic-dbus.xml
common/ic-utils.c
common/ic-utils.h
daemon/icd-dbus.c
daemon/icd-ioty.c
daemon/icd-ioty.h
daemon/icd-payload.c
doc/iotcon_doc.h
lib/icl-dbus-type.c
lib/icl-dbus-type.h
lib/icl-lite-resource.c
lib/icl-payload.c
lib/icl-query.c
lib/icl-remote-resource.c
lib/icl-remote-resource.h
lib/icl-representation.c
lib/icl-representation.h
lib/icl-resource-interfaces.c [new file with mode: 0644]
lib/icl-resource-interfaces.h [new file with mode: 0644]
lib/icl-resource-types.c
lib/icl-resource.c
lib/icl-resource.h
lib/icl-response.c
lib/icl-response.h
lib/include/iotcon-constant.h
lib/include/iotcon-query.h
lib/include/iotcon-remote-resource.h
lib/include/iotcon-representation.h
lib/include/iotcon-resource-interfaces.h [new file with mode: 0644]
lib/include/iotcon-resource-types.h
lib/include/iotcon-resource.h
lib/include/iotcon-response.h
lib/include/iotcon-types.h
test/iotcon-test-basic-client.c
test/iotcon-test-basic-server.c
test/iotcon-test-encap-client.c
test/iotcon-test-iface-client.c
test/iotcon-test-iface-server.c

index ac623faeedf60c7ae44328f0ffce4b95f494a78f..d2ef59c632dc90f0501913cc7bc2aa81878f5f06 100644 (file)
 #define IC_DBUS_SIGNAL_MONITORING "MONITORING"
 #define IC_DBUS_SIGNAL_CACHING "CACHING"
 
-#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 "oic.mi.grp"
-#define IC_INTERFACE_READONLY "oic.if.r"
-
 #define IC_FEATURE_OIC "http://tizen.org/feature/iot.oic"
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__ */
index 66c72483e7cc37e565748385bf3ad72e2baaba33..8a9d36eb8d1c556c42b7246216b28137c934a8db 100644 (file)
@@ -3,7 +3,7 @@
                <method name="registerResource">
                        <arg type="s" name="uri_path" direction="in"/>
                        <arg type="as" name="resource_types" direction="in"/>
-                       <arg type="i" name="ifaces" direction="in"/>
+                       <arg type="as" name="ifaces" direction="in"/>
                        <arg type="i" name="properties" direction="in"/>
                        <arg type="b" name="is_lite" direction="in"/>
                        <arg type="x" name="signal_number" direction="out"/>
@@ -14,7 +14,7 @@
                </method>
                <method name="bindInterface">
                        <arg type="x" name="resource" direction="in"/>
-                       <arg type="i" name="iface" direction="in"/>
+                       <arg type="s" name="iface" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="bindType">
                </method>
                <method name="put">
                        <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
-                       <arg type="(siasa{sv}av)" name="repr" direction="in"/>
+                       <arg type="(sasasa{sv}av)" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="post">
                        <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
-                       <arg type="(siasa{sv}av)" name="repr" direction="in"/>
+                       <arg type="(sasasa{sv}av)" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
index 1f0cedcc7e796abd88e061708dbba2794e7e1d08..4e2d317b220f6817124ed047c0d866b0e9d057a1 100644 (file)
@@ -62,57 +62,6 @@ char* ic_utils_dbus_decode_str(char *src)
 }
 
 
-int ic_utils_convert_interface_flag(iotcon_interface_e src, char **dest)
-{
-       switch (src) {
-       case IOTCON_INTERFACE_DEFAULT:
-               *dest = IC_INTERFACE_DEFAULT;
-               break;
-       case IOTCON_INTERFACE_LINK:
-               *dest = IC_INTERFACE_LINK;
-               break;
-       case IOTCON_INTERFACE_BATCH:
-               *dest = IC_INTERFACE_BATCH;
-               break;
-       case IOTCON_INTERFACE_GROUP:
-               *dest = IC_INTERFACE_GROUP;
-               break;
-       case IOTCON_INTERFACE_READONLY:
-               *dest = IC_INTERFACE_READONLY;
-               break;
-       case IOTCON_INTERFACE_NONE:
-       default:
-               ERR("Invalid interface(%d)", src);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-       return IOTCON_ERROR_NONE;
-}
-
-
-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 if (IC_STR_EQUAL == strcmp(IC_INTERFACE_READONLY, src)) {
-               *dest = IOTCON_INTERFACE_READONLY;
-       } else {
-               ERR("Invalid Interface(%s)", src);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       return IOTCON_ERROR_NONE;
-}
-
-
 void ic_utils_gvariant_array_free(GVariant **value)
 {
        int i;
@@ -129,7 +78,7 @@ bool ic_utils_check_oic_feature_supported()
        if (_ic_oic_feature_supported < 0) {
                bool feature_supported = false;
                system_info_get_platform_bool(IC_FEATURE_OIC, &feature_supported);
-               _ic_oic_feature_supported = feature_supported? 1: 0;
+               _ic_oic_feature_supported = feature_supported ? 1 : 0;
        }
        return _ic_oic_feature_supported;
 #else
index 7bda22d3a405f8aa4401419825962dfee8af238f..87b6bf9a50dd490a50aa591349cdc2d7ca2478cd 100644 (file)
 #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 | IOTCON_INTERFACE_READONLY)
-
 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);
 bool ic_utils_check_oic_feature_supported();
 
index e07487e6a59918b7b914c66148de01a7caf624b5..011c237c88fc46c930be885cafee61c17144b59e 100644 (file)
@@ -642,7 +642,7 @@ static gboolean _dbus_handle_register_resource(icDbus *object,
                GDBusMethodInvocation *invocation,
                const gchar *uri_path,
                const gchar* const *resource_types,
-               gint ifaces,
+               const gchar* const *ifaces,
                gint properties,
                gboolean is_lite)
 {
@@ -714,7 +714,7 @@ static gboolean _dbus_handle_unregister_resource(icDbus *object,
 
 
 static gboolean _dbus_handle_bind_interface(icDbus *object,
-               GDBusMethodInvocation *invocation, gint64 resource, gint iface)
+               GDBusMethodInvocation *invocation, gint64 resource, const gchar *iface)
 {
        int ret;
 
index 5cf0a552f1603e508d2f7e0146b4a54feecacc2d..c74003d3fc5620a401e276db9fdff0ffc76b9821 100644 (file)
@@ -131,38 +131,17 @@ static int _ioty_properties_to_oic_properties(int properties)
 }
 
 OCResourceHandle icd_ioty_register_resource(const char *uri_path,
-               const char * const *res_types, int ifaces, int properties)
+               const char* const *res_types, const char* const *res_ifaces, int properties)
 {
        FN_CALL;
        int i;
        OCStackResult ret;
        OCResourceHandle handle;
-       const char *res_iface = NULL;
-
-       if (IOTCON_INTERFACE_DEFAULT & ifaces) {
-               res_iface = IC_INTERFACE_DEFAULT;
-               ifaces ^= IOTCON_INTERFACE_DEFAULT;
-       } else if (IOTCON_INTERFACE_LINK & ifaces) {
-               res_iface = IC_INTERFACE_LINK;
-               ifaces ^= IOTCON_INTERFACE_LINK;
-       } else if (IOTCON_INTERFACE_BATCH & ifaces) {
-               res_iface = IC_INTERFACE_BATCH;
-               ifaces ^= IOTCON_INTERFACE_BATCH;
-       } else if (IOTCON_INTERFACE_GROUP & ifaces) {
-               res_iface = IC_INTERFACE_GROUP;
-               ifaces ^= IOTCON_INTERFACE_GROUP;
-       } else if (IOTCON_INTERFACE_READONLY & ifaces) {
-               res_iface = IC_INTERFACE_READONLY;
-               ifaces ^= IOTCON_INTERFACE_READONLY;
-       } else {
-               ERR("Invalid interface type(%d)", ifaces);
-               return NULL;
-       }
 
        properties = _ioty_properties_to_oic_properties(properties);
 
        icd_ioty_csdk_lock();
-       ret = OCCreateResource(&handle, res_types[0], res_iface, uri_path,
+       ret = OCCreateResource(&handle, res_types[0], res_ifaces[0], uri_path,
                        icd_ioty_ocprocess_req_handler, NULL, properties);
        icd_ioty_csdk_unlock();
        if (OC_STACK_OK != ret) {
@@ -173,16 +152,8 @@ OCResourceHandle icd_ioty_register_resource(const char *uri_path,
        for (i = 1; res_types[i]; i++)
                icd_ioty_bind_type(handle, res_types[i]);
 
-       if (IOTCON_INTERFACE_DEFAULT & ifaces)
-               icd_ioty_bind_interface(handle, IOTCON_INTERFACE_DEFAULT);
-       if (IOTCON_INTERFACE_LINK & ifaces)
-               icd_ioty_bind_interface(handle, IOTCON_INTERFACE_LINK);
-       if (IOTCON_INTERFACE_BATCH & ifaces)
-               icd_ioty_bind_interface(handle, IOTCON_INTERFACE_BATCH);
-       if (IOTCON_INTERFACE_GROUP & ifaces)
-               icd_ioty_bind_interface(handle, IOTCON_INTERFACE_GROUP);
-       if (IOTCON_INTERFACE_READONLY & ifaces)
-               icd_ioty_bind_interface(handle, IOTCON_INTERFACE_READONLY);
+       for (i = 1; res_ifaces[i]; i++)
+               icd_ioty_bind_interface(handle, res_ifaces[i]);
 
        return handle;
 }
@@ -205,25 +176,17 @@ int icd_ioty_unregister_resource(OCResourceHandle handle)
 }
 
 
-int icd_ioty_bind_interface(OCResourceHandle handle, iotcon_interface_e iface)
+int icd_ioty_bind_interface(OCResourceHandle handle, const char *resource_interface)
 {
-       int ret;
-       OCStackResult result;
-       char *resource_interface;
-
-       ret = ic_utils_convert_interface_flag(iface, &resource_interface);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("ic_utils_convert_interface_flag(%d) Fail(%d)", iface, ret);
-               return ret;
-       }
+       OCStackResult ret;
 
        icd_ioty_csdk_lock();
-       result = OCBindResourceInterfaceToResource(handle, resource_interface);
+       ret = OCBindResourceInterfaceToResource(handle, resource_interface);
        icd_ioty_csdk_unlock();
 
-       if (OC_STACK_OK != result) {
-               ERR("OCBindResourceInterfaceToResource() Fail(%d)", result);
-               return icd_ioty_convert_error(result);
+       if (OC_STACK_OK != ret) {
+               ERR("OCBindResourceInterfaceToResource() Fail(%d)", ret);
+               return icd_ioty_convert_error(ret);
        }
 
        return IOTCON_ERROR_NONE;
index 99a999641e1d907dad5b32c56af3f4ab74537d60..983f4ed561f881ebe34e8336c61eb02a239e2ef3 100644 (file)
@@ -86,11 +86,11 @@ GThread* icd_ioty_init(const char *addr, unsigned short port);
 void icd_ioty_deinit(GThread *thread);
 
 OCResourceHandle icd_ioty_register_resource(const char *uri_path,
-               const char* const* res_types, int ifaces, int properties);
+               const char* const *res_types, const char* const *res_ifaces, int properties);
 
 int icd_ioty_unregister_resource(OCResourceHandle handle);
 
-int icd_ioty_bind_interface(OCResourceHandle handle, iotcon_interface_e iface);
+int icd_ioty_bind_interface(OCResourceHandle handle, const char *resource_interface);
 
 int icd_ioty_bind_type(OCResourceHandle handle, const char *resource_type);
 
index d323d906912738312dcee017ee4f5ebb01cec689..960e8a3ad2b94dfc900a4e0ab8e3ab40e8258f30 100644 (file)
@@ -48,15 +48,14 @@ static GVariantBuilder* _icd_state_value_to_gvariant_builder(OCRepPayload *repr)
 GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
 {
        int port = 0;
-       int ifaces;
        GVariant **value;
        OCStringLL *node;
-       iotcon_interface_e iface;
        GVariantBuilder types;
+       GVariantBuilder ifaces;
        OCRandomUuidResult random_res;
        OCDiscoveryPayload *discovered;
        struct OCResourcePayload *resource;
-       int i, properties, ret, res_count;
+       int i, properties, res_count;
        char device_id[UUID_STRING_SIZE] = {0};
 
        discovered = (OCDiscoveryPayload*)payload;
@@ -96,21 +95,16 @@ GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
                }
 
                /* Resource Interfaces */
-               ifaces = 0;
+               g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
                node = resource->interfaces;
                if (NULL == node) {
                        ERR("resource interfaces is NULL");
                        g_variant_builder_clear(&types);
                        continue;
                }
-               for (; node; node = node->next) {
-                       ret = ic_utils_convert_interface_string(node->value, &iface);
-                       if (IOTCON_ERROR_NONE != ret) {
-                               ERR("ic_utils_convert_interface_string() Fail(%d)", ret);
-                               g_variant_builder_clear(&types);
-                               continue;
-                       }
-                       ifaces |= iface;
+               while (node) {
+                       g_variant_builder_add(&ifaces, "s", node->value);
+                       node = node->next;
                }
 
                /* Resource Properties */
@@ -121,7 +115,7 @@ GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
 
                /* TODO
                 * Check "resource->secure" and "resource->bitmap" */
-               value[i] = g_variant_new("(ssiasibsi)", resource->uri, device_id, ifaces, &types,
+               value[i] = g_variant_new("(ssasasibsi)", resource->uri, device_id, &ifaces, &types,
                                properties, resource->secure, dev_addr->addr, port);
                DBG("found resource[%d] : %s", i, g_variant_print(value[i], FALSE));
        }
@@ -278,12 +272,10 @@ static GVariant* _icd_payload_representation_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;
+       GVariantBuilder children, types_builder, ifaces_builder;
 
        RETV_IF(NULL == repr, NULL);
 
@@ -297,16 +289,11 @@ static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr,
        }
 
        /* Resource Interfaces */
+       g_variant_builder_init(&ifaces_builder, G_VARIANT_TYPE("as"));
+
        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);
-                       g_variant_builder_clear(&types_builder);
-                       return NULL;
-               }
-               ifaces |= iface;
-
+               g_variant_builder_add(&ifaces_builder, "s", node->value);
                node = node->next;
        }
 
@@ -324,8 +311,8 @@ static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr,
                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);
+       value = g_variant_new("(sasasa{sv}av)", ic_utils_dbus_encode_str(repr->uri),
+                       &ifaces_builder, &types_builder, repr_gvar, &children);
 
        return value;
 }
@@ -334,13 +321,14 @@ static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr,
 GVariant* icd_payload_representation_empty_gvariant(void)
 {
        GVariant *value;
-       GVariantBuilder types, repr, children;
+       GVariantBuilder ifaces, types, repr, children;
 
+       g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
        g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
        g_variant_builder_init(&repr, G_VARIANT_TYPE("a{sv}"));
        g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
 
-       value = g_variant_new("(siasa{sv}av)", IC_STR_NULL, 0, &types, &repr, &children);
+       value = g_variant_new("(sasasa{sv}av)", IC_STR_NULL, &ifaces, &types, &repr, &children);
 
        return value;
 }
@@ -737,32 +725,23 @@ static int _icd_state_value_from_gvariant(OCRepPayload *repr, GVariantIter *iter
 
 OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var)
 {
+       int ret;
        GVariant *child;
-       int ret, i, ifaces = 0;
        OCRepPayload *repr, *cur;
-       char *uri_path, *iface_str, *resource_type;
-       GVariantIter *resource_types, *repr_gvar, *children;
+       char *uri_path, *resource_iface, *resource_type;
+       GVariantIter *resource_types, *resource_ifaces, *repr_gvar, *children;
 
        repr = OCRepPayloadCreate();
 
-       g_variant_get(var, "(&siasa{sv}av)", &uri_path, &ifaces, &resource_types, &repr_gvar,
-                       &children);
+       g_variant_get(var, "(&sasasa{sv}av)", &uri_path, &resource_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;
+       while (g_variant_iter_loop(resource_ifaces, "s", &resource_iface))
+               OCRepPayloadAddInterface(repr, resource_iface);
 
-               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);
 
index 2a9ed8f9da5747f5d2418aaf532d66db7e8ac6ef..9d55d7f1e739bb7d497491e169c76121b08916a4 100644 (file)
@@ -125,11 +125,11 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
 ...
 {
        int ret;
-       int interfaces = IOTCON_INTERFACE_DEFAULT;
        int properties = (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE);
        const char *uri_path = "/door/1";
        const char *type = "org.tizen.door";
        iotcon_resource_types_h resource_types;
+       iotcon_resource_interfaces_h resource_ifaces;
        iotcon_resource_h resource = NULL;
 
        ret = iotcon_resource_types_create(&resource_types);
@@ -142,13 +142,27 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                return;
        }
 
+       ret = iotcon_resource_interfaces_create(&resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret)
+               iotcon_resource_types_destroy(resource_types);
+               return;
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
        ret = iotcon_resource_create(uri_path, resource_types,
-                       interfaces, properties, _request_handler, NULL, &resource);
+                       resource_ifaces, properties, _request_handler, NULL, &resource);
        if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                iotcon_resource_types_destroy(resource_types);
                return;
        }
 
+       iotcon_resource_interfaces_destroy(resource_ifaces);
        iotcon_resource_types_destroy(resource_types);
 }
  * @endcode
@@ -171,12 +185,12 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                void *user_data)
 {
        int ret;
-       int resource_interfaces;
        char *resource_uri_path;
        char *resource_host;
        char *device_id;
        iotcon_query_h query;
        iotcon_resource_types_h resource_types;
+       iotcon_resource_interfaces_h resource_interfaces;
        iotcon_remote_resource_h resource_clone = NULL;
 
        if (IOTCON_ERROR_NONE != result)
@@ -297,11 +311,11 @@ static void _request_handler(iotcon_request_h request, void *user_data)
 ...
 {
        int ret;
-       int interfaces = IOTCON_INTERFACE_DEFAULT;
        int properties = (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE);
        const char *uri_path = "/door/1";
        const char *type = "org.tizen.door";
        iotcon_resource_types_h resource_types;
+       iotcon_resource_interfaces_h resource_ifaces;
 
        ret = iotcon_resource_types_create(&resource_types);
        if (IOTCON_ERROR_NONE != ret)
@@ -313,13 +327,27 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                return;
        }
 
+       ret = iotcon_resource_interfaces_create(&resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret)
+               iotcon_resource_types_destroy(resource_types);
+               return;
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
        ret = iotcon_resource_create(uri_path, resource_types,
-                       interfaces, properties, _request_handler, NULL, &_door_handle);
+                       resource_ifaces, properties, _request_handler, NULL, &_door_handle);
        if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                iotcon_resource_types_destroy(resource_types);
                return;
        }
 
+       iotcon_resource_interfaces_destroy(resource_ifaces);
        iotcon_resource_types_destroy(resource_types);
 }
 ...
index 43683b21c1728e879b86628809589076f17a7ce7..30de3942958a1b945d1d555ea0b8be88033f6668 100644 (file)
@@ -23,6 +23,7 @@
 #include "icl.h"
 #include "icl-resource.h"
 #include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
 #include "icl-options.h"
 #include "icl-query.h"
 #include "icl-request.h"
 #include "icl-observation.h"
 #include "icl-dbus-type.h"
 
+const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h ifaces)
+{
+       int i = 0;
+       GList *node = ifaces->iface_list;
+       int len = g_list_length(node);
+
+       if (0 == len) {
+               ERR("Empty Resource Interface List");
+               return NULL;
+       }
+
+       const char **array = calloc(len + 1, sizeof(char*));
+       if (NULL == array) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       for (node = ifaces->iface_list; node; node = node->next, i++)
+               array[i] = node->data;
+       array[i] = NULL;
+
+       return array;
+}
+
+
 const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
 {
        int i = 0;
        GList *node = types->type_list;
        int len = g_list_length(node);
 
+       if (0 == len) {
+               ERR("Empty Resource Type List");
+               return NULL;
+       }
+
        const char **array = calloc(len + 1, sizeof(char*));
        if (NULL == array) {
                ERR("calloc() Fail(%d)", errno);
index 18a096c89f823ca3a20c7ef5abfffa5287c28179..188367acc9fccc48329a50ac48018aaf93ead827 100644 (file)
@@ -21,6 +21,7 @@
 #include "icl-device.h"
 #include "icl-resource-types.h"
 
+const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h types);
 const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types);
 GVariant* icl_dbus_representation_to_gvariant(struct icl_representation_s *repr);
 GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response);
index e534d22adb9c08c073bae743b9e04d0fb9dfe2a8..ba9517609dfbe6685b90c596879bfd18f9220eb3 100644 (file)
@@ -94,7 +94,7 @@ static int _icl_lite_resource_response_send(iotcon_representation_h repr,
                ERR("calloc() Fail(%d)", errno);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
-       response->iface = IOTCON_INTERFACE_DEFAULT;
+       response->iface = strdup(IOTCON_INTERFACE_DEFAULT);
        response->result = response_result;
        response->oic_request_h = oic_request_h;
        response->oic_resource_h = oic_resource_h;
@@ -194,7 +194,7 @@ static void _icl_lite_resource_request_handler(GDBusConnection *connection,
                        return;
                }
 
-               g_variant_get(repr_gvar, "(siasa{sv}av)", NULL, NULL, NULL, &state_iter,
+               g_variant_get(repr_gvar, "(sasasa{sv}av)", NULL, NULL, NULL, &state_iter,
                                NULL);
 
                ret = iotcon_state_create(&recv_state);
@@ -293,9 +293,9 @@ API int iotcon_lite_resource_create(const char *uri_path,
                void *user_data,
                iotcon_lite_resource_h *resource_handle)
 {
-       int ret, iface;
+       int ret;
        unsigned int sub_id;
-       const gchar **types;
+       const gchar **types, **ifaces;
        GError *error = NULL;
        iotcon_lite_resource_h resource;
        int64_t signal_number;
@@ -315,26 +315,37 @@ API int iotcon_lite_resource_create(const char *uri_path,
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       iface = IOTCON_INTERFACE_DEFAULT;
+       ifaces = calloc(2, sizeof(char*));
+       if (NULL == ifaces) {
+               ERR("calloc() Fail(%d)", errno);
+               free(resource);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ifaces[0] = IOTCON_INTERFACE_DEFAULT;
+       ifaces[1] = NULL;
 
        types = icl_dbus_resource_types_to_array(res_types);
        if (NULL == types) {
                ERR("icl_dbus_resource_types_to_array() Fail");
+               free(ifaces);
                free(resource);
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, iface,
+       ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, ifaces,
                        properties, true, &signal_number, &(resource->handle), NULL, &error);
        if (error) {
                ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
                ret = icl_dbus_convert_dbus_error(error->code);
                g_error_free(error);
                free(types);
+               free(ifaces);
                free(resource);
                return ret;
        }
        free(types);
+       free(ifaces);
 
        if (0 == resource->handle) {
                ERR("iotcon-daemon Fail");
index c0ece7061d5a6e6b6d3aaa9f4dfc598af2956829..e7bb2ef556af168a3101e80a6500af0e42a7c144 100644 (file)
@@ -24,6 +24,7 @@
 #include "icl-list.h"
 #include "icl-value.h"
 #include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
 #include "icl-response.h"
 #include "icl-payload.h"
 
@@ -176,13 +177,14 @@ static GVariant* _icl_state_value_to_gvariant(GHashTable *hash)
 static GVariant* _icl_representation_empty_gvariant(void)
 {
        GVariant *value;
-       GVariantBuilder types, repr, children;
+       GVariantBuilder types, ifaces, repr, children;
 
+       g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
        g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
        g_variant_builder_init(&repr, G_VARIANT_TYPE("a{sv}"));
        g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
 
-       value = g_variant_new("(siasa{sv}av)", IC_STR_NULL, 0, &types, &repr, &children);
+       value = g_variant_new("(sasasa{sv}av)", IC_STR_NULL, &ifaces, &types, &repr, &children);
 
        return value;
 }
@@ -191,12 +193,11 @@ static GVariant* _icl_representation_empty_gvariant(void)
 GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
 {
        GList *node;
-       int ifaces = 0;
        const char *uri_path;
        GVariant *value, *child;
        iotcon_state_h state;
        GVariantBuilder *repr_gvar = NULL;
-       GVariantBuilder children, resource_types;
+       GVariantBuilder children, resource_types, resource_ifaces;
 
        if (NULL == repr)
                return _icl_representation_empty_gvariant();
@@ -206,6 +207,7 @@ GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
 
        /* Resource Types & Interfaces */
        g_variant_builder_init(&resource_types, G_VARIANT_TYPE("as"));
+       g_variant_builder_init(&resource_ifaces, G_VARIANT_TYPE("as"));
 
        if (ICL_VISIBILITY_PROP & repr->visibility) {
                if (repr->res_types) {
@@ -213,7 +215,10 @@ GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
                                g_variant_builder_add(&resource_types, "s", node->data);
                }
 
-               ifaces = repr->interfaces;
+               if (repr->interfaces) {
+                       for (node = repr->interfaces->iface_list; node; node = node->next)
+                               g_variant_builder_add(&resource_ifaces, "s", node->data);
+               }
        }
 
        /* Representation */
@@ -230,7 +235,7 @@ GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
                g_variant_builder_add(&children, "v", child);
        }
 
-       value = g_variant_new("(siasa{sv}av)", uri_path, ifaces, &resource_types,
+       value = g_variant_new("(sasasa{sv}av)", uri_path, &resource_ifaces, &resource_types,
                        repr_gvar, &children);
 
        return value;
@@ -393,8 +398,8 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
        GVariant *child;
        iotcon_representation_h repr;
        iotcon_state_h state;
-       char *uri_path, *resource_type;
-       GVariantIter *children, *repr_gvar, *resource_types;
+       char *uri_path, *resource_type, *resource_iface;
+       GVariantIter *children, *repr_gvar, *resource_types, *resource_ifaces;
 
        ret = iotcon_representation_create(&repr);
        if (IOTCON_ERROR_NONE != ret) {
@@ -409,8 +414,8 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
                return NULL;
        }
 
-       g_variant_get(var, "(&siasa{sv}av)", &uri_path, &repr->interfaces,
-                       &resource_types, &repr_gvar, &children);
+       g_variant_get(var, "(&sasasa{sv}av)", &uri_path, &resource_ifaces, &resource_types,
+                       &repr_gvar, &children);
 
        /* uri path */
        if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
@@ -421,6 +426,7 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
                ret = iotcon_resource_types_create(&repr->res_types);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("iotcon_resource_types_create() Fail(%d)", ret);
+                       g_variant_iter_free(resource_ifaces);
                        g_variant_iter_free(resource_types);
                        g_variant_iter_free(children);
                        iotcon_state_destroy(state);
@@ -433,6 +439,23 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
        }
        g_variant_iter_free(resource_types);
 
+       /* resource ifaces */
+       if (g_variant_iter_n_children(resource_ifaces)) {
+               ret = iotcon_resource_interfaces_create(&repr->interfaces);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+                       g_variant_iter_free(resource_ifaces);
+                       g_variant_iter_free(children);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(repr);
+                       return NULL;
+               }
+
+               while (g_variant_iter_loop(resource_ifaces, "s", &resource_iface))
+                       iotcon_resource_interfaces_add(repr->interfaces, resource_iface);
+       }
+       g_variant_iter_free(resource_ifaces);
+
        /* attribute */
        icl_state_from_gvariant(state, repr_gvar);
 
index 9cf2d8f43502de56652e42908d8f11d9e47c334b..5cd3da8857898b68de1d489bee8c43bd78283047 100644 (file)
@@ -74,21 +74,21 @@ API int iotcon_query_get_resource_type(iotcon_query_h query,
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_query_get_interface(iotcon_query_h query, iotcon_interface_e *iface)
+API int iotcon_query_get_interface(iotcon_query_h query, char **resource_iface)
 {
-       char *iface_str = NULL;
+       char *iface;
 
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
 
-       iotcon_query_lookup(query, ICL_QUERY_KEY_INTERFACE, &iface_str);
-       if (NULL == iface_str) {
-               ERR("iface_str is NULL");
+       iotcon_query_lookup(query, ICL_QUERY_KEY_INTERFACE, &iface);
+       if (NULL == iface) {
+               ERR("iface is NULL");
                return IOTCON_ERROR_NO_DATA;
        }
 
-       *iface = atoi(iface_str);
+       *resource_iface = iface;
 
        return IOTCON_ERROR_NONE;
 }
@@ -123,12 +123,11 @@ API int iotcon_query_set_resource_type(iotcon_query_h query, const char *resourc
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_query_set_interface(iotcon_query_h query, iotcon_interface_e iface)
+API int iotcon_query_set_interface(iotcon_query_h query, const char *resource_iface)
 {
        int length_old = 0;
        int length_new = 0;
        char *value = NULL;
-       char iface_str[ICL_QUERY_LENGTH_MAX] = {0};
 
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
@@ -137,8 +136,8 @@ API int iotcon_query_set_interface(iotcon_query_h query, iotcon_interface_e ifac
        if (value)
                length_old = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(value) + 2;
 
-       snprintf(iface_str, sizeof(iface_str), "%d", iface);
-       length_new = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(iface_str) + 2;
+       if (resource_iface && *resource_iface)
+               length_new = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(resource_iface) + 2;
 
        if (ICL_QUERY_LENGTH_MAX < query->len - length_old + length_new) {
                ERR("Length of query is invalid.");
@@ -148,7 +147,7 @@ API int iotcon_query_set_interface(iotcon_query_h query, iotcon_interface_e ifac
        if (value)
                iotcon_query_remove(query, ICL_QUERY_KEY_INTERFACE);
 
-       iotcon_query_add(query, ICL_QUERY_KEY_INTERFACE, iface_str);
+       iotcon_query_add(query, ICL_QUERY_KEY_INTERFACE, resource_iface);
 
        return IOTCON_ERROR_NONE;
 }
index 9759ee7b95c4fdc711ee85b417488c8a4607ddb9..bfabe5b44ca2a14d05949f4710d0be7fe91c0c26 100644 (file)
@@ -28,6 +28,7 @@
 #include "icl-representation.h"
 #include "icl-remote-resource.h"
 #include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
 #include "icl-payload.h"
 
 #define ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL 3600 /* 60 min */
@@ -184,7 +185,7 @@ API int iotcon_remote_resource_create(const char *host_address,
                const char *uri_path,
                int properties,
                iotcon_resource_types_h resource_types,
-               int resource_ifs,
+               iotcon_resource_interfaces_h resource_ifaces,
                iotcon_remote_resource_h *resource_handle)
 {
        FN_CALL;
@@ -194,6 +195,7 @@ API int iotcon_remote_resource_create(const char *host_address,
        RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == resource_ifaces, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
 
        resource = calloc(1, sizeof(struct icl_remote_resource));
@@ -207,7 +209,7 @@ API int iotcon_remote_resource_create(const char *host_address,
        resource->uri_path = ic_utils_strdup(uri_path);
        resource->properties = properties;
        resource->types = icl_resource_types_ref(resource_types);
-       resource->ifaces = resource_ifs;
+       resource->ifaces = icl_resource_interfaces_ref(resource_ifaces);
        resource->ref_count = 1;
 
        *resource_handle = resource;
@@ -223,6 +225,7 @@ static void _icl_remote_resource_destroy(iotcon_remote_resource_h resource)
        free(resource->uri_path);
        free(resource->host_address);
        free(resource->device_id);
+       iotcon_resource_interfaces_destroy(resource->ifaces);
        iotcon_resource_types_destroy(resource->types);
 
        /* null COULD be allowed */
@@ -320,16 +323,20 @@ API int iotcon_remote_resource_clone(iotcon_remote_resource_h src,
                }
        }
 
-       if (src->types) {
-               ret = iotcon_resource_types_clone(src->types, &resource->types);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_resource_types_clone() Fail(%d)", ret);
-                       iotcon_remote_resource_destroy(resource);
-                       return ret;
-               }
+       ret = iotcon_resource_types_clone(src->types, &resource->types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_types_clone() Fail(%d)", ret);
+               iotcon_remote_resource_destroy(resource);
+               return ret;
+       }
+
+       ret = iotcon_resource_interfaces_clone(src->ifaces, &resource->ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_clone() Fail(%d)", ret);
+               iotcon_remote_resource_destroy(resource);
+               return ret;
        }
 
-       resource->ifaces = src->ifaces;
        resource->connectivity_type = src->connectivity_type;
 
        *dest = resource;
@@ -407,8 +414,9 @@ API int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
 }
 
 
+/* The content of the resource should not be freed by user. */
 API int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
-               int *ifaces)
+               iotcon_resource_interfaces_h *ifaces)
 {
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
@@ -468,14 +476,15 @@ static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *pay
 {
        int ret;
        iotcon_remote_resource_h resource;
-       GVariantIter *types_iter;
+       GVariantIter *types_iter, *ifaces_iter;
        char host_addr[PATH_MAX] = {0};
        iotcon_resource_types_h res_types;
-       char *uri_path, *device_id, *res_type, *addr;
-       int ifaces, properties, is_secure, port;
+       iotcon_resource_interfaces_h ifaces;
+       char *uri_path, *device_id, *res_type, *iface, *addr;
+       int properties, is_secure, port;
 
-       g_variant_get(payload, "(&s&siasib&si)", &uri_path, &device_id, &ifaces, &types_iter,
-                       &properties, &is_secure, &addr, &port);
+       g_variant_get(payload, "(&s&sasasib&si)", &uri_path, &device_id, &ifaces_iter,
+                       &types_iter, &properties, &is_secure, &addr, &port);
 
        switch (connectivity_type) {
        case IOTCON_CONNECTIVITY_IPV6:
@@ -498,10 +507,21 @@ static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *pay
        while (g_variant_iter_loop(types_iter, "s", &res_type))
                iotcon_resource_types_add(res_types, res_type);
 
+       ret = iotcon_resource_interfaces_create(&ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+               iotcon_resource_types_destroy(res_types);
+               return NULL;
+       }
+
+       while (g_variant_iter_loop(ifaces_iter, "s", &iface))
+               iotcon_resource_interfaces_add(ifaces, iface);
+
        ret = iotcon_remote_resource_create(host_addr, connectivity_type, uri_path,
                        properties, res_types, ifaces, &resource);
-       if (res_types)
-               iotcon_resource_types_destroy(res_types);
+
+       iotcon_resource_interfaces_destroy(ifaces);
+       iotcon_resource_types_destroy(res_types);
 
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_remote_resource_create() Fail");
index 46b931ba9e05a1ad411b2c90e0d0497b052aace1..48cdfc8dcf7fa9e9a5f8bf91cc57e22a835caa17 100644 (file)
@@ -37,7 +37,7 @@ struct icl_remote_resource {
        int properties;
        iotcon_options_h header_options;
        iotcon_resource_types_h types;
-       int ifaces;
+       iotcon_resource_interfaces_h ifaces;
        iotcon_connectivity_type_e connectivity_type;
        int64_t observe_handle;
        unsigned int observe_sub_id;
index f7fdac0db28525b31eaa6405ded27cc94da38734..b2a118d10e2244e7fb7ad5231f6ce681f3371e81 100644 (file)
@@ -26,6 +26,7 @@
 #include "icl.h"
 #include "icl-resource.h"
 #include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
 #include "icl-response.h"
 #include "icl-list.h"
 #include "icl-value.h"
@@ -80,6 +81,10 @@ API void iotcon_representation_destroy(iotcon_representation_h repr)
        /* (GDestroyNotify) : iotcon_representation_h is proper type than gpointer */
        g_list_free_full(repr->children, (GDestroyNotify)iotcon_representation_destroy);
 
+       /* null COULD be allowed */
+       if (repr->interfaces)
+               iotcon_resource_interfaces_destroy(repr->interfaces);
+
        /* null COULD be allowed */
        if (repr->res_types)
                iotcon_resource_types_destroy(repr->res_types);
@@ -150,7 +155,7 @@ API int iotcon_representation_set_resource_types(iotcon_representation_h repr,
 }
 
 API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
-               int *ifaces)
+               iotcon_resource_interfaces_h *ifaces)
 {
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
@@ -162,13 +167,16 @@ API int iotcon_representation_get_resource_interfaces(iotcon_representation_h re
 }
 
 API int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
-               int ifaces)
+               iotcon_resource_interfaces_h ifaces)
 {
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
-       RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || IC_INTERFACE_MAX < ifaces,
-                       IOTCON_ERROR_INVALID_PARAMETER);
+       if (ifaces)
+               ifaces = icl_resource_interfaces_ref(ifaces);
+
+       if (repr->interfaces)
+               iotcon_resource_interfaces_destroy(repr->interfaces);
 
        repr->interfaces = ifaces;
 
@@ -295,7 +303,8 @@ API int iotcon_representation_clone(const iotcon_representation_h src,
        FN_CALL;
        int ret;
        GList *node;
-       iotcon_resource_types_h list;
+       iotcon_resource_types_h types;
+       iotcon_resource_interfaces_h ifaces;
        iotcon_representation_h cloned_repr, copied_repr;
 
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
@@ -317,17 +326,24 @@ API int iotcon_representation_clone(const iotcon_representation_h src,
                }
        }
 
-       if (src->interfaces)
-               cloned_repr->interfaces = src->interfaces;
+       if (src->interfaces) {
+               ret = iotcon_resource_interfaces_clone(src->interfaces, &ifaces);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("iotcon_resource_interfaces_clone() Fail(%d)");
+                       iotcon_representation_destroy(cloned_repr);
+                       return ret;
+               }
+               cloned_repr->interfaces = ifaces;
+       }
 
        if (src->res_types) {
-               ret = iotcon_resource_types_clone(src->res_types, &list);
+               ret = iotcon_resource_types_clone(src->res_types, &types);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("iotcon_resource_types_clone() Fail");
                        iotcon_representation_destroy(cloned_repr);
                        return ret;
                }
-               cloned_repr->res_types = list;
+               cloned_repr->res_types = types;
        }
 
        if (src->children) {
index a862a319bc849828ca7047f4debe1f2cd91e7fd8..86a42f6a790854eac4323a4f2dd69f893568d274 100644 (file)
@@ -29,10 +29,10 @@ struct icl_state_s {
 struct icl_representation_s {
        char *uri_path;
        int ref_count;
-       int interfaces;
        int visibility;
        GList *children;
        iotcon_resource_types_h res_types;
+       iotcon_resource_interfaces_h interfaces;
        struct icl_state_s *state;
 };
 
diff --git a/lib/icl-resource-interfaces.c b/lib/icl-resource-interfaces.c
new file mode 100644 (file)
index 0000000..1b2c262
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ * 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 <string.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon-types.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-resource-interfaces.h"
+
+iotcon_resource_interfaces_h icl_resource_interfaces_ref(
+               iotcon_resource_interfaces_h ifaces)
+{
+       RETV_IF(NULL == ifaces, NULL);
+       RETV_IF(ifaces->ref_count <= 0, NULL);
+
+       ifaces->ref_count++;
+
+       return ifaces;
+}
+
+
+API int iotcon_resource_interfaces_create(iotcon_resource_interfaces_h *ret_ifaces)
+{
+       iotcon_resource_interfaces_h ifaces;
+
+       RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == ret_ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+
+       ifaces = calloc(1, sizeof(struct icl_resource_ifaces));
+       if (NULL == ifaces) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ifaces->ref_count = 1;
+
+       *ret_ifaces = ifaces;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_resource_interfaces_destroy(iotcon_resource_interfaces_h ifaces)
+{
+       RET_IF(NULL == ifaces);
+
+       ifaces->ref_count--;
+
+       if (0 == ifaces->ref_count) {
+               g_list_free_full(ifaces->iface_list, free);
+               free(ifaces);
+       }
+}
+
+
+static int _icl_resource_interfaces_strcmp(const void *a, const void *b)
+{
+       return strcmp(a, b);
+}
+
+
+static bool _icl_resource_interfaces_duplicate_check(iotcon_resource_interfaces_h ifaces,
+               const char *iface)
+{
+       GList *node = NULL;
+
+       RETV_IF(NULL == ifaces, false);
+       RETV_IF(NULL == iface, false);
+
+       node = g_list_find_custom(ifaces->iface_list, iface, _icl_resource_interfaces_strcmp);
+       if (NULL == node)
+               return false;
+
+       return true;
+}
+
+
+/* Duplicate strings are not allowed. */
+API int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces,
+               const char *iface)
+{
+       char *resource_iface;
+
+       RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Don't modify it. It is already set.");
+
+       if (true == _icl_resource_interfaces_duplicate_check(ifaces, iface)) {
+               ERR("%s is already contained.", iface);
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       resource_iface = strdup(iface);
+       if (NULL == resource_iface) {
+               ERR("strdup() Fail");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       ifaces->iface_list = g_list_append(ifaces->iface_list, resource_iface);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_interfaces_remove(iotcon_resource_interfaces_h ifaces,
+               const char *iface)
+{
+       GList *node;
+
+       RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Don't modify it. It is already set.");
+
+       node = g_list_find_custom(ifaces->iface_list, iface, _icl_resource_interfaces_strcmp);
+       if (NULL == node) {
+               ERR("g_list_find_custom() Fail");
+               return IOTCON_ERROR_NO_DATA;
+       }
+
+       ifaces->iface_list = g_list_delete_link(ifaces->iface_list, node);
+       free(node->data);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_interfaces_foreach(iotcon_resource_interfaces_h ifaces,
+               iotcon_resource_interfaces_foreach_cb cb, void *user_data)
+{
+       GList *node;
+
+       RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       for (node = ifaces->iface_list; node; node = node->next) {
+               if (IOTCON_FUNC_STOP == cb((const char*)node->data, user_data))
+                       break;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_interfaces_clone(iotcon_resource_interfaces_h src,
+               iotcon_resource_interfaces_h *dest)
+{
+       GList *node;
+       char *resource_iface;
+       iotcon_resource_interfaces_h resource_ifaces;
+
+       RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
+       RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+       resource_ifaces = calloc(1, sizeof(struct icl_resource_ifaces));
+       if (NULL == resource_ifaces) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       for (node = src->iface_list; node; node = node->next) {
+               resource_iface = ic_utils_strdup(node->data);
+               if (NULL == resource_iface) {
+                       iotcon_resource_interfaces_destroy(resource_ifaces);
+                       ERR("ic_utils_strdup() Fail");
+                       return IOTCON_ERROR_OUT_OF_MEMORY;
+               }
+               resource_ifaces->iface_list = g_list_append(resource_ifaces->iface_list,
+                               resource_iface);
+       }
+
+       resource_ifaces->ref_count = 1;
+
+       *dest = resource_ifaces;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* counting from 0 */
+const char* icl_resource_interfaces_get_nth_data(iotcon_resource_interfaces_h ifaces,
+               int index)
+{
+       return g_list_nth_data(ifaces->iface_list, index);
+}
+
+
+unsigned int icl_resource_interfaces_get_length(iotcon_resource_interfaces_h ifaces)
+{
+       return g_list_length(ifaces->iface_list);
+}
diff --git a/lib/icl-resource-interfaces.h b/lib/icl-resource-interfaces.h
new file mode 100644 (file)
index 0000000..251ddba
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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_RESOURCE_INTERFACES_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__
+
+#include <glib.h>
+#include "iotcon-types.h"
+
+struct icl_resource_ifaces {
+       int ref_count;
+       GList *iface_list;
+};
+
+iotcon_resource_interfaces_h icl_resource_interfaces_ref(
+               iotcon_resource_interfaces_h res_ifaces);
+const char* icl_resource_interfaces_get_nth_data(iotcon_resource_interfaces_h res_ifaces,
+               int index);
+unsigned int icl_resource_interfaces_get_length(iotcon_resource_interfaces_h res_ifaces);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__ */
index 41844fec86648486d1fc52ee804252780abb70c8..c2887822ccbc4db7d0bd3b342560b4490b9a3f37 100644 (file)
@@ -141,8 +141,8 @@ API int iotcon_resource_types_remove(iotcon_resource_types_h types, const char *
                return IOTCON_ERROR_NO_DATA;
        }
 
-       free(found_node->data);
        types->type_list = g_list_delete_link(types->type_list, found_node);
+       free(found_node->data);
 
        return IOTCON_ERROR_NONE;
 }
index 04deb2eb79e147b9e01395e49f3d1cea33a1cbfa..0d9b35f78a773c0a6a671eff069514783b560a50 100644 (file)
@@ -29,6 +29,7 @@
 #include "icl-request.h"
 #include "icl-dbus-type.h"
 #include "icl-resource-types.h"
+#include "icl-resource-interfaces.h"
 #include "icl-resource.h"
 #include "icl-payload.h"
 
@@ -141,6 +142,7 @@ static void _icl_resource_conn_cleanup(iotcon_resource_h resource)
                return;
        }
 
+       iotcon_resource_interfaces_destroy(resource->ifaces);
        iotcon_resource_types_destroy(resource->types);
        if (resource->observers)
                iotcon_observers_destroy(resource->observers);
@@ -152,7 +154,7 @@ static void _icl_resource_conn_cleanup(iotcon_resource_h resource)
 /* The length of uri_path should be less than or equal to 36. */
 API int iotcon_resource_create(const char *uri_path,
                iotcon_resource_types_h res_types,
-               int ifaces,
+               iotcon_resource_interfaces_h ifaces,
                int properties,
                iotcon_request_handler_cb cb,
                void *user_data,
@@ -160,7 +162,7 @@ API int iotcon_resource_create(const char *uri_path,
 {
        int ret;
        unsigned int sub_id;
-       const gchar **types;
+       const gchar **type_array, **iface_array;
        GError *error = NULL;
        iotcon_resource_h resource;
        int64_t signal_number;
@@ -172,6 +174,7 @@ API int iotcon_resource_create(const char *uri_path,
        RETVM_IF(ICL_URI_PATH_LENGTH_MAX < strlen(uri_path),
                        IOTCON_ERROR_INVALID_PARAMETER, "Invalid uri_path(%s)", uri_path);
        RETV_IF(NULL == res_types, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
 
@@ -181,24 +184,34 @@ API int iotcon_resource_create(const char *uri_path,
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       types = icl_dbus_resource_types_to_array(res_types);
-       if (NULL == types) {
+       type_array = icl_dbus_resource_types_to_array(res_types);
+       if (NULL == type_array) {
                ERR("icl_dbus_resource_types_to_array() Fail");
                free(resource);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, ifaces,
+       iface_array = icl_dbus_resource_interfaces_to_array(ifaces);
+       if (NULL == iface_array) {
+               ERR("icl_dbus_resource_interfaces_to_array() Fail");
+               free(type_array);
+               free(resource);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, type_array, iface_array,
                        properties, false, &signal_number, &(resource->handle), NULL, &error);
        if (error) {
                ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
                ret = icl_dbus_convert_dbus_error(error->code);
                g_error_free(error);
-               free(types);
+               free(iface_array);
+               free(type_array);
                free(resource);
                return ret;
        }
-       free(types);
+       free(iface_array);
+       free(type_array);
 
        if (0 == resource->handle) {
                ERR("iotcon-daemon Fail");
@@ -209,9 +222,9 @@ API int iotcon_resource_create(const char *uri_path,
        resource->cb = cb;
        resource->user_data = user_data;
 
-       resource->types = icl_resource_types_ref(res_types);
        resource->uri_path = ic_utils_strdup(uri_path);
-       resource->ifaces = ifaces;
+       resource->types = icl_resource_types_ref(res_types);
+       resource->ifaces = icl_resource_interfaces_ref(ifaces);
        resource->properties = properties;
 
        snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
@@ -221,7 +234,8 @@ API int iotcon_resource_create(const char *uri_path,
                        _icl_request_handler);
        if (0 == sub_id) {
                ERR("icl_dbus_subscribe_signal() Fail");
-               iotcon_resource_types_destroy(res_types);
+               iotcon_resource_interfaces_destroy(resource->ifaces);
+               iotcon_resource_types_destroy(resource->types);
                free(resource->uri_path);
                free(resource);
                return IOTCON_ERROR_DBUS;
@@ -246,6 +260,7 @@ API int iotcon_resource_destroy(iotcon_resource_h resource)
 
        if (0 == resource->handle) { /* iotcon dbus disconnected */
                WARN("Invalid Resource handle");
+               iotcon_resource_interfaces_destroy(resource->ifaces);
                iotcon_resource_types_destroy(resource->types);
                if (resource->observers)
                        iotcon_observers_destroy(resource->observers);
@@ -276,24 +291,33 @@ API int iotcon_resource_destroy(iotcon_resource_h resource)
 }
 
 
-API int iotcon_resource_bind_interface(iotcon_resource_h resource,
-               iotcon_interface_e iface)
+API int iotcon_resource_bind_interface(iotcon_resource_h resource, const char *iface)
 {
        FN_CALL;
        int ret;
        GError *error = NULL;
+       iotcon_resource_interfaces_h resource_ifaces;
 
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
        if (0 == resource->sub_id) {
                ERR("Invalid Resource handle");
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       if (resource->ifaces & iface) {
-               ERR("iface(%d) is already contained.", iface);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = iotcon_resource_interfaces_clone(resource->ifaces, &resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_clone() Fail(%d)", ret);
+               return ret;
+       }
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, iface);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               return ret;
        }
 
        ic_dbus_call_bind_interface_sync(icl_dbus_get_object(), resource->handle,
@@ -302,14 +326,18 @@ API int iotcon_resource_bind_interface(iotcon_resource_h resource,
                ERR("ic_dbus_call_bind_interface_sync() Fail(%s)", error->message);
                ret = icl_dbus_convert_dbus_error(error->code);
                g_error_free(error);
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                return ret;
        }
 
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon-daemon Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                return icl_dbus_convert_daemon_error(ret);
        }
-       resource->ifaces |= iface;
+
+       iotcon_resource_interfaces_destroy(resource->ifaces);
+       resource->ifaces = resource_ifaces;
 
        return ret;
 }
@@ -541,7 +569,8 @@ API int iotcon_resource_get_types(iotcon_resource_h resource,
 }
 
 
-API int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces)
+API int iotcon_resource_get_interfaces(iotcon_resource_h resource,
+               iotcon_resource_interfaces_h *ifaces)
 {
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
index a9aac205db4935f22f42d778305e6fa22c941d1e..97e55cbfcac261f3f1436f01aa19236b15fa8773 100644 (file)
@@ -37,7 +37,7 @@
 #define ICL_URI_PATH_LENGTH_MAX 36
 
 struct icl_notify_msg {
-       iotcon_interface_e iface;
+       char *iface;
        iotcon_representation_h repr;
 };
 
@@ -45,7 +45,7 @@ struct icl_resource {
        char *uri_path;
        int properties;
        iotcon_resource_types_h types;
-       int ifaces;
+       iotcon_resource_interfaces_h ifaces;
        iotcon_request_handler_cb cb;
        void *user_data;
        unsigned int sub_id;
index 5ea164ca6e742c9f645f0d53ef617d46fce8127d..a4b6d829ad17ecfb01e4beb7c4e25edead4f7c35 100644 (file)
@@ -63,6 +63,8 @@ API void iotcon_response_destroy(iotcon_response_h resp)
                iotcon_representation_destroy(resp->repr);
        if (resp->header_options)
                iotcon_options_destroy(resp->header_options);
+       if (resp->iface)
+               free(resp->iface);
        free(resp);
 }
 
@@ -121,13 +123,15 @@ API int iotcon_response_set_result(iotcon_response_h resp,
 }
 
 
-API int iotcon_response_set_representation(iotcon_response_h resp,
-               iotcon_interface_e iface, iotcon_representation_h repr)
+API int iotcon_response_set_representation(iotcon_response_h resp, const char *iface,
+               iotcon_representation_h repr)
 {
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
 
-       resp->iface = iface;
+       free(resp->iface);
+       resp->iface = strdup(iface);
 
        if (repr)
                repr = icl_representation_ref(repr);
@@ -161,24 +165,12 @@ API int iotcon_response_set_options(iotcon_response_h resp,
 static bool _icl_response_representation_child_cb(iotcon_representation_h child,
                void *user_data)
 {
-       int iface = GPOINTER_TO_INT(user_data);
+       char *iface = user_data;
 
-       switch (iface) {
-       case IOTCON_INTERFACE_BATCH:
+       if (IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_BATCH, iface))
                child->visibility = ICL_VISIBILITY_REPR;
-               break;
-       case IOTCON_INTERFACE_NONE:
-       case IOTCON_INTERFACE_DEFAULT:
-       case IOTCON_INTERFACE_LINK:
-       case IOTCON_INTERFACE_GROUP:
+       else
                child->visibility = ICL_VISIBILITY_PROP;
-               break;
-       case IOTCON_INTERFACE_READONLY:
-       default:
-               WARN("Invalid interface type(%d)", iface);
-               child->visibility = ICL_VISIBILITY_PROP;
-               break;
-       }
 
        return IOTCON_FUNC_CONTINUE;
 }
@@ -194,27 +186,16 @@ static int _icl_response_check_representation_visibility(iotcon_response_h resp)
 
        iotcon_representation_h first = resp->repr;
 
-       DBG("interface type of response : %d", resp->iface);
+       DBG("interface type of response : %s", resp->iface);
 
-       switch (resp->iface) {
-       case IOTCON_INTERFACE_NONE:
-       case IOTCON_INTERFACE_DEFAULT:
-       case IOTCON_INTERFACE_GROUP:
-               first->visibility = ICL_VISIBILITY_REPR;
-               break;
-       case IOTCON_INTERFACE_LINK:
-       case IOTCON_INTERFACE_BATCH:
+       if (IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_LINK, resp->iface)
+                       || IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_BATCH, resp->iface))
                first->visibility = ICL_VISIBILITY_NONE;
-               break;
-       case IOTCON_INTERFACE_READONLY:
-       default:
-               WARN("Invalid interface type(%d)", resp->iface);
+       else
                first->visibility = ICL_VISIBILITY_REPR;
-               break;
-       }
 
        ret = iotcon_representation_foreach_children(first,
-                       _icl_response_representation_child_cb, GINT_TO_POINTER(resp->iface));
+                       _icl_response_representation_child_cb, resp->iface);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_representation_foreach_children() Fail(%d)", ret);
                return ret;
index 403db656f8a9db3a0b1b0e39d20e2a96259f5f4f..f447cbd7da1fb617334e440bc4bb2cb85b9e000c 100644 (file)
@@ -28,7 +28,7 @@ typedef enum {
 
 struct icl_resource_response {
        iotcon_options_h header_options;
-       iotcon_interface_e iface;
+       char *iface;
        int result;
        iotcon_representation_h repr;
        int64_t oic_request_h;
index b1eb6b7aa8d2086a37ae6c2885301e8ae66861c4..f25d397af5f49b5aaa75e48b84a611e1ff5ca7e2 100644 (file)
  */
 #define IOTCON_FUNC_CONTINUE true
 
+/**
+ * @brief Default Interface
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_DEFAULT "oic.if.baseline"
+
+/**
+ * @brief List Links Interface which is used to list the references to other resources contained in a resource
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_LINK "oic.if.ll"
+
+/**
+ * @brief Batch Interface which is used to manipulate (GET, PUT, POST, DELETE) on other resource contained in a resource
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_BATCH "oic.if.b"
+
+/**
+ * @brief Group Interface which is used to manipulate (GET, PUT, POST) a group of remote resources
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_GROUP "oic.mi.grp"
+
+/**
+ * @brief Read-Only Interface which is used to limit the methods that can be applied to a resource to GET only
+ *
+ * @since_tizen 3.0
+ */
+#define IOTCON_INTERFACE_READONLY "oic.if.r"
+
 /**
  * @brief Enumeration for type of observation.
  *
@@ -70,20 +105,6 @@ typedef enum {
        IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER = 1 /**< Indicates observation request for all notifications including stale notifications */
 } iotcon_observe_policy_e;
 
-/**
- * @brief Enumeration for type of interfaces which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-typedef enum {
-       IOTCON_INTERFACE_NONE = 0, /**< Indicates interface not specified or uninitialized */
-       IOTCON_INTERFACE_DEFAULT = (1 << 0), /**< Indicates interface for default */
-       IOTCON_INTERFACE_LINK = (1 << 1), /**< Indicates interface which is used to list the references to other resources contained in a resource */
-       IOTCON_INTERFACE_BATCH = (1 << 2), /**< Indicates interface which is used to manipulate (GET, PUT, POST, DELETE) on other resources contained in a resource */
-       IOTCON_INTERFACE_GROUP = (1 << 3), /**< Indicates interface which is used to manipulate (GET, PUT, POST) a group of remote resources */
-       IOTCON_INTERFACE_READONLY = (1 << 4), /**< Indicates interface which is used to limit the methods that can be applied to a resource to GET only */
-} iotcon_interface_e;
-
 /**
  * @brief Enumeration for of connectivities which can be held in a resource.
  *
index af874a474f20bb665a4e8de9a191247e84ce79f1..1e974afd4f15fcb95072c365eedb659a989fe829 100644 (file)
@@ -173,12 +173,14 @@ int iotcon_query_get_resource_type(iotcon_query_h query, char **resource_type);
 
 /**
  * @brief Gets resource interface from the query.
- * @details @a iface could be one of #iotcon_interface_e.
  *
  * @since_tizen 3.0
  *
+ * @remarks @a resource_iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ * @remarks @a resource_iface must not be released using free().
+ *
  * @param[in] query The handle of the query
- * @param[out] iface Found interface from query
+ * @param[out] resource_iface Found resource interface from query
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
@@ -192,7 +194,7 @@ int iotcon_query_get_resource_type(iotcon_query_h query, char **resource_type);
  * @see iotcon_query_remove()
  * @see iotcon_query_set_interface()
  */
-int iotcon_query_get_interface(iotcon_query_h query, iotcon_interface_e *iface);
+int iotcon_query_get_interface(iotcon_query_h query, char **resource_iface);
 
 /**
  * @brief Sets the resource type into the query.
@@ -218,12 +220,14 @@ int iotcon_query_get_interface(iotcon_query_h query, iotcon_interface_e *iface);
 int iotcon_query_set_resource_type(iotcon_query_h query, const char *resource_type);
 
 /**
- * @brief Sets the interface into the query.
+ * @brief Sets the resource interface into the query.
  *
  * @since_tizen 3.0
  *
+ * @remarks @a resource_iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
  * @param[in] query The handle of the query
- * @param[in] iface The interface to add into the query
+ * @param[in] resource_iface The resource interface to add into the query
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
@@ -238,7 +242,7 @@ int iotcon_query_set_resource_type(iotcon_query_h query, const char *resource_ty
  * @see iotcon_query_lookup()
  * @see iotcon_query_get_interface()
  */
-int iotcon_query_set_interface(iotcon_query_h query, iotcon_interface_e iface);
+int iotcon_query_set_interface(iotcon_query_h query, const char *resource_iface);
 
 /**
  * @brief Adds a new key and correspoding value into the query.
index 7ffd827b08e41e7b559387acca4edb59c33eaddc..a4ce0e166a239d842c4e84353f3179e117ecfd8f 100644 (file)
@@ -114,8 +114,6 @@ static void _find_light_resource()
  * If not, you should discover the resource object manually.\n
  * The @a properties can contain multiple properties like
  * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.\n
- * The @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
  *
  * @since_tizen 3.0
  *
@@ -126,9 +124,8 @@ static void _find_light_resource()
  * @param[in] connectivity_type The connectivity type
  * @param[in] uri_path The URI path of the resource
  * @param[in] properties The properties of the resource\n Set of #iotcon_resource_property_e
- * @param[in] resource_types The resource type of the resource. For example, "core.light"
- * @param[in] resource_ifaces The resource interfaces (whether it is collection etc)\n
- * Set of #iotcon_interface_e
+ * @param[in] resource_types The resource types of the resource. For example, "core.light"
+ * @param[in] resource_ifaces The resource interfaces of the resource.
  * @param[out] remote_resource Generated resource handle
  *
  * @return 0 on success, otherwise a negative error value.
@@ -147,7 +144,7 @@ int iotcon_remote_resource_create(const char *host_address,
                const char *uri_path,
                int properties,
                iotcon_resource_types_h resource_types,
-               int resource_ifaces,
+               iotcon_resource_interfaces_h resource_ifaces,
                iotcon_remote_resource_h *remote_resource);
 
 /**
@@ -698,13 +695,13 @@ int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
 
 /**
  * @brief Gets resource interfaces of the remote resource
- * @details @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
  *
  * @since_tizen 3.0
  *
+ * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
+ *
  * @param[in] resource The handle of the remote resource
- * @param[out] ifaces The resource interfaces of the remote resource\n Set of #iotcon_interface_e
+ * @param[out] ifaces The resource interfaces of the remote resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
@@ -719,7 +716,8 @@ int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
  * @see iotcon_remote_resource_get_properties()
  * @see iotcon_remote_resource_set_options()
  */
-int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource, int *ifaces);
+int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
+               iotcon_resource_interfaces_h *ifaces);
 
 /**
  * @brief Checks whether the remote resource is observable or not.
index 12c564730940077197fdb65e9de36d82c2cc9647..afd4caadb30ed89c0e9b5040bd258a01ed90adf2 100644 (file)
@@ -34,7 +34,7 @@
  * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_OVERVIEW Overview
  * The Iotcon Representation API provides data type of resp_repr handling.\n
  * A resp_repr is a payload of a request or a response.\n
- * It has uri_path, interface, list of resource types and its attributes.\n
+ * It has uri_path, list of resource interfaces, list of resource types and its attributes.\n
  * Attributes have capabilties to store and retrieve integer, boolean, double, string,
  * byte string, list, null, resp_repr.\n
  * A list is a container that includes number of datas of same type.\n
@@ -325,15 +325,15 @@ int iotcon_representation_get_resource_types(iotcon_representation_h repr,
                iotcon_resource_types_h *types);
 
 /**
- * @brief Sets interfaces to the representation.
- * @details If you set new interfaces, current interfaces value will be replaced with @a ifaces.\n
- * @a ifaces can be consist of multiple interface like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
+ * @brief Sets list of resource interfaces to the representation.
  *
  * @since_tizen 3.0
  *
+ * @remarks Stored list is replaced with @a ifaces. If @a ifaces is NULL, stored list is set
+ * by NULL.
+ *
  * @param[in] repr The representation handle
- * @param[in] ifaces The interfaces to set\n Set of #iotcon_interface_e
+ * @param[in] ifaces The list of resource interfaces
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
@@ -341,24 +341,25 @@ int iotcon_representation_get_resource_types(iotcon_representation_h repr,
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  */
 int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
-               int ifaces);
+               iotcon_resource_interfaces_h ifaces);
 
 /**
- * @brief Gets resource interfaces from the representation.
- * @details @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
+ * @brief Gets list of resource interfaces from the representation.
  *
  * @since_tizen 3.0
  *
+ * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
+ *
  * @param[in] repr The representation handle
- * @param[out] ifaces The interfaces to get\n Set of #iotcon_interface_e
+ * @param[out] ifaces The list of resource interfaces to get
  *
- * @return Interfaces to get. Interfaces may contain multiple interfaces.
- * @retval #IOTCON_INTERFACE_NONE  Not set
- * @retval Bitwise OR value which consists of iotcon_interface_e items
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  */
 int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
-               int *ifaces);
+               iotcon_resource_interfaces_h *ifaces);
 
 /**
  * @brief Sets a new state handle into the representation.
diff --git a/lib/include/iotcon-resource-interfaces.h b/lib/include/iotcon-resource-interfaces.h
new file mode 100644 (file)
index 0000000..272bbe8
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+ * 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_STRUCT_RESOURCE_INTERFACES_H__
+#define __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__
+
+#include <iotcon-types.h>
+
+/**
+ * @file iotcon-resource-interfaces.h
+ */
+
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
+ * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE Resource Interfaces
+ *
+ * @brief Iotcon Resource Interfaces provides API to manage resource interfaces.
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_HEADER Required Header
+ *  \#include <iotcon.h>
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_OVERVIEW Overview
+ * The iotcon resource interfaces API provides methods for managing handle and add, remove resource interfaces.
+ * A resource interface indicates a class or category of resources.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+               void *user_data)
+{
+       // handle request
+       ...
+}
+
+static void _create_light_resource()
+{
+       int ret;
+       iotcon_resource_h resource = NULL;
+       iotcon_resource_interfaces_h resource_ifaces = NULL;
+       iotcon_resource_interfaces_h resource_types = NULL;
+
+       ret = iotcon_resource_types_create(&resource_types);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
+
+       ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_interfaces_create(&resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret)
+               iotcon_resource_types_destroy(resource_types);
+               return;
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces,
+                       IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       iotcon_resource_interfaces_destroy(resource_ifaces);
+       iotcon_resource_types_destroy(resource_types);
+}
+ * @endcode
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ *  - http://tizen.org/feature/iot.oic\n
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ * @{
+ */
+
+/**
+ * @brief Creates a new resource interfaces handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must destroy @a ifaces by calling iotcon_resource_interfaces_destroy()
+ * if @a ifaces is no longer needed.
+ *
+ * @param[out] ifaces A newly allocated list of resource ifaces handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_remove()
+ * @see iotcon_resource_interfaces_clone()
+ */
+int iotcon_resource_interfaces_create(iotcon_resource_interfaces_h *ifaces);
+
+/**
+ * @brief Destroys a resource ifaces handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] ifaces The handle of the resource ifaces
+ *
+ * @return void
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_remove()
+ * @see iotcon_resource_interfaces_clone()
+ */
+void iotcon_resource_interfaces_destroy(iotcon_resource_interfaces_h ifaces);
+
+/**
+ * @brief Inserts a resource iface into the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
+ * @param[in] ifaces The handle of the resource ifaces
+ * @param[in] iface The string data to insert into the resource ifaces
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_remove()
+ * @see iotcon_resource_interfaces_clone()
+ */
+int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces,
+               const char *iface);
+
+/**
+ * @brief Delete a resource iface form the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
+ * @param[in] ifaces The handle of the resource ifaces
+ * @param[in] iface The string data to delete from the resource ifaces
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA  No data available
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_clone()
+ */
+int iotcon_resource_interfaces_remove(iotcon_resource_interfaces_h ifaces,
+               const char *iface);
+
+/**
+ * @brief Specifies the iface of function passed to iotcon_resource_interfaces_foreach()
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
+ * @param[in] iface The value of the resource ifaces
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return true to continue with the next iteration of the loop,
+ * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
+ * are more friendly values for the return.
+ *
+ * @pre iotcon_resource_interfaces_foreach() will invoke this callback function.
+ *
+ * @see iotcon_resource_interfaces_foreach()
+ */
+typedef bool (*iotcon_resource_interfaces_foreach_cb)(const char *iface, void *user_data);
+
+/**
+ * @brief Gets all of the resource ifaces of the list by invoking the callback function.
+ * @details iotcon_resource_interfaces_foreach_cb() will be called for each iface.\n
+ * If iotcon_resource_interfaces_foreach_cb() returns false, iteration will be stop.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] ifaces The handle of resource ifaces
+ * @param[in] cb The callback function to get data
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @post iotcon_resource_interfaces_foreach() will be called for each iface.
+ *
+ * @see iotcon_resource_interfaces_foreach_cb()
+ */
+int iotcon_resource_interfaces_foreach(iotcon_resource_interfaces_h ifaces,
+               iotcon_resource_interfaces_foreach_cb cb, void *user_data);
+
+/**
+ * @brief Clones the resource ifaces handle.
+ * @details Makes a deep copy of a source list of resource ifaces.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must @a destroy dest by calling iotcon_resource_interfaces_destroy()
+ * if @a dest is no longer needed.
+ *
+ * @param[in] src The origin handle of the resource ifaces
+ * @param[out] dest Clone of a source list of resource ifaces
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED  Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @see iotcon_resource_interfaces_create()
+ * @see iotcon_resource_interfaces_destroy()
+ * @see iotcon_resource_interfaces_add()
+ * @see iotcon_resource_interfaces_remove()
+ */
+int iotcon_resource_interfaces_clone(iotcon_resource_interfaces_h src,
+               iotcon_resource_interfaces_h *dest);
+
+/**
+ * @}
+ */
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__ */
index 2251078498c8b23d6b62c879d86c6f75dca63205..7b0e81055539e79dbb3d88e96892a283d2488cea 100644 (file)
@@ -49,7 +49,8 @@ static void _create_light_resource()
 {
        int ret;
        iotcon_resource_h resource = NULL;
-       iotcon_resource_types_h resource_types = NULL;
+       iotcon_resource_interfaces_h resource_ifaces = NULL;
+       iotcon_resource_interfaces_h resource_types = NULL;
 
        ret = iotcon_resource_types_create(&resource_types);
        if (IOTCON_ERROR_NONE != ret)
@@ -61,13 +62,27 @@ static void _create_light_resource()
                return;
        }
 
-       ret = iotcon_resource_create("/light/1", resource_types, IOTCON_INTERFACE_DEFAULT,
+       ret = iotcon_resource_interfaces_create(&resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret)
+               iotcon_resource_types_destroy(resource_types);
+               return;
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces,
                        IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource);
        if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                iotcon_resource_types_destroy(resource_types);
                return;
        }
 
+       iotcon_resource_interfaces_destroy(resource_ifaces);
        iotcon_resource_types_destroy(resource_types);
 }
  * @endcode
index d58badabe34d21cadee40c9e00fbebca8dab1e75..13a4b1345afa6130967dd06447f29ff73e546d73 100644 (file)
@@ -55,13 +55,12 @@ static void _door_request_handler(iotcon_resource_h resource, iotcon_request_h r
 static void _create_resource()
 {
        int ret;
-       int ifaces;
        int properties;
-       iotcon_resource_types_h resource_types = NULL;
+       iotcon_resource_interfaces_h resource_ifaces = NULL;
+       iotcon_resource_interfaces_h resource_types = NULL;
        iotcon_resource_h resource_door = NULL;
 
        // 1. create room resource
-       ifaces = IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH;
        properties = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE;
 
        ret = iotcon_resource_types_create(&resource_types);
@@ -74,16 +73,43 @@ static void _create_resource()
                return;
        }
 
-       ret = iotcon_resource_create("/room/1", resource_types, ifaces,
+       ret = iotcon_resource_interfaces_create(&resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret)
+               iotcon_resource_types_destroy(resource_types);
+               return;
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_LINK);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_BATCH);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               return;
+       }
+
+       ret = iotcon_resource_create("/room/1", resource_types, resource_ifaces,
                        properties, _room_request_handler, NULL, &_resource_room);
        if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                iotcon_resource_types_destroy(resource_types);
                return;
        }
+       iotcon_resource_interfaces_destroy(resource_ifaces);
        iotcon_resource_types_destroy(resource_types);
 
        // 2. create door resource
-       ifaces = IOTCON_INTERFACE_DEFAULT;
        properties = IOTCON_RESOURCE_OBSERVABLE;
 
        ret = iotcon_resource_types_create(&resource_types);
@@ -101,14 +127,30 @@ static void _create_resource()
                return;
        }
 
-       ret = iotcon_resource_create("/door/1", resource_types, ifaces,
+       ret = iotcon_resource_interfaces_create(&resource_ifaces);
+       if (IOTCON_ERROR_NONE != ret)
+               iotcon_resource_types_destroy(resource_types);
+               iotcon_resource_destroy(_resource_room);
+               return;
+
+       ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
+               iotcon_resource_types_destroy(resource_types);
+               iotcon_resource_destroy(_resource_room);
+               return;
+       }
+
+       ret = iotcon_resource_create("/door/1", resource_types, resource_ifaces,
                        properties, _door_request_handler, NULL, &resource_door);
        if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_interfaces_destroy(resource_ifaces);
                iotcon_resource_types_destroy(resource_types);
                iotcon_resource_destroy(_resource_room);
                _resource_room = NULL;
                return;
        }
+       iotcon_resource_interfaces_destroy(resource_ifaces);
        iotcon_resource_types_destroy(resource_types);
 
        // 3. bind door resouce to room resource
@@ -164,8 +206,8 @@ typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
  * @a uri_path format would be relative URI path like '/a/light'\n
  * @a res_types is a list of resource types. Create a iotcon_resource_types_h handle and
  * add types string to it.\n
- * @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.\n
+ * @a ifaces is a list of resource interfaces. Create a iotcon_resource_interfaces_h handle and
+ * add interfaces string to it.\n
  * @a properties also can contain multiple properties like
  * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.\n
  * iotcon_request_handler_cb() will be called when receive CRUD request to the registered
@@ -182,7 +224,7 @@ typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
  *
  * @param[in] uri_path The URI path of the resource
  * @param[in] res_types The list of type of the resource
- * @param[in] ifaces The interfaces of the resource\n Set of #iotcon_interface_e
+ * @param[in] ifaces The list of interface of the resource
  * @param[in] properties The properties of the resource\n Set of #iotcon_resource_property_e
  * @param[in] cb The request handler callback function
  * @param[in] user_data The user data to pass to the callback function
@@ -209,7 +251,7 @@ typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
  */
 int iotcon_resource_create(const char *uri_path,
                iotcon_resource_types_h res_types,
-               int ifaces,
+               iotcon_resource_interfaces_h ifaces,
                int properties,
                iotcon_request_handler_cb cb,
                void *user_data,
@@ -249,13 +291,12 @@ int iotcon_resource_destroy(iotcon_resource_h resource_handle);
 /**
  * @brief Binds an interface to the resource
  *
- * @details The @a iface could be one of #iotcon_interface_e.
  * @since_tizen 3.0
  * @privlevel public
  * @privilege %http://tizen.org/privilege/network.get
  * @privilege %http://tizen.org/privilege/d2d.datasharing
  *
- * @remarks Sets only one interface to @a iface. If not, @a iface will be ignored.
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
  *
  * @param[in] resource The handle of the resource
  * @param[in] iface The interface to be bound to the resource
@@ -276,7 +317,7 @@ int iotcon_resource_destroy(iotcon_resource_h resource_handle);
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
  */
-int iotcon_resource_bind_interface(iotcon_resource_h resource, iotcon_interface_e iface);
+int iotcon_resource_bind_interface(iotcon_resource_h resource, const char *iface);
 
 /**
  * @brief Binds a type to the resource
@@ -530,13 +571,13 @@ int iotcon_resource_get_types(iotcon_resource_h resource, iotcon_resource_types_
 
 /**
  * @brief Gets the interfaces of the resource
- * @a ifaces can contain multiple interfaces like
- * IOTCON_INTERFACE_LINK | IOTCON_INTERFACE_BATCH.
  *
  * @since_tizen 3.0
  *
+ * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
+ *
  * @param[in] resource The handle of the resource
- * @param[out] ifaces The interfaces of the resource\n Set of #iotcon_interface_e
+ * @param[out] ifaces The interfaces of the resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
@@ -549,7 +590,8 @@ int iotcon_resource_get_types(iotcon_resource_h resource, iotcon_resource_types_
  * @see iotcon_resource_get_types()
  * @see iotcon_resource_get_properties()
  */
-int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces);
+int iotcon_resource_get_interfaces(iotcon_resource_h resource,
+               iotcon_resource_interfaces_h *ifaces);
 
 /**
  * @brief Gets the properties in the resource
index b470dff21f09da6d83a52adaafd6d6d6161bb598..2fe8691801009473d49c8b02a19beda4788689f7 100644 (file)
@@ -106,7 +106,6 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
 {
        int ret;
        int types;
-       iotcon_interface_e iface = IOTCON_INTERFACE_DEFAULT;
        iotcon_query_h query = NULL;
 
        ret = iotcon_request_get_types(request, &types);
@@ -155,7 +154,7 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                        return;
                }
 
-               ret = iotcon_response_set_representation(response, iface, repr);
+               ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, repr);
                if (IOTCON_ERROR_NONE != ret) {
                        iotcon_representation_destroy(repr);
                        iotcon_response_destroy(response);
@@ -313,6 +312,8 @@ int iotcon_response_set_result(iotcon_response_h resp, iotcon_response_result_e
  *
  * @since_tizen 3.0
  *
+ * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
+ *
  * @param[in] resp The handle of the response
  * @param[in] iface The interface of the representation
  * @param[in] repr The representation of the response
@@ -326,8 +327,8 @@ int iotcon_response_set_result(iotcon_response_h resp, iotcon_response_result_e
  * @see iotcon_response_create()
  * @see iotcon_response_destroy()
  */
-int iotcon_response_set_representation(iotcon_response_h resp,
-               iotcon_interface_e iface, iotcon_representation_h repr);
+int iotcon_response_set_representation(iotcon_response_h resp, const char *iface,
+               iotcon_representation_h repr);
 
 /**
  * @brief Sets header options into the response
index b5e90a9262c058805d485c690fec86422da226f1..c3c90ea2c3034882f2e72de4818f10fe3d7ea562 100644 (file)
@@ -147,6 +147,15 @@ typedef struct icl_device_info* iotcon_device_info_h;
  */
 typedef struct icl_platform_info* iotcon_platform_info_h;
 
+/**
+ * @brief The handle of resource interface
+ * @details @a iotcon_resource_interfaces_h is an opaque data structure to have list
+ * of resource interfaces. A resource interface is datatype of string.
+ *
+ * @since_tizen 3.0
+ */
+typedef struct icl_resource_ifaces* iotcon_resource_interfaces_h;
+
 /**
  * @brief The handle of resource types
  * @details @a iotcon_resource_types_h is an opaque data structure to have list
@@ -219,5 +228,6 @@ typedef struct icl_state_s* iotcon_state_h;
 #include <iotcon-options.h>
 #include <iotcon-representation.h>
 #include <iotcon-resource-types.h>
+#include <iotcon-resource-interfaces.h>
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_TYPES_H__ */
index 0744053b0cf8fd4ea8ff218d9254de8d27354bc9..e2eb5aebaf29ea07d3606a749e980829d830f295 100644 (file)
@@ -113,12 +113,13 @@ static void _on_response_delete(iotcon_remote_resource_h resource,
 static void _on_response_post(iotcon_remote_resource_h resource,
                iotcon_response_h response, void *user_data)
 {
+       int ret;
        iotcon_state_h recv_state;
        char *host, *created_uri_path;
-       int ret, ifaces = 0;
        iotcon_connectivity_type_e connectivity_type;
        iotcon_response_result_e response_result;
        iotcon_resource_types_h types = NULL;
+       iotcon_resource_interfaces_h ifaces = NULL;
        iotcon_remote_resource_h new_door_resource;
        iotcon_representation_h recv_repr = NULL;
 
@@ -310,6 +311,15 @@ static void _on_response_get(iotcon_remote_resource_h resource,
        iotcon_representation_destroy(send_repr);
 }
 
+static bool _get_res_iface_cb(const char *string, void *user_data)
+{
+       char *resource_uri_path = user_data;
+
+       DBG("[%s] resource interface : %s", resource_uri_path, string);
+
+       return IOTCON_FUNC_CONTINUE;
+}
+
 static bool _get_res_type_cb(const char *string, void *user_data)
 {
        char *resource_uri_path = user_data;
@@ -404,13 +414,14 @@ static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
 static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
                void *user_data)
 {
+       int ret;
        GList *node;
        char *resource_host;
        char *resource_uri_path;
        char *resource_device_id;
        iotcon_presence_h presence_handle;
        iotcon_resource_types_h resource_types;
-       int ret, resource_interfaces;
+       iotcon_resource_interfaces_h resource_interfaces;
        iotcon_connectivity_type_e connectivity_type;
        iotcon_remote_resource_h resource_clone = NULL;
 
@@ -479,16 +490,15 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                free(door_resource_device_id);
                return;
        }
-       if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
-               DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_LINK & resource_interfaces)
-               DBG("[%s] resource interface : LINK_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_BATCH & resource_interfaces)
-               DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_GROUP & resource_interfaces)
-               DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_READONLY & resource_interfaces)
-               DBG("[%s] resource interface : READONLY_INTERFACE", resource_uri_path);
+
+       ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
+                       resource_uri_path);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+               free(door_resource_device_id);
+               return;
+       }
 
        /* get the resource types */
        ret = iotcon_remote_resource_get_types(resource, &resource_types);
index 3ba6de579841d3b93b706ee2c0d96bb58695e6d2..8c71dc2371de1d4ab6fc446b96308aa3c1f5a054 100644 (file)
@@ -30,7 +30,7 @@ typedef struct _door_resource_s {
        bool state;
        char *uri_path;
        char *type;
-       int ifaces;
+       iotcon_resource_interfaces_h ifaces;
        int properties;
        iotcon_resource_h handle;
        iotcon_observers_h observers;
@@ -61,12 +61,29 @@ static int _set_door_resource(door_resource_s *door)
                return -1;
        }
 
-       door->ifaces = IOTCON_INTERFACE_DEFAULT;
+       ret = iotcon_resource_interfaces_create(&door->ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+               free(door->type);
+               free(door->uri_path);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_add(door->ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(door->ifaces);
+               free(door->type);
+               free(door->uri_path);
+               return -1;
+       }
+
        door->properties = IOTCON_RESOURCE_DISCOVERABLE;
 
        ret = iotcon_observers_create(&door->observers);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_observers_create() Fail");
+               iotcon_resource_interfaces_destroy(door->ifaces);
                free(door->type);
                free(door->uri_path);
                return -1;
@@ -78,6 +95,7 @@ static int _set_door_resource(door_resource_s *door)
 static void _free_door_resource(door_resource_s *door)
 {
        iotcon_observers_destroy(door->observers);
+       iotcon_resource_interfaces_destroy(door->ifaces);
        free(door->type);
        free(door->uri_path);
 }
@@ -90,8 +108,8 @@ static void _check_door_state(door_resource_s door)
                INFO("[Door] opened.");
 }
 
-static iotcon_resource_h _create_door_resource(char *uri_path, char *type, int ifaces,
-               int properties, void *user_data)
+static iotcon_resource_h _create_door_resource(char *uri_path, char *type,
+               iotcon_resource_interfaces_h ifaces, int properties, void *user_data)
 {
        int ret;
        iotcon_resource_h handle;
@@ -354,7 +372,7 @@ static int _request_handler_post(door_resource_s *door, iotcon_request_h request
        }
 
        new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type,
-                       IOTCON_INTERFACE_DEFAULT, IOTCON_RESOURCE_NO_PROPERTY, door);
+                       door->ifaces, IOTCON_RESOURCE_NO_PROPERTY, door);
        if (NULL == new_door_handle) {
                ERR("_create_door_resource() Fail");
                return -1;
@@ -560,7 +578,13 @@ int main(int argc, char **argv)
        }
 
        /* add resource options */
-       my_door.ifaces |= IOTCON_INTERFACE_BATCH;
+       ret = iotcon_resource_interfaces_add(my_door.ifaces, IOTCON_INTERFACE_BATCH);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               _free_door_resource(&my_door);
+               iotcon_disconnect();
+               return -1;
+       }
        my_door.properties |= IOTCON_RESOURCE_OBSERVABLE;
 
        /* add presence */
index b4d78aecd550b97f55ebe8b7b2d36e2c41424b62..84f74bba171c63ef784f135398e9f0848d1af37e 100644 (file)
@@ -25,6 +25,15 @@ static GList *device_id_list;
 
 #define DOOR_RESOURCE_TYPE "org.tizen.door"
 
+static bool _get_res_iface_cb(const char *string, void *user_data)
+{
+       char *resource_uri_path = user_data;
+
+       DBG("[%s] resource interface : %s", resource_uri_path, string);
+
+       return IOTCON_FUNC_CONTINUE;
+}
+
 static bool _get_res_type_cb(const char *string, void *user_data)
 {
        char *resource_uri_path = user_data;
@@ -92,11 +101,12 @@ static void _representation_changed_cb(iotcon_remote_resource_h resource,
 static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
                void *user_data)
 {
+       int ret;
        GList *node;
        char *resource_host;
        char *resource_uri_path;
        char *resource_device_id;
-       int ret, resource_interfaces;
+       iotcon_resource_interfaces_h resource_interfaces;
        iotcon_resource_types_h resource_types;
        iotcon_remote_resource_h cloned_resource;
 
@@ -156,16 +166,15 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                free(door_resource_device_id);
                return;
        }
-       if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
-               DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_LINK & resource_interfaces)
-               DBG("[%s] resource interface : LINK_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_BATCH & resource_interfaces)
-               DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_GROUP & resource_interfaces)
-               DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_READONLY & resource_interfaces)
-               DBG("[%s] resource interface : READONLY_INTERFACE", resource_uri_path);
+
+       ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
+                       resource_uri_path);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+               free(door_resource_device_id);
+               return;
+       }
 
        /* get the resource types */
        ret = iotcon_remote_resource_get_types(resource, &resource_types);
index 4c172422014312661484c6ea2acb5a76630544c3..57defc91f251abd13df7c9f2c79338798a83f140 100644 (file)
@@ -246,7 +246,16 @@ static void _on_response_1st(iotcon_remote_resource_h resource,
        iotcon_query_destroy(query_params);
 }
 
-static bool _get_res_type_fn(const char *string, void *user_data)
+static bool _get_res_iface_cb(const char *string, void *user_data)
+{
+       char *resource_uri_path = user_data;
+
+       DBG("[%s] resource interface : %s", resource_uri_path, string);
+
+       return IOTCON_FUNC_CONTINUE;
+}
+
+static bool _get_res_type_cb(const char *string, void *user_data)
 {
        char *resource_uri_path = user_data;
 
@@ -263,11 +272,12 @@ static int _device_id_compare(const void *a, const void *b)
 static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
                void *user_data)
 {
+       int ret;
        GList *node;
        char *resource_host;
        char *resource_uri_path;
        char *resource_device_id;
-       int ret, resource_interfaces;
+       iotcon_resource_interfaces_h resource_interfaces;
        iotcon_resource_types_h resource_types;
        iotcon_remote_resource_h cloned_resource;
 
@@ -327,16 +337,15 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                free(room_resource_device_id);
                return;
        }
-       if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
-               DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_LINK & resource_interfaces)
-               DBG("[%s] resource interface : LINK_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_BATCH & resource_interfaces)
-               DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_GROUP & resource_interfaces)
-               DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
-       if (IOTCON_INTERFACE_READONLY & resource_interfaces)
-               DBG("[%s] resource interface : READONLY_INTERFACE", resource_uri_path);
+
+       ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
+                       resource_uri_path);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+               free(room_resource_device_id);
+               return;
+       }
 
        /* get the resource types */
        ret = iotcon_remote_resource_get_types(resource, &resource_types);
@@ -346,7 +355,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                free(room_resource_device_id);
                return;
        }
-       ret = iotcon_resource_types_foreach(resource_types, _get_res_type_fn,
+       ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
                        resource_uri_path);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
index 130a7b8cc7c9fc77827af38e845d861d59790c16..fcf1e689dd5084d1fd794f830e87fe5f5c43fb50 100644 (file)
@@ -32,7 +32,7 @@ typedef struct _light_resource_s {
        int brightness;
        char *uri_path;
        char *type;
-       int ifaces;
+       iotcon_resource_interfaces_h ifaces;
        int properties;
        iotcon_resource_h handle;
 } light_resource_s;
@@ -42,7 +42,7 @@ typedef struct _fan_resource_s {
        bool state;
        char *uri_path;
        char *type;
-       int ifaces;
+       iotcon_resource_interfaces_h ifaces;
        int properties;
        iotcon_resource_h handle;
 } fan_resource_s;
@@ -53,7 +53,7 @@ typedef struct _room_resource_s {
        int today_temp[5];
        char *uri_path;
        char *type;
-       int ifaces;
+       iotcon_resource_interfaces_h ifaces;
        int properties;
        iotcon_resource_h handle;
        light_resource_s *child_light;
@@ -62,6 +62,8 @@ typedef struct _room_resource_s {
 
 static int _set_room_resource(room_resource_s *room)
 {
+       int ret;
+
        room->name = strdup("Michael's Room");
        if (NULL == room->name) {
                ERR("strdup() Fail");
@@ -89,7 +91,35 @@ static int _set_room_resource(room_resource_s *room)
                return -1;
        }
 
-       room->ifaces = IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH;
+       ret = iotcon_resource_interfaces_create(&room->ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+               free(room->type);
+               free(room->uri_path);
+               free(room->name);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_add(room->ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(room->ifaces);
+               free(room->type);
+               free(room->uri_path);
+               free(room->name);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_add(room->ifaces, IOTCON_INTERFACE_BATCH);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(room->ifaces);
+               free(room->type);
+               free(room->uri_path);
+               free(room->name);
+               return -1;
+       }
+
        room->properties = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE;
 
        return 0;
@@ -97,6 +127,7 @@ static int _set_room_resource(room_resource_s *room)
 
 static void _free_room_resource(room_resource_s *room)
 {
+       iotcon_resource_interfaces_destroy(room->ifaces);
        free(room->type);
        free(room->uri_path);
        free(room->name);
@@ -104,6 +135,8 @@ static void _free_room_resource(room_resource_s *room)
 
 static int _set_light_resource(light_resource_s *light)
 {
+       int ret;
+
        light->brightness = 50;
 
        light->uri_path = strdup(LIGHT_RESOURCE_URI);
@@ -119,7 +152,23 @@ static int _set_light_resource(light_resource_s *light)
                return -1;
        }
 
-       light->ifaces = IOTCON_INTERFACE_DEFAULT;
+       ret = iotcon_resource_interfaces_create(&light->ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+               free(light->type);
+               free(light->uri_path);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_add(light->ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(light->ifaces);
+               free(light->type);
+               free(light->uri_path);
+               return -1;
+       }
+
        light->properties = IOTCON_RESOURCE_NO_PROPERTY;
 
        return 0;
@@ -127,12 +176,15 @@ static int _set_light_resource(light_resource_s *light)
 
 static void _free_light_resource(light_resource_s *light)
 {
+       iotcon_resource_interfaces_destroy(light->ifaces);
        free(light->type);
        free(light->uri_path);
 }
 
 static int _set_fan_resource(fan_resource_s *fan)
 {
+       int ret;
+
        fan->state = false;
 
        fan->uri_path = strdup(FAN_RESOURCE_URI);
@@ -148,7 +200,23 @@ static int _set_fan_resource(fan_resource_s *fan)
                return -1;
        }
 
-       fan->ifaces = IOTCON_INTERFACE_DEFAULT;
+       ret = iotcon_resource_interfaces_create(&fan->ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+               free(fan->type);
+               free(fan->uri_path);
+               return -1;
+       }
+
+       ret = iotcon_resource_interfaces_add(fan->ifaces, IOTCON_INTERFACE_DEFAULT);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+               iotcon_resource_interfaces_destroy(fan->ifaces);
+               free(fan->type);
+               free(fan->uri_path);
+               return -1;
+       }
+
        fan->properties = IOTCON_RESOURCE_NO_PROPERTY;
 
        return 0;
@@ -156,12 +224,17 @@ static int _set_fan_resource(fan_resource_s *fan)
 
 static void _free_fan_resource(fan_resource_s *fan)
 {
+       iotcon_resource_interfaces_destroy(fan->ifaces);
        free(fan->type);
        free(fan->uri_path);
 }
 
-static iotcon_resource_h _create_resource(char *uri_path, char *type, int ifaces,
-               int properties, iotcon_request_handler_cb cb, void *user_data)
+static iotcon_resource_h _create_resource(char *uri_path,
+               char *type,
+               iotcon_resource_interfaces_h ifaces,
+               int properties,
+               iotcon_request_handler_cb cb,
+               void *user_data)
 {
        int ret;
        iotcon_resource_h handle;
@@ -194,7 +267,7 @@ static iotcon_resource_h _create_resource(char *uri_path, char *type, int ifaces
 }
 
 static int _send_response(iotcon_request_h request, iotcon_representation_h repr,
-               iotcon_interface_e iface, iotcon_response_result_e result)
+               const char *iface, iotcon_response_result_e result)
 {
        int ret;
        iotcon_response_h response;
@@ -295,8 +368,7 @@ static int _light_request_handler_get(light_resource_s *light, iotcon_request_h
                return -1;
        }
 
-       ret = _send_response(request, repr, IOTCON_INTERFACE_DEFAULT,
-                       IOTCON_RESPONSE_OK);
+       ret = _send_response(request, repr, IOTCON_INTERFACE_DEFAULT, IOTCON_RESPONSE_OK);
        if (0 != ret) {
                ERR("_send_response() Fail(%d)", ret);
                iotcon_representation_destroy(repr);
@@ -548,7 +620,7 @@ static int _room_request_handler_get(room_resource_s *room, iotcon_request_h req
        int ret;
        iotcon_query_h query;
        iotcon_representation_h repr;
-       iotcon_interface_e iface = IOTCON_INTERFACE_DEFAULT;
+       char *iface = IOTCON_INTERFACE_DEFAULT;
 
        INFO("GET request - Room");
 
@@ -594,7 +666,7 @@ static void _light_request_handler(iotcon_resource_h resource, iotcon_request_h
        int ret;
        iotcon_request_type_e type;
        light_resource_s *light = user_data;
-       int iface = IOTCON_INTERFACE_DEFAULT;
+       char *iface = IOTCON_INTERFACE_DEFAULT;
 
        RET_IF(NULL == request);
 
@@ -620,7 +692,7 @@ static void _fan_request_handler(iotcon_resource_h resource, iotcon_request_h re
        int ret;
        iotcon_request_type_e type;
        fan_resource_s *fan = user_data;
-       int iface = IOTCON_INTERFACE_DEFAULT;
+       char *iface = IOTCON_INTERFACE_DEFAULT;
 
        RET_IF(NULL == request);
 
@@ -648,7 +720,7 @@ static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h r
        iotcon_request_type_e type;
        char *host_address;
        room_resource_s *room = user_data;
-       int iface = IOTCON_INTERFACE_DEFAULT;
+       char *iface = IOTCON_INTERFACE_DEFAULT;
 
        RET_IF(NULL == request);