Reinforce Struct & Get functions
authoryoungman <yman.jung@samsung.com>
Tue, 2 Jun 2015 03:40:19 +0000 (12:40 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 8 Jun 2015 10:41:30 +0000 (19:41 +0900)
Change-Id: Iefe066d3c9d96a4e20ec06bb86e1f71041f63904
Signed-off-by: youngman <yman.jung@samsung.com>
31 files changed:
lib/ic-client.c
lib/ic-client.h
lib/ic-device.c
lib/ic-device.h [deleted file]
lib/ic-ioty.cpp
lib/ic-ioty.h [changed mode: 0644->0755]
lib/ic-observation.c [changed mode: 0644->0755]
lib/ic-options.c
lib/ic-query.c
lib/ic-repr-obj.c
lib/ic-repr.c
lib/ic-repr.h
lib/ic-request.c
lib/ic-request.h
lib/ic-resource-types.c [new file with mode: 0755]
lib/ic-resource-types.h [new file with mode: 0755]
lib/ic-utils.c
lib/ic-utils.h [changed mode: 0644->0755]
lib/ic.c
lib/ic.h
lib/include/iotcon-constant.h
lib/include/iotcon-errors.h
lib/include/iotcon-representation.h
lib/include/iotcon-struct.h
lib/include/iotcon.h
test/crud-test-client.c
test/crud-test-server.c
test/device-test-client.c [changed mode: 0644->0755]
test/device-test-server.c [changed mode: 0644->0755]
test/repr-test-client.c [changed mode: 0644->0755]
test/repr-test-server.c [changed mode: 0644->0755]

index 745601102aa5a9636a7964b3a2874b49790b5a9a..ed2b156d5c4a3822e30d736d279d36057c9686a3 100755 (executable)
 #include "ic-utils.h"
 #include "ic-ioty.h"
 #include "ic-options.h"
+#include "ic-resource-types.h"
 #include "ic-client.h"
 
 /* host address should begin with "coap://"
- * The length of resource_type should be less than and equal to 61.
+ * The length of resource_type should be less than or equal to 61.
  * If resource_type is NULL, then All resources in host are discovered. */
 API int iotcon_find_resource(const char *host_addr, const char *resource_type,
                iotcon_found_resource_cb cb, void *user_data)
@@ -51,28 +52,16 @@ API int iotcon_find_resource(const char *host_addr, const char *resource_type,
 
 
 /* If you know the information of resource, then you can make a proxy of the resource. */
-API iotcon_client_h iotcon_client_new(const char *host,
-               const char *uri,
-               bool is_observable,
-               iotcon_str_list_s *resource_types,
-               iotcon_interface_e resource_ifs)
+API iotcon_client_h iotcon_client_new(const char *host, const char *uri,
+               bool is_observable, iotcon_resource_types_h resource_types, int resource_ifs)
 {
        FN_CALL;
-       int i;
        iotcon_client_h resource = NULL;
 
        RETV_IF(NULL == host, NULL);
        RETV_IF(NULL == uri, NULL);
        RETV_IF(NULL == resource_types, NULL);
 
-       for (i = 0; i < iotcon_str_list_length(resource_types); i++) {
-               if (IOTCON_RESOURCE_TYPE_LENGTH_MAX
-                               < strlen(iotcon_str_list_nth_data(resource_types, i))) {
-                       ERR("The length of resource_type is invalid");
-                       return NULL;
-               }
-       }
-
        resource = calloc(1, sizeof(struct ic_remote_resource));
        if (NULL == resource) {
                ERR("calloc() Fail(%d)", errno);
@@ -82,7 +71,7 @@ API iotcon_client_h iotcon_client_new(const char *host,
        resource->host = ic_utils_strdup(host);
        resource->uri = ic_utils_strdup(uri);
        resource->is_observable = is_observable;
-       resource->types = resource_types;
+       resource->types = ic_resource_types_ref(resource_types);
        resource->ifaces = resource_ifs;
 
        return resource;
@@ -98,7 +87,7 @@ API void iotcon_client_free(iotcon_client_h resource)
        free(resource->uri);
        free(resource->host);
        ic_options_free(resource->header_options);
-       iotcon_str_list_free(resource->types);
+       iotcon_resource_types_free(resource->types);
        free(resource);
 }
 
@@ -112,8 +101,12 @@ API iotcon_client_h iotcon_client_clone(iotcon_client_h resource)
        clone = iotcon_client_new(resource->host,
                        resource->uri,
                        resource->is_observable,
-                       iotcon_str_list_clone(resource->types),
+                       iotcon_resource_types_clone(resource->types),
                        resource->ifaces);
+       if (NULL == clone) {
+               ERR("iotcon_client_new() Fail");
+               return clone;
+       }
 
        clone->observe_handle = resource->observe_handle;
 
@@ -121,35 +114,61 @@ API iotcon_client_h iotcon_client_clone(iotcon_client_h resource)
 }
 
 
-API const char* iotcon_client_get_uri(iotcon_client_h resource)
+/* The content of the resource should not be freed by user. */
+API int iotcon_client_get_uri(iotcon_client_h resource, char **uri)
 {
-       RETV_IF(NULL == resource, NULL);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *uri = resource->uri;
 
-       return resource->uri;
+       return IOTCON_ERROR_NONE;
 }
 
 
-API const char* iotcon_client_get_host(iotcon_client_h resource)
+/* The content of the resource should not be freed by user. */
+API int iotcon_client_get_host(iotcon_client_h resource, char **host)
 {
-       RETV_IF(NULL == resource, NULL);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *host = resource->host;
 
-       return resource->host;
+       return IOTCON_ERROR_NONE;
 }
 
 
-API iotcon_str_list_s* iotcon_client_get_types(iotcon_client_h resource)
+/* The content of the resource should not be freed by user. */
+API int iotcon_client_get_types(iotcon_client_h resource, iotcon_resource_types_h *types)
 {
-       RETV_IF(NULL == resource, NULL);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
 
-       return resource->types;
+       *types = resource->types;
+
+       return IOTCON_ERROR_NONE;
 }
 
 
-API int iotcon_client_get_interfaces(iotcon_client_h resource)
+API int iotcon_client_get_interfaces(iotcon_client_h resource, int *ifaces)
 {
-       RETV_IF(NULL == resource, IOTCON_INTERFACE_NONE);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *ifaces = resource->ifaces;
+
+       return IOTCON_ERROR_NONE;
+}
 
-       return resource->ifaces;
+
+API int iotcon_client_is_observable(iotcon_client_h resource, bool *observable)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == observable, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *observable = resource->is_observable;
+
+       return IOTCON_ERROR_NONE;
 }
 
 
index 43dffada37979a72e61016ac7503ae839a94dba7..d642b96597d158760a8e70fe38bd95687f54acbe 100755 (executable)
@@ -27,7 +27,7 @@ struct ic_remote_resource {
        bool is_observable;
        bool is_collection;
        iotcon_options_h header_options;
-       iotcon_str_list_s *types;
+       iotcon_resource_types_h types;
        int ifaces;
        iotcon_observe_h observe_handle;
 };
index 14e8ebd0fa7565983eee0246093b98dabf9abc11..413291ada740d4a277779ad42f152fef57b985f6 100755 (executable)
 #include "iotcon.h"
 #include "ic-common.h"
 #include "ic-ioty.h"
-#include "ic-device.h"
 
 /* The length of manufacturer_name should be less than and equal to 16.
  * The length of manufacturer_url should be less than and equal to 32. */
-API int iotcon_register_device_info(
-               char *device_name,
-               char *host_name,
-               char *device_uuid,
-               char *content_type,
-               char *version,
-               char *manufacturer_name,
-               char *manufacturer_url,
-               char *model_number,
-               char *date_of_manufacture,
-               char *platform_version,
-               char *firmware_version,
-               char *support_url)
+API int iotcon_register_device_info(iotcon_device_info_s device_info)
 {
        int ret;
-       struct ic_device_info device_info = {0};
 
-       if (manufacturer_name
-                       && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(manufacturer_name))) {
-               ERR("The length of manufacturer_name(%s) is invalid.", manufacturer_name);
+       if (device_info.manuf_name
+                       && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(device_info.manuf_name))) {
+               ERR("The length of manufacturer_name(%s) is invalid.", device_info.manuf_name);
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       if (manufacturer_url
-                       && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(manufacturer_url))) {
-               ERR("The length of manufacturer_url(%s) is invalid.", manufacturer_url);
+       if (device_info.manuf_url
+                       && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(device_info.manuf_url))) {
+               ERR("The length of manufacturer_url(%s) is invalid.", device_info.manuf_url);
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       device_info.device_name = device_name;
-       device_info.host_name = host_name;
-       device_info.device_uuid = device_uuid;
-       device_info.content_type = content_type;
-       device_info.version = version;
-       device_info.manufacturer_name = manufacturer_name;
-       device_info.manufacturer_url = manufacturer_url;
-       device_info.model_number = model_number;
-       device_info.date_of_manufacture = date_of_manufacture;
-       device_info.platform_ver = platform_version;
-       device_info.firmware_ver = firmware_version;
-       device_info.support_url = support_url;
 
-       ret = ic_ioty_register_device_info(&device_info);
+       ret = ic_ioty_register_device_info(device_info);
        if (IOTCON_ERROR_NONE != ret)
                ERR("ic_ioty_register_device_info() Fail(%d)", ret);
 
        return ret;
 }
 
+
 /* host_address should begin with "coap://" */
 API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
                void *user_data)
@@ -92,100 +67,3 @@ API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb c
 
        return IOTCON_ERROR_NONE;
 }
-
-
-API const char* iotcon_device_info_get_device_name(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->device_name;
-}
-
-
-API const char* iotcon_device_info_get_host_name(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->host_name;
-}
-
-
-API const char* iotcon_device_info_get_device_uuid(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->device_uuid;
-}
-
-
-API const char* iotcon_device_info_get_content_type(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->content_type;
-}
-
-
-API const char* iotcon_device_info_get_version(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->version;
-}
-
-
-API const char* iotcon_device_info_get_manufacturer_name(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->manufacturer_name;
-}
-
-
-API const char* iotcon_device_info_get_manufacturer_url(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->manufacturer_url;
-}
-
-
-API const char* iotcon_device_info_get_model_number(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->model_number;
-}
-
-
-API const char* iotcon_device_info_get_date_of_manufacture(
-               iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->date_of_manufacture;
-}
-
-
-API const char* iotcon_device_info_get_platform_version(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->platform_ver;
-}
-
-
-API const char* iotcon_device_info_get_firmware_version(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->firmware_ver;
-}
-
-
-API const char* iotcon_device_info_get_support_url(iotcon_device_info_h device_info)
-{
-       RETV_IF(NULL == device_info, NULL);
-
-       return device_info->support_url;
-}
diff --git a/lib/ic-device.h b/lib/ic-device.h
deleted file mode 100755 (executable)
index 36e9be9..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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_INTERNAL_DEVICE_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_DEVICE_H__
-
-struct ic_device_info {
-       char *device_name;
-       char *host_name;
-       char *device_uuid;
-       char *content_type;
-       char *version;
-       char *manufacturer_name;
-       char *manufacturer_url;
-       char *model_number;
-       char *date_of_manufacture;
-       char *platform_ver;
-       char *firmware_ver;
-       char *support_url;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_DEVICE_H__ */
index 4426b152de778e878b3b07f0a21a3ded72d11468..6b3888d3327ffade61ae7d3ba7b04770e3921182 100755 (executable)
 #include <OCPlatform.h>
 
 extern "C" {
+#include "iotcon-struct.h"
 #include "ic.h"
 #include "ic-common.h"
 #include "ic-utils.h"
 #include "ic-client.h"
-#include "ic-device.h"
 #include "ic-request.h"
 #include "ic-response.h"
+#include "ic-resource-types.h"
 #include "ic-repr.h"
 #include "ic-ioty-repr.h"
 #include "ic-ioty.h"
@@ -108,23 +109,24 @@ namespace icIotivityHandler {
                        resource_s.types = NULL;
 
                        vector<string> resource_types = resource->getResourceTypes();
-                       for (string &resource_type : resource_types)
-                               resource_s.types
-                                       = iotcon_str_list_append(resource_s.types,
-                                                       resource_type.c_str());
+                       if (0 < resource_types.size()) {
+                               resource_s.types = iotcon_resource_types_new();
+                               for (string &resource_type : resource_types)
+                                       iotcon_resource_types_insert(resource_s.types, resource_type.c_str());
+                       }
 
                        vector<string> resource_interfaces = resource->getResourceInterfaces();
                        for (string &resource_interface : resource_interfaces) {
-                               if (STR_EQUAL == resource_interface.compare(DEFAULT_INTERFACE))
+                               if (IC_STR_EQUAL == resource_interface.compare(DEFAULT_INTERFACE))
                                        resource_s.ifaces |= IOTCON_INTERFACE_DEFAULT;
 
-                               if (STR_EQUAL == resource_interface.compare(BATCH_INTERFACE))
+                               if (IC_STR_EQUAL == resource_interface.compare(BATCH_INTERFACE))
                                        resource_s.ifaces |= IOTCON_INTERFACE_BATCH;
 
-                               if (STR_EQUAL == resource_interface.compare(LINK_INTERFACE))
+                               if (IC_STR_EQUAL == resource_interface.compare(LINK_INTERFACE))
                                        resource_s.ifaces |= IOTCON_INTERFACE_LINK;
 
-                               if (STR_EQUAL == resource_interface.compare(GROUP_INTERFACE))
+                               if (IC_STR_EQUAL == resource_interface.compare(GROUP_INTERFACE))
                                        resource_s.ifaces |= IOTCON_INTERFACE_GROUP;
                        }
 
@@ -133,7 +135,7 @@ namespace icIotivityHandler {
 
                        free(resource_s.uri);
                        free(resource_s.host);
-                       iotcon_str_list_free(resource_s.types);
+                       iotcon_resource_types_free(resource_s.types);
                }
        };
 
@@ -377,7 +379,7 @@ namespace icIotivityHandler {
 
                void receivedDeviceInfo(const OCRepresentation& ocRep)
                {
-                       struct ic_device_info info = {0};
+                       iotcon_device_info_s info = {0};
                        string readbuf;
 
                        if (ocRep.getValue("ct", readbuf))
@@ -385,17 +387,17 @@ namespace icIotivityHandler {
                        if (ocRep.getValue("mndt", readbuf))
                                info.date_of_manufacture = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("dn", readbuf))
-                               info.device_name = ic_utils_strdup(readbuf.c_str());
+                               info.name = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("di", readbuf))
-                               info.device_uuid = ic_utils_strdup(readbuf.c_str());
+                               info.uuid = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("mnfv", readbuf))
                                info.firmware_ver = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("hn", readbuf))
                                info.host_name = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("mnmn", readbuf))
