(ACR) Modify the handle and API naming for resource and client(remote resource)
authoryoungman <yman.jung@samsung.com>
Wed, 14 Oct 2015 01:54:33 +0000 (10:54 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:08:20 +0000 (20:08 +0900)
Change-Id: Ia26f2ed0f7c2fa47c2d7127b4198b6b6eb5ba5a5
Signed-off-by: youngman <yman.jung@samsung.com>
19 files changed:
common/ic-dbus.xml
daemon/icd-dbus.c
doc/iotcon_doc.h
lib/icl-client-crud.c [deleted file]
lib/icl-client.c [deleted file]
lib/icl-client.h [deleted file]
lib/icl-dbus-type.c
lib/icl-dbus-type.h
lib/icl-device.c
lib/icl-remote-resource-crud.c [new file with mode: 0644]
lib/icl-remote-resource.c [new file with mode: 0644]
lib/icl-remote-resource.h [new file with mode: 0644]
lib/icl-resource.c
lib/include/iotcon-struct.h
lib/include/iotcon.h
test/crud-test-client.c
test/crud-test-server.c
test/repr-test-client.c
test/repr-test-server.c

index b36c0b86d8c5c807d0af4d1e2f2b00b3c376f89a..261dab921a518255a85188a4658f05f6755c3b78 100644 (file)
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="get">
-                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="put">
-                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
                        <arg type="(siasa{sv}av)" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="post">
-                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
                        <arg type="(siasa{sv}av)" name="repr" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="(a(qs)vi)" name="ret" direction="out"/>
                </method>
                <method name="delete">
-                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
                        <arg type="(a(qs)i)" name="ret" direction="out"/>
                </method>
                <method name="observerStart">
-                       <arg type="(ssba(qs)i)" name="client" direction="in"/>
+                       <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
                        <arg type="i" name="observe_type" direction="in"/>
                        <arg type="a(ss)" name="query" direction="in"/>
                        <arg type="u" name="signal_number" direction="in"/>
index 50a1c8e16c7936dc7f85dce6dba05c8f24ed26df..1092e909067434af06e137d74895b11e984a1695 100644 (file)
@@ -514,7 +514,7 @@ static gboolean _dbus_handle_find_resource(icDbus *object,
 
 static gboolean _dbus_handle_observer_start(icDbus *object,
                GDBusMethodInvocation *invocation,
-               GVariant *client,
+               GVariant *resource,
                gint observe_type,
                GVariant *query,
                guint signal_number)
@@ -523,8 +523,8 @@ static gboolean _dbus_handle_observer_start(icDbus *object,
        const gchar *sender;
 
        sender = g_dbus_method_invocation_get_sender(invocation);
-       observe_h = icd_ioty_observer_start(client, observe_type, query, signal_number,
-                       sender);
+       observe_h = icd_ioty_observer_start(resource, observe_type, query,
+                       signal_number, sender);
        if (NULL == observe_h)
                ERR("icd_ioty_observer_start() Fail");
 
index 4bac0fd90cd45c0eac6f3ae686749dee343aaa1b..379109cfe784c846c97ae8814e972cc6c3d386b9 100644 (file)
@@ -31,7 +31,7 @@
  * RESTful API.\n\n
  *
  * @subsection CAPI_IOT_CONNECTIVITY_MODULE_RESOURCE Resource
- * A Resrouce is a component in a server that can be viewed and conrolled by another client.\n
+ * A Resource is a component in a server that can be viewed and conrolled by another client.\n
  * There are different resource types, for example a temperature sensor, a light controller etc.\n\n
  *
  * @subsection CAPI_IOT_CONNECTIVITY_MODULE_RESOURCE_REGISTRATION Resource registration
@@ -130,7 +130,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                return;
        }
 
-       iotcon_resource_h handle = iotcon_register_resource(uri_path, resource_types,
+       iotcon_resource_h handle = iotcon_resource_create(uri_path, resource_types,
                        interfaces, properties, _request_handler, NULL);
        if (NULL == handle) {
                iotcon_resource_types_destroy(resource_types);
@@ -155,37 +155,37 @@ static void _on_get(iotcon_options_h header_options, iotcon_representation_h rec
        // handle get from response
 }
 ...
-static void _found_resource(iotcon_client_h resource, void *user_data)
+static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
 {
        int ret;
        int resource_interfaces;
        char *resource_uri_path;
        char *resource_host;
-       char *resource_sid;
+       char *device_id;
        iotcon_query_h query;
        iotcon_resource_types_h resource_types;
 
-       ret = iotcon_client_get_uri_path(resource, &resource_uri_path);
+       ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
        if (IOTCON_ERROR_NONE != ret) {
                return;
        }
 
-       ret = iotcon_client_get_device_id(resource, &resource_sid);
+       ret = iotcon_remote_resource_get_device_id(resource, &device_id);
        if (IOTCON_ERROR_NONE != ret) {
                return;
        }
 
-       ret = iotcon_client_get_host(resource, &resource_host);
+       ret = iotcon_remote_resource_get_host(resource, &resource_host);
        if (IOTCON_ERROR_NONE != ret) {
                return;
        }
 
-       ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
+       ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
        if (IOTCON_ERROR_NONE != ret) {
                return;
        }
 
-       ret = iotcon_client_get_types(resource, &resource_types);
+       ret = iotcon_remote_resource_get_types(resource, &resource_types);
        if (IOTCON_ERROR_NONE != ret) {
                return;
        }
@@ -197,7 +197,7 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
 
        iotcon_query_insert(query, "key", "value");
 
-       iotcon_get(resource, query, &_on_get, NULL);
+       iotcon_remote_resource_get(resource, query, &_on_get, NULL);
        iotcon_query_destroy(query);
 }
 ...
@@ -291,7 +291,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
                return;
        }
 
-       ret = iotcon_register_resource(uri_path, resource_types,
+       ret = iotcon_resource_create(uri_path, resource_types,
                        interfaces, properties, _request_handler, NULL, door_handle);
        if (IOTCON_ERROR_NONE != ret) {
                iotcon_resource_types_destroy(resource_types);
@@ -333,7 +333,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
  * @code
 #include <iotcon.h>
 ...
-static iotcon_client_h door_resource;
+static iotcon_remote_resource_h door_resource;
 ...
 static void _on_observe(iotcon_options_h header_options, iotcon_representation_h recv_repr,
                int response_result, int sequence_number, void *user_data)
@@ -342,8 +342,8 @@ static void _on_observe(iotcon_options_h header_options, iotcon_representation_h
 ...
 {
        int ret;
-       ret = iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, &_on_observe, NULL);
-
+       ret = iotcon_remote_resource_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL,
+                       &_on_observe, NULL);
        if (IOTCON_ERROR_NONE != ret)
                return;
 }
@@ -359,11 +359,11 @@ static void _on_observe(iotcon_options_h header_options, iotcon_representation_h
  *         <td><b>Client</b></td>
  *     </tr>
  *     <tr>
- *         <td>iotcon_register_resource</td>
+ *         <td>iotcon_resource_create</td>
  *         <td>iotcon_get_device_info</td>
  *     </tr>
  *     <tr>
- *         <td>iotcon_unregister_resource</td>
+ *         <td>iotcon_resource_destroy</td>
  *         <td>iotcon_subscribe_presence</td>
  *     </tr>
  *     <tr>
@@ -376,27 +376,27 @@ static void _on_observe(iotcon_options_h header_options, iotcon_representation_h
  *     </tr>
  *     <tr>
  *         <td>iotcon_resource_bind_request_handler</td>
- *         <td>iotcon_observer_start</td>
+ *         <td>iotcon_remote_resource_observer_start</td>
  *     </tr>
  *     <tr>
  *         <td>iotcon_resource_bind_child_resource</td>
- *         <td>iotcon_observer_stop</td>
+ *         <td>iotcon_remote_resource_observer_stop</td>
  *     </tr>
  *     <tr>
  *         <td>iotcon_resource_unbind_child_resource</td>
- *         <td>iotcon_get</td>
+ *         <td>iotcon_remote_resource_get</td>
  *     </tr>
  *     <tr>
  *         <td>iotcon_register_device_info</td>
- *         <td>iotcon_put</td>
+ *         <td>iotcon_remote_resource_put</td>
  *     </tr>
  *     <tr>
  *         <td>iotcon_start_presence</td>
- *         <td>iotcon_post</td>
+ *         <td>iotcon_remote_resource_post</td>
  *     </tr>
  *     <tr>
  *         <td>iotcon_stop_presence</td>
- *         <td>iotcon_delete</td>
+ *         <td>iotcon_remote_resource_delete</td>
  *     </tr>
  *     <tr>
  *         <td>iotcon_response_send</td>
diff --git a/lib/icl-client-crud.c b/lib/icl-client-crud.c
deleted file mode 100644 (file)
index e91a4db..0000000
+++ /dev/null
@@ -1,559 +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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "ic-dbus.h"
-#include "icl.h"
-#include "icl-options.h"
-#include "icl-dbus.h"
-#include "icl-dbus-type.h"
-#include "icl-repr.h"
-#include "icl-client.h"
-#include "icl-payload.h"
-
-typedef struct {
-       iotcon_on_cru_cb cb;
-       void *user_data;
-       iotcon_client_h resource;
-} icl_on_cru_s;
-
-typedef struct {
-       iotcon_on_delete_cb cb;
-       void *user_data;
-       iotcon_client_h resource;
-} icl_on_delete_s;
-
-typedef struct {
-       iotcon_on_observe_cb cb;
-       void *user_data;
-       iotcon_client_h resource;
-} icl_on_observe_s;
-
-
-static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
-{
-       int res, ret;
-       iotcon_representation_h repr;
-       GVariantIter *options;
-       unsigned short option_id;
-       char *option_data;
-       GVariant *repr_gvar;
-       iotcon_options_h header_options = NULL;
-       iotcon_on_cru_cb cb = cb_container->cb;
-
-       g_variant_get(result, "(a(qs)vi)", &options, &repr_gvar, &res);
-
-       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
-               ret = iotcon_options_create(&header_options);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_options_create() Fail(%d)", ret);
-                       return;
-               }
-
-               while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
-                       iotcon_options_insert(header_options, option_id, option_data);
-       }
-       g_variant_iter_free(options);
-
-       repr = icl_representation_from_gvariant(repr_gvar);
-       if (NULL == repr) {
-               ERR("icl_representation_from_gvariant() Fail");
-               if (header_options)
-                       iotcon_options_destroy(header_options);
-
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return;
-       }
-
-       res = icl_dbus_convert_daemon_error(res);
-
-       if (cb)
-               cb(cb_container->resource, repr, header_options, res,
-                               cb_container->user_data);
-
-       if (repr)
-               iotcon_representation_destroy(repr);
-       if (header_options)
-               iotcon_options_destroy(header_options);
-
-       iotcon_client_destroy(cb_container->resource);
-       free(cb_container);
-}
-
-
-static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res,
-               gpointer user_data)
-{
-       GVariant *result;
-       GError *error = NULL;
-       icl_on_cru_s *cb_container = user_data;
-
-       ic_dbus_call_get_finish(IC_DBUS(object), &result, g_async_res, &error);
-       if (error) {
-               ERR("ic_dbus_call_get_finish() Fail(%s)", error->message);
-               g_error_free(error);
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return;
-       }
-
-       _icl_on_cru_cb(result, cb_container);
-}
-
-
-static void _icl_on_put_cb(GObject *object, GAsyncResult *g_async_res,
-               gpointer user_data)
-{
-       GVariant *result;
-       GError *error = NULL;
-       icl_on_cru_s *cb_container = user_data;
-
-       ic_dbus_call_put_finish(IC_DBUS(object), &result, g_async_res, &error);
-       if (error) {
-               ERR("ic_dbus_call_put_finish() Fail(%s)", error->message);
-               g_error_free(error);
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return;
-       }
-
-       _icl_on_cru_cb(result, cb_container);
-}
-
-
-static void _icl_on_post_cb(GObject *object, GAsyncResult *g_async_res,
-               gpointer user_data)
-{
-       GVariant *result;
-       GError *error = NULL;
-       icl_on_cru_s *cb_container = user_data;
-
-       ic_dbus_call_post_finish(IC_DBUS(object), &result, g_async_res, &error);
-       if (error) {
-               ERR("ic_dbus_call_post_finish() Fail(%s)", error->message);
-               g_error_free(error);
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return;
-       }
-
-       _icl_on_cru_cb(result, cb_container);
-}
-
-
-API int iotcon_get(iotcon_client_h resource, iotcon_query_h query, iotcon_on_cru_cb cb,
-               void *user_data)
-{
-       int ret;
-       GVariant *arg_query;
-       GVariant *arg_client;
-       icl_on_cru_s *cb_container;
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
-       cb_container = calloc(1, sizeof(icl_on_cru_s));
-       if (NULL == cb_container) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = iotcon_client_ref(resource, &cb_container->resource);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_ref() Fail");
-               free(cb_container);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       cb_container->cb = cb;
-       cb_container->user_data = user_data;
-
-       arg_client = icl_dbus_client_to_gvariant(resource);
-       arg_query = icl_dbus_query_to_gvariant(query);
-
-       ic_dbus_call_get(icl_dbus_get_object(), arg_client, arg_query, NULL, _icl_on_get_cb,
-                       cb_container);
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr,
-               iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
-{
-       int ret;
-       GVariant *arg_repr;
-       GVariant *arg_client;
-       GVariant *arg_query;
-       icl_on_cru_s *cb_container;
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
-       cb_container = calloc(1, sizeof(icl_on_cru_s));
-       if (NULL == cb_container) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = iotcon_client_ref(resource, &cb_container->resource);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_ref() Fail");
-               free(cb_container);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       cb_container->cb = cb;
-       cb_container->user_data = user_data;
-
-       arg_repr = icl_representation_to_gvariant(repr);
-       if (NULL == arg_repr) {
-               ERR("icl_representation_to_gvariant() Fail");
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return IOTCON_ERROR_REPRESENTATION;
-       }
-
-       arg_client = icl_dbus_client_to_gvariant(resource);
-       arg_query = icl_dbus_query_to_gvariant(query);
-
-       ic_dbus_call_put(icl_dbus_get_object(), arg_client, arg_repr, arg_query,
-                       NULL, _icl_on_put_cb, cb_container);
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr,
-               iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
-{
-       int ret;
-       GVariant *arg_repr;
-       GVariant *arg_query;
-       GVariant *arg_client;
-       icl_on_cru_s *cb_container;
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
-       cb_container = calloc(1, sizeof(icl_on_cru_s));
-       if (NULL == cb_container) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = iotcon_client_ref(resource, &cb_container->resource);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_ref() Fail");
-               free(cb_container);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       cb_container->cb = cb;
-       cb_container->user_data = user_data;
-
-       arg_repr = icl_representation_to_gvariant(repr);
-       if (NULL == arg_repr) {
-               ERR("icl_representation_to_gvariant() Fail");
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return IOTCON_ERROR_REPRESENTATION;
-       }
-
-       arg_client = icl_dbus_client_to_gvariant(resource);
-       arg_query = icl_dbus_query_to_gvariant(query);
-
-       ic_dbus_call_post(icl_dbus_get_object(), arg_client, arg_repr, arg_query,
-                       NULL, _icl_on_post_cb, cb_container);
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
-               gpointer user_data)
-{
-       int res, ret;
-       GVariant *result;
-       char *option_data;
-       GError *error = NULL;
-       GVariantIter *options;
-       unsigned short option_id;
-       iotcon_options_h header_options = NULL;
-
-       icl_on_delete_s *cb_container = user_data;
-       iotcon_on_delete_cb cb = cb_container->cb;
-
-       ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error);
-       if (error) {
-               ERR("ic_dbus_call_delete_finish() Fail(%s)", error->message);
-               g_error_free(error);
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return;
-       }
-       g_variant_get(result, "(a(qs)i)", &options, &res);
-
-       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
-               ret = iotcon_options_create(&header_options);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_options_create() Fail(%d)", ret);
-                       g_variant_iter_free(options);
-                       iotcon_client_destroy(cb_container->resource);
-                       free(cb_container);
-                       return;
-               }
-
-               while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
-                       iotcon_options_insert(header_options, option_id, option_data);
-       }
-       g_variant_iter_free(options);
-
-       res = icl_dbus_convert_daemon_error(res);
-
-       if (cb)
-               cb(cb_container->resource, header_options, res, cb_container->user_data);
-
-       if (header_options)
-               iotcon_options_destroy(header_options);
-
-       iotcon_client_destroy(cb_container->resource);
-       free(cb_container);
-}
-
-
-API int iotcon_delete(iotcon_client_h resource, iotcon_on_delete_cb cb, void *user_data)
-{
-       int ret;
-       GVariant *arg_client;
-       icl_on_delete_s *cb_container;
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
-       cb_container = calloc(1, sizeof(icl_on_delete_s));
-       if (NULL == cb_container) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = iotcon_client_ref(resource, &cb_container->resource);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_ref() Fail");
-               free(cb_container);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       cb_container->cb = cb;
-       cb_container->user_data = user_data;
-
-       arg_client = icl_dbus_client_to_gvariant(resource);
-
-       ic_dbus_call_delete(icl_dbus_get_object(), arg_client, NULL, _icl_on_delete_cb,
-                       cb_container);
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_on_observe_cb(GDBusConnection *connection,
-               const gchar *sender_name,
-               const gchar *object_path,
-               const gchar *interface_name,
-               const gchar *signal_name,
-               GVariant *parameters,
-               gpointer user_data)
-{
-       int res, ret;
-       int seq_num;
-       iotcon_representation_h repr;
-       GVariantIter *options;
-       unsigned short option_id;
-       char *option_data;
-       GVariant *repr_gvar;
-       iotcon_options_h header_options = NULL;
-
-       icl_on_observe_s *cb_container = user_data;
-       iotcon_on_observe_cb cb = cb_container->cb;
-
-       g_variant_get(parameters, "(a(qs)vii)", &options, &repr_gvar, &res,
-                       &seq_num);
-
-       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
-               ret = iotcon_options_create(&header_options);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_options_create() Fail(%d)", ret);
-                       g_variant_iter_free(options);
-                       iotcon_client_destroy(cb_container->resource);
-                       free(cb_container);
-                       return;
-               }
-
-               while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
-                       iotcon_options_insert(header_options, option_id, option_data);
-       }
-       g_variant_iter_free(options);
-
-       repr = icl_representation_from_gvariant(repr_gvar);
-       if (NULL == repr) {
-               ERR("icl_representation_from_gvariant() Fail");
-               if (header_options)
-                       iotcon_options_destroy(header_options);
-
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return;
-       }
-
-       res = icl_dbus_convert_daemon_error(res);
-
-       if (cb)
-               cb(cb_container->resource, repr, header_options, res, seq_num,
-                               cb_container->user_data);
-
-       if (repr)
-               iotcon_representation_destroy(repr);
-       if (header_options)
-               iotcon_options_destroy(header_options);
-}
-
-
-static void _icl_observe_conn_cleanup(icl_on_observe_s *cb_container)
-{
-       cb_container->resource->observe_handle = 0;
-       cb_container->resource->observe_sub_id = 0;
-       iotcon_client_destroy(cb_container->resource);
-       free(cb_container);
-}
-
-
-API int iotcon_observer_start(iotcon_client_h resource, int observe_type,
-               iotcon_query_h query, iotcon_on_observe_cb cb, void *user_data)
-{
-       GVariant *arg_query;
-       unsigned int sub_id;
-       GVariant *arg_client;
-       GError *error = NULL;
-       int64_t observe_handle;
-       icl_on_observe_s *cb_container;
-       int ret, signal_number;
-       char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
-       signal_number = icl_dbus_generate_signal_number();
-
-       arg_client = icl_dbus_client_to_gvariant(resource);
-       arg_query = icl_dbus_query_to_gvariant(query);
-
-       ic_dbus_call_observer_start_sync(icl_dbus_get_object(), arg_client, observe_type,
-                       arg_query, signal_number, &observe_handle, NULL, &error);
-       if (error) {
-               ERR("ic_dbus_call_observer_start_sync() Fail(%s)", error->message);
-               ret = icl_dbus_convert_dbus_error(error->code);
-               g_error_free(error);
-               g_variant_unref(arg_query);
-               g_variant_unref(arg_client);
-               return ret;
-       }
-
-       if (0 == observe_handle) {
-               ERR("iotcon-daemon Fail");
-               return IOTCON_ERROR_IOTIVITY;
-       }
-
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_OBSERVE,
-                       signal_number);
-
-       cb_container = calloc(1, sizeof(icl_on_observe_s));
-       if (NULL == cb_container) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = iotcon_client_ref(resource, &cb_container->resource);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_ref() Fail");
-               free(cb_container);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       cb_container->cb = cb;
-       cb_container->user_data = user_data;
-
-       sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
-                       _icl_observe_conn_cleanup, _icl_on_observe_cb);
-       if (0 == sub_id) {
-               ERR("icl_dbus_subscribe_signal() Fail");
-               iotcon_client_destroy(cb_container->resource);
-               free(cb_container);
-               return IOTCON_ERROR_DBUS;
-       }
-       resource->observe_sub_id = sub_id;
-       resource->observe_handle = observe_handle;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_observer_stop(iotcon_client_h resource)
-{
-       int ret;
-       GError *error = NULL;
-       GVariant *arg_options;
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       if (0 == resource->observe_handle) {
-               ERR("It doesn't have a observe_handle");
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       arg_options = icl_dbus_options_to_gvariant(resource->header_options);
-
-       ic_dbus_call_observer_stop_sync(icl_dbus_get_object(), resource->observe_handle,
-                       arg_options, &ret, NULL, &error);
-       if (error) {
-               ERR("ic_dbus_call_observer_stop_sync() Fail(%s)", error->message);
-               ret = icl_dbus_convert_dbus_error(error->code);
-               g_error_free(error);
-               return ret;
-       }
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon-daemon Fail(%d)", ret);
-               return icl_dbus_convert_daemon_error(ret);
-       }
-
-       icl_dbus_unsubscribe_signal(resource->observe_sub_id);
-
-       return ret;
-}
-
diff --git a/lib/icl-client.c b/lib/icl-client.c
deleted file mode 100644 (file)
index 9e0c8dd..0000000
+++ /dev/null
@@ -1,349 +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 <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-options.h"
-#include "icl-dbus.h"
-#include "icl-repr.h"
-#include "icl-client.h"
-#include "icl-resource-types.h"
-#include "icl-payload.h"
-
-typedef struct {
-       iotcon_found_resource_cb cb;
-       void *user_data;
-       unsigned int id;
-} icl_found_resource_s;
-
-static iotcon_client_h _icl_client_from_gvariant(GVariant *payload,
-               iotcon_connectivity_type_e conn_type);
-
-static void _icl_found_resource_cb(GDBusConnection *connection,
-               const gchar *sender_name,
-               const gchar *object_path,
-               const gchar *interface_name,
-               const gchar *signal_name,
-               GVariant *parameters,
-               gpointer user_data)
-{
-       FN_CALL;
-       int conn_type;
-       iotcon_client_h client;
-
-       GVariant *payload;
-       icl_found_resource_s *cb_container = user_data;
-       iotcon_found_resource_cb cb = cb_container->cb;
-
-       g_variant_get(parameters, "(vi)", &payload, &conn_type);
-
-       client = _icl_client_from_gvariant(payload, conn_type);
-       if (NULL == client) {
-               ERR("icl_client_parse_resource_object() Fail");
-               return;
-       }
-
-       if (cb)
-               cb(client, cb_container->user_data);
-
-       iotcon_client_destroy(client);
-
-       /* TODO
-        * When is callback removed?
-        */
-}
-
-
-/* The length of resource_type should be less than or equal to 61.
- * If resource_type is NULL, then All resources in host are discovered. */
-API int iotcon_find_resource(const char *host_address, const char *resource_type,
-               iotcon_found_resource_cb cb, void *user_data)
-{
-       unsigned int sub_id;
-       GError *error = NULL;
-       int ret, signal_number;
-       icl_found_resource_s *cb_container;
-       char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-       RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-       if (resource_type && (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
-               ERR("The length of resource_type(%s) is invalid", resource_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       signal_number = icl_dbus_generate_signal_number();
-
-       ic_dbus_call_find_resource_sync(icl_dbus_get_object(), host_address,
-                       ic_utils_dbus_encode_str(resource_type), signal_number, &ret, NULL, &error);
-       if (error) {
-               ERR("ic_dbus_call_find_resource_sync() Fail(%s)", error->message);
-               ret = icl_dbus_convert_dbus_error(error->code);
-               g_error_free(error);
-               return ret;
-       }
-
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon-daemon Fail(%d)", ret);
-               return icl_dbus_convert_daemon_error(ret);
-       }
-
-       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_FOUND_RESOURCE,
-                       signal_number);
-
-       cb_container = calloc(1, sizeof(icl_found_resource_s));
-       if (NULL == cb_container) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       cb_container->cb = cb;
-       cb_container->user_data = user_data;
-
-       sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
-                       _icl_found_resource_cb);
-       if (0 == sub_id) {
-               ERR("icl_dbus_subscribe_signal() Fail");
-               return IOTCON_ERROR_DBUS;
-       }
-
-       cb_container->id = sub_id;
-
-       return ret;
-}
-
-
-/* If you know the information of resource, then you can make a proxy of the resource. */
-API int iotcon_client_create(const char *host,
-               const char *uri_path,
-               bool is_observable,
-               iotcon_resource_types_h resource_types,
-               int resource_ifs,
-               iotcon_client_h *client_handle)
-{
-       FN_CALL;
-       iotcon_client_h resource = NULL;
-
-       RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == client_handle, IOTCON_ERROR_INVALID_PARAMETER);
-
-       resource = calloc(1, sizeof(struct icl_remote_resource));
-       if (NULL == resource) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
-
-       resource->host = ic_utils_strdup(host);
-       resource->uri_path = ic_utils_strdup(uri_path);
-       resource->is_observable = is_observable;
-       resource->types = icl_resource_types_ref(resource_types);
-       resource->ifaces = resource_ifs;
-
-       resource->ref_count = 1;
-
-       *client_handle = resource;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_client_destroy(iotcon_client_h resource)
-{
-       RET_IF(NULL == resource);
-
-       resource->ref_count--;
-
-       if (0 < resource->ref_count)
-               return;
-
-       free(resource->uri_path);
-       free(resource->host);
-       free(resource->device_id);
-       iotcon_resource_types_destroy(resource->types);
-
-       /* null COULD be allowed */
-       if (resource->header_options)
-               iotcon_options_destroy(resource->header_options);
-
-       free(resource);
-}
-
-
-API int iotcon_client_ref(iotcon_client_h src, iotcon_client_h *dest)
-{
-       RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(src->ref_count <= 0, IOTCON_ERROR_INVALID_PARAMETER);
-
-       src->ref_count++;
-
-       *dest = src;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_client_get_uri_path(iotcon_client_h resource, char **uri_path)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-
-       *uri_path = resource->uri_path;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_client_get_host(iotcon_client_h resource, char **host)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
-
-       *host = resource->host;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_client_get_device_id(iotcon_client_h resource, char **device_id)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == device_id, IOTCON_ERROR_INVALID_PARAMETER);
-
-       *device_id = resource->device_id;
-
-       return IOTCON_ERROR_NONE;
-}
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_client_get_types(iotcon_client_h resource, iotcon_resource_types_h *types)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
-
-       *types = resource->types;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_client_get_interfaces(iotcon_client_h resource, int *ifaces)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
-
-       *ifaces = resource->ifaces;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_client_is_observable(iotcon_client_h resource, bool *observable)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == observable, IOTCON_ERROR_INVALID_PARAMETER);
-
-       *observable = resource->is_observable;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-/* if header_options is NULL, then client's header_options is unset */
-API int iotcon_client_set_options(iotcon_client_h resource,
-               iotcon_options_h header_options)
-{
-       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
-       if (resource->header_options)
-               iotcon_options_destroy(resource->header_options);
-
-       if (header_options)
-               resource->header_options = icl_options_ref(header_options);
-       else
-               resource->header_options = NULL;
-
-       return IOTCON_ERROR_NONE;
-}
-
-
-static iotcon_client_h _icl_client_from_gvariant(GVariant *payload,
-               iotcon_connectivity_type_e conn_type)
-{
-       int ret;
-       iotcon_client_h client;
-       GVariantIter *types_iter;
-       char host_addr[PATH_MAX] = {0};
-       iotcon_resource_types_h res_types;
-       char *uri_path, *sid, *res_type, *addr;
-       int ifaces, is_observable, is_secure, port;
-
-       g_variant_get(payload, "(&s&siasib&si)", &uri_path, &sid, &ifaces, &types_iter,
-                       &is_observable, &is_secure, &addr, &port);
-
-       switch (conn_type) {
-       case IOTCON_CONNECTIVITY_IPV6:
-               snprintf(host_addr, sizeof(host_addr), "[%s]:%d", addr, port);
-               break;
-       case IOTCON_CONNECTIVITY_IPV4:
-       default:
-               snprintf(host_addr, sizeof(host_addr), "%s:%d", addr, port);
-       }
-
-       ret = iotcon_resource_types_create(&res_types);
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_resource_types_create() Fail(%d)", ret);
-               return NULL;
-       }
-
-       while (g_variant_iter_loop(types_iter, "s", &res_type))
-               iotcon_resource_types_insert(res_types, res_type);
-
-       ret = iotcon_client_create(host_addr, uri_path, !!is_observable, res_types, ifaces,
-                       &client);
-       if (res_types)
-               iotcon_resource_types_destroy(res_types);
-
-       if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_create() Fail");
-               return NULL;
-       }
-       client->ref_count = 1;
-
-       client->device_id = strdup(sid);
-       if (NULL == client->device_id) {
-               ERR("strdup(sid) Fail(%d)", errno);
-               iotcon_client_destroy(client);
-               return NULL;
-       }
-       client->conn_type = conn_type;
-       client->is_secure = is_secure;
-
-       return client;
-}
-
diff --git a/lib/icl-client.h b/lib/icl-client.h
deleted file mode 100644 (file)
index f9b1507..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__
-
-#include <stdint.h>
-#include "iotcon-struct.h"
-#include "icl-options.h"
-
-struct icl_remote_resource {
-       int ref_count;
-       char *uri_path;
-       char *host;
-       char *device_id;
-       bool is_secure;
-       bool is_observable;
-       iotcon_options_h header_options;
-       iotcon_resource_types_h types;
-       int ifaces;
-       iotcon_connectivity_type_e conn_type;
-       int64_t observe_handle;
-       unsigned int observe_sub_id;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__ */
index 45657e84374d2fcab1059bd217be75e02bfd9278..6bebd8bcbacf83df9a2dce9967f892f7a4a1e519 100644 (file)
@@ -27,7 +27,7 @@
 #include "icl-query.h"
 #include "icl-request.h"
 #include "icl-response.h"
-#include "icl-client.h"
+#include "icl-remote-resource.h"
 #include "icl-repr.h"
 #include "icl-payload.h"
 #include "icl-observation.h"
@@ -114,7 +114,7 @@ GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
 }
 
 
-GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource)
+GVariant* icl_dbus_remote_resource_to_gvariant(struct icl_remote_resource *resource)
 {
        FN_CALL;
        GVariant *value;
index f8cc40ca95abd1adef387ee243436240f40543fe..3275ded8f20e174d75864d2cf4b19389c823fff4 100644 (file)
@@ -23,7 +23,7 @@
 const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types);
 GVariant* icl_dbus_notimsg_to_gvariant(struct icl_notify_msg *msg);
 GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response);
-GVariant* icl_dbus_client_to_gvariant(struct icl_remote_resource *resource);
+GVariant* icl_dbus_remote_resource_to_gvariant(struct icl_remote_resource *resource);
 GVariant* icl_dbus_device_info_to_gvariant(const char *device_name);
 GVariant* icl_dbus_platform_info_to_gvariant(iotcon_platform_info_s *platform_info);
 GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query);
index 120758b27a452d36405140fa0b5b860b2421153b..e43cf7fd31cb55f2f2f33786570f54b39bf08030 100644 (file)
@@ -230,7 +230,7 @@ static void _icl_platform_info_cb(GDBusConnection *connection,
 
        info = calloc(1, sizeof(iotcon_platform_info_s));
        if (NULL == info) {
-               ERR("calloc(client) Fail(%d)", errno);
+               ERR("calloc(info) Fail(%d)", errno);
                return;
        }
 
diff --git a/lib/icl-remote-resource-crud.c b/lib/icl-remote-resource-crud.c
new file mode 100644 (file)
index 0000000..a7f8065
--- /dev/null
@@ -0,0 +1,569 @@
+/*
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-utils.h"
+#include "ic-dbus.h"
+#include "icl.h"
+#include "icl-options.h"
+#include "icl-dbus.h"
+#include "icl-dbus-type.h"
+#include "icl-repr.h"
+#include "icl-remote-resource.h"
+#include "icl-payload.h"
+
+typedef struct {
+       iotcon_remote_resource_cru_cb cb;
+       void *user_data;
+       iotcon_remote_resource_h resource;
+} icl_on_cru_s;
+
+typedef struct {
+       iotcon_remote_resource_delete_cb cb;
+       void *user_data;
+       iotcon_remote_resource_h resource;
+} icl_on_delete_s;
+
+typedef struct {
+       iotcon_remote_resource_observe_cb cb;
+       void *user_data;
+       iotcon_remote_resource_h resource;
+} icl_on_observe_s;
+
+
+static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
+{
+       int res, ret;
+       iotcon_representation_h repr;
+       GVariantIter *options;
+       unsigned short option_id;
+       char *option_data;
+       GVariant *repr_gvar;
+       iotcon_options_h header_options = NULL;
+       iotcon_remote_resource_cru_cb cb = cb_container->cb;
+
+       g_variant_get(result, "(a(qs)vi)", &options, &repr_gvar, &res);
+
+       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
+               ret = iotcon_options_create(&header_options);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("iotcon_options_create() Fail(%d)", ret);
+                       return;
+               }
+
+               while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
+                       iotcon_options_insert(header_options, option_id, option_data);
+       }
+       g_variant_iter_free(options);
+
+       repr = icl_representation_from_gvariant(repr_gvar);
+       if (NULL == repr) {
+               ERR("icl_representation_from_gvariant() Fail");
+               if (header_options)
+                       iotcon_options_destroy(header_options);
+
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return;
+       }
+
+       res = icl_dbus_convert_daemon_error(res);
+
+       if (cb)
+               cb(cb_container->resource, repr, header_options, res,
+                               cb_container->user_data);
+
+       if (repr)
+               iotcon_representation_destroy(repr);
+       if (header_options)
+               iotcon_options_destroy(header_options);
+
+       iotcon_remote_resource_destroy(cb_container->resource);
+       free(cb_container);
+}
+
+
+static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res,
+               gpointer user_data)
+{
+       GVariant *result;
+       GError *error = NULL;
+       icl_on_cru_s *cb_container = user_data;
+
+       ic_dbus_call_get_finish(IC_DBUS(object), &result, g_async_res, &error);
+       if (error) {
+               ERR("ic_dbus_call_get_finish() Fail(%s)", error->message);
+               g_error_free(error);
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return;
+       }
+
+       _icl_on_cru_cb(result, cb_container);
+}
+
+
+static void _icl_on_put_cb(GObject *object, GAsyncResult *g_async_res,
+               gpointer user_data)
+{
+       GVariant *result;
+       GError *error = NULL;
+       icl_on_cru_s *cb_container = user_data;
+
+       ic_dbus_call_put_finish(IC_DBUS(object), &result, g_async_res, &error);
+       if (error) {
+               ERR("ic_dbus_call_put_finish() Fail(%s)", error->message);
+               g_error_free(error);
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return;
+       }
+
+       _icl_on_cru_cb(result, cb_container);
+}
+
+
+static void _icl_on_post_cb(GObject *object, GAsyncResult *g_async_res,
+               gpointer user_data)
+{
+       GVariant *result;
+       GError *error = NULL;
+       icl_on_cru_s *cb_container = user_data;
+
+       ic_dbus_call_post_finish(IC_DBUS(object), &result, g_async_res, &error);
+       if (error) {
+               ERR("ic_dbus_call_post_finish() Fail(%s)", error->message);
+               g_error_free(error);
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return;
+       }
+
+       _icl_on_cru_cb(result, cb_container);
+}
+
+
+API int iotcon_remote_resource_get(iotcon_remote_resource_h resource,
+               iotcon_query_h query, iotcon_remote_resource_cru_cb cb, void *user_data)
+{
+       int ret;
+       GVariant *arg_query;
+       GVariant *arg_remote_resource;
+       icl_on_cru_s *cb_container;
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       cb_container = calloc(1, sizeof(icl_on_cru_s));
+       if (NULL == cb_container) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_ref() Fail");
+               free(cb_container);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       cb_container->cb = cb;
+       cb_container->user_data = user_data;
+
+       arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
+       arg_query = icl_dbus_query_to_gvariant(query);
+
+       ic_dbus_call_get(icl_dbus_get_object(), arg_remote_resource, arg_query, NULL,
+                       _icl_on_get_cb, cb_container);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
+               iotcon_representation_h repr,
+               iotcon_query_h query,
+               iotcon_remote_resource_cru_cb cb,
+               void *user_data)
+{
+       int ret;
+       GVariant *arg_repr;
+       GVariant *arg_remote_resource;
+       GVariant *arg_query;
+       icl_on_cru_s *cb_container;
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       cb_container = calloc(1, sizeof(icl_on_cru_s));
+       if (NULL == cb_container) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_ref() Fail");
+               free(cb_container);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       cb_container->cb = cb;
+       cb_container->user_data = user_data;
+
+       arg_repr = icl_representation_to_gvariant(repr);
+       if (NULL == arg_repr) {
+               ERR("icl_representation_to_gvariant() Fail");
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return IOTCON_ERROR_REPRESENTATION;
+       }
+
+       arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
+       arg_query = icl_dbus_query_to_gvariant(query);
+
+       ic_dbus_call_put(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query,
+                       NULL, _icl_on_put_cb, cb_container);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
+               iotcon_representation_h repr,
+               iotcon_query_h query,
+               iotcon_remote_resource_cru_cb cb,
+               void *user_data)
+{
+       int ret;
+       GVariant *arg_repr;
+       GVariant *arg_query;
+       GVariant *arg_remote_resource;
+       icl_on_cru_s *cb_container;
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       cb_container = calloc(1, sizeof(icl_on_cru_s));
+       if (NULL == cb_container) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_ref() Fail");
+               free(cb_container);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       cb_container->cb = cb;
+       cb_container->user_data = user_data;
+
+       arg_repr = icl_representation_to_gvariant(repr);
+       if (NULL == arg_repr) {
+               ERR("icl_representation_to_gvariant() Fail");
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return IOTCON_ERROR_REPRESENTATION;
+       }
+
+       arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
+       arg_query = icl_dbus_query_to_gvariant(query);
+
+       ic_dbus_call_post(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query,
+                       NULL, _icl_on_post_cb, cb_container);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
+               gpointer user_data)
+{
+       int res, ret;
+       GVariant *result;
+       char *option_data;
+       GError *error = NULL;
+       GVariantIter *options;
+       unsigned short option_id;
+       iotcon_options_h header_options = NULL;
+
+       icl_on_delete_s *cb_container = user_data;
+       iotcon_remote_resource_delete_cb cb = cb_container->cb;
+
+       ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error);
+       if (error) {
+               ERR("ic_dbus_call_delete_finish() Fail(%s)", error->message);
+               g_error_free(error);
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return;
+       }
+       g_variant_get(result, "(a(qs)i)", &options, &res);
+
+       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
+               ret = iotcon_options_create(&header_options);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("iotcon_options_create() Fail(%d)", ret);
+                       g_variant_iter_free(options);
+                       iotcon_remote_resource_destroy(cb_container->resource);
+                       free(cb_container);
+                       return;
+               }
+
+               while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
+                       iotcon_options_insert(header_options, option_id, option_data);
+       }
+       g_variant_iter_free(options);
+
+       res = icl_dbus_convert_daemon_error(res);
+
+       if (cb)
+               cb(cb_container->resource, header_options, res, cb_container->user_data);
+
+       if (header_options)
+               iotcon_options_destroy(header_options);
+
+       iotcon_remote_resource_destroy(cb_container->resource);
+       free(cb_container);
+}
+
+
+API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
+               iotcon_remote_resource_delete_cb cb, void *user_data)
+{
+       int ret;
+       GVariant *arg_remote_resource;
+       icl_on_delete_s *cb_container;
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       cb_container = calloc(1, sizeof(icl_on_delete_s));
+       if (NULL == cb_container) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_ref() Fail");
+               free(cb_container);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       cb_container->cb = cb;
+       cb_container->user_data = user_data;
+
+       arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
+
+       ic_dbus_call_delete(icl_dbus_get_object(), arg_remote_resource, NULL,
+                       _icl_on_delete_cb, cb_container);
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+static void _icl_on_observe_cb(GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
+{
+       int res, ret;
+       int seq_num;
+       iotcon_representation_h repr;
+       GVariantIter *options;
+       unsigned short option_id;
+       char *option_data;
+       GVariant *repr_gvar;
+       iotcon_options_h header_options = NULL;
+
+       icl_on_observe_s *cb_container = user_data;
+       iotcon_remote_resource_observe_cb cb = cb_container->cb;
+
+       g_variant_get(parameters, "(a(qs)vii)", &options, &repr_gvar, &res,
+                       &seq_num);
+
+       if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
+               ret = iotcon_options_create(&header_options);
+               if (IOTCON_ERROR_NONE != ret) {
+                       ERR("iotcon_options_create() Fail(%d)", ret);
+                       g_variant_iter_free(options);
+                       iotcon_remote_resource_destroy(cb_container->resource);
+                       free(cb_container);
+                       return;
+               }
+
+               while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
+                       iotcon_options_insert(header_options, option_id, option_data);
+       }
+       g_variant_iter_free(options);
+
+       repr = icl_representation_from_gvariant(repr_gvar);
+       if (NULL == repr) {
+               ERR("icl_representation_from_gvariant() Fail");
+               if (header_options)
+                       iotcon_options_destroy(header_options);
+
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return;
+       }
+
+       res = icl_dbus_convert_daemon_error(res);
+
+       if (cb)
+               cb(cb_container->resource, repr, header_options, res, seq_num,
+                               cb_container->user_data);
+
+       if (repr)
+               iotcon_representation_destroy(repr);
+       if (header_options)
+               iotcon_options_destroy(header_options);
+}
+
+
+static void _icl_observe_conn_cleanup(icl_on_observe_s *cb_container)
+{
+       cb_container->resource->observe_handle = 0;
+       cb_container->resource->observe_sub_id = 0;
+       iotcon_remote_resource_destroy(cb_container->resource);
+       free(cb_container);
+}
+
+
+API int iotcon_remote_resource_observer_start(iotcon_remote_resource_h resource,
+               int observe_type,
+               iotcon_query_h query,
+               iotcon_remote_resource_observe_cb cb,
+               void *user_data)
+{
+       GVariant *arg_query;
+       unsigned int sub_id;
+       GVariant *arg_remote_resource;
+       GError *error = NULL;
+       int64_t observe_handle;
+       icl_on_observe_s *cb_container;
+       int ret, signal_number;
+       char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       signal_number = icl_dbus_generate_signal_number();
+
+       arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
+       arg_query = icl_dbus_query_to_gvariant(query);
+
+       ic_dbus_call_observer_start_sync(icl_dbus_get_object(), arg_remote_resource,
+                       observe_type, arg_query, signal_number, &observe_handle, NULL, &error);
+       if (error) {
+               ERR("ic_dbus_call_observer_start_sync() Fail(%s)", error->message);
+               ret = icl_dbus_convert_dbus_error(error->code);
+               g_error_free(error);
+               g_variant_unref(arg_query);
+               g_variant_unref(arg_remote_resource);
+               return ret;
+       }
+
+       if (0 == observe_handle) {
+               ERR("iotcon-daemon Fail");
+               return IOTCON_ERROR_IOTIVITY;
+       }
+
+       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_OBSERVE,
+                       signal_number);
+
+       cb_container = calloc(1, sizeof(icl_on_observe_s));
+       if (NULL == cb_container) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_ref() Fail");
+               free(cb_container);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       cb_container->cb = cb;
+       cb_container->user_data = user_data;
+
+       sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
+                       _icl_observe_conn_cleanup, _icl_on_observe_cb);
+       if (0 == sub_id) {
+               ERR("icl_dbus_subscribe_signal() Fail");
+               iotcon_remote_resource_destroy(cb_container->resource);
+               free(cb_container);
+               return IOTCON_ERROR_DBUS;
+       }
+       resource->observe_sub_id = sub_id;
+       resource->observe_handle = observe_handle;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_remote_resource_observer_stop(iotcon_remote_resource_h resource)
+{
+       int ret;
+       GError *error = NULL;
+       GVariant *arg_options;
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       if (0 == resource->observe_handle) {
+               ERR("It doesn't have a observe_handle");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       arg_options = icl_dbus_options_to_gvariant(resource->header_options);
+
+       ic_dbus_call_observer_stop_sync(icl_dbus_get_object(), resource->observe_handle,
+                       arg_options, &ret, NULL, &error);
+       if (error) {
+               ERR("ic_dbus_call_observer_stop_sync() Fail(%s)", error->message);
+               ret = icl_dbus_convert_dbus_error(error->code);
+               g_error_free(error);
+               return ret;
+       }
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon-daemon Fail(%d)", ret);
+               return icl_dbus_convert_daemon_error(ret);
+       }
+
+       icl_dbus_unsubscribe_signal(resource->observe_sub_id);
+
+       return ret;
+}
+
diff --git a/lib/icl-remote-resource.c b/lib/icl-remote-resource.c
new file mode 100644 (file)
index 0000000..24d22c2
--- /dev/null
@@ -0,0 +1,350 @@
+/*
+ * 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 <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-options.h"
+#include "icl-dbus.h"
+#include "icl-repr.h"
+#include "icl-remote-resource.h"
+#include "icl-resource-types.h"
+#include "icl-payload.h"
+
+typedef struct {
+       iotcon_found_resource_cb cb;
+       void *user_data;
+       unsigned int id;
+} icl_found_resource_s;
+
+static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *payload,
+               iotcon_connectivity_type_e conn_type);
+
+static void _icl_found_resource_cb(GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
+{
+       FN_CALL;
+       int conn_type;
+       iotcon_remote_resource_h resource;
+
+       GVariant *payload;
+       icl_found_resource_s *cb_container = user_data;
+       iotcon_found_resource_cb cb = cb_container->cb;
+
+       g_variant_get(parameters, "(vi)", &payload, &conn_type);
+
+       resource = _icl_remote_resource_from_gvariant(payload, conn_type);
+       if (NULL == resource) {
+               ERR("icl_remote_resource_from_gvariant() Fail");
+               return;
+       }
+
+       if (cb)
+               cb(resource, cb_container->user_data);
+
+       iotcon_remote_resource_destroy(resource);
+
+       /* TODO
+        * When is callback removed?
+        */
+}
+
+
+/* The length of resource_type should be less than or equal to 61.
+ * If resource_type is NULL, then All resources in host are discovered. */
+API int iotcon_find_resource(const char *host_address, const char *resource_type,
+               iotcon_found_resource_cb cb, void *user_data)
+{
+       unsigned int sub_id;
+       GError *error = NULL;
+       int ret, signal_number;
+       icl_found_resource_s *cb_container;
+       char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
+
+       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+       RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+       if (resource_type && (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
+               ERR("The length of resource_type(%s) is invalid", resource_type);
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
+       signal_number = icl_dbus_generate_signal_number();
+
+       ic_dbus_call_find_resource_sync(icl_dbus_get_object(), host_address,
+                       ic_utils_dbus_encode_str(resource_type), signal_number, &ret, NULL, &error);
+       if (error) {
+               ERR("ic_dbus_call_find_resource_sync() Fail(%s)", error->message);
+               ret = icl_dbus_convert_dbus_error(error->code);
+               g_error_free(error);
+               return ret;
+       }
+
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon-daemon Fail(%d)", ret);
+               return icl_dbus_convert_daemon_error(ret);
+       }
+
+       snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_FOUND_RESOURCE,
+                       signal_number);
+
+       cb_container = calloc(1, sizeof(icl_found_resource_s));
+       if (NULL == cb_container) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       cb_container->cb = cb;
+       cb_container->user_data = user_data;
+
+       sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
+                       _icl_found_resource_cb);
+       if (0 == sub_id) {
+               ERR("icl_dbus_subscribe_signal() Fail");
+               return IOTCON_ERROR_DBUS;
+       }
+
+       cb_container->id = sub_id;
+
+       return ret;
+}
+
+
+/* If you know the information of resource, then you can make a proxy of the resource. */
+API int iotcon_remote_resource_create(const char *host,
+               const char *uri_path,
+               bool is_observable,
+               iotcon_resource_types_h resource_types,
+               int resource_ifs,
+               iotcon_remote_resource_h *resource_handle)
+{
+       FN_CALL;
+       iotcon_remote_resource_h resource = NULL;
+
+       RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
+
+       resource = calloc(1, sizeof(struct icl_remote_resource));
+       if (NULL == resource) {
+               ERR("calloc() Fail(%d)", errno);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       resource->host = ic_utils_strdup(host);
+       resource->uri_path = ic_utils_strdup(uri_path);
+       resource->is_observable = is_observable;
+       resource->types = icl_resource_types_ref(resource_types);
+       resource->ifaces = resource_ifs;
+
+       resource->ref_count = 1;
+
+       *resource_handle = resource;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource)
+{
+       RET_IF(NULL == resource);
+
+       resource->ref_count--;
+
+       if (0 < resource->ref_count)
+               return;
+
+       free(resource->uri_path);
+       free(resource->host);
+       free(resource->device_id);
+       iotcon_resource_types_destroy(resource->types);
+
+       /* null COULD be allowed */
+       if (resource->header_options)
+               iotcon_options_destroy(resource->header_options);
+
+       free(resource);
+}
+
+
+API int iotcon_remote_resource_ref(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest)
+{
+       RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(src->ref_count <= 0, IOTCON_ERROR_INVALID_PARAMETER);
+
+       src->ref_count++;
+
+       *dest = src;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_remote_resource_get_uri_path(iotcon_remote_resource_h resource, char **uri_path)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *uri_path = resource->uri_path;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_remote_resource_get_host(iotcon_remote_resource_h resource, char **host)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *host = resource->host;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource, char **device_id)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == device_id, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *device_id = resource->device_id;
+
+       return IOTCON_ERROR_NONE;
+}
+
+/* The content of the resource should not be freed by user. */
+API int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource, iotcon_resource_types_h *types)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *types = resource->types;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource, int *ifaces)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *ifaces = resource->ifaces;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_remote_resource_is_observable(iotcon_remote_resource_h resource,
+               bool *observable)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == observable, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *observable = resource->is_observable;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+/* if header_options is NULL, then client's header_options is unset */
+API int iotcon_remote_resource_set_options(iotcon_remote_resource_h resource,
+               iotcon_options_h header_options)
+{
+       RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+
+       if (resource->header_options)
+               iotcon_options_destroy(resource->header_options);
+
+       if (header_options)
+               resource->header_options = icl_options_ref(header_options);
+       else
+               resource->header_options = NULL;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
+static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *payload,
+               iotcon_connectivity_type_e conn_type)
+{
+       int ret;
+       iotcon_remote_resource_h resource;
+       GVariantIter *types_iter;
+       char host_addr[PATH_MAX] = {0};
+       iotcon_resource_types_h res_types;
+       char *uri_path, *device_id, *res_type, *addr;
+       int ifaces, is_observable, is_secure, port;
+
+       g_variant_get(payload, "(&s&siasib&si)", &uri_path, &device_id, &ifaces, &types_iter,
+                       &is_observable, &is_secure, &addr, &port);
+
+       switch (conn_type) {
+       case IOTCON_CONNECTIVITY_IPV6:
+               snprintf(host_addr, sizeof(host_addr), "[%s]:%d", addr, port);
+               break;
+       case IOTCON_CONNECTIVITY_IPV4:
+       default:
+               snprintf(host_addr, sizeof(host_addr), "%s:%d", addr, port);
+       }
+
+       ret = iotcon_resource_types_create(&res_types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_types_create() Fail(%d)", ret);
+               return NULL;
+       }
+
+       while (g_variant_iter_loop(types_iter, "s", &res_type))
+               iotcon_resource_types_insert(res_types, res_type);
+
+       ret = iotcon_remote_resource_create(host_addr, uri_path, !!is_observable, res_types, ifaces,
+                       &resource);
+       if (res_types)
+               iotcon_resource_types_destroy(res_types);
+
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_create() Fail");
+               return NULL;
+       }
+       resource->ref_count = 1;
+
+       resource->device_id = strdup(device_id);
+       if (NULL == resource->device_id) {
+               ERR("strdup(device_id) Fail(%d)", errno);
+               iotcon_remote_resource_destroy(resource);
+               return NULL;
+       }
+       resource->conn_type = conn_type;
+       resource->is_secure = is_secure;
+
+       return resource;
+}
+
diff --git a/lib/icl-remote-resource.h b/lib/icl-remote-resource.h
new file mode 100644 (file)
index 0000000..f9b1507
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__
+
+#include <stdint.h>
+#include "iotcon-struct.h"
+#include "icl-options.h"
+
+struct icl_remote_resource {
+       int ref_count;
+       char *uri_path;
+       char *host;
+       char *device_id;
+       bool is_secure;
+       bool is_observable;
+       iotcon_options_h header_options;
+       iotcon_resource_types_h types;
+       int ifaces;
+       iotcon_connectivity_type_e conn_type;
+       int64_t observe_handle;
+       unsigned int observe_sub_id;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__ */
index 125f6b712efc46b0f7e8b2c1258a99ebd1bd6b7c..27e72ff72905beaab71bbcac5eab255238d35887 100644 (file)
@@ -148,7 +148,7 @@ static void _icl_resource_conn_cleanup(iotcon_resource_h resource)
 
 
 /* The length of uri_path should be less than or equal to 36. */
-API int iotcon_register_resource(const char *uri_path,
+API int iotcon_resource_create(const char *uri_path,
                iotcon_resource_types_h res_types,
                int ifaces,
                uint8_t properties,
@@ -232,7 +232,7 @@ API int iotcon_register_resource(const char *uri_path,
 }
 
 
-API int iotcon_unregister_resource(iotcon_resource_h resource)
+API int iotcon_resource_destroy(iotcon_resource_h resource)
 {
        FN_CALL;
        int ret;
@@ -334,7 +334,7 @@ API int iotcon_resource_bind_type(iotcon_resource_h resource, const char *resour
 }
 
 
-API int iotcon_resource_bind_request_handler(iotcon_resource_h resource,
+API int iotcon_resource_set_request_handler(iotcon_resource_h resource,
                iotcon_request_handler_cb cb)
 {
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
index 904dca783afdcc785ade1e5a11867e8b967dc70f..0b4050a66b50c4659c9ac1fd12f5ebe9afd719d4 100644 (file)
@@ -39,8 +39,8 @@ typedef struct icl_list_s* iotcon_list_h;
 /**
  * @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
  * @brief The handle of representation.
- * @details iotcon_representation_h is an opaque data structure to have uri_path, list of resource types
- * and interfaces.\n
+ * @details iotcon_representation_h is an opaque data structure to have uri_path,\n
+ * list of resource types and interfaces.\n
  * It could contain other representation as children.\n
  *
  * @since_tizen 3.0
@@ -416,8 +416,8 @@ int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
 
 /**
  * @brief The handle of resource types
- * @details iotcon_resource_types_h is an opaque data structure to have list of resource types.\n
- * A resource type is datatype of string.
+ * @details iotcon_resource_types_h is an opaque data structure to have list\n
+ * of resource types. A resource type is datatype of string.
  *
  * @since_tizen 3.0
  */
@@ -643,11 +643,11 @@ int iotcon_observers_delete(iotcon_observers_h observers, int obs_id);
 
 /**
  * @brief The handle of resource.
- * @details iotcon_resource_h is an opaque data structure to represent registered resource by server.
- * A resource has host, uri_path, resource types, interfaces and internal handle.\n
- * If observable attribute of resource is true, client can observe this resource.\n
- * When client request by CRUD functions, handler will be invoked if registered.
- * It could contain other resource as children.\n
+ * @details iotcon_resource_h is an opaque data structure to represent registered\n
+ * resource by server. A resource has host, uri_path, resource types, interfaces\n
+ * and internal handle. If observable attribute of resource is true, client can observe\n
+ * this resource. When client request by CRUD functions, handler will be invoked\n
+ * if registered. It could contain other resource as children.\n
  *
  * @since_tizen 3.0
  */
@@ -776,129 +776,132 @@ int iotcon_resource_get_interfaces(iotcon_resource_h resource, int *ifaces);
 int iotcon_resource_is_observable(iotcon_resource_h resource, bool *observable);
 
 /**
- * @brief The handle of client
+ * @brief The handle of remote resource
  * @details When Client success to find out resource from remote server,
- * server's resource information is reorganized as iotcon_client_h by Iotcon.
+ * server's resource information is reorganized as iotcon_remote_resource_h by Iotcon.
  * Client can request CRUD to server by using this.\n
- * iotcon_client_h is an opaque data structure to have host, uri_path, resource types, interfaces,
- * options and server id.\n
+ * iotcon_remote_resource_h is an opaque data structure to have host, uri_path,\n
+ * resource types, interfaces, options and device id.\n
  * If observable attribute is true, remote resource is observable.\n
  * When you observe remote resource, observe_handle will be set.
  *
  * @since_tizen 3.0
  */
-typedef struct icl_remote_resource* iotcon_client_h;
+typedef struct icl_remote_resource* iotcon_remote_resource_h;
 
 /**
- * @brief Gets an URI path of the client
+ * @brief Gets an URI path of the remote resource
  *
  * @since_tizen 3.0
  * @remarks @a uri_path must not be released using free().
  *
- * @param[in] resource The handle of the client
- * @param[out] uri_path The URI path of the client
+ * @param[in] resource The handle of the remote resource
+ * @param[out] uri_path The URI path of the remote resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_host()
- * @see iotcon_client_get_device_id()
- * @see iotcon_client_get_types()
- * @see iotcon_client_get_interfaces()
- * @see iotcon_client_is_observable()
- * @see iotcon_client_set_options()
+ * @see iotcon_remote_resource_get_host()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_is_observable()
+ * @see iotcon_remote_resource_set_options()
  */
-int iotcon_client_get_uri_path(iotcon_client_h resource, char **uri_path);
+int iotcon_remote_resource_get_uri_path(iotcon_remote_resource_h resource,
+               char **uri_path);
 
 /**
- * @brief Gets an host address of the client
+ * @brief Gets an host address of the remote resource
  *
  * @since_tizen 3.0
  * @remarks @a host must not be released using free().
  *
- * @param[in] resource The handle of the client
- * @param[out] host The host address of the client
+ * @param[in] resource The handle of the remote resource
+ * @param[out] host The host address of the remote resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_uri_path()
- * @see iotcon_client_get_device_id()
- * @see iotcon_client_get_types()
- * @see iotcon_client_get_interfaces()
- * @see iotcon_client_is_observable()
- * @see iotcon_client_set_options()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_is_observable()
+ * @see iotcon_remote_resource_set_options()
  */
-int iotcon_client_get_host(iotcon_client_h resource, char **host);
+int iotcon_remote_resource_get_host(iotcon_remote_resource_h resource, char **host);
 
 /**
- * @brief Gets an server id of the client
+ * @brief Gets an device id of the remote resource
  *
  * @since_tizen 3.0
- * @remarks @a sid must not be released using free().
+ * @remarks @a device_id must not be released using free().
  *
- * @param[in] resource The handle of the client
- * @param[out] device_id The device id of the client
+ * @param[in] resource The handle of the remote resource
+ * @param[out] device_id The device id of the remote resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_uri_path()
- * @see iotcon_client_get_host()
- * @see iotcon_client_get_types()
- * @see iotcon_client_get_interfaces()
- * @see iotcon_client_is_observable()
- * @see iotcon_client_set_options()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_host()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_is_observable()
+ * @see iotcon_remote_resource_set_options()
  */
-int iotcon_client_get_device_id(iotcon_client_h resource, char **device_id);
+int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource,
+               char **device_id);
 
 /**
- * @brief Gets resource types of the client
+ * @brief Gets resource types of the remote resource
  *
  * @since_tizen 3.0
  *
- * @param[in] resource The handle of the client
- * @param[out] types The resource types of the client
+ * @param[in] resource The handle of the remote resource
+ * @param[out] types The resource types of the remote resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_uri_path()
- * @see iotcon_client_get_host()
- * @see iotcon_client_get_device_id()
- * @see iotcon_client_get_interfaces()
- * @see iotcon_client_is_observable()
- * @see iotcon_client_set_options()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_host()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_is_observable()
+ * @see iotcon_remote_resource_set_options()
  */
-int iotcon_client_get_types(iotcon_client_h resource, iotcon_resource_types_h *types);
+int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
+               iotcon_resource_types_h *types);
 
 /**
- * @brief Gets resource interfaces of the client
+ * @brief Gets resource interfaces of the remote resource
  *
  * @since_tizen 3.0
  *
- * @param[in] resource The handle of the client
- * @param[out] ifaces The resource interfaces of the client
+ * @param[in] resource The handle of the remote resource
+ * @param[out] ifaces The resource interfaces of the remote resource
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_uri_path()
- * @see iotcon_client_get_host()
- * @see iotcon_client_get_device_id()
- * @see iotcon_client_get_types()
- * @see iotcon_client_is_observable()
- * @see iotcon_client_set_options()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_host()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_is_observable()
+ * @see iotcon_remote_resource_set_options()
  */
-int iotcon_client_get_interfaces(iotcon_client_h resource, int *ifaces);
+int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource, int *ifaces);
 
 /**
- * @brief Checks whether the client is observable or not.
+ * @brief Checks whether the remote resource is observable or not.
  *
  * @since_tizen 3.0
  *
@@ -909,35 +912,37 @@ int iotcon_client_get_interfaces(iotcon_client_h resource, int *ifaces);
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_uri_path()
- * @see iotcon_client_get_host()
- * @see iotcon_client_get_device_id()
- * @see iotcon_client_get_types()
- * @see iotcon_client_get_interfaces()
- * @see iotcon_client_set_options()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_host()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_set_options()
  */
-int iotcon_client_is_observable(iotcon_client_h resource, bool *observable);
+int iotcon_remote_resource_is_observable(iotcon_remote_resource_h resource,
+               bool *observable);
 
 /**
- * @brief Sets options into the client
+ * @brief Sets options into the remote resource
  *
  * @since_tizen 3.0
  *
- * @param[in] resource The handle of the client
+ * @param[in] resource The handle of the remote resource
  * @param[in] options The handle of the header options
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_get_uri_path()
- * @see iotcon_client_get_host()
- * @see iotcon_client_get_device_id()
- * @see iotcon_client_get_types()
- * @see iotcon_client_get_interfaces()
- * @see iotcon_client_is_observable()
+ * @see iotcon_remote_resource_get_uri_path()
+ * @see iotcon_remote_resource_get_host()
+ * @see iotcon_remote_resource_get_device_id()
+ * @see iotcon_remote_resource_get_types()
+ * @see iotcon_remote_resource_get_interfaces()
+ * @see iotcon_remote_resource_is_observable()
  */
-int iotcon_client_set_options(iotcon_client_h resource, iotcon_options_h options);
+int iotcon_remote_resource_set_options(iotcon_remote_resource_h resource,
+               iotcon_options_h options);
 
 /**
 * @brief The handle of request
index 7dd0b4987badb6d6e0cfa81886fb9151500b211f..673b55dbbd8f249e99f078816765b1901d18c4ad 100644 (file)
@@ -126,8 +126,8 @@ int iotcon_add_connection_changed_cb(iotcon_connection_changed_cb cb, void *user
 int iotcon_remove_connection_changed_cb(iotcon_connection_changed_cb cb, void *user_data);
 
 /**
- * @brief Specifies the type of function passed to iotcon_register_resource() and
- * iotcon_resource_bind_request_handler()
+ * @brief Specifies the type of function passed to iotcon_resource_create() and
+ * iotcon_resource_set_request_handler()
  * @details Called when server receive request from the client.
  *
  * @since_tizen 3.0
@@ -136,16 +136,16 @@ int iotcon_remove_connection_changed_cb(iotcon_connection_changed_cb cb, void *u
  * @param[in] request The request from client
  * @param[in] user_data The user data to pass to the function
  *
- * @pre The callback must be registered using iotcon_register_resource()
+ * @pre The callback must be registered using iotcon_resource_create()
  *
- * @see iotcon_register_resource()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_create()
+ * @see iotcon_resource_set_request_handler()
  */
 typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
                iotcon_request_h request, void *user_data);
 
 /**
- * @brief Registers a resource in server
+ * @brief Create a resource handle and registers the resource in server
  * @details Registers a resource specified by @a uri_path, @a res_types, @a ifaces which have
  * @a properties in Iotcon server.\n
  * When client find the registered resource, iotcon_request_handler_cb() will be called automatically.\n
@@ -164,7 +164,7 @@ typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
  * @privilege %http://tizen.org/privilege/internet
  *
  * @remarks @a uri_path length must be less than or equal 36.\n
- * You must unregister resource by calling iotcon_unregister_resource()
+ * You must unregister resource by calling iotcon_resource_destroy()
  * if resource is no longer needed.
  *
  * @param[in] uri_path The URI path of the resource.
@@ -185,15 +185,15 @@ typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
  *
  * @post When the resource receive CRUD request, iotcon_request_handler_cb() will be called.
  *
- * @see iotcon_unregister_resource()
+ * @see iotcon_resource_destroy()
  * @see iotcon_resource_bind_interface()
  * @see iotcon_resource_bind_type()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_set_request_handler()
  * @see iotcon_resource_bind_child_resource()
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
  */
-int iotcon_register_resource(const char *uri_path,
+int iotcon_resource_create(const char *uri_path,
                iotcon_resource_types_h res_types,
                int ifaces,
                uint8_t properties,
@@ -202,7 +202,7 @@ int iotcon_register_resource(const char *uri_path,
                iotcon_resource_h *resource_handle);
 
 /**
- * @brief Unregisters a resource and releases its data.
+ * @brief Destroy the resource and releases its data.
  *
  * @since_tizen 3.0
  * @privlevel public
@@ -220,15 +220,15 @@ int iotcon_register_resource(const char *uri_path,
  * @retval #IOTCON_ERROR_DBUS  Dbus error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_register_resource()
+ * @see iotcon_resource_create()
  * @see iotcon_resource_bind_interface()
  * @see iotcon_resource_bind_type()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_set_request_handler()
  * @see iotcon_resource_bind_child_resource()
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
  */
-int iotcon_unregister_resource(iotcon_resource_h resource_handle);
+int iotcon_resource_destroy(iotcon_resource_h resource_handle);
 
 /**
  * @brief Binds an interface to the resource
@@ -250,10 +250,10 @@ int iotcon_unregister_resource(iotcon_resource_h resource_handle);
  * @retval #IOTCON_ERROR_SYSTEM System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_register_resource()
- * @see iotcon_unregister_resource()
+ * @see iotcon_resource_create()
+ * @see iotcon_resource_destroy()
  * @see iotcon_resource_bind_type()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_set_request_handler()
  * @see iotcon_resource_bind_child_resource()
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
@@ -277,10 +277,10 @@ int iotcon_resource_bind_interface(iotcon_resource_h resource, int iface);
  * @retval #IOTCON_ERROR_SYSTEM System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_register_resource()
- * @see iotcon_unregister_resource()
+ * @see iotcon_resource_create()
+ * @see iotcon_resource_destroy()
  * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_set_request_handler()
  * @see iotcon_resource_bind_child_resource()
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
@@ -304,15 +304,15 @@ int iotcon_resource_bind_type(iotcon_resource_h resource_handle,
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_register_resource()
- * @see iotcon_unregister_resource()
+ * @see iotcon_resource_create()
+ * @see iotcon_resource_destroy()
  * @see iotcon_resource_bind_interface()
  * @see iotcon_resource_bind_type()
  * @see iotcon_resource_bind_child_resource()
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
  */
-int iotcon_resource_bind_request_handler(iotcon_resource_h resource,
+int iotcon_resource_set_request_handler(iotcon_resource_h resource,
                iotcon_request_handler_cb cb);
 
 /**
@@ -333,11 +333,11 @@ int iotcon_resource_bind_request_handler(iotcon_resource_h resource,
  * @retval #IOTCON_ERROR_SYSTEM System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_register_resource()
- * @see iotcon_unregister_resource()
+ * @see iotcon_resource_create()
+ * @see iotcon_resource_destroy()
  * @see iotcon_resource_bind_interface()
  * @see iotcon_resource_bind_type()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_set_request_handler()
  * @see iotcon_resource_unbind_child_resource()
  * @see iotcon_request_handler_cb()
  */
@@ -361,11 +361,11 @@ int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
  * @retval #IOTCON_ERROR_SYSTEM System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_register_resource()
- * @see iotcon_unregister_resource()
+ * @see iotcon_resource_create()
+ * @see iotcon_resource_destroy()
  * @see iotcon_resource_bind_interface()
  * @see iotcon_resource_bind_type()
- * @see iotcon_resource_bind_request_handler()
+ * @see iotcon_resource_set_request_handler()
  * @see iotcon_resource_bind_child_resource()
  * @see iotcon_request_handler_cb()
  */
@@ -625,7 +625,7 @@ int iotcon_unsubscribe_presence(iotcon_presence_h presence_handle);
  *
  * @see iotcon_find_resource()
  */
-typedef void (*iotcon_found_resource_cb)(iotcon_client_h resource, void *user_data);
+typedef void (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource, void *user_data);
 
 /**
  * @brief Finds resources.
@@ -680,15 +680,15 @@ int iotcon_find_resource(const char *host_address, const char *resource_type,
  * @retval #IOTCON_ERROR_DBUS  Dbus errors
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  *
- * @see iotcon_client_destroy()
- * @see iotcon_client_ref()
+ * @see iotcon_remote_resource_destroy()
+ * @see iotcon_remote_resource_ref()
  */
-int iotcon_client_create(const char *host,
+int iotcon_remote_resource_create(const char *host,
                const char *uri_path,
                bool is_observable,
                iotcon_resource_types_h resource_types,
                int resource_ifs,
-               iotcon_client_h *client_handle);
+               iotcon_remote_resource_h *client_handle);
 
 /**
  * @brief Releases a resource handle.
@@ -701,10 +701,10 @@ int iotcon_client_create(const char *host,
  *
  * @return void
  *
- * @see iotcon_client_create()
- * @see iotcon_client_ref()
+ * @see iotcon_remote_resource_create()
+ * @see iotcon_remote_resource_ref()
  */
-void iotcon_client_destroy(iotcon_client_h resource);
+void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource);
 
 /**
  * @brief Increments reference count of the source resource.
@@ -718,13 +718,13 @@ void iotcon_client_destroy(iotcon_client_h resource);
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
- * @see iotcon_client_create()
- * @see iotcon_client_destroy()
+ * @see iotcon_remote_resource_create()
+ * @see iotcon_remote_resource_destroy()
  */
-int iotcon_client_ref(iotcon_client_h src, iotcon_client_h *dest);
+int iotcon_remote_resource_ref(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest);
 
 /**
- * @brief Specifies the type of function passed to iotcon_observer_start().
+ * @brief Specifies the type of function passed to iotcon_remote_resource_observer_start().
  * @details Called when a client receive notifications from a server. The @a response_result could be one of #iotcon_response_result_e.
  *
  * @since_tizen 3.0
@@ -736,11 +736,11 @@ int iotcon_client_ref(iotcon_client_h src, iotcon_client_h *dest);
  * @param[in] sequence_number The sequence of notifications from server.
  * @param[in] user_data The user data passed from the callback registration function
  *
- * @pre The callback must be registered using iotcon_observer_start()
+ * @pre The callback must be registered using iotcon_remote_resource_observer_start()
  *
- * @see iotcon_observer_start()
+ * @see iotcon_remote_resource_observer_start()
  */
-typedef void (*iotcon_on_observe_cb)(iotcon_client_h resource,
+typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resource,
                iotcon_representation_h repr,
                iotcon_options_h options,
                int response_result,
@@ -749,7 +749,7 @@ typedef void (*iotcon_on_observe_cb)(iotcon_client_h resource,
 
 /**
  * @brief Sets observation on the resource
- * @details When server sends notification message, iotcon_on_observe_cb() will be called.
+ * @details When server sends notification message, iotcon_remote_resource_observe_cb() will be called.
  * The @a observe_type could be one of #iotcon_observe_type_e.
  *
  * @since_tizen 3.0
@@ -770,16 +770,19 @@ typedef void (*iotcon_on_observe_cb)(iotcon_client_h resource,
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @post When the @a resource receive notification message, iotcon_on_observe_cb() will be called.
+ * @post When the @a resource receive notification message, iotcon_remote_resource_observe_cb() will be called.
  *
- * @see iotcon_on_observe_cb()
- * @see iotcon_observer_stop()
+ * @see iotcon_remote_resource_observe_cb()
+ * @see iotcon_remote_resource_observer_stop()
  * @see iotcon_notimsg_create()
  * @see iotcon_notify_list_of_observers()
  * @see iotcon_resource_notify_all()
  */
-int iotcon_observer_start(iotcon_client_h resource, int observe_type,
-               iotcon_query_h query, iotcon_on_observe_cb cb, void *user_data);
+int iotcon_remote_resource_observer_start(iotcon_remote_resource_h resource,
+               int observe_type,
+               iotcon_query_h query,
+               iotcon_remote_resource_observe_cb cb,
+               void *user_data);
 
 /**
  * @brief Cancels the observation on the resource
@@ -797,13 +800,13 @@ int iotcon_observer_start(iotcon_client_h resource, int observe_type,
  * @retval #IOTCON_ERROR_SYSTEM System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_on_observe_cb()
- * @see iotcon_observer_start()
+ * @see iotcon_remote_resource_observe_cb()
+ * @see iotcon_remote_resource_observer_start()
  * @see iotcon_notimsg_create()
  * @see iotcon_notify_list_of_observers()
  * @see iotcon_resource_notify_all()
  */
-int iotcon_observer_stop(iotcon_client_h resource);
+int iotcon_remote_resource_observer_stop(iotcon_remote_resource_h resource);
 
 /**
  * @brief Send response for incoming request.
@@ -838,9 +841,9 @@ int iotcon_response_send(iotcon_response_h resp);
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  *
- * @see iotcon_on_observe_cb()
- * @see iotcon_observer_start()
- * @see iotcon_observer_stop()
+ * @see iotcon_remote_resource_observe_cb()
+ * @see iotcon_remote_resource_observer_start()
+ * @see iotcon_remote_resource_observer_stop()
  * @see iotcon_notify_list_of_observers()
  * @see iotcon_resource_notify_all()
  */
@@ -879,9 +882,9 @@ void iotcon_notimsg_destroy(iotcon_notimsg_h msg);
  * @retval #IOTCON_ERROR_SYSTEM  System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_on_observe_cb()
- * @see iotcon_observer_start()
- * @see iotcon_observer_stop()
+ * @see iotcon_remote_resource_observe_cb()
+ * @see iotcon_remote_resource_observer_start()
+ * @see iotcon_remote_resource_observer_stop()
  * @see iotcon_notimsg_create()
  * @see iotcon_resource_notify_all()
  */
@@ -904,16 +907,16 @@ int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notimsg_h
  * @retval #IOTCON_ERROR_SYSTEM  System error
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @see iotcon_on_observe_cb()
- * @see iotcon_observer_start()
- * @see iotcon_observer_stop()
+ * @see iotcon_remote_resource_observe_cb()
+ * @see iotcon_remote_resource_observer_start()
+ * @see iotcon_remote_resource_observer_stop()
  * @see iotcon_notimsg_create()
  * @see iotcon_notify_list_of_observers()
  */
 int iotcon_resource_notify_all(iotcon_resource_h resource);
 
 /**
- * @brief Specifies the type of function passed to iotcon_get(), iotcon_put(), iotcon_post()
+ * @brief Specifies the type of function passed to iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post()
  * @details The @a response_result could be one of #iotcon_response_result_e.
  *
  * @since_tizen 3.0
@@ -924,18 +927,21 @@ int iotcon_resource_notify_all(iotcon_resource_h resource);
  * @param[in] response_result The response result code
  * @param[in] user_data The user data to pass to the function
  *
- * @pre The callback must be registered using iotcon_get(), iotcon_put(), iotcon_post()
+ * @pre The callback must be registered using iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post()
  *
- * @see iotcon_get()
- * @see iotcon_put()
- * @see iotcon_post()
+ * @see iotcon_remote_resource_get()
+ * @see iotcon_remote_resource_put()
+ * @see iotcon_remote_resource_post()
  */
-typedef void (*iotcon_on_cru_cb)(iotcon_client_h resource, iotcon_representation_h repr,
-               iotcon_options_h options, int response_result, void *user_data);
+typedef void (*iotcon_remote_resource_cru_cb)(iotcon_remote_resource_h resource,
+               iotcon_representation_h repr,
+               iotcon_options_h options,
+               int response_result,
+               void *user_data);
 
 /**
  * @brief Gets the attributes of a resource.
- * @details When server sends response on get request, iotcon_on_cru_cb() will be called.
+ * @details When server sends response on get request, iotcon_remote_resource_cru_cb() will be called.
  *
  * @since_tizen 3.0
  * @privlevel public
@@ -953,18 +959,18 @@ typedef void (*iotcon_on_cru_cb)(iotcon_client_h resource, iotcon_representation
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @post When the client receive get response, iotcon_on_cru_cb() will be called.
+ * @post When the client receive get response, iotcon_remote_resource_cru_cb() will be called.
  *
- * @see iotcon_on_cru_cb()
- * @see iotcon_put()
- * @see iotcon_post()
+ * @see iotcon_remote_resource_cru_cb()
+ * @see iotcon_remote_resource_put()
+ * @see iotcon_remote_resource_post()
  */
-int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
-               iotcon_on_cru_cb cb, void *user_data);
+int iotcon_remote_resource_get(iotcon_remote_resource_h resource, iotcon_query_h query,
+               iotcon_remote_resource_cru_cb cb, void *user_data);
 
 /**
  * @brief Sets the representation of a resource (via PUT)
- * @details When server sends response on put request, iotcon_on_cru_cb() will be called.
+ * @details When server sends response on put request, iotcon_remote_resource_cru_cb() will be called.
  *
  * @since_tizen 3.0
  * @privlevel public
@@ -983,18 +989,21 @@ int iotcon_get(iotcon_client_h resource, iotcon_query_h query,
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @post When the client receive put response, iotcon_on_cru_cb() will be called.
+ * @post When the client receive put response, iotcon_remote_resource_cru_cb() will be called.
  *
- * @see iotcon_on_cru_cb()
- * @see iotcon_get()
- * @see iotcon_post()
+ * @see iotcon_remote_resource_cru_cb()
+ * @see iotcon_remote_resource_get()
+ * @see iotcon_remote_resource_post()
  */
-int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr,
-               iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data);
+int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
+               iotcon_representation_h repr,
+               iotcon_query_h query,
+               iotcon_remote_resource_cru_cb cb,
+               void *user_data);
 
 /**
  * @brief Posts on a resource
- * @details When server sends response on post request, iotcon_on_cru_cb() will be called.
+ * @details When server sends response on post request, iotcon_remote_resource_cru_cb() will be called.
  *
  * @since_tizen 3.0
  * @privlevel public
@@ -1013,17 +1022,20 @@ int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr,
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @post When the client receive post response, iotcon_on_cru_cb() will be called.
+ * @post When the client receive post response, iotcon_remote_resource_cru_cb() will be called.
  *
- * @see iotcon_on_cru_cb()
- * @see iotcon_get()
- * @see iotcon_put()
+ * @see iotcon_remote_resource_cru_cb()
+ * @see iotcon_remote_resource_get()
+ * @see iotcon_remote_resource_put()
  */
-int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr,
-               iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data);
+int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
+               iotcon_representation_h repr,
+               iotcon_query_h query,
+               iotcon_remote_resource_cru_cb cb,
+               void *user_data);
 
 /**
- * @brief Specifies the type of function passed to iotcon_delete()
+ * @brief Specifies the type of function passed to iotcon_remote_resource_delete()
  * @details The @a response_result could be one of #iotcon_response_result_e.
  *
  * @since_tizen 3.0
@@ -1033,16 +1045,18 @@ int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr,
  * @param[in] response_result The response result code
  * @param[in] user_data The user data to pass to the function
  *
- * @pre The callback must be registered using iotcon_delete()
+ * @pre The callback must be registered using iotcon_remote_resource_delete()
  *
- * @see iotcon_delete()
+ * @see iotcon_remote_resource_delete()
  */
-typedef void (*iotcon_on_delete_cb)(iotcon_client_h resource, iotcon_options_h options,
-               int response_result, void *user_data);
+typedef void (*iotcon_remote_resource_delete_cb)(iotcon_remote_resource_h resource,
+               iotcon_options_h options,
+               int response_result,
+               void *user_data);
 
 /**
  * @brief Deletes a resource.
- * @details When server sends response on delete request, iotcon_on_delete_cb() will be called.
+ * @details When server sends response on delete request, iotcon_remote_resource_delete_cb() will be called.
  *
  * @since_tizen 3.0
  * @privlevel public
@@ -1059,12 +1073,12 @@ typedef void (*iotcon_on_delete_cb)(iotcon_client_h resource, iotcon_options_h o
  * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
  * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
  *
- * @post When the client receive delete response, iotcon_on_delete_cb() will be called.
+ * @post When the client receive delete response, iotcon_remote_resource_delete_cb() will be called.
  *
- * @see iotcon_on_delete_cb()
+ * @see iotcon_remote_resource_delete_cb()
  */
-int iotcon_delete(iotcon_client_h resource, iotcon_on_delete_cb cb, void *user_data);
-
+int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
+               iotcon_remote_resource_delete_cb cb, void *user_data);
 
 /**
  * @}
index bab0a08ab78fd2a80852c14cac3fd5c42652f820..c06c3e238feec65ff153e46adb6aaa846663a5cb 100644 (file)
 #include <iotcon.h>
 #include "test.h"
 
-static char *door_resource_sid;
-static GList *resource_sid_list;
+static char *door_resource_device_id;
+static GList *device_id_list;
 
 static const char* const door_uri_path = "/a/door";
 
-static void _on_observe(iotcon_client_h resource,
+static void _on_observe(iotcon_remote_resource_h resource,
                iotcon_representation_h recv_repr,
                iotcon_options_h header_options,
                int response_result,
@@ -38,14 +38,14 @@ static void _on_observe(iotcon_client_h resource,
        i++;
 
        if (2 == i)
-               iotcon_observer_stop(resource);
+               iotcon_remote_resource_observer_stop(resource);
 }
 
-static void _on_delete(iotcon_client_h resource, iotcon_options_h header_options,
+static void _on_delete(iotcon_remote_resource_h resource, iotcon_options_h header_options,
                int response_result, void *user_data)
 {
        int ret;
-       iotcon_client_h door_resource = user_data;
+       iotcon_remote_resource_h door_resource = user_data;
 
        RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
                        && IOTCON_RESPONSE_RESULT_RESOURCE_DELETED != response_result,
@@ -54,22 +54,22 @@ static void _on_delete(iotcon_client_h resource, iotcon_options_h header_options
 
        /* delete callback operations */
 
