(1) Encapsulate structures (2) Add macro(well known address)
authoryoungman <yman.jung@samsung.com>
Tue, 19 May 2015 13:35:55 +0000 (22:35 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 8 Jun 2015 10:40:37 +0000 (19:40 +0900)
Change-Id: Icb01f4d785b9ba604ac7c66d93dea03208c774fc
Signed-off-by: youngman <yman.jung@samsung.com>
30 files changed:
.gitignore
lib/ic-client.c [new file with mode: 0755]
lib/ic-device.c [new file with mode: 0755]
lib/ic-handler.c [deleted file]
lib/ic-ioty-repr.cpp
lib/ic-ioty.cpp [changed mode: 0644->0755]
lib/ic-ioty.h
lib/ic-observation.c [new file with mode: 0644]
lib/ic-options.c
lib/ic-options.h
lib/ic-query.c [new file with mode: 0644]
lib/ic-repr-list.c [changed mode: 0644->0755]
lib/ic-repr-obj.c
lib/ic-repr-value.c
lib/ic-repr.c
lib/ic-request.c [new file with mode: 0755]
lib/ic-response.c [new file with mode: 0755]
lib/ic-struct.h [changed mode: 0644->0755]
lib/ic-utils.c [changed mode: 0644->0755]
lib/ic-utils.h
lib/ic.c [changed mode: 0644->0755]
lib/ic.h [moved from lib/ic-handler.h with 73% similarity]
lib/include/iotcon-constant.h
lib/include/iotcon-representation.h [changed mode: 0644->0755]
lib/include/iotcon-struct.h [changed mode: 0644->0755]
lib/include/iotcon.h [changed mode: 0644->0755]
packaging/iotcon.spec
test/CMakeLists.txt
test/crud-test-client.c [changed mode: 0644->0755]
test/crud-test-server.c

index de565f4..a5f168c 100644 (file)
@@ -1,3 +1,5 @@
 cscope.out
 *~
 *.sw*
+.cproject
+.project
diff --git a/lib/ic-client.c b/lib/ic-client.c
new file mode 100755 (executable)
index 0000000..2757f17
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * 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 <errno.h>
+#include <glib.h>
+
+#include "iotcon-struct.h"
+#include "ic-common.h"
+#include "ic-utils.h"
+#include "ic-struct.h"
+#include "ic-options.h"
+#include "ic-ioty.h"
+
+/* host address should begin with "coap://"
+ * 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)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == host_addr, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_find_resource(host_addr, resource_type, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_find_resource() Fail(%d)", ret);
+
+       return ret;
+}
+
+
+/* If you know the information of resource, then you 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)
+{
+       FN_CALL;
+       iotcon_client_h resource = NULL;
+
+       RETV_IF(NULL == host, NULL);
+       RETV_IF(NULL == uri, NULL);
+       RETV_IF(NULL == resource_types, NULL);
+
+       resource = calloc(1, sizeof(struct ic_remote_resource));
+       if (NULL == resource) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       resource->host = ic_utils_strdup(host);
+       resource->uri = ic_utils_strdup(uri);
+       resource->is_observable = is_observable;
+       resource->types = resource_types;
+       resource->ifaces = resource_ifs;
+
+       return resource;
+}
+
+
+API void iotcon_client_free(iotcon_client_h resource)
+{
+       FN_CALL;
+
+       RET_IF(NULL == resource);
+
+       free(resource->uri);
+       free(resource->host);
+       ic_options_free(resource->header_options);
+       iotcon_str_list_free(resource->types);
+       free(resource);
+}
+
+
+API iotcon_client_h iotcon_client_clone(iotcon_client_h resource)
+{
+       iotcon_client_h clone;
+
+       RETV_IF(NULL == resource, NULL);
+
+       clone = iotcon_client_new(resource->host,
+                       resource->uri,
+                       resource->is_observable,
+                       iotcon_str_list_clone(resource->types),
+                       resource->ifaces);
+
+       clone->observe_handle = resource->observe_handle;
+
+       return clone;
+}
+
+
+API const char* iotcon_client_get_uri(iotcon_client_h resource)
+{
+       RETV_IF(NULL == resource, NULL);
+
+       return resource->uri;
+}
+
+
+API const char* iotcon_client_get_host(iotcon_client_h resource)
+{
+       RETV_IF(NULL == resource, NULL);
+
+       return resource->host;
+}
+
+
+API iotcon_str_list_s* iotcon_client_get_types(iotcon_client_h resource)
+{
+       RETV_IF(NULL == resource, NULL);
+
+       return resource->types;
+}
+
+
+API int iotcon_client_get_interfaces(iotcon_client_h resource)
+{
+       RETV_IF(NULL == resource, IOTCON_INTERFACE_NONE);
+
+       return resource->ifaces;
+}
+
+
+/* if header_options is NULL, then client's header_options is unset */
+API void iotcon_client_set_options(iotcon_client_h resource,
+               iotcon_options_h header_options)
+{
+       RET_IF(NULL == resource);
+
+       if (resource->header_options)
+               iotcon_options_free(resource->header_options);
+
+       resource->header_options = header_options;
+}
+
+
+API int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
+               iotcon_on_get_cb cb, void *user_data)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_get(resource, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_get() Fail(%d)", ret);
+
+       return ret;
+}
+
+
+API int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr,
+               iotcon_query_h query, iotcon_on_put_cb cb, void *user_data)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_put(resource, repr, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_put() Fail(%d)", ret);
+
+       return ret;
+}
+
+
+API int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr,
+               iotcon_query_h query, iotcon_on_post_cb cb, void *user_data)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_post(resource, repr, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_post() Fail(%d)", ret);
+
+       return ret;
+}
+
+
+API int iotcon_delete(iotcon_client_h resource, iotcon_on_delete_cb cb, void *user_data)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_delete_res(resource, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_delete_res() Fail(%d)", ret);
+
+       return ret;
+}
+
+
+API int iotcon_observer_start(iotcon_client_h resource,
+               iotcon_observe_type_e observe_type,
+               iotcon_query_h query,
+               iotcon_on_observe_cb cb,
+               void *user_data)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_observe(resource, observe_type, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_observe() Fail(%d)", ret);
+
+       return ret;
+}
+
+
+API int iotcon_observer_stop(iotcon_client_h resource)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_cancel_observe(resource);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_cancel_observe() Fail(%d)", ret);
+
+       return ret;
+}
diff --git a/lib/ic-device.c b/lib/ic-device.c
new file mode 100755 (executable)
index 0000000..aeb6ca3
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * 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 <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-common.h"
+#include "ic-struct.h"
+#include "ic-ioty.h"
+
+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)
+{
+       int ret;
+       struct ic_device_info device_info = {0};
+
+       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);
+       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)
+{
+       FN_CALL;
+       int ret = IOTCON_ERROR_NONE;
+
+       RETV_IF(NULL == host_address, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_get_device_info(host_address, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("ic_ioty_get_device_info() Fail(%d)", ret);
+               return ret;
+       }
+
+       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-handler.c b/lib/ic-handler.c
deleted file mode 100644 (file)
index b9b21f1..0000000
+++ /dev/null
@@ -1,51 +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.
- */
-
-#include "iotcon.h"
-
-#include "ic-common.h"
-#include "ic-ioty.h"
-#include "ic-handler.h"
-
-static gboolean _find_valid_resource(gpointer key, gpointer value, gpointer user_data)
-{
-       return (key == user_data);
-}
-
-resource_handler_s* ic_get_resource_handler_data(void *handle)
-{
-       resource_handler_s *handler;
-       ic_ctx_s *ic_ctx = ic_get_ctx();
-
-       handler = g_hash_table_find(ic_ctx->entity_cb_hash, _find_valid_resource, handle);
-       return handler;
-}
-
-void ic_get_device_info_handler(iotcon_device_info_s *info)
-{
-       FN_CALL;
-       ic_ctx_s *ic_ctx = ic_get_ctx();
-       iotcon_found_device_info_cb notify_cb = NULL;
-
-       GList *node = g_list_first(ic_ctx->found_device_cb_lst);
-       while (node) {
-               notify_cb = node->data;
-               if (notify_cb)
-                       notify_cb(info);
-
-               node = node->next;
-       }
-}
index 553264a..571c06e 100644 (file)
@@ -21,7 +21,7 @@ extern "C" {
 #include "ic-common.h"
 #include "ic-utils.h"
 #include "ic-repr.h"
-#include "ic-handler.h"
+#include "ic.h"
 }
 #include "ic-ioty-repr.h"
 
@@ -31,7 +31,7 @@ using namespace std;
 static iotcon_repr_h _ic_ioty_repr_create_repr(const OCRepresentation& ocRep)
 {
        FN_CALL;
-
+       // incoming json format example : {"href":"/a/address","rep":{"text":"Hello world"}}
        string jsonStr = ocRep.getJSONRepresentation();
        iotcon_repr_h repr = ic_repr_parse_json(jsonStr.c_str());
 
@@ -124,60 +124,3 @@ OCRepresentation ic_ioty_repr_parse(iotcon_repr_h repr)
        return ocRep;
 }
 
-void ic_ioty_repr_found_device_cb(const OCRepresentation& ocRep)
-{
-       iotcon_device_info_s info = {0};
-       string readbuf;
-
-       if (ocRep.getValue("ct", readbuf))
-               info.content_type = ic_utils_strdup(readbuf.c_str());
-
-       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());
-
-       if (ocRep.getValue("di", readbuf))
-               info.device_uuid = ic_utils_strdup(readbuf.c_str());
-
-       if (ocRep.getValue("mnfv", readbuf))
-               info.firmware_version = 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());
-
-       if (ocRep.getValue("mnml", readbuf))
-               info.manufacturer_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))
-               info.platform_version = ic_utils_strdup(readbuf.c_str());
-
-       if (ocRep.getValue("mnsl", readbuf))
-               info.support_url = ic_utils_strdup(readbuf.c_str());
-
-       if (ocRep.getValue("icv", readbuf))
-               info.version = ic_utils_strdup(readbuf.c_str());
-
-       ic_get_device_info_handler(&info);
-
-       free(info.device_name);
-       free(info.host_name);
-       free(info.device_uuid);
-       free(info.content_type);
-       free(info.version);
-       free(info.manufacturer_name);
-       free(info.manufacturer_url);
-       free(info.model_number);
-       free(info.date_of_manufacture);
-       free(info.platform_version);
-       free(info.firmware_version);
-       free(info.support_url);
-}
-
old mode 100644 (file)
new mode 100755 (executable)
index 048fb0d..c8f31f5
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdint.h>
 #include <glib.h>
 #include <OCApi.h>
 #include <OCPlatform.h>
 
 extern "C" {
+#include "ic.h"
 #include "ic-common.h"
 #include "ic-utils.h"
 #include "ic-repr.h"
-#include "ic-handler.h"
 #include "ic-struct.h"
+#include "ic-ioty.h"
 }
 #include "ic-ioty-repr.h"
-#include "ic-ioty.h"
+
+#define IC_UNICAST_RESOURCE_DISCOVERY ":5683/oc/core"
+#define IC_MULTICAST_RESOURCE_DISCOVERY "/oc/core"
+#define IC_DEVICE_DISCOVERY "/oc/core/d"
 
 using namespace std;
 using namespace OC;