-                               info.manufacturer_name = ic_utils_strdup(readbuf.c_str());
+                               info.manuf_name = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("mnml", readbuf))
-                               info.manufacturer_url = ic_utils_strdup(readbuf.c_str());
+                               info.manuf_url = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("mnmo", readbuf))
                                info.model_number = ic_utils_strdup(readbuf.c_str());
                        if (ocRep.getValue("mnpv", readbuf))
@@ -406,15 +408,15 @@ namespace icIotivityHandler {
                                info.version = ic_utils_strdup(readbuf.c_str());
 
                        if (found_cb)
-                               found_cb(&info, cb_data);
+                               found_cb(info, cb_data);
 
-                       free(info.device_name);
+                       free(info.name);
                        free(info.host_name);
-                       free(info.device_uuid);
+                       free(info.uuid);
                        free(info.content_type);
                        free(info.version);
-                       free(info.manufacturer_name);
-                       free(info.manufacturer_url);
+                       free(info.manuf_name);
+                       free(info.manuf_url);
                        free(info.model_number);
                        free(info.date_of_manufacture);
                        free(info.platform_ver);
@@ -441,9 +443,10 @@ static OCEntityHandlerResult _ic_ioty_request_handler(
                shared_ptr<OCResourceRequest> request)
 {
        FN_CALL;
+       const char *request_type = NULL;
        HeaderOptions headerOptions;
        QueryParamsMap queryParams;
-       ic_resource_s *temp_res = NULL;
+       iotcon_resource_h temp_res = NULL;
        struct ic_resource_request request_s = {0};
 
        temp_res = ic_get_resource_handler_data(request->getResourceHandle());
@@ -452,32 +455,35 @@ static OCEntityHandlerResult _ic_ioty_request_handler(
                return OC_EH_ERROR;
        }
 
-       request_s.query = iotcon_query_new();
-       if (NULL == request_s.query) {
-               ERR("iotcon_query_new() Fail");
-               return OC_EH_ERROR;
-       }
-
-       map<string,string>::iterator it;
        queryParams = request->getQueryParameters();
-       for (it = queryParams.begin(); it != queryParams.end(); ++it) {
-               DBG("key=%s value=%s", it->first.c_str(), it->second.c_str());
-               iotcon_query_insert(request_s.query, it->first.c_str(), it->second.c_str());
-       }
+       if (0 < queryParams.size()) {
+               request_s.query = iotcon_query_new();
+               if (NULL == request_s.query) {
+                       ERR("iotcon_query_new() Fail");
+                       return OC_EH_ERROR;
+               }
 
-       request_s.header_options = iotcon_options_new();
-       if (NULL == request_s.header_options) {
-               ERR("iotcon_options_new() Fail");
-               return OC_EH_ERROR;
+               for (auto it : queryParams) {
+                       DBG("key = %s value = %s", it.first.c_str(), it.second.c_str());
+                       iotcon_query_insert(request_s.query, it.first.c_str(), it.second.c_str());
+               }
        }
 
        headerOptions = request->getHeaderOptions();
        if (0 < headerOptions.size()) {
-               for (auto it1 = headerOptions.begin(); it1 != headerOptions.end(); ++it1) {
-                       DBG("OptionID=%d, OptionData=%s",
-                                       it1->getOptionID(), it1->getOptionData().c_str());
-                       iotcon_options_insert(request_s.header_options, it1->getOptionID(),
-                                       it1->getOptionData().c_str());
+               request_s.header_options = iotcon_options_new();
+               if (NULL == request_s.header_options) {
+                       ERR("iotcon_options_new() Fail");
+                       if (request_s.query)
+                               iotcon_query_free(request_s.query);
+                       return OC_EH_ERROR;
+               }
+
+               for (auto it : headerOptions) {
+                       DBG("OptionID = %d, OptionData = %s",
+                                       it.getOptionID(), it.getOptionData().c_str());
+                       iotcon_options_insert(request_s.header_options, it.getOptionID(),
+                                       it.getOptionData().c_str());
                }
        }
 
@@ -491,24 +497,44 @@ static OCEntityHandlerResult _ic_ioty_request_handler(
                }
        }
 
-       request_s.request_type = ic_utils_strdup(request->getRequestType().c_str());
-       if (NULL == request_s.request_type) {
-               ERR("ic_utils_strdup() Fail");
-               iotcon_options_free(request_s.header_options);
-               iotcon_query_free(request_s.query);
-               return OC_EH_ERROR;
+       if (RequestFlag & request->getRequestHandlerFlag()) {
+               request_type = request->getRequestType().c_str();
+               if (NULL == request_type) {
+                       ERR("request_type is NULL");
+                       if (request_s.repr)
+                               iotcon_repr_free(request_s.repr);
+                       if (request_s.header_options)
+                               iotcon_options_free(request_s.header_options);
+                       if (request_s.query)
+                               iotcon_query_free(request_s.query);
+                       return OC_EH_ERROR;
+               }
+
+               if (IC_STR_EQUAL == strcmp("GET", request_type))
+                       request_s.types = IOTCON_REQUEST_GET;
+               else if (IC_STR_EQUAL == strcmp("PUT", request_type))
+                       request_s.types = IOTCON_REQUEST_PUT;
+               else if (IC_STR_EQUAL == strcmp("POST", request_type))
+                       request_s.types = IOTCON_REQUEST_POST;
+               else if (IC_STR_EQUAL == strcmp("DELETE", request_type))
+                       request_s.types = IOTCON_REQUEST_DELETE;
        }
 
+       if (ObserverFlag & request->getRequestHandlerFlag())
+               request_s.types |= IOTCON_REQUEST_OBSERVE;
+
        request_s.uri = ic_utils_strdup(request->getResourceUri().c_str());
-       if (NULL == request_s.request_type) {
+       if (NULL == request_s.uri) {
                ERR("ic_utils_strdup() Fail");
-               free(request_s.request_type);
-               iotcon_options_free(request_s.header_options);
-               iotcon_query_free(request_s.query);
+               if (request_s.repr)
+                       iotcon_repr_free(request_s.repr);
+               if (request_s.header_options)
+                       iotcon_options_free(request_s.header_options);
+               if (request_s.query)
+                       iotcon_query_free(request_s.query);
                return OC_EH_ERROR;
        }
 
-       request_s.request_handler_flag = request->getRequestHandlerFlag();
        request_s.request_handle = (iotcon_request_h)request->getRequestHandle();
        request_s.resource_handle = (iotcon_client_h)request->getResourceHandle();
 
@@ -525,34 +551,34 @@ static OCEntityHandlerResult _ic_ioty_request_handler(
                WARN("temp_res->request_handler_cb is null");
        }
 
-       free(request_s.request_type);
        free(request_s.uri);
 
        /* To avoid unnecessary ERR log (repr could be NULL) */
        if (request_s.repr)
                iotcon_repr_free(request_s.repr);
-
-       iotcon_options_free(request_s.header_options);
-       iotcon_query_free(request_s.query);
+       if (request_s.header_options)
+               iotcon_options_free(request_s.header_options);
+       if (request_s.query)
+               iotcon_query_free(request_s.query);
 
        return OC_EH_OK;
 }
 
 
 extern "C" OCResourceHandle ic_ioty_register_res(const char *uri,
-               iotcon_str_list_s *res_types, int ifaces, uint8_t properties)
+               iotcon_resource_types_h res_types, int ifaces, uint8_t properties)
 {
        FN_CALL;
+       unsigned int i;
        OCStackResult ret;
        string resUri;
        string resType;
        string resInterface;
        OCResourceHandle handle;
-       unsigned int i;
 
        resUri = uri;
 
-       resType = iotcon_str_list_nth_data(res_types, 0);
+       resType = ic_resource_types_get_nth_data(res_types, 0);
 
        if (IOTCON_INTERFACE_DEFAULT & ifaces) {
                resInterface = DEFAULT_INTERFACE;
@@ -577,9 +603,8 @@ extern "C" OCResourceHandle ic_ioty_register_res(const char *uri,
                ERR("registerResource Fail(%d)", ret);
                return NULL;
        }
-
-       for (i = 1; i < iotcon_str_list_length(res_types); i++)
-               ic_ioty_bind_type_to_res(handle, iotcon_str_list_nth_data(res_types, i));
+       for (i = 1; i < ic_resource_types_get_length(res_types); i++)
+               ic_ioty_bind_type_to_res(handle, ic_resource_types_get_nth_data(res_types, i));
 
        if (IOTCON_INTERFACE_DEFAULT & ifaces)
                ic_ioty_bind_iface_to_res(handle, IOTCON_INTERFACE_DEFAULT);
@@ -617,16 +642,16 @@ extern "C" int ic_ioty_convert_interface_string(const char *src, iotcon_interfac
 
        string interface_str(src);
 
-       if (STR_EQUAL == DEFAULT_INTERFACE.compare(interface_str)) {
+       if (IC_STR_EQUAL == DEFAULT_INTERFACE.compare(interface_str)) {
                *dest = IOTCON_INTERFACE_DEFAULT;
        }
-       else if (STR_EQUAL == LINK_INTERFACE.compare(interface_str)) {
+       else if (IC_STR_EQUAL == LINK_INTERFACE.compare(interface_str)) {
                *dest = IOTCON_INTERFACE_LINK;
        }
-       else if (STR_EQUAL == BATCH_INTERFACE.compare(interface_str)) {
+       else if (IC_STR_EQUAL == BATCH_INTERFACE.compare(interface_str)) {
                *dest = IOTCON_INTERFACE_BATCH;
        }
-       else if (STR_EQUAL == GROUP_INTERFACE.compare(interface_str)) {
+       else if (IC_STR_EQUAL == GROUP_INTERFACE.compare(interface_str)) {
                *dest = IOTCON_INTERFACE_GROUP;
        }
        else {
@@ -731,24 +756,37 @@ extern "C" int ic_ioty_bind_res(OCResourceHandle parent, OCResourceHandle child)
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_register_device_info(iotcon_device_info_h device_info)
+extern "C" int ic_ioty_unbind_res(OCResourceHandle parent, OCResourceHandle child)
+{
+       OCStackResult ret;
+
+       ret = unbindResource(parent, child);
+       if (OC_STACK_OK != ret) {
+               ERR("unbindResource() Fail(%d)", ret);
+               return IOTCON_ERROR_IOTIVITY;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
+extern "C" int ic_ioty_register_device_info(iotcon_device_info_s device_info)
 {
        FN_CALL;
        OCStackResult ret;
 
        OCDeviceInfo deviceInfo = {0};
-       deviceInfo.deviceName = device_info->device_name;
-       deviceInfo.hostName = device_info->host_name;
-       deviceInfo.deviceUUID = device_info->device_uuid;
-       deviceInfo.contentType = device_info->content_type;
-       deviceInfo.version = device_info->version;
-       deviceInfo.manufacturerName = device_info->manufacturer_name;
-       deviceInfo.manufacturerUrl = device_info->manufacturer_url;
-       deviceInfo.modelNumber = device_info->model_number;
-       deviceInfo.dateOfManufacture = device_info->date_of_manufacture;
-       deviceInfo.platformVersion = device_info->platform_ver;
-       deviceInfo.firmwareVersion = device_info->firmware_ver;
-       deviceInfo.supportUrl = device_info->support_url;
+       deviceInfo.deviceName = device_info.name;
+       deviceInfo.hostName = device_info.host_name;
+       deviceInfo.deviceUUID = device_info.uuid;
+       deviceInfo.contentType = device_info.content_type;
+       deviceInfo.version = device_info.version;
+       deviceInfo.manufacturerName = device_info.manuf_name;
+       deviceInfo.manufacturerUrl = device_info.manuf_url;
+       deviceInfo.modelNumber = device_info.model_number;
+       deviceInfo.dateOfManufacture = device_info.date_of_manufacture;
+       deviceInfo.platformVersion = device_info.platform_ver;
+       deviceInfo.firmwareVersion = device_info.firmware_ver;
+       deviceInfo.supportUrl = device_info.support_url;
 
        ret = registerDeviceInfo(deviceInfo);
        if (OC_STACK_OK != ret) {
@@ -793,7 +831,7 @@ extern "C" int ic_ioty_send_notify(OCResourceHandle resHandle, struct ic_notify_
 
        GList *node = g_list_first((GList*)observers);
        while (node) {
-               uint8_t obs_id = GPOINTER_TO_UINT(node->data);
+               int obs_id = GPOINTER_TO_UINT(node->data);
                obsIds.push_back(obs_id);
 
                node = node->next;
@@ -939,7 +977,7 @@ extern "C" int ic_ioty_find_resource(const char *host_address, const char *resou
        OCStackResult ret;
        ostringstream resource_name;
 
-       if (STR_EQUAL == strcmp(IOTCON_MULTICAST_ADDRESS, host_address))
+       if (IC_STR_EQUAL == strcmp(IOTCON_MULTICAST_ADDRESS, host_address))
                resource_name << host_address << IC_MULTICAST_RESOURCE_DISCOVERY;
        else
                resource_name << host_address << IC_UNICAST_RESOURCE_DISCOVERY;
@@ -971,6 +1009,16 @@ static int _ic_ioty_accumulate_options_vector(unsigned short id, const char *dat
        return IOTCON_FUNC_CONTINUE;
 }
 
+
+static int _ic_ioty_accumulate_res_types(const char *type, void *user_data)
+{
+       vector<string> *types = static_cast<vector<string>*>(user_data);
+       (*types).push_back(type);
+
+       return IOTCON_FUNC_CONTINUE;
+}
+
+
 static OCResource::Ptr _ic_ioty_create_oc_resource(iotcon_client_h resource)
 {
        string host;
@@ -988,12 +1036,8 @@ static OCResource::Ptr _ic_ioty_create_oc_resource(iotcon_client_h resource)
        host = resource->host;
        uri = resource->uri;
 
-       iotcon_str_list_s *list = resource->types;
-       while (list) {
-               string resource_type = list->string;
-               resource_types.push_back(resource_type);
-               list = list->next;
-       }
+       iotcon_resource_types_foreach(resource->types, _ic_ioty_accumulate_res_types,
+                       (void*)&resource_types);
 
        if (IOTCON_INTERFACE_NONE == resource->ifaces) {
                resource_ifs.push_back(DEFAULT_INTERFACE);
old mode 100644 (file)
new mode 100755 (executable)
index cc79826..dc10b1c
@@ -24,8 +24,8 @@
 
 void ic_ioty_config(const char *addr, unsigned short port);
 
-void* ic_ioty_register_res(const char *uri, iotcon_str_list_s *res_types,
-               int ifaces, uint8_t properties);
+void* ic_ioty_register_res(const char *uri, iotcon_resource_types_h res_types, int ifaces,
+               uint8_t properties);
 
 int ic_ioty_unregister_res(iotcon_resource_h resource_handle);
 
@@ -35,7 +35,9 @@ int ic_ioty_bind_type_to_res(void *resource_handle, const char *resource_type);
 
 int ic_ioty_bind_res(void *parent, void *child);
 
-int ic_ioty_register_device_info(iotcon_device_info_h device_info);
+int ic_ioty_unbind_res(void *parent, void *child);
+
+int ic_ioty_register_device_info(iotcon_device_info_s device_info);
 
 int ic_ioty_get_device_info(const char *host_address, iotcon_device_info_cb found_cb,
                void *user_data);
old mode 100644 (file)
new mode 100755 (executable)
index a9aec15..2bd76af
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <stdint.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <glib.h>
@@ -28,15 +27,17 @@ API void iotcon_observers_free(iotcon_observers_h observers)
        g_list_free(observers);
 }
 
+
 /* If you want to make a new list, then you should set observers is NULL. */
 API iotcon_observers_h iotcon_observers_append(iotcon_observers_h observers,
-               uint8_t obs_id)
+               int obs_id)
 {
        return g_list_append(observers, GUINT_TO_POINTER(obs_id));
 }
 
+
 API iotcon_observers_h iotcon_observers_remove(iotcon_observers_h observers,
-               uint8_t obs_id)
+               int obs_id)
 {
        RETV_IF(NULL == observers, observers);
 
index e90c548cbf1ee994c78f15d02755500dcb0a8d80..1da19e41e5407aaf2df9b3b98deb0b6b9072107d 100755 (executable)
@@ -55,8 +55,8 @@ API void iotcon_options_free(iotcon_options_h options)
 
 
 /* iotcon_options_h can have up to 2 options.
- * option id is always situated between 2014 and 3000.
- * Length of option data is less than and equal to 15. */
+ * option id is always situated between 2048 and 3000.
+ * Length of option data is less than or equal to 15. */
 API int iotcon_options_insert(iotcon_options_h options, unsigned short id,
                const char *data)
 {
index e96cb73ef5c87a2428b3e9195b6b3d48c64d8c87..abb2cdc3026d3f2bbd36cfe03eda52493025e99c 100755 (executable)
@@ -46,7 +46,7 @@ API void iotcon_query_free(iotcon_query_h query)
 }
 
 
-/* The full length of query should be less than and equal to 64. */
+/* The full length of query should be less than or equal to 64. */
 API int iotcon_query_insert(iotcon_query_h query, const char *key, const char *value)
 {
        int query_len;
index 6766b858d3a6888c6f41050875cd397f47af1164..4d5a8c688f271a66f8534071faaf2edab0b5cfdf 100755 (executable)
@@ -31,8 +31,8 @@ int ic_obj_del_value(iotcon_repr_h repr, const char *key,
        gboolean ret = FALSE;
        iotcon_value_h value = NULL;
 
-       RETV_IF(NULL == repr, false);
-       RETV_IF(NULL == key, false);
+       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
 
        value = g_hash_table_lookup(repr->hash_table, key);
        if (NULL == value) {
@@ -484,28 +484,20 @@ int ic_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value)
        return IOTCON_ERROR_NONE;
 }
 
-static inline int _ic_obj_to_json(GHashTable *hash, iotcon_str_list_s *key_list,
-               unsigned int index, JsonObject *json_obj)
+static inline int _ic_obj_to_json(const char *key, iotcon_value_h value,
+               JsonObject *json_obj)
 {
        FN_CALL;
        int type, ret;
-       const char *key;
        iotcon_repr_h child_repr = NULL;
        iotcon_list_h child_list = NULL;
-       iotcon_value_h value = NULL;
 
        JsonObject *child_obj = NULL;
        JsonNode *child_node = NULL;
        JsonArray *child_array = NULL;
 
-       RETV_IF(NULL == hash, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == key_list, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(index < 0, IOTCON_ERROR_INVALID_PARAMETER);
-
-       key = iotcon_str_list_nth_data(key_list, index);
-       value = g_hash_table_lookup(hash, key);
-       if (NULL == value)
-               ERR("g_hash_table_lookup(%s) Fail", key);
+       RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
 
        type = value->type;
        switch (type) {
@@ -567,27 +559,29 @@ static inline int _ic_obj_to_json(GHashTable *hash, iotcon_str_list_s *key_list,
 JsonObject* ic_obj_to_json(iotcon_repr_h repr)
 {
        int ret;
-       unsigned int i = 0;
-       iotcon_str_list_s *key_list = NULL;
+       int key_count;
        JsonObject *json_obj = NULL;
-       JsonObject *parent_obj;
+       JsonObject *parent_obj = NULL;
+
+       GHashTableIter iter;
+       gpointer key, value;
 
        RETV_IF(NULL == repr, NULL);
+       RETV_IF(NULL == repr->hash_table, NULL);
 
-       key_list = iotcon_repr_get_key_list(repr);
-       if (key_list) {
+       key_count = iotcon_repr_get_keys_count(repr);
+       if (key_count) {
                json_obj = json_object_new();
-               for (i = 0; i < iotcon_str_list_length(key_list); i++) {
-                       ret = _ic_obj_to_json(repr->hash_table, key_list, i, json_obj);
 
+               g_hash_table_iter_init(&iter, repr->hash_table);
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       ret = _ic_obj_to_json(key, value, json_obj);
                        if (IOTCON_ERROR_NONE != ret) {
                                ERR("_ic_obj_to_json() Fail(%d)", ret);
                                json_object_unref(json_obj);
-                               iotcon_str_list_free(key_list);
                                return NULL;
                        }
                }
-               iotcon_str_list_free(key_list);
        }
 
        parent_obj = json_object_new();
index d24eee7400ba8dee6f2035781a598c195c979ae5..d99b740094b7155145ae4720008f19cf9cf15e3a 100755 (executable)
@@ -25,7 +25,9 @@
 #include "iotcon-representation.h"
 #include "ic-common.h"
 #include "ic-utils.h"
+#include "ic-resource-types.h"
 #include "ic-ioty.h"
+#include "ic.h"
 #include "ic-repr-list.h"
 #include "ic-repr-value.h"
 #include "ic-repr-obj.h"
@@ -102,7 +104,7 @@ API int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri)
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_str_list_s **types)
+API int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resource_types_h *types)
 {
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
@@ -112,15 +114,15 @@ API int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_str_list_s **t
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_str_list_s *types)
+API int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_resource_types_h types)
 {
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
-       iotcon_str_list_free(repr->res_types);
+       iotcon_resource_types_free(repr->res_types);
        repr->res_types = NULL;
 
-       if (NULL != types)
-               repr->res_types = iotcon_str_list_clone(types);
+       if (types)
+               repr->res_types = ic_resource_types_ref(types);
 
        return IOTCON_ERROR_NONE;
 }
@@ -136,6 +138,9 @@ API int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces)
 {
        RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
+       RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || IC_INTERFACE_MAX < ifaces,
+                       IOTCON_ERROR_INVALID_PARAMETER);
+
        repr->interfaces = ifaces;
 
        return IOTCON_ERROR_NONE;
@@ -194,20 +199,22 @@ API int iotcon_repr_get_nth_child(iotcon_repr_h parent, int pos, iotcon_repr_h *
        return IOTCON_ERROR_NONE;
 }
 
-API iotcon_str_list_s* iotcon_repr_get_key_list(iotcon_repr_h repr)
+API int iotcon_repr_foreach_keys(iotcon_repr_h repr, iotcon_repr_key_fn fn,
+               void *user_data)
 {
        GHashTableIter iter;
        gpointer key, value;
-       iotcon_str_list_s *key_list = NULL;
 
-       RETV_IF(NULL == repr, NULL);
-       RETV_IF(NULL == repr->hash_table, NULL);
+       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == fn, IOTCON_ERROR_INVALID_PARAMETER);
 
        g_hash_table_iter_init(&iter, repr->hash_table);
-       while (g_hash_table_iter_next(&iter, &key, &value))
-               key_list = iotcon_str_list_append(key_list, key);
+       while (g_hash_table_iter_next(&iter, &key, &value)) {
+               if (IOTCON_FUNC_STOP == fn(key, value, user_data))
+                       break;
+       }
 
-       return key_list;
+       return IOTCON_ERROR_NONE;
 }
 
 API int iotcon_repr_get_keys_count(iotcon_repr_h repr)
@@ -239,7 +246,7 @@ static JsonObject* _ic_repr_data_generate_json(iotcon_repr_h cur_repr,
        JsonObject *repr_obj = NULL;
        unsigned int rt_count = 0;
        JsonObject *prop_obj = NULL;
-       iotcon_str_list_s *resource_types = NULL;
+       iotcon_resource_types_h resource_types = NULL;
 
        RETV_IF(NULL == cur_repr, NULL);
 
@@ -261,7 +268,7 @@ static JsonObject* _ic_repr_data_generate_json(iotcon_repr_h cur_repr,
        }
 
        if (cur_repr->res_types)
-               rt_count = iotcon_str_list_length(cur_repr->res_types);
+               rt_count = ic_resource_types_get_length(cur_repr->res_types);
 
        if (0 < rt_count || IOTCON_INTERFACE_NONE != cur_repr->interfaces) {
                prop_obj = json_object_new();
@@ -278,10 +285,10 @@ static JsonObject* _ic_repr_data_generate_json(iotcon_repr_h cur_repr,
                        return NULL;
                }
 
-               ret = iotcon_str_list_foreach(resource_types, _ic_repr_get_res_type_fn,
+               ret = iotcon_resource_types_foreach(resource_types, _ic_repr_get_res_type_fn,
                                rt_array);
                if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_str_list_foreach() Fail");
+                       ERR("iotcon_resource_types_foreach() Fail");
                        json_object_unref(repr_obj);
                        return NULL;
                }
@@ -291,7 +298,7 @@ static JsonObject* _ic_repr_data_generate_json(iotcon_repr_h cur_repr,
        if (IOTCON_INTERFACE_NONE != cur_repr->interfaces) {
                JsonArray *if_array = json_array_new();
                ifaces = iotcon_repr_get_resource_interfaces(cur_repr);
-               for (i = 1; i < IOTCON_INTERFACE_MAX; i = i << 1) {
+               for (i = 1; i <= IC_INTERFACE_MAX; i = i << 1) {
                        if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */
                                continue;
                        ret = ic_ioty_convert_interface_flag((ifaces & i), &iface_str);
@@ -464,17 +471,20 @@ iotcon_repr_h ic_repr_parse_json(const char *json_string)
                IOTCON_KEY_PROPERTY);
 
                if (json_object_has_member(property_obj, IOTCON_KEY_RESOURCETYPES)) {
-                       iotcon_str_list_s *res_types = NULL;
+                       iotcon_resource_types_h res_types = NULL;
                        JsonArray *rt_array = json_object_get_array_member(property_obj,
                        IOTCON_KEY_RESOURCETYPES);
                        unsigned int rt_index = 0;
                        unsigned int rt_count = json_array_get_length(rt_array);
 
-                       for (rt_index = 0; rt_index < rt_count; rt_index++) {
-                               rtype_str = json_array_get_string_element(rt_array, rt_index);
-                               res_types = iotcon_str_list_append(res_types, rtype_str);
+                       if (0 < rt_count) {
+                               res_types = iotcon_resource_types_new();
+                               for (rt_index = 0; rt_index < rt_count; rt_index++) {
+                                       rtype_str = json_array_get_string_element(rt_array, rt_index);
+                                       iotcon_resource_types_insert(res_types, rtype_str);
+                               }
+                               iotcon_repr_set_resource_types(repr, res_types);
                        }
-                       iotcon_repr_set_resource_types(repr, res_types);
                }
                if (json_object_has_member(property_obj, IOTCON_KEY_INTERFACES)) {
                        JsonArray *if_array = json_object_get_array_member(property_obj,
@@ -522,7 +532,7 @@ API void iotcon_repr_free(iotcon_repr_h repr)
 
        /* repr->res_types COULD be not null */
        if (repr->res_types)
-               iotcon_str_list_free(repr->res_types);
+               iotcon_resource_types_free(repr->res_types);
        g_hash_table_destroy(repr->hash_table);
        free(repr);
 
@@ -605,7 +615,7 @@ API iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src)
        FN_CALL;
        GList *node;
        iotcon_repr_h dest, copied_repr;
-       iotcon_str_list_s *list = NULL;
+       iotcon_resource_types_h list;
 
        RETV_IF(NULL == src, NULL);
 
@@ -628,9 +638,9 @@ API iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src)
                dest->interfaces = src->interfaces;
 
        if (src->res_types) {
-               list = iotcon_str_list_clone(src->res_types);
+               list = iotcon_resource_types_clone(src->res_types);
                if (NULL == list) {
-                       ERR("iotcon_str_list_clone() Fail");
+                       ERR("iotcon_resource_types_clone() Fail");
                        iotcon_repr_free(dest);
                        return NULL;
                }
index 27802b575e2dde4dbfc144c895b141dc0b5f5d1b..0476652ef7e499ab12ff1ff8dacf05c66c8c8a62 100755 (executable)
@@ -35,7 +35,7 @@ struct ic_repr_s {
        int interfaces;
        GHashTable *hash_table;
        GList *children;
-       iotcon_str_list_s *res_types;
+       iotcon_resource_types_h res_types;
 };
 
 /**
index 76757df4195cc1a26818e28276c84dc25046abc7..a9ac5d74efd992ec5e8857e66924588cd8cfef10 100755 (executable)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <stdint.h>
-
 #include "iotcon-struct.h"
 #include "iotcon-constant.h"
 #include "ic-common.h"
 #include "ic-request.h"
 
-API iotcon_repr_h iotcon_request_get_representation(iotcon_request_h request)
+/* The content of the request should not be freed by user. */
+API int iotcon_request_get_uri(iotcon_request_h request, char **uri)
 {
-       RETV_IF(NULL == request, NULL);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *uri = request->uri;
 
-       return request->repr;
+       return IOTCON_ERROR_NONE;
 }
 
 
-API const char* iotcon_request_get_request_type(iotcon_request_h request)
+/* The content of the request should not be freed by user. */
+API int iotcon_request_get_representation(iotcon_request_h request, iotcon_repr_h *repr)
 {
-       RETV_IF(NULL == request, NULL);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
-       return request->request_type;
+       *repr = request->repr;
+
+       return IOTCON_ERROR_NONE;
 }
 
 
-API int iotcon_request_get_request_handler_flag(iotcon_request_h request)
+API int iotcon_request_get_types(iotcon_request_h request, int *types)
 {
-       RETV_IF(NULL == request, 0);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *types = request->types;
 
-       return request->request_handler_flag;
+       return IOTCON_ERROR_NONE;
 }
 
 
-API iotcon_options_h iotcon_request_get_options(iotcon_request_h request)
+/* The content of the request should not be freed by user. */
+API int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *options)
 {
-       RETV_IF(NULL == request, NULL);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
 
-       return request->header_options;
+       *options = request->header_options;
+
+       return IOTCON_ERROR_NONE;
 }
 
 
-API iotcon_query_h iotcon_request_get_query(iotcon_request_h request)
+/* The content of the request should not be freed by user. */
+API int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query)
 {
-       RETV_IF(NULL == request, NULL);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *query = request->query;
 
-       return request->query;
+       return IOTCON_ERROR_NONE;
 }
 
 
-API iotcon_observe_action_e iotcon_request_get_observer_action(iotcon_request_h request)
+API int iotcon_request_get_observer_action(iotcon_request_h request,
+               iotcon_observe_action_e *action)
 {
-       RETV_IF(NULL == request, IOTCON_OBSERVE_NO_OPTION);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == action, IOTCON_ERROR_INVALID_PARAMETER);
 
-       return request->observation_info.action;
+       *action = request->observation_info.action;
+
+       return IOTCON_ERROR_NONE;
 }
 
 
-API uint8_t iotcon_request_get_observer_id(iotcon_request_h request)
+API int iotcon_request_get_observer_id(iotcon_request_h request, int *observer_id)
 {
-       RETV_IF(NULL == request, 0);
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == observer_id, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *observer_id = request->observation_info.observer_id;
 
-       return request->observation_info.observer_id;
+       return IOTCON_ERROR_NONE;
 }
 
index 4b4bb291cd869d1f133f773cf6f3c2bf499dda05..eee1a8227bc206e56238e5e7dff1185d675b1395 100755 (executable)
@@ -16,8 +16,6 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_REQUEST_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_REQUEST_H__
 
-#include <stdint.h>
-
 #include "iotcon-struct.h"
 #include "iotcon-constant.h"
 
@@ -26,11 +24,11 @@ typedef void* oc_resource_h;
 
 struct ic_observe_info {
        iotcon_observe_action_e action;
-       uint8_t observer_id;
+       int observer_id;
 };
 
 struct ic_resource_request {
-       char *request_type;
+       int types;
        char *uri;
        iotcon_options_h header_options;
        iotcon_query_h query;
diff --git a/lib/ic-resource-types.c b/lib/ic-resource-types.c
new file mode 100755 (executable)
index 0000000..13f7f64
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * 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-struct.h"
+#include "iotcon-constant.h"
+#include "ic-common.h"
+#include "ic-utils.h"
+#include "ic-resource-types.h"
+
+iotcon_resource_types_h ic_resource_types_ref(iotcon_resource_types_h types)
+{
+       RETV_IF(NULL == types, NULL);
+       RETV_IF(types->ref_count <= 0, NULL);
+
+       types->ref_count++;
+
+       return types;
+}
+
+
+API iotcon_resource_types_h iotcon_resource_types_new()
+{
+       iotcon_resource_types_h types = calloc(1, sizeof(struct ic_resource_types));
+       if (NULL == types) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       types->ref_count = 1;
+
+       return types;
+}
+
+
+API void iotcon_resource_types_free(iotcon_resource_types_h types)
+{
+       RET_IF(NULL == types);
+
+       types->ref_count--;
+
+       if (0 == types->ref_count) {
+               g_list_free_full(types->type_list, free);
+               free(types);
+       }
+}
+
+
+static int _ic_resource_types_strcmp(const void *a, const void *b)
+{
+       return strcmp(a, b);
+}
+
+
+static bool _ic_resource_types_duplicate_check(iotcon_resource_types_h types,
+               const char *type)
+{
+       GList *ret = NULL;
+
+       ret = g_list_find_custom(types->type_list, type, _ic_resource_types_strcmp);
+       if (NULL == ret)
+               return false;
+
+       return true;
+}
+
+
+/* If you want to make a new list, then you should set res_types is NULL.
+ * The length of resource type should be less than or equal to 61.
+ * Duplicate strings are not allowed. */
+API int iotcon_resource_types_insert(iotcon_resource_types_h types, const char *type)
+{
+       char *resource_type;
+
+       RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+
+       if (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(type)) {
+               ERR("The length of type(%s) should be less than or equal to %d.", type,
+                               IOTCON_RESOURCE_TYPE_LENGTH_MAX);
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       if (true == _ic_resource_types_duplicate_check(types, type)) {
+               ERR("%s is already contained.", type);
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       resource_type = strdup(type);
+       if (NULL == resource_type) {
+               ERR("strdup() Fail");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       types->type_list = g_list_append(types->type_list, resource_type);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_types_delete(iotcon_resource_types_h types, const char *type)
+{
+       GList *found_node;
+
+       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+
+       found_node = g_list_find_custom(types->type_list, type, _ic_resource_types_strcmp);
+       if (NULL == found_node) {
+               ERR("g_list_find_custom() Fail");
+               return IOTCON_ERROR_NO_DATA;
+       }
+
+       types->type_list = g_list_delete_link(types->type_list, found_node);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_types_foreach(iotcon_resource_types_h types,
+               iotcon_resource_types_foreach_cb cb, void *user_data)
+{
+       GList *node;
+
+       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       for (node = types->type_list; node; node = node->next) {
+               if (IOTCON_FUNC_STOP == cb((const char*)node->data, user_data))
+                       break;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API iotcon_resource_types_h iotcon_resource_types_clone(iotcon_resource_types_h types)
+{
+       GList * node;
+       char *resource_type;
+       iotcon_resource_types_h clone;
+
+       RETV_IF(NULL == types, NULL);
+
+       clone = calloc(1, sizeof(struct ic_resource_types));
+       if (NULL == clone) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       for (node = types->type_list; node; node = node->next) {
+               resource_type = ic_utils_strdup(node->data);
+               if (NULL == resource_type) {
+                       iotcon_resource_types_free(clone);
+                       ERR("ic_utils_strdup() Fail");
+                       return NULL;
+               }
+               clone->type_list = g_list_append(clone->type_list, resource_type);
+       }
+
+       clone->ref_count = 1;
+
+       return clone;
+}
+
+
+/* counting from 0 */
+const char* ic_resource_types_get_nth_data(iotcon_resource_types_h types, int index)
+{
+       return g_list_nth_data(types->type_list, index);
+}
+
+
+unsigned int ic_resource_types_get_length(iotcon_resource_types_h types)
+{
+       return g_list_length(types->type_list);
+}
diff --git a/lib/ic-resource-types.h b/lib/ic-resource-types.h
new file mode 100755 (executable)
index 0000000..0f0a30a
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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_INTERNAL_RESOURCE_TYPES_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_RESOURCE_TYPES_H__
+
+#include "iotcon-struct.h"
+
+struct ic_resource_types {
+       int ref_count;
+       GList *type_list;
+};
+
+iotcon_resource_types_h ic_resource_types_ref(iotcon_resource_types_h res_types);
+const char* ic_resource_types_get_nth_data(iotcon_resource_types_h res_types, int index);
+unsigned int ic_resource_types_get_length(iotcon_resource_types_h res_types);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_RESOURCE_TYPES_H__ */
index 1566450e3d85b34cb056bfa318902841c9da2732..dc05f58ad5d810e58da65c4284b8eb8de3575e3d 100755 (executable)
@@ -36,147 +36,3 @@ char* ic_utils_strdup(const char *src)
 
        return dest;
 }
-
-
-static iotcon_str_list_s* _ic_str_list_last(iotcon_str_list_s *str_list)
-{
-       RETV_IF(NULL == str_list, NULL);
-
-       while (str_list->next)
-               str_list = str_list->next;
-
-       return str_list;
-}
-
-
-API void iotcon_str_list_free(iotcon_str_list_s *str_list)
-{
-       iotcon_str_list_s *cur_node = NULL;
-
-       RET_IF(NULL == str_list);
-
-       while (cur_node) {
-               cur_node = str_list;
-               str_list = str_list->next;
-               free(cur_node->string);
-               free(cur_node);
-       }
-}
-
-
-/* If you want to make a new list, then you should set str_list is NULL. */
-API iotcon_str_list_s* iotcon_str_list_append(iotcon_str_list_s *str_list,
-               const char *string)
-{
-       iotcon_str_list_s *last_node = NULL;
-       iotcon_str_list_s *new_node = NULL;
-
-       RETV_IF(NULL == string, str_list);
-
-       new_node = calloc(1, sizeof(iotcon_str_list_s));
-       if (NULL == new_node) {
-               ERR("calloc() Fail(%d)", errno);
-               return NULL;
-       }
-
-       new_node->string = ic_utils_strdup(string);
-
-       if (str_list) {
-               last_node = _ic_str_list_last(str_list);
-               last_node->next = new_node;
-               return str_list;
-       }
-       else {
-               return new_node;
-       }
-}
-
-
-API iotcon_str_list_s* iotcon_str_list_remove(iotcon_str_list_s *str_list,
-               const char *string)
-{
-       iotcon_str_list_s *cur_node = NULL;
-       iotcon_str_list_s *prev_node = NULL;
-
-       RETV_IF(NULL == str_list, NULL);
-       RETV_IF(NULL == string, str_list);
-
-       cur_node = str_list;
-
-       while (cur_node) {
-               if (STR_EQUAL == strcmp(string, cur_node->string)) {
-                       if (prev_node)
-                               prev_node->next = cur_node->next;
-                       else
-                               str_list = cur_node->next;
-
-                       free(cur_node->string);
-                       free(cur_node);
-                       break;
-               }
-               prev_node = cur_node;
-               cur_node = cur_node->next;
-       }
-
-       return str_list;
-}
-
-
-API iotcon_str_list_s* iotcon_str_list_clone(iotcon_str_list_s *str_list)
-{
-       iotcon_str_list_s *new_list = NULL;
-
-       RETV_IF(NULL == str_list, NULL);
-
-       while (str_list) {
-               new_list = iotcon_str_list_append(new_list, str_list->string);
-               str_list = str_list->next;
-       }
-
-       return new_list;
-}
-
-
-API unsigned int iotcon_str_list_length(iotcon_str_list_s *str_list)
-{
-       unsigned int length = 0;
-
-       RETV_IF(NULL == str_list, 0);
-
-       while (str_list) {
-               length++;
-               str_list = str_list->next;
-       }
-
-       return length;
-}
-
-API int iotcon_str_list_foreach(iotcon_str_list_s *str_list, iotcon_string_foreach_cb cb,
-               void *user_data)
-{
-       RETV_IF(NULL == str_list, IOTCON_ERROR_INVALID_PARAMETER);
-
-       while (str_list) {
-               if (false == cb(str_list->string, user_data))
-                       break;
-               str_list = str_list->next;
-       }
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API const char* iotcon_str_list_nth_data(iotcon_str_list_s *str_list, unsigned int n)
-{
-       int i;
-
-       RETV_IF(NULL == str_list, NULL);
-
-       for (i = 0; i < n; i++) {
-               str_list = str_list->next;
-               if (NULL == str_list)
-                       return NULL;
-       }
-
-       return str_list->string;
-}
old mode 100644 (file)
new mode 100755 (executable)
index 4dc5e5a..cba63b6
@@ -16,7 +16,7 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__
 
-#define STR_EQUAL 0
+#define IC_STR_EQUAL 0
 
 char* ic_utils_strdup(const char *src);
 
index 631894dc04e177e245b309158e6448645f111712..77b1844c47aac71e9e64a9b4bedf76de36733f61 100755 (executable)
--- a/lib/ic.c
+++ b/lib/ic.c
@@ -24,6 +24,7 @@
 #include "iotcon.h"
 #include "ic-common.h"
 #include "ic-utils.h"
+#include "ic-resource-types.h"
 #include "ic-ioty.h"
 #include "ic-repr.h"
 #include "ic.h"
@@ -86,22 +87,21 @@ static gboolean _find_valid_resource(gpointer key, gpointer value, gpointer user
 }
 
 
-ic_resource_s* ic_get_resource_handler_data(void *handle)
+iotcon_resource_h ic_get_resource_handler_data(void *handle)
 {
        return g_hash_table_find(ic_request_cb_hash, _find_valid_resource, handle);
 }
 
 
-/* The length of uri should be less than and equal to 36. */
+/* The length of uri should be less than or equal to 36. */
 API iotcon_resource_h iotcon_register_resource(const char *uri,
-               iotcon_str_list_s *res_types,
+               iotcon_resource_types_h res_types,
                int ifaces,
                uint8_t properties,
                iotcon_request_handler_cb cb,
                void *user_data)
 {
        FN_CALL;
-       int i;
        iotcon_resource_h resource;
 
        RETV_IF(NULL == uri, NULL);
@@ -110,15 +110,7 @@ API iotcon_resource_h iotcon_register_resource(const char *uri,
        RETV_IF(NULL == res_types, NULL);
        RETV_IF(NULL == cb, NULL);
 
-       for (i = 0; i < iotcon_str_list_length(res_types); i++) {
-               if (IOTCON_RESOURCE_TYPE_LENGTH_MAX
-                               < strlen(iotcon_str_list_nth_data(res_types, i))) {
-                       ERR("The length of resource_type is invalid");
-                       return NULL;
-               }
-       }
-
-       resource = calloc(1, sizeof(struct _resource_s));
+       resource = calloc(1, sizeof(struct ic_resource));
        if (NULL == resource) {
                ERR("calloc Fail(%d)", errno);
                return NULL;
@@ -134,6 +126,11 @@ API iotcon_resource_h iotcon_register_resource(const char *uri,
        resource->cb = cb;
        resource->user_data = user_data;
 
+       resource->uri = ic_utils_strdup(uri);
+       resource->types = ic_resource_types_ref(res_types);
+       resource->ifaces = ifaces;
+       resource->is_observable = properties & IOTCON_OBSERVABLE;
+
        g_hash_table_insert(ic_request_cb_hash, resource->handle, resource);
 
        return resource;
@@ -185,22 +182,163 @@ API int iotcon_bind_type(iotcon_resource_h resource, const char *resource_type)
 }
 
 
+API int iotcon_bind_request_handler(iotcon_resource_h resource,
+               iotcon_request_handler_cb cb)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       WARN("Request handler is changed");
+       resource->cb = cb;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
 API int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child)
 {
        FN_CALL;
        int ret;
+       int i;
 
        RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(parent == child, IOTCON_ERROR_INVALID_PARAMETER);
 
-       ret = ic_ioty_bind_res(parent->handle, child->handle);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_bind_res() Fail(%d)", ret);
+       for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+               if (child == parent->children[i]) {
+                       ERR("Child resource was already bound to parent resource.");
+                       return IOTCON_ERROR_ALREADY;
+               }
+               if (NULL == parent->children[i]) {
+                       ret = ic_ioty_bind_res(parent->handle, child->handle);
+                       if (IOTCON_ERROR_NONE == ret)
+                               parent->children[i] = child;
+                       else
+                               ERR("ic_ioty_bind_res() Fail(%d)", ret);
+
+                       return ret;
+               }
+       }
+
+       ERR("There is no slot to bind a child resource");
+       return IOTCON_ERROR_OUT_OF_MEMORY;
+}
+
+
+API int iotcon_unbind_resource(iotcon_resource_h parent, iotcon_resource_h child)
+{
+       int ret;
+       int i;
+
+       RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+
+       ret = ic_ioty_unbind_res(parent->handle, child->handle);
+       if (IOTCON_ERROR_NONE == ret) {
+               for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+                       if (child == parent->children[i])
+                               parent->children[i] = NULL;
+               }
+       }
+       else
+               ERR("ic_ioty_unbind_res() Fail(%d)", ret);
 
        return ret;
 }
 
 
+API int iotcon_resource_get_number_of_children(iotcon_resource_h resource, int *number)
+{
+       int i;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == number, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *number = 0;
+       for (i = 0; i < IOTCON_CONTAINED_RESOURCES_MAX; i++) {
+               if (resource->children[i])
+                       *number += 1;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_get_nth_child(iotcon_resource_h parent, int index,
+               iotcon_resource_h *child)
+{
+       RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+       if ((index < 0) || (IOTCON_CONTAINED_RESOURCES_MAX <= index)) {
+               ERR("Invalid index(%d)", index);
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       *child = parent->children[index];
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_resource_get_uri(iotcon_resource_h resource, char **uri)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *uri = resource->uri;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_resource_get_host(iotcon_resource_h resource, char **host)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *host = resource->host;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_resource_get_types(iotcon_resource_h resource, iotcon_resource_types_h *types)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *types = resource->types;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *ifaces = resource->ifaces;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_resource_is_observable(iotcon_resource_h resource, bool *observable)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == observable, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *observable = resource->is_observable;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
 API int iotcon_start_presence(unsigned int time_to_live)
 {
        FN_CALL;
@@ -227,7 +365,7 @@ API int iotcon_stop_presence()
 }
 
 
-/* The length of resource_type should be less than and equal to 61. */
+/* The length of resource_type should be less than or equal to 61. */
 API iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
                const char *resource_type, iotcon_presence_cb cb, void *user_data)
 {
index b58bcbfd5b9e17e985e4da6c4c4fb35a8c8f0af7..d97e96fac836c2d22c8fb7dc2eca4889cb5be291 100755 (executable)
--- a/lib/ic.h
+++ b/lib/ic.h
 
 #include "iotcon.h"
 
-typedef struct _resource_s {
+#define IC_INTERFACE_MAX (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | \
+               IOTCON_INTERFACE_BATCH | IOTCON_INTERFACE_GROUP)
+
+struct ic_resource {
+       char *uri;
+       char *host;
+       bool is_observable;
+       iotcon_resource_types_h types;
+       int ifaces;
        void *handle;
        iotcon_request_handler_cb cb;
        void *user_data;
-} ic_resource_s;
+       iotcon_resource_h children[IOTCON_CONTAINED_RESOURCES_MAX];
+};
 
 struct ic_notify_msg {
        int error_code;
@@ -30,6 +39,6 @@ struct ic_notify_msg {
        iotcon_repr_h repr;
 };
 
-ic_resource_s* ic_get_resource_handler_data(void *handle);
+iotcon_resource_h ic_get_resource_handler_data(void *handle);
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__ */
index 0b0fd12f2f2293e1dd37fb3df682a6b68739ff62..d05317d80d33ff64bc3c76e1eff10cc8ff814ff9 100755 (executable)
@@ -42,9 +42,7 @@
 #define IOTCON_MANUFACTURER_NAME_LENGTH_MAX 15
 #define IOTCON_MANUFACTURER_URL_LENGTH_MAX 32
 
-/* TODO
 #define IOTCON_CONTAINED_RESOURCES_MAX 5
-*/
 
 #define IOTCON_FUNC_STOP 0
 #define IOTCON_FUNC_CONTINUE 1
@@ -74,7 +72,6 @@ typedef enum {
        IOTCON_INTERFACE_LINK = (1 << 1), /* discovers children of the parent resource */
        IOTCON_INTERFACE_BATCH = (1 << 2), /* requests CRUD to children of the parent resource */
        IOTCON_INTERFACE_GROUP = (1 << 3), /* requests CRUD to remote resources of a group. */
-       IOTCON_INTERFACE_MAX = (1 << 4)
 } iotcon_interface_e;
 
 typedef enum {
@@ -96,11 +93,12 @@ typedef enum {
 } iotcon_response_property_e;
 
 typedef enum {
-       IOTCON_NO_FLAG = 0,
-       IOTCON_INIT_FLAG = (1 << 0),
-       IOTCON_CRUD_FLAG = (1 << 1),
-       IOTCON_OBSERVE_FLAG = (1 << 2)
-} iotcon_request_handler_flag_e;
+       IOTCON_REQUEST_GET = (1 << 0),
+       IOTCON_REQUEST_PUT = (1 << 1),
+       IOTCON_REQUEST_POST = (1 << 2),
+       IOTCON_REQUEST_DELETE = (1 << 3),
+       IOTCON_REQUEST_OBSERVE = (1 << 4),
+} iotcon_request_type_e;
 
 typedef enum {
        IOTCON_RESPONSE_RESULT_OK = 0,
index 0055809a7b0b0530def153d55c0a3560a96d9391..5a044b9fe01262395470ebf2b043e35221d244ea 100755 (executable)
@@ -37,6 +37,7 @@ typedef enum
        IOTCON_ERROR_IOTIVITY = TIZEN_ERROR_IOTCON | 0x01, /**< Iotivity errors */
        IOTCON_ERROR_REPRESENTATION = TIZEN_ERROR_IOTCON | 0x02, /**< Representation errors */
        IOTCON_ERROR_INVALID_TYPE = TIZEN_ERROR_IOTCON | 0x03, /**< Invalid type */
+       IOTCON_ERROR_ALREADY = TIZEN_ERROR_IOTCON | 0x04, /**< Already */
 }iotcon_error_e;
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_ERRORS_H__ */
index 11edcce3ef84ba7ee1fa8fe727db1bceef60e76b..2317acaf9609a770132da8527e29b1e95b5e7872 100755 (executable)
@@ -55,8 +55,8 @@ int iotcon_repr_get_uri(iotcon_repr_h repr, const char **uri);
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  */
-int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_str_list_s *types);
-int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_str_list_s **types);
+int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_resource_types_h types);
+int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resource_types_h *types);
 
 int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces);
 int iotcon_repr_get_resource_interfaces(iotcon_repr_h repr);
@@ -108,7 +108,8 @@ int iotcon_repr_foreach_children(iotcon_repr_h parent, iotcon_children_fn fn,
 unsigned int iotcon_repr_get_children_count(iotcon_repr_h parent);
 int iotcon_repr_get_nth_child(iotcon_repr_h parent, int pos, iotcon_repr_h *child);
 
-iotcon_str_list_s* iotcon_repr_get_key_list(iotcon_repr_h repr);
+typedef int (*iotcon_repr_key_fn)(iotcon_repr_h repr, const char *key, void *user_data);
+int iotcon_repr_foreach_keys(iotcon_repr_h repr, iotcon_repr_key_fn fn, void *user_data);
 int iotcon_repr_get_keys_count(iotcon_repr_h repr);
 
 char* iotcon_repr_generate_json(iotcon_repr_h repr);
index a2ed4d06cb6e2b6b99e7893c1e6d14c4244602c8..1a951518fb10db687c39eb97d0c1606a33f6caad 100755 (executable)
@@ -16,7 +16,6 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_H__
 #define __IOT_CONNECTIVITY_MANAGER_STRUCT_H__
 
-#include <stdint.h>
 #include <stdbool.h>
 
 #include "iotcon-constant.h"
@@ -25,15 +24,24 @@ typedef struct ic_value_s* iotcon_value_h;
 typedef struct ic_list_s* iotcon_list_h;
 typedef struct ic_repr_s* iotcon_repr_h;
 
-typedef struct _resource_s* iotcon_resource_h;
 typedef struct ic_notify_msg* iotcon_notimsg_h;
 
 typedef void* iotcon_presence_h;
 
-typedef struct _str_list {
-       char *string;
-       struct _str_list *next;
-} iotcon_str_list_s;
+typedef struct _device_info {
+       char *name;
+       char *host_name;
+       char *uuid;
+       char *content_type;
+       char *version;
+       char *manuf_name;
+       char *manuf_url;
+       char *model_number;
+       char *date_of_manufacture;
+       char *platform_ver;
+       char *firmware_ver;
+       char *support_url;
+} iotcon_device_info_s;
 
 
 typedef struct ic_options* iotcon_options_h;
@@ -61,69 +69,64 @@ int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
                void *user_data);
 iotcon_query_h iotcon_query_clone(iotcon_query_h query);
 
+
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
+ * @brief Appends resource type to list.
+ * @since_tizen 3.0
+ * @remarks  Duplicate resource types are not allowed.
+ *
+ * @param[in] res_types The handle to the list
+ * @param[in] type The resource type
+ *
+ * @return the (possibly changed) start of the list, otherwise a null pointer on failure
+ */
+typedef struct ic_resource_types* iotcon_resource_types_h;
+iotcon_resource_types_h iotcon_resource_types_new();
+void iotcon_resource_types_free(iotcon_resource_types_h types);
+int iotcon_resource_types_insert(iotcon_resource_types_h types, const char *type);
+int iotcon_resource_types_delete(iotcon_resource_types_h types, const char *type);
+typedef int (*iotcon_resource_types_foreach_cb)(const char *type, void *user_data);
+int iotcon_resource_types_foreach(iotcon_resource_types_h types,
+               iotcon_resource_types_foreach_cb cb, void *user_data);
+iotcon_resource_types_h iotcon_resource_types_clone(iotcon_resource_types_h types);
+
+
 typedef void* iotcon_observers_h;
 void iotcon_observers_free(iotcon_observers_h observers);
-iotcon_observers_h iotcon_observers_append(iotcon_observers_h observers, uint8_t obs_id);
-iotcon_observers_h iotcon_observers_remove(iotcon_observers_h observers, uint8_t obs_id);
+iotcon_observers_h iotcon_observers_append(iotcon_observers_h observers, int obs_id);
+iotcon_observers_h iotcon_observers_remove(iotcon_observers_h observers, int obs_id);
+
+typedef struct ic_resource* iotcon_resource_h;
+int iotcon_resource_get_number_of_children(iotcon_resource_h resource, int *number);
+int iotcon_resource_get_nth_child(iotcon_resource_h parent, int index,
+               iotcon_resource_h *child);
+int iotcon_resource_get_uri(iotcon_resource_h resource, char **uri);
+int iotcon_resource_get_host(iotcon_resource_h resource, char **host);
+int iotcon_resource_get_types(iotcon_resource_h resource, iotcon_resource_types_h *types);
+int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces);
+int iotcon_resource_is_observable(iotcon_resource_h resource, bool *observable);
 
 typedef struct ic_remote_resource* iotcon_client_h;
-const char* iotcon_client_get_uri(iotcon_client_h resource);
-const char* iotcon_client_get_host(iotcon_client_h resource);
-iotcon_str_list_s* iotcon_client_get_types(iotcon_client_h resource);
-int iotcon_client_get_interfaces(iotcon_client_h resource);
-int iotcon_client_set_options(iotcon_client_h resource,
-               iotcon_options_h header_options);
+int iotcon_client_get_uri(iotcon_client_h resource, char **uri);
+int iotcon_client_get_host(iotcon_client_h resource, char **host);
+int iotcon_client_get_types(iotcon_client_h resource, iotcon_resource_types_h *types);
+int iotcon_client_get_interfaces(iotcon_client_h resource, int *ifaces);
+int iotcon_client_is_observable(iotcon_client_h resource, bool *observable);
+int iotcon_client_set_options(iotcon_client_h resource, iotcon_options_h header_options);
 
 typedef struct ic_resource_request* iotcon_request_h;
-iotcon_repr_h iotcon_request_get_representation(iotcon_request_h request);
-const char* iotcon_request_get_request_type(iotcon_request_h request);
-int iotcon_request_get_request_handler_flag(iotcon_request_h request);
-iotcon_options_h iotcon_request_get_options(iotcon_request_h request);
-iotcon_query_h iotcon_request_get_query(iotcon_request_h request);
-iotcon_observe_action_e iotcon_request_get_observer_action(iotcon_request_h request);
-uint8_t iotcon_request_get_observer_id(iotcon_request_h request);
+int iotcon_request_get_representation(iotcon_request_h request, iotcon_repr_h *repr);
+int iotcon_request_get_types(iotcon_request_h request, int *types);
+int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *options);
+int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query);
+int iotcon_request_get_observer_action(iotcon_request_h request,
+               iotcon_observe_action_e *action);
+int iotcon_request_get_observer_id(iotcon_request_h request, int *observer_id);
 
 typedef struct ic_resource_response* iotcon_response_h;
 iotcon_response_h iotcon_response_new(iotcon_request_h request_h);
 void iotcon_response_free(iotcon_response_h resp);
 int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop, ...);
 
-typedef struct ic_device_info* iotcon_device_info_h;
-const char* iotcon_device_info_get_device_name(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_host_name(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_device_uuid(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_content_type(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_version(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_manufacturer_name(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_manufacturer_url(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_model_number(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_date_of_manufacture(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_platform_version(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_firmware_version(iotcon_device_info_h device_info);
-const char* iotcon_device_info_get_support_url(iotcon_device_info_h device_info);
-
-void iotcon_str_list_free(iotcon_str_list_s *str_list);
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
- * @brief Appends string value to list.
- * @since_tizen 3.0
- * @remarks  Duplicate strings are not allowed.
- *
- * @param[in] str_list The handle to the list
- * @param[in] string The string
- *
- * @return the (possibly changed) start of the list, otherwise a null pointer on failure
- */
-iotcon_str_list_s* iotcon_str_list_append(iotcon_str_list_s *str_list,
-               const char *string);
-iotcon_str_list_s* iotcon_str_list_remove(iotcon_str_list_s *str_list,
-               const char *string);
-iotcon_str_list_s* iotcon_str_list_clone(iotcon_str_list_s *str_list);
-unsigned int iotcon_str_list_length(iotcon_str_list_s *str_list);
-typedef int (*iotcon_string_foreach_cb)(const char *string, void *user_data);
-int iotcon_str_list_foreach(iotcon_str_list_s *str_list, iotcon_string_foreach_cb cb,
-               void *user_data);
-const char* iotcon_str_list_nth_data(iotcon_str_list_s *str_list, unsigned int n);
-
 #endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_H__ */
index b2368dd73bcab18abf559dfc708e206f6135cc48..78cf56c59fe7dee1ec351bf22c2615d76844975a 100755 (executable)
@@ -31,7 +31,7 @@ void iotcon_deinitialize();
 
 typedef void (*iotcon_request_handler_cb)(iotcon_request_h request, void *user_data);
 iotcon_resource_h iotcon_register_resource(const char *uri,
-               iotcon_str_list_s *res_types,
+               iotcon_resource_types_h res_types,
                int ifaces,
                uint8_t properties,
                iotcon_request_handler_cb cb,
@@ -42,22 +42,12 @@ int iotcon_bind_interface(iotcon_resource_h resource,
                iotcon_interface_e iface);
 int iotcon_bind_type(iotcon_resource_h resource_handle,
                const char *resource_type);
+int iotcon_bind_request_handler(iotcon_resource_h resource, iotcon_request_handler_cb cb);
 int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child);
+int iotcon_unbind_resource(iotcon_resource_h parent, iotcon_resource_h child);
 
-int iotcon_register_device_info(
-               char *device_name,
-               char *host_name,
-               char *device_uuid,
-               char *content_type,
-               char *version,
-               char *manufacturer_name,
-               char *manufacturer_url,
-               char *model_number,
-               char *date_of_manufacture,
-               char *platform_version,
-               char *firmware_version,
-               char *support_url);
-typedef void (*iotcon_device_info_cb)(iotcon_device_info_h info, void *user_data);
+int iotcon_register_device_info(iotcon_device_info_s device_info);
+typedef void (*iotcon_device_info_cb)(iotcon_device_info_s info, void *user_data);
 int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
                void *user_data);
 
@@ -75,7 +65,7 @@ typedef void (*iotcon_found_resource_cb)(iotcon_client_h resource, void *user_da
 int iotcon_find_resource(const char *host_address, const char *resource_type,
                iotcon_found_resource_cb cb, void *user_data);
 iotcon_client_h iotcon_client_new(const char *host, const char *uri, bool is_observable,
-               iotcon_str_list_s *resource_types, iotcon_interface_e resource_interfaces);
+               iotcon_resource_types_h resource_types, int resource_interfaces);
 void iotcon_client_free(iotcon_client_h resource);
 iotcon_client_h iotcon_client_clone(iotcon_client_h resource);
 
index 00f60131e5d275fba58ebaf7bf91d6b02117fbb2..9b3aeddf0a7cf3b1e393b5c93f6ea48aee4bb468 100755 (executable)
@@ -54,8 +54,12 @@ static void _on_delete(iotcon_options_h header_options, int response_result,
 static void _on_post(iotcon_options_h header_options, iotcon_repr_h recv_repr,
                int response_result, void *user_data)
 {
+       int ret;
        char *created_uri = NULL;
        iotcon_client_h new_door_resource = NULL;
+       char *host = NULL;
+       iotcon_resource_types_h types = NULL;
+       int ifaces = 0;
 
        RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
                        && IOTCON_RESPONSE_RESULT_RESOURCE_CREATED != response_result,
@@ -65,19 +69,35 @@ static void _on_post(iotcon_options_h header_options, iotcon_repr_h recv_repr,
        _print_repr_info(recv_repr);
 
        iotcon_repr_get_str(recv_repr, "createduri", &created_uri);
-       if (created_uri) {
-               DBG("New resource created : %s", created_uri);
 
-               new_door_resource = iotcon_client_new(
-                               iotcon_client_get_host(door_resource),
-                               created_uri,
-                               true,
-                               iotcon_client_get_types(door_resource),
-                               iotcon_client_get_interfaces(door_resource));
+       if (NULL == created_uri) {
+               ERR("created_uri is NULL");
+               return;
+       }
+
+       DBG("New resource created : %s", created_uri);
 
-               iotcon_delete(new_door_resource, _on_delete, NULL);
+       ret = iotcon_client_get_host(door_resource, &host);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_host() Fail(%d)", ret);
+               return;
        }
 
+       ret = iotcon_client_get_types(door_resource, &types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_types() Fail(%d)", ret);
+               return;
+       }
+
+       ret = iotcon_client_get_interfaces(door_resource, &ifaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_ifaces() Fail(%d)", ret);
+               return;
+       }
+
+       new_door_resource = iotcon_client_new(host, created_uri, true, types, ifaces);
+
+       iotcon_delete(new_door_resource, _on_delete, NULL);
 }
 
 static void _on_put(iotcon_options_h header_options, iotcon_repr_h recv_repr,
@@ -141,57 +161,71 @@ static void _presence_handler(int result, unsigned int nonce,
 static void _found_resource(iotcon_client_h resource, void *user_data)
 {
        int ret;
-       const char *resource_uri = NULL;
-       const char *resource_host = NULL;
-       iotcon_str_list_s *resource_types = NULL;
+       char *resource_uri = NULL;
+       char *resource_host = NULL;
+       iotcon_resource_types_h resource_types = NULL;
        int resource_interfaces = 0;
 
-       if (resource) {
-               INFO("===== resource found =====");
-
-               /* get the resource URI */
-               resource_uri = iotcon_client_get_uri(resource);
-               if (NULL == resource_uri) {
-                       ERR("uri is NULL");
-                       return;
-               }
-
-               /* get the resource host address */
-               resource_host = iotcon_client_get_host(resource);
-               DBG("[%s] resource host : %s", resource_uri, resource_host);
-
-               /* get the resource interfaces */
-               resource_interfaces = iotcon_client_get_interfaces(resource);
-               if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
-                       DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri);
-               if (IOTCON_INTERFACE_LINK & resource_interfaces)
-                       DBG("[%s] resource interface : LINK_INTERFACE", resource_uri);
-               if (IOTCON_INTERFACE_BATCH & resource_interfaces)
-                       DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri);
-               if (IOTCON_INTERFACE_GROUP & resource_interfaces)
-                       DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri);
-
-               /* get the resource types */
-               resource_types = iotcon_client_get_types(resource);
-               ret = iotcon_str_list_foreach(resource_types, _get_res_type_fn,
-                               (void *)resource_uri);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_str_list_foreach() Fail(%d)", ret);
-                       return;
-               }
-
-               iotcon_subscribe_presence(resource_host, "core.door", _presence_handler, NULL);
-
-               if (!strcmp(door_uri, resource_uri)) {
-                       door_resource = iotcon_client_clone(resource);
-
-                       iotcon_query_h query = iotcon_query_new();
-                       iotcon_query_insert(query, "key", "value");
-
-                       /* send GET Request */
-                       iotcon_get(resource, query, _on_get, NULL);
-                       iotcon_query_free(query);
-               }
+       if (NULL == resource)
+               return;
+
+       INFO("===== resource found =====");
+
+       /* get the resource URI */
+       ret = iotcon_client_get_uri(resource, &resource_uri);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_uri() Fail(%d)", ret);
+               return;
+       }
+
+       /* get the resource host address */
+       ret = iotcon_client_get_host(resource, &resource_host);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_host() Fail(%d)", ret);
+               return;
+       }
+       DBG("[%s] resource host : %s", resource_uri, resource_host);
+
+       /* get the resource interfaces */
+       ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_interfaces() Fail(%d)", ret);
+               return;
+       }
+       if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
+               DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri);
+       if (IOTCON_INTERFACE_LINK & resource_interfaces)
+               DBG("[%s] resource interface : LINK_INTERFACE", resource_uri);
+       if (IOTCON_INTERFACE_BATCH & resource_interfaces)
+               DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri);
+       if (IOTCON_INTERFACE_GROUP & resource_interfaces)
+               DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri);
+
+       /* get the resource types */
+       ret = iotcon_client_get_types(resource, &resource_types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_types() Fail(%d)", ret);
+               return;
+       }
+
+       ret = iotcon_resource_types_foreach(resource_types, _get_res_type_fn,
+                       resource_uri);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
+               return;
+       }
+
+       iotcon_subscribe_presence(resource_host, "core.door", _presence_handler, NULL);
+
+       if (!strcmp(door_uri, resource_uri)) {
+               door_resource = iotcon_client_clone(resource);
+
+               iotcon_query_h query = iotcon_query_new();
+               iotcon_query_insert(query, "key", "value");
+
+               /* send GET Request */
+               iotcon_get(resource, query, _on_get, NULL);
+               iotcon_query_free(query);
        }
 }
 
index 66710e95cc882adbe63aeabe3027854a7914dd23..7e5d46f5d24b7471b4996cd4792c06d0b60832a1 100755 (executable)
@@ -68,16 +68,25 @@ static void _check_door_state()
 static iotcon_resource_h _create_door_resource(char *uri, iotcon_interface_e interfaces,
                iotcon_resource_property_e properties)
 {
-       iotcon_str_list_s resource_types = {my_door.type, NULL};
+       iotcon_resource_types_h resource_types = iotcon_resource_types_new();
+       int ret = iotcon_resource_types_insert(resource_types, my_door.type);
+       if (IOTCON_ERROR_NONE != ret) {
+               iotcon_resource_types_free(resource_types);
+               ERR("iotcon_resource_types_insert() Fail(%d)", ret);
+               return NULL;
+       }
 
        /* register door resource */
-       iotcon_resource_h handle = iotcon_register_resource(uri, &resource_types,
+       iotcon_resource_h handle = iotcon_register_resource(uri, resource_types,
                        interfaces, properties, _request_handler, NULL);
        if (NULL == handle) {
+               iotcon_resource_types_free(resource_types);
                ERR("iotcon_register_resource() Fail");
                return NULL;
        }
 
+       iotcon_resource_types_free(resource_types);
+
        return handle;
 }
 
@@ -107,11 +116,16 @@ static void _request_handler_get(iotcon_response_h response)
 static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
 {
        bool bval;
+       int ret;
        iotcon_repr_h req_repr = NULL;
        iotcon_repr_h resp_repr = NULL;
        INFO("PUT request");
 
-       req_repr = iotcon_request_get_representation(request);
+       ret = iotcon_request_get_representation(request, &req_repr);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_representation() Fail(%d)", ret);
+               return;
+       }
        iotcon_repr_get_bool(req_repr, "opened", &bval);
        my_door.state = bval;
 
@@ -129,22 +143,24 @@ static void _request_handler_post(iotcon_response_h response)
        iotcon_repr_h resp_repr = NULL;
        INFO("POST request");
 
-       if (false == resource_created) {
-               new_door_handle = _create_door_resource("/a/door1", IOTCON_INTERFACE_DEFAULT,
-                               (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE));
-               if (NULL == new_door_handle) {
-                       ERR("_create_door_resource() Fail");
-                       return;
-               }
-               resource_created = true;
-
-               /* send information that new resource was created */
-               resp_repr = iotcon_repr_new();
-               iotcon_repr_set_str(resp_repr, "createduri", "/a/door1");
+       if (resource_created) {
+               INFO("Resource is already created");
+               return;
+       }
 
-               _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
+       new_door_handle = _create_door_resource("/a/door1", IOTCON_INTERFACE_DEFAULT,
+                       (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE));
+       if (NULL == new_door_handle) {
+               ERR("_create_door_resource() Fail");
+               return;
        }
+       resource_created = true;
+
+       /* send information that new resource was created */
+       resp_repr = iotcon_repr_new();
+       iotcon_repr_set_str(resp_repr, "createduri", "/a/door1");
 
+       _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
 }
 
 static gboolean _notifier(gpointer user_data)
@@ -187,50 +203,63 @@ static int _query_cb(const char *key, const char *value, void *user_data)
 
 static void _request_handler(iotcon_request_h request, void *user_data)
 {
-       const char *request_type = NULL;
-       int request_flag = IOTCON_INIT_FLAG;
-       iotcon_query_h query = NULL;
+       int ret;
+       int types;
+       iotcon_query_h query;
        iotcon_response_h response = NULL;
-       FN_CALL;
+       iotcon_observe_action_e observer_action;
+       int observer_id;
 
        RET_IF(NULL == request);
 
-       query = iotcon_request_get_query(request);
+       ret = iotcon_request_get_query(request, &query);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_query() Fail(%d)", ret);
+               return;
+       }
        if (query)
                iotcon_query_foreach(query, _query_cb, NULL);
 
-       request_type = iotcon_request_get_request_type(request);
-       if (NULL == request_type) {
-               ERR("request_type is NULL");
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_types() Fail(%d)", ret);
                return;
        }
 
-       request_flag = iotcon_request_get_request_handler_flag(request);
-       if (request_flag & IOTCON_CRUD_FLAG) {
-               response = iotcon_response_new(request);
-               if (NULL == response) {
-                       ERR("iotcon_response_new() Fail(NULL == response)");
-                       return;
-               }
+       response = iotcon_response_new(request);
+       if (NULL == response) {
+               ERR("iotcon_response_new() Fail(NULL == response)");
+               return;
+       }
 
-               if (!strcmp("GET", request_type))
-                       _request_handler_get(response);
+       if (IOTCON_REQUEST_GET & types)
+               _request_handler_get(response);
 
-               else if (!strcmp("PUT", request_type))
-                       _request_handler_put(request, response);
+       else if (IOTCON_REQUEST_PUT & types)
+               _request_handler_put(request, response);
 
-               else if (!strcmp("POST", request_type))
-                       _request_handler_post(response);
+       else if (IOTCON_REQUEST_POST & types)
+               _request_handler_post(response);
 
-               else if (!strcmp("DELETE", request_type))
-                       _request_handler_delete(response);
+       else if (IOTCON_REQUEST_DELETE & types)
+               _request_handler_delete(response);
 
-               iotcon_response_free(response);
-       }
-       if (request_flag & IOTCON_OBSERVE_FLAG) {
-               if (IOTCON_OBSERVE_REGISTER == iotcon_request_get_observer_action(request))
-                       observers = iotcon_observers_append(observers,
-                                       iotcon_request_get_observer_id(request));
+       iotcon_response_free(response);
+
+       if (IOTCON_REQUEST_OBSERVE & types) {
+               ret = iotcon_request_get_observer_action(request, &observer_action);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("iotcon_request_get_observer_action() Fail(%d)", ret);
+                       return;
+               }
+               if (IOTCON_OBSERVE_REGISTER == observer_action) {
+                       ret = iotcon_request_get_observer_id(request, &observer_id);
+                       if (IOTCON_ERROR_NONE != ret) {
+                               ERR("iotcon_request_get_observer_id() Fail(%d)", ret);
+                               return;
+                       }
+                       observers = iotcon_observers_append(observers, observer_id);
+               }
        }
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 8e0e756..69a25eb
@@ -2,20 +2,20 @@
 #include <iotcon.h>
 #include "test-log.h"
 
-static void _get_device_info(iotcon_device_info_h info, void *user_data)
+static void _get_device_info(iotcon_device_info_s info, void *user_data)
 {
-       INFO("device_name : %s", iotcon_device_info_get_device_name(info));
-       INFO("host_name : %s", iotcon_device_info_get_host_name(info));
-       INFO("device_uuid : %s", iotcon_device_info_get_device_uuid(info));
-       INFO("content_type : %s", iotcon_device_info_get_content_type(info));
-       INFO("version : %s", iotcon_device_info_get_version(info));
-       INFO("manufacturer_name : %s", iotcon_device_info_get_manufacturer_name(info));
-       INFO("manufacturer_url : %s", iotcon_device_info_get_manufacturer_url(info));
-       INFO("model_number : %s", iotcon_device_info_get_model_number(info));
-       INFO("date_of_manufacture : %s", iotcon_device_info_get_date_of_manufacture(info));
-       INFO("platform_version : %s", iotcon_device_info_get_platform_version(info));
-       INFO("firmware_version : %s", iotcon_device_info_get_firmware_version(info));
-       INFO("support_url : %s", iotcon_device_info_get_support_url(info));
+       INFO("name : %s", info.name);
+       INFO("host_name : %s", info.host_name);
+       INFO("uuid : %s", info.uuid);
+       INFO("content_type : %s", info.content_type);
+       INFO("version : %s", info.version);
+       INFO("manuf_name : %s", info.manuf_name);
+       INFO("manuf_url : %s", info.manuf_url);
+       INFO("model_number : %s", info.model_number);
+       INFO("date_of_manufacture : %s", info.date_of_manufacture);
+       INFO("platform_ver : %s", info.platform_ver);
+       INFO("firmware_ver : %s", info.firmware_ver);
+       INFO("support_url : %s", info.support_url);
 }
 
 int main()
old mode 100644 (file)
new mode 100755 (executable)
index ba62a70..324c4e7
@@ -7,35 +7,26 @@ int main()
        int ret;
        GMainLoop *loop;
 
-       char *device_name = "device_name";
-       char *host_name = "host_name";
-       char *device_uuid = "device_uuid";
-       char *content_type = "content_type";
-       char *version = "version";
-       char *manufacturer_name = "manuf_name";
-       char *manufacturer_url = "manuf_url";
-       char *model_number = "model_number";
-       char *date_of_manufacture = "date_of_manufacture";
-       char *platform_version = "platform_version";
-       char *firmware_version = "firmware_version";
-       char *support_url = "support_url";
+       iotcon_device_info_s device_info = {0};
+
+       device_info.name = "device_name";
+       device_info.host_name = "host_name";
+       device_info.uuid = "device_uuid";
+       device_info.content_type = "content_type";
+       device_info.version = "version";
+       device_info.manuf_name = "manuf_name";
+       device_info.manuf_url = "manuf_url";
+       device_info.model_number = "model_number";
+       device_info.date_of_manufacture = "date_of_manufacture";
+       device_info.platform_ver = "platform_version";
+       device_info.firmware_ver = "firmware_version";
+       device_info.support_url = "support_url";
 
        loop = g_main_loop_new(NULL, FALSE);
 
        iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
 
-       ret = iotcon_register_device_info(device_name,
-                       host_name,
-                       device_uuid,
-                       content_type,
-                       version,
-                       manufacturer_name,
-                       manufacturer_url,
-                       model_number,
-                       date_of_manufacture,
-                       platform_version,
-                       firmware_version,
-                       support_url);
+       ret = iotcon_register_device_info(device_info);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_register_device_info() Fail(%d)", ret);
                return -1;
old mode 100644 (file)
new mode 100755 (executable)
index 584d94f..e00afec
@@ -35,11 +35,11 @@ static int _get_int_list_fn(int pos, const int value, void *user_data)
 static void _on_get(iotcon_repr_h recv_repr, int response_result)
 {
        int i, ret;
+       int key_count;
        unsigned int children_count;
        const char *uri;
        iotcon_repr_h child_repr;
        iotcon_list_h list;
-       iotcon_str_list_s *key_list = NULL;
 
        RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result,
                        "_on_get Response error(%d)", response_result);
@@ -49,8 +49,8 @@ static void _on_get(iotcon_repr_h recv_repr, int response_result)
        iotcon_repr_get_uri(recv_repr, &uri);
        if (uri)
                DBG("uri : %s", uri);
-       key_list = iotcon_repr_get_key_list(recv_repr);
-       if (key_list) {
+       key_count = iotcon_repr_get_keys_count(recv_repr);
+       if (key_count) {
                char *str;
                iotcon_repr_get_str(recv_repr, "name", &str);
                if (str)
@@ -60,7 +60,6 @@ static void _on_get(iotcon_repr_h recv_repr, int response_result)
 
                DBG("today's temperature :");
                iotcon_list_foreach_int(list, _get_int_list_fn, NULL);
-               iotcon_str_list_free(key_list);
 
                if (iotcon_repr_is_null(recv_repr, "null value"))
                        DBG("null value is null");
@@ -83,21 +82,19 @@ static void _on_get(iotcon_repr_h recv_repr, int response_result)
                        DBG("uri : %s", uri);
 
                if (!strcmp("/a/light", uri)) {
-                       key_list = iotcon_repr_get_key_list(child_repr);
-                       if (key_list) {
+                       key_count = iotcon_repr_get_keys_count(child_repr);
+                       if (key_count) {
                                int brightness;
                                iotcon_repr_get_int(child_repr, "brightness", &brightness);
                                DBG("brightness : %d", brightness);
-                               iotcon_str_list_free(key_list);
                        }
                }
                else if (!strcmp("/a/switch", uri)) {
-                       key_list = iotcon_repr_get_key_list(child_repr);
-                       if (key_list) {
+                       key_count = iotcon_repr_get_keys_count(child_repr);
+                       if (key_count) {
                                bool bswitch;
                                iotcon_repr_get_bool(child_repr, "switch", &bswitch);
                                DBG("switch : %d", bswitch);
-                               iotcon_str_list_free(key_list);
                        }
                }
        }
@@ -136,52 +133,61 @@ static int _get_res_type_fn(const char *string, void *user_data)
 
 static void _found_resource(iotcon_client_h resource, void *user_data)
 {
-       const char *resource_uri;
-       const char *resource_host;
-       iotcon_str_list_s *resource_types = NULL;
+       int ret;
+       char *resource_uri;
+       char *resource_host;
+       iotcon_resource_types_h resource_types = NULL;
        int resource_interfaces = 0;
 
-       if (resource) {
-               INFO("===== resource found =====");
+       if (NULL == resource)
+               return;
 
-               /* get the resource URI */
-               resource_uri = iotcon_client_get_uri(resource);
-               if (NULL == resource_uri) {
-                       ERR("uri is NULL");
-                       return;
-               }
-
-               /* get the resource host address */
-               resource_host = iotcon_client_get_host(resource);
-               DBG("[%s] resource host : %s", resource_uri, resource_host);
+       INFO("===== resource found =====");
 
-               /* get the resource interfaces */
-               resource_interfaces = iotcon_client_get_interfaces(resource);
-
-               if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
-                       DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri);
-               if (IOTCON_INTERFACE_LINK & resource_interfaces)
-                       DBG("[%s] resource interface : LINK_INTERFACE", resource_uri);
-               if (IOTCON_INTERFACE_BATCH & resource_interfaces)
-                       DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri);
-               if (IOTCON_INTERFACE_GROUP & resource_interfaces)
-                       DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri);
+       /* get the resource URI */
+       ret = iotcon_client_get_uri(resource, &resource_uri);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_uri() Fail(%d)", ret);
+               return;
+       }
 
-               /* get the resource types */
-               resource_types = iotcon_client_get_types(resource);
-               iotcon_str_list_foreach(resource_types, _get_res_type_fn, (void *)resource_uri);
+       /* get the resource host address */
+       ret = iotcon_client_get_host(resource, &resource_host);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_host() Fail(%d)", ret);
+               return;
+       }
+       DBG("[%s] resource host : %s", resource_uri, resource_host);
 
-               if (!strcmp(room_uri, resource_uri)) {
-                       iotcon_query_h query_params;
-                       /* copy resource to use elsewhere */
-                       room_resource = iotcon_client_clone(resource);
+       /* get the resource interfaces */
+       ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_interfaces() Fail(%d)", ret);
+               return;
+       }
+       if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
+               DBG("[%s] resource interface : DEFAULT_INTERFACE", resource_uri);
+       if (IOTCON_INTERFACE_LINK & resource_interfaces)
+               DBG("[%s] resource interface : LINK_INTERFACE", resource_uri);
+       if (IOTCON_INTERFACE_BATCH & resource_interfaces)
+               DBG("[%s] resource interface : BATCH_INTERFACE", resource_uri);
+       if (IOTCON_INTERFACE_GROUP & resource_interfaces)
+               DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri);
+
+       /* get the resource types */
+       ret = iotcon_client_get_types(resource, &resource_types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_client_get_types() Fail(%d)", ret);
+               return;
+       }
+       iotcon_resource_types_foreach(resource_types, _get_res_type_fn, (void*)resource_uri);
 
-                       query_params = iotcon_query_new();
-                       /* send GET request */
-                       iotcon_get(resource, query_params, _on_get_1st, NULL);
+       if (!strcmp(room_uri, resource_uri)) {
+               /* copy resource to use elsewhere */
+               room_resource = iotcon_client_clone(resource);
 
-                       iotcon_query_free(query_params);
-               }
+               /* send GET request */
+               iotcon_get(resource, NULL, _on_get_1st, NULL);
        }
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 177d39c..e347ab2
@@ -59,6 +59,7 @@ static int _query_foreach_cb(const char *key, const char *value, void *user_data
 static void _room_request_handler_get(iotcon_request_h request,
                iotcon_response_h response)
 {
+       int ret;
        iotcon_repr_h room_repr;
        iotcon_repr_h light_repr;
        iotcon_repr_h switch_repr;
@@ -102,8 +103,13 @@ static void _room_request_handler_get(iotcon_request_h request,
        iotcon_repr_free(light_repr);
        iotcon_repr_free(switch_repr);
 
-       query = iotcon_request_get_query(request);
-       iotcon_query_foreach(query, _query_foreach_cb, &query_str);
+       ret = iotcon_request_get_query(request, &query);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_query() Fail(%d)", ret);
+               return;
+       }
+       if (query)
+               iotcon_query_foreach(query, _query_foreach_cb, &query_str);
 
        if (query_str && !strcmp("oc.mi.b", query_str)) {
                DBG("operation for BATCH interface");
@@ -160,97 +166,93 @@ static void _request_handler_delete(iotcon_response_h response)
 
 static void _light_request_handler(iotcon_request_h request, void *user_data)
 {
-       const char *request_type = NULL;
-       int request_flag = IOTCON_INIT_FLAG;
+       int ret;
+       int types;
        iotcon_response_h response;
        FN_CALL;
 
        RET_IF(NULL == request);
 
-       request_type = iotcon_request_get_request_type(request);
-       if (NULL == request_type) {
-               ERR("request_type is NULL");
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_types() Fail(%d)", ret);
                return;
        }
 
-       request_flag = iotcon_request_get_request_handler_flag(request);
-       if (request_flag & IOTCON_CRUD_FLAG) {
-               response = iotcon_response_new(request);
-               if (NULL == response) {
-                       ERR("iotcon_response_new() Fail");
-                       return;
+       response = iotcon_response_new(request);
+       if (NULL == response) {
+               ERR("iotcon_response_new() Fail");
+               return;
                }
 
-               if (!strcmp("GET", request_type))
-                       _light_request_handler_get(response);
+       if (IOTCON_REQUEST_GET & types)
+               _light_request_handler_get(response);
 
-               else if (!strcmp("PUT", request_type))
-                       _request_handler_put(request, response);
+       else if (IOTCON_REQUEST_PUT & types)
+               _request_handler_put(request, response);
 
-               else if (!strcmp("POST", request_type))
-                       _request_handler_post(response);
+       else if (IOTCON_REQUEST_POST & types)
+               _request_handler_post(response);
 
-               else if (!strcmp("DELETE", request_type))
-                       _request_handler_delete(response);
+       else if (IOTCON_REQUEST_DELETE & types)
+               _request_handler_delete(response);
 
-               iotcon_response_free(response);
-       }
+       iotcon_response_free(response);
 }
 
 static void _room_request_handler(iotcon_request_h request, void *user_data)
 {
-       const char *request_type = NULL;
-       int request_flag = IOTCON_INIT_FLAG;
+       int ret;
+       int types;
        iotcon_response_h response;
        FN_CALL;
 
        RET_IF(NULL == request);
 
-       request_type = iotcon_request_get_request_type(request);
-       if (NULL == request_type) {
-               ERR("request_type is NULL");
+       ret = iotcon_request_get_types(request, &types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_types() Fail(%d)", ret);
                return;
        }
 
-       request_flag = iotcon_request_get_request_handler_flag(request);
-       if (request_flag & IOTCON_CRUD_FLAG) {
-               response = iotcon_response_new(request);
-               if (NULL == response) {
-                       ERR("iotcon_response_new() Fail");
-                       return;
+       response = iotcon_response_new(request);
+       if (NULL == response) {
+               ERR("iotcon_response_new() Fail");
+               return;
                }
 
-               if (!strcmp("GET", request_type))
-                       _room_request_handler_get(request, response);
+       if (IOTCON_REQUEST_GET & types)
+               _room_request_handler_get(request, response);
 
-               else if (!strcmp("PUT", request_type))
-                       _request_handler_put(request, response);
+       else if (IOTCON_REQUEST_PUT & types)
+               _request_handler_put(request, response);
 
-               else if (!strcmp("POST", request_type))
-                       _request_handler_post(response);
+       else if (IOTCON_REQUEST_POST & types)
+               _request_handler_post(response);
 
-               else if (!strcmp("DELETE", request_type))
-                       _request_handler_delete(response);
+       else if (IOTCON_REQUEST_DELETE & types)
+               _request_handler_delete(response);
 
-               iotcon_response_free(response);
-       }
+       iotcon_response_free(response);
 }
 
 int main(int argc, char **argv)
 {
        FN_CALL;
        GMainLoop *loop;
-       iotcon_str_list_s room_rtypes = {strdup("core.room"), NULL};
-       iotcon_str_list_s light_rtypes = {strdup("core.light"), NULL};
+       iotcon_resource_types_h room_rtypes = NULL;
+       iotcon_resource_types_h light_rtypes = NULL;
        iotcon_error_e iotcon_error = IOTCON_ERROR_NONE;
 
        loop = g_main_loop_new(NULL, FALSE);
 
        /* initialize address and port */
-       iotcon_initialize("0.0.0.0", 0);
+       iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
 
        /* register room resource */
-       iotcon_resource_h room_handle = iotcon_register_resource("/a/room", &room_rtypes,
+       room_rtypes = iotcon_resource_types_new();
+       iotcon_resource_types_insert(room_rtypes, "core.room");
+       iotcon_resource_h room_handle = iotcon_register_resource("/a/room", room_rtypes,
                        (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
                        (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _room_request_handler,
                        NULL);
@@ -260,7 +262,9 @@ int main(int argc, char **argv)
        }
 
        /* register room resource */
-       iotcon_resource_h light_handle = iotcon_register_resource("/a/light", &light_rtypes,
+       light_rtypes = iotcon_resource_types_new();
+       iotcon_resource_types_insert(light_rtypes, "core.light");
+       iotcon_resource_h light_handle = iotcon_register_resource("/a/light", light_rtypes,
                        (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
                        (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _light_request_handler,
                        NULL);