-       ret = iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe,
-                       NULL);
+       ret = iotcon_remote_resource_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL,
+                       _on_observe, NULL);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("iotcon_observer_start() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_observer_start() Fail(%d)", ret);
 
-       iotcon_client_destroy(door_resource);
+       iotcon_remote_resource_destroy(door_resource);
 }
 
-static void _on_post(iotcon_client_h resource, iotcon_representation_h recv_repr,
+static void _on_post(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr,
                iotcon_options_h header_options, int response_result, void *user_data)
 {
        int ret, ifaces = 0;
        iotcon_state_h recv_state;
        char *host, *created_uri_path;
        iotcon_resource_types_h types = NULL;
-       iotcon_client_h new_door_resource, door_resource;
+       iotcon_remote_resource_h new_door_resource, door_resource;
 
        RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
                        && IOTCON_RESPONSE_RESULT_RESOURCE_CREATED != response_result,
@@ -89,50 +89,50 @@ static void _on_post(iotcon_client_h resource, iotcon_representation_h recv_repr
        }
        DBG("New resource created : %s", created_uri_path);
 
-       ret = iotcon_client_get_host(resource, &host);
+       ret = iotcon_remote_resource_get_host(resource, &host);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_host() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_host() Fail(%d)", ret);
                return;
        }
 
-       ret = iotcon_client_get_types(resource, &types);
+       ret = iotcon_remote_resource_get_types(resource, &types);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_types() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
                return;
        }
 
