From: Jihoon Jung Date: Tue, 9 Jan 2018 05:33:14 +0000 (+0900) Subject: Add bind function and some comments X-Git-Tag: submit/tizen/20190131.065036~271 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec016eb901783c3238f1e8f5ff0da9f29e68a7e8;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Add bind function and some comments Signed-off-by: Jihoon Jung --- diff --git a/src/fn-manager/include/fn_context.h b/src/fn-manager/include/fn_context.h index 04a8d1a..8111277 100755 --- a/src/fn-manager/include/fn_context.h +++ b/src/fn-manager/include/fn_context.h @@ -14,6 +14,9 @@ typedef struct { // resource list GList *resource_list[FN_RESOURCE_TYPE_MAX]; + + char *device_uuid; + int operation_resource_count; } fn_context_t; int fn_context_create(); diff --git a/src/fn-manager/include/fn_enum.h b/src/fn-manager/include/fn_enum.h index f8dfb57..7967496 100755 --- a/src/fn-manager/include/fn_enum.h +++ b/src/fn-manager/include/fn_enum.h @@ -24,7 +24,7 @@ typedef enum { /* resource type enum */ typedef enum { FN_RESOURCE_TYPE_GROUP = 0, - FN_RESOURCE_TYPE_GROUP_DEVICE = 0, + FN_RESOURCE_TYPE_GROUP_DEVICE, FN_RESOURCE_TYPE_OPERATION, FN_RESOURCE_TYPE_MAX } fn_resource_type_e; diff --git a/src/fn-manager/include/fn_iot.h b/src/fn-manager/include/fn_iot.h index 054b863..03e3fc4 100755 --- a/src/fn-manager/include/fn_iot.h +++ b/src/fn-manager/include/fn_iot.h @@ -6,7 +6,7 @@ #define SVR_PATH "/tmp/.svr.dat" int fn_iot_initialize(); -int fn_iot_add_resource(fn_resource_type_e resource_type, char *name); +int fn_iot_add_resource(fn_resource_type_e resource_type, char *uri); 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(); diff --git a/src/fn-manager/include/fn_resource.h b/src/fn-manager/include/fn_resource.h index f5cfe43..245e9da 100755 --- a/src/fn-manager/include/fn_resource.h +++ b/src/fn-manager/include/fn_resource.h @@ -7,19 +7,21 @@ typedef struct { fn_resource_type_e resource_type; char *type; - char *uri; + char *uri_prefix; uint8_t policies; } fn_rd_t; typedef struct { iotcon_resource_h resource; - char *name; + char *uri; } fn_re_t; -int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_resource_h resource); +int fn_resource_append(fn_resource_type_e resource_type, char *uri, iotcon_resource_h resource); char *fn_resource_get_type(fn_resource_type_e resource_type); -char *fn_resource_get_uri(fn_resource_type_e resource_type); +char *fn_resource_get_uri_prefix(fn_resource_type_e resource_type); uint8_t fn_resource_get_policies(fn_resource_type_e resource_type); void fn_resource_print_list(); +int fn_resource_get_resource_from_uri(fn_resource_type_e resource_type, + char *uri, iotcon_resource_h *parent_resource); #endif diff --git a/src/fn-manager/src/fn_context.c b/src/fn-manager/src/fn_context.c index 0d21eda..8b5273c 100755 --- a/src/fn-manager/src/fn_context.c +++ b/src/fn-manager/src/fn_context.c @@ -10,6 +10,7 @@ int fn_context_create() LOG_DEBUG("create mtp_context is failed"); return FN_ERROR_UNKNOWN; } + _fn_ctx->device_uuid = g_strdup("123123"); return FN_ERROR_NONE; } diff --git a/src/fn-manager/src/fn_group.c b/src/fn-manager/src/fn_group.c index ddd78dd..11d972e 100755 --- a/src/fn-manager/src/fn_group.c +++ b/src/fn-manager/src/fn_group.c @@ -14,11 +14,30 @@ int fn_group_create(char* name) LOG_BEGIN(); + ret = fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP, name); if (ret != FN_ERROR_NONE) { LOG_ERR("Add resource is failed : %s", fn_log_get_error_string(ret)); } + + /* A own group device is included in the created group by default. */ + /* I would like to use multiple group device resource bindings for this created group resources. + If there is a better way, please change it. + + Group/Jihoon (Group (In this daemon)) + - Group/Device123123 (Group Device (In this daemon)) + - Group/Device3321 (Group Device (remote)) + - Group/Device1101 (Group Device (remote)) + */ + + fn_context_t *fn_ctx = fn_context_get_context(); + + ret = fn_iot_bind_resource(FN_RESOURCE_TYPE_GROUP, name, FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid); + if (ret != FN_ERROR_NONE) { + LOG_ERR("Bind resource is failed : %s", fn_log_get_error_string(ret)); + } + LOG_END(); return FN_ERROR_NONE; diff --git a/src/fn-manager/src/fn_iot.c b/src/fn-manager/src/fn_iot.c index 4421296..985fc39 100755 --- a/src/fn-manager/src/fn_iot.c +++ b/src/fn-manager/src/fn_iot.c @@ -5,6 +5,28 @@ int fn_iot_initialize() int ret = iotcon_initialize(SVR_PATH); LOG_DEBUG("iotcon_initialize : %s", get_error_message(ret)); + fn_context_t *fn_ctx = fn_context_get_context(); + + /* + "Group device" resource + The Group device resource is only one per device. + resource type is core.fn.group.device + This resource has device information as an attribute. + The resource uri is /fn/group/device + certain uuid. + ex) /fn/group/device123123 + */ + fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid); + + /* + "operation" resource + The operation resource is a control command channel between daemon and daemon. + resource type is core.fn.operation + Within this function we create a default operation resource. (uri is /fn/operation/1) + If we need more control channels, increase the number. + ex) /fn/operation/2, /fn/operation/3 + */ + fn_iot_add_resource(FN_RESOURCE_TYPE_OPERATION, "1"); + return FN_ERROR_NONE; } @@ -21,15 +43,13 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques //resource type "operation" don't have "get" request type. } -int fn_iot_add_resource(fn_resource_type_e resource_type, char *name) +int fn_iot_add_resource(fn_resource_type_e resource_type, char *uri) { iotcon_resource_h resource = NULL; iotcon_resource_types_h resource_types = NULL; iotcon_resource_interfaces_h resource_ifaces = NULL; char uri_path[PATH_MAX] = {0,}; - fn_context_mutex_lock(); - int ret = iotcon_resource_types_create(&resource_types); if (IOTCON_ERROR_NONE != ret) { LOG_ERR("iotcon_resource_types_create failed! : %s", get_error_message(ret)); @@ -54,10 +74,10 @@ int fn_iot_add_resource(fn_resource_type_e resource_type, char *name) goto EXIT; } - strncpy(uri_path, fn_resource_get_uri(resource_type), PATH_MAX); - strncat(uri_path, name, PATH_MAX); + strncpy(uri_path, fn_resource_get_uri_prefix(resource_type), PATH_MAX); + strncat(uri_path, uri, PATH_MAX); - LOG_DEBUG("resource uri is %s", uri_path); + LOG_DEBUG("[ADD] resource uri is %s", uri_path); //name duplication check ret = iotcon_resource_create(uri_path, resource_types, resource_ifaces, @@ -68,7 +88,7 @@ int fn_iot_add_resource(fn_resource_type_e resource_type, char *name) } //get resource list of resource type - ret = fn_resource_append(resource_type, name, resource); + ret = fn_resource_append(resource_type, uri, resource); if (FN_ERROR_NONE != ret) { LOG_ERR("fn_resource_append failed! : %s", fn_log_get_error_string(ret)); goto EXIT; @@ -81,7 +101,43 @@ EXIT: if (resource_ifaces != NULL) iotcon_resource_interfaces_destroy(resource_ifaces); - fn_context_mutex_unlock(); + return FN_ERROR_NONE; +} + +int fn_iot_bind_resource(fn_resource_type_e parent_resource_type, char *parent_uri, + fn_resource_type_e child_resource_type, char *child_uri) +{ + int ret; + + iotcon_resource_h parent_resource = NULL; + iotcon_resource_h child_resource = NULL; + + ret = fn_resource_get_resource_from_uri(parent_resource_type, parent_uri, &parent_resource); + if (ret != 0) { + LOG_DEBUG("parent Resource can't found"); + return FN_ERROR_UNKNOWN; + } + + ret = fn_resource_get_resource_from_uri(child_resource_type, child_uri, &child_resource); + if (ret != 0) { + LOG_DEBUG("child Resource can't found"); + return FN_ERROR_UNKNOWN; + } + + ret = iotcon_resource_bind_child_resource(parent_resource, child_resource); + if (ret != 0) { + LOG_DEBUG("bind resource failed"); + return FN_ERROR_UNKNOWN; + } + + unsigned int *count = 0; + ret = iotcon_resource_get_child_count(parent_resource, &count); + if (ret != 0) { + LOG_DEBUG("get child count failed"); + return FN_ERROR_UNKNOWN; + } + + LOG_DEBUG("Now, resource type %d, uri %s has child count %d", parent_resource_type, parent_uri, count); return FN_ERROR_NONE; } diff --git a/src/fn-manager/src/fn_manager.c b/src/fn-manager/src/fn_manager.c index 6fc725a..4024488 100755 --- a/src/fn-manager/src/fn_manager.c +++ b/src/fn-manager/src/fn_manager.c @@ -4,7 +4,7 @@ int main(int argc, char *argv[]) { int ret; - LOG_DEBUG("FN Manager start. thread id"); + LOG_DEBUG("FN Manager start"); //1. create & get context ret = fn_context_create(); diff --git a/src/fn-manager/src/fn_resource.c b/src/fn-manager/src/fn_resource.c index ed851a1..676e3f0 100755 --- a/src/fn-manager/src/fn_resource.c +++ b/src/fn-manager/src/fn_resource.c @@ -10,7 +10,7 @@ static fn_rd_t fn_rds[] = { IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE}, }; -int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_resource_h resource) +int fn_resource_append(fn_resource_type_e resource_type, char *uri, iotcon_resource_h resource) { fn_context_t *fn_ctx = fn_context_get_context(); GList *list = fn_ctx->resource_list[resource_type]; @@ -18,7 +18,7 @@ int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_reso //append resource handle / name to list fn_re_t *element = g_new0(fn_re_t, 1); element->resource = resource; - element->name = g_strdup(name); + element->uri = g_strdup(uri); list = g_list_append(list, element); fn_ctx->resource_list[resource_type] = list; @@ -26,14 +26,34 @@ int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_reso return 0; } +int fn_resource_get_resource_from_uri(fn_resource_type_e resource_type, + char *uri, iotcon_resource_h *parent_resource) +{ + fn_context_t *fn_ctx = fn_context_get_context(); + GList *list = fn_ctx->resource_list[resource_type]; + + GList *l; + for (l = list; l != NULL; l = l->next) { + fn_re_t *re = (fn_re_t *)l->data; + + if (strcmp(re->uri, uri) == 0) { + LOG_DEBUG("Resource found - type : %d uri : %s", resource_type, uri); + *parent_resource = re->resource; + return 0; + } + } + + return -1; +} + char *fn_resource_get_type(fn_resource_type_e resource_type) { return fn_rds[resource_type].type; } -char *fn_resource_get_uri(fn_resource_type_e resource_type) +char *fn_resource_get_uri_prefix(fn_resource_type_e resource_type) { - return fn_rds[resource_type].uri; + return fn_rds[resource_type].uri_prefix; } uint8_t fn_resource_get_policies(fn_resource_type_e resource_type) @@ -44,7 +64,7 @@ uint8_t fn_resource_get_policies(fn_resource_type_e resource_type) 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); + LOG_DEBUG(" ** resource : %x, uri : %s", re->resource, re->uri); } void fn_resource_print_list()