//
#include "ITs-iotcon-common.h"
-#include "assert.h"
-
-#define ITC_LOG_TAG "NativeTCT"
-#include <dlog.h>
-
-#define ITC_LOG_RED "\033[0;31m"
-#define ITC_LOG_GREEN "\033[0;32m"
-#define ITC_LOG_END "\033[0;m"
-
-#define ITC_INFO(fmt, arg...) \
- do { \
- dlog_print(DLOG_INFO, ITC_LOG_TAG, ITC_LOG_GREEN "[%s][Line : %d] " fmt ITC_LOG_END, __FILE__, __LINE__, ##arg); \
- } while (0)
-
-#define FN_CALL \
- do { \
- dlog_print(DLOG_INFO, ITC_LOG_TAG, ITC_LOG_GREEN "[%s][Line : %d] %s >>>>>>> called " ITC_LOG_END, __FILE__, __LINE__, __FUNCTION__); \
- } while (0)
-
-#define ITC_ERR(fmt, arg...) \
- do { \
- dlog_print(DLOG_ERROR, ITC_LOG_TAG, ITC_LOG_RED "[%s][Line : %d] " fmt ITC_LOG_END, __FILE__, __LINE__, ##arg); \
- } while (0)
-
-#define ITC_ASSERT_EQ(var, ref) \
- if (var != ref) { \
- dlog_print(DLOG_ERROR, ITC_LOG_TAG, \
- ITC_LOG_RED "(%s == 0x%x) and (%s == 0x%x) are not equal" ITC_LOG_END, \
- #var, (int)var, #ref, (int)ref); \
- assert_eq(var, ref); \
- } while (0)
-
#define LIGHT_RESOURCE_TYPE "core.light"
#define LIGHT_RESOURCE_TYPE2 "core.light2"
#define LIGHT_RESOURCE_TYPE3 "core.light3"
#define LED_RESOURCE_URI "/a/led"
enum {
- RESOURCE_BIND_CHILD_RESOURCE_P,
- RESOURCE_BIND_CHILD_RESOURCE_N,
- RESOURCE_BIND_INTERFACE_P,
- RESOURCE_BIND_INTERFACE_N,
- RESOURCE_BIND_TYPE_P,
- RESOURCE_BIND_TYPE_N,
- RESOURCE_CREATE_P,
- RESOURCE_CREATE_N,
- RESOURCE_DESTROY_P,
- RESOURCE_DESTROY_N,
- RESOURCE_GET_INTERFACES_P,
- RESOURCE_GET_INTERFACES_N,
- RESOURCE_GET_NTH_CHILD_P,
- RESOURCE_GET_NTH_CHILD_N,
- RESOURCE_GET_NUMBER_OF_CHILDREN_P,
- RESOURCE_GET_NUMBER_OF_CHILDREN_N,
- RESOURCE_GET_PROPERTIES_P,
- RESOURCE_GET_PROPERTIES_N,
- RESOURCE_GET_TYPES_P,
- RESOURCE_GET_TYPES_N,
- RESOURCE_GET_URI_PATH_P,
- RESOURCE_GET_URI_PATH_N,
- RESOURCE_NOTIFY_P,
- RESOURCE_NOTIFY_N,
- RESOURCE_SET_REQUEST_HANDLER_P,
- RESOURCE_SET_REQUEST_HANDLER_N,
- RESOURCE_UNBIND_CHILD_RESOURCE_P,
- RESOURCE_UNBIND_CHILD_RESOURCE_N,
+ RESOURCE_BIND_CHILD_RESOURCE,
+ RESOURCE_BIND_INTERFACE,
+ RESOURCE_BIND_TYPE,
+ RESOURCE_CREATE,
+ RESOURCE_DESTROY,
+ RESOURCE_GET_INTERFACES,
+ RESOURCE_GET_NTH_CHILD,
+ RESOURCE_GET_NUMBER_OF_CHILDREN,
+ RESOURCE_GET_PROPERTIES,
+ RESOURCE_GET_TYPES,
+ RESOURCE_GET_URI_PATH,
+ RESOURCE_NOTIFY,
+ RESOURCE_SET_REQUEST_HANDLER,
+ RESOURCE_UNBIND_CHILD_RESOURCE,
};
-static bool g_feature;
bool g_check = false;
+static bool g_bRequestHandlerCB = false;
+static bool g_bResult;
+static iotcon_resource_h g_hLightResource;
+static iotcon_remote_resource_h g_hRemoteResource;
-int itc_create_resource_types(const char *type, iotcon_resource_types_h *types_h)
-{
- int nRet;
- iotcon_resource_types_h types;
-
- nRet = iotcon_resource_types_create(&types);
- if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_resource_types_create() Fail(%d)", nRet);
- return nRet;
- }
-
- nRet = iotcon_resource_types_add(types, type);
- if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_resource_types_add() Fail(%d)", nRet);
- iotcon_resource_types_destroy(types);
- return nRet;
- }
-
- *types_h = types;
- return 0;
-}
-
-int itc_create_resource_interfaces(iotcon_resource_interfaces_h *ifaces_h)
-{
- int nRet;
- iotcon_resource_interfaces_h ifaces;
-
- nRet = iotcon_resource_interfaces_create(&ifaces);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("iotcon_resource_interfaces_create() Fail(%d)", nRet);
- return nRet;
- }
-
- nRet = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("iotcon_resource_interfaces_add() Fail(%d)", nRet);
- iotcon_resource_interfaces_destroy(ifaces);
- return nRet;
- }
-
- nRet = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_BATCH);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("iotcon_resource_interfaces_add() Fail(%d)", nRet);
- iotcon_resource_interfaces_destroy(ifaces);
- return nRet;
- }
-
- *ifaces_h = ifaces;
-
- return 0;
-}
-
-static void _Iotcon_request_handler(iotcon_resource_h resource,
- iotcon_request_h request, void *user_data)
-{
- g_check = true;
- FN_CALL;
-}
-
-int itc_create_resource(const char *resource_type, const char *resource_uri, iotcon_resource_h *resource_handle)
-{
- int nRet;
- int nIotconTimeoutId = 0;
- iotcon_resource_h resource = NULL;
- iotcon_resource_types_h types;
- iotcon_resource_interfaces_h ifaces;
-
- nRet = itc_create_resource_types(resource_type, &types);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("itc_create_resource_types() Fail(%d)", nRet);
- return nRet;
- }
-
- nRet = itc_create_resource_interfaces(&ifaces);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("itc_create_resource_interfaces() Fail(%d)", nRet);
- iotcon_resource_types_destroy(types);
- return nRet;
- }
-
- nRet = iotcon_resource_create(resource_uri,
- types,
- ifaces,
- (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE),
- _Iotcon_request_handler,
- NULL,
- &resource);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("iotcon_resource_create() Fail(%d)", nRet);
- iotcon_resource_interfaces_destroy(ifaces);
- iotcon_resource_types_destroy(types);
- return nRet;
- }
- RUN_POLLING_LOOP;
-
- iotcon_resource_interfaces_destroy(ifaces);
- iotcon_resource_types_destroy(types);
-
- *resource_handle = resource;
- return 0;
-}
-
-int itc_create_state(iotcon_state_h *state_h)
+/**
+* @function CreateState
+* @description Called to create iotcon state handle
+* @parameter iotcon_state_h : The state handle
+* @return int
+*/
+static int CreateState(iotcon_state_h *state_h)
{
int nRet;
iotcon_state_h state, val_state;
nRet = iotcon_state_create(&state);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_create() Fail(%d)", nRet);
return nRet;
}
nRet = iotcon_state_add_int(state, "int", 1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_int() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_int() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_state_add_bool(state, "bool", true);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_bool() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_bool() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_state_add_double(state, "double", 1.1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_double() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_double() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_state_add_null(state, "null");
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_null() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_null() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_state_add_str(state, "str", "string");
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_str() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_str() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_state_add_byte_str(state, "bytestr", byte_str, 3);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_byte_str() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_byte_str() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
/* state */
nRet = iotcon_state_create(&val_state);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_create() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_state_add_int(val_state, "val_state", 10);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_int() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_int() Fail(%d)", nRet);
iotcon_state_destroy(val_state);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_state_add_state(state, "state", val_state);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_state() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_state() Fail(%d)", nRet);
iotcon_state_destroy(val_state);
iotcon_state_destroy(state);
return nRet;
/* state list */
nRet = iotcon_list_create(IOTCON_TYPE_STATE, &list6);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_state_destroy(val_state);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_list_add_state(list6, val_state, -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_state() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_state() Fail(%d)", nRet);
iotcon_list_destroy(list6);
iotcon_state_destroy(val_state);
iotcon_state_destroy(state);
nRet = iotcon_state_add_list(state, "state_list", list6);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list6);
iotcon_state_destroy(state);
return nRet;
/* int list */
nRet = iotcon_list_create(IOTCON_TYPE_INT, &list1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_list_add_int(list1, 1, -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_int() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_int() Fail(%d)", nRet);
iotcon_list_destroy(list1);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_state_add_list(state, "int_list", list1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list1);
iotcon_state_destroy(state);
return nRet;
/* boolean list */
nRet = iotcon_list_create(IOTCON_TYPE_BOOL, &list2);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_list_add_bool(list2, true, -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_bool() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_bool() Fail(%d)", nRet);
iotcon_list_destroy(list2);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_state_add_list(state, "bool_list", list2);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list2);
iotcon_state_destroy(state);
return nRet;
/* string list */
nRet = iotcon_list_create(IOTCON_TYPE_STR, &list3);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_list_add_str(list3, "string", -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_str() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_str() Fail(%d)", nRet);
iotcon_list_destroy(list3);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_state_add_list(state, "str_list", list3);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list3);
iotcon_state_destroy(state);
return nRet;
/* byte string list */
nRet = iotcon_list_create(IOTCON_TYPE_BYTE_STR, &list4);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_list_add_byte_str(list4, byte_str, 3, -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_byte_str() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_byte_str() Fail(%d)", nRet);
iotcon_list_destroy(list4);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_state_add_list(state, "byte_str_list", list4);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list4);
iotcon_state_destroy(state);
return nRet;
/* list list */
nRet = iotcon_list_create(IOTCON_TYPE_LIST, &list5);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_list_destroy(list4);
iotcon_state_destroy(state);
return nRet;
nRet = iotcon_list_add_list(list5, list4, -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list5);
iotcon_list_destroy(list4);
iotcon_state_destroy(state);
nRet = iotcon_state_add_list(state, "list_list", list5);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list5);
iotcon_state_destroy(state);
return nRet;
/* double list */
nRet = iotcon_list_create(IOTCON_TYPE_DOUBLE, &list7);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_create() Fail(%d)", nRet);
iotcon_state_destroy(state);
return nRet;
}
nRet = iotcon_list_add_double(list7, 1.1, -1);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_list_add_double() Fail(%d)", nRet);
+ FPRINTF("iotcon_list_add_double() Fail(%d)", nRet);
iotcon_list_destroy(list7);
iotcon_state_destroy(state);
return nRet;
nRet =iotcon_state_add_list(state, "double_list", list7);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_state_add_list() Fail(%d)", nRet);
+ FPRINTF("iotcon_state_add_list() Fail(%d)", nRet);
iotcon_list_destroy(list7);
iotcon_state_destroy(state);
return nRet;
return 0;
}
-int itc_create_representation(iotcon_representation_h *representation)
+/**
+* @function CreateResourceTypes
+* @description Called to create iotcon resource types handle
+* @parameter iotcon_resource_types_h : The resource types handle
+* @return int
+*/
+static int CreateResourceTypes(const char *type, iotcon_resource_types_h *types_h)
+{
+ int nRet;
+ iotcon_resource_types_h types;
+
+ nRet = iotcon_resource_types_create(&types);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_types_create() Fail(%d)", nRet);
+ return nRet;
+ }
+
+ nRet = iotcon_resource_types_add(types, type);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_types_add() Fail(%d)", nRet);
+ iotcon_resource_types_destroy(types);
+ return nRet;
+ }
+
+ *types_h = types;
+ return 0;
+}
+
+/**
+* @function CreateResourceInterfaces
+* @description Called to create iotcon interfaces handle
+* @parameter iotcon_resource_interfaces_h : The interfaces handle
+* @return int
+*/
+static int CreateResourceInterfaces(iotcon_resource_interfaces_h *ifaces_h)
+{
+ int nRet;
+ iotcon_resource_interfaces_h ifaces;
+
+ nRet = iotcon_resource_interfaces_create(&ifaces);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_interfaces_create() Fail(%d)", nRet);
+ return nRet;
+ }
+
+ nRet = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_DEFAULT);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_interfaces_add() Fail(%d)", nRet);
+ iotcon_resource_interfaces_destroy(ifaces);
+ return nRet;
+ }
+
+ nRet = iotcon_resource_interfaces_add(ifaces, IOTCON_INTERFACE_BATCH);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_interfaces_add() Fail(%d)", nRet);
+ iotcon_resource_interfaces_destroy(ifaces);
+ return nRet;
+ }
+
+ *ifaces_h = ifaces;
+
+ return 0;
+}
+
+/**
+* @function CreateRepresentation
+* @description Called to create iotcon representation handle
+* @parameter iotcon_representation_h : The representation handle
+* @return int
+*/
+static int CreateRepresentation(iotcon_representation_h *representation)
{
int nRet;
char *uri_path = "/uri_path";
nRet = iotcon_representation_create(&repr);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_representation_create() Fail(%d)", nRet);
+ FPRINTF("iotcon_representation_create() Fail(%d)", nRet);
return nRet;
}
/* uri path */
nRet = iotcon_representation_set_uri_path(repr, uri_path);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_representation_set_uri_path() Fail(%d)", nRet);
+ FPRINTF("iotcon_representation_set_uri_path() Fail(%d)", nRet);
iotcon_representation_destroy(repr);
return nRet;
}
/* resource types */
- nRet = itc_create_resource_types(LIGHT_RESOURCE_TYPE, &types);
+ nRet = CreateResourceTypes(LIGHT_RESOURCE_TYPE, &types);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("itc_create_resource_types() Fail(%d)", nRet);
+ FPRINTF("CreateResourceTypes() Fail(%d)", nRet);
iotcon_representation_destroy(repr);
return nRet;
}
nRet = iotcon_representation_set_resource_types(repr, types);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_representation_set_resource_types() Fail(%d)", nRet);
+ FPRINTF("iotcon_representation_set_resource_types() Fail(%d)", nRet);
iotcon_resource_types_destroy(types);
iotcon_representation_destroy(repr);
return nRet;
iotcon_resource_types_destroy(types);
/* resource interfaces */
- nRet = itc_create_resource_interfaces(&ifaces);
+ nRet = CreateResourceInterfaces(&ifaces);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("itc_create_resource_interfaces() Fail(%d)", nRet);
+ FPRINTF("CreateResourceInterfaces() Fail(%d)", nRet);
iotcon_representation_destroy(repr);
return nRet;
}
nRet = iotcon_representation_set_resource_interfaces(repr, ifaces);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_representation_set_resource_interfaces() Fail(%d)", nRet);
+ FPRINTF("iotcon_representation_set_resource_interfaces() Fail(%d)", nRet);
iotcon_resource_interfaces_destroy(ifaces);
iotcon_representation_destroy(repr);
return nRet;
iotcon_resource_interfaces_destroy(ifaces);
/* state */
- nRet = itc_create_state(&state);
+ nRet = CreateState(&state);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("itc_create_state() Fail(%d)", nRet);
+ FPRINTF("CreateState() Fail(%d)", nRet);
iotcon_representation_destroy(repr);
return nRet;
}
nRet = iotcon_representation_set_state(repr, state);
if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_representation_set_state() Fail(%d)", nRet);
+ FPRINTF("iotcon_representation_set_state() Fail(%d)", nRet);
iotcon_state_destroy(state);
iotcon_representation_destroy(repr);
return nRet;
return 0;
}
+/**
+ * @function gmain_loop_quit_idle
+ * @description Called if some callback is not invoked for a particular timeout
+ * @parameter gpointer data
+ * @return gboolean
+ */
+static gboolean gmain_loop_quit_idle(gpointer p)
+{
+
+ g_main_loop_quit(g_pMainLoop);
+ return G_SOURCE_REMOVE;
+}
+
+/**
+* @function QuitGmainLoopIdle
+* @description Called to quit
+* @parameter NA
+* @return NA
+*/
+static void QuitGmainLoopIdle(bool result)
+{
+ g_bResult = result;
+ g_idle_add(gmain_loop_quit_idle, NULL);
+}
+
+/**
+* @function FindRequestHandlerCB
+* @description Called when create iotcon resource to get response handle
+* @parameter iotcon_resource_h : The resource handle, iotcon_request_h : The request handle
+* user_data : The user data passed from function
+* @return NA
+*/
+static void FindRequestHandlerCB(iotcon_resource_h resource,
+ iotcon_request_h request, void *user_data)
+{
+ FPRINTF("Inside FindRequestHandlerCB callback... \n");
+
+ int nRet;
+ iotcon_representation_h repr;
+ g_bRequestHandlerCB = true;
+ iotcon_response_h response;
+ nRet = CreateRepresentation(&repr);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("CreateRepresentation() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_response_create(request, &response);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_create() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, repr);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_set_representation() Fail(%d)", nRet);
+ iotcon_response_destroy(response);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_response_set_result(response, IOTCON_RESPONSE_OK);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_set_result() Fail(%d)", nRet);
+ iotcon_response_destroy(response);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ iotcon_representation_destroy(repr);
+
+ nRet = iotcon_response_send(response);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_send() Fail(%d)", nRet);
+ iotcon_response_destroy(response);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ iotcon_response_destroy(response);
+}
+
+
+/**
+* @function RequestHandlerCB
+* @description Called when create iotcon resource to get request handle
+* @parameter iotcon_resource_h : The resource handle, iotcon_request_h : The request handle
+* user_data : The user data passed from function
+* @return NA
+*/
+static void RequestHandlerCB(iotcon_resource_h resource, iotcon_request_h request,
+ void *user_data)
+{
+ FPRINTF("Inside RequestHandlerCB callback... \n");
+
+ int nRet;
+ iotcon_representation_h hRep = NULL;
+ iotcon_response_h hResponse;
+ g_bRequestHandlerCB = true;
+
+ nRet = CreateRepresentation(&hRep);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("CreateRepresentation() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_response_create(request, &hResponse);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_create() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_response_set_representation(hResponse, IOTCON_INTERFACE_DEFAULT, hRep);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_set_representation() Fail(%d)", nRet);
+ iotcon_response_destroy(hResponse);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_response_set_result(hResponse, IOTCON_RESPONSE_OK);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_set_result() Fail(%d)", nRet);
+ iotcon_response_destroy(hResponse);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ iotcon_representation_destroy(hRep);
+
+ nRet = iotcon_response_send(hResponse);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_response_send() Fail(%d)", nRet);
+ iotcon_response_destroy(hResponse);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ iotcon_response_destroy(hResponse);
+}
+
+/**
+* @function CreateResource
+* @description Called to create and add resource and interface.
+* @parameter NA
+* @return intiger : 0 if sussess
+*/
+static int CreateResource(int tc_index)
+{
+ FPRINTF("Inside CreateResource... \n");
+ int nRet;
+ iotcon_resource_types_h hLightTypes;
+ iotcon_resource_interfaces_h hLightiFaces;
+
+ nRet = iotcon_resource_types_create(&hLightTypes);
+ PRINT_RESULT(IOTCON_ERROR_NONE, nRet, "iotcon_resource_types_create", IotConGetError(nRet));
+
+ nRet = iotcon_resource_types_add(hLightTypes, LIGHT_RESOURCE_TYPE);
+ PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_resource_types_add", IotConGetError(nRet),iotcon_resource_types_destroy(hLightTypes));
+
+ nRet = iotcon_resource_interfaces_create(&hLightiFaces);
+ PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_resource_interfaces_create", IotConGetError(nRet),iotcon_resource_types_destroy(hLightTypes));
+
+ nRet = iotcon_resource_interfaces_add(hLightiFaces, IOTCON_INTERFACE_DEFAULT);
+ PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_resource_interfaces_add", IotConGetError(nRet),iotcon_resource_interfaces_destroy(hLightiFaces);iotcon_resource_types_destroy(hLightTypes));
+
+ nRet = iotcon_resource_interfaces_add(hLightiFaces, IOTCON_INTERFACE_BATCH);
+ PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_resource_interfaces_add", IotConGetError(nRet),iotcon_resource_interfaces_destroy(hLightiFaces);iotcon_resource_types_destroy(hLightTypes));
+ nRet = iotcon_resource_create(LIGHT_RESOURCE_URI,
+ hLightTypes,
+ hLightiFaces,
+ (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE),
+ RequestHandlerCB,
+ GINT_TO_POINTER(tc_index),
+ &g_hLightResource);
+
+ PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_resource_create", IotConGetError(nRet),iotcon_resource_interfaces_destroy(hLightiFaces);iotcon_resource_types_destroy(hLightTypes));
+
+ iotcon_resource_interfaces_destroy(hLightiFaces);
+ iotcon_resource_types_destroy(hLightTypes);
+
+ return 0;
+}
+
+/**
+* @function ResourceNotifyIdle
+* @description Called when Resource idle is notified
+* @parameter gpointer data
+* @return gboolean
+*/
+static gboolean ResourceNotifyIdle(gpointer p)
+{
+ int nRet;
+ iotcon_representation_h repr;
+ CreateRepresentation(&repr);
+ nRet = iotcon_resource_notify(g_hLightResource, repr, NULL, IOTCON_QOS_HIGH);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_notify() Fail(%d)", nRet);
+ iotcon_representation_destroy(repr);
+ QuitGmainLoopIdle(false);
+ return G_SOURCE_REMOVE;
+ }
+ iotcon_representation_destroy(repr);
+ return G_SOURCE_REMOVE;
+}
+
+/**
+* @function ResourceObserveCB
+* @description Called when resource observe is registered
+* @parameter iotcon_remote_resource_h : The remote resource handle, iotcon_error_e : The iotcon error,
+* sequence number ,iotcon_response_h: Iotcon Reponse user_data : The user data passed from function
+* @return NA
+*/
+static void ResourceObserveCB(iotcon_remote_resource_h resource,
+ iotcon_error_e err, int sequence_number, iotcon_response_h response, void *user_data)
+{
+ static int notify_count = 0;
+ int tc_index = (int)user_data;
+
+ switch (tc_index) {
+ case RESOURCE_CREATE:
+ case RESOURCE_SET_REQUEST_HANDLER:
+ QuitGmainLoopIdle(true);
+ return;
+ case RESOURCE_NOTIFY:
+ if (0 == notify_count++) {
+ FPRINTF("RESOURCE_NOTIFY");
+ g_idle_add(ResourceNotifyIdle, NULL);
+ return;
+ }
+ QuitGmainLoopIdle(true);
+ return;
+ default:
+ FPRINTF("Invalid tc_index(%d)", tc_index);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+}
+
+/**
+* @function FoundResourceCB
+* @description get remote resource clone
+* @parameter iotcon_remote_resource_h : The remote resource handle, iotcon_error_e : iotcon error
+* user_data : The user data passed from function
+* @return NA
+*/
+static void FoundResourceCB(iotcon_remote_resource_h resource,
+ iotcon_error_e err, void *user_data)
+{
+ FPRINTF("Inside FoundResourceCB callback... \n");
+
+ int nRet;
+ int tc_index = (int)user_data;
+ int nIotconTimeoutId = 0;
+
+ if (IOTCON_ERROR_TIMEOUT == err && nIotconTimeoutId < TIMEOUT_COUNT_MAX) {
+ nIotconTimeoutId++;
+ nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
+ LIGHT_RESOURCE_TYPE, false, FoundResourceCB, user_data);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_find_resource() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+ return;
+ } else if (IOTCON_ERROR_NONE != err) {
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ switch (tc_index) {
+ case RESOURCE_SET_REQUEST_HANDLER:
+ nRet = iotcon_resource_set_request_handler(g_hLightResource,
+ FindRequestHandlerCB, (void *)tc_index);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_resource_set_request_handler() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_remote_resource_clone(resource, &g_hRemoteResource);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_remote_resource_clone() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_remote_resource_observe_register(g_hRemoteResource,
+ IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER, NULL, ResourceObserveCB, (void *)tc_index);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_remote_resource_observe_register() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+ break;
+ case RESOURCE_CREATE:
+ case RESOURCE_NOTIFY:
+ nRet = iotcon_remote_resource_clone(resource, &g_hRemoteResource);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_remote_resource_clone() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+
+ nRet = iotcon_remote_resource_observe_register(g_hRemoteResource,
+ IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER, NULL, ResourceObserveCB, (void *)tc_index);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_remote_resource_observe_register() Fail(%d)", nRet);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+ break;
+ default:
+ FPRINTF("Invalid tc_index(%d)", tc_index);
+ QuitGmainLoopIdle(false);
+ return;
+ }
+}
+
+/**
+* @function CreateAndFindResource
+* @description Function to create and find resource
+* @parameter NA
+* @return intiger : 0 if sussess
+*/
+static int CreateAndFindResource(int tc_index)
+{
+ FPRINTF("[Line : %d][%s] Inside : CreateAndFindResource !!!\\n", __LINE__, API_NAMESPACE);
+ int nRet;
+ g_pMainLoop = g_main_loop_new(NULL, FALSE);
+ g_bRequestHandlerCB = false;
+
+ nRet = CreateResource(tc_index);
+ if (nRet == 1) {
+ FPRINTF("[Line : %d][%s] CreateResource() \\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+
+ nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
+ LIGHT_RESOURCE_TYPE, false, FoundResourceCB, (void *)tc_index);
+ if (IOTCON_ERROR_NONE != nRet) {
+ FPRINTF("iotcon_find_resource() Fail(%d)", nRet);
+ return 1;
+ }
+
+ g_main_loop_run(g_pMainLoop);
+ g_main_loop_unref(g_pMainLoop);
+
+ if(g_bRequestHandlerCB != true)
+ {
+ FPRINTF("[Line : %d][%s] CreateAndFindResource failed... \\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }else
+ return 0;
+}
+
//& set: Iotcon
/** @addtogroup itc-iotcon
return 0;
}
-
-
-static void _resource_request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
-{
- g_check = true;
- FN_CALL;
-}
-
/**
* @function ITs_iotcon_resource_startup
* @description Called before each test
* @precondition NA
* @postcondition NA
*/
-
int ITc_iotcon_resource_set_request_handler_p(void)
{
START_TEST;
- int nRet;
- int nIotconTimeoutId = 0;
- iotcon_resource_h resource = NULL;
- g_check = false;
-
- nRet = itc_create_resource(LIGHT_RESOURCE_TYPE, LIGHT_RESOURCE_URI, &resource);
- if(nRet != 0)
- {
- FPRINTF("ITc_iotcon_resource_set_request_handler_p: itc_create_resource FAILS \n");
- return 1;
- }
-
- nRet = iotcon_resource_set_request_handler(resource, _resource_request_handler, NULL);
- if (IOTCON_ERROR_NONE != nRet) {
- FPRINTF("iotcon_resource_set_request_handler() Fail(%d)", nRet);
- iotcon_resource_destroy(resource);
- return 1;
- }
- RUN_POLLING_LOOP;
- if(g_check == false)
- {
- FPRINTF("iotcon_resource_set_request_handler: Callback not invoked \n");
- return 1;
- }
-
- iotcon_resource_destroy(resource);
+ int nRet = CreateAndFindResource(RESOURCE_SET_REQUEST_HANDLER);
+ PRINT_RESULT(IOTCON_ERROR_NONE, nRet, "CreateAndFindResource", IotConGetError(nRet));
return 0;
}
* @precondition NA
* @postcondition NA
*/
-//int ITc_iotcon_resource_notify_p(void)
-
int ITc_iotcon_resource_notify_p(void)
{
START_TEST;
- int nRet;
- iotcon_resource_h resource = NULL;
- iotcon_representation_h repr = NULL;
- g_check = false;
-
- nRet = itc_create_resource(LIGHT_RESOURCE_TYPE, LIGHT_RESOURCE_URI, &resource);
- ITC_ASSERT_EQ(nRet, 0);
- if(g_check == false)
- {
- FPRINTF("ITc_iotcon_resource_notify_p: Callback not invoked \n");
- return 1;
- }
+ int nRet = CreateAndFindResource(RESOURCE_NOTIFY);
+ PRINT_RESULT(IOTCON_ERROR_NONE, nRet, "CreateAndFindResource", IotConGetError(nRet));
- nRet = itc_create_representation(&repr);
- if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("itc_create_representation() Fail(%d)", nRet);
- iotcon_resource_destroy(resource);
- return 1;
- }
-
- nRet = iotcon_resource_notify(resource, repr, NULL, IOTCON_QOS_HIGH);
- if (IOTCON_ERROR_NONE != nRet) {
- ITC_ERR("iotcon_resource_notify() Fail(%d)", nRet);
- iotcon_representation_destroy(repr);
- iotcon_resource_destroy(resource);
- return 1;
- }
-
- iotcon_representation_destroy(repr);
- iotcon_resource_destroy(resource);
return 0;
}
/** @} */
-/** @} */
+/** @} */
\ No newline at end of file