-       ret = iotcon_client_get_interfaces(resource, &ifaces);
+       ret = iotcon_remote_resource_get_interfaces(resource, &ifaces);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_ifaces() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
                return;
        }
 
-       ret = iotcon_client_create(host, created_uri_path, true, types, ifaces,
+       ret = iotcon_remote_resource_create(host, created_uri_path, true, types, ifaces,
                        &new_door_resource);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_create() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_create() Fail(%d)", ret);
                return;
        }
 
-       ret = iotcon_client_ref(resource, &door_resource);
+       ret = iotcon_remote_resource_ref(resource, &door_resource);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_ref() Fail(%d)", ret);
-               iotcon_client_destroy(new_door_resource);
+               ERR("iotcon_remote_resource_ref() Fail(%d)", ret);
+               iotcon_remote_resource_destroy(new_door_resource);
                return;
        }
 
-       ret = iotcon_delete(new_door_resource, _on_delete, door_resource);
+       ret = iotcon_remote_resource_delete(new_door_resource, _on_delete, door_resource);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_delete() Fail(%d)", ret);
-               iotcon_client_destroy(door_resource);
-               iotcon_client_destroy(new_door_resource);
+               ERR("iotcon_remote_resource_delete() Fail(%d)", ret);
+               iotcon_remote_resource_destroy(door_resource);
+               iotcon_remote_resource_destroy(new_door_resource);
                return;
        }
 