@@ -40,11 +45,11 @@ namespace icIotivityHandler {
        class presenceObject
        {
        private:
-               iotcon_presence_handle_cb presence_handler;
+               iotcon_presence_cb presence_handler;
                void *cb_data;
 
        public:
-               presenceObject(iotcon_presence_handle_cb user_cb, void *user_data)
+               presenceObject(iotcon_presence_cb user_cb, void *user_data)
                {
                        presence_handler = user_cb;
                        cb_data = user_data;
@@ -53,18 +58,26 @@ namespace icIotivityHandler {
                void presenceHandler(OCStackResult result, const unsigned int nonce,
                                const string& hostAddress)
                {
-                       iotcon_error_e ret;
+                       int res;
 
-                       if (OC_STACK_OK != result) {
-                               ERR("subscribePresence() result Fail(%d)", result);
-                               ret = IOTCON_ERROR_IOTIVITY;
-                       }
-                       else {
-                               ret = IOTCON_ERROR_NONE;
+                       switch (result) {
+                       case OC_STACK_OK:
+                               res = IOTCON_PRESENCE_OK;
+                               break;
+                       case OC_STACK_PRESENCE_STOPPED:
+                               res = IOTCON_PRESENCE_STOPPED;
+                               break;
+                       case OC_STACK_PRESENCE_TIMEOUT:
+                               res = IOTCON_PRESENCE_TIMEOUT;
+                               break;
+                       case OC_STACK_ERROR:
+                       default:
+                               ERR("subscribePresence() Fail(%d)", result);
+                               res = IOTCON_PRESENCE_ERROR;
                        }
 
                        if (presence_handler)
-                               presence_handler(ret, nonce, hostAddress.c_str(), cb_data);
+                               presence_handler(res, nonce, hostAddress.c_str(), cb_data);
                }
        };
 
@@ -83,33 +96,40 @@ namespace icIotivityHandler {
 
                void foundResource(shared_ptr<OCResource> resource)
                {
-                       iotcon_resource_s resource_s = {0};
+                       struct ic_remote_resource resource_s = {0};
 
-                       resource_s.resource_uri = ic_utils_strdup(resource->uri().c_str());
-                       resource_s.resource_host = ic_utils_strdup(resource->host().c_str());
+                       resource_s.uri = ic_utils_strdup(resource->uri().c_str());
+                       resource_s.host = ic_utils_strdup(resource->host().c_str());
                        resource_s.is_observable = resource->isObservable();
-                       resource_s.resource_types = iotcon_resource_types_new();
-                       resource_s.resource_interfaces = iotcon_resource_interfaces_new();
+                       resource_s.types = NULL;
 
                        vector<string> resource_types = resource->getResourceTypes();
                        for (string &resource_type : resource_types)
-                               resource_s.resource_types
-                                       = iotcon_resource_types_insert(resource_s.resource_types,
-                                                       ic_utils_strdup(resource_type.c_str()));
+                               resource_s.types
+                                       = iotcon_str_list_append(resource_s.types,
+                                                       resource_type.c_str());
 
                        vector<string> resource_interfaces = resource->getResourceInterfaces();
-                       for (string &resource_interface : resource_interfaces)
-                               resource_s.resource_interfaces
-                                       = g_list_append(resource_s.resource_interfaces,
-                                                       ic_utils_strdup(resource_interface.c_str()));
+                       for (string &resource_interface : resource_interfaces) {
+                               if (STR_EQUAL == resource_interface.compare(DEFAULT_INTERFACE))
+                                       resource_s.ifaces |= IOTCON_INTERFACE_DEFAULT;
+
+                               if (STR_EQUAL == resource_interface.compare(BATCH_INTERFACE))
+                                       resource_s.ifaces |= IOTCON_INTERFACE_BATCH;
+
+                               if (STR_EQUAL == resource_interface.compare(LINK_INTERFACE))
+                                       resource_s.ifaces |= IOTCON_INTERFACE_LINK;
+
+                               if (STR_EQUAL == resource_interface.compare(GROUP_INTERFACE))
+                                       resource_s.ifaces |= IOTCON_INTERFACE_GROUP;
+                       }
 
                        if (found_resource)
                                found_resource(&resource_s, cb_data);
 
-                       free(resource_s.resource_uri);
-                       free(resource_s.resource_host);
-                       iotcon_resource_types_free(resource_s.resource_types);
-                       iotcon_resource_interfaces_free(resource_s.resource_interfaces);
+                       free(resource_s.uri);
+                       free(resource_s.host);
+                       iotcon_str_list_free(resource_s.types);
                }
        };
 
@@ -134,10 +154,13 @@ namespace icIotivityHandler {
                        iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
-                       if (OC_STACK_OK == eCode)
-                               res = IOTCON_ERROR_NONE;
-                       else
-                               res = IOTCON_ERROR_IOTIVITY;
+                       if (OC_STACK_OK == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_OK;
+                       }
+                       else {
+                               ERR("get() Fail(%d)", eCode);
+                               res = IOTCON_RESPONSE_RESULT_ERROR;
+                       }
 
                        options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
@@ -176,10 +199,13 @@ namespace icIotivityHandler {
                        iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
-                       if (OC_STACK_OK == eCode)
-                               res = IOTCON_ERROR_NONE;
-                       else
-                               res = IOTCON_ERROR_IOTIVITY;
+                       if (OC_STACK_OK == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_OK;
+                       }
+                       else {
+                               ERR("put() Fail(%d)", eCode);
+                               res = IOTCON_RESPONSE_RESULT_ERROR;
+                       }
 
                        options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
@@ -218,10 +244,16 @@ namespace icIotivityHandler {
                        iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
-                       if (OC_STACK_OK == eCode || OC_STACK_RESOURCE_CREATED == eCode)
-                               res = IOTCON_ERROR_NONE;
-                       else
-                               res = IOTCON_ERROR_IOTIVITY;
+                       if (OC_STACK_OK == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_OK;
+                       }
+                       else if (OC_STACK_RESOURCE_CREATED == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_RESOURCE_CREATED;
+                       }
+                       else {
+                               ERR("post() Fail(%d)", eCode);
+                               res = IOTCON_RESPONSE_RESULT_ERROR;
+                       }
 
                        options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
@@ -257,10 +289,16 @@ namespace icIotivityHandler {
                        int res;
                        iotcon_options_h options;
 
-                       if (OC_STACK_OK == eCode || OC_STACK_RESOURCE_DELETED == eCode)
-                               res = IOTCON_ERROR_NONE;
-                       else
-                               res = IOTCON_ERROR_IOTIVITY;
+                       if (OC_STACK_OK == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_OK;
+                       }
+                       else if (OC_STACK_RESOURCE_DELETED == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
+                       }
+                       else {
+                               ERR("deleteResource() Fail(%d)", eCode);
+                               res = IOTCON_RESPONSE_RESULT_ERROR;
+                       }
 
                        options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
@@ -296,10 +334,13 @@ namespace icIotivityHandler {
                        iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
-                       if (OC_STACK_OK == eCode)
-                               res = IOTCON_ERROR_NONE;
-                       else
-                               res = IOTCON_ERROR_IOTIVITY;
+                       if (OC_STACK_OK == eCode) {
+                               res = IOTCON_RESPONSE_RESULT_OK;
+                       }
+                       else {
+                               ERR("observe() Fail(%d)", eCode);
+                               res = IOTCON_RESPONSE_RESULT_ERROR;
+                       }
 
                        options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
@@ -316,9 +357,70 @@ namespace icIotivityHandler {
                        iotcon_options_free(options);
                }
        };
+
+       class deviceObject
+       {
+       private:
+               iotcon_device_info_cb found_cb;
+               void *cb_data;
+
+       public:
+               deviceObject(iotcon_device_info_cb user_cb, void *user_data)
+               {
+                       found_cb = user_cb;
+                       cb_data = user_data;
+               }
+
+               void receivedDeviceInfo(const OCRepresentation& ocRep)
+               {
+                       struct ic_device_info info = {0};
+                       string readbuf;
+
+                       if (ocRep.getValue("ct", readbuf))
+                               info.content_type = ic_utils_strdup(readbuf.c_str());
+                       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());
+                       if (ocRep.getValue("di", readbuf))
+                               info.device_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());
+                       if (ocRep.getValue("mnml", readbuf))
+                               info.manufacturer_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))
+                               info.platform_ver = ic_utils_strdup(readbuf.c_str());
+                       if (ocRep.getValue("mnsl", readbuf))
+                               info.support_url = ic_utils_strdup(readbuf.c_str());
+                       if (ocRep.getValue("icv", readbuf))
+                               info.version = ic_utils_strdup(readbuf.c_str());
+
+                       if (found_cb)
+                               found_cb(&info, cb_data);
+
+                       free(info.device_name);
+                       free(info.host_name);
+                       free(info.device_uuid);
+                       free(info.content_type);
+                       free(info.version);
+                       free(info.manufacturer_name);
+                       free(info.manufacturer_url);
+                       free(info.model_number);
+                       free(info.date_of_manufacture);
+                       free(info.platform_ver);
+                       free(info.firmware_ver);
+                       free(info.support_url);
+               }
+       };
 }
 
-extern "C" void ic_iotivity_config(const char *addr, unsigned short port)
+extern "C" void ic_ioty_config(const char *addr, unsigned short port)
 {
        PlatformConfig cfg {
                ServiceType::InProc,
@@ -331,13 +433,14 @@ extern "C" void ic_iotivity_config(const char *addr, unsigned short port)
        DBG("Created a platform");
 }
 
-static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> request)
+static OCEntityHandlerResult _ic_ioty_request_handler(
+               shared_ptr<OCResourceRequest> request)
 {
        FN_CALL;
        HeaderOptions headerOptions;
        QueryParamsMap queryParams;
        resource_handler_s *temp_res = NULL;
-       iotcon_request_s request_s = {0};
+       struct ic_resource_request request_s = {0};
 
        temp_res = ic_get_resource_handler_data(request->getResourceHandle());
        if (NULL == temp_res) {
@@ -345,9 +448,9 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
                return OC_EH_ERROR;
        }
 
-       request_s.query = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+       request_s.query = iotcon_query_new();
        if (NULL == request_s.query) {
-               ERR("g_hash_table_new_full() Fail");
+               ERR("iotcon_query_new() Fail");
                return OC_EH_ERROR;
        }
 
@@ -355,8 +458,7 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
        queryParams = request->getQueryParameters();
        for (it = queryParams.begin(); it != queryParams.end(); ++it) {
                DBG("key=%s value=%s", it->first.c_str(), it->second.c_str());
-               g_hash_table_insert(request_s.query, ic_utils_strdup(it->first.c_str()),
-                               ic_utils_strdup(it->second.c_str()));
+               iotcon_query_insert(request_s.query, it->first.c_str(), it->second.c_str());
        }
 
        request_s.header_options = iotcon_options_new();
@@ -393,7 +495,7 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
                return OC_EH_ERROR;
        }
 
-       request_s.res_uri = ic_utils_strdup(request->getResourceUri().c_str());
+       request_s.uri = ic_utils_strdup(request->getResourceUri().c_str());
        if (NULL == request_s.request_type) {
                ERR("ic_utils_strdup() Fail");
                free(request_s.request_type);
@@ -404,27 +506,28 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
 
        request_s.request_handler_flag = request->getRequestHandlerFlag();
        request_s.request_handle = (iotcon_request_h)request->getRequestHandle();
-       request_s.resource_handle = (iotcon_resource_h)request->getResourceHandle();
-       ObservationInfo observationInfo = request->getObservationInfo();
+       request_s.resource_handle = (iotcon_client_h)request->getResourceHandle();
 
-       request_s.observation_info.action = (iotcon_osbserve_action_e)observationInfo.action;
-       request_s.observation_info.obs_id = (iotcon_observation_id)observationInfo.obsId;
+       ObservationInfo observationInfo = request->getObservationInfo();
+       request_s.observation_info.action = (iotcon_observe_action_e)observationInfo.action;
+       request_s.observation_info.observer_id = observationInfo.obsId;
        DBG("obs_info.obsId=%d", observationInfo.obsId);
 
        /* call handler_cb */
-       if (temp_res->rest_api_cb) {
-               temp_res->rest_api_cb(&request_s);
+       if (temp_res->request_handler_cb) {
+               temp_res->request_handler_cb(&request_s, temp_res->user_data);
        }
        else {
-               WARN("temp_res->rest_api_cb is null");
+               WARN("temp_res->request_handler_cb is null");
        }
 
        free(request_s.request_type);
-       free(request_s.res_uri);
+       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);
 
@@ -432,68 +535,116 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
 }
 
 
-extern "C" void* ic_ioty_register_res(const char *uri, const char *rt,
-               iotcon_interface_e iface, iotcon_resource_property_e rt_property)
+extern "C" OCResourceHandle ic_ioty_register_res(const char *uri,
+               iotcon_str_list_s *res_types, int ifaces, uint8_t properties)
 {
+       FN_CALL;
        OCStackResult ret;
        string resUri;
        string resType;
        string resInterface;
        OCResourceHandle handle;
+       unsigned int i;
 
        resUri = uri;
-       resType = rt;
 
-       if (IOTCON_INTERFACE_LINK == iface)
+       resType = iotcon_str_list_nth_data(res_types, 1);
+
+       if (IOTCON_INTERFACE_DEFAULT & ifaces) {
+               resInterface = DEFAULT_INTERFACE;
+               ifaces ^= IOTCON_INTERFACE_DEFAULT;
+       }
+       else if (IOTCON_INTERFACE_LINK & ifaces) {
                resInterface = LINK_INTERFACE;
-       else if (IOTCON_INTERFACE_BATCH == iface)
+               ifaces ^= IOTCON_INTERFACE_LINK;
+       }
+       else if (IOTCON_INTERFACE_BATCH & ifaces) {
                resInterface = BATCH_INTERFACE;
-       else if (IOTCON_INTERFACE_GROUP == iface)
+               ifaces ^= IOTCON_INTERFACE_BATCH;
+       }
+       else if (IOTCON_INTERFACE_GROUP & ifaces) {
                resInterface = GROUP_INTERFACE;
-       else
-               resInterface = DEFAULT_INTERFACE;
-
+               ifaces ^= IOTCON_INTERFACE_GROUP;
+       }
 
-       ret = registerResource(handle, resUri, resType, resInterface, _entity_handler,
-                       (unsigned int)rt_property);
+       ret = registerResource(handle, resUri, resType, resInterface,
+                       _ic_ioty_request_handler, properties);
        if (OC_STACK_OK != ret) {
                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));
+
+       if (IOTCON_INTERFACE_DEFAULT & ifaces)
+               ic_ioty_bind_iface_to_res(handle, IOTCON_INTERFACE_DEFAULT);
+
+       if (IOTCON_INTERFACE_LINK & ifaces)
+               ic_ioty_bind_iface_to_res(handle, IOTCON_INTERFACE_LINK);
+
+       if (IOTCON_INTERFACE_BATCH & ifaces)
+               ic_ioty_bind_iface_to_res(handle, IOTCON_INTERFACE_BATCH);
+
+       if (IOTCON_INTERFACE_GROUP & ifaces)
+               ic_ioty_bind_iface_to_res(handle, IOTCON_INTERFACE_GROUP);
+
        return handle;
 }
 
 
-extern "C" int ic_ioty_unregister_res(const iotcon_resource_h resource_handle)
+extern "C" int ic_ioty_unregister_res(iotcon_resource_h resource_handle)
 {
        OCResourceHandle resourceHandle = resource_handle;
 
-       try {
-               OCStackResult result = unregisterResource(resourceHandle);
-               if(OC_STACK_OK != result) {
-                       ERR("OCPlatform::unregisterResource Fail(%d)", result);
-                       return IOTCON_ERROR_IOTIVITY;
-               }
-       }
-       catch(OCException& e) {
-               ERR("unregisterResource() Fail(%s)", e.what());
+       OCStackResult result = unregisterResource(resourceHandle);
+       if(OC_STACK_OK != result) {
+               ERR("unregisterResource Fail(%d)", result);
                return IOTCON_ERROR_IOTIVITY;
        }
 
        return IOTCON_ERROR_NONE;
 }
 
+static int _ic_ioty_generate_interface(iotcon_interface_e iface, string &interface_str)
+{
+       switch (iface) {
+       case IOTCON_INTERFACE_GROUP:
+               interface_str = GROUP_INTERFACE;
+               break;
+       case IOTCON_INTERFACE_BATCH:
+               interface_str = BATCH_INTERFACE;
+               break;
+       case IOTCON_INTERFACE_LINK:
+               interface_str = LINK_INTERFACE;
+               break;
+       case IOTCON_INTERFACE_DEFAULT:
+       case IOTCON_INTERFACE_NONE:
+               interface_str = DEFAULT_INTERFACE;
+               break;
+       default:
+               ERR("Invalid interface");
+               return IOTCON_ERROR_PARAM;
+       }
+       return IOTCON_ERROR_NONE;
+}
 
-extern "C" int ic_ioty_bind_iface_to_res(const iotcon_resource_h resource_handle,
-               const char *interface_type)
+extern "C" int ic_ioty_bind_iface_to_res(OCResourceHandle resourceHandle,
+               iotcon_interface_e iface)
 {
-       OCStackResult ret = OC_STACK_ERROR;
-       OCResourceHandle resourceHandle = resource_handle;
+       int ret;
+       OCStackResult ocRet;
+       string resource_interface;
 
-       ret = bindInterfaceToResource(resourceHandle, interface_type);
-       if (OC_STACK_OK != ret) {
-               ERR("bindInterfaceToResource() Fail(%d)", ret);
+       ret = _ic_ioty_generate_interface(iface, resource_interface);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("_ic_ioty_generate_interface() Fail(%d)", ret);
+               return ret;
+       }
+
+       ocRet = bindInterfaceToResource(resourceHandle, resource_interface);
+       if (OC_STACK_OK != ocRet) {
+               ERR("bindInterfaceToResource() Fail(%d)", ocRet);
                return IOTCON_ERROR_IOTIVITY;
        }
 
@@ -501,7 +652,7 @@ extern "C" int ic_ioty_bind_iface_to_res(const iotcon_resource_h resource_handle
 }
 
 
-extern "C" int ic_ioty_bind_type_to_res(const iotcon_resource_h resource_handle,
+extern "C" int ic_ioty_bind_type_to_res(OCResourceHandle resource_handle,
                const char *resource_type)
 {
        OCStackResult ret;
@@ -516,39 +667,37 @@ extern "C" int ic_ioty_bind_type_to_res(const iotcon_resource_h resource_handle,
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_bind_res(iotcon_resource_h parent, iotcon_resource_h child)
+extern "C" int ic_ioty_bind_res(OCResourceHandle parent, OCResourceHandle child)
 {
        OCStackResult ret;
-       OCResourceHandle p_handle = parent;
-       OCResourceHandle c_handle = child;
 
-       ret = OCBindResource(p_handle, c_handle);
+       ret = bindResource(parent, child);
        if (OC_STACK_OK != ret) {
-               ERR("OCBindResource() Fail(%d)", ret);
+               ERR("bindResource() 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)
+extern "C" int ic_ioty_register_device_info(iotcon_device_info_device_info)
 {
        FN_CALL;
        OCStackResult ret;
 
        OCDeviceInfo deviceInfo = {0};
-       deviceInfo.deviceName = ic_utils_strdup(device_info->device_name);
-       deviceInfo.hostName = ic_utils_strdup(device_info->host_name);
-       deviceInfo.deviceUUID = ic_utils_strdup(device_info->device_uuid);
-       deviceInfo.contentType = ic_utils_strdup(device_info->content_type);
-       deviceInfo.version = ic_utils_strdup(device_info->version);
-       deviceInfo.manufacturerName = ic_utils_strdup(device_info->manufacturer_name);
-       deviceInfo.manufacturerUrl = ic_utils_strdup(device_info->manufacturer_url);
-       deviceInfo.modelNumber = ic_utils_strdup(device_info->model_number);
-       deviceInfo.dateOfManufacture = ic_utils_strdup(device_info->date_of_manufacture);
-       deviceInfo.platformVersion = ic_utils_strdup(device_info->platform_version);
-       deviceInfo.firmwareVersion = ic_utils_strdup(device_info->firmware_version);
-       deviceInfo.supportUrl = ic_utils_strdup(device_info->support_url);
+       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;
 
        ret = registerDeviceInfo(deviceInfo);
        if (OC_STACK_OK != ret) {
@@ -560,18 +709,20 @@ extern "C" int ic_ioty_register_device_info(iotcon_device_info_s *device_info)
 }
 
 
-extern "C" int ic_ioty_get_device_info(char *host, char *uri)
+extern "C" int ic_ioty_get_device_info(const char *host_address,
+               iotcon_device_info_cb found_cb, void *user_data)
 {
        OCStackResult ret;
-       string resHost;
-       string resUri;
+       string resHost = host_address + string(IC_DEVICE_DISCOVERY);
 
-       resHost = host;
-       resUri = uri;
+       shared_ptr<icIotivityHandler::deviceObject> object
+               = make_shared<icIotivityHandler::deviceObject>(found_cb, user_data);
+       FindDeviceCallback findDeviceCallback = bind(
+                       &icIotivityHandler::deviceObject::receivedDeviceInfo,
+                       object,
+                       placeholders::_1);
 
-       /* register device_cb
-        to monitor upper apps who wnat to know other device infomation */
-       ret = getDeviceInfo(resHost, resUri, ic_ioty_repr_found_device_cb);
+       ret = getDeviceInfo("", resHost, findDeviceCallback);
        if (OC_STACK_OK != ret) {
                ERR("getDeviceInfo() Fail(%d)", ret);
                return IOTCON_ERROR_IOTIVITY;
@@ -581,55 +732,36 @@ extern "C" int ic_ioty_get_device_info(char *host, char *uri)
 }
 
 
-extern "C" int ic_ioty_send_notify(struct ic_res_response_s *resp,
-               iotcon_observers observers)
+extern "C" int ic_ioty_send_notify(OCResourceHandle resHandle, struct ic_notify_msg *msg,
+               iotcon_observers_h observers)
 {
        int ret;
+       OCStackResult ocRet;
        ObservationIds obsIds;
-       OCResourceHandle resHandle;
-       string interface;
-
-       RETV_IF(NULL == resp, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == resp->repr, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == observers, IOTCON_ERROR_PARAM);
-
-       resHandle = resp->resource_handle;
-
-       RETV_IF(NULL == resp->repr, IOTCON_ERROR_PARAM);
+       string iface;
 
-       OCRepresentation ocRep = ic_ioty_repr_parse(resp->repr);
-
-       GList *node = g_list_first(observers);
+       GList *node = g_list_first((GList*)observers);
        while (node) {
-               iotcon_observation_info_s *temp = (iotcon_observation_info_s*)node->data;
-               obsIds.push_back(temp->obs_id);
+               uint8_t obs_id = GPOINTER_TO_UINT(node->data);
+               obsIds.push_back(obs_id);
 
                node = node->next;
        }
 
        shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
-       resourceResponse->setErrorCode(resp->error_code);
+       resourceResponse->setErrorCode(msg->error_code);
 
-       switch (resp->interface) {
-       case IOTCON_INTERFACE_GROUP:
-               interface = GROUP_INTERFACE;
-               break;
-       case IOTCON_INTERFACE_BATCH:
-               interface = BATCH_INTERFACE;
-               break;
-       case IOTCON_INTERFACE_LINK:
-               interface = LINK_INTERFACE;
-               break;
-       case IOTCON_INTERFACE_DEFAULT:
-       default:
-               interface = DEFAULT_INTERFACE;
+       OCRepresentation ocRep = ic_ioty_repr_parse(msg->repr);
+       ret = _ic_ioty_generate_interface(msg->iface, iface);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("_ic_ioty_generate_interface() Fail(%d)", ret);
+               return ret;
        }
+       resourceResponse->setResourceRepresentation(ocRep, iface);
 
-       resourceResponse->setResourceRepresentation(ocRep, interface);
-
-       ret = notifyListOfObservers(resHandle, obsIds, resourceResponse);
-       if (OC_STACK_NO_OBSERVERS == ret) {
-               ERR("No More observers, stopping notifications");
+       ocRet = notifyListOfObservers(resHandle, obsIds, resourceResponse);
+       if (OC_STACK_OK != ocRet) {
+               ERR("notifyListOfObservers() Fail(%d)", ocRet);
                return IOTCON_ERROR_IOTIVITY;
        }
 
@@ -637,15 +769,12 @@ extern "C" int ic_ioty_send_notify(struct ic_res_response_s *resp,
 }
 
 
-extern "C" int ic_ioty_send_res_response_data(struct ic_res_response_s *resp)
+extern "C" int ic_ioty_send_res_response_data(struct ic_resource_response *resp)
 {
        FN_CALL;
-       string interface;
-       int ret = OC_STACK_ERROR;
-
-       RETV_IF(NULL == resp, IOTCON_ERROR_PARAM);
-
-       RETV_IF(NULL == resp->repr, IOTCON_ERROR_PARAM);
+       string iface;
+       int ret;
+       OCStackResult ocRet;
 
        OCRepresentation ocRep = ic_ioty_repr_parse(resp->repr);
 
@@ -656,26 +785,17 @@ extern "C" int ic_ioty_send_res_response_data(struct ic_res_response_s *resp)
                pResponse->setErrorCode(resp->error_code);
                pResponse->setResponseResult((OCEntityHandlerResult)resp->result);
 
-               switch (resp->interface) {
-               case IOTCON_INTERFACE_GROUP:
-                       interface = GROUP_INTERFACE;
-                       break;
-               case IOTCON_INTERFACE_BATCH:
-                       interface = BATCH_INTERFACE;
-                       break;
-               case IOTCON_INTERFACE_LINK:
-                       interface = LINK_INTERFACE;
-                       break;
-               case IOTCON_INTERFACE_DEFAULT:
-               default:
-                       interface = DEFAULT_INTERFACE;
+               ret = _ic_ioty_generate_interface(resp->iface, iface);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("_ic_ioty_generate_interface() Fail(%d)", ret);
+                       return ret;
                }
 
-               pResponse->setResourceRepresentation(ocRep, interface);
+               pResponse->setResourceRepresentation(ocRep, iface);
 
-               ret = sendResponse(pResponse);
-               if (OC_STACK_OK != ret) {
-                       ERR("sendResponse() Fail(%d)", ret);
+               ocRet = sendResponse(pResponse);
+               if (OC_STACK_OK != ocRet) {
+                       ERR("sendResponse() Fail(%d)", ocRet);
                        return IOTCON_ERROR_IOTIVITY;
                }
        }
@@ -686,8 +806,10 @@ extern "C" int ic_ioty_send_res_response_data(struct ic_res_response_s *resp)
 
 }
 
-extern "C" iotcon_presence_h ic_ioty_subscribe_presence(const char *host_address,
-               iotcon_presence_handle_cb presence_handler_cb, void *user_data)
+extern "C" const iotcon_presence_h ic_ioty_subscribe_presence(const char *host_address,
+               const char *resource_type,
+               iotcon_presence_cb presence_handler_cb,
+               void *user_data)
 {
        OCStackResult ret;
        iotcon_presence_h presence_handle = NULL;
@@ -698,7 +820,9 @@ extern "C" iotcon_presence_h ic_ioty_subscribe_presence(const char *host_address
                = bind(&icIotivityHandler::presenceObject::presenceHandler, object,
                                placeholders::_1, placeholders::_2, placeholders::_3);
 
-       ret = subscribePresence(presence_handle, host_address, subscribeCallback);
+       ret = subscribePresence(presence_handle, host_address, resource_type,
+                       subscribeCallback);
+
        if (OC_STACK_OK != ret) {
                ERR("subscribePresence() Fail(%d)", ret);
                return NULL;
@@ -720,12 +844,13 @@ extern "C" int ic_ioty_unsubscribe_presence(iotcon_presence_h presence_handle)
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_start_presence(const unsigned int time_to_live)
+extern "C" int ic_ioty_start_presence(unsigned int time_to_live)
 {
-       try {
-               startPresence(time_to_live);
-       } catch (OCException e) {
-               ERR("startPresence() Fail(%s)", e.what());
+       OCStackResult ret;
+
+       ret = startPresence(time_to_live);
+       if (OC_STACK_OK != ret) {
+               ERR("startPresence() Fail(%d)", ret);
                return IOTCON_ERROR_IOTIVITY;
        }
 
@@ -734,27 +859,37 @@ extern "C" int ic_ioty_start_presence(const unsigned int time_to_live)
 
 extern "C" int ic_ioty_stop_presence()
 {
-       try {
-               stopPresence();
-       } catch (OCException e) {
-               ERR("stopPresence() Fail(%s)", e.what());
+       OCStackResult ret;
+
+       ret = stopPresence();
+       if (OC_STACK_OK != ret) {
+               ERR("stopPresence() Fail(%d)", ret);
                return IOTCON_ERROR_IOTIVITY;
        }
 
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_find_resource(const char *host, const char *resource_name,
+extern "C" int ic_ioty_find_resource(const char *host_address, const char *resource_type,
                iotcon_found_resource_cb found_resource_cb, void *user_data)
 {
        OCStackResult ret;
+       ostringstream resource_name;
+
+       if (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;
+
+       if (resource_type)
+               resource_name << "?rt=" << resource_type;
 
        shared_ptr<icIotivityHandler::findObject> object
                = make_shared<icIotivityHandler::findObject>(found_resource_cb, user_data);
        FindCallback findCallback = bind(&icIotivityHandler::findObject::foundResource,
                        object, placeholders::_1);
 
-       ret = findResource(host, resource_name, findCallback);
+       ret = findResource("", resource_name.str(), findCallback);
        if (OC_STACK_OK != ret) {
                ERR("findResource() Fail(%d)", ret);
                return IOTCON_ERROR_IOTIVITY;
@@ -763,71 +898,92 @@ extern "C" int ic_ioty_find_resource(const char *host, const char *resource_name
        return IOTCON_ERROR_NONE;
 }
 
-static void _change_options(unsigned short id, char *data, void *user_data)
+static void _ic_ioty_accumulate_options_vector(unsigned short id, const char *data,
+               void *user_data)
 {
-       HeaderOptions *options = static_cast<HeaderOptions *>(user_data);
+       HeaderOptions *options = static_cast<HeaderOptions*>(user_data);
        HeaderOption::OCHeaderOption option(id, data);
        (*options).push_back(option);
 }
 
-static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
+static OCResource::Ptr _ic_ioty_create_oc_resource(iotcon_client_h resource)
 {
-       string host = resource.resource_host;
-       string uri = resource.resource_uri;
+       string host;
+       string uri;
        vector<string> resource_types;
        vector<string> resource_ifs;
 
        HeaderOptions header_options;
 
-       RETV_IF(NULL == resource.resource_host, NULL);
-       RETV_IF(NULL == resource.resource_uri, NULL);
+       RETV_IF(NULL == resource, NULL);
+       RETV_IF(NULL == resource->host, NULL);
+       RETV_IF(NULL == resource->uri, NULL);
+       RETV_IF(NULL == resource->types, NULL);
 
-       GList *node = resource.resource_types;
-       for (node = g_list_first(node); node; node = g_list_next(node)) {
-               string resource_type_str = (char *)node->data;
-               resource_types.push_back(resource_type_str);
+       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;
+       }
+
+       if (IOTCON_INTERFACE_NONE == resource->ifaces) {
+               resource_ifs.push_back(DEFAULT_INTERFACE);
        }
+       else {
+               if (IOTCON_INTERFACE_DEFAULT & resource->ifaces)
+                       resource_ifs.push_back(DEFAULT_INTERFACE);
 
-       node = resource.resource_interfaces;
-       for (node = g_list_first(node); node; node = g_list_next(node)) {
-               string resource_if_str = (char *)node->data;
-               resource_ifs.push_back(resource_if_str);
+               if (IOTCON_INTERFACE_LINK & resource->ifaces)
+                       resource_ifs.push_back(LINK_INTERFACE);
+
+               if (IOTCON_INTERFACE_BATCH & resource->ifaces)
+                       resource_ifs.push_back(BATCH_INTERFACE);
+
+               if (IOTCON_INTERFACE_GROUP & resource->ifaces)
+                       resource_ifs.push_back(GROUP_INTERFACE);
        }
 
        OCResource::Ptr ocResource = constructResourceObject(host, uri,
-                       resource.is_observable, resource_types, resource_ifs);
+                       resource->is_observable, resource_types, resource_ifs);
 
-       if (resource.header_options) {
-               iotcon_options_foreach(resource.header_options, _change_options,
-                               (void *)&header_options);
+       if (resource->header_options) {
+               iotcon_options_foreach(resource->header_options,
+                               _ic_ioty_accumulate_options_vector, (void*)&header_options);
                ocResource->setHeaderOptions(header_options);
        }
 
        return ocResource;
 }
 
-extern "C" int ic_ioty_get(iotcon_resource_s resource,
-               iotcon_query query, iotcon_on_get_cb on_get_cb, void *user_data)
+
+static void _ic_ioty_accumulate_query_map(const char *key, const char *value,
+               void *user_data)
+{
+       QueryParamsMap *queryParams = static_cast<QueryParamsMap*>(user_data);
+       string keyStr = key;
+       string valueStr = value;
+       (*queryParams)[keyStr] = valueStr;
+}
+
+
+extern "C" int ic_ioty_get(iotcon_client_h resource, iotcon_query_h query,
+               iotcon_on_get_cb on_get_cb, void *user_data)
 {
        FN_CALL;
        OCStackResult ret;
-       OCResource::Ptr ocResource = NULL;
-
+       OCResource::Ptr ocResource;
        QueryParamsMap queryParams;
 
-       GHashTableIter iter;
-       gpointer key, value;
-
        if (query) {
-               g_hash_table_iter_init(&iter, query);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       string keyStr = (char *)key;
-                       string valueStr = (char *)value;
-                       queryParams[keyStr] = valueStr;
-               }
+               iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void *)&queryParams);
+               iotcon_query_free(query);
        }
 
-       ocResource = _create_oc_resource(resource);
+       ocResource = _ic_ioty_create_oc_resource(resource);
 
        shared_ptr<icIotivityHandler::getObject> object
                = make_shared<icIotivityHandler::getObject>(on_get_cb, user_data);
@@ -842,34 +998,24 @@ extern "C" int ic_ioty_get(iotcon_resource_s resource,
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_put(iotcon_resource_s resource,
-               iotcon_repr_h repr,
-               iotcon_query query,
-               iotcon_on_put_cb on_put_cb,
-               void *user_data)
+
+extern "C" int ic_ioty_put(iotcon_client_h resource, iotcon_repr_h repr,
+               iotcon_query_h query, iotcon_on_put_cb on_put_cb, void *user_data)
 {
        FN_CALL;
        OCStackResult ret;
-
-       OCResource::Ptr ocResource = NULL;
+       OCResource::Ptr ocResource;
        OCRepresentation ocRep;
        QueryParamsMap queryParams;
 
-       GHashTableIter iter;
-       gpointer key, value;
-
        if (query) {
-               g_hash_table_iter_init(&iter, query);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       string keyStr = (char *)key;
-                       string valueStr = (char *)value;
-                       queryParams[keyStr] = valueStr;
-               }
+               iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
+               iotcon_query_free(query);
        }
 
        ocRep = ic_ioty_repr_parse(repr);
 
-       ocResource = _create_oc_resource(resource);
+       ocResource = _ic_ioty_create_oc_resource(resource);
 
        shared_ptr<icIotivityHandler::putObject> object
                = make_shared<icIotivityHandler::putObject>(on_put_cb, user_data);
@@ -885,32 +1031,23 @@ extern "C" int ic_ioty_put(iotcon_resource_s resource,
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_post(iotcon_resource_s resource,
-               iotcon_repr_h repr,
-               iotcon_query query,
-               iotcon_on_post_cb on_post_cb,
-               void *user_data)
+extern "C" int ic_ioty_post(iotcon_client_h resource, iotcon_repr_h repr,
+               iotcon_query_h query, iotcon_on_post_cb on_post_cb, void *user_data)
 {
        FN_CALL;
        OCStackResult ret;
-       GHashTableIter iter;
-       gpointer key, value;
        QueryParamsMap queryParams;
        OCRepresentation ocRep;
-       OCResource::Ptr ocResource = NULL;
+       OCResource::Ptr ocResource;
 
        if (query) {
-               g_hash_table_iter_init(&iter, query);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       string keyStr = (char *)key;
-                       string valueStr = (char *)value;
-                       queryParams[keyStr] = valueStr;
-               }
+               iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
+               iotcon_query_free(query);
        }
 
        ocRep = ic_ioty_repr_parse(repr);
 
-       ocResource = _create_oc_resource(resource);
+       ocResource = _ic_ioty_create_oc_resource(resource);
 
        shared_ptr<icIotivityHandler::postObject> object
                = make_shared<icIotivityHandler::postObject>(on_post_cb, user_data);
@@ -926,14 +1063,14 @@ extern "C" int ic_ioty_post(iotcon_resource_s resource,
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_delete_res(iotcon_resource_s resource,
+extern "C" int ic_ioty_delete_res(iotcon_client_h resource,
                iotcon_on_delete_cb on_delete_cb, void *user_data)
 {
        FN_CALL;
        OCStackResult ret;
-       OCResource::Ptr ocResource = NULL;
+       OCResource::Ptr ocResource;
 
-       ocResource = _create_oc_resource(resource);
+       ocResource = _ic_ioty_create_oc_resource(resource);
 
        shared_ptr<icIotivityHandler::deleteObject> object
                = make_shared<icIotivityHandler::deleteObject>(on_delete_cb, user_data);
@@ -949,28 +1086,20 @@ extern "C" int ic_ioty_delete_res(iotcon_resource_s resource,
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
+extern "C" int ic_ioty_observe(iotcon_client_h resource,
                iotcon_observe_type_e observe_type,
-               iotcon_query query,
+               iotcon_query_h query,
                iotcon_on_observe_cb on_observe_cb,
                void *user_data)
 {
        OCStackResult ret;
-
-       OCResource::Ptr ocResource = NULL;
+       OCResource::Ptr ocResource;
        ObserveType observeType;
-
        QueryParamsMap queryParams;
-       GHashTableIter iter;
-       gpointer key, value;
 
        if (query) {
-               g_hash_table_iter_init(&iter, query);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       string keyStr = (char *)key;
-                       string valueStr = (char *)value;
-                       queryParams[keyStr] = valueStr;
-               }
+               iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
+               iotcon_query_free(query);
        }
 
        if (IOTCON_OBSERVE == observe_type) {
@@ -984,11 +1113,11 @@ extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
                return IOTCON_ERROR_PARAM;
        }
 
-       ocResource = _create_oc_resource(*resource);
+       ocResource = _ic_ioty_create_oc_resource(resource);
 
        resource_handle *obs_h = new resource_handle();
        obs_h->ocResource = ocResource;
-       resource->observe_handle = (void *)obs_h;
+       resource->observe_handle = (void*)obs_h;
 
        shared_ptr<icIotivityHandler::observeObject> object
                = make_shared<icIotivityHandler::observeObject>(on_observe_cb, user_data);
@@ -1004,13 +1133,14 @@ extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
        return IOTCON_ERROR_NONE;
 }
 
-extern "C" int ic_ioty_cancel_observe(iotcon_resource_s resource)
+extern "C" int ic_ioty_cancel_observe(iotcon_client_h resource)
 {
        OCStackResult ret;
+       resource_handle *resource_h = (resource_handle *)resource->observe_handle;
 
-       OCResource::Ptr ocResource = ((resource_handle *)resource.observe_handle)->ocResource;
-       delete (resource_handle *)resource.observe_handle;
-       resource.observe_handle = NULL;
+       OCResource::Ptr ocResource = resource_h->ocResource;
+       delete (resource_handle *)resource->observe_handle;
+       resource->observe_handle = NULL;
 
        ret = ocResource->cancelObserve();
        if (OC_STACK_OK != ret) {
index d61ec8c..26094e9 100644 (file)
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_IOTIVITY_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_IOTIVITY_H__
 
-#include "iotcon.h"
-
-typedef struct _resource_handler_s {
-       char *rt_name;
-       char *if_name;
-       char *uri_name;
-       iotcon_rest_api_handle_cb rest_api_cb;
-} resource_handler_s;
+#include <stdint.h>
 
-void ic_iotivity_config(const char *addr, unsigned short port);
+#include "iotcon.h"
+#include "iotcon-constant.h"
+#include "ic-struct.h"
 
-void* ic_ioty_register_res(const char *uri, const char *rt,
-               iotcon_interface_e iface, iotcon_resource_property_e rt_property);
+void ic_ioty_config(const char *addr, unsigned short port);
 
-int ic_ioty_unregister_res(const iotcon_resource_h resource_handle);
+void* ic_ioty_register_res(const char *uri, iotcon_str_list_s *res_types,
+               int ifaces, uint8_t properties);
 
-int ic_ioty_bind_iface_to_res(const iotcon_resource_h resource_handle,
-               const char *interface_type);
+int ic_ioty_unregister_res(iotcon_resource_h resource_handle);
 
-int ic_ioty_bind_type_to_res(const iotcon_resource_h resource_handle,
-               const char *resource_type);
+int ic_ioty_bind_iface_to_res(void *resource_handle, iotcon_interface_e iface);
 
-int ic_ioty_bind_res(iotcon_resource_h parent, iotcon_resource_h child);
+int ic_ioty_bind_type_to_res(void *resource_handle, const char *resource_type);
 
-int ic_ioty_register_device_info(iotcon_device_info_s *device_info);
+int ic_ioty_bind_res(void *parent, void *child);
 
-int ic_ioty_get_device_info(char *host, char *uri);
+int ic_ioty_register_device_info(iotcon_device_info_h device_info);
 
-int ic_ioty_send_notify(struct ic_res_response_s *resp,
-               iotcon_observers observers);
+int ic_ioty_get_device_info(const char *host_address, iotcon_device_info_cb found_cb,
+               void *user_data);
 
-int ic_ioty_send_res_response_data(struct ic_res_response_s *resp);
+int ic_ioty_send_notify(void *resource, struct ic_notify_msg *msg,
+               iotcon_observers_h observers);
 
-iotcon_presence_h ic_ioty_subscribe_presence(const char *host_address,
-               iotcon_presence_handle_cb presence_handler_cb, void *user_data);
+int ic_ioty_send_res_response_data(struct ic_resource_response *resp);
 
+const iotcon_presence_h ic_ioty_subscribe_presence(const char *host_address,
+               const char *resource_type,
+               iotcon_presence_cb presence_handler_cb,
+               void *user_data);
 int ic_ioty_unsubscribe_presence(iotcon_presence_h presence_handle);
-int ic_ioty_start_presence(const unsigned int time_to_live);
+int ic_ioty_start_presence(unsigned int time_to_live);
 int ic_ioty_stop_presence();
 
-int ic_ioty_find_resource(const char *host, const char *resource_name,
+int ic_ioty_find_resource(const char *host_address, const char *resource_type,
                iotcon_found_resource_cb found_resource_cb, void *user_data);
 
-int ic_ioty_get(iotcon_resource_s resource,    iotcon_query query,
+int ic_ioty_get(iotcon_client_h resource, iotcon_query_h query,
                iotcon_on_get_cb on_get_cb, void *user_data);
 
-int ic_ioty_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+int ic_ioty_put(iotcon_client_h resource, iotcon_repr_h repr, iotcon_query_h query,
                iotcon_on_put_cb on_put_cb, void *user_data);
 
-int ic_ioty_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+int ic_ioty_post(iotcon_client_h resource, iotcon_repr_h repr, iotcon_query_h query,
                iotcon_on_put_cb on_post_cb, void *user_data);
 
-int ic_ioty_delete_res(iotcon_resource_s resource,
+int ic_ioty_delete_res(iotcon_client_h resource,
                iotcon_on_delete_cb on_delete_cb, void *user_data);
 
-int ic_ioty_observe(iotcon_resource_s *resource, iotcon_observe_type_e observe_type,
-               iotcon_query query, iotcon_on_observe_cb on_observe_cb, void *user_data);
+int ic_ioty_observe(iotcon_client_h resource, iotcon_observe_type_e observe_type,
+               iotcon_query_h query, iotcon_on_observe_cb on_observe_cb, void *user_data);
 
-int ic_ioty_cancel_observe(iotcon_resource_s resource);
-
-/**
- * @brief hash-table for resource callback handler
- */
-typedef struct _iot_ctx {
-       GHashTable *entity_cb_hash;
-       GList *found_device_cb_lst;
-} ic_ctx_s;
+int ic_ioty_cancel_observe(iotcon_client_h resource);
 
-ic_ctx_s* ic_get_ctx();
 
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_IOTIVITY_H__ */
+#endif //__IOT_CONNECTIVITY_MANAGER_INTERNAL_IOTIVITY_H__
diff --git a/lib/ic-observation.c b/lib/ic-observation.c
new file mode 100644 (file)
index 0000000..b06e432
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 <stdint.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-common.h"
+
+API void iotcon_observers_free(iotcon_observers_h observers)
+{
+       RET_IF(NULL == observers);
+
+       g_list_free(observers);
+}
+
+/* If you want 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)
+{
+       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)
+{
+       RETV_IF(NULL == observers, observers);
+
+       return g_list_remove(observers, GUINT_TO_POINTER(obs_id));
+}
+
index 999d30e..ae99844 100644 (file)
 #include <glib.h>
 
 #include "iotcon.h"
-
 #include "ic-common.h"
 #include "ic-utils.h"
 #include "ic-struct.h"
-#include "ic-ioty.h"
 #include "ic-options.h"
 
 API iotcon_options_h iotcon_options_new()
 {
-       iotcon_options_h options = calloc(1, sizeof(struct ic_options_s));
+       iotcon_options_h options = calloc(1, sizeof(struct ic_options));
        if (NULL == options) {
                ERR("calloc() Fail(%d)", errno);
                return NULL;
@@ -37,6 +35,7 @@ API iotcon_options_h iotcon_options_new()
        return options;
 }
 
+
 void ic_options_free(iotcon_options_h options)
 {
        RET_IF(NULL == options);
@@ -45,6 +44,7 @@ void ic_options_free(iotcon_options_h options)
        free(options);
 }
 
+
 API void iotcon_options_free(iotcon_options_h options)
 {
        RET_IF(NULL == options);
@@ -53,23 +53,25 @@ API void iotcon_options_free(iotcon_options_h options)
        ic_options_free(options);
 }
 
-API int iotcon_options_insert(iotcon_options_h options, const unsigned short id,
+
+/* options id is always situated between 2014 and 3000 */
+API int iotcon_options_insert(iotcon_options_h options, unsigned short id,
                const char *data)
 {
        FN_CALL;
-       gpointer value;
-
-       RETVM_IF(((id < IOTCON_OPTIONID_MIN) || (IOTCON_OPTIONID_MAX < id)), IOTCON_ERROR_PARAM,
-                       "Invalid id(%d)", id);
 
-       value = ic_utils_strdup(data);
+       RETV_IF(NULL == options, IOTCON_ERROR_PARAM);
+       RETVM_IF(((id < IOTCON_OPTIONID_MIN) || (IOTCON_OPTIONID_MAX < id)),
+                       IOTCON_ERROR_PARAM, "Invalid id(%d)", id);
+       RETV_IF(NULL == data, IOTCON_ERROR_PARAM);
 
-       g_hash_table_insert(options->options, GUINT_TO_POINTER(id), value);
+       g_hash_table_insert(options->options, GUINT_TO_POINTER(id), ic_utils_strdup(data));
 
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_options_delete(iotcon_options_h options, const unsigned short id)
+
+API int iotcon_options_delete(iotcon_options_h options, unsigned short id)
 {
        gboolean ret;
 
@@ -83,7 +85,8 @@ API int iotcon_options_delete(iotcon_options_h options, const unsigned short id)
        return IOTCON_ERROR_NONE;
 }
 
-API const char* iotcon_options_lookup(iotcon_options_h options, const unsigned short id)
+
+API const char* iotcon_options_lookup(iotcon_options_h options, unsigned short id)
 {
        const char *ret;
 
@@ -96,33 +99,36 @@ API const char* iotcon_options_lookup(iotcon_options_h options, const unsigned s
        return ret;
 }
 
+
 API void iotcon_options_foreach(iotcon_options_h options,
-               iotcon_options_foreach_cb foreach_cb, void *user_data)
+               iotcon_options_foreach_cb cb, void *user_data)
 {
        GHashTableIter iter;
        gpointer key, value;
 
        RET_IF(NULL == options);
+       RET_IF(NULL == cb);
 
        g_hash_table_iter_init(&iter, options->options);
        while (g_hash_table_iter_next(&iter, &key, &value))
-               foreach_cb(GPOINTER_TO_UINT(key), value, user_data);
+               cb(GPOINTER_TO_UINT(key), value, user_data);
 }
 
-API iotcon_options_h iotcon_options_clone(iotcon_options_h options)
+
+iotcon_options_h ic_options_ref(iotcon_options_h options)
 {
-       iotcon_options_h clone = NULL;
+       iotcon_options_h ref;
 
        RETV_IF(NULL == options, NULL);
 
-       clone = calloc(1, sizeof(struct ic_options_s));
-       if (NULL == clone) {
+       ref = calloc(1, sizeof(struct ic_options));
+       if (NULL == ref) {
                ERR("calloc() Fail(%d)", errno);
                return NULL;
        }
 
-       clone->options = g_hash_table_ref(options->options);
+       ref->options = g_hash_table_ref(options->options);
 
-       return clone;
+       return ref;
 }
 
index d920630..ba52be2 100644 (file)
@@ -19,5 +19,6 @@
 #include "iotcon-struct.h"
 
 void ic_options_free(iotcon_options_h options);
+iotcon_options_h ic_options_ref(iotcon_options_h options);
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__ */
diff --git a/lib/ic-query.c b/lib/ic-query.c
new file mode 100644 (file)
index 0000000..e328e58
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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 <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-common.h"
+#include "ic-utils.h"
+#include "ic-struct.h"
+
+API iotcon_query_h iotcon_query_new()
+{
+       return g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+}
+
+API void iotcon_query_free(iotcon_query_h query)
+{
+       RET_IF(NULL == query);
+
+       g_hash_table_unref(query);
+}
+
+API int iotcon_query_insert(iotcon_query_h query, const char *key, const char *value)
+{
+       RETV_IF(NULL == query, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+
+       g_hash_table_insert(query, ic_utils_strdup(key), ic_utils_strdup(value));
+
+       return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_query_delete(iotcon_query_h query, const char *key)
+{
+       gboolean ret;
+
+       RETV_IF(NULL == query, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+
+       ret = g_hash_table_remove(query, key);
+       if (FALSE == ret) {
+               ERR("g_hash_table_remove() Fail");
+               return IOTCON_ERROR_PARAM;
+       }
+       return IOTCON_ERROR_NONE;
+}
+
+API const char* iotcon_query_lookup(iotcon_query_h query, const char *key)
+{
+       const char *ret = NULL;
+
+       RETV_IF(NULL == query, NULL);
+       RETV_IF(NULL == key, NULL);
+
+       ret = g_hash_table_lookup(query, key);
+       if (NULL == ret)
+               ERR("g_hash_table_lookup() Fail");
+
+       return ret;
+}
+
+API void iotcon_query_foreach(iotcon_query_h query,
+               iotcon_query_foreach_cb cb, void *user_data)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+
+       RET_IF(NULL == query);
+       RET_IF(NULL == cb);
+
+       g_hash_table_iter_init(&iter, query);
+       while (g_hash_table_iter_next(&iter, &key, &value))
+               cb(key, value, user_data);
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index 44581d3..7e0740c
@@ -407,7 +407,7 @@ iotcon_list_h ic_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
        return list;
 }
 
-API void iotcon_int_list_foreach(iotcon_list_h list, iotcon_int_list_fn fn, void *user_data)
+API void iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn, void *user_data)
 {
        GList *cur;
        int index = 0;
@@ -426,7 +426,7 @@ API void iotcon_int_list_foreach(iotcon_list_h list, iotcon_int_list_fn fn, void
        }
 }
 
-API void iotcon_bool_list_foreach(iotcon_list_h list, iotcon_bool_list_fn fn, void *user_data)
+API void iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn, void *user_data)
 {
        GList *cur;
        int index = 0;
@@ -445,7 +445,7 @@ API void iotcon_bool_list_foreach(iotcon_list_h list, iotcon_bool_list_fn fn, vo
        }
 }
 
-API void iotcon_double_list_foreach(iotcon_list_h list, iotcon_double_list_fn fn, void *user_data)
+API void iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn, void *user_data)
 {
        GList *cur;
        int index = 0;
@@ -464,7 +464,7 @@ API void iotcon_double_list_foreach(iotcon_list_h list, iotcon_double_list_fn fn
        }
 }
 
-API void iotcon_str_list_foreach(iotcon_list_h list, iotcon_str_list_fn fn, void *user_data)
+API void iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn, void *user_data)
 {
        GList *cur;
        int index = 0;
@@ -502,7 +502,7 @@ API void iotcon_list_list_foreach(iotcon_list_h list, iotcon_list_list_fn fn, vo
        }
 }
 
-API void iotcon_repr_list_foreach(iotcon_list_h list, iotcon_repr_list_fn fn, void *user_data)
+API void iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data)
 {
        int index = 0;
        GList *cur = NULL;
index 12cba8b..c231cff 100644 (file)
@@ -13,8 +13,9 @@
  * limitations under the License.
  */
 
-#include "iotcon.h"
+#include <glib.h>
 
+#include "iotcon.h"
 #include "ic-common.h"
 #include "ic-struct.h"
 #include "ic-utils.h"
@@ -424,12 +425,12 @@ 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, GList *key_list, unsigned int index,
-               JsonObject *json_obj)
+static inline int _ic_obj_to_json(GHashTable *hash, iotcon_str_list_s *key_list,
+               unsigned int index, JsonObject *json_obj)
 {
        FN_CALL;
        int type;
-       char *key;
+       const char *key;
        iotcon_repr_h child_repr = NULL;
        iotcon_list_h child_list = NULL;
        iotcon_value_h value = NULL;
@@ -442,7 +443,7 @@ static inline int _ic_obj_to_json(GHashTable *hash, GList *key_list, unsigned in
        RETV_IF(NULL == key_list, IOTCON_ERROR_PARAM);
        RETV_IF(index < 0, IOTCON_ERROR_PARAM);
 
-       key = g_list_nth_data(key_list, index);
+       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);
@@ -499,7 +500,7 @@ JsonObject* ic_obj_to_json(iotcon_repr_h repr)
        FN_CALL;
        int ret;
        unsigned int i = 0;
-       GList *key_list = NULL;
+       iotcon_str_list_s *key_list = NULL;
        JsonObject *json_obj = NULL;
        JsonObject *parent_obj;
 
@@ -508,18 +509,17 @@ JsonObject* ic_obj_to_json(iotcon_repr_h repr)
        key_list = iotcon_repr_get_key_list(repr);
        if (key_list) {
                json_obj = json_object_new();
-               ic_utils_print_str_list(key_list);
-
-               for (i = 0; i < g_list_length(key_list); i++) {
+               for (i = 0; i < iotcon_str_list_length(key_list); i++) {
                        ret = _ic_obj_to_json(repr->hash_table, key_list, i, json_obj);
+
                        if (IOTCON_ERROR_NONE != ret) {
                                ERR("_ic_obj_to_json() Fail(%d)", ret);
                                json_object_unref(json_obj);
-                               g_list_free(key_list);
+                               iotcon_str_list_free(key_list);
                                return NULL;
                        }
                }
-               g_list_free(key_list);
+               iotcon_str_list_free(key_list);
        }
 
        parent_obj = json_object_new();
@@ -601,8 +601,6 @@ iotcon_repr_h ic_obj_from_json(JsonObject *json_repr)
 
        repr = iotcon_repr_new();
        if (key_list) {
-               ic_utils_print_str_list(key_list);
-
                for (i = 0; i < g_list_length(key_list); i++) {
                        ret = _ic_obj_from_json(obj, key_list, i, repr);
                        if (IOTCON_ERROR_NONE != ret) {
index 5288f9f..880392d 100644 (file)
@@ -132,7 +132,7 @@ iotcon_value_h ic_value_new_str(char *val)
                return NULL;
        }
 
-       value->val.s = val;
+       value->val.s = ic_utils_strdup(val);
 
        return (iotcon_value_h)value;
 }
@@ -334,7 +334,11 @@ API iotcon_value_h ic_value_from_json(JsonNode *node)
 void ic_value_free(gpointer data)
 {
        FN_CALL;
-       iotcon_value_h value = data;
+       iotcon_value_h value;
+
+       RET_IF(NULL == data);
+
+       value = data;
 
        int type = value->type;
        switch (type) {
index eece65d..6a0dc25 100644 (file)
@@ -68,11 +68,12 @@ API int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri)
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_repr_delete_uri(iotcon_repr_h repr)
+API int iotcon_repr_del_uri(iotcon_repr_h repr)
 {
        RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
 
        free(repr->uri);
+       repr->uri = NULL;
 
        return IOTCON_ERROR_NONE;
 }
@@ -111,7 +112,7 @@ API int iotcon_repr_append_resource_types(iotcon_repr_h repr, const char *type)
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_repr_delete_resource_types(iotcon_repr_h repr, const char *type)
+API int iotcon_repr_del_resource_types(iotcon_repr_h repr, const char *type)
 {
        GList *cur = NULL;
        RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
@@ -145,14 +146,14 @@ API int iotcon_repr_get_resource_interfaces_count(iotcon_repr_h repr)
        return g_list_length(repr->interfaces);
 }
 
-API int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *interface)
+API int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *iface)
 {
        char *res_interface = NULL;
 
        RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == interface, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == iface, IOTCON_ERROR_PARAM);
 
-       res_interface = ic_utils_strdup(interface);
+       res_interface = ic_utils_strdup(iface);
        if (NULL == res_interface) {
                ERR("ic_utils_strdup() Fail");
                return IOTCON_ERROR_MEMORY;
@@ -162,16 +163,16 @@ API int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *i
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_repr_delete_resource_interfaces(iotcon_repr_h repr, const char *interface)
+API int iotcon_repr_del_resource_interface(iotcon_repr_h repr, const char *iface)
 {
        GList *cur = NULL;
        RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == interface, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == iface, IOTCON_ERROR_PARAM);
        RETV_IF(NULL == repr->interfaces, IOTCON_ERROR_PARAM);
 
-       cur = g_list_find_custom(repr->interfaces, interface, (GCompareFunc)g_strcmp0);
+       cur = g_list_find_custom(repr->interfaces, iface, (GCompareFunc)g_strcmp0);
        if (NULL == cur) {
-               WARN("g_list_find(%s) returns NULL", interface);
+               WARN("g_list_find(%s) returns NULL", iface);
                return IOTCON_ERROR_NO_DATA;
        }
 
@@ -215,12 +216,20 @@ API iotcon_repr_h iotcon_repr_get_nth_child(iotcon_repr_h parent, int index)
        return g_list_nth_data(parent->children, index);
 }
 
-API GList* iotcon_repr_get_key_list(iotcon_repr_h repr)
+API iotcon_str_list_s* iotcon_repr_get_key_list(iotcon_repr_h repr)
 {
+       GHashTableIter iter;
+       gpointer key, value;
+       iotcon_str_list_s *key_list = NULL;
+
        RETV_IF(NULL == repr, NULL);
        RETV_IF(NULL == repr->hash_table, NULL);
 
-       return g_hash_table_get_keys(repr->hash_table);
+       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);
+
+       return key_list;
 }
 
 API int iotcon_repr_get_keys_count(iotcon_repr_h repr)
diff --git a/lib/ic-request.c b/lib/ic-request.c
new file mode 100755 (executable)
index 0000000..e6ea5fc
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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 <stdint.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-common.h"
+#include "ic-struct.h"
+
+API iotcon_repr_h iotcon_request_get_representation(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, NULL);
+
+       return request->repr;
+}
+
+
+API const char* iotcon_request_get_request_type(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, NULL);
+
+       return request->request_type;
+}
+
+
+API int iotcon_request_get_request_handler_flag(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, 0);
+
+       return request->request_handler_flag;
+}
+
+
+API iotcon_options_h iotcon_request_get_options(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, NULL);
+
+       return request->header_options;
+}
+
+
+API iotcon_query_h iotcon_request_get_query(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, NULL);
+
+       return request->query;
+}
+
+
+API iotcon_observe_action_e iotcon_request_get_observer_action(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, IOTCON_OBSERVE_NO_OPTION);
+
+       return request->observation_info.action;
+}
+
+
+API uint8_t iotcon_request_get_observer_id(iotcon_request_h request)
+{
+       RETV_IF(NULL == request, 0);
+
+       return request->observation_info.observer_id;
+}
+
diff --git a/lib/ic-response.c b/lib/ic-response.c
new file mode 100755 (executable)
index 0000000..efea995
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * 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 <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-common.h"
+#include "ic-utils.h"
+#include "ic-struct.h"
+#include "ic-ioty.h"
+#include "ic-options.h"
+
+API iotcon_response_h iotcon_response_new(iotcon_request_h request_h)
+{
+       FN_CALL;
+
+       RETV_IF(NULL == request_h, NULL);
+
+       iotcon_response_h resp = calloc(1, sizeof(struct ic_resource_response));
+       if (NULL == resp) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       resp->request_handle = request_h->request_handle;
+       resp->resource_handle = request_h->resource_handle;
+       resp->error_code = 200;
+
+       return resp;
+}
+
+
+API void iotcon_response_free(iotcon_response_h resp)
+{
+       FN_CALL;
+
+       RET_IF(NULL == resp);
+
+       if (resp->repr)
+               iotcon_repr_free(resp->repr);
+       if (resp->new_uri)
+               free(resp->new_uri);
+       if (resp->header_options)
+               ic_options_free(resp->header_options);
+       free(resp);
+}
+
+
+API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop, ...)
+{
+       int value;
+       va_list args;
+       char *new_resource_uri = NULL;
+       iotcon_options_h options = NULL;
+
+       va_start(args, prop);
+
+       switch (prop) {
+       case IOTCON_RESPONSE_INTERFACE:
+               resp->iface = va_arg(args, int);
+               break;
+       case IOTCON_RESPONSE_REPRESENTATION:
+               resp->repr = va_arg(args, iotcon_repr_h);
+               break;
+       case IOTCON_RESPONSE_RESULT:
+               value = va_arg(args, int);
+               if (value < IOTCON_RESPONSE_RESULT_OK || IOTCON_RESPONSE_RESULT_MAX <= value) {
+                       ERR("Invalid value(%d)", value);
+                       return IOTCON_ERROR_PARAM;
+               }
+               resp->result = value;
+               break;
+       case IOTCON_RESPONSE_RESOURCE_URI:
+               new_resource_uri = va_arg(args, char*);
+               if (resp->new_uri)
+                       free(resp->new_uri);
+
+               if (new_resource_uri)
+                       resp->new_uri = ic_utils_strdup(new_resource_uri);
+               else
+                       resp->new_uri = NULL;
+               break;
+       case IOTCON_RESPONSE_HEADER_OPTIONS:
+               options = va_arg(args, iotcon_options_h);
+               if (resp->header_options)
+                       ic_options_free(resp->header_options);
+
+               if (true == options->has_parent)
+                       resp->header_options = ic_options_ref(options);
+               else
+                       resp->header_options = options;
+               resp->header_options->has_parent = true;
+               break;
+       case IOTCON_RESPONSE_NONE:
+       default:
+               break;
+       }
+
+       va_end(args);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_response_send(iotcon_response_h resp)
+{
+       FN_CALL;
+       int ret;
+
+       RETV_IF(NULL == resp, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == resp->repr, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_send_res_response_data(resp);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_send_res_response_data() Fail(%d)", ret);
+
+       return ret;
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index e676d93..6adfe3d
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_STRUCT_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_STRUCT_H__
 
+#include <stdint.h>
+#include <stdbool.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "iotcon-constant.h"
 #include "iotcon-struct.h"
 
 struct ic_value_s {
@@ -55,21 +61,78 @@ typedef struct {
        struct ic_repr_s *repr;
 } ic_val_repr_s;
 
-struct ic_options_s {
+struct ic_options {
        bool has_parent;
        GHashTable *options;
 };
 
-/* related with iotcon_response_property_e */
-struct ic_res_response_s {
-       char *new_resource_uri;
+struct ic_observe_info {
+       iotcon_observe_action_e action;
+       uint8_t observer_id;
+};
+
+typedef void* oc_request_h;
+typedef void* oc_resource_h;
+
+typedef struct ic_resource {
+       void *handle;
+       iotcon_request_handler_cb request_handler_cb;
+       void *user_data;
+} resource_handler_s;
+
+struct ic_remote_resource {
+       char *uri;
+       char *host;
+       bool is_observable;
+       bool is_collection;
+       iotcon_options_h header_options;
+       iotcon_str_list_s *types;
+       int ifaces;
+       iotcon_observe_h observe_handle;
+};
+
+struct ic_resource_request {
+       char *request_type;
+       char *uri;
+       iotcon_options_h header_options;
+       iotcon_query_h query;
+       int request_handler_flag;
+       struct ic_observe_info observation_info;
+       iotcon_repr_h repr;
+       oc_request_h request_handle;
+       oc_resource_h resource_handle;
+};
+
+struct ic_resource_response {
+       char *new_uri;
        int error_code;
        iotcon_options_h header_options;
-       iotcon_interface_e interface;
-       iotcon_request_h request_handle;
-       iotcon_resource_h resource_handle;
-       iotcon_entity_handler_result_e result;
+       iotcon_interface_e iface;
+       iotcon_response_result_e result;
+       iotcon_repr_h repr;
+       oc_request_h request_handle;
+       oc_resource_h resource_handle;
+};
+
+struct ic_notify_msg {
+       int error_code;
+       iotcon_interface_e iface;
        iotcon_repr_h repr;
 };
 
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_STRUCT_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_STRUCT_H__
old mode 100644 (file)
new mode 100755 (executable)
index 8210cf6..30c603a
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 
+#include "iotcon-struct.h"
 #include "ic-common.h"
 #include "ic-utils.h"
 
@@ -35,15 +37,144 @@ char* ic_utils_strdup(const char *src)
        return dest;
 }
 
-static void _ic_utils_print_str(void *str, void *user_data)
+
+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 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)
 {
-       char *s = str;
+       iotcon_str_list_s *new_list = NULL;
+
+       RETV_IF(NULL == str_list, NULL);
 
-       if (s)
-               DBG("list item : %s", s);
+       while (str_list) {
+               new_list = iotcon_str_list_append(new_list, str_list->string);
+               str_list = str_list->next;
+       }
+
+       return new_list;
 }
 
-void ic_utils_print_str_list(GList *list)
+
+API unsigned int iotcon_str_list_length(iotcon_str_list_s *str_list)
 {
-       g_list_foreach(list, _ic_utils_print_str, NULL);
+       unsigned int length = 0;
+
+       RETV_IF(NULL == str_list, 0);
+
+       while (str_list) {
+               length++;
+               str_list = str_list->next;
+       }
+
+       return length;
+}
+
+
+API void iotcon_str_list_foreach(iotcon_str_list_s *str_list,
+               iotcon_string_foreach_cb cb, void *user_data)
+{
+       RET_IF(NULL == str_list);
+
+       while (str_list) {
+               cb(str_list->string, user_data);
+               str_list = str_list->next;
+       }
+}
+
+
+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 = 1; i < n; i++) {
+               str_list = str_list->next;
+               if (NULL == str_list)
+                       return NULL;
+       }
+
+       return str_list->string;
 }
index 2941190..5573298 100644 (file)
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__
 
-#include <glib.h>
+#include "iotcon-struct.h"
+
+#define STR_EQUAL 0
 
 char* ic_utils_strdup(const char *src);
-void ic_utils_print_str_list(GList *list);
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__ */
old mode 100644 (file)
new mode 100755 (executable)
index 6a942d6..0b68b47
--- a/lib/ic.c
+++ b/lib/ic.c
  * limitations under the License.
  */
 #include <stdlib.h>
+#include <stdint.h>
 #include <errno.h>
 #include <glib.h>
 #include <glib-object.h>
 
 #include "iotcon.h"
-
 #include "ic-common.h"
 #include "ic-utils.h"
 #include "ic-struct.h"
 #include "ic-ioty.h"
-#include "ic-options.h"
+#include "ic.h"
 
 /**
  * @brief global context
  */
-static ic_ctx_s ic_ctx;
-static gboolean ic_is_init = FALSE;
-
-static const char *IC_INTERFACE_DEFAULT = "oc.mi.def";
-static const char *IC_INTERFACE_LINK = "oc.mi.ll";
-static const char *IC_INTERFACE_BATCH = "oc.mi.b";
-static const char *IC_INTERFACE_GROUP = "oc.mo.grp";
+static GHashTable *ic_request_cb_hash;
+static bool ic_is_init = false;
 
-ic_ctx_s* ic_get_ctx()
+static void _free_resource(gpointer data)
 {
-       return &ic_ctx;
-}
-
-
-static void _delete_resource_value(gpointer data)
-{
-       resource_handler_s *value = data;
+       int ret;
+       iotcon_resource_h resource = data;
 
        RET_IF(NULL == data);
 
-       free(value->if_name);
-       free(value->rt_name);
-       free(value->uri_name);
-       value->rest_api_cb = NULL;
-}
-
-gboolean iotcon_is_init(void)
-{
-       return ic_is_init;
-}
+       ret = ic_ioty_unregister_res(resource->handle);
+       if (IOTCON_ERROR_NONE != ret)
+               ERR("ic_ioty_unregister_res() Fail(%d)", ret);
 
-static void _set_iotcon_init(gboolean tag)
-{
-       ic_is_init = tag;
+       free(resource);
 }
 
+/* Host address should begin with "coap://" */
 API void iotcon_initialize(const char *addr, unsigned short port)
 {
        FN_CALL;
 
-       RETM_IF(TRUE == iotcon_is_init(), "already initialized");
+       RETM_IF(true == ic_is_init, "already initialized");
+       RET_IF(NULL == addr);
+
+       ic_ioty_config(addr, port);
+       ic_request_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
+                       _free_resource);
 
-       ic_iotivity_config(addr, port);
-       ic_ctx.entity_cb_hash = g_hash_table_new_full(g_int_hash, g_str_equal, NULL,
-                       _delete_resource_value);
 #if !GLIB_CHECK_VERSION(2,35,0)
        g_type_init();
 #endif
-       _set_iotcon_init(TRUE);
+       ic_is_init = true;
 }
 
-API void iotcon_deinitialize()
-{
-       FN_CALL;
-
-       RETM_IF(FALSE == iotcon_is_init(), "Not initialized");
 
-       g_hash_table_destroy(ic_ctx.entity_cb_hash);
-       g_list_free(ic_ctx.found_device_cb_lst);
-       _set_iotcon_init(FALSE);
-}
-
-API iotcon_response_h iotcon_response_new(iotcon_request_h req_h,
-               iotcon_resource_h res_h)
+API void iotcon_deinitialize()
 {
        FN_CALL;
 
-       iotcon_response_h resp = calloc(1, sizeof(struct ic_res_response_s));
-       if (NULL == resp) {
-               ERR("calloc() Fail(%d)", errno);
-               return NULL;
-       }
+       RETM_IF(false == ic_is_init, "Not initialized");
 
-       resp->request_handle = req_h;
-       resp->resource_handle = res_h;
+       g_hash_table_destroy(ic_request_cb_hash);
+       ic_request_cb_hash = NULL;
 
-       return resp;
+       ic_is_init = false;
 }
 
 
-API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop,
-               ...)
+static gboolean _find_valid_resource(gpointer key, gpointer value, gpointer user_data)
 {
-       int value;
-       va_list args;
-       char *new_resource_uri = NULL;
-       iotcon_options_h options = NULL;
-
-       va_start(args, prop);
-
-       switch (prop) {
-       case IOTCON_RESP_INTERFACE:
-               resp->interface = va_arg(args, int);
-               break;
-       case IOTCON_RESP_REPRESENTATION:
-               resp->repr = va_arg(args, iotcon_repr_h);
-               break;
-       case IOTCON_RESP_RESULT:
-               value = va_arg(args, int);
-               if (value < IOTCON_EH_OK || IOTCON_EH_MAX <= value) {
-                       ERR("Invalid value");
-                       return IOTCON_ERROR_PARAM;
-               }
-               resp->result = value;
-               break;
-       case IOTCON_RESP_ERR_CODE:
-               resp->error_code = va_arg(args, int);
-               break;
-       case IOTCON_RESP_RES_URI:
-               new_resource_uri = va_arg(args, char*);
-               if (resp->new_resource_uri)
-                       free(resp->new_resource_uri);
-
-               if (new_resource_uri)
-                       resp->new_resource_uri = ic_utils_strdup(new_resource_uri);
-               else
-                       resp->new_resource_uri = NULL;
-               break;
-       case IOTCON_RESP_HEADER_OPTIONS:
-               options = va_arg(args, iotcon_options_h);
-               if (resp->header_options)
-                       ic_options_free(resp->header_options);
-
-               if (true == options->has_parent)
-                       resp->header_options = iotcon_options_clone(options);
-               else
-                       resp->header_options = options;
-               resp->header_options->has_parent = true;
-               break;
-       case IOTCON_RESP_NONE:
-       default:
-               break;
-       }
-
-       va_end(args);
-
-       return IOTCON_ERROR_NONE;
+       return (key == user_data);
 }
 
-API void iotcon_response_free(iotcon_response_h resp)
-{
-       FN_CALL;
-       struct ic_res_response_s *data = resp;
-
-       RET_IF(NULL == resp);
 
-       free(data->new_resource_uri);
-
-       /* To avoid unnecessary ERR log (header_options could be NULL) */
-       if (resp->header_options)
-               ic_options_free(resp->header_options);
-       iotcon_repr_free(resp->repr);
-       free(data);
-}
-
-API iotcon_repr_h iotcon_request_get_representation(const iotcon_request_s *request)
+resource_handler_s* ic_get_resource_handler_data(void *handle)
 {
-       RETV_IF(NULL == request, NULL);
-       return request->repr;
+       return g_hash_table_find(ic_request_cb_hash, _find_valid_resource, handle);
 }
 
-API iotcon_resource_h iotcon_register_resource(const char *iot_uri,
-               const char *iot_rt,
-               iotcon_interface_e iot_if,
-               iotcon_resource_property_e iot_rt_type,
-               iotcon_rest_api_handle_cb entity_handler_cb)
+
+API iotcon_resource_h iotcon_register_resource(const char *uri,
+               iotcon_str_list_s *res_types,
+               int ifaces,
+               uint8_t properties,
+               iotcon_request_handler_cb cb,
+               void *user_data)
 {
        FN_CALL;
+       iotcon_resource_h resource;
 
-       resource_handler_s *res;
-       iotcon_resource_h ret_handle;
-
-       RETV_IF(NULL == iot_uri, NULL);
-       RETV_IF(NULL == iot_rt, NULL);
-       RETV_IF(NULL == entity_handler_cb, NULL);
+       RETV_IF(NULL == uri, NULL);
+       RETV_IF(NULL == res_types, NULL);
+       RETV_IF(NULL == cb, NULL);
 
-       res = calloc(1, sizeof(resource_handler_s));
-       if (NULL == res) {
+       resource = calloc(1, sizeof(struct ic_resource));
+       if (NULL == resource) {
                ERR("calloc Fail(%d)", errno);
                return NULL;
        }
 
-       switch (iot_if) {
-       case IOTCON_INTERFACE_GROUP:
-               res->if_name = ic_utils_strdup(IC_INTERFACE_GROUP);
-               break;
-       case IOTCON_INTERFACE_BATCH:
-               res->if_name = ic_utils_strdup(IC_INTERFACE_BATCH);
-               break;
-       case IOTCON_INTERFACE_LINK:
-               res->if_name = ic_utils_strdup(IC_INTERFACE_LINK);
-               break;
-       case IOTCON_INTERFACE_DEFAULT:
-       default:
-               res->if_name = ic_utils_strdup(IC_INTERFACE_DEFAULT);
-               break;
-       }
-
-       res->rt_name = ic_utils_strdup(iot_rt);
-       if (NULL == res->rt_name) {
-               ERR("ic_utils_strdup() Fail(%d)", errno);
-               free(res);
+       resource->handle = ic_ioty_register_res(uri, res_types, ifaces, properties);
+       if (NULL == resource->handle) {
+               ERR("ic_ioty_register_res() Fail");
+               free(resource);
                return NULL;
        }
 
-       res->uri_name = ic_utils_strdup(iot_uri);
-       if (NULL == res->uri_name) {
-               ERR("ic_utils_strdup() Fail(%d)", errno);
-               free(res->rt_name);
-               free(res);
-               return NULL;
-       }
+       resource->request_handler_cb = cb;
+       resource->user_data = user_data;
 
-       res->rest_api_cb = entity_handler_cb;
+       g_hash_table_insert(ic_request_cb_hash, resource->handle, resource);
 
-       ret_handle = ic_ioty_register_res(iot_uri, iot_rt, iot_if, iot_rt_type);
-       if (NULL == ret_handle) {
-               ERR("registerResource Fail");
-               free(res->rt_name);
-               free(res->uri_name);
-               free(res);
-               return NULL;
-       }
-
-       g_hash_table_insert(ic_ctx.entity_cb_hash, ret_handle, res);
-
-       return ret_handle;
+       return resource;
 }
 
 
-API int iotcon_unregister_resource(const iotcon_resource_h resource_handle)
+API void iotcon_unregister_resource(iotcon_resource_h resource)
 {
        FN_CALL;
 
-       int ret;
-
-       ret = ic_ioty_unregister_res(resource_handle);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_bind_type_to_res() Fail(%d)", ret);
-
-       g_hash_table_remove(ic_ctx.entity_cb_hash, resource_handle);
+       RET_IF(NULL == resource);
 
-       return ret;
+       g_hash_table_remove(ic_request_cb_hash, resource->handle);
 }
 
-API int iot_bind_interface_to_resource(iotcon_resource_h resource_handle,
-               const char *interface_type)
+
+API int iotcon_bind_interface(iotcon_resource_h resource, iotcon_interface_e iface)
 {
        FN_CALL;
-
        int ret;
 
-       ret = ic_ioty_bind_iface_to_res(resource_handle, interface_type);
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_bind_iface_to_res(resource->handle, iface);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_bind_type_to_res() Fail(%d)", ret);
+               ERR("ic_ioty_bind_iface_to_res() Fail(%d)", ret);
 
        return ret;
 }
 
-API int iotcon_bind_type_to_resource(iotcon_resource_h resource_handle,
-               const char *resource_type)
+
+API int iotcon_bind_type(iotcon_resource_h resource, const char *resource_type)
 {
        FN_CALL;
-
        int ret;
 
-       ret = ic_ioty_bind_type_to_res(resource_handle, resource_type);
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == resource_type, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_bind_type_to_res(resource->handle, resource_type);
        if (IOTCON_ERROR_NONE != ret)
                ERR("ic_ioty_bind_type_to_res() Fail(%d)", ret);
 
        return ret;
 }
 
+
 API int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child)
 {
        FN_CALL;
-
        int ret;
 
-       ret = ic_ioty_bind_res(parent, child);
+       RETV_IF(NULL == parent, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == child, IOTCON_ERROR_PARAM);
+
+       ret = ic_ioty_bind_res(parent->handle, child->handle);
        if (IOTCON_ERROR_NONE != ret)
                ERR("ic_ioty_bind_res() Fail(%d)", ret);
 
@@ -316,486 +183,107 @@ API int iotcon_bind_resource(iotcon_resource_h parent, iotcon_resource_h child)
 }
 
 
-API int iotcon_register_device_info(iotcon_device_info_s *device_info)
+API int iotcon_start_presence(unsigned int time_to_live)
 {
        FN_CALL;
-
        int ret;
 
-       ret = ic_ioty_register_device_info(device_info);
+       ret = ic_ioty_start_presence(time_to_live);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_register_device_info() Fail(%d)", ret);
+               ERR("ic_ioty_start_presence() Fail(%d)", ret);
 
        return ret;
 }
 
-API int iotcon_subscribe_device_info(char *host, char *uri,
-               iotcon_found_device_info_cb found_cb /*, int QoS*/)
-{
-       FN_CALL;
-
-       int ret = IOTCON_ERROR_NONE;
-
-       RETV_IF(NULL == uri, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == found_cb, IOTCON_ERROR_PARAM);
-
-       /* If we add device_cb to manage app's CB if we don't have any app's cb */
-       if (0 == g_list_length(ic_ctx.found_device_cb_lst)) {
-               ret = ic_ioty_get_device_info(host, uri);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("ic_ioty_get_device_info() Fail(%d)", ret);
-                       return ret;
-               }
-       }
-
-       ic_ctx.found_device_cb_lst = g_list_append(ic_ctx.found_device_cb_lst, found_cb);
-
-       return IOTCON_ERROR_NONE;
-}
-
-API void iotcon_unsubscribe_device_info(char *host, char *uri,
-               iotcon_found_device_info_cb found_cb)
-{
-       FN_CALL;
 
-       RET_IF(NULL == host);
-       RET_IF(NULL == uri);
-       RET_IF(NULL == found_cb);
-
-       GList *node = g_list_first(ic_ctx.found_device_cb_lst);
-       while (node) {
-               GList *next_node = node->next;
-
-               iotcon_found_device_info_cb found_cb_check = node->data;
-               if (found_cb_check == found_cb) {
-                       ic_ctx.found_device_cb_lst = g_list_remove_link(ic_ctx.found_device_cb_lst,
-                                       node);
-                       g_list_free_1(node);
-               }
-               node = next_node;
-       }
-}
-
-API int iotcon_send_notify_response(iotcon_response_h resp, iotcon_observers observers)
+API int iotcon_stop_presence()
 {
        FN_CALL;
        int ret;
 
-       RETV_IF(NULL == resp, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == observers, IOTCON_ERROR_PARAM);
-
-       ret = ic_ioty_send_notify(resp, observers);
+       ret = ic_ioty_stop_presence();
        if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_send_notify() Fail(%d)", ret);
+               ERR("ic_ioty_stop_presence() Fail(%d)", ret);
 
        return ret;
 }
 
-API int iotcon_send_resource_response(iotcon_response_h resp)
-{
-       FN_CALL;
-       int ret;
-
-       RETV_IF(NULL == resp, IOTCON_ERROR_PARAM);
-
-       ret = ic_ioty_send_res_response_data(resp);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_send_res_response_data() Fail(%d)", ret);
-
-       return ret;
-}
 
 API iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
-               iotcon_presence_handle_cb presence_handler_cb, void *user_data)
+               const char *resource_type, iotcon_presence_cb cb, void *user_data)
 {
        iotcon_presence_h handle;
 
-       handle = ic_ioty_subscribe_presence(host_address, presence_handler_cb, user_data);
+       RETV_IF(NULL == host_address, NULL);
+       RETV_IF(NULL == cb, NULL);
+       if (NULL == resource_type)
+               resource_type = "";
+
+       handle = ic_ioty_subscribe_presence(host_address, resource_type, cb, user_data);
        if (NULL == handle)
                ERR("ic_ioty_subscribe_presence() Fail");
 
        return handle;
 }
 
-API int iotcon_unsubscribe_presence(iotcon_presence_h presence_handle)
-{
-       FN_CALL;
-
-       int ret;
 
-       ret = ic_ioty_unsubscribe_presence(presence_handle);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_unsubscribe_presence() Fail(%d)", ret);
-
-       return ret;
-}
-
-API int iotcon_start_presence(const unsigned int time_to_live)
+API int iotcon_unsubscribe_presence(iotcon_presence_h handle)
 {
        FN_CALL;
-
        int ret;
 
-       ret = ic_ioty_start_presence(time_to_live);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_start_presence() Fail(%d)", ret);
-
-       return ret;
-}
-
-API int iotcon_stop_presence()
-{
-       FN_CALL;
+       RETV_IF(NULL == handle, IOTCON_ERROR_PARAM);
 
-       int ret;
-
-       ret = ic_ioty_stop_presence();
+       ret = ic_ioty_unsubscribe_presence(handle);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_stop_presence() Fail(%d)", ret);
+               ERR("ic_ioty_unsubscribe_presence() Fail(%d)", ret);
 
        return ret;
 }
 
-API int iotcon_find_resource(const char *host, const char *resource_name,
-               iotcon_found_resource_cb found_resource_cb, void *user_data)
-{
-       FN_CALL;
-
-       int ret = IOTCON_ERROR_NONE;
-
-       RETV_IF(NULL == host, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == resource_name, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == found_resource_cb, IOTCON_ERROR_PARAM);
 
-       ret = ic_ioty_find_resource(host, resource_name, found_resource_cb, user_data);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_find_resource() Fail(%d)", ret);
-
-       return ret;
-}
-
-API iotcon_resource_s iotcon_construct_resource_object(const char *host,
-                                                                                               const char *uri,
-                                                                                               bool is_observable,
-                                                                                               iotcon_resource_types resource_type,
-                                                                                               iotcon_resource_interfaces resource_if)
+API iotcon_notimsg_h iotcon_notimsg_new(iotcon_repr_h repr, iotcon_interface_e iface)
 {
-       FN_CALL;
-
-       iotcon_resource_s resource_s = {0};
-       GList *node = NULL;
+       iotcon_notimsg_h msg;
 
-       resource_s.resource_host = ic_utils_strdup(host);
-       resource_s.resource_uri = ic_utils_strdup(uri);
-       resource_s.is_observable = is_observable;
-       resource_s.resource_types = iotcon_resource_types_new();
-       resource_s.resource_interfaces = iotcon_resource_interfaces_new();
-
-       for (node = g_list_first(resource_type); node; node = g_list_next(node)) {
-               resource_s.resource_types = g_list_append(resource_s.resource_types,
-                               ic_utils_strdup(node->data));
-       }
+       RETV_IF(NULL == repr, NULL);
 
-       for (node = g_list_first(resource_if); node; node = g_list_next(node)) {
-               resource_s.resource_interfaces = g_list_append(resource_s.resource_interfaces,
-                               ic_utils_strdup(node->data));
-       }
-
-       return resource_s;
-}
-
-API void iotcon_destruct_resource_object(iotcon_resource_s *resource)
-{
-       FN_CALL;
-
-       free(resource->resource_uri);
-       free(resource->resource_host);
-       iotcon_options_free(resource->header_options);
-       iotcon_resource_types_free(resource->resource_types);
-       iotcon_resource_interfaces_free(resource->resource_interfaces);
-}
-
-API iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource)
-{
-       FN_CALL;
-
-       iotcon_resource_s resource_s = {0};
-       GList *node = NULL;
-
-       resource_s.resource_host = ic_utils_strdup(resource.resource_host);
-       resource_s.resource_uri = ic_utils_strdup(resource.resource_uri);
-       resource_s.is_observable = resource.is_observable;
-       resource_s.resource_types = iotcon_resource_types_new();
-       resource_s.resource_interfaces = iotcon_resource_interfaces_new();
-       resource_s.observe_handle = resource.observe_handle;
-
-       for (node = g_list_first(resource.resource_types); node; node = g_list_next(node)) {
-               resource_s.resource_types = g_list_append(resource_s.resource_types,
-                               ic_utils_strdup(node->data));
+       msg = calloc(1, sizeof(struct ic_notify_msg));
+       if (NULL == msg) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
        }
 
-       for (node = g_list_first(resource.resource_interfaces); node;
-                       node = g_list_next(node)) {
-               resource_s.resource_interfaces = g_list_append(resource_s.resource_interfaces,
-                               ic_utils_strdup(node->data));
-       }
+       msg->repr = repr;
+       msg->iface = iface;
+       msg->error_code = 200;
 
-       return resource_s;
+       return msg;
 }
 
-API int iotcon_get(iotcon_resource_s resource, iotcon_query query,
-               iotcon_on_get_cb on_get_cb, void *user_data)
-{
-       FN_CALL;
-
-       RETV_IF(NULL == on_get_cb, IOTCON_ERROR_PARAM);
-
-       int ret = IOTCON_ERROR_NONE;
-
-       ret = ic_ioty_get(resource, query, on_get_cb, user_data);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_get() Fail(%d)", ret);
-
-       return ret;
-}
 
-API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
-               iotcon_on_put_cb on_put_cb, void *user_data)
+API void iotcon_notimsg_free(iotcon_notimsg_h msg)
 {
-       FN_CALL;
-
-       int ret = IOTCON_ERROR_NONE;
-
-       RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
-       RETV_IF(NULL == on_put_cb, IOTCON_ERROR_PARAM);
-
-       ret = ic_ioty_put(resource, repr, query, on_put_cb, user_data);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_put() Fail(%d)", ret);
+       RET_IF(NULL == msg);
 
-       return ret;
+       iotcon_repr_free(msg->repr);
+       free(msg);
 }
 
-API int iotcon_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
-               iotcon_on_post_cb on_post_cb, void *user_data)
-{
-       FN_CALL;
-
-       int ret = IOTCON_ERROR_NONE;
 
-       RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
-
-       ret = ic_ioty_post(resource, repr, query, on_post_cb, user_data);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_post() Fail(%d)", ret);
-
-       return ret;
-}
-
-API int iotcon_delete_resource(iotcon_resource_s resource,
-               iotcon_on_delete_cb on_delete_cb, void *user_data)
+API int iotcon_notify(iotcon_resource_h resource, iotcon_notimsg_h msg,
+               iotcon_observers_h observers)
 {
-       FN_CALL;
-
-       int ret = IOTCON_ERROR_NONE;
-
-       ret = ic_ioty_delete_res(resource, on_delete_cb, user_data);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_delete_res() Fail(%d)", ret);
-
-       return ret;
-}
-
-API int iotcon_observe(iotcon_observe_type_e observe_type,
-               iotcon_resource_s *resource,
-               iotcon_query query,
-               iotcon_on_observe_cb on_observe_cb,
-               void *user_data)
-{
-       FN_CALL;
-
-       int ret = IOTCON_ERROR_NONE;
-
-       RETV_IF(NULL == on_observe_cb, IOTCON_ERROR_PARAM);
-
-       ret = ic_ioty_observe(resource, observe_type, query, on_observe_cb, user_data);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_observe() Fail(%d)", ret);
-
-       return ret;
-}
-
-API int iotcon_cancel_observe(iotcon_resource_s resource)
-{
-       FN_CALL;
+       int ret;
 
-       int ret = IOTCON_ERROR_NONE;
+       RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == observers, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == msg, IOTCON_ERROR_PARAM);
+       RETV_IF(NULL == msg->repr, IOTCON_ERROR_PARAM);
 
-       ret = ic_ioty_cancel_observe(resource);
+       ret = ic_ioty_send_notify(resource->handle, msg, observers);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("ic_ioty_cancel_observe() Fail(%d)", ret);
+               ERR("ic_ioty_send_notify() Fail(%d)", ret);
 
        return ret;
 }
-
-API iotcon_resource_types iotcon_resource_types_new()
-{
-       return NULL;
-}
-
-API iotcon_resource_types iotcon_resource_types_insert(
-               iotcon_resource_types resource_types, const char *resource_type)
-{
-       FN_CALL;
-
-       resource_types = g_list_append(resource_types, ic_utils_strdup(resource_type));
-       return resource_types;
-}
-
-API void iotcon_resource_types_free(iotcon_resource_types resource_types)
-{
-       FN_CALL;
-
-       g_list_free_full(resource_types, free);
-}
-
-API iotcon_resource_interfaces iotcon_resource_interfaces_new()
-{
-       FN_CALL;
-
-       return NULL;
-}
-
-API iotcon_resource_interfaces iotcon_resource_interfaces_insert(
-               iotcon_resource_interfaces resource_interfaces, iotcon_interface_e interface)
-{
-       FN_CALL;
-
-       char *resource_interface;
-
-       switch (interface) {
-       case IOTCON_INTERFACE_GROUP:
-               resource_interface = ic_utils_strdup(IC_INTERFACE_GROUP);
-               break;
-       case IOTCON_INTERFACE_BATCH:
-               resource_interface = ic_utils_strdup(IC_INTERFACE_BATCH);
-               break;
-       case IOTCON_INTERFACE_LINK:
-               resource_interface = ic_utils_strdup(IC_INTERFACE_LINK);
-               break;
-       case IOTCON_INTERFACE_DEFAULT:
-               resource_interface = ic_utils_strdup(IC_INTERFACE_DEFAULT);
-               break;
-       default:
-               ERR("Invalid Interface");
-               return resource_interfaces;
-       }
-
-       resource_interfaces = g_list_append(resource_interfaces, resource_interface);
-
-       return resource_interfaces;
-}
-
-API void iotcon_resource_interfaces_free(iotcon_resource_interfaces resource_interfaces)
-{
-       FN_CALL;
-
-       g_list_free_full(resource_interfaces, free);
-}
-
-API iotcon_query iotcon_query_new()
-{
-       iotcon_query query = NULL;
-
-       query = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
-
-       return query;
-}
-
-API void iotcon_query_insert(iotcon_query query, const char *key, const char *value)
-{
-       g_hash_table_insert(query, ic_utils_strdup(key), ic_utils_strdup(value));
-}
-
-API void iotcon_query_free(iotcon_query query)
-{
-       RET_IF(NULL == query);
-
-       g_hash_table_destroy(query);
-}
-
-API char* iotcon_query_lookup(iotcon_query query, const char *key)
-{
-       return g_hash_table_lookup(query, key);
-}
-
-API iotcon_observers iotcon_observation_new()
-{
-       return NULL;
-}
-
-API iotcon_observers iotcon_observation_insert(iotcon_observers observers,
-               iotcon_observation_info_s obs)
-{
-       iotcon_observation_info_s *obs_node = calloc(1, sizeof(iotcon_observation_info_s));
-       RETV_IF(NULL == obs_node, observers);
-
-       obs_node->action = obs.action;
-       obs_node->obs_id = obs.obs_id;
-
-       observers = g_list_append(observers, obs_node);
-
-       return observers;
-}
-
-API iotcon_observers iotcon_observation_delete(iotcon_observers observers,
-               iotcon_observation_info_s obs)
-{
-       GList *node = NULL;
-
-       node = g_list_find(observers, (gconstpointer)&obs);
-       observers = g_list_delete_link(observers, node);
-
-       return observers;
-}
-
-API void iotcon_observation_free(iotcon_observers observers)
-{
-       g_list_free_full(observers, free);
-}
-
-API char* iotcon_resource_get_uri(iotcon_resource_s resource_s)
-{
-       return resource_s.resource_uri;
-}
-
-API char* iotcon_resource_get_host(iotcon_resource_s resource_s)
-{
-       return resource_s.resource_host;
-}
-
-API iotcon_resource_types iotcon_resource_get_types(iotcon_resource_s resource_s)
-{
-       return resource_s.resource_types;
-}
-
-API iotcon_resource_interfaces iotcon_resource_get_interfaces(iotcon_resource_s resource_s)
-{
-       return resource_s.resource_interfaces;
-}
-
-API void iotcon_resource_set_options(iotcon_resource_s *resource,
-               iotcon_options_h header_options)
-{
-       RET_IF(NULL == resource);
-
-       if (resource->header_options)
-               iotcon_options_free(resource->header_options);
-
-       resource->header_options = header_options;
-}
-
-API iotcon_options_h iotcon_request_get_options(iotcon_request_s request)
-{
-       return request.header_options;
-}
similarity index 73%
rename from lib/ic-handler.h
rename to lib/ic.h
index f4d530d..f570313 100644 (file)
+++ b/lib/ic.h
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_HANDLER_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_HANDLER_H__
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__
 
-#include "ic-ioty.h"
+#include "ic-struct.h"
 
 resource_handler_s* ic_get_resource_handler_data(void *handle);
 
-void ic_get_device_info_handler(iotcon_device_info_s *info);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_HANDLER_H__ */
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__ */
index 7bde6e7..491d518 100644 (file)
@@ -17,7 +17,7 @@
 #define __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
 
 /**
- * @brief HeaderOption range from 2048 t0 3000
+ * @brief HeaderOption range from 2048 to 3000
  * NOTE: HeaderOptionID  is an unsigned integer value which MUST be within
  * range of 2048 to 3000 inclusive of lower and upper bound.
  * HeaderOptions instance creation fails if above condition is not satisfied.
@@ -25,6 +25,9 @@
 #define IOTCON_OPTIONID_MIN 2048
 #define IOTCON_OPTIONID_MAX 3000
 
+#define IOTCON_ALL_INTERFACES "0.0.0.0"
+#define IOTCON_RANDOM_PORT 0
+#define IOTCON_MULTICAST_ADDRESS "coap://224.0.1.187"
 
 /**
  * @brief Action associated with observation
@@ -33,7 +36,7 @@ typedef enum {
        IOTCON_OBSERVE_REGISTER = 0,
        IOTCON_OBSERVE_DEREGISTER = 1,
        IOTCON_OBSERVE_NO_OPTION = 2
-} iotcon_osbserve_action_e;
+} iotcon_observe_action_e;
 
 typedef enum {
        IOTCON_OBSERVE = 0,
@@ -41,11 +44,12 @@ typedef enum {
 } iotcon_observe_type_e;
 
 typedef enum {
-       IOTCON_INTERFACE_DEFAULT = 0,
-       IOTCON_INTERFACE_LINK = 1,
-       IOTCON_INTERFACE_BATCH = 2,
-       IOTCON_INTERFACE_GROUP = 3,
-       IOTCON_INTERFACE_MAX = 4
+       IOTCON_INTERFACE_NONE = 0,
+       IOTCON_INTERFACE_DEFAULT = (1 << 0),
+       IOTCON_INTERFACE_LINK = (1 << 1),
+       IOTCON_INTERFACE_BATCH = (1 << 2),
+       IOTCON_INTERFACE_GROUP = (1 << 3),
+       IOTCON_INTERFACE_MAX = (1 << 4)
 } iotcon_interface_e;
 
 typedef enum {
@@ -58,30 +62,37 @@ typedef enum {
 } iotcon_resource_property_e;
 
 typedef enum {
-       IOTCON_RESP_NONE = 0,
-       IOTCON_RESP_RES_URI = 1,
-       IOTCON_RESP_ERR_CODE = 2,
-       IOTCON_RESP_RESULT = 3,
-       IOTCON_RESP_REPRESENTATION = 4,
-       IOTCON_RESP_HEADER_OPTIONS = 5,
-       IOTCON_RESP_INTERFACE = 6,
+       IOTCON_RESPONSE_NONE = 0,
+       IOTCON_RESPONSE_RESOURCE_URI = 1,
+       IOTCON_RESPONSE_RESULT = 2,
+       IOTCON_RESPONSE_REPRESENTATION = 3,
+       IOTCON_RESPONSE_HEADER_OPTIONS = 4,
+       IOTCON_RESPONSE_INTERFACE = 5,
 } iotcon_response_property_e;
 
 typedef enum {
+       IOTCON_NO_FLAG = 0,
        IOTCON_INIT_FLAG = (1 << 0),
-       IOTCON_REQUEST_FLAG = (1 << 1),
+       IOTCON_CRUD_FLAG = (1 << 1),
        IOTCON_OBSERVE_FLAG = (1 << 2)
-} iotcon_entity_handler_flag_e;
+} iotcon_request_handler_flag_e;
 
 typedef enum {
-       IOTCON_EH_OK = 0,
-       IOTCON_EH_ERROR,
-       IOTCON_EH_RESOURCE_CREATED,
-       IOTCON_EH_RESOURCE_DELETED,
-       IOTCON_EH_SLOW,
-       IOTCON_EH_FORBIDDEN,
-       IOTCON_EH_MAX
-} iotcon_entity_handler_result_e;
+       IOTCON_RESPONSE_RESULT_OK = 0,
+       IOTCON_RESPONSE_RESULT_ERROR,
+       IOTCON_RESPONSE_RESULT_RESOURCE_CREATED,
+       IOTCON_RESPONSE_RESULT_RESOURCE_DELETED,
+       IOTCON_RESPONSE_RESULT_SLOW,
+       IOTCON_RESPONSE_RESULT_FORBIDDEN,
+       IOTCON_RESPONSE_RESULT_MAX
+} iotcon_response_result_e;
+
+typedef enum {
+       IOTCON_PRESENCE_OK = 0,
+       IOTCON_PRESENCE_STOPPED,
+       IOTCON_PRESENCE_TIMEOUT,
+       IOTCON_PRESENCE_ERROR
+} iotcon_presence_result_e;
 
 typedef enum {
        IOTCON_TYPE_NONE = 0,
old mode 100644 (file)
new mode 100755 (executable)
index 8067c6c..181225b
 #ifndef __IOT_CONNECTIVITY_MANAGER_REPRESENTATION_H__
 #define __IOT_CONNECTIVITY_MANAGER_REPRESENTATION_H__
 
+#include <stdbool.h>
+
 iotcon_repr_h iotcon_repr_new();
 void iotcon_repr_free(iotcon_repr_h repr);
 iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src);
 
 int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri);
 const char* iotcon_repr_get_uri(iotcon_repr_h repr);
-int iotcon_repr_delete_uri(iotcon_repr_h repr);
+int iotcon_repr_del_uri(iotcon_repr_h repr);
 
 /**
  * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
@@ -43,14 +45,14 @@ typedef void (*iotcon_resourcetype_fn)(const char *res_type, void *user_data);
 void iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resourcetype_fn fn,
                void *user_data);
 int iotcon_repr_get_resource_types_count(iotcon_repr_h repr);
-int iotcon_repr_delete_resource_types(iotcon_repr_h repr, const char *type);
+int iotcon_repr_del_resource_types(iotcon_repr_h repr, const char *type);
 
-int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *interface);
+int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *iface);
 typedef void (*iotcon_interface_fn)(const char *res_if, void *user_data);
 void iotcon_repr_get_resource_interfaces(iotcon_repr_h repr, iotcon_interface_fn fn,
                void *user_data);
 int iotcon_repr_get_resource_interfaces_count(iotcon_repr_h repr);
-int iotcon_repr_delete_resource_interfaces(iotcon_repr_h repr, const char *type);
+int iotcon_repr_del_resource_interfaces(iotcon_repr_h repr, const char *type);
 
 /**
  * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
@@ -97,7 +99,7 @@ void iotcon_repr_get_children(iotcon_repr_h parent, iotcon_children_fn fn,
 int iotcon_repr_get_children_count(iotcon_repr_h parent);
 iotcon_repr_h iotcon_repr_get_nth_child(iotcon_repr_h parent, int index);
 
-GList* iotcon_repr_get_key_list(iotcon_repr_h repr);
+iotcon_str_list_s* iotcon_repr_get_key_list(iotcon_repr_h repr);
 int iotcon_repr_get_keys_count(iotcon_repr_h repr);
 
 char* iotcon_repr_generate_json(iotcon_repr_h repr);
@@ -129,17 +131,17 @@ int iotcon_list_del_nth_repr(iotcon_list_h list, int pos);
 int iotcon_list_get_type(iotcon_list_h list);
 int iotcon_list_get_length(iotcon_list_h list);
 
-typedef void (*iotcon_int_list_fn)(int index, const int value, void *user_data);
-void iotcon_int_list_foreach(iotcon_list_h list, iotcon_int_list_fn fn, void *user_data);
-typedef void (*iotcon_bool_list_fn)(int index, const bool value, void *user_data);
-void iotcon_bool_list_foreach(iotcon_list_h list, iotcon_bool_list_fn fn, void *user_data);
-typedef void (*iotcon_double_list_fn)(int index, const double value, void *user_data);
-void iotcon_double_list_foreach(iotcon_list_h list, iotcon_double_list_fn fn, void *user_data);
-typedef void (*iotcon_str_list_fn)(int index, const char *value, void *user_data);
-void iotcon_str_list_foreach(iotcon_list_h list, iotcon_str_list_fn fn, void *user_data);
+typedef void (*iotcon_list_int_fn)(int index, const int value, void *user_data);
+void iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn, void *user_data);
+typedef void (*iotcon_list_bool_fn)(int index, const bool value, void *user_data);
+void iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn, void *user_data);
+typedef void (*iotcon_list_double_fn)(int index, const double value, void *user_data);
+void iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn, void *user_data);
+typedef void (*iotcon_list_str_fn)(int index, const char *value, void *user_data);
+void iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn, void *user_data);
 typedef void (*iotcon_list_list_fn)(int index, iotcon_list_h value, void *user_data);
 void iotcon_list_list_foreach(iotcon_list_h list, iotcon_list_list_fn fn, void *user_data);
-typedef void (*iotcon_repr_list_fn)(int index, iotcon_repr_h value, void *user_data);
-void iotcon_repr_list_foreach(iotcon_list_h list, iotcon_repr_list_fn fn, void *user_data);
+typedef void (*iotcon_list_repr_fn)(int index, iotcon_repr_h value, void *user_data);
+void iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data);
 
 #endif /* __IOT_CONNECTIVITY_MANAGER_REPRESENTATION_H__ */
old mode 100644 (file)
new mode 100755 (executable)
index 295c437..ab2dc06
@@ -16,8 +16,7 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_H__
 #define __IOT_CONNECTIVITY_MANAGER_STRUCT_H__
 
-#include <stdbool.h>
-#include <glib.h>
+#include <stdint.h>
 
 #include "iotcon-constant.h"
 
@@ -25,79 +24,94 @@ typedef struct ic_value_s* iotcon_value_h;
 typedef struct ic_list_s* iotcon_list_h;
 typedef struct ic_repr_s* iotcon_repr_h;
 
-/**
- * @brief Handle to an OCResource object owned by the OCStack.
- */
-typedef void* iotcon_resource_h;
-typedef void* iotcon_request_h;
+typedef struct ic_resource* iotcon_resource_h;
+typedef struct ic_notify_msg* iotcon_notimsg_h;
+
 typedef void* iotcon_presence_h;
 typedef void* iotcon_observe_h;
 
-typedef GList* iotcon_observers;
-typedef unsigned char iotcon_observation_id;
-
-typedef struct ic_options_s* iotcon_options_h;
-typedef GHashTable* iotcon_query;
-
-typedef GList *iotcon_resource_types;
-typedef GList *iotcon_resource_interfaces;
+typedef struct _str_list {
+       char *string;
+       struct _str_list *next;
+} iotcon_str_list_s;
+
+
+typedef struct ic_options* iotcon_options_h;
+iotcon_options_h iotcon_options_new();
+void iotcon_options_free(iotcon_options_h options);
+int iotcon_options_insert(iotcon_options_h options, unsigned short id,
+               const char *data);
+int iotcon_options_delete(iotcon_options_h options, unsigned short id);
+const char* iotcon_options_lookup(iotcon_options_h options, unsigned short id);
+typedef void (*iotcon_options_foreach_cb)(unsigned short id, const char *data,
+               void *user_data);
+void iotcon_options_foreach(iotcon_options_h options,
+               iotcon_options_foreach_cb cb, void *user_data);
+
+
+typedef void* iotcon_query_h;
+iotcon_query_h iotcon_query_new();
+void iotcon_query_free(iotcon_query_h query);
+int iotcon_query_insert(iotcon_query_h query, const char *key, const char *value);
+int iotcon_query_delete(iotcon_query_h query, const char *key);
+const char* iotcon_query_lookup(iotcon_query_h query, const char *key);
+typedef void (*iotcon_query_foreach_cb)(const char *key, const char *value,
+               void *user_data);
+void 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);
+
+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);
+
+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);
+void 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);
+
+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);
+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 void (*iotcon_string_foreach_cb)(const char *string, void *user_data);
+void 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);
 
-
-typedef struct ic_res_response_s* iotcon_response_h;
-
-/**
- * @brief observation information structure
- */
-typedef struct {
-       /* Action associated with observation request */
-       iotcon_osbserve_action_e action;
-       /* Identifier for observation being registered/deregistered */
-       iotcon_observation_id obs_id;
-} iotcon_observation_info_s;
-
-
-typedef struct {
-       char *resource_uri;
-       char *resource_host;
-       bool is_observable;
-       bool is_collection;
-       iotcon_options_h header_options;
-       iotcon_resource_types resource_types;
-       iotcon_resource_interfaces resource_interfaces;
-       iotcon_observe_h observe_handle;
-} iotcon_resource_s;
-
-
-typedef struct {
-       char *request_type;
-       char *res_uri;
-       iotcon_options_h header_options;
-       iotcon_query query;
-       int request_handler_flag;
-       iotcon_request_h request_handle;
-       iotcon_resource_h resource_handle;
-       iotcon_observation_info_s observation_info;
-       iotcon_repr_h repr;
-} iotcon_request_s;
-
-
-/**
- * @brief Following structure describes the device properties.
- *        All non-Null properties will be included in a device discovery request.
- */
-typedef struct
-{
-       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;
-} iotcon_device_info_s;
 #endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_H__ */
old mode 100644 (file)
new mode 100755 (executable)
index 0f87df0..b2368dd
@@ -20,6 +20,7 @@
 extern "C" {
 #endif
 
+#include <stdint.h>
 #include <iotcon-errors.h>
 #include <iotcon-struct.h>
 #include <iotcon-constant.h>
@@ -28,123 +29,91 @@ extern "C" {
 void iotcon_initialize(const char *addr, unsigned short port);
 void iotcon_deinitialize();
 
-iotcon_response_h iotcon_response_new(iotcon_request_h req_h, iotcon_resource_h res_h);
-void iotcon_response_free(iotcon_response_h resp);
-
-typedef void (*iotcon_rest_api_handle_cb)(const iotcon_request_s *request);
-
-iotcon_repr_h iotcon_request_get_representation(const iotcon_request_s *request);
-
-iotcon_resource_h iotcon_register_resource(const char *uri, const char *rt,
-               iotcon_interface_e iot_if, iotcon_resource_property_e rt_type,
-               iotcon_rest_api_handle_cb entity_handler_cb);
-int iotcon_unregister_resource(const iotcon_resource_h resource_handle);
+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,
+               int ifaces,
+               uint8_t properties,
+               iotcon_request_handler_cb cb,
+               void *user_data);
+void iotcon_unregister_resource(iotcon_resource_h resource_handle);
 
-int iotcon_bind_interface_to_resource(iotcon_resource_h resource_handle,
-               const char *interface_type);
-int iotcon_bind_type_to_resource(iotcon_resource_h resource_handle,
+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_resource(iotcon_resource_h parent, iotcon_resource_h child);
 
-typedef void (*iotcon_found_device_info_cb)(const iotcon_device_info_s *info);
-
-int iotcon_register_device_info(iotcon_device_info_s *device_info);
-
-int iotcon_subscribe_device_info(char *host, char *uri,
-               iotcon_found_device_info_cb found_cb);
-void iotcon_unsubscribe_device_info(char *host, char *uri,
-               iotcon_found_device_info_cb found_cb);
-
-int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e prop, ...);
-
-int iotcon_send_notify_response(iotcon_response_h resp, iotcon_observers observers);
-int iotcon_send_resource_response(iotcon_response_h resp);
+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_get_device_info(const char *host_address, iotcon_device_info_cb cb,
+               void *user_data);
 
-typedef void (*iotcon_presence_handle_cb)(iotcon_error_e result, const unsigned int nonce,
+int iotcon_start_presence(unsigned int time_to_live);
+int iotcon_stop_presence();
+typedef void (*iotcon_presence_cb)(int result, unsigned int nonce,
                const char *host_address, void *user_data);
-
 iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
-               iotcon_presence_handle_cb presence_handler_cb, void *user_data);
+               const char *resource_type,
+               iotcon_presence_cb cb,
+               void *user_data);
 int iotcon_unsubscribe_presence(iotcon_presence_h presence_handle);
-int iotcon_start_presence(const unsigned int time_to_live);
-int iotcon_stop_presence();
 
-typedef void (*iotcon_found_resource_cb)(iotcon_resource_s *resource, void *user_data);
+typedef void (*iotcon_found_resource_cb)(iotcon_client_h resource, void *user_data);
+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);
+void iotcon_client_free(iotcon_client_h resource);
+iotcon_client_h iotcon_client_clone(iotcon_client_h resource);
+
+typedef void (*iotcon_on_observe_cb)(iotcon_options_h header_options, iotcon_repr_h repr,
+               int response_result, int sequence_number, void *user_data);
+int iotcon_observer_start(iotcon_client_h resource,
+               iotcon_observe_type_e observe_type,
+               iotcon_query_h query,
+               iotcon_on_observe_cb cb,
+               void *user_data);
+int iotcon_observer_stop(iotcon_client_h resource);
 
-int iotcon_find_resource(const char *host, const char *resource_name,
-               iotcon_found_resource_cb found_resource_cb, void *user_data);
+int iotcon_response_send(iotcon_response_h resp);
 
-typedef void (*iotcon_on_get_cb)(const iotcon_options_h header_options,
-               const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_put_cb)(const iotcon_options_h header_options,
-               const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_post_cb)(const iotcon_options_h header_options,
-               const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_observe_cb)(const iotcon_options_h header_options,
-               const iotcon_repr_h repr, const int e_code, const int sequence_number,
-               void *user_data);
-typedef void (*iotcon_on_delete_cb)(const iotcon_options_h header_options,
-               const int e_code, void *user_data);
+iotcon_notimsg_h iotcon_notimsg_new(iotcon_repr_h repr, iotcon_interface_e iface);
+void iotcon_notimsg_free(iotcon_notimsg_h msg);
+int iotcon_notify(iotcon_resource_h resource, iotcon_notimsg_h msg,
+               iotcon_observers_h observers);
 
-iotcon_resource_s iotcon_construct_resource_object(const char *host, const char *uri,
-bool is_observable, iotcon_resource_types resource_type,
-               iotcon_resource_interfaces resource_if);
-void iotcon_destruct_resource_object(iotcon_resource_s *resource);
-iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource);
+typedef void (*iotcon_on_get_cb)(iotcon_options_h header_options, iotcon_repr_h repr,
+               int response_result, void *user_data);
+int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
+               iotcon_on_get_cb cb, void *user_data);
 
-int iotcon_get(iotcon_resource_s resource, iotcon_query query, iotcon_on_get_cb on_get_cb,
-               void *user_data);
-int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
-               iotcon_on_put_cb on_put_cb, void *user_data);
-int iotcon_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
-               iotcon_on_post_cb on_post_cb, void *user_data);
-int iotcon_delete_resource(iotcon_resource_s resource, iotcon_on_delete_cb on_delete_cb,
-               void *user_data);
+typedef void (*iotcon_on_put_cb)(iotcon_options_h header_options, iotcon_repr_h repr,
+               int response_result, void *user_data);
+int iotcon_put(iotcon_client_h resource, iotcon_repr_h repr, iotcon_query_h query,
+               iotcon_on_put_cb cb, void *user_data);
 
-int iotcon_observe(iotcon_observe_type_e observe_type, iotcon_resource_s *resource,
-               iotcon_query query, iotcon_on_observe_cb on_observe_cb, void *user_data);
-int iotcon_cancel_observe(iotcon_resource_s resource);
+typedef void (*iotcon_on_post_cb)(iotcon_options_h header_options, iotcon_repr_h repr,
+               int response_result, void *user_data);
+int iotcon_post(iotcon_client_h resource, iotcon_repr_h repr, iotcon_query_h query,
+               iotcon_on_post_cb cb, void *user_data);
 
-iotcon_resource_types iotcon_resource_types_new();
-iotcon_resource_types iotcon_resource_types_insert(iotcon_resource_types resource_types,
-               const char *resource_type);
-void iotcon_resource_types_free(iotcon_resource_types resource_types);
-
-iotcon_resource_interfaces iotcon_resource_interfaces_new();
-iotcon_resource_interfaces iotcon_resource_interfaces_insert(
-               iotcon_resource_interfaces resource_interfaces, iotcon_interface_e interface);
-void iotcon_resource_interfaces_free(iotcon_resource_interfaces resource_interfaces);
-
-iotcon_options_h iotcon_options_new();
-void iotcon_options_free(iotcon_options_h options);
-int iotcon_options_insert(iotcon_options_h options, const unsigned short id,
-               const char *data);
-int iotcon_options_delete(iotcon_options_h options, const unsigned short id);
-const char* iotcon_options_lookup(iotcon_options_h options, const unsigned short id);
-typedef void (*iotcon_options_foreach_cb)(unsigned short id, char *data, void *user_data);
-void iotcon_options_foreach(iotcon_options_h options,
-               iotcon_options_foreach_cb foreach_cb, void *user_data);
-iotcon_options_h iotcon_options_clone(iotcon_options_h options);
-
-iotcon_query iotcon_query_new();
-void iotcon_query_insert(iotcon_query query, const char *key, const char *value);
-void iotcon_query_free(iotcon_query query);
-char* iotcon_query_lookup(iotcon_query query, const char *key);
-
-iotcon_observers iotcon_observation_new();
-iotcon_observers iotcon_observation_insert(iotcon_observers observers,
-               iotcon_observation_info_s obs);
-iotcon_observers iotcon_observation_delete(iotcon_observers observers,
-               iotcon_observation_info_s obs);
-void iotcon_observation_free(iotcon_observers observers);
-
-char* iotcon_resource_get_uri(iotcon_resource_s resource_s);
-char* iotcon_resource_get_host(iotcon_resource_s resource_s);
-iotcon_resource_types iotcon_resource_get_types(iotcon_resource_s resource_s);
-iotcon_resource_interfaces iotcon_resource_get_interfaces(iotcon_resource_s resource_s);
-
-void iotcon_resource_set_options(iotcon_resource_s *resource,
-               iotcon_options_h header_options);
+typedef void (*iotcon_on_delete_cb)(iotcon_options_h header_options, int response_result,
+               void *user_data);
+int iotcon_delete(iotcon_client_h resource, iotcon_on_delete_cb cb,
+               void *user_data);
 
 #ifdef __cplusplus
 }
index e288d5c..c537dcd 100644 (file)
@@ -12,7 +12,6 @@ BuildRequires:  iotivity-devel
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(json-glib-1.0)
 BuildRequires:  pkgconfig(dlog)
-BuildRequires:  pkgconfig(notification)
 
 
 %description
index ef2b277..d9e0adb 100644 (file)
@@ -1,20 +1,20 @@
 LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include)
 
-SET(CRUD_TEST_CLIENT "crud-test-client")               
+SET(CRUD_TEST_CLIENT "crud-test-client")
 SET(CRUD_TEST_SERVER "crud-test-server")
 
-FILE(GLOB CRUD_TEST_CLIENT_SRCS crud-test-client.c)            
+FILE(GLOB CRUD_TEST_CLIENT_SRCS crud-test-client.c)
 FILE(GLOB CRUD_TEST_SERVER_SRCS crud-test-server.c)
 
-pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0 notification)
+pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0)
 INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
 
-ADD_EXECUTABLE(${CRUD_TEST_CLIENT} ${CRUD_TEST_CLIENT_SRCS})           
-TARGET_LINK_LIBRARIES(${CRUD_TEST_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})            
-INSTALL(TARGETS ${CRUD_TEST_CLIENT} DESTINATION ${BIN_INSTALL_DIR})            
-                       
-ADD_EXECUTABLE(${CRUD_TEST_SERVER} ${CRUD_TEST_SERVER_SRCS})           
-TARGET_LINK_LIBRARIES(${CRUD_TEST_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})            
+ADD_EXECUTABLE(${CRUD_TEST_CLIENT} ${CRUD_TEST_CLIENT_SRCS})
+TARGET_LINK_LIBRARIES(${CRUD_TEST_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})
+INSTALL(TARGETS ${CRUD_TEST_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
+
+ADD_EXECUTABLE(${CRUD_TEST_SERVER} ${CRUD_TEST_SERVER_SRCS})
+TARGET_LINK_LIBRARIES(${CRUD_TEST_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
 INSTALL(TARGETS ${CRUD_TEST_SERVER} DESTINATION ${BIN_INSTALL_DIR})
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 90f557a..4428509
@@ -15,6 +15,8 @@
  */
 
 #include <stdlib.h>
+#include <glib.h>
+
 #include <iotcon.h>
 #include "test-log.h"
 
@@ -22,7 +24,7 @@
 
 const char* const door_uri = "/a/door";
 
-iotcon_resource_s door_resource = {0};
+iotcon_client_h door_resource = NULL;
 
 char* _alloc_str_from_glist(GList *list)
 {
@@ -45,23 +47,26 @@ void _print_repr_info(iotcon_repr_h repr)
                DBG("rep : \n%s", iotcon_repr_generate_json(repr));
 }
 
-static void _on_delete(const iotcon_options_h header_options, const int e_code,
+static void _on_delete(iotcon_options_h header_options, int response_result,
                void *user_data)
 {
-       RETM_IF(IOTCON_EH_OK != e_code && IOTCON_EH_RESOURCE_DELETED != e_code,
-                       "_on_delete Response error(%d)", e_code);
+       RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
+                       && IOTCON_RESPONSE_RESULT_RESOURCE_DELETED != response_result,
+                       "_on_delete Response error(%d)", response_result);
        INFO("DELETE request was successful");
 
        /* delete callback operations */
 }
 
-static void _on_post(const iotcon_options_h header_options, iotcon_repr_h recv_repr,
-               const int e_code, void *user_data)
+static void _on_post(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+               int response_result, void *user_data)
 {
        char *created_uri = NULL;
-       iotcon_resource_s new_door_resource = {0};
+       iotcon_client_h new_door_resource = NULL;
 
-       RETM_IF(IOTCON_EH_OK != e_code, "_on_post Response error(%d)", e_code);
+       RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
+                       && IOTCON_RESPONSE_RESULT_RESOURCE_CREATED != response_result,
+                       "_on_post Response error(%d)", response_result);
        INFO("POST request was successful");
 
        _print_repr_info(recv_repr);
@@ -70,26 +75,30 @@ static void _on_post(const iotcon_options_h header_options, iotcon_repr_h recv_r
        if (created_uri) {
                DBG("New resource created : %s", created_uri);
 
-               new_door_resource = iotcon_construct_resource_object(door_resource.resource_host,
+               new_door_resource = iotcon_client_new(
+                               iotcon_client_get_host(door_resource),
                                created_uri,
-                               true, door_resource.resource_types, door_resource.resource_interfaces);
+                               true,
+                               iotcon_client_get_types(door_resource),
+                               iotcon_client_get_interfaces(door_resource));
 
-               iotcon_delete_resource(new_door_resource, _on_delete, NULL);
+               iotcon_delete(new_door_resource, _on_delete, NULL);
        }
 
 }
 
-static void _on_put(const iotcon_options_h header_options, iotcon_repr_h recv_repr,
-               const int e_code, void *user_data)
+static void _on_put(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+               int response_result, void *user_data)
 {
-       RETM_IF(IOTCON_EH_OK != e_code, "_on_put Response error(%d)", e_code);
+       RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_put Response error(%d)",
+                       response_result);
        INFO("PUT request was successful");
 
        _print_repr_info(recv_repr);
 
        iotcon_repr_h send_repr = iotcon_repr_new();
 
-       iotcon_query query_params = iotcon_query_new();
+       iotcon_query_h query_params = iotcon_query_new();
        /* send POST request */
        iotcon_post(door_resource, send_repr, query_params, _on_post, NULL);
 
@@ -98,10 +107,11 @@ static void _on_put(const iotcon_options_h header_options, iotcon_repr_h recv_re
 
 }
 
-static void _on_get(const iotcon_options_h header_options, iotcon_repr_h recv_repr,
-               const int e_code, void *user_data)
+static void _on_get(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+               int response_result, void *user_data)
 {
-       RETM_IF(IOTCON_EH_OK != e_code, "_on_get Response error(%d)", e_code);
+       RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_get Response error(%d)",
+                       response_result);
        INFO("GET request was successful");
 
        _print_repr_info(recv_repr);
@@ -109,64 +119,86 @@ static void _on_get(const iotcon_options_h header_options, iotcon_repr_h recv_re
        iotcon_repr_h send_repr = iotcon_repr_new();
        iotcon_repr_set_bool(send_repr, "opened", true);
 
-       iotcon_query query_params = iotcon_query_new();
+       iotcon_query_h query_params = iotcon_query_new();
        /* send PUT request */
        iotcon_put(door_resource, send_repr, query_params, _on_put, NULL);
 
        iotcon_repr_free(send_repr);
        iotcon_query_free(query_params);
+}
 
+static void _on_observe(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+               int response_result, int sequence_number, void *user_data)
+{
+       INFO("_on_observe");
 }
 
-static void _found_resource(iotcon_resource_s *resource, void *user_data)
+static void _get_res_type_fn(const char *string, void *user_data)
 {
-       char *resource_uri = NULL;
-       char *resource_host = NULL;
-       iotcon_resource_types resource_types = NULL;
-       iotcon_resource_interfaces resource_interfaces = NULL;
+       char *resource_uri = user_data;
 
-       if (resource) {
-               char *interfaces_str = NULL;
-               char *res_types_str = NULL;
+       DBG("[%s] resource type : %s", resource_uri, string);
+}
+
+static void _presence_handler(int result, unsigned int nonce,
+               const char *host_address, void *user_data)
+{
+       INFO("_presence_handler");
+       INFO("result : %d", result);
+       INFO("nonce : %d", nonce);
+       INFO("host_address : %s", host_address);
+}
 
+static void _found_resource(iotcon_client_h resource, void *user_data)
+{
+       const char *resource_uri = NULL;
+       const char *resource_host = NULL;
+       iotcon_str_list_s *resource_types = NULL;
+       int resource_interfaces = 0;
+
+       if (resource) {
                INFO("===== resource found =====");
 
                /* get the resource URI */
-               resource_uri = iotcon_resource_get_uri(*resource);
+               resource_uri = iotcon_client_get_uri(resource);
                if (NULL == resource_uri) {
                        ERR("uri is NULL");
                        return;
                }
 
                /* get the resource host address */
-               resource_host = iotcon_resource_get_host(*resource);
+               resource_host = iotcon_client_get_host(resource);
                DBG("[%s] resource host : %s", resource_uri, resource_host);
 
                /* get the resource interfaces */
-               resource_interfaces = iotcon_resource_get_interfaces(*resource);
-               if (resource_interfaces) {
-                       interfaces_str = _alloc_str_from_glist(resource_interfaces);
-                       DBG("[%s] resource interfaces : %s", resource_uri, interfaces_str);
-                       free(interfaces_str);
-               }
+               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_resource_get_types(*resource);
-               if (resource_types) {
-                       res_types_str = _alloc_str_from_glist(resource_types);
-                       DBG("[%s] resource types : %s", resource_uri, res_types_str);
-                       free(res_types_str);
-               }
+               resource_types = iotcon_client_get_types(resource);
+               iotcon_str_list_foreach(resource_types, _get_res_type_fn,
+                               (void *)resource_uri);
+
+               iotcon_subscribe_presence(resource_host, "core.door", _presence_handler, NULL);
 
                if (!strcmp(door_uri, resource_uri)) {
-                       /* copy resource to use elsewhere */
-                       door_resource = iotcon_copy_resource(*resource);
+                       door_resource = iotcon_client_clone(resource);
+
+                       iotcon_query_h query = iotcon_query_new();
 
-                       iotcon_query query_params = iotcon_query_new();
-                       /* send GET request */
-                       iotcon_get(*resource, query_params, _on_get, NULL);
+                       /* send GET Request */
+                       iotcon_get(resource, query, _on_get, NULL);
+                       iotcon_query_free(query);
 
-                       iotcon_query_free(query_params);
+                       iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe,
+                                       NULL);
                }
        }
 }
@@ -178,11 +210,10 @@ int main(int argc, char **argv)
        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);
 
        /* find door typed resources */
-       iotcon_find_resource("", "coap://224.0.1.187/oc/core?rt=core.door", &_found_resource,
-       NULL);
+       iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.door", &_found_resource, NULL);
 
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
index 67c7aa6..4eb7c32 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <stdlib.h>
 #include <stdbool.h>
+#include <glib.h>
+
 #include <iotcon.h>
 #include "test-log.h"
 
@@ -31,7 +33,9 @@ static door_resource_s my_door;
 static bool resource_created = false;
 iotcon_resource_h new_door_handle;
 
-static void _request_handler(const iotcon_request_s *request);
+iotcon_observers_h observers = NULL;
+
+static void _request_handler(iotcon_request_h request, void *user_data);
 
 static iotcon_error_e _set_door_resource()
 {
@@ -62,9 +66,11 @@ 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};
+
        /* register door resource */
-       iotcon_resource_h door_handle = iotcon_register_resource(uri, my_door.type,
-                       interfaces, properties, _request_handler);
+       iotcon_resource_h door_handle = iotcon_register_resource(uri, &resource_types,
+                       interfaces, properties, _request_handler, door_handle);
        if (NULL == door_handle) {
                ERR("iotcon_register_resource() Fail");
                return NULL;
@@ -74,14 +80,13 @@ static iotcon_resource_h _create_door_resource(char *uri, iotcon_interface_e int
 }
 
 static void _send_response(iotcon_response_h response, iotcon_repr_h repr,
-               iotcon_entity_handler_result_e result)
+               iotcon_response_result_e result)
 {
-       iotcon_response_set(response, IOTCON_RESP_RESULT, result);
-       iotcon_response_set(response, IOTCON_RESP_REPRESENTATION, repr);
-       iotcon_response_set(response, IOTCON_RESP_ERR_CODE, 200);
+       iotcon_response_set(response, IOTCON_RESPONSE_RESULT, result);
+       iotcon_response_set(response, IOTCON_RESPONSE_REPRESENTATION, repr);
 
        /* send Representation to the client */
-       iotcon_send_resource_response(response);
+       iotcon_response_send(response);
 }
 
 static void _request_handler_get(iotcon_response_h response)
@@ -94,11 +99,10 @@ static void _request_handler_get(iotcon_response_h response)
        iotcon_repr_set_uri(resp_repr, my_door.uri);
        iotcon_repr_set_bool(resp_repr, "opened", my_door.state);
 
-       _send_response(response, resp_repr, IOTCON_EH_OK);
+       _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
 }
 
-static void _request_handler_put(const iotcon_request_s *request,
-               iotcon_response_h response)
+static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
 {
        iotcon_repr_h req_repr = NULL;
        iotcon_repr_h resp_repr = NULL;
@@ -113,7 +117,7 @@ static void _request_handler_put(const iotcon_request_s *request,
        iotcon_repr_set_uri(resp_repr, my_door.uri);
        iotcon_repr_set_bool(resp_repr, "opened", my_door.state);
 
-       _send_response(response, resp_repr, IOTCON_EH_OK);
+       _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
 }
 
 static void _request_handler_post(iotcon_response_h response)
@@ -134,41 +138,42 @@ static void _request_handler_post(iotcon_response_h response)
                resp_repr = iotcon_repr_new();
                iotcon_repr_set_str(resp_repr, "createduri", "/a/door1");
 
-               _send_response(response, resp_repr, IOTCON_EH_RESOURCE_CREATED);
+               _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
        }
 
 }
 
 static void _request_handler_delete(iotcon_response_h response)
 {
-       int ret = IOTCON_ERROR_NONE;
        iotcon_repr_h resp_repr = NULL;
-       iotcon_entity_handler_result_e result = IOTCON_EH_OK;
+       iotcon_response_result_e result = IOTCON_RESPONSE_RESULT_OK;
        INFO("DELETE request");
 
-       ret = iotcon_unregister_resource(new_door_handle);
+       iotcon_unregister_resource(new_door_handle);
        resp_repr = iotcon_repr_new();
-       if (IOTCON_ERROR_NONE == ret)
-               result = IOTCON_EH_RESOURCE_DELETED;
-       else
-               result = IOTCON_EH_ERROR;
+       result = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
 
        _send_response(response, resp_repr, result);
 }
 
-static void _request_handler(const iotcon_request_s *request)
+static void _request_handler(iotcon_request_h request, void *user_data)
 {
-       char *request_type = NULL;
+       const char *request_type = NULL;
        int request_flag = IOTCON_INIT_FLAG;
        iotcon_response_h response = NULL;
        FN_CALL;
 
        RET_IF(NULL == request);
 
-       request_type = request->request_type;
-       request_flag = request->request_handler_flag;
-       if (request_flag & IOTCON_REQUEST_FLAG) {
-               response = iotcon_response_new(request->request_handle, request->resource_handle);
+       request_type = iotcon_request_get_request_type(request);
+       if (NULL == request_type) {
+               ERR("request_type is NULL");
+               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;
@@ -188,6 +193,36 @@ static void _request_handler(const iotcon_request_s *request)
 
                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));
+       }
+}
+
+static gboolean _timeout(gpointer user_data)
+{
+       static int i = 0;
+       i++;
+       if (i % 2)
+               iotcon_start_presence(10);
+       else
+               iotcon_stop_presence();
+
+       if (4 == i)
+               return FALSE;
+
+       return TRUE;
+}
+
+static gboolean _observe_timeout(gpointer user_data)
+{
+       INFO("NOTIFY!");
+       iotcon_repr_h repr = iotcon_repr_new();
+       iotcon_notimsg_h msg = iotcon_notimsg_new(repr, IOTCON_INTERFACE_DEFAULT);
+       iotcon_notify(user_data, msg, observers);
+
+       return TRUE;
 }
 
 int main(int argc, char **argv)
@@ -202,11 +237,10 @@ int main(int argc, char **argv)
        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);
 
        /* set local door resource */
        iotcon_error = _set_door_resource();
-
        if (IOTCON_ERROR_NONE != iotcon_error) {
                ERR("_set_door_resource() Fail");
                return -1;
@@ -216,6 +250,9 @@ int main(int argc, char **argv)
        door_interfaces |= IOTCON_INTERFACE_BATCH;
        resource_properties |= IOTCON_OBSERVABLE;
 
+       /* add presence */
+       g_timeout_add_seconds(10, _timeout, NULL);
+
        /* create new door resource */
        door_handle = _create_door_resource("/a/door", door_interfaces, resource_properties);
        if (NULL == door_handle) {
@@ -223,6 +260,9 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       /* add observe */
+       g_timeout_add_seconds(10, _observe_timeout, door_handle);
+
        _check_door_state();
 
        g_main_loop_run(loop);