static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
+ //get resource element from fn resource list or, parsing resource uri
+ //if request type is "get" and resource type is "group",
+ //then OWNER send device information to CLIENT(Device info Exchange)
+ //if request type is "put" and resource type is "operation",
+ //then It is join request. CLIENT send device information to OWNER(Device info Exchange)
+ //resource type "operation" don't have "get" request type.
}
int fn_iot_add_resource(fn_resource_type_e resource_type, char *name)
ret = iotcon_resource_types_add(resource_types, fn_resource_get_type(resource_type));
if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_types_add failed! : %d", get_error_message(ret));
+ LOG_ERR("iotcon_resource_types_add failed! : %s", get_error_message(ret));
goto EXIT;
}
ret = iotcon_resource_interfaces_create(&resource_ifaces);
if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_interfaces_create failed! : %d", get_error_message(ret));
+ LOG_ERR("iotcon_resource_interfaces_create failed! : %s", get_error_message(ret));
goto EXIT;
}
ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_resource_interfaces_add failed! : %d", get_error_message(ret));
+ LOG_ERR("iotcon_resource_interfaces_add failed! : %s", get_error_message(ret));
goto EXIT;
}
ret = iotcon_resource_create(uri_path, resource_types, resource_ifaces,
fn_resource_get_policies(resource_type), _request_handler, NULL, &resource);
+ if (IOTCON_ERROR_NONE != ret) {
+ LOG_ERR("iotcon_resource_create failed! : %s", get_error_message(ret));
+ goto EXIT;
+ }
//get resource list of resource type
ret = fn_resource_append(resource_type, name, resource);
+ if (FN_ERROR_NONE != ret) {
+ LOG_ERR("fn_resource_append failed! : %s", fn_log_get_error_string(ret));
+ goto EXIT;
+ }
EXIT:
if (resource_types != NULL)
return FN_ERROR_NONE;
}
+static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
+ void *user_data)
+{
+ int ret;
+ char *resource_uri_path = NULL;
+ iotcon_resource_types_h resource_types;
+
+ ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
+ if (IOTCON_ERROR_NONE != ret)
+ return IOTCON_FUNC_CONTINUE;
+
+ ret = iotcon_remote_resource_get_types(resource, &resource_types);
+ LOG_DEBUG("resource uri : %s", resource_uri_path);
+
+ return IOTCON_FUNC_CONTINUE;
+}
+
+int fn_iot_discovery_resource(fn_resource_type_e resource_type)
+{
+ int ret;
+ iotcon_query_h query;
+
+ ret = iotcon_query_create(&query);
+ if (IOTCON_ERROR_NONE != ret)
+ /* Error handling */
+
+ ret = iotcon_query_set_resource_type(query, fn_resource_get_type(resource_type));
+ if (IOTCON_ERROR_NONE != ret)
+ /* Error handling */
+
+ LOG_DEBUG("find resource : %s", get_error_message(ret));
+
+ ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
+ IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
+ query, _found_resource, NULL);
+
+ LOG_DEBUG("find resource : %s", get_error_message(ret));
+}
+
int fn_iot_delete_resource(fn_resource_type_e resource_type)
{
//delete resource from resource list using resource_type and index
}
}
+void __print_foreach_resource(gpointer data, gpointer user_data)
+{
+ fn_re_t *re = (fn_re_t *)data;
+ LOG_DEBUG(" ** resource : %x, name : %s", re->resource, re->name);
+}
+
void fn_log_print_resource_list()
{
+ fn_context_t *fn_ctx = fn_context_get_context();
+
+ LOG_DEBUG("-------------------Print resource list-----------------------");
+
+ for (int i = 0; i < FN_RESOURCE_TYPE_MAX; i++) {
+ LOG_DEBUG("Resource type %d list length : %d", i, g_list_length(fn_ctx->resource_list[i]));
+ g_list_foreach(fn_ctx->resource_list[i], __print_foreach_resource, NULL);
+ }
+ LOG_DEBUG("-------------------Print resource list end-------------------");
}
//4. dbus interface initialize
//5. Make TX interface
+ //example code
+ fn_context_t *fn_ctx = fn_context_get_context();
+
+ if (fn_ctx->role == FN_ROLE_OWNER) {
+ LOG_DEBUG("OWNER");
+ ret = fn_group_create("group1");
+ ret = fn_group_create("group223");
+ fn_log_print_resource_list();
+ } else {
+ LOG_DEBUG("CLIENT");
+ ret = fn_group_discovery(NULL, NULL);
+ }
+
//6. group mgr initialize
ret = fn_group_initialize();
if (ret != FN_ERROR_NONE) {
//7. operation mgr initialize
//8. g main loop run
- fn_context_t *fn_ctx = fn_context_get_context();
+
fn_ctx->main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(fn_ctx->main_loop);