-       iotcon_client_destroy(new_door_resource);
+       iotcon_remote_resource_destroy(new_door_resource);
 }
 
-static void _on_put(iotcon_client_h resource, iotcon_representation_h recv_repr,
+static void _on_put(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr,
                iotcon_options_h header_options, int response_result, void *user_data)
 {
        int ret;
@@ -149,14 +149,14 @@ static void _on_put(iotcon_client_h resource, iotcon_representation_h recv_repr,
        }
 
        /* send POST request */
-       ret = iotcon_post(resource, send_repr, NULL, _on_post, NULL);
+       ret = iotcon_remote_resource_post(resource, send_repr, NULL, _on_post, NULL);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("iotcon_post() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_post() Fail(%d)", ret);
 
        iotcon_representation_destroy(send_repr);
 }
 
-static void _on_get(iotcon_client_h resource, iotcon_representation_h recv_repr,
+static void _on_get(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr,
                iotcon_options_h header_options, int response_result, void *user_data)
 {
        int ret;
@@ -213,9 +213,9 @@ static void _on_get(iotcon_client_h resource, iotcon_representation_h recv_repr,
        iotcon_state_destroy(send_state);
 
        /* send PUT request */
-       ret = iotcon_put(resource, send_repr, NULL, _on_put, NULL);
+       ret = iotcon_remote_resource_put(resource, send_repr, NULL, _on_put, NULL);
        if (IOTCON_ERROR_NONE != ret)
-               ERR("iotcon_put() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_put() Fail(%d)", ret);
 
        iotcon_representation_destroy(send_repr);
 }
@@ -238,19 +238,18 @@ static void _presence_handler(int result, unsigned int nonce,
        INFO("host_address : %s", host_address);
 }
 
-static int _sid_compare(const void *a, const void *b)
+static int _device_id_compare(const void *a, const void *b)
 {
        return strcmp(a, b);
 }
 
-static void _found_resource(iotcon_client_h resource, void *user_data)
+static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
 {
-       int ret;
        GList *node;
-       char *resource_sid;
        char *resource_host;
        char *resource_uri_path;
-       int resource_interfaces;
+       char *resource_device_id;
+       int ret, resource_interfaces;
        iotcon_presence_h presence_handle;
        iotcon_resource_types_h resource_types;
 
@@ -260,52 +259,52 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
        INFO("===== resource found =====");
 
        /* get the resource URI */
-       ret = iotcon_client_get_uri_path(resource, &resource_uri_path);
+       ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_uri_path() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret);
                return;
        }
 
-       /* get the resource unique id.
+       /* get the device unique id.
         * this is unique per-server independent on how it was discovered. */
-       ret = iotcon_client_get_device_id(resource, &resource_sid);
+       ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_device_id() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret);
                return;
        }
-       DBG("[%s] resource server id : %s", resource_uri_path, resource_sid);
+       DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
 
-       node = g_list_find_custom(resource_sid_list, resource_sid, _sid_compare);
+       node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
 
        if (node && TEST_STR_EQUAL == strcmp(door_uri_path, resource_uri_path)) {
                DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
                return;
        }
 
-       door_resource_sid = strdup(resource_sid);
-       if (NULL == door_resource_sid) {
-               ERR("strdup(door_resource_sid) Fail");
+       door_resource_device_id = strdup(resource_device_id);
+       if (NULL == door_resource_device_id) {
+               ERR("strdup(door_resource_device_id) Fail");
                return;
        }
 
-       resource_sid_list = g_list_append(resource_sid_list, door_resource_sid);
+       device_id_list = g_list_append(device_id_list, door_resource_device_id);
 
        /* get the resource host address */
-       ret = iotcon_client_get_host(resource, &resource_host);
+       ret = iotcon_remote_resource_get_host(resource, &resource_host);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_host() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-               free(door_resource_sid);
+               ERR("iotcon_remote_resource_get_host() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+               free(door_resource_device_id);
                return;
        }
        DBG("[%s] resource host : %s", resource_uri_path, resource_host);
 
        /* get the resource interfaces */
-       ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
+       ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_interfaces() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-               free(door_resource_sid);
+               ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+               free(door_resource_device_id);
                return;
        }
        if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
@@ -318,11 +317,11 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
                DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
 
        /* get the resource types */
-       ret = iotcon_client_get_types(resource, &resource_types);
+       ret = iotcon_remote_resource_get_types(resource, &resource_types);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_types() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-               free(door_resource_sid);
+               ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+               free(door_resource_device_id);
                return;
        }
 
@@ -330,8 +329,8 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
                        resource_uri_path);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-               free(door_resource_sid);
+               device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+               free(door_resource_device_id);
                return;
        }
 
@@ -344,8 +343,8 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
                ret = iotcon_query_create(&query);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("iotcon_query_create() Fail(%d)", ret);
-                       resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-                       free(door_resource_sid);
+                       device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+                       free(door_resource_device_id);
                        return;
                }
 
@@ -353,21 +352,21 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("iotcon_query_insert() Fail(%d)", ret);
                        iotcon_query_destroy(query);
-                       resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-                       free(door_resource_sid);
+                       device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+                       free(door_resource_device_id);
                        return;
                }
 
                /* send GET Request */
-               ret = iotcon_get(resource, query, _on_get, NULL);
+               ret = iotcon_remote_resource_get(resource, query, _on_get, NULL);
                if (IOTCON_ERROR_NONE != ret)
-                       ERR("iotcon_get() Fail(%d)", ret);
+                       ERR("iotcon_remote_resource_get() Fail(%d)", ret);
 
                iotcon_query_destroy(query);
        }
 
