Modify terms related to signal
[platform/core/iot/iotcon.git] / daemon / icd-ioty.c
index 668be65..1627704 100644 (file)
@@ -17,9 +17,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h> /* for uint8_t etc */
-#include <stdbool.h>
 #include <errno.h>
 #include <glib.h>
+#include <tizen_type.h>
 #include <system_info.h>
 #include <system_settings.h>
 
@@ -104,6 +104,33 @@ void icd_ioty_deinit(GThread *thread)
                ERR("OCStop() Fail(%d)", result);
 }
 
+static int _ioty_properties_to_oic_properties(int properties)
+{
+       int prop = OC_RES_PROP_NONE;
+
+       if (IOTCON_DISCOVERABLE & properties)
+               prop |= OC_DISCOVERABLE;
+
+       if (IOTCON_OBSERVABLE & properties)
+               prop |= OC_OBSERVABLE;
+
+       if (IOTCON_ACTIVE & properties)
+               prop |= OC_ACTIVE;
+
+       if (IOTCON_SLOW & properties)
+               prop |= OC_SLOW;
+
+       if (IOTCON_SECURE & properties)
+               prop |= OC_SECURE;
+
+       if (IOTCON_EXPLICIT_DISCOVERABLE & properties)
+               prop |= OC_EXPLICIT_DISCOVERABLE;
+
+       /* TODO: Secure option is not supported yet. */
+       properties = (properties & OC_SECURE)? (properties ^ OC_SECURE):properties;
+
+       return prop;
+}
 
 OCResourceHandle icd_ioty_register_resource(const char *uri_path,
                const char* const* res_types, int ifaces, int properties)
@@ -131,8 +158,7 @@ OCResourceHandle icd_ioty_register_resource(const char *uri_path,
                return NULL;
        }
 
-       /* Secure option is not supported yet. */
-       properties = (properties & OC_SECURE)? (properties ^ OC_SECURE):properties;
+       properties = _ioty_properties_to_oic_properties(properties);
 
        icd_ioty_csdk_lock();
        ret = OCCreateResource(&handle, res_types[0], res_iface, uri_path,
@@ -251,10 +277,9 @@ int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child)
        return IOTCON_ERROR_NONE;
 }
 
-
 int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers)
 {
-       int i, error_code, obs_length, msg_length;
+       int i, obs_length, msg_length;
        GVariant *repr_gvar;
        GVariantIter obs_iter, msg_iter;
        OCStackResult ret;
@@ -272,7 +297,7 @@ int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers)
        g_variant_iter_init(&msg_iter, msg);
        msg_length = g_variant_iter_n_children(&msg_iter);
        if (msg_length) {
-               g_variant_iter_loop(&msg_iter, "(iv)", &error_code, &repr_gvar);
+               g_variant_iter_loop(&msg_iter, "v", &repr_gvar);
                /* TODO : How to use error_code. */
                payload = icd_payload_representation_from_gvariant(repr_gvar);
        }
@@ -330,11 +355,10 @@ int icd_ioty_send_response(GVariant *resp)
        GVariantIter *options;
        OCStackResult ret;
        OCEntityHandlerResponse response = {0};
-       int result, error_code, options_size;
+       int result, options_size;
        int64_t request_handle, resource_handle;
 
-       g_variant_get(resp, "(ia(qs)ivxx)",
-                       &error_code,
+       g_variant_get(resp, "(a(qs)ivxx)",
                        &options,
                        &result,
                        &repr_gvar,
@@ -387,7 +411,7 @@ static void _ioty_free_signal_context(void *data)
 
 
 int icd_ioty_find_resource(const char *host_address, int conn_type,
-               const char *resource_type, unsigned int signum, const char *bus_name)
+               const char *resource_type, unsigned int signal_number, const char *bus_name)
 {
        int len;
        OCStackResult result;
@@ -417,7 +441,7 @@ int icd_ioty_find_resource(const char *host_address, int conn_type,
        }
 
        context->bus_name = ic_utils_strdup(bus_name);
-       context->signum = signum;
+       context->signal_number = signal_number;
 
        cbdata.context = context;
        cbdata.cb = icd_ioty_ocprocess_find_cb;
@@ -545,8 +569,12 @@ void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int re
 }
 
 
-static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *invocation,
-               GVariant *resource, GVariant *query, GVariant *repr)
+static gboolean _icd_ioty_crud(int type,
+               icDbus *object,
+               GDBusMethodInvocation *invocation,
+               GVariant *resource,
+               GVariant *query,
+               GVariant *repr)
 {
        bool is_secure;
        OCMethod rest_type;
@@ -691,8 +719,8 @@ gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
 }
 
 
-OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVariant *query,
-               unsigned int signal_number, const char *bus_name)
+OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type,
+               GVariant *query, unsigned int signal_number, const char *bus_name)
 {
        bool is_secure;
        OCMethod method;
@@ -731,7 +759,7 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVarian
                return NULL;
        }
        context->bus_name = ic_utils_strdup(bus_name);
-       context->signum = signal_number;
+       context->signal_number = signal_number;
 
        cbdata.context = context;
        cbdata.cb = icd_ioty_ocprocess_observe_cb;
@@ -854,7 +882,7 @@ int icd_ioty_get_info(int type, const char *host_address, int conn_type,
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
        context->bus_name = ic_utils_strdup(bus_name);
-       context->signum = signal_number;
+       context->signal_number = signal_number;
 
        cbdata.context = context;
        cbdata.cb = icd_ioty_ocprocess_info_cb;
@@ -1059,7 +1087,7 @@ int icd_ioty_set_tizen_info()
                        ICD_IOTY_TIZEN_INFO_URI,
                        icd_ioty_ocprocess_tizen_info_handler,
                        NULL,
-                       OC_RES_PROP_NONE);
+                       OC_EXPLICIT_DISCOVERABLE);
        icd_ioty_csdk_unlock();
        if (OC_STACK_OK != ret) {
                ERR("OCCreateResource() Fail(%d)", ret);
@@ -1159,7 +1187,7 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type,
                return NULL;
        }
        context->bus_name = ic_utils_strdup(bus_name);
-       context->signum = signal_number;
+       context->signal_number = signal_number;
 
        cbdata.context = context;
        cbdata.cb = icd_ioty_ocprocess_presence_cb;
@@ -1167,12 +1195,8 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type,
 
        oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
 
-       /* In case of IPV4 or IPV6, connectivity type is CT_ADAPTER_IP in iotivity 0.9.2 */
-       if (CT_IP_USE_V4 == oic_conn_type && CT_IP_USE_V6 == oic_conn_type)
-               oic_conn_type = CT_ADAPTER_IP;
-
        icd_ioty_csdk_lock();
-       result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, CT_ADAPTER_IP,
+       result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, oic_conn_type,
                        OC_LOW_QOS, &cbdata, NULL, 0);
        icd_ioty_csdk_unlock();