From: Jihoon Jung Date: Thu, 14 Dec 2017 08:27:54 +0000 (+0900) Subject: Change fn manager X-Git-Tag: submit/tizen/20190131.065036~289 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e30d8e10c0b204cadeefd9502afa5dbb5b53cb33;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Change fn manager Signed-off-by: Jihoon Jung --- diff --git a/src/fn-manager/fn_group.c b/src/fn-manager/fn_group.c index 2108865..9ab14a7 100755 --- a/src/fn-manager/fn_group.c +++ b/src/fn-manager/fn_group.c @@ -20,10 +20,12 @@ int fn_group_create(char *group_name) return ret; } -int fn_group_discovery(fn_resource_type_e resource_type, fn_resource_h *resources, int *count) +int fn_group_discovery(fn_group_h *groups, int *count) { + int ret; //if I'm owner, get the device list and info in network. //if I'm client, get the owner and group list. + ret = fn_iot_discovery_resource(FN_RESOURCE_TYPE_GROUP); return FN_ERROR_NONE; } diff --git a/src/fn-manager/fn_iot.c b/src/fn-manager/fn_iot.c index 53d4576..6c58671 100755 --- a/src/fn-manager/fn_iot.c +++ b/src/fn-manager/fn_iot.c @@ -11,7 +11,13 @@ int fn_iot_initialize() 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) @@ -31,19 +37,19 @@ 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; } @@ -55,9 +61,17 @@ int fn_iot_add_resource(fn_resource_type_e resource_type, char *name) 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) @@ -71,6 +85,45 @@ EXIT: 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 diff --git a/src/fn-manager/fn_log.c b/src/fn-manager/fn_log.c index 1cdd294..bd8a81e 100755 --- a/src/fn-manager/fn_log.c +++ b/src/fn-manager/fn_log.c @@ -27,7 +27,22 @@ const char *fn_log_get_error_string(int result) { } } +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-------------------"); } diff --git a/src/fn-manager/fn_manager.c b/src/fn-manager/fn_manager.c index f0f7fc8..7bc8859 100755 --- a/src/fn-manager/fn_manager.c +++ b/src/fn-manager/fn_manager.c @@ -23,6 +23,19 @@ int main(int argc, char *argv[]) //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) { @@ -33,7 +46,7 @@ int main(int argc, char *argv[]) //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); diff --git a/src/fn-manager/fn_resource.c b/src/fn-manager/fn_resource.c index 42c21ff..a66278b 100755 --- a/src/fn-manager/fn_resource.c +++ b/src/fn-manager/fn_resource.c @@ -16,8 +16,11 @@ int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_reso fn_re_t *element = g_new0(fn_re_t, 1); element->resource = resource; element->name = g_strdup(name); + element->resource_type = resource_type; list = g_list_append(list, element); + fn_ctx->resource_list[resource_type] = list; + return 0; } diff --git a/src/include/fn_group.h b/src/include/fn_group.h index 9a9f846..b353803 100755 --- a/src/include/fn_group.h +++ b/src/include/fn_group.h @@ -1,9 +1,15 @@ #ifndef __FN_GROUP_H__ #define __FN_GROUP_H__ -#include #include +typedef struct fn_group_t *fn_group_h; + +typedef struct { + char *group_name; + /*and device information*/ +} fn_group_t; + int fn_group_initialize(); int fn_group_create(char *group_name); int fn_group_discovery(); diff --git a/src/include/fn_iot.h b/src/include/fn_iot.h index eee361d..054b863 100755 --- a/src/include/fn_iot.h +++ b/src/include/fn_iot.h @@ -8,6 +8,7 @@ int fn_iot_initialize(); int fn_iot_add_resource(fn_resource_type_e resource_type, char *name); int fn_iot_delete_resource(fn_resource_type_e resource_type); +int fn_iot_discovery_resource(fn_resource_type_e resource_type); int fn_iot_deinitialize(); #endif diff --git a/src/include/fn_log.h b/src/include/fn_log.h index 8ce5976..bee839b 100755 --- a/src/include/fn_log.h +++ b/src/include/fn_log.h @@ -3,6 +3,7 @@ #include #include +#include #ifdef LOG_TAG #undef LOG_TAG diff --git a/src/include/fn_resource.h b/src/include/fn_resource.h index 8f7d57f..a81e7b5 100755 --- a/src/include/fn_resource.h +++ b/src/include/fn_resource.h @@ -2,16 +2,8 @@ #define __FN_RESOURCE_H__ #include -#include #include -typedef struct fn_resource_t *fn_resource_h; - -typedef struct { - fn_resource_type_e resource_type; - char *name; -} fn_resource_t; - typedef struct { fn_resource_type_e resource_type; char *type;