-       resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
-       free(door_resource_sid);
+       device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+       free(door_resource_device_id);
 }
 
 int main(int argc, char **argv)
@@ -397,7 +396,7 @@ int main(int argc, char **argv)
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
 
-       g_list_free_full(resource_sid_list, free);
+       g_list_free_full(device_id_list, free);
 
        /* iotcon close */
        iotcon_close();
index 3b35b16a72d8049effa8155a0791b16e7526768b..0a37ee06eff579a0e0916dff4caf766bf22dd2fb 100644 (file)
@@ -107,11 +107,11 @@ static iotcon_resource_h _create_door_resource(char *uri_path, char *type, int i
        }
 
        /* register door resource */
-       ret = iotcon_register_resource(uri_path, resource_types, ifaces, properties,
+       ret = iotcon_resource_create(uri_path, resource_types, ifaces, properties,
                        _request_handler, user_data, &handle);
        if (IOTCON_ERROR_NONE != ret) {
                iotcon_resource_types_destroy(resource_types);
-               ERR("iotcon_register_resource() Fail");
+               ERR("iotcon_resource_create() Fail");
                return NULL;
        }
 
@@ -393,7 +393,7 @@ static void _request_handler_delete(iotcon_resource_h resource,
        iotcon_response_result_e result = IOTCON_RESPONSE_RESULT_OK;
        INFO("DELETE request");
 
-       ret = iotcon_unregister_resource(resource);
+       ret = iotcon_resource_destroy(resource);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_unregiser_resource() Fail(%d)", ret);
                return;
@@ -557,7 +557,7 @@ int main(int argc, char **argv)
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
 
-       iotcon_unregister_resource(my_door.handle);
+       iotcon_resource_destroy(my_door.handle);
 
        _free_door_resource(&my_door);
 
index 198894ac263e11262ed419312432f972283dccf7..4616a7a798da632506908bd2888451ebf1c6846a 100644 (file)
@@ -19,8 +19,8 @@
 #include <iotcon.h>
 #include "test.h"
 
-static char *room_resource_sid;
-static GList *resource_sid_list;
+static char *room_resource_device_id;
+static GList *device_id_list;
 
 static const char* const room_uri_path = "/a/room";
 
@@ -157,14 +157,20 @@ static void _on_get(iotcon_representation_h recv_repr, int response_result)
        }
 }
 
-static void _on_get_2nd(iotcon_client_h resource, iotcon_representation_h recv_repr,
-               iotcon_options_h header_options, int response_result, void *user_data)
+static void _on_get_2nd(iotcon_remote_resource_h resource,
+               iotcon_representation_h recv_repr,
+               iotcon_options_h header_options,
+               int response_result,
+               void *user_data)
 {
        _on_get(recv_repr, response_result);
 }
 
-static void _on_get_1st(iotcon_client_h resource, iotcon_representation_h recv_repr,
-               iotcon_options_h header_options, int response_result, void *user_data)
+static void _on_get_1st(iotcon_remote_resource_h resource,
+               iotcon_representation_h recv_repr,
+               iotcon_options_h header_options,
+               int response_result,
+               void *user_data)
 {
        int ret;
        iotcon_query_h query_params;
@@ -185,9 +191,9 @@ static void _on_get_1st(iotcon_client_h resource, iotcon_representation_h recv_r
        }
 
        /* send GET request again with BATCH interface */
-       ret = iotcon_get(resource, query_params, _on_get_2nd, NULL);
+       ret = iotcon_remote_resource_get(resource, query_params, _on_get_2nd, NULL);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_get() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get() Fail(%d)", ret);
                iotcon_query_destroy(query_params);
                return;
        }
@@ -204,19 +210,18 @@ static int _get_res_type_fn(const char *string, void *user_data)
        return IOTCON_FUNC_CONTINUE;
 }
 
-static int _sid_compare(const void *a, const void *b)
+static int _device_id_compare(const void *a, const void *b)
 {
        return strcmp(a, b);
 }
 
-static void _found_resource(iotcon_client_h resource, void *user_data)
+static void _found_resource(iotcon_remote_resource_h resource, void *user_data)
 {
-       int ret;
        GList *node;
-       char *resource_sid;
        char *resource_host;
        char *resource_uri_path;
-       int resource_interfaces;
+       char *resource_device_id;
+       int ret, resource_interfaces;
        iotcon_resource_types_h resource_types;
 
        if (NULL == resource)
@@ -225,51 +230,51 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
        INFO("===== resource found =====");
 
        /* get the resource URI */
-       ret = iotcon_client_get_uri_path(resource, &resource_uri_path);
+       ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_uri_path() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret);
                return;
        }
 
-       /* get the resource server id */
-       ret = iotcon_client_get_device_id(resource, &resource_sid);
+       /* get the resource device id */
+       ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_device_id() Fail(%d)", ret);
+               ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret);
                return;
        }
-       DBG("[%s] resource server id : %s", resource_uri_path, resource_sid);
+       DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
 
-       node = g_list_find_custom(resource_sid_list, resource_sid, _sid_compare);
+       node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
 
        if (node && TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
                DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
                return;
        }
 
-       room_resource_sid = strdup(resource_sid);
-       if (NULL == room_resource_sid) {
-               ERR("strdup(room_resource_sid) Fail");
+       room_resource_device_id = strdup(resource_device_id);
+       if (NULL == room_resource_device_id) {
+               ERR("strdup(room_resource_device_id) Fail");
                return;
        }
 
-       resource_sid_list = g_list_append(resource_sid_list, room_resource_sid);
+       device_id_list = g_list_append(device_id_list, room_resource_device_id);
 
        /* get the resource host address */
-       ret = iotcon_client_get_host(resource, &resource_host);
+       ret = iotcon_remote_resource_get_host(resource, &resource_host);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_host() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
-               free(room_resource_sid);
+               ERR("iotcon_remote_resource_get_host() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+               free(room_resource_device_id);
                return;
        }
        DBG("[%s] resource host : %s", resource_uri_path, resource_host);
 
        /* get the resource interfaces */
-       ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
+       ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_interfaces() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
-               free(room_resource_sid);
+               ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+               free(room_resource_device_id);
                return;
        }
        if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
@@ -282,31 +287,31 @@ static void _found_resource(iotcon_client_h resource, void *user_data)
                DBG("[%s] resource interface : GROUP_INTERFACE", resource_uri_path);
 
        /* get the resource types */
-       ret = iotcon_client_get_types(resource, &resource_types);
+       ret = iotcon_remote_resource_get_types(resource, &resource_types);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_client_get_types() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
-               free(room_resource_sid);
+               ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
+               device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+               free(room_resource_device_id);
                return;
        }
        ret = iotcon_resource_types_foreach(resource_types, _get_res_type_fn,
                        resource_uri_path);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
-               resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
-               free(room_resource_sid);
+               device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+               free(room_resource_device_id);
                return;
        }
 
        if (TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
                /* send GET request */
-               ret = iotcon_get(resource, NULL, _on_get_1st, NULL);
+               ret = iotcon_remote_resource_get(resource, NULL, _on_get_1st, NULL);
                if (IOTCON_ERROR_NONE != ret)
-                       ERR("iotcon_get() Fail(%d)", ret);
+                       ERR("iotcon_remote_resource_get() Fail(%d)", ret);
        }
 
-       resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
-       free(room_resource_sid);
+       device_id_list = g_list_remove(device_id_list, room_resource_device_id);
+       free(room_resource_device_id);
 }
 
 int main(int argc, char **argv)
@@ -336,7 +341,7 @@ int main(int argc, char **argv)
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
 
-       g_list_free_full(resource_sid_list, free);
+       g_list_free_full(device_id_list, free);
 
        /* iotcon close */
        iotcon_close();
index f7d6090cdb3d6aee1567028fbb8452b3a3aaa196..1f9d951082eeee6ee9f04da401fde619a77b1b35 100644 (file)
@@ -512,12 +512,12 @@ int main(int argc, char **argv)
                return -1;
        }
 
-       ret = iotcon_register_resource("/a/room", room_rtypes,
+       ret = iotcon_resource_create("/a/room", room_rtypes,
                        (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
                        (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _room_request_handler,
                        NULL, &room_handle);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_register_resource() Fail(%d)", ret);
+               ERR("iotcon_resource_create() Fail(%d)", ret);
                iotcon_resource_types_destroy(room_rtypes);
                iotcon_close();
                return -1;
@@ -528,7 +528,7 @@ int main(int argc, char **argv)
        ret = iotcon_resource_types_create(&light_rtypes);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_resource_types_create() Fail(%d)", ret);
-               iotcon_unregister_resource(room_handle);
+               iotcon_resource_destroy(room_handle);
                iotcon_close();
                return -1;
        }
@@ -536,19 +536,19 @@ int main(int argc, char **argv)
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_resource_types_insert(%s) Fail(%d)", "core.light", ret);
                iotcon_resource_types_destroy(light_rtypes);
-               iotcon_unregister_resource(room_handle);
+               iotcon_resource_destroy(room_handle);
                iotcon_close();
                return -1;
        }
 
-       ret = iotcon_register_resource("/a/light", light_rtypes,
+       ret = iotcon_resource_create("/a/light", light_rtypes,
                        (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
                        (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _light_request_handler,
                        NULL, &light_handle);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("iotcon_register_resource() Fail");
+               ERR("iotcon_resource_create() Fail");
                iotcon_resource_types_destroy(light_rtypes);
-               iotcon_unregister_resource(room_handle);
+               iotcon_resource_destroy(room_handle);
                iotcon_close();
                return -1;
        }
@@ -557,8 +557,8 @@ int main(int argc, char **argv)
        ret = iotcon_resource_bind_child_resource(room_handle, light_handle);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_resource_bind_child_resource() Fail");
-               iotcon_unregister_resource(light_handle);
-               iotcon_unregister_resource(room_handle);
+               iotcon_resource_destroy(light_handle);
+               iotcon_resource_destroy(room_handle);
                iotcon_close();
                return -1;
        }
@@ -566,8 +566,8 @@ int main(int argc, char **argv)
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
 
-       iotcon_unregister_resource(light_handle);
-       iotcon_unregister_resource(room_handle);
+       iotcon_resource_destroy(light_handle);
+       iotcon_resource_destroy(room_handle);
 
        /* iotcon close */
        iotcon_close();