Convert enumeration between iotcon and iotivity
authorsung.goo.kim <sung.goo.kim@samsung.com>
Thu, 5 Nov 2015 02:38:07 +0000 (11:38 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 10 Nov 2015 10:12:51 +0000 (19:12 +0900)
Change-Id: Ibc07fd4707eafeb4b5431ca19be5b8fd743dfd7b

daemon/icd-ioty-ocprocess.c
daemon/icd-ioty.c
lib/include/iotcon-constant.h

index 1eca6b5fa6fd0b333534d0f6deb4b82000188d60..1ee728dc963772dcea8be0b9bd81b86d0f3de4eb 100644 (file)
@@ -210,11 +210,29 @@ static inline GVariantBuilder* _ocprocess_parse_header_options(
        return options;
 }
 
+static int _ioty_oic_action_to_ioty_action(int oic_action)
+{
+       int action;
+
+       switch (oic_action) {
+       case OC_OBSERVE_REGISTER:
+               action = IOTCON_OBSERVE_REGISTER;
+               break;
+       case OC_OBSERVE_DEREGISTER:
+               action = IOTCON_OBSERVE_DEREGISTER;
+               break;
+       case OC_OBSERVE_NO_OPTION:
+       default:
+               ERR("Invalid action (%d)", oic_action);
+               action = IOTCON_OBSERVE_NO_OPTION;
+       }
+       return action;
+}
 
 static int _worker_req_handler(void *context)
 {
        GVariant *value;
-       int ret, conn_type;
+       int ret, conn_type, action;
        struct icd_req_context *ctx = context;
        GVariantBuilder payload_builder;
        char addr[PATH_MAX] = {0};
@@ -231,13 +249,15 @@ static int _worker_req_handler(void *context)
        conn_type = icd_ioty_transport_flag_to_conn_type(ctx->dev_addr->adapter,
                        ctx->dev_addr->flags);
 
+       action = _ioty_oic_action_to_ioty_action(ctx->observe_action);
+
        value = g_variant_new("(siia(qs)a(ss)iiavxx)",
                        addr,
                        conn_type,
                        ctx->types,
                        ctx->options,
                        ctx->query,
-                       ctx->observe_action,
+                       action,
                        ctx->observer_id,
                        &payload_builder,
                        ICD_POINTER_TO_INT64(ctx->request_h),
index 513401ed3c6cb6bab43c6643cc72a8119ab973d3..da050e71f9fc0d9ea38f8cb507c6cca9ac0d25c1 100644 (file)
@@ -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,
@@ -1057,7 +1083,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);
index 275d8f56d4bcf07650f85e9efc233e54ec9effd7..ba225bcaa96b569dba2097ef5ad9807e6fd9fc24 100644 (file)
@@ -293,6 +293,7 @@ typedef enum {
        IOTCON_ACTIVE = (1 << 2), /**< Indicates resource initialized and activated */
        IOTCON_SLOW = (1 << 3), /**< Indicates resource which takes some delay to respond */
        IOTCON_SECURE = (1 << 4), /**< Indicates secure resource */
+       IOTCON_EXPLICIT_DISCOVERABLE = (1 << 5), /**< When this bit is set, the resource is allowed to be discovered only if discovery request contains an explicit querystring. */
 } iotcon_resource_property_e;
 